<?php
class c_services_poll_get_themes
{
  function show()
  { if (!isset($_GET['id'])) $id=1 ; else  $id=(int)$_GET['id'] ;
	if (!$id) $id=1 ;
	$recs_themes=execSQL('select pkey,obj_name,parent,level,
				  		  (select count(t2.pkey) from view_poll_themes t2 where t2.parent=t1.pkey and t2.clss in (1,572)) as cnt_subsections, 
				  		  (select count(t2.pkey) from view_poll_questions t2 where t2.parent=t1.pkey) as cnt_questions 
				  		  from poll_themes t1 
				  		  where clss in (1,572) 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['parent']==1)? 'theme':'section',
		            'parent'=>$rec['parent'],
		            'has_children'=>($rec['cnt_subsections'] or $rec['cnt_questions'])? true:false
                  ) ;
    }

    echo json_encode($res,JSON_UNESCAPED_UNICODE) ;

  }
}
