<?
function panel_terminals($recs,$options=array('term_page'=>'new_window'))
{  ob_start() ;  $text_tr='' ;
    if (!$options['no_fast_search']) {?><div id="panel_fast_search">Быстрый поиск по ID: <input type="text" id="fast_search_terminal_id"> </div><?}?>
     <table class="basic fz_small full auto" id="list_terminals">
        <tr><th>ID</th><th>Тип</th><th>Наименование</th><th>IP</th>
            <?if ($options['show_serial']){?><th>Модель</th><th>Серийный номер</th><?}?>
            <th>Версия ПО</th><th>Состояние</th><th>Доп.инф</th><th>Видео</th><th>Тонометр</th><th>Термометр</th><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">
                <a href="<?echo $rec['__href']?>" class="new_window"><?echo addslashes($rec['obj_name'])?></a><br>
                Профиль: <strong><?echo $rec['_profil_name']?></strong><?
                if (!$options['no_panel_actions'] and !$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>
            <?if ($options['show_serial']){?>
                <td><? echo $rec['_devices']['terminal']['model']?></td>
                <td><? echo $rec['_devices']['terminal']['serial_number']?></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['_profil']['video']) echo ($rec['video'])? '<i class="fa fa-check-circle green"></i>':'<i class="fa fa-exclamation-circle red"></i>'?></td>
            <td class="status"><?if ($rec['_profil']['tonometer']) echo ($rec['tonometer'])? '<i class="fa fa-check-circle green"></i>':'<i class="fa fa-exclamation-circle red"></i>'?></td>
            <td class="status"><?if ($rec['_profil']['thermometer']) echo ($rec['thermometer'])? '<i class="fa fa-check-circle green"></i>':'<i class="fa fa-exclamation-circle red"></i>'?></td>
            <td class="status"><?if ($rec['_profil']['alcotester']) echo ($rec['alcotester'])? '<i class="fa fa-check-circle green"></i>':'<i class="fa fa-exclamation-circle red"></i>'?></td>
            <td class="status"><?if ($rec['_profil']['pupilometer']) echo ($rec['pupilometer'])? '<i class="fa fa-check-circle green"></i>':'<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>
   <script type="text/javascript">
     $j('#fast_search_terminal_id').keyup(
         function(e)
         {   var term_id=$j(this).val() ;
             if (term_id!="")
             { $j('#list_terminals tr.term_tr').hide() ;
               $j('#list_terminals tr#term_'+term_id).show() ;
             } else $j('#list_terminals tr.term_tr').show() ;

         }) ;
   </script>
   <?
    $text=ob_get_clean() ;
    if (!$options['only_tr_terminal']) echo $text ;
    else echo $text_tr ;
    //damp_array($recs) ;

 }

 function panel_terminal_actions($terminal_id)
 {
     ?><div class="panel_actions">
            <i class="fa fa-bell v2" title="Проверить статус" cmd="esmo_setting/exec_terminal_cmd" terminal_action="check_status" terminal_id="<?echo $terminal_id?>"></i>
            <i class="fa fa-pause-circle v2" title="Перевод в спящий режим" cmd="esmo_setting/exec_terminal_cmd" terminal_action="sleep" terminal_id="<?echo $terminal_id?>"></i>
            <i class="fa fa-repeat v2" title="Перезагрузка" cmd="esmo_setting/exec_terminal_cmd" terminal_action="reboot" terminal_id="<?echo $terminal_id?>"></i>
            <i class="fa fa-power-off v2" title="Выключение" cmd="esmo_setting/exec_terminal_cmd" terminal_action="poweroff" terminal_id="<?echo $terminal_id?>"></i>
            <i class="fa fa-exclamation-triangle v2" title="Перевод в режим неисправности" cmd="esmo_setting/exec_terminal_cmd" terminal_action="fault" terminal_id="<?echo $terminal_id?>"></i>
      </div>
     <?
 }
?>
