<?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');
$ObjStructureOrganizationMod = new StructureOrganizationMod($MS_SP);
if(true === isset($_POST['operation']) && '' != ($_POST['operation'])){
  switch ($_POST['operation']) {
    case 'create_node':
      $ArrStructureOrganization = $ObjStructureOrganizationMod->Add($_POST);
      if (true === isset($ArrStructureOrganization['status']) && 1 == $ArrStructureOrganization['status'] && true === isset($ArrStructureOrganization['id']) && true === is_numeric($ArrStructureOrganization['id'])){
        $VarReturn = '{ "status" : 1, "id" : '. $ArrStructureOrganization['id'] .' }';
      }
      else{
        $VarReturn = '{ "status" : 0}';
      }
    break;

    case 'rename_node':
      $ArrStructureOrganization = $ObjStructureOrganizationMod->Edit($_POST);
      if (true === is_numeric($ArrStructureOrganization)){
        $VarReturn = '{ "status" : 1 }';
      }
      else{
        $VarReturn = '{ "status" : 0}';
      }
    break;

    case 'remove_node':
      if (true === isset($_POST['id']) && true === is_numeric($_POST['id']) && 0 < $_POST['id']){
        $ArrStructureOrganization = $ObjStructureOrganizationMod->Del($_POST['id']);
        if (true === $ArrStructureOrganization){
          $VarReturn = '{ "status" : 1 }';
        }
        else{
          $VarReturn = '{ "status" : 0}';
        }
      }
      else{
        $VarReturn = '{ "status" : 0}';
      }
    break;


    case 'move_node':
      if (true === isset($_POST['copy']) && true === is_numeric($_POST['copy']) && 0 == $_POST['copy']){
        $ArrStructureOrganization = $ObjStructureOrganizationMod->Move($_POST);
        if (true === $ArrStructureOrganization){
          $VarReturn = '{ "status" : 1, "id" : 1 }';//{ "status" : 1, "id" : 1 }
        }
        else{
          $VarReturn = '{ "status" : 0}';
        }
      }
      if (true === isset($_POST['copy']) && true === is_numeric($_POST['copy']) && 1 == $_POST['copy']){
        $ArrStructureOrganization = $ObjStructureOrganizationMod->Copy($_POST);
        if (true === isset($ArrStructureOrganization['status']) && 1 == $ArrStructureOrganization['status'] && true === isset($ArrStructureOrganization['id']) && true === is_numeric($ArrStructureOrganization['id'])){
          $VarReturn = '{ "status" : 1, "id" : '. $ArrStructureOrganization['id'] .' }';//{ "status" : 1, "id" : 100 }
        }
        else{
          $VarReturn = '{ "status" : 0}';
        }
      }
    break;

    default:
    break;
  }

}
else{
  $VarReturn = '{ "status" : 0}';
}
echo $VarReturn;
?>