<?php
include_once('c_poll_theme_card.php');
class c_page_cab_poll_theme_card_questions extends c_page_cab_poll_theme_card
{
    public $h1='Опрос - карточка темы - разделы темы';

    function block_main()
    {
        $this->panel_poll_rasdel_tickets($this->rec_section) ;
    }

    function panel_poll_rasdel_tickets($rec)
     {
       $arr=TREE('view_poll_tree')->get_arr_parents_names($rec['parent'],array('from_level'=>2)) ;
       echo '<h1>'.implode(' / ',$arr).'</h1>'  ;
       //$this->h1.=' / Вопрос № '.$this->rec_question['indx'] ;

       $recs=execSQL('select * from view_poll_questions where parent='.$rec['pkey']) ;
       $recs_answers=[] ; $recs_contents=[] ;
       if (_sizeof($recs)) $recs_answers=execSQL('select * from poll_answers where question_id in ('.implode(',',array_keys($recs)).')') ;
       if (_sizeof($recs)) $recs_contents=execSQL('select * from poll_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">
           <div id="panel_buttons">
                <button class="button v1" href="<? echo $rec['__href'] ?>new_question/">Добавить вопрос</button>
                <?if (_sizeof($recs)){?>
                <button class="button v2" cmd="poll/get_panel_tiket_move" tree_parent_id="<?echo $rec['pkey']?>">Переместить вопрос</button>
                <button class="button v2" cmd="poll/get_panel_tiket_delete" tree_parent_id="<?echo $rec['pkey']?>">Удалить вопрос</button>
                <button class="button v2" cmd="poll/tiket_check" section_id="<?echo $rec['pkey']?>">Тест раздела</button>
              <?}?>
           </div>
         <input type="hidden" name="section_id" value="<?echo $rec['pkey']?>">
       <table class="basic fz_small full auto">
         <tr>
             <th style="width:70px;">ID</th>
             <th style="width:70px;">Выбор</th>
             <th style="width:70px;">№ вопроса</th>
             <th style="width:30%;">Вопрос</th>
             <th style="width:auto;">Ответы</th>
             <th style="width:200px;">Фото/Видео</th>
             <th style="width:200px;">Операции</th>
         </tr><?
           $i=1 ;
       foreach($recs as $rec)
       {   ?><tr>
               <td><?echo $rec['pkey']?></td>
               <td><input type="checkbox" name="_check[]" value="<?echo $rec['pkey']?>"></td>
               <td><?echo $i ; $i++?></td>
               <td class="left"><a class="v1" href="/frame/poll/question/card/<?echo $rec['pkey']?>/"><?echo $rec['obj_name']?></a></td>
               <td class="left">
                   <?
                        switch($rec['answer_type'])
                        { case 1: echo 'Баллы от 1 до 5' ; break ;
                          case 2: ?><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><?
                   switch($rec['answer_type'])
                   { case 1: ; break ;
                     case 2:
                                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 ;
                 }
                                }
                }
                ?></td>
                 <td>
                     <input type="submit" class="v2 center" cmd="poll/tiket_check" tiket_id="<?echo $rec['pkey']?>" value="Тест вопроса" validate="form">
                 </td>
           </tr><?
       }
           ?></table></form></div><?
     }


}

?>
