<?php
include_once(_DIR_EXT."/aspmo_setting/c_setting_members.php");
class c_page_cab_esmo_setting_terminal_updates extends c_page_cab_setting_members
{
  public $h1='Медицинские терминалы' ;

 function block_main()
 { global $member ;
   $this->page_title() ;
   if (isset($member->cur_group_id))
   {
     $recs=ESMO()->get_list_terminals($member->cur_group_id);
     if (_sizeof($recs)) {
         $firmware = ESMO()->get_available_terminal_firmware();
         $this->panel_terminal_edit($recs, $firmware) ;
     }
     else {
         echo '<div class=alert>В данной рабочей группе терминалы отстутсвуют. Воспользуйтесь конфигуратором системы для добавления терминалов в группу.</div>' ;
     }
   }
   //damp_array($_SERVER) ;
 }

function panel_terminal_edit(&$recs, &$firmware)
{  global $member ;
   ?><div id="panel_terminal_edit"><form><input type="hidden" name="group_id" value="<?echo $member->cur_group_id?>">
    <h2>Операции:</h2>
         <select name="terminal_id" style="width:300px;" data-select><option></option>
             <? if (_sizeof($recs)) foreach($recs as $rec) {?><option value="<?echo $rec['id']?>"><?echo $rec['obj_name']?> [<?echo $rec['id']?>]</option><?}?>
         </select>
         <select name="terminal_action" data-select><option></option>
                                                    <option value="check_status">Проверить статус 1</option>
                                                    <option value="sleep">Переход в спящий режим</option>
                                                    <option value="fault">Переход в режим неисправности</option>
                                                    <option value="reboot">Перезагрузка</option>
                                                    <option value="poweroff">Выключение</option>
         </select>
         <button class="v2" cmd="esmo_setting/exec_terminal_cmd">Выполнить</button>
         <?/* $vt=0 ;
            if (_sizeof($recs)) foreach($recs as $rec) if ($rec['virt']) $vt++ ;
            if ($vt) {?><br><br><strong>Все виртуальные терминалы:</strong> <button class="v2" cmd="aspmo_term/vt_terminal_init">INIT</button> <button class="v2" cmd="aspmo_term/vt_terminal_start">START</button> <button class="v2" cmd="aspmo_term/vt_terminal_stop">STOP</button><?}
           */
         ?>
      <h2>Список терминалов:</h2>
      <table class="basic fz_small">
          <tr><th rowspan="2">ID</th><th rowspan="2">Наименование</th><th rowspan="2">IP</th><th rowspan="2">Текущая версия</th><th rowspan="2">Обновить до</th><th rowspan="2">Состояние</th><th rowspan="2">Доп.инф</th><th rowspan="2">video</th><th colspan="2">tonometer</th><th colspan="2">thermometer</th><th colspan="2">alcotester</th><th colspan="2">pupilometer</th><th rowspan="2"></th></tr>
        <tr><th>T</th><th>P</th><th>T</th><th>P</th><th>T</th><th>P</th><th>T</th><th>P</th></tr>
     <?  if (_sizeof($recs)) foreach($recs as $rec)

     {?><tr><td><input class="id" type=text name=term[<?echo $rec['pkey']?>][id] value="<?echo addslashes($rec['id'])?>"></td>
            <td><input class="name" type=text name=term[<?echo $rec['pkey']?>][obj_name] value="<?echo addslashes($rec['obj_name'])?>"></td>
            <td style="white-space: nowrap"><input type=text name=term[<?echo $rec['pkey']?>][ip] value="<?echo addslashes($rec['ip'])?>" style="width: 110px"> :<?echo _TERMINAL_PORT?></td>
            <td><?= $rec['firmware_current_version'] ? $rec['firmware_current_version'] : 'uncknown' ?></td>
            <td>
                <select name="term[<?echo $rec['pkey']?>][firmvare_update_to_version]" style="width:100px; height: 25px" data-select>
                    <option></option>
                    <? if (_sizeof($firmware)) foreach($firmware as $firmware_rec) {?>
                        <? if ($rec['firmware_current_version'] != $firmware_rec['version']) { ?>
                            <option value="<?echo $firmware_rec['version']?>" <?= $firmware_rec['version'] == $rec['firmware_update_to_version'] && $rec['firmware_current_version'] != $rec['firmware_update_to_version'] ? 'selected' : '' ?>><?echo $firmware_rec['version']?></option>
                        <? } ?>
                    <?}?>
                </select>
            </td>
            <td class="status"><? echo $_SESSION['ARR_terminal_status_color'][$rec['status']]?></td>
            <td class="status"><? if ($rec['ext_info']) damp_array(unserialize($rec['ext_info']),1,-1)?></td>
            <td class="status"><img src="/images/status_<? echo $rec['video']?>.png"></td>
            <td class="status"><img src="/images/status_<? echo $rec['tonometer']?>.png"></td>
            <td class="status"><img src="/images/status_<? echo $rec['_profil']['tonometer']?>.png"></td>
            <td class="status"><img src="/images/status_<? echo $rec['thermometer']?>.png"></td>
            <td class="status"><img src="/images/status_<? echo $rec['_profil']['thermometer']?>.png"></td>
            <td class="status"><img src="/images/status_<? echo $rec['alcotester']?>.png"></td>
            <td class="status"><img src="/images/status_<? echo $rec['_profil']['alcotester']?>.png"></td>
            <td class="status"><img src="/images/status_<? echo $rec['pupilometer']?>.png"></td>
            <td class="status"><img src="/images/status_<? echo $rec['_profil']['pupilometer']?>.png"></td>
            <td class="left">Профиль: <strong><?echo $rec['_profil_name']?></strong></td>
         </tr>
     <?}?>
   </table><br>
   <input type="submit" class="v2" cmd="esmo_setting/terminal_save" value="Сохранить">
   </form></div><?
    //damp_array($recs) ;

 }

}



?>
