<?php
include($_SERVER['DOCUMENT_ROOT'] .'/script/HeaderInc.php');
if('XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH'] && true === isset($_GET['demands_id']) && true === is_numeric($_GET['demands_id'])){
  $ObjDemandsMod = new DemandsMod($MS_SP);
  $ArrDemands = $ObjDemandsMod->GetFromDb('SqlAll', 'GetRow', "a.demands_id = '". $_GET['demands_id'] ."'");
  $smarty->assign('ArrDemands', $ArrDemands);
  $ObjUsersMod = new UsersMod($MS_SP);
  $VarWhereAdd = 'us.webservices_id = -1';
  if(true === isset($_SESSION['SessionAuth']['id']) && true === is_numeric($_SESSION['SessionAuth']['id'])){
    $VarWhereAdd = 'u.users_id = "'. $_SESSION['SessionAuth']['id'] .'"';
  }
  if(true === isset($_SESSION['SessionAuth']['SvtAdmin']['reg']) && 1 == $_SESSION['SessionAuth']['SvtAdmin']['reg']){
    $VarWhereAdd = 'us.webservices_id IN (1,2,3)';
  }
  $ArrUsersMaster = $ObjUsersMod->GetFromDb('SqlServices', 'GetAssoc', $VarWhereAdd);
  if (true === isset($ArrDemands['demands_masterid']) && true === isset($ArrDemands['master_fio']) && true !== array_key_exists($ArrDemands['demands_masterid'], $ArrUsersMaster)){
    $ArrUsersMaster[] = array("users_id" => $ArrDemands['demands_masterid'], "users_fio" => $ArrDemands['master_fio']);
  }
  $smarty->assign('ArrUsersMaster', $ArrUsersMaster);
  
  $ObjSprStatusMod = new SprStatusMod($MS_SP);
  $ArrSprStatus = $ObjSprStatusMod->GetFromDb('SqlAll', 'GetAll', '', 'a.sprstatus_order');
  $smarty->assign('ArrSprStatus', $ArrSprStatus);
  
  $ObjDemandsClassifMod = new DemandsClassifMod($MS_SP);
  $ArrDemandsClassif = $ObjDemandsClassifMod->GetFromDb('SqlAll', 'GetAll', '', 'a.demandsclassif_order');
  $smarty->assign('ArrDemandsClassif', $ArrDemandsClassif);

  if ((true === isset($_SESSION['SessionAuth']['SvtAdmin']['reg']) && 1 == $_SESSION['SessionAuth']['SvtAdmin']['reg']) ||
    (true === isset($_SESSION['SessionAuth']['SvtOperatorAdv']['reg']) && 1 == $_SESSION['SessionAuth']['SvtOperatorAdv']['reg']) ||
    (true === isset($_SESSION['SessionAuth']['SvtOperator']['reg']) && 1 == $_SESSION['SessionAuth']['SvtOperator']['reg'])
   ){
    $VarPagesTxt = $smarty->fetch('Demands/OpDemandsDetailView.tpl');
   }
   else{
     $VarPagesTxt = $smarty->fetch('Demands/DemandsDetailView.tpl');
   }
}
else{
  $smarty->assign('VarError', $MS_SP->Sp_LangMessage['error']['ErrSettingWrong']);
  $VarPagesTxt = $smarty->fetch('error.tpl');
}
echo $VarPagesTxt;
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
?>