<?php
    function panel_terminals($recs,$options = array('term_page'=>'new_window'))
    {
        ob_start() ;  $text_tr='' ;?>
        <table class="basic fz_small full auto" id="list_terminals">
            <tr>
                <th rowspan="2">ID</th>
                <th rowspan="2">Тип</th>
                <th rowspan="2" width="200">Наименование</th>
                <th rowspan="2">IP</th>
                <th rowspan="2">Версия ПО</th>
                <th rowspan="2">Состояние</th>
                <th rowspan="2">Доп.инф</th>
                <th colspan="2">Исправность оборудования</th>
            </tr>
            <tr>
                <th>Видео</th>
                <th>Алкотестер</th>
            </tr><?
            $last_group=0 ;
            if (_sizeof($recs)) foreach ($recs as $rec) {
                if ($last_group!=$rec['parent'] and !$options['no_panel_group'])
                { ?><tr><td colspan="12" style="font-size:18px;font-weight:bold;color:#0057aa;text-align:left;"><?echo $rec['_group_name']?></td></tr><?
                    $last_group=$rec['parent'] ;
                }
                ob_start();
                ?>
                <tr class="term_tr" id="term_<?echo $rec['pkey'] ?>">
                    <td><?echo $rec['id'] ?></td>
                    <td class="center"><?echo $rec['terminal_type'] ?></td>
                    <td class="left">
                        <?echo addslashes($rec['obj_name']) ?><br><?
                        if (!$rec['virt']) panel_terminal_actions($rec['pkey']);
                        if ($rec['virt']) {?><br><a href="<?echo $rec['__href_virt'] ?>" class="new_window">Открыть эмулятор</a><?} ?>
                    </td>
                    <td class="center"><?echo $rec['ip'] ?></td>
                    <td><? echo $rec['vers'] ?></td>
                    <td><? echo $_SESSION['ARR_terminal_status_color'][$rec['status']];
                        $ext_info = unserialize($rec['ext_info']);
                        if ($ext_info['alcotester_calibration']) echo '<br><span style="background:#cf4b25;color:white;padding:4px;margin:0 0;">Требуется калиборока алкотестера</span>'; ?>
                    </td>
                    <td><? if ($rec['ext_info']) damp_array($ext_info, 1, -1) ?></td>
                    <td class="status"><?if ($rec['video']) echo '<i class="fa fa-check-circle green"></i>'; else echo '<i class="fa fa-exclamation-circle red"></i>' ?></td>
                    <td class="status"><?if ($rec['alcotester']) echo '<i class="fa fa-check-circle green"></i>'; else echo '<i class="fa fa-exclamation-circle red"></i>' ?></td>
                </tr>
                <? $text_tr = ob_get_clean();
                if (!$options['only_tr_terminal']) echo $text_tr;
            } ?>
        </table>
        <style type="text/css">
            td.status {font-size: 20px;}
            div.panel_actions {font-size: 16px;margin: 10px 0;}
            div.panel_actions i {padding-right: 20px;color: #aaaaaa;cursor: pointer;}
            div.panel_actions i:hover {color: green;}
        </style><?
        $text = ob_get_clean();
        if (!$options['only_tr_terminal']) echo $text;
        else echo $text_tr;
    }

    function panel_terminal_actions($terminal_id)
    {?>
        <div class="panel_actions">
            <i class="fa fa-bell v2" title="Проверить статус" cmd="kt/exec_terminal_cmd" terminal_action="check_status" terminal_id="<?echo $terminal_id ?>"></i>
            <i class="fa fa-pause-circle v2" title="Перевод в спящий режим" cmd="kt/exec_terminal_cmd" terminal_action="set_sleep" terminal_id="<?echo $terminal_id ?>"></i>
            <i class="fa fa-repeat v2" title="Перезагрузка" cmd="kt/exec_terminal_cmd" terminal_action="reboot" terminal_id="<?echo $terminal_id ?>"></i>
        </div><?
    }
?>
