<?php
class c_services_poll_get_themes_tikets
{
  function show()
  { if (!isset($_GET['id'])) $id=1 ; else  $id=(int)$_GET['id'] ;
	if (!$id) $id=1 ;
	$recs_themes=execSQL('select *,
				  		  (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) ;

  	$recs_qustions=execSQL('select *
				  		    from view_poll_questions 
				  		    where 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'],
			            'clss'=>$rec['clss'],
			            'has_children'=>($rec['cnt_subsections'] or $rec['cnt_questions'])? true:false
	                ) ;
    $i=1 ;
    if (_sizeof($recs_qustions)) foreach($recs_qustions as $rec)
    { $res[]=array('id'=>$rec['pkey'],'label'=>$i.'. '.$rec['obj_name'],'type'=>'item','clss'=>$rec['clss'],'parent'=>$rec['parent'],'has_children'=>false) ;
      $i++ ;
    }

    echo json_encode($res,JSON_UNESCAPED_UNICODE) ;

  }
}
