<?php
class c_services_events_poll_get_themes
{
  function show()
  { if (!isset($_GET['event_id'])) return ;
    $rec_event=EVENTS()->get_event_by_id($_GET['event_id']) ;
	$arr_themes_ids=$rec_event['_ext_info']['themes_ids'] ;

	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 poll_themes t2 where t2.parent=t1.pkey and t2.clss in (1,472)) as cnt_subsections
				  		  from poll_themes t1 
				  		  where clss in (1,472) and parent='.$id) ;

    $res=array() ;
    if (_sizeof($recs_themes)) foreach($recs_themes as $rec)
    {   $checked=(_sizeof($arr_themes_ids) and in_array($rec['pkey'],$arr_themes_ids))? 1:0 ;
    	$res[]=array('id'=>$rec['pkey'],'label'=>$rec['obj_name'],'type'=>'section','parent'=>$rec['parent'],'show_checkbox'=>1,'checked'=>$checked,'has_children'=>($rec['cnt_subsections'])? true:false) ;
    }

    echo json_encode($res) ;

  }
}
