<?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['svtgiveoutstatus_id']) && true === is_numeric($_GET['svtgiveoutstatus_id'])){
    $VarWhere .= " AND a.svtgiveoutstatus_id = '". $_GET['svtgiveoutstatus_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();
  $ObjSvtGiveoutMod = new SvtGiveoutMod($MS_SP);
  $count = $ObjSvtGiveoutMod->GetFromDb('SqlCount', 'GetOne', $VarWhere);
  $total_pages = $ObjJqGridMod->GetTotalPages($count);
  $page = $ObjJqGridMod->GetPage();
  $ArrSvtGiveout = $ObjSvtGiveoutMod->GetFromDb('SqlAll', 'GetAll', $VarWhere, $VarOrder, $VarLimit);
  //SiteLibs::GetVarDump($ArrSvtGiveout);
  $ArrFields = array();
  foreach ($ArrSvtGiveout AS $key => $row){
    $VarSvtBuxname = '';
    if(true === isset($row['svt_buxname']) && '' != $row['svt_buxname']){
      $VarSvtBuxname = '<a class="ui-state-default" href="'. $MS_SP->Sp_PathTop .'/SvtInformation.php?svt_id='. $row['svt_id'] .'" target="_blank" title="Подробнее о '. $row['svt_buxname'] .'">'. $row['svt_buxname'] .'</a>';
    }
    $VarSvtName = '';
    if(true === isset($row['svt_name']) && '' != $row['svt_name']){
      $VarSvtName = '<a class="ui-state-default" href="'. $MS_SP->Sp_PathTop .'/SvtInformation.php?svt_id='. $row['svt_id'] .'" target="_blank" title="Подробнее о '. $row['svt_name'] .'">'. $row['svt_name'] .'</a>';
    }
    
    $ArrFields[$key]['id'] = $row['svtgiveout_id'];
    $ArrFields[$key]['cell'][] = $row['master_fio'].'';
    $ArrFields[$key]['cell'][] = '<span style="background-color: '. $row['svtgiveoutstatus_color'] .';">'. $row['svtgiveoutstatus_name'] .'</span>';
    $ArrFields[$key]['cell'][] = $VarSvtBuxname;
    $ArrFields[$key]['cell'][] = $VarSvtName;
    $ArrFields[$key]['cell'][] = $row['svt_invnum'].'';
    $ArrFields[$key]['cell'][] = $row['svt_serialnum'].'';
    $ArrFields[$key]['cell'][] = $row['users_fio'].'';
    $ArrFields[$key]['cell'][] = $row['svtgiveout_date_b'].'';
    $ArrFields[$key]['cell'][] = $row['svtgiveout_date_e'].'';
    $ArrFields[$key]['cell'][] = $row['svtgiveout_note'].'';
  }
  $json = array("page" => $page, "total" => $total_pages, "records" => $count,"rows" => $ArrFields);
  echo json_encode($json);
}
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
?>