<?php
include_once("c_setting.php");
class c_page_cab_setting_devices extends c_page_cab_setting
{
    public $h1='Устройства' ;

    var $type_device = [
        'pp' => 'Пост печати'
    ];

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

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

    function panel_device_create() {
        $arr_groups=execSQL('select pkey,parent,obj_name from obj_site_account where clss in (1,206) order by parent,obj_name') ;
        $arr_groups2=$arr_groups ;
        convert_list_to_tree($arr_groups2,$arr_tree) ;
        $this->convert_tree_to_select_options_arr($arr_tree,$arr_groups,$options_list) ;
        ?><div id="panel_filter">
        <form id="sky-form" class="sky-form">
            <input type="hidden" name="filter_dir" value="<?echo _CUR_REPORT_DIR?>">
            <fieldset>
                <div class="row">
                    <section class="col col-2">
                        <label class="label"><?echo $GLOBALS['LS_person_group_title'].':'?></label>
                        <label class="select">
                            <select class="filter" name="device_parent">
                                <?if (_sizeof($options_list)) foreach($options_list as $id=>$value) {?><option value="<?echo $id?>"><?echo $value?></option><?}?>
                            </select>
                        </label>
                    </section>
                    <section class="col col-2">
                        <label class="label">Тип устройства:</label>
                        <label class="select">
                            <select class="filter" name="device_type">
                                <?foreach ($this->type_device as $key=>$value) {?><option value="<?echo $key?>"><?echo $value?></option><?}?>
                            </select>
                        </label>
                    </section>
                    <section class="col col-2">
                        <label class="label">Название устройства:</label>
                        <label class="input"><input type="text" data-required name="device_name" value=""></label>
                    </section>
                    <section class="col col-2">
                        <label class="label">ID устройства:</label>
                        <label class="input"><input type="text" data-required name="device_id" value=""></label>
                    </section>
                    <section class="col col-2">
                        <label class="label">IP адрес:</label>
                        <label class="input"><input type="text" data-required name="device_ip" value=""></label>
                    </section>
                </div>
            </fieldset>
            <div id="panel_buttons"><input type="submit" class="button v2" cmd="aspmo_setting/device_create" value="Добавить устройство"  validate="form"></div><br>
        </form>
        </div>
        <br>
        <?
    }

    function panel_device_list() {
        $recs=DEVICE()->get_list_terminals(0,'pp') ;

        ?><table class="basic fz_small auto">
        <tr>
            <th rowspan="2">ID</th>
            <th rowspan="2">Группа</th>
            <th rowspan="2">Тип</th>
            <th rowspan="2">Наименование</th>
            <th rowspan="2">IP</th>
            <th rowspan="2">Версия ПО</th>
            <th rowspan="2">Состояние</th>
            <th colspan="2">Исправность оборудования</th>
            <th rowspan="2"></th>
        </tr>
        <tr>
            <th>Видео</th>
            <th>Принтер</th>
        </tr>
        <?  if (_sizeof($recs)) foreach($recs as $rec) {?>
            <tr><td><?echo $rec['id']?></td>
                <td class="left"><?echo $rec['_group_name']?></td>
                <td class="left"><?echo $rec['terminal_type']?></td>
                <td class="left"><?echo addslashes($rec['obj_name'])?></td>
                <td class="left"><?echo $rec['ip']?></td>
                <td class="center"><?echo $rec['vers']?></td>
                <td class="status"><? echo $_SESSION['ARR_terminal_status_color'][$rec['status']]?></td>
                <td class="status"><img src="/images/status_<? echo $rec['video']?>.png"></td>
                <td class="status"><img src="/images/status_<? echo $rec['printer']?>.png"></td>
                <td><button class="v2" device_id="<?echo $rec['pkey']?>" device_type="<?echo $rec['terminal_type']?>" cmd="aspmo_setting/device_reboot">Перезагрузить</button></td>
            </tr>
        <?}?>
        </table>
        <?
    }

}



?>
