<?
// вниамение!!!
// во всех фильтрах:
// data_from, data_to - дата в текстовом формате
// time_from, time_to - дата в UNIX формате

class report_quiz_themes extends c_report
{
    var $title='Темы контроля знаний';
    public $view_by_space_filter=1;
    public $personal_id=0;
    public $event_id=0;

    function init($options=array())
    {
        //if (!$this->filter['group_id']) $this->filter['group_id']=MEMBER()->cur_group_id ;
    }

    function setting()
    {
        ?>
        <div id="panel_filter">
            <form id="sky-form" class="sky-form">
                <input type="hidden" name="filter_dir" value="<? echo $this->url_report ?>">
                <fieldset>
                    <div class="row">
                        <div id="panel_buttons">
                                <button class="button v2" cmd="quiz/get_panel_theme_create">Добавить тему</button>
                                <button class="button v2" cmd="quiz/get_panel_theme_import">Импортировать тему</button>
                                <button class="button v2" cmd="quiz/get_panel_theme_export" use_form="form_themes">Экспортировать тему</button>
                                <!--<button class="button v2" cmd="quiz/get_panel_theme_delete">Удалить тему</button>-->
                                </div>
                    </div>

                </fieldset>
            </form>
        </div>
        <?
    }

    function panel_info_filter()
    {
        $_str=array();
        $info=array();
        $title='';     //damp_array($this->filter,1,-1) ;
        if($this->filter['name']) $info['Наименование']='"'.$this->filter['name'].'"';

        if(_sizeof($info)) foreach($info as $title=>$value) if(is_array($value)) $_str[]=$title.': <strong>'.implode(', ',$value).'</strong>';
        else $_str[]=$title.': <strong>'.$value.'</strong>';
        if(_sizeof($_str)) $title='<p class="center">'.implode(' ',$_str).'</p>';
        return $title;
    }

    function create_usl_select_obj($_params,&$options)
    { //damp_array($this->filter,1,-1);
        $_usl=[];
        $_usl[]='t1.parent=1';
        if($this->filter['name']) $_usl[]='obj_name like "%'.$this->filter['name'].'%"';

        //damp_array($_usl,1,-1);
        $usl_res=(_sizeof($_usl))? implode(' and ',$_usl):1;
        return ($usl_res);
    }

    function get_cnt_items($usl,$options=array())
    {
        $options['debug']=0;
        $this->cnt_items=execSQL_value('select count(pkey) from quiz_themes t1 where '.$usl,$options);
        return ($this->cnt_items);
    }

    function get_items($usl,$options=array())
    {
        $limit=($options['limit'])? ' '.$options['limit']:'';
        $order=' order by c_data desc';
        $options['debug']=0;
        $recs=execSQL('select t1.*,t2.obj_name as event_name,(select count(t3.pkey) from quiz_themes t3 where t3.parent2=t1.pkey) as cnt_sections 
                       from quiz_themes t1
                       left join obj_site_events_schedule t2 on t2.pkey=t1.event_id
                       where '.$usl.$order.$limit,$options);
        //if (_sizeof($recs) and !$options['no_public_info']) foreach($recs as $id=>$rec) QUIZ()->prepare_public_info_to_kz($recs[$id],$options) ;
        return ($recs);
    }

    // шаблон - вывод ссылками без разделитея
    function print_template_HTML($list_recs,$options=array())
    {
        ?><form id="form_themes">
        <table class="basic fz_small full auto">
        <tr class="head">
            <th>Выбор</th>
            <th>ID</th>
            <th>Наименование</th>
            <th>Дата создания</th>
            <th>Число разделов/подразделов</th>
            <th>Число вопросов</th>
            <th>Мероприятие КЗ</th>
        </tr><?

        //damp_array($quiz_results);
        if(_sizeof($list_recs)) foreach($list_recs as $rec)
        { ?>
            <tr>
            <td><input type="checkbox" name="_check[]" value="<? echo $rec['pkey'] ?>"></td>
            <td><? echo $rec['pkey'] ?></td>
            <td class="left"><a href="/window/quiz/theme/card/<? echo $rec['pkey'] ?>/" class="new_window" target="_blank" title="window_quiz_theme"><? echo $rec['obj_name'] ?></a></td>
            <td><? echo date('d.m.Y H:i',$rec['c_data']) ?></td>
            <td><?echo ($rec['cnt_sections'])? $rec['cnt_sections']:'-' ?></td>
            <td><? ?></td>
            <td class="left">
                <a href="/window/events_quiz/card/<? echo $rec['event_id'] ?>/" class="new_window" target="_blank" title="window_event"><? echo $rec['event_name'] ?></a>
            </td>
            </tr><?
        }
        ?></table></form><?
    }
}

?>
