<?php
include_once(_DIR_TO_CLASS.'/c_page.php') ;
include_once('i_daily_briefing_ui.php') ;

class c_page_cab_daily_briefing extends c_page
{
    public $h1='Рабочее место техника' ;
    public $allow_access_to_rol=9 ;

    function second_menu_config()
    {
        $this->second_menu=$this->menu['/cab/daily_briefing/']['items'] ;
    }

    function block_main()
    {
        if (MEMBER()->rol==9) {
            $recs=DAILY_BRIEFING()->get_briefings(array('briefing_type'=>'technician_instruction'));
            if (_sizeof($recs)==1) ENGINE()->redirect_301_to($recs[0]['__href']);
        }
        $this->page_title() ;
        if (MEMBER()->rol==1) $this->panel_create_briefing() ;
        $this->panel_briefing_list() ;
    }

    function panel_create_briefing()
    {
        ?>
        <div id="panel_filter">
            <form class="sky-form no_box_shadow">
                <fieldset>
                    <div class="row">
                        <section class="col col-12 center">
                            <label class="label">&nbsp;</label>
                            <button class="button v2" cmd="daily_briefing/show_create_briefing_modal" style="position:absolute;top:0;right:25px;">Создать инструктаж</button>
                        </section>
                    </div>
                </fieldset>
            </form>
        </div>
        <br>
        <?php
    }

    function panel_briefing_list()
    {
        $recs=DAILY_BRIEFING()->get_briefings(array('briefing_type'=>'technician_instruction'));
        ?>
        <table class="basic fz_small full auto">
            <tr>
                <th>ID</th>
                <th>Наименование</th>
                <th>Тип</th>
                <th>Создан</th>
                <th>Сегодня прошло</th>
                <th>Открыть</th>
            </tr>
            <?php if (_sizeof($recs)) {
                foreach($recs as $rec) {?>
                    <tr>
                        <td><?= (int)$rec['pkey'] ?></td>
                        <td class="left"><?= htmlspecialchars($rec['obj_name']) ?></td>
                        <td><?= htmlspecialchars($rec['_briefing_type_name']) ?></td>
                        <td><?= ($rec['c_data'])?date('d.m.Y H:i',$rec['c_data']):'' ?></td>
                        <td><strong><?= DAILY_BRIEFING()->get_today_completed_count($rec['pkey']) ?></strong></td>
                        <td><a href="<?= $rec['__href'] ?>">Карточка инструктажа</a></td>
                    </tr>
                <?php }
            } else {?>
                <tr><td colspan="6" class="center">Инструктажи пока не созданы</td></tr>
            <?php }?>
        </table>
        <?php
    }
}
?>
