<?php
include_once("c_events_quiz_card.php");

class c_page_cab_events_quiz_card_edit_step1 extends c_page_cab_events_quiz_card
{
    public $h1='Редактирование параметров мероприятия по контролю знаний';
    var $after_save_url;

    function select_obj_info()
    {
        parent::select_obj_info();
        if($this->rec_event['pkey'])
        {
            $this->h1=$this->obj_event->name.' "'.$this->rec_event['obj_name'].'" - параметры мероприятия';
            if($this->rec_event['enabled']) $this->after_save_url=$this->rec_event['__href'].'edit/step1/';
            else                             $this->after_save_url=$this->rec_event['__href'].'edit/step2/';
        }
    }

    function second_menu_config()
    {
        if($this->rec_event['pkey'])
        {
            $this->second_menu['/window/events_quiz/card/'.$this->rec_event['pkey'].'/edit/step1/']='Параметры контроля';
            if($this->rec_event['_ext_info']['local_usl_select']) $this->second_menu['/window/events_quiz/card/'.$this->rec_event['pkey'].'/edit/step2/']='Выбор участников';
            if($this->rec_event['_ext_info']['local_themes']) $this->second_menu['/window/events_quiz/card/'.$this->rec_event['pkey'].'/edit/step3/']='Выбор тем КЗ';
        }
    }

    function block_main()
    {
        $this->page_title();
        $this->panel_params_edit();
    }

    function panel_params_edit()
    {   ?>
        <table class="col2x">
            <tr>
                <td style="width:600px"><? $this->panel_params_edit_left() ?></td>
                <td><? ?></td>
            </tr>
        </table>
        <style type="text/css">
            table.col2x
            {}

            table.col2x td
            {vertical-align: top;}
        </style>
        <?
    }

    function panel_params_edit_left()
    {
        $arr_groups=execSQL('select pkey,parent,obj_name from obj_site_account where clss in (1,206) order by parent,obj_name');
        $arr_groups2=$arr_groups;
        convert_list_to_tree($arr_groups2,$arr_tree);
        $this->convert_tree_to_select_options_arr($arr_tree,$arr_groups,$options_list);

        $form=new i_form(['post_array_name'=>'data']);
        $form->form_open();
        $form->row_open();
        if(!$this->rec_event['date_from']) $this->rec_event['date_from']=time();
        if(!$this->rec_event['date_to']) $this->rec_event['date_to']=time();
        ?><input type="hidden" name="data[dyn_pass]" value="1"><?
        $form->label('Активность:',4);
        ?><section class="col col-8">
        <label class="radio"><input type="radio" name="data[enabled]" value="1" <? if($this->rec_event['enabled']) echo 'checked' ?>><i></i> Включено</label>
        <label class="radio"><input type="radio" name="data[enabled]" value="0" <? if(!$this->rec_event['enabled']) echo 'checked' ?>><i></i> Выключено
        </label>
        </section>
        <?$form->label('Собственный выбор сотрудников:',4);?>
        <section class="col col-8">
        <label class="radio"><input type="radio" name="data[local_usl_select]" value="1" <? if($this->rec_event['_ext_info']['local_usl_select']) echo 'checked' ?>><i></i> Включено</label>
        <label class="radio"><input type="radio" name="data[local_usl_select]" value="2" <? if(!$this->rec_event['_ext_info']['local_usl_select']) echo 'checked' ?>><i></i> Выключено
        </label>
        </section>
        <?$form->label('Собственный список тем КP:',4);?>
        <section class="col col-8">
        <label class="radio"><input type="radio" name="data[local_themes]" value="1" <? if($this->rec_event['_ext_info']['local_themes']) echo 'checked' ?>><i></i> Включено</label>
        <label class="radio"><input type="radio" name="data[local_themes]" value="2" <? if(!$this->rec_event['_ext_info']['local_themes']) echo 'checked' ?>><i></i> Выключено
        </label>
        </section>
        <?

        $form->label('Наименование мероприятия:',4);
        $form->filter_section_input_text('name','',8,array('value'=>$this->rec_event['obj_name']));
        $form->label('Периодичность прохождения:',4);
        $form->filter_section_select('close_period','',8,QUIZ()->arr_events_close_period,array('cur_value'=>$this->rec_event['_ext_info']['close_period'],'nospace_element'=>1));
        $form->label('Условия прохождения:',4);
        $form->filter_section_select('close_status','',8,QUIZ()->arr_events_close_status,array('cur_value'=>$this->rec_event['_ext_info']['close_status'],'nospace_element'=>1));
        $form->label('Срок проведения:',4);
        $form->filter_section_input_text('date_from','',4,array('class'=>'datepicker','value'=>date('d.m.Y',$this->rec_event['date_from'])));
        $form->filter_section_input_text('date_to','',4,array('class'=>'datepicker','value'=>date('d.m.Y',$this->rec_event['date_to'])));
        $form->label('Метод доведения контента:',4);
        $form->filter_section_select('method','',8,QUIZ()->arr_kz_method,array('cur_value'=>$this->rec_event['_ext_info']['method'],'nospace_element'=>1));
        $form->label('Место доведения контента:',4);
        $form->filter_section_select_multiple('group_ids','',8,$options_list,array('cur_values'=>$this->rec_event['_ext_info']['group_ids'],'nospace_element'=>1));
        $form->label('Дни показа контента:',4);
        $form->filter_section_select('allow_days','',8,$this->obj_event->arr_allow_days,array('cur_value'=>$this->rec_event['_ext_info']['allow_days'],'nospace_element'=>1));
        $form->label('Число вопросов в одной сессии КЗ:',4);
        if (!$this->rec_event['_ext_info']['question_count']) $this->rec_event['_ext_info']['question_count']=2 ;
        $form->filter_section_input_text('question_count','',8,array('cur_value'=>$this->rec_event['_ext_info']['question_count']));
        $form->label('Архив:',4);
        ?>
        <section class="col col-4">
        <input type="hidden" name="data[arhive]" value="0">
        <label class="checkbox"><input type="checkbox" name="data[arhive]" value="1" <? if($this->rec_event['status']==5) echo 'checked' ?>><i></i> В архиве</label>
        </section><?

        $form->row_close();
        $form->panel_button_apply(array('cmd_method'=>'v1','cmd'=>'save_event'));
        /*?><input type="hidden" name="data[enabled]" value="1"><?*/
        $form->form_close();
        //damp_array($form) ;
        //damp_array($this->rec_event) ;
    }

    //  удаляем  ID родительской темы из списка, если есть потомок

    function CMD_save_event()
    {  //damp_array($_POST);
        if(_sizeof($_POST['filter']['themes_ids'])) $_POST['filter']['themes_ids']=array_keys($_POST['filter']['themes_ids']);
        EVENTS()->save_events($this->rec_event['pkey'],$_POST['data']);
        //if (!$this->rec_event['enabled']) redirect_301_to($this->rec_event['__href'].'edit/step2/') ;
        //else
        $this->select_obj_info();
        //$this->rec_event=EVENTS()->get_event_by_id($this->rec_event['pkey']) ;
    }
}

?>
