<?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'] && 
  true === isset($_GET['svt_id']) && true === is_numeric($_GET['svt_id']) && 
  true === isset($_GET['po_id']) && true === is_numeric($_GET['po_id'])) {

  $ObjSvtPoMod = new SvtPoMod($MS_SP);
  $VarIsset = $ObjSvtPoMod->GetFromDb('SqlAll', 'GetOne', 'sp.svt_id = "'. $_GET['svt_id'] .'" AND sp.po_id = "'. $_GET['po_id'] .'"');
  if (true === isset($VarIsset) && true === is_numeric($VarIsset)){
    $ArrReturn = array('error' => $MS_SP->Sp_LangMessage['error']['ErrRecordAlreadyExist']);
  }
  else{
    $VarSvtPoId = $ObjSvtPoMod->Add(array('svt_id' => $_GET['svt_id'], 'po_id' => $_GET['po_id']));
    if (true === is_numeric($VarSvtPoId)){
      $ArrReturn = array('message' => $MS_SP->Sp_LangMessage['message']['MessRecordAddSuccess']);
    }
    else{
      $ArrReturn = $VarSvtPoId;
    }
  }
}
else{
  $ArrReturn = array('error' => $MS_SP->Sp_LangMessage['error']['ErrFuncAccessDenied']);
}
echo json_encode($ArrReturn);
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
?>
