<?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 = '';
  if(true === isset($_GET['_search']) && 'true' == $_GET['_search']){
    if(true === isset($ObjJqGridMod->filters) && '' != $ObjJqGridMod->filters){
      $VarWhere .= $ObjJqGridMod->generateSearchStringFromFilter();
    }
    if(true === isset($ObjJqGridMod->searchField) && '' != $ObjJqGridMod->searchField){
      $VarWhere .= $ObjJqGridMod->generateSearchStringFromSearchField();
    }
  }
  $VarOrder = $ObjJqGridMod->GetOrder();
  $VarLimit = $ObjJqGridMod->GetLimit();
  $ObjUsersMod = new UsersMod($MS_SP);
  $count = $ObjUsersMod->GetFromDb('SqlCount', 'GetOne', $VarWhere);
  $total_pages = $ObjJqGridMod->GetTotalPages($count);
  $page = $ObjJqGridMod->GetPage();
  $ArrUsers = $ObjUsersMod->GetFromDb('SqlAll', 'GetAll', $VarWhere, $VarOrder, $VarLimit);

  $ArrFields = array();
  foreach ($ArrUsers AS $key => $row){
    if('1' == $row['users_status']){
      $VarUsersStatus = $MS_SP->Sp_LangMessage['script']['ScrStatusOn'];
    }
    else{
      $VarUsersStatus = $MS_SP->Sp_LangMessage['script']['ScrStatusOff'];
    }
    $VarHref = $row['users_id'];
    $ArrFields[$key]['id'] = $row['users_id'];
    $ArrFields[$key]['cell'][] = $VarUsersStatus;
    $ArrFields[$key]['cell'][] = $row['users_fio'];
    $ArrFields[$key]['cell'][] = $row['structureorganization_title'];
    $ArrFields[$key]['cell'][] = $row['users_jobtitle'];
    $ArrFields[$key]['cell'][] = $row['users_numofice'];
    $ArrFields[$key]['cell'][] = $row['users_tel'];
    $ArrFields[$key]['cell'][] = $row['users_telint'];
    $ArrFields[$key]['cell'][] = $row['users_telcell'];
    $ArrFields[$key]['cell'][] = $row['users_email'];
    $ArrFields[$key]['cell'][] = $row['users_note'];
    $ArrFields[$key]['cell'][] = $row['users_name'];
    $ArrFields[$key]['cell'][] = $row['users_passclean'];
  }
  $json = array("page" => $page, "total" => $total_pages, "records" => $count,"rows" => $ArrFields);
  echo json_encode($json);
}
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
?>