<?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']) && true === isset($_GET['demandscomments_id']) && true === is_numeric($_GET['demandscomments_id'])) {
  
  $ObjDemandsMod = new DemandsMod($MS_SP);
  $ArrDemands = $ObjDemandsMod->GetFromDb('SqlAll', 'GetRow', "a.demands_id = '". $_GET['demands_id'] ."'");
  //SiteLibs::GetVarDump($ArrDemands);

  $ObjUsersMod = new UsersMod($MS_SP);
//  $VarWhere = 'u.structureorganization_id = "'. $ArrDemands['structureorganization_id'] .'"';
//  $ArrUsers = $ObjUsersMod->GetFromDb('SqlAll', 'GetAll', $VarWhere);
//  SiteLibs::GetVarDump($_SESSION['SessionAuth']);
  
  //$VarWhereAdd = 'us.webservices_id = -1';
  if(true === isset($_SESSION['SessionAuth']['id']) && true === is_numeric($_SESSION['SessionAuth']['id'])){
    if(true === isset($_SESSION['SessionAuth']['SvtAdmin']['reg']) && 1 == $_SESSION['SessionAuth']['SvtAdmin']['reg']){
      $VarWhere = 'us.webservices_id IN (1,2,3)';
      $ArrUsers = $ObjUsersMod->GetFromDb('SqlServices', 'GetAll', $VarWhere);
    }
    else{
      $VarWhere = 'u.users_id = "'. $_SESSION['SessionAuth']['id'] .'"';
      $ArrUsers = $ObjUsersMod->GetFromDb('SqlServices', 'GetAll', $VarWhere);
    }
  }
  else{
    $VarWhere = 'u.structureorganization_id = "'. $ArrDemands['structureorganization_id'] .'"';
    $ArrUsers = $ObjUsersMod->GetFromDb('SqlAll', 'GetAll', $VarWhere);
  }
  
  
  
  //SiteLibs::GetVarDump(array_merge($ArrUsers, $ArrUsersMaster));
  $smarty->assign('ArrUsers', $ArrUsers);
  
  $ObjDemandsCommentsMod = new DemandsCommentsMod($MS_SP);
  if(true === isset($_GET['UrlAction']) && 'edit' == $_GET['UrlAction']){
    $ArrDemandsComments = $ObjDemandsCommentsMod->GetFromDb('SqlAll', 'GetRow', "a.demandscomments_id = '". $_GET['demandscomments_id'] ."'");
    $smarty->assign('ArrDemandsComments', $ArrDemandsComments);
  }
  else{
    $_GET['demandscommentsparent_id'] = $_GET['demandscomments_id'];
    $_GET['demandscomments_id'] = '';
  }
  $VarReturn = $smarty->fetch('Demands/AnswFormEdit.tpl');
}
else{
  $VarReturn = $MS_SP->Sp_LangMessage['error']['ErrFuncAccessDenied'];
}
echo $VarReturn;
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
?>
