<?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']) {
  $ObjStructureOrganizationMod = new StructureOrganizationMod($MS_SP);
  if(true === isset($_GET['id']) && true === is_numeric($_GET['id'])){
    $VarWhere = "a.structureorganization_parent_id = '". $_GET['id'] ."'";
  }
  else{
    $VarWhere = "a.structureorganization_parent_id = '0'";
  }
  $ArrStructureOrganization = $ObjStructureOrganizationMod->GetFromDb('SqlBuildTree', 'GetAll', $VarWhere, 'a.structureorganization_position');

  $ArrFields = array();
  foreach ($ArrStructureOrganization AS $key => $row){
    if (1 <= $row['childcount']){
      $VarState = 'closed';
    }
    else{
      $VarState = '';
    }
    $ArrFields[$key] = array("attr" => array("id" => "node_". $row['structureorganization_id'], "rel" => $row['structureorganization_type']),
                        "state" => $VarState,
                        "data" => array("title" => $row['structureorganization_title'])
                       );
  }
  echo json_encode($ArrFields);
}
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
?>