<?php
include_once("c_term.php");
class c_page_term_kz extends c_page_term
{
  public $h1='Терминал контроля знаний' ;



  function block_main()
  {   //$this->page_title() ;
      $this->panel_mt() ;
  }

  function panel_mt()
  {
      $this->rec_terminal=DEVICE()->get_terminal_by_id($this->terminal_id) ;
      $status=($this->rec_terminal['virt_status'])? ' [auto]':'' ;
      //damp_array($this->rec_terminal) ;

      $this->page_title('Эмулятор терминала КЗ № '.$this->terminal_id.$status) ;


      if ($this->rec_terminal)
      { $recs_term[]=$this->rec_terminal ;
        include_once(_DIR_EXT.'/esmo_setting/panel_terminals.php')  ;
        panel_terminals($recs_term,array('no_fast_search'=>1,'no_panel_actions'=>1,'no_panel_group'=>1,'term_page'=>'')) ;


          //update_rec_in_table('obj_site_account',array('status'=>2),'pkey='.$rec['pkey']) ;
         //if (!$this->rec_terminal['virt_status'])
         { ?>&nbsp;&nbsp;
             <br>

           <?
     $arr_accounts=ACCOUNTS()->get_list_members(array('rol'=>'2,3','no_filter_by_cur_group'=>1)) ;
     $arr_groups=ACCOUNTS()->get_arr_tree_workgroups() ;

     $this->form->filter['group_id']=$this->rec_terminal['parent'] ;
     $this->form->filter['doctor_id']=ESMO()->check_doctor($this->rec_terminal['parent']) ;
     $this->form->filter['profil_id']=$this->rec_terminal['profil'] ;

     ?><div id="panel_filter">
       <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="<?echo $this->url_report?>">
            <fieldset>
                <div class="row">
                    <? $this->filter_section_select('group_id',$GLOBALS['LS_person_group_title'].':',2,$arr_groups,array('nospace_element'=>1)) ;
                       $this->filter_section_input_text('propusk','Номер пропуска:',2,['cur_value'=>'id10656']) ;
                       $this->filter_section_input_text('cnt','Число проверок:',2,['cur_value'=>'10']) ;
                    ?>
                </div>
            </fieldset>
            <div id="panel_buttons" style="">
                <input type="submit" id=send_propusk class="button v2" cmd="aspmo_term/qz_send_check_access" terminal_id="<?echo $this->terminal_id?>" value="Отправить">
                 <? if (0 and $this->rec_terminal['virt_status']==0){?><button class="button v2" cmd="aspmo_term/start_auto" terminal_id=<?echo $this->terminal_id?>>Start Auto</button>&nbsp;&nbsp;<?}?>
                 <? if (0 and $this->rec_terminal['virt_status']==1){?><button class="button v2" cmd="aspmo_term/stop_auto" terminal_id=<?echo $this->terminal_id?>>Stop Auto</button>&nbsp;&nbsp;<?}?>
                 <? if (0 and $this->rec_terminal['virt_status']==2){?><button class="button v2" cmd="aspmo_term/stop_auto" terminal_id=<?echo $this->terminal_id?>>Stop Auto</button>&nbsp;&nbsp;<?}?>
            </div>
        </form>
    <?
    //echo 'virt_status='.$this->rec_terminal['virt_status'].'<br>' ;
           //  print_r($_SESSION['a123']) ;
    ?>
       </div>
             <div id="panel_message"></div>
           <?
         }

             $this->send_form('id10656') ;

      }

      if (!$this->rec_terminal['virt_status']) // если статус = 2 и не авто режим - обновлям каждые 1 мин
       { ?><script type="text/javascript">$j(document).ready(function()
         { //$j('body').everyTime(60000,'check_status',function(){send_ajax_request({cmd:'aspmo_term/check_status_and_update',terminal_id:<?echo $this->terminal_id?>})})
         }) ;
         </script><?
       }

      $this->panel_debug() ;
  }

    function send_form($propusk)
      {
           if ($propusk)
           { ?><script type="text/javascript">$j(document).ready(function()
               { $j('input[name="filter[propusk]"]').val('<?echo $propusk?>') ;
                 $j('input#send_propusk').trigger('click') ;
               }) ;
             </script><?
           }
           else // иначе просто перегружаем страницк
            { ?><script type="text/javascript">$j(document).ready(function()
               {
                   $j('body').oneTime(3000,'timer_reload',function(){location.reload()}) ;
               }) ;
             </script><?
             }
      }



}



?>