<?php

class c_services_personal_get_structure
{
    function show()
    {
        if(!isset($_GET['id'])) $id=1;
        else  $id=(int)$_GET['id'];
        if(!$id) $id=1;
        $cur_level=execSQL_value('select level from obj_site_personals where pkey='.$id) ;
        $cur_level++ ;
        $recs_themes=execSQL('select pkey,obj_name,parent,level,
                            (select count(t2.pkey) from obj_site_personals t2 where t2.parent'.$cur_level.'=t1.pkey and t2.clss in (1,207,208)) as cnt_subsections 
                            from obj_site_personals t1 
                            where clss in (1,207,208) and parent='.$id);

        $res=array();
        if(_sizeof($recs_themes)) foreach($recs_themes as $rec)
        {
            $res[]=array('id'=>$rec['pkey'],
                         'label'=>$rec['obj_name'],
                         'type'=>($rec['clss']==207)? 'org':'otdel',
                         'parent'=>$rec['parent'],
                         'has_children'=>($rec['cnt_subsections'])? true:false,
                         //'show_checkbox'=>true,
                         //'checkbox_cmd'=>'quiz/save_theme_orgs'
            );
        }

        echo json_encode($res);
    }
}
