<?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']) && true === is_numeric($_SESSION['SessionAuth']['id'])) {
  $ObjSvtMod = new SvtMod($MS_SP);
  $ObjSvtMoveMod = new SvtMoveMod($MS_SP);
  if (true === isset($_POST['svt_id']) && true === is_numeric($_POST['svt_id'])){
    $ArrSvt = $ObjSvtMod->GetFromDb('SqlAll', 'GetRow', 'a.svt_id = "'. $_POST['svt_id'] .'"');
//    $ArrSvt[''] = ''
//            %5B%5D=93&FrmAgreeStructureOrganizationHidden=&FrmAgreeUsersCheckboxes%5B%5D=240&FrmAgreeUsersHidden=&svt_id=733&svtmove_date=23.01.2014&svtmove_note=wdwedwd
    $_POST['structureorganization_id_from'] = $ArrSvt['structureorganization_id'];
    $_POST['users_id_from'] = $ArrSvt['users_id'];
    $_POST['structureorganization_id_to'] = NULL;
    $_POST['users_id_to'] = NULL;
    if(true === isset($_POST['FrmAgreeStructureOrganizationCheckboxes']) && '' != current($_POST['FrmAgreeStructureOrganizationCheckboxes'])){
      $_POST['structureorganization_id_to'] = current($_POST['FrmAgreeStructureOrganizationCheckboxes']);
    }
    if(true === isset($_POST['FrmAgreeUsersCheckboxes']) && '' != current($_POST['FrmAgreeUsersCheckboxes'])){
      $_POST['users_id_to'] = current($_POST['FrmAgreeUsersCheckboxes']);
    }
    $VarSvtId = $ObjSvtMod->Move($_POST);
    $VarSvtMoveId = $ObjSvtMoveMod->Add($_POST);
    if (true !== is_numeric($VarSvtId)){
      $ArrReturn = $VarSvtId;
    }
    if (true !== is_numeric($VarSvtMoveId)){
      $ArrReturn = $VarSvtMoveId;
    }
    if (true === is_numeric($VarSvtId) && true === is_numeric($VarSvtMoveId)){
      $ArrReturn = array('message' => $MS_SP->Sp_LangMessage['message']['MessRecordAddSuccess']);
    }
    else{
      $ArrReturn = array('error' => $MS_SP->Sp_LangMessage['error']['ErrUnknownError']);
    }
  }
  else{
    $ArrReturn = array('error' => $MS_SP->Sp_LangMessage['error']['ErrSettingWrong']);
  }
}
else{
  $ArrReturn = array('error' => $MS_SP->Sp_LangMessage['error']['ErrFuncAccessDenied']);
}
echo json_encode($ArrReturn);
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
?>