<?php
include_once('c_quiz_theme_card.php');
class c_page_cab_quiz_theme_card_sections extends c_page_cab_quiz_theme_card
{
    public $h1='Контроль знаний - карточка раздела - подразделы';
    public $title=' - подразделы';

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

    function panel_quiz_theme_sections()
    {
        $recs_subsections=[];
        $recs=execSQL('select t1.*,t2.pkey as event_id,t2.obj_name as event_name
                      from quiz_themes t1
                      left join obj_site_events_schedule t2 on t2.pkey=t1.event_id
                      where t1.parent='.$this->rec_section['pkey'].' and t1.clss in (1,472,481)');
        if (_sizeof($recs)) $recs_subsections=execSQL('select pkey,obj_name,parent,info_filter,clss from quiz_themes where parent in ('.implode(',',array_keys($recs)).') and clss in (472,1,481)') ;
        $recs_subsections_by_sections=group_by_field('parent',$recs_subsections) ;


        ?>
        <div id="panel_filter" class="full">
        <form id="sky-form" class="sky-form">
            <div id="panel_buttons">
                <button class="button v2" cmd="quiz/get_panel_section_create" theme_id="<? echo $this->rec_section['pkey'] ?>">Добавить подраздел</button>
                <?if (_sizeof($recs)){?>
                <button class="button v2" cmd="quiz/get_panel_section_move" theme_id="<? echo $this->rec_section['pkey'] ?>">Переместить подраздел</button>
                <button class="button v2" cmd="quiz/get_panel_section_delete" theme_id="<? echo $this->rec_section['pkey'] ?>">Удалить подраздел</button>
                <?}?>
            </div>

        <table class="basic fz_small full auto">
            <tr>
                <th style="width:100px;">Выбор</th>
                <!--<th style="width:100px;">ID</th>
                <th style="width:100px;">Число билетов</th>-->
                <th>Наименование подраздела</th>
                <th style="width:700px;">Мероприятие / Отбор сотрудников</th>
            </tr><?
            foreach($recs as $rec)
            {   ?>
                <tr>
                <td><input type="checkbox" name="_check[]" value="<? echo $rec['pkey'] ?>"></td>
                <!--<td><? echo $rec['pkey'] ?></td>
                <td><? echo $rec['cnt_tikets'] ?></td>-->
                <td class="left"><strong><a class="v1" href="/frame/quiz/theme/card/<?echo $rec['pkey']?>/"><? echo $rec['obj_name'] ?></a></strong></td>
                <td class="center"><? if ($rec['event_id'])    echo '<a href="/window/events_quiz/card/'.$rec['event_id'].'/" class="new_window" target="_blank" title="window_event">'.$rec['event_name'].'</a>' ;
                                    if ($rec['info_filter']) echo $rec['info_filter'] ?></td>
                </tr><?
                if (_sizeof($recs_subsections_by_sections[$rec['pkey']])) foreach($recs_subsections_by_sections[$rec['pkey']] as $rec_subsection)
                {   $icon='' ;
                    switch($rec_subsection['clss'])
                    { case 481: $icon='<i class="far fa-bookmark"></i>' ; break ;
                      case 472: $icon='<i class="fas fa-folder-open"></i>' ; break ;
                      case 1: $icon='<i class="fas fa-folder-open"></i>' ; break ;
                    }
                    ?>
                        <tr>
                        <td></td>
                        <!--<td><? echo $rec_subsection['pkey'] ?></td>
                        <td><? echo $rec_subsection['cnt_tikets'] ?></td>-->
                        <td class="left"><?echo $icon?><a style="color:gray;" class="v1" href="/frame/quiz/theme/card/<?echo $rec_subsection['pkey']?>/"><? echo $rec_subsection['obj_name'] ?></a></td>
                        <td class="left"><? echo $rec_subsection['info_filter'] ?></td>
                        </tr>
                    <?
                }
            }
            ?></table>
        </form></div>
        <?
    }

}

?>
