<?php
include_once(_DIR_EXT.'/HTML/c_page_JSON.php') ;
class c_page_ajax_json extends c_page_JSON
{
  function get_tree_content()
  { if ($_GET['id']=='#') $id=1 ;
    //else  list($level,$id)=explode('_',$_GET['id']) ;
    else  $id=(int)$_GET['id'] ;
  	$recs=execSQL('select pkey,obj_name,parent,level,(select count(t2.pkey) from obj_site_personals t2 where t2.parent=t1.pkey and t2.clss in (207,208)) as cnt from obj_site_personals t1 where clss in (207,208) and parent='.$id) ;
    $res=array() ;
    if (_sizeof($recs)) foreach($recs as $rec)
    {   $has_children=($rec['cnt'])? true:false ;
        //$type=($rec['parent']==1)? 'root':
	    //$perent_uid=($rec['parent']==1)? '#':($rec['level']-1).'_'.$rec['parent'] ;
	    $perent_uid=($rec['parent']==1)? '#':$rec['parent'] ;
	    $type=($rec['parent']==1)? '':'' ;
	    //$uid=$rec['level'].'_'.$rec['pkey'] ;
	    $uid=$rec['pkey'] ;
	    $res[]=array('id'=>$uid,'text'=>$rec['obj_name'],'parent'=>$perent_uid,'type'=>$type,'children'=>$has_children,'state'=>array('opened'=>false,'selected'=>false)) ;
    }
    return($res) ;
  	
  }
}
