<?php  
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");
include($_SERVER['DOCUMENT_ROOT'] .'/script/HeaderInc.php');
if('XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH']) {
  $ObjJqGridMod = new JqGridMod();
  $ObjJqGridMod->SetArrayIn($_GET);
  $VarWhere = ' AND (p.pass_share != 1 OR p.users_id ="'. $_SESSION['SessionAuth']['id'] .'")';
  if(true === isset($_GET['_search']) && 'true' == $_GET['_search']){
    if(true === isset($ObjJqGridMod->filters) && '' != $ObjJqGridMod->filters){
      $VarWhere .= ' AND '. $ObjJqGridMod->generateSearchStringFromFilter();
    }
    if(true === isset($ObjJqGridMod->searchField) && '' != $ObjJqGridMod->searchField){
      $VarWhere .= ' AND '. $ObjJqGridMod->generateSearchStringFromSearchField();
    }
  }
  $VarWhere = SiteLibs::StripAndOrFirst($VarWhere);
  $VarOrder = $ObjJqGridMod->GetOrder();
  $VarLimit = $ObjJqGridMod->GetLimit();
  $ObjPassMod = new PassMod($MS_SP);
  $count = $ObjPassMod->GetFromDb('SqlCount', 'GetOne', $VarWhere);
  $total_pages = $ObjJqGridMod->GetTotalPages($count);
  $page = $ObjJqGridMod->GetPage();
  $ArrPass = $ObjPassMod->GetFromDb('SqlAll', 'GetAll', $VarWhere, $VarOrder, $VarLimit);
  $ArrFields = array();
  foreach ($ArrPass AS $key => $row){
    if('1' == $row['pass_share']){
      $VarPassShare = $MS_SP->Sp_LangMessage['script']['ScrShareOn'];
    }
    else{
      $VarPassShare = $MS_SP->Sp_LangMessage['script']['ScrShareOff'];
    }
    $ArrFields[$key]['id'] = $row['pass_id'];
    $ArrFields[$key]['cell'][] = $VarPassShare;
    $ArrFields[$key]['cell'][] = $row['pass_name'].'';
    $ArrFields[$key]['cell'][] = $row['pass_login'].'';
    $ArrFields[$key]['cell'][] = $row['pass_date'];
    $ArrFields[$key]['cell'][] = $row['pass_note'].'';
  }
  $json = array("page" => $page, "total" => $total_pages, "records" => $count,"rows" => $ArrFields);
  echo json_encode($json);
}
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
?>