<?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'] && true === isset($_SESSION['SessionAuth']['id']) && 0 < $_SESSION['SessionAuth']['id']) {
  $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();
  $ObjCartridgeMod = new CartridgeMod($MS_SP);
  $count = $ObjCartridgeMod->GetFromDb('SqlCount', 'GetOne', $VarWhere);
  $total_pages = $ObjJqGridMod->GetTotalPages($count);
  $page = $ObjJqGridMod->GetPage();
  $ArrCartridge = $ObjCartridgeMod->GetFromDb('SqlAll', 'GetAll', $VarWhere, $VarOrder, $VarLimit);
  //SiteLibs::GetVarDump($ArrCartridge);
  $ArrFields = array();
  foreach ($ArrCartridge AS $key => $row){
    $ArrFields[$key]['id'] = $row['cartridge_id'];
    $ArrFields[$key]['cell'][] = $row['cartridge_name'].'';
    $ArrFields[$key]['cell'][] = '<a class="ui-state-default" href="'. $MS_SP->Sp_PathTop .'/SvtInformation.php?svt_id='. $row['svt_id'] .'" target="_blank" title="Подробнее о '. $row['svt_buxname'] .'" target="_blank">'. $row['svt_buxname'] .'</a>';
    $ArrFields[$key]['cell'][] = $row['organiz_name'].'';
    $ArrFields[$key]['cell'][] = $row['cartridge_serialnum'].'';
    $ArrFields[$key]['cell'][] = $row['cartridgetype_name'].'';
    $ArrFields[$key]['cell'][] = $row['cartridge_writeoff'] .' из '. $row['cartridgetype_writeoff'];
    $ArrFields[$key]['cell'][] = $row['cartridge_loaddate'].'';
    $ArrFields[$key]['cell'][] = $row['cartridge_buydate'].'';
    $ArrFields[$key]['cell'][] = $row['cartridge_note'].'';
  }
  $json = array("page" => $page, "total" => $total_pages, "records" => $count,"rows" => $ArrFields);
  echo json_encode($json);
}
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
?>