<?php
include_once('c_quiz_theme_card.php');

class c_page_cab_quiz_theme_card_new_knowledge extends c_page_cab_quiz_theme_card
{
    public $h1='Контроль знаний - карточка раздела - добавление нового знания';
    public $title=' - добавление нового знания';

    function prepare_menu_config()
    {
        $menu=parent::prepare_menu_config() ;
        $menu[_CUR_PAGE_DIR]='Новое знание' ;
        return($menu) ;

    }

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

    function panel_quiz_tiket_create()
    {  ?><br><?
       $form=new i_form() ;
       $form->form_open(array('class'=>'form-horizontal','col_count'=>6,'col_count_title'=>1)) ;
       $form->section_input(['name'=>'name','title'=>'Наименование знания','comment'=>'Например, пункт 1.1.','_placeholder'=>'Пишите текст']) ;
       $form->section_textarea(['name'=>'manual','title'=>'Текст знания','comment'=>'Укажите содержание вашего знания','_placeholder'=>'Пишите текст','style'=>'height:200px']) ;

    	?><h3>Вопросы знания:</h3><div class="green">Вы сможете добавить новые вопросы в знание после его создания</div><?
          if ($this->filter['questions_ids'])
          { $arr_questions_ids=explode(';',$this->filter['questions_ids']) ;
            $this->panel_quiz_tickets($arr_questions_ids) ;
          }
          ?>
          <br>
          <h3>Обучение знанию:</h3>
        <?
        $form->section_input(['name'=>'proc_offset','col_count'=>2,'title'=>'Процент правильных ответов для получения зачета по знанию','comment'=>'Укажите пороговое значение процента правильных ответов на вопросы знания, после которого сотрудник получит зачет','_placeholder'=>'Пишите текст']) ;

        ?><h3>Поясняющие материалы по знанию:</h3><?
        //$this->panel_append_content() ;


        $form->button('Добавить знание','quiz/known_create',['section_id'=>$this->rec_section['pkey'],'go_url'=>'']) ;


        $form->form_close();

    }

    function panel_quiz_tickets($arr_questions_ids)
     {
       $recs=execSQL('select * from quiz_questions where pkey in ('.implode(',',$arr_questions_ids).') order by indx') ;
       if (_sizeof($recs)) $recs_answers=execSQL('select * from quiz_answers where question_id in ('.implode(',',array_keys($recs)).')') ;
       if (_sizeof($recs)) $recs_contents=execSQL('select * from quiz_content where question_id in ('.implode(',',array_keys($recs)).')') ;
       $recs_answers_by_question=group_by_field('question_id',$recs_answers) ;
       $recs_contents_by_question=group_by_field('question_id',$recs_contents) ;
       ?><div id="panel_filter" class="full"><form id="sky-form" class="sky-form">
         <input type="hidden" name="section_id" value="<?echo $this->rec_section['pkey']?>">
       <table class="basic fz_small full auto">
         <tr>
             <th style="width:70px;">ID</th>
             <th style="width:30%;">Вопрос</th>
             <th style="width:auto;">Ответы</th>
             <th style="width:200px;">Фото/Видео</th>
         </tr><?
           $i=1 ;
       foreach($recs as $rec)
       {   ?><tr>
               <td><?echo $rec['pkey']?></td>
               <td class="left"><a class="v1" href="/frame/quiz/question/card/<?echo $rec['pkey']?>/"><?echo $rec['obj_name']?></a></td>
               <td class="left"><ul><? if (_sizeof($recs_answers_by_question[$rec['pkey']])) foreach($recs_answers_by_question[$rec['pkey']] as $rec_answer) {?><li class="<?echo ($rec_answer['status']==1)? 'green':''?>"><?echo $rec_answer['obj_name']?></li><?}?></ul></td>
               <td><? if (_sizeof($recs_contents_by_question[$rec['pkey']])) foreach($recs_contents_by_question[$rec['pkey']] as $rec_content)
               { switch($rec_content['type'])
                 { case 'image/jpeg': ?><img src="<?echo $rec_content['dir'].$rec_content['file_name']?>" width="150px"><? break ;

                 }
                 //print_r($rec_content) ; echo '<br>' ;
                }
                ?></td>
           </tr><?
       }
           ?></table></form></div><?
     }


    function panel_append_content()
    { ?><div style="margin:10px 0;text-align:center;width:400px;">
        <div style="margin:10px 0;text-align:center;width:400px;">
            <button class="select_media_content" desc="media_text">Текст</button>
            <button class="select_media_content" desc="media_photo">Фото</button>
            <button class="select_media_content" desc="media_video">Видео</button>
        </div>
      <form>
      <? include(_DIR_EXT.'/upload_files/panel_upload_files.php')  ;?>
      <div id="panels_content">
          <div id="media_text" class="panel_content" style="font-size:18px;text-align:center;">
              <textarea style="width:400px;height:150px;font-size:18px;text-align:center;" name="event_text"><?/*echo htmlspecialchars($this->rec_event['_ext_info']['message1'])*/?></textarea>
              <button class="v2" cmd="events_media/append_event_text" event_id="<?echo $this->rec_event['pkey']?>">Добавить текст</button>
          </div>
          <div id="media_photo" class="panel_content hidden">
              <? panel_upload_files(array('text'=>'Перетяните и отпустите сюда<br>изображение',
                                         'upload_url'=>'/services/events_media/upload_file/',
                                         'upload_params'=>array('event_id'=>$this->rec_event['pkey']),
                                         'file_filter'=>'jpg;',
                                         'SendFormOnUploadSuccess'=>0,
                                         'view_debug_panel'=>0,
                                         'style_panel'=>'width:400px;margin:20px auto;',
                                         'onUploadSuccessFunction'=>'onUploadSuccessFunction',
                        )) ;
              ?>
          </div>
          <div id="media_video" class="panel_content hidden">
              <?  panel_upload_files(array('text'=>'Перетяните и отпустите сюда<br>видео',
                                           'upload_url'=>'/services/events_media/upload_file/',
                                           'upload_params'=>array('event_id'=>$this->rec_event['pkey']),
                                            'file_filter'=>'mkv;avi;3gp;mp4;mpeg;',
                                            'SendFormOnUploadSuccess'=>0,
                                            'view_debug_panel'=>0,
                                            'style_panel'=>'width:400px;margin:20px auto;;',
                                            'onUploadSuccessFunction'=>'onUploadSuccessFunction',
                                      )) ;
          ?></div>

      </div><div class="clear"></div>
      </form>
    </div>
      <style type="text/css">
        div#panels_content{position:relative;width:500px;margin:0 auto;}
        div#panels_content div#media_text textarea{padding:10px;margin-bottom:10px;}
        div#panels_content div#panel_file_upload{float:left;}
        div#panels_content div#report{float:left;}
        div#panels_content div#debug{float:left;clear:none;}
      </style>
      <script type="text/javascript">
       $j(document).ready(function()
       {
          //$j('body').on('button.select_media_content','click',function()
          $j('button.select_media_content').on('click',function()
          {
            var desc=$j(this).attr('desc') ;
            console.log(desc) ;
            $j('div#panels_content .panel_content').hide() ;
            $j('div#panels_content #'+desc+'.panel_content').show() ;

          })

        }) ;

       function  onUploadSuccessFunction(data)
       {
          console.log('===============') ;
          if (data.PanelReportHTML!=null) $j('div#panel_report').html(data.PanelReportHTML) ;
       }

      </script>
      <?
      //damp_array($this->rec_event) ;
    }




}

?>
