<?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']['IpsAdmin']['reg']) && 1 == $_SESSION['SessionAuth']['IpsAdmin']['reg']){
  //SiteLibs::GetVarDump($_POST);
  array_walk($_POST, 'SiteLibs::ConvertArrayIconv', $MS_SP->Sp_Config['charset']);
  require_once($_SERVER['DOCUMENT_ROOT'] .'/script/Country.mod.php');
  $ObjCountryMod = new CountryMod($MS_SP);
  if (true === isset($_POST['country_id']) && true === is_numeric($_POST['country_id'])){
    $VarResult = $ObjCountryMod->Edit($_POST);
    if (true === is_numeric($VarResult)){
      $ArrReturn = array('message' => $MS_SP->Sp_LangMessage['message']['MessRecordEditSuccess']);
    }
    else{
      $ArrReturn = $VarResult;
    }
  }
  else{
    $VarResult = $ObjCountryMod->Add($_POST);
    if (true === is_numeric($VarResult)){
      $ArrReturn = array('message' => $MS_SP->Sp_LangMessage['message']['MessRecordAddSuccess']);
    }
    else{
      $ArrReturn = $VarResult;
    }
  }
}
else{
  $ArrReturn = array('error' => $MS_SP->Sp_LangMessage['error']['ErrFuncAccessDenied']);
}
array_walk($ArrReturn, 'SiteLibs::ConvertArrayIconvBack', $MS_SP->Sp_Config['charset']);
echo json_encode($ArrReturn);
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
?>