<?php
include_once(_DIR_TO_CLASS.'/c_page.php');
class c_page_cab_quiz_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=QUIZ()->get_question_by_id(_CUR_ID) ;
         if ($this->rec_question['pkey'])
         { //$this->h1=$this->rec_theme['obj_name'] ;
           $arr=TREE('quiz_themes')->get_arr_parents_names($this->rec_question['parent'],array('from_level'=>2)) ;
           $arr[]='Билет № '.$this->rec_question['indx'] ;
           $this->h1=implode(' / ',$arr) ;
         }
         if (!$this->rec_question['pkey']) $this->result=404 ;
       } else $this->result=404 ;

     }


     function prepare_menu_config()
     {  $menu=[] ;
        $menu['/'._CUR_ROOT_DIR_NAME.'/quiz/question/card/'.$this->rec_question['pkey'].'/']='Билет' ;
        $menu['/'._CUR_ROOT_DIR_NAME.'/quiz/question/card/'.$this->rec_question['pkey'].'/stats/']='Статистика' ;
        $menu['/'._CUR_ROOT_DIR_NAME.'/quiz/question/card/'.$this->rec_question['pkey'].'/sessions/']='Результаты КЗ' ;
        $menu['/'._CUR_ROOT_DIR_NAME.'/quiz/question/card/'.$this->rec_question['pkey'].'/db/']='Исходные данные' ;
//        $menu['/'._CUR_ROOT_DIR_NAME.'/quiz/question/card/'.$this->rec_question['pkey'].'/learned/']='Усваиваемость' ;
        return($menu) ;
     }

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

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

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



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

    function get_question_iamge_css($proc)
    {
        $result=[];
        if ($proc==100) {
            $result=['x'=>0,'y'=>0];
        } else {
            $cel = floor($proc / 10);
            $drob = $proc-$cel*10;
            $result['y'] = $cel * -1 * 62;
            $result['x']= - 62 - 62 * $drob;
        }
        return $result;
    }

    function panel_quiz_tiket_edit()
    { $recs_answers=QUIZ()->get_answers_by_question_id($this->rec_question['pkey']) ;
      $recs_contents=QUIZ()->get_contents_by_question_id($this->rec_question['pkey']) ;
      $question_stats=QUIZ()->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']?>"></label>
                 </section>
                 <section class="col col-1">
                      <?
                      if (_sizeof($question_stats)) {
                          $knowledge_css=$this->get_question_iamge_css($question_stats['knowledge']['proc']);
                          $learned_css=$this->get_question_iamge_css($question_stats['learned']['proc']);
                          ?>
<!--                          <label>Усваиваемость</label>-->
                          <div class="question_stat">
                              <div class="question_stat_image knowledge" title="Уровень знаний: <?=$question_stats['knowledge']['proc']?>%"></div>
                              <div class="question_stat_image learned" title="Усваиваемость: <?=$question_stats['learned']['proc']?>%"></div>
                          </div>
                          <style>
                              div.question_stat {
                                  display: flex;
                              }
                              div.question_stat_image {
                                  width: 58px;
                                  height: 58px;
                                  background: url("/<?=_CLASS_?>/images/percent.png");
                              }
                              div.question_stat_image.knowledge {
                                  background-position: <?=$knowledge_css['x']?>px <?=$knowledge_css['y']?>px;
                              }
                              div.question_stat_image.learned {
                                  background-position: <?=$learned_css['x']?>px <?=$learned_css['y']?>px;
                              }
                          </style>
                          <?
                      }
                      ?>
                 </section>
             </div>
             <br>
             <h3>Варианты ответов:</h3>
             <table class="basic fz_small full auto left" style="text-align:left;">
                  <tr><th style="width:5%;">№ ответа</th>
                      <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 style="width:5%;"><label class="checkbox">
                           <input type="hidden" name="answer[<?echo $rec_answer['pkey']?>][status]" value="0">
                           <input type="checkbox" name="answer[<?echo $rec_answer['pkey']?>][status]" value="1" <?if ($rec_answer['status']) echo 'checked'?>><i></i> Да
                       </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="quiz/tiket_save" tiket_id="<?echo $this->rec_question['pkey']?>" value="Сохранить измемения" validate="form">
                <input type="submit" class="button v2" cmd="quiz/tiket_append_question" tiket_id="<?echo $this->rec_question['pkey']?>" value="Добавить ответ" validate="form">
                <input type="submit" class="button v2" cmd="quiz/tiket_check" tiket_id="<?echo $this->rec_question['pkey']?>" value="Тест вопроса" validate="form">
           </div>
           </form>
           </div>
           <script type="text/javascript">
               $j(document).ready(function() {
                   $j('input.questionTimeout').mask('000');
               }) ;
           </script>
           <?
           //print_2x_arr($recs_answers) ;
    }



}

?>
