<?php
include_once(_DIR_TO_CLASS.'/c_page.php');
class c_page_cab_poll_question_card extends c_page
{
    public $h1='Опрос - карточка темы';
    public $rec_question ;

    function __construct($options=array())
    {
        if (_CUR_ROOT_DIR_NAME=='frame') $this->body_class='no_menu';
        parent::__construct($options);
    }


    function select_obj_info()
     { if (_CUR_ID)
       { $this->rec_question=POLL()->get_question_by_id(_CUR_ID) ;
         if ($this->rec_question['pkey'])
         { //$this->h1=$this->rec_theme['obj_name'] ;
           $arr=TREE('view_poll_tree')->get_arr_parents_names($this->rec_question['pkey'],array('from_level'=>2)) ;
           //$arr[]='Билет № '.$this->rec_question['indx'] ;
           $this->h1=implode(' / ',$arr) ;
           $_SESSION['cur_obj_page_dir'][_CUR_ROOT_DIR_NAME][$this->rec_question['tkey']][$this->rec_question['clss']]=str_replace(_CUR_ID,'***',_CUR_PAGE_DIR) ;
           $this->rec_question['__href']='/'._CUR_ROOT_DIR_NAME.'/poll/question/card/'.$this->rec_question['pkey'].'/' ;
         }
         if (!$this->rec_question['pkey']) $this->result=404 ;
       } else $this->result=404 ;

     }


     function prepare_menu_config()
     {  $menu=[] ;
        $menu[$this->rec_question['__href']]='Билет' ;
        $menu[$this->rec_question['__href'].'orgs/']='Статистика по подразделениям' ;
        $menu[$this->rec_question['__href'].'stats/']='Прохождение опроса' ;
        $menu[$this->rec_question['__href'].'db/']='Исходные данные' ;
        return($menu) ;
     }

    function menu_config()
    {
       if (_CUR_ROOT_DIR_NAME=='window') $this->menu=$this->prepare_menu_config() ;
    }

    function second_menu_config()
    {
      if (_CUR_ROOT_DIR_NAME=='frame') $this->second_menu=$this->prepare_menu_config() ;
    }

    function panel_main_menu()
    {
        if (_CUR_ROOT_DIR_NAME!='frame') parent::panel_main_menu() ;
    }


    function block_main()
    {
        $this->page_title() ;
        if ($this->rec_question['answer_type']==1) $this->panel_poll_tiket_edit_by_ball() ;
        if ($this->rec_question['answer_type']==2) $this->panel_poll_tiket_by_questions() ;
    }

    function panel_poll_tiket_edit_by_ball()
    {
      $form=new i_form() ;
      $form->form_open();
      $form->fieldset_open();
      $form->row_open();
      $this->section_textarea(['type'=>'text','name'=>'question[obj_name]','value'=>htmlspecialchars($this->rec_question['obj_name']),'title'=>'Вопрос','placeholder'=>'Текст вопроса опроса..','col_count'=>'0','style'=>'height:200px;']) ;
      $form->row_close() ;
      $form->row_open();
      $form->section_select(['name'=>'question[answer_type]','title'=>'Варианты ответов','value'=>$this->rec_question['answer_type'],'recs'=>POLL()->answer_types,'nospace_element'=>1]) ;
      $form->row_close() ;
      $form->fieldset_close();
      $form->button('Сохранить','poll/tiket_save',['tiket_id'=>$this->rec_question['pkey']]);
      $form->button('Тест вопроса','poll/tiket_check',['tiket_id'=>$this->rec_question['pkey']]);
      $form->button('Удалить вопрос','poll/get_panel_tiket_delete',['tiket_id'=>$this->rec_question['pkey']]);
      $form->form_close() ;
    }

     function panel_poll_tiket_by_questions()
      { $recs_answers=POLL()->get_answers_by_question_id($this->rec_question['pkey']) ;
        $recs_contents=POLL()->get_contents_by_question_id($this->rec_question['pkey']) ;
        //$question_stats=POLL()->get_question_stats($this->rec_question['pkey']);
        ?>
        <div id="panel_filter"><form id="sky-form" class="sky-form">
               <div class="row">
                   <section class="col col-9">
                       <label>Вопрос:</label>
                       <label class="input"><input type="text" name="question[obj_name]" no_autocomplete value="<?echo htmlspecialchars($this->rec_question['obj_name'])?>"></label>
                   </section>
                   <section class="col col-2">
                       <label>Время для ответа (секунды):</label>
                       <label class="input"><input type="text" class="questionTimeout" name="question[timeout]" value="<?echo $this->rec_question['timeout']?>" data-mask="000"></label>
                   </section>
               </div>
               <br>
               <h3>Варианты ответов:</h3>
               <table class="basic fz_small full auto left" style="text-align:left;">
                    <tr><th style="width:5%;">№ ответа</th>
                        <th>Текст ответа</th>
                        <td rowspan="5" style="width:20%;"><?
      	                include(_DIR_EXT.'/upload_files/panel_upload_files.php')  ;
      	                panel_upload_files(array('text'=>'Перетяните и отпустите сюда<br>методические материалы по билету')) ;
      	              ?></th></tr>
                <?if (_sizeof($recs_answers)) foreach($recs_answers as $rec_answer){?>
                 <tr>
                     <td><label class="input"><input type="text" style="width:50px;" name="answer[<?echo $rec_answer['pkey']?>][indx]" no_autocomplete value="<?echo $rec_answer['indx']?>"></label></td>
                     <td>
                        <label class="textarea"><textarea name="answer[<?echo $rec_answer['pkey']?>][obj_name]" no_autocomplete><?echo htmlspecialchars($rec_answer['obj_name'])?></textarea></label>
                     </td>
                </tr>
                <?}?></table>
             <br>
             <h3>Картинка или видео к вопросу</h3><br>
             <? //print_2x_arr($recs_contents) ;
                if (_sizeof($recs_contents)) foreach($recs_contents as $rec_content)
                        { switch($rec_content['type'])
                          { case 'image/jpeg':
                            default:
                              ?><div class="content_item">
                                     <div class="action">
                                         <label class="checkbox">
                                            <input type="checkbox" name="contents[<?echo $rec_content['pkey']?>][delete]" value="1"><i></i> Удалить файл
                                         </label>
                                     </div><div class="clear"></div>
                                     <a href="<?echo $rec_content['dir'].$rec_content['file_name']?>"  onclick="return hs.expand(this)"><img src="<?echo $rec_content['dir'].$rec_content['file_name']?>" width=300 border="0"></a><br>
                                     <!--<div class="info">Размер: <?echo show_size($rec_content['size'])?></div>-->
                                 </div><? break ;
                          }
                        }
             ?><div class="clear"></div>

             <div id="panel_buttons">
                  <input type="submit" class="button v2" cmd="poll/tiket_save" tiket_id="<?echo $this->rec_question['pkey']?>" value="Сохранить измемения" validate="form">
                  <input type="submit" class="button v2" cmd="poll/tiket_append_question" tiket_id="<?echo $this->rec_question['pkey']?>" value="Добавить ответ" validate="form">
                  <input type="submit" class="button v2" cmd="poll/tiket_check" tiket_id="<?echo $this->rec_question['pkey']?>" value="Тест вопроса" validate="form">
             </div>
             </form>
             </div>
             <?
      }



}

?>
