<?php
include($_SERVER['DOCUMENT_ROOT'] .'/script/HeaderInc.php');

//SiteLibs::GetVarDump($_SESSION);
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'])
   ){
  $smarty->assign('VarMenuMain', $VarMenu);
  
	$ObjDemandsMod = new DemandsMod($MS_SP);
	$ArrDemands = $ObjDemandsMod->GetFromDb('SqlForFirstPageCount', 'GetAll', '', 'b.sprstatus_order');
  //SiteLibs::GetVarDump($ArrDemands);
  $smarty->assign('ArrDemands', $ArrDemands);
  $VarDemandsForFirstPage = $smarty->fetch('Demands/DemandsForFirstPageCount.tpl');
  $smarty->assign('VarDemandsForFirstPage', $VarDemandsForFirstPage);
  
//	$ArrDemandsMasterByStatus = $ObjDemandsMod->GetFromDb('SqlDemandsStatusMasterForFirstPageCount', 'GetAll', '"'. date("Y-m") .'-01" <= d.demands_statusdate AND d.demands_statusdate <= "'. date("Y-m-d") .'"', 's.sprstatus_order');
	$ArrDemandsMasterByStatus = $ObjDemandsMod->GetFromDb('SqlDemandsStatusMasterForFirstPageCount', 'GetAll', '', 's.sprstatus_order');
//  SiteLibs::GetVarDump($ArrDemandsMasterByStatus);
  $smarty->assign('ArrDemandsMasterByStatus', $ArrDemandsMasterByStatus);
  $VarDemandsMasterByStatus = $smarty->fetch('Demands/DemandsStatusMasterForFirstPageCount.tpl');
  $smarty->assign('VarDemandsMasterByStatus', $VarDemandsMasterByStatus);
  
  $VarWhere = '';
	$ObjSvtGiveoutMod = new SvtGiveoutMod($MS_SP);
	$ArrSvtGiveout = $ObjSvtGiveoutMod->GetFromDb('SqlForFirstPageCount', 'GetAll', $VarWhere, 'b.svtgiveoutstatus_order');
  $smarty->assign('ArrSvtGiveout', $ArrSvtGiveout);
//  SiteLibs::GetVarDump($ArrSvtGiveout);
  $VarSvtGiveoutForFirstPage = $smarty->fetch('SvtGiveout/SvtGiveoutForFirstPageCount.tpl');
  $smarty->assign('VarSvtGiveoutForFirstPage', $VarSvtGiveoutForFirstPage);

  $VarWhere = '';
	$ObjRepairMod = new RepairMod($MS_SP);
	$ArrRepair = $ObjRepairMod->GetFromDb('SqlForFirstPageCount', 'GetAll', $VarWhere, 'b.repairstatus_order');
  $smarty->assign('ArrRepair', $ArrRepair);
  $VarRepairForFirstPage = $smarty->fetch('Repair/RepairForFirstPageCount.tpl');
  $smarty->assign('VarRepairForFirstPage', $VarRepairForFirstPage);
  
  $VarPolicence_datee = date("Y-m-d", strtotime('+'. $MS_SP->Sp_Config['LicPoDeadLine'] .' month'));
  $VarWhere = 'a.policence_datee <= "'. $VarPolicence_datee .'"';
//  echo $VarWhere;
	$ObjPoLicenceMod = new PoLicenceMod($MS_SP);
	$ArrPoLicence = $ObjPoLicenceMod->GetFromDb('SqlAll', 'GetAll', $VarWhere, 'a.policence_datee');
  $smarty->assign('ArrPoLicence', $ArrPoLicence);
  $VarPoLicenceForFirstPage = $smarty->fetch('PoLicence/PoLicenceForFirstPageCount.tpl');
  $smarty->assign('VarPoLicenceForFirstPage', $VarPoLicenceForFirstPage);
  
  $VarPurchase_datetill = date("Y-m-d", strtotime('+'. $MS_SP->Sp_Config['PurchaseDeadLine'] .' month'));
  $VarWhere = 'p.purchase_datetill <= "'. $VarPurchase_datetill .'" AND p.purchasestatus_id = 1';
//  echo $VarWhere;
	$ObjPurchaseMod = new PurchaseMod($MS_SP);
	$ArrPurchase = $ObjPurchaseMod->GetFromDb('SqlAll', 'GetAll', $VarWhere, 'p.purchase_datetill');
  $smarty->assign('ArrPurchase', $ArrPurchase);
  $VarPurchaseForFirstPage = $smarty->fetch('Purchase/PurchaseForFirstPageCount.tpl');
  $smarty->assign('VarPurchaseForFirstPage', $VarPurchaseForFirstPage);
  
  $VarPagesTxt .= $smarty->fetch('Info/ForFirstPage.tpl');
  if(true === is_file($MS_SP->SP_CurrFileNameText)){
    $VarPagesTxt .= $smarty->fetch($MS_SP->SP_CurrFileNameText);
    //$smarty->assign('VarCurrPageTxt', @$VarCurrPageTxt);
  }
}
else{
  if(true === isset($_POST['form_auth_login']) && '' != $_POST['form_auth_login'] && true === isset($ArrUser) && true === is_array($ArrUser) && 0 < count($ArrUser)){
    $smarty->assign('VarError', $MS_SP->Sp_LangMessage['error']['ErrAuthAccessDenied']);
    $VarAuthForm .= $smarty->fetch('AccessDenied.tpl');
  }
//  $VarAuthForm .= $smarty->fetch('Auth/FormAuth.tpl');
  $VarAuthForm = 1;
  //$VarPagesTxt .= $VarAuthForm;
  
  $ObjIPFilterMod = new IPFilterMod();
  if(true === $ObjIPFilterMod->check($_SERVER['REMOTE_ADDR'])){
    $VarPagesTxt .= $smarty->fetch('Demands/DemandsUsers.tpl');
  }
}
//SiteLibs::GetVarDump($MS_SP);
$smarty->assign('VarAuthForm', @$VarAuthForm);
$smarty->assign('VarPagesTxt', @$VarPagesTxt);
if (true === isset($MS_SP->SP_CurrPage['template_file']) && '' != $MS_SP->SP_CurrPage['template_file']){
	$smarty->display($MS_SP->SP_CurrPage['template_file']);
}
else {
	$smarty->display('Page.tpl');
}
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
?>