<?
// вниамение!!!
// во всех фильтрах:
// data_from, data_to - дата в текстовом формате
// time_from, time_to - дата в UNIX формате

class report_kt_monitor extends c_report
{
 var $title='Монитор контроля трезвости' ;
 var $view_only_model=1 ;
 var $mo_sort='pkey' ;
 public $view_by_space_filter=0 ;
    public $use_datepicker=1 ;

 function init($options=array())
 {
    //if (!$this->filter['group_id']) $this->filter['group_id']=MEMBER()->cur_group_id ;
 }


function setting()
{ //if (isset($this->filter['time_from'])) $this->filter['data_from']=date('d.m.Y',$this->filter['time_from']);
  //if (isset($this->filter['time_to'])) $this->filter['data_to']=date('d.m.Y',$this->filter['time_to']);
  if (isset($this->filter['personal_id'])) $this->filter['name']=PERSONAL()->get_name_by_id($this->filter['personal_id']);

  $arr_accounts=ACCOUNTS()->get_list_members(array('group_id'=>MEMBER()->cur_group_id,'rol'=>'2,3')) ;
  $arr_groups=ACCOUNTS()->get_arr_groups_to_cur_account() ;
  list($arr_orgs_ids,$arr_otdel_ids,$arr_works_ids)=PERSONAL()->get_org_otdels_works_to_cur_account($this->filter) ;
  $arr_terminals=DEVICE()->get_list_terminals(MEMBER()->cur_group_id,'kt') ;

  ?><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">
                    <? $this->filter_section_select('group_id',$GLOBALS['LS_person_group_title'].':',2,$arr_groups) ;
                       $this->filter_section_select_multiple('org_ids','Организация:',2,$arr_orgs_ids) ;
                       $this->filter_section_select_multiple('otdel_ids','Подразделение:',2,$arr_otdel_ids) ;
                       $this->filter_section_input_text('name','ФИО:',2,array('auto_complete'=>"autocomplette_personal_name")) ;
                    ?>
                </div>
                <div class="row">
                    <? if (MEMBER()->rol!=2) $this->filter_section_select('doctor_id','Оператор:',2,$arr_accounts,array('space_element'=>1)) ;
                       $this->filter_section_input_text('data_from','От:',2,array('class'=>'datetimepicker')) ;
                       $this->filter_section_input_text('data_to','До:',2,array('class'=>'datetimepicker')) ;
                       $this->filter_section_select('tk','Тип контроля:',2,KT()->ARR_kt_tk_type,array('use_id_plus_1'=>1)) ;
                       $this->filter_section_select('terminal_id','Терминал:',2,$arr_terminals,array('key_fname'=>'id')) ;
                    ?>
                </div>
                <div class="row">
                    <section class="col col-2">
                        <label class="label">Результат КТ:</label>
                        <label class="radio"><input type="radio" name="filter[status]" value="0" <?if (!$this->filter['status']) echo 'checked'?>><i></i>Не важно</label>
                        <? if (_sizeof(KT()->ARR_status_sess)) foreach(KT()->ARR_status_sess as $id=>$value)  if ($id>0)
                           {?><label class="radio"><input type="radio" name="filter[status]" value="<?echo $id?>" <?if ($this->filter['status']==$id) echo 'checked'?>><i></i><?echo $value?></label><?}
                        ?>
                    </section>
                    <section class="col col-2">
                        <label class="label">Допуск:</label>
                        <label class="radio">
                        <?
                        if (_sizeof(KT()->ARR_status_dopusk)) foreach(KT()->ARR_status_dopusk as $id=>$value)
                           {?><label class="radio"><input type="checkbox" name="filter[dopusk][]" value="<?echo $id?>" <?if (($this->filter['dopusk'][$id])) echo 'checked'?>><i></i><?echo $value?></label><?}
                        ?>
                    </section>
                    <section class="col col-2">
                        <label class="label">Показывать:</label>
                        <label class="radio"><input type="checkbox" name="filter[equipmentFailure]" value="1" <?if ($this->filter['equipmentFailure']) echo 'checked'?>><i></i>Отказ оборудования</label>
                        <label class="radio"><input type="checkbox" name="filter[equipmentError]" value="1" <?if ($this->filter['equipmentError']) echo 'checked'?>><i></i>Отказ в КТ</label>
                    </section>
                </div>
            </fieldset>
            <?$this->panel_buttons();?>
        </form>
     </div>
  <?
}
 function setting_old()
 {
     $arr_groups=ACCOUNTS()->get_arr_groups_to_cur_account() ;
     list($arr_orgs_ids,$arr_otdel_ids,$arr_works_ids)=PERSONAL()->get_org_otdels_works_to_cur_account($this->filter) ;
     $arr_terminals=DEVICE()->get_list_terminals(MEMBER()->cur_group_id,'kt') ;

     ?><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) ;
                       $this->filter_section_select_multiple('org_ids','Организация:',2,$arr_orgs_ids) ;
                       $this->filter_section_select_multiple('otdel_ids','Подразделение:',2,$arr_otdel_ids) ;
                       $this->filter_section_input_text('name','ФИО:',4,array('auto_complete'=>"autocomplette_personal_name")) ;
                    ?>
                </div>
                <div class="row">
                    <? $this->filter_section_input_text('id_mo','ID МО:',2) ;
                       $this->filter_section_select('terminal_id','Терминал:',2,$arr_terminals,array('key_fname'=>'id')) ;
                       $this->filter_section_select('tk','Тип контроля:',2,$_SESSION['ARR_mo_tk_type'],array('use_id_plus_1'=>1)) ;
                       $this->filter_section_input_text('data_from','От:',2,array('class'=>'datetimepicker')) ;
                       $this->filter_section_input_text('data_to','До:',2,array('class'=>'datetimepicker')) ;
                    ?>
                </div>
                <div class="row">
                    <section class="col col-2">
                        <label class="label">Результат МО:</label>
                        <label class="radio"><input type="radio" name="filter[status]" value="0" <?if (!$this->filter['status']) echo 'checked'?>><i></i>Не важно</label>
                        <? if (_sizeof($_SESSION['ARR_status_sess'])) foreach($_SESSION['ARR_status_sess'] as $id=>$value)  if ($id>0)
                           {?><label class="radio"><input type="radio" name="filter[status]" value="<?echo $id?>" <?if ($this->filter['status']==$id) echo 'checked'?>><i></i><?echo $value?></label><?}
                        ?>
                    </section>
                    <section class="col col-2">
                        <label class="label">Допуск к смене:</label>
                        <label class="radio">
                        <? if (_sizeof($_SESSION['ARR_status_dopusk'])) foreach($_SESSION['ARR_status_dopusk'] as $id=>$value)
                           {   ?><label class="radio"><input type="checkbox" name="filter[dopusk][]" value="<?echo $id?>" <?if (($this->filter['dopusk'][$id])) echo 'checked'?>><i></i><?echo $value?></label><?
                           }
                        ?>
                    </section>
                    <section class="col col-2">
                        <label class="label">Причина отказа:</label>
                        <label class="radio"><input type="checkbox" name="filter[a]" value="1" <?if ($this->filter['a']) echo 'checked'?>><i></i>Алкоголь</label>
                        <label class="radio"><input type="checkbox" name="filter[d]" value="1" <?if ($this->filter['d']) echo 'checked'?>><i></i>Давление</label>
                        <label class="radio"><input type="checkbox" name="filter[p]" value="1" <?if ($this->filter['p']) echo 'checked'?>><i></i>Пульс</label>
                        <label class="radio"><input type="checkbox" name="filter[n]" value="1" <?if ($this->filter['n']) echo 'checked'?>><i></i>ПП</label>
                        <label class="radio"><input type="checkbox" name="filter[q]" value="1" <?if ($this->filter['q']) echo 'checked'?>><i></i>Жалобы</label>
                        <label class="radio"><input type="checkbox" name="filter[v]" value="1" <?if ($this->filter['v']) echo 'checked'?>><i></i>ТКТ</label>
                    </section>
                    <section class="col col-2">
                        <label class="label">Модель МО:</label>
                        <? $arr=[1,3,5,7,9] ;
                           foreach($arr as $model_id)
                           {?><label class="radio"><input type="checkbox" name="filter[model][]" value="<?echo $model_id?>" <?if ($this->filter['model'][$model_id]) echo 'checked'?>><i></i><?echo $_SESSION['ARR_model_osmotr'][$model_id]?></label><?}
                        ?>
                    </section>
                    <section class="col col-2">
                        <label class="label">&nbsp;</label>
                        <? $arr=[2,4,6,8,10] ;
                           foreach($arr as $model_id)
                           {?><label class="radio"><input type="checkbox" name="filter[model][]" value="<?echo $model_id?>" <?if ($this->filter['model'][$model_id]) echo 'checked'?>><i></i><?echo $_SESSION['ARR_model_osmotr'][$model_id]?></label><?}
                        ?>
                    </section>
                    <section class="col col-2">
                        <label class="label">Показывать:</label>
                        <label class="radio"><input type="checkbox" name="filter[equipmentFailure]" value="1" <?if ($this->filter['equipmentFailure']) echo 'checked'?>><i></i>Отказ оборудования</label>
                        <label class="radio"><input type="checkbox" name="filter[equipmentError]" value="1" <?if ($this->filter['equipmentError']) echo 'checked'?>><i></i>Отказ в МО</label>
                        <label class="radio"><input type="checkbox" name="filter[skoro]" value="1" <?if ($this->filter['skoro']) echo 'checked'?>><i></i>Ожидается на проверку</label>
                        <label class="radio"><input type="checkbox" name="filter[cur_smena]" value="1" <?if ($this->filter['cur_smena']) echo 'checked'?>><i></i>Текущая смена</label>
                    </section>
                </div>
            </fieldset>
            <?$this->panel_button_apply();?>
        </form>
     </div>
  <?
}

 function setting_small()
 {?><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">
                    <section class="col col-3">
                        <label class="label">ФИО:</label>
                        <label class="input"><input type="text" name="filter[name]" value="<?echo $this->filter['name']?>" id="personal_name" SetAutoComplete cmd="autocomplette_personal_name"></label>
                    </section>
                    <section class="col col-3">
                        <label class="label">Пропуск:</label>
                        <label class="input"><input type="text" name="filter[propusk]" LANG="LAT" value="<?echo $this->filter['propusk']?>"></label>
                    </section>
                    <section class="col col-4">
                        <label class="label">Подразделениe:</label>
                        <label class="select">
                             <select name="filter[dep_id]"><option value="0">Все</option>
                               <? echo PERSONAL()->get_select_option(1,$this->filter['dep_id']) ;?>
                            </select>
                        </label>
                    </section>
                    <section class="col col-2">
                        <label class="label">Тип контроля:</label>
                        <label class="select">
                            <select name="filter[tk]"><option value="0">Все</option><?
                              if (_sizeof($_SESSION['ARR_mo_tk_type'])) foreach($_SESSION['ARR_mo_tk_type'] as $id=>$name) {?><option value="<?echo $id+1?>" <?if($this->filter['tk']==($id+1)) echo 'selected'?>><?echo $name?></option><?}?>
                            </select>
                        </label>
                    </section>

                </div>
                <div class="row">
                    <section class="col col-2">
                        <label class="label">Допуск к смене:</label>
                        <label class="radio">
                        <? if (_sizeof($_SESSION['ARR_status_dopusk'])) foreach($_SESSION['ARR_status_dopusk'] as $id=>$value)
                           {?><label class="radio"><input type="checkbox" name="filter[dopusk][]" value="<?echo $id?>" <?if (($this->filter['dopusk'][$id])) echo 'checked'?>><i></i><?echo $value?></label><?}
                        ?>
                    </section>
                    <section class="col col-2">
                        <label class="label">Причина отказа:</label>
                        <label class="radio"><input type="checkbox" name="filter[a]" value="1" <?if ($this->filter['a']) echo 'checked'?>><i></i>Алкоголь</label>
                        <label class="radio"><input type="checkbox" name="filter[d]" value="1" <?if ($this->filter['d']) echo 'checked'?>><i></i>Давление</label>
                    </section>
                    <section class="col col-2">
                        <label class="label">&nbsp;</label>
                        <label class="radio"><input type="checkbox" name="filter[p]" value="1" <?if ($this->filter['p']) echo 'checked'?>><i></i>Пульс</label>
                        <!--<label class="radio"><input type="checkbox" name="filter[n]" value="1" <?if ($this->filter['n']) echo 'checked'?>><i></i>ПП</label>-->
                        <label class="radio"><input type="checkbox" name="filter[q]" value="1" <?if ($this->filter['q']) echo 'checked'?>><i></i>Жалобы</label>
                        <label class="radio"><input type="checkbox" name="filter[v]" value="1" <?if ($this->filter['v']) echo 'checked'?>><i></i>ТКТ</label>
                    </section>
                    <section class="col col-2">
                        <label class="label">Показывать:</label>
                        <label class="radio"><input type="checkbox" name="filter[skoro]" value="1" <?if ($this->filter['skoro']) echo 'checked'?>><i></i>Ожидается на проверку</label>
                        <label class="radio"><input type="checkbox" name="filter[cur_smena]" value="1" <?if ($this->filter['cur_smena']) echo 'checked'?>><i></i>Текущая смена</label>
                    </section>
                </div>
            </fieldset>
            <?$this->panel_button_apply();?>
        </form>
     </div>
  <?
}

 function panel_info_filter()
 { $_str=array() ; $info=array() ; $title='' ;     //damp_array($this->filter,1,-1) ;

   // начало смены или авторизация пользователя
   $now=getdate(time()) ;
   // для администратора - последние 24 часа
   if ($this->filter['skoro']) $this->filter['cur_smena']=1 ;
   if ($this->filter['cur_smena'])
   { if (MEMBER()->info['rol']==1) $info['Режим']='Администратор, все ТК  за последние 24 часа (c '.date('d.m.Y H:i',mktime($now['hours']-24,$now['minutes'],0,$now['mon'],$now['mday'],$now['year'])).')' ;
     // для остальных - с начала смены
     elseif (MEMBER()->info['smena_in']) $info['Режим']='Дежурный фельдшер, МО с начала смены (c '.date('d.m.Y H:i',MEMBER()->info['smena_in']).')<br>' ;
     // если смена не начала - с момента авторизации
     else  $info['Режим']='Фельдшер, МО  с момента авторизации (c '.date('d.m.Y H:i',MEMBER()->login_time).')' ;
   }
   if ($this->filter['skoro'])                           $info['Ожидаются на проверку']='Да' ;

   if ($this->filter['data_from'])                       $info['c']=$this->filter['data_from'] ;
   if ($this->filter['data_to'])                         $info['по']=$this->filter['data_to'] ;
   if ($this->filter['time_from'])                       $info['c']=date('d.m.Y H:i',$this->filter['time_from']) ;
   if ($this->filter['time_to'])                         $info['по']=date('d.m.Y H:i',$this->filter['time_to']) ;
   if ($this->filter['group_id'])                        $info[$GLOBALS['LS_person_group_title'].':']=ACCOUNTS()->get_member_name_by_id($this->filter['group_id'])  ;
   if ($this->filter['org_id'])                          $info['Организация']=PERSONAL()->get_name_by_id($this->filter['org_id'])  ;
   if ($this->filter['otdel_id'])                        $info['Подразделение']=PERSONAL()->get_name_by_id($this->filter['otdel_id'])  ;
   if ($this->filter['org_ids'])                         $info['Организация']=PERSONAL()->get_org_names_by_ids(array_keys($this->filter['org_ids']))  ;
   if ($this->filter['otdel_ids'])                       $info['Подразделение']=PERSONAL()->get_org_names_by_ids(array_keys($this->filter['otdel_ids']))  ;
   if ($this->filter['dep_id'])                          $info['Подразделение']=PERSONAL()->get_full_dep_name_by_dep_id($this->filter['dep_id'])  ;
   if ($this->filter['tk'])                              $info['Тип контроля']=$_SESSION['ARR_mo_tk_type'][$this->filter['tk']-1]  ;

   if ($this->filter['name'])                            $info['ФИО']='"'.$this->filter['name'].'"' ;
   if ($this->filter['propusk'])                         $info['Пропуск']='"'.$this->filter['propusk'].'"' ;
   if ($this->filter['id_mo'])                           $info['ID MO']='"'.$this->filter['id_mo'].'"' ;
   if ($this->filter['doctor_id'])                       $info['Фельдшер']=ACCOUNTS()->get_member_name_by_id($this->filter['doctor_id'])  ;
   if ($this->filter['terminal_id'])                     $info['Терминал']=$this->filter['terminal_id']  ;
   if ($this->filter['tk'])                              $info['Тип контроля']=$_SESSION['ARR_mo_tk_type'][$this->filter['tk']-1]  ;
   if ($this->filter['status'])                          $info['Осмотр на терминале']=$_SESSION['ARR_status_sess'][$this->filter['status']]  ;
   if (is_array($this->filter['dopusk']))  { if(_sizeof($this->filter['dopusk']))  foreach($this->filter['dopusk'] as $dopusk_id=>$value) $info['Допуск'][]=$_SESSION['ARR_status_dopusk'][$dopusk_id]  ;}
   else if ($this->filter['dopusk'])                     $info['Допуск']=$_SESSION['ARR_status_dopusk'][$this->filter['dopusk']]  ;
   if ($this->filter['uklon'])                           $info['Уклонился']='Да'  ;
   if ($this->filter['a'])                               $info['Причина отказа'][]='Алкоголь'  ;
   if ($this->filter['d'])                               $info['Причина отказа'][]='Давление'  ;
   if ($this->filter['p'])                               $info['Причина отказа'][]='Пульс'  ;
   if ($this->filter['q'])                               $info['Причина отказа'][]='Жалобы'  ;
   if ($this->filter['n'])                               $info['Причина отказа'][]='ПП'  ;
   if ($this->filter['v'])                               $info['Причина отказа'][]='ТКТ'  ;
   if ($this->filter['other'])                           $info['Причина отказа'][]='Другое'  ;  // все кроме алкоголя
   if ($this->filter['ef'])                              $info['Ошибка оборудования']='Да'  ;
   if ($this->filter['equipmentFailure'])                $info['Ошибка оборудования']='Да'  ;
   if ($this->filter['equipmentError'])                  $info['Ошибка измерения']='Да'  ;
   if ($this->filter['equipment'])                       $info['Устройство'][]=$this->filter['equipment']  ;

   if (_sizeof($this->filter['model']))                   foreach($this->filter['model'] as $model_id=>$value) $info['Модель МО'][]=$_SESSION['ARR_model_osmotr'][$model_id]  ;
   if ($this->filter['mo_ids'])                          { $info['ID MO']=implode(',',array_keys($this->filter['mo_ids'])) ; unset($info['Модель МО']) ; }
   if (_sizeof($info)) foreach($info as $title=>$value)   if (is_array($value)) $_str[]=$title.': <strong>'.implode(', ',$value).'</strong>' ; else $_str[]=$title.': <strong>'.$value.'</strong>' ;
   if (_sizeof($_str)) $title='<p class=center>'.implode(' ',$_str).'</p>' ;
   return $title ;

 }

 function create_usl_select_obj($_params,&$options)
 { $usl=array() ; $usl2=array() ;   //damp_array($this->filter) ;
   if ($this->filter['only_denited']) $usl2[]='dopusk=2' ;
   if ($this->filter['only_calibration']) $usl2[]='reason="alcotester_calibration"' ;
   if (_sizeof($usl2)) $usl[]='('.implode(' or ',$usl2).')';
   if ($this->filter['group_id'])   $usl[]='group_id in ('.MEMBER()->cur_groups_visible.')' ;
   if ($this->filter['terminal_id'])   $usl[]='terminal_id='.$this->filter['terminal_id'].'' ;
   if ($this->filter['personal_id'])   $usl[]='personal_id='.$this->filter['personal_id'].'' ;
     if ($this->filter['exlude_tk'])   $usl[]='pkey!='.$this->filter['exlude_tk'].'' ;
     if ($this->filter['status']) {
         if (is_array($this->filter['status'])) {
             $usl[]='status in ('.implode(',',array_keys($this->filter['status'])).')' ;
         } else {
             $usl[]='status in ('.$this->filter['status'].')' ;
         }
     }
     $usl2=[];
     if ($this->filter['equipmentFailure']) $usl2[]='reason="equipmentFailure"' ;
     if ($this->filter['equipmentError']) $usl2[]='reason="equipmentError"' ;
     if (_sizeof($usl2)) $usl[]='('.implode(' or ',$usl2).')';
     if ($this->filter['name'])
     {   $arr_ids=execSQL_line('select pkey from obj_site_personals where clss=211 and obj_name like "%'.addslashes($this->filter['name']).'%"') ;
         if (_sizeof($arr_ids))  $usl[]='member_id in ('.implode(',',$arr_ids).')' ;
         else                   $usl[]='member_id=-1' ;
     }

     if ($this->filter['org_ids'])          $usl[]='personal_parent2 in ('.implode(',',array_keys($this->filter['org_ids'])).')' ;
     if ($this->filter['otdel_ids'])        $usl[]='(personal_parent3 in ('.implode(',',array_keys($this->filter['otdel_ids'])).') or 
                                                     personal_parent4 in ('.implode(',',array_keys($this->filter['otdel_ids'])).') or
                                                      personal_parent5 in ('.implode(',',array_keys($this->filter['otdel_ids'])).')
                                                     )' ;
     if ($this->filter['dopusk'])   $usl[]='dopusk in ('.implode(',',array_keys($this->filter['dopusk'])).')' ;

     if ($this->filter['doctor_id'])   $usl[]='doctor_id='.$this->filter['doctor_id'] ;
     if ($this->filter['data_from'])   $usl[]='c_data>='.strtotime($this->filter['data_from']) ;
     if ($this->filter['data_to'])     $usl[]='c_data<='.strtotime($this->filter['data_to']) ;
     if ($this->filter['tk'])          $usl[]='tk='.(int)($this->filter['tk']-1) ;

     $usl[]='personal_id in (select pkey from '.MEMBER()->personal_viewer_name.')' ;

     $usl_res=(_sizeof($usl))? implode(' and ',$usl):1 ;
     //damp_array($usl,1,-1) ;
     return($usl_res) ;
 }

  function get_cnt_items($usl,$options=array())
  { //$options['debug']=2 ;
    $this->cnt_items=execSQL_value('select count(pkey) from '.KT()->view_mo_session.' where '.$usl,$options) ;
    return($this->cnt_items) ;
  }

  function get_items($usl,$options=array())
  { $limit=($options['limit'])? ' '.$options['limit']:'' ;
    //$order=($options['order'])? ' order by '.$options['order']:' order by '.$this->mo_sort ;
    $order=($this->filter['skoro'])? ' order by pkey ':' order by pkey desc' ; //.$this->mo_sort ;
    if ($options['order']) $order=' order by '.$options['order'] ;
    if ($this->order) $order=' order by '.$this->order ;
    $options['debug']=0 ;
    $recs=execSQL('select * from '.KT()->view_mo_session.' where '.$usl.$order.$limit,$options) ;
    if (_sizeof($recs) and !$options['no_public_info']) foreach($recs as $id=>$rec) KT()->prepare_public_info_to_mo($recs[$id],$options) ;
    return($recs) ;
  }

 // шаблон - вывод ссылками без разделитея
  function print_template_HTML($list_recs,$options=array())
  {  $options['id']='panel_last_mo' ;
     $options['base_dir']='' ;
     if (!isset($options['no_reverse_indx'])) $options['no_reverse_indx']=$this->filter['skoro'] ;
     $this->list_kt_sessions($list_recs,$options) ;

  }

    // шаблон - вывод ссылками без разделитея
     function list_kt_sessions($list_recs,$options=array())
     { global $member ;
       $id=($options['id'])? 'id='.$options['id']:'' ;
       //$arr_member_views=
       ?><div class=list_mo_sessions <?echo $id?>>
         <table>
           <tr class="head"><th>№</th><th>Дата/время</th><th>Терминал</th><th>Тип<br>контроля</th><th>ФИО<br>сотрудника</th><th>Фото</th><th>Результат проверки</th><th>Допуск</th></tr><?
           $i=($options['no_reverse_indx'])? 1:_sizeof($list_recs) ;
           if (_sizeof($list_recs)) foreach($list_recs as $rec)
             {   $options['i']=$i ;
                 $this->list_kt_sessions_tr($rec,$options) ;
                 if ($options['no_reverse_indx']) $i++ ; else $i-- ;
             }


         ?></table><div id="panel_image_preview"></div></div>
         <script type="text/javascript">
             $j(document).ready(function()
             {    $j('div.list_mo_sessions td.photo div.img img').hover(
                     function() { $j('div#panel_image_preview').addClass('active').html('<img src="'+$j(this).attr('src')+'">');},
                     function() {  $j('div#panel_image_preview').removeClass('active');}
                   ) ;
             }) ;
         </script>

         <?
     }


  // шаблон одной стоки списка сессии МО
  //include_once(_DIR_EXT.'/aspmo_signature/class.DTW.php') ;
  //include_once(_DIR_TO_MODULES.'/signature/m_signature.php') ; - нет необходимости, все модули подключаются автоматиски
  function list_kt_sessions_tr(&$rec,$options=array())
  { ?><tr class=item id="mo_tr_<?echo $rec['pkey']?>">
                <td><?echo $options['i'] ; ?><br><br><a class="new_window"  target="_blank" title="win_second" href="<?echo $rec['__href']?>"><?echo $rec['pkey']?></a><?if ($rec['member_demo_access']){?><div class="demo_access" title="Сотрудник может проходить неограниченное число МО"></div><?}?></td>
                <td><?echo $rec['_data']?><br><?echo $rec['_doctor_name']?></td>
                <td><?echo $rec['group_name'].'<br>' ; echo ($rec['hand_check_user_id'])? '<img src="/images/doctor2.png" title="'.$rec['_hand_check_user_name'].'"><br>'.$rec['_hand_check_user_name']:$rec['terminal_name']?>

                    <?if ($rec['_term_cam_1'] or $rec['video']){?>&nbsp;<span class="v2" cmd="media_server/get_video_from_terminal" id_kt="<?echo $rec['pkey']?>"><i class="fa fa-video-camera"></i></span><?}?>
                </td>
                <td><?echo $rec['_tk_name']?></td>
                <td class="name">
                <?  $arr_info=array() ;
                    if ($rec['member_id']) $arr_info[]='<a class="new_window"  target="_blank" title="win_second" href="'.$rec['__href'].'">'.$rec['member_name'].'</a>' ;
                    if ($rec['_org_name']) $arr_info[]=$rec['_org_name'] ;
                    if ($rec['_otdel_name']) $arr_info[]=$rec['_otdel_name'] ;
                    if (MEMBER()->rol==1 and $rec['propusk']) $arr_info[]='Пропуск: '.$rec['propusk'] ;
                    if (_sizeof($arr_info)) echo implode('<br>',$arr_info) ;
                ?>
                </td>
                <td class="photo"><div>
                    <div class="img"><? if ($rec['_member_img']) { ?><img width=100 src="<?echo $rec['_member_img']?>"><?}?></div>
                    <div class="img"><? if ($rec['_member_img_auth']) {?><img width=100 src="<?echo $rec['_member_img_auth']?>"><?}?></div>
                    <div class="img"><? if ($rec['_member_img_alco']) {?><img width=100 src="<?echo $rec['_member_img_alco']?>"><?}?></div>
                    <div class="clear"></div></div>
                </td>
                <td class="comment"><?  if ($rec['status']==2) echo '<div class=ok>'.$rec['_status_name'].'</div>' ;
                                        echo $rec['_comment'];
                                        if ($rec['terminal_comment']) {?><div class="terminal_comment"><i class="fa fa-desktop" aria-hidden="true"></i> <?echo $rec['terminal_comment']?></div><?}
                                        if ($rec['alko'])  {?><table><tr><td>Алкоголь:</td><td><?echo $rec['_alko']?></td></tr></table><?}
                                    ?>
                    <?if ($rec['reason']=='alcotester_calibration') echo '<br><span style="background:#cf4b25;color:white;padding:4px;margin:0 0;">Требуется калиборока</span>' ;?>
                    <?if ($rec['__dlit_mo']) echo '<br>'.$rec['__dlit_mo'].' c' ;?>
                </td>
                <td class="dopusk_<?echo $rec['dopusk']?>">
                    <? echo $rec['_dopusk_status'] ;
                       if ($options['show_button_dopusk'] and $rec['status']==3 and !$rec['dopusk']) {?><button class="v1" window="sec_win" href="/cab/rmv/hand_mo/<?echo $rec['personal_id']?>/">Ручная проверка</button><?}
                    ?>


                </td>
            </tr>
      <?
  }



  // шаблон - вывод ссылками без разделитея
  function print_template_HTML_small($list_recs,$options=array())
  {  $options['id']='panel_last_mo' ;
     $options['base_dir']='' ;
     if (!isset($options['no_reverse_indx'])) $options['no_reverse_indx']=$this->filter['skoro'] ;
     $id=($options['id'])? 'id='.$options['id']:'' ;
     ?><div class=list_mo_sessions <?echo $id?>>
      <table>
        <colgroup><col id="c0"><col id="c1"><col id="c2"><col id="c22"><col id="c3"><col id="c_photo"><col id="c_result"><col id="c12"><col id="c13"></colgroup>
        <tr class="head"><th>№</th><th>Дата/время</th><th>Терминал</th><th>Тип<br>контроля</th><th>ФИО<br>сотрудника</th><th>Фото</th><th>Результат осмотра</th><th>Комментарий доктора</th><th>Допуск</th></tr><?
        $i=($options['no_reverse_indx'])? 1:_sizeof($list_recs) ;
        if (_sizeof($list_recs)) foreach($list_recs as $rec)
          {   $options['i']=$i ;
              ?><tr class=item id="mo_tr_<?echo $rec['pkey']?>">
                  <td><?echo $options['i'] ; ?><br><br><a class="new_window"  target="_blank" title="win_second" href="<?echo $rec['__href']?>"><?echo $rec['pkey']?></a><?if ($rec['member_demo_access']){?><div class="demo_access" title="Сотрудник может проходить неограниченное число МО"></div><?}?></td>
                  <td><?echo $rec['_data']?><br><?echo $rec['_doctor_name']?></td>
                  <td><?echo $rec['group_name'].'<br>' ; echo ($rec['hand_check_user_id'])? '<img src="/images/doctor2.png" title="'.$rec['_hand_check_user_name'].'"><br>'.$rec['_hand_check_user_name']:$rec['terminal_name']?>

                      <?if ($rec['_term_cam_1'] or $rec['video']){?>&nbsp;<span class="v2" cmd="media_server/get_video_from_terminal" id_kt="<?echo $rec['pkey']?>"><i class="fa fa-video-camera"></i></span><?}?>
                  </td>
                  <td><?echo $rec['_tk_name']?><!--<br><?echo $rec['model']?>--><br><?echo $rec['_model_name']?></td>
                  <td class="name"><a class="new_window"  target="_blank" title="win_second" href="<?echo $rec['__href']?>"><?echo $rec['member_name']?></a><br><?echo $rec['_otdel_name']?><? if (MEMBER()->rol==1) echo '<br>Пропуск: '.$rec['propusk']?></td>
                  <td class="photo"><div>
                      <div class="img"><? if ($rec['_member_img']) { ?><img width=100 src="<?echo $rec['_member_img']?>"><?}?></div>
                      <div class="img"><? if ($rec['_member_img_auth']) {?><img width=100 src="<?echo $rec['_member_img_auth']?>"><?}?></div>
                      <div class="img"><? if ($rec['_member_img_alco']) {?><img width=100 src="<?echo $rec['_member_img_alco']?>"><?}?></div>
                      <div class="clear"></div></div>
                  </td>
                  <td class="comment"><?  if ($rec['status']==2) echo '<div class=ok>'.$rec['_status_name'].'</div>' ;
                                          echo $rec['_comment'];
                                         if ($rec['sign_id'] > 0 and ($rec['status']==2 or $rec['status']==3))
                                         { if ($rec['DTW_res']) echo '<div class="green">Подпись верна</div>';
                                           else                 echo '<div class="red">Подпись неверна</div>' ;
  }
                                      ?>
                  </td>
                  <td>
                      <? if ($rec['doctor_comment'])  echo $rec['doctor_comment'] ; ?>
                  </td>
                  <td class="dopusk_<?echo $rec['dopusk']?>"><? echo $rec['_dopusk_status'] ; ?>
                  </td>
              </tr>
        <?

              if ($options['no_reverse_indx']) $i++ ; else $i-- ;
          }


      ?></table><div id="panel_image_preview"></div></div>
      <script type="text/javascript">
          $j(document).ready(function()
          {    $j('div.list_mo_sessions td.photo div.img img').hover(
                  function() { $j('div#panel_image_preview').addClass('active').html('<img src="'+$j(this).attr('src')+'">');},
                  function() {  $j('div#panel_image_preview').removeClass('active');}
                ) ;
          }) ;
      </script>

      <?
  }


}
?>
