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

class report_mo_rmv extends c_report
{
 var $title='Журнал МО' ;
 var $view_only_model=1 ;
 var $mo_sort='pkey' ;
 public $view_by_space_filter=0 ;
 public $use_fusioncharts=1;

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

 function setting()
 {
     //$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=ESMO()->get_list_terminals(MEMBER()->cur_group_id) ;

     ?><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')) ;
                       if ($GLOBALS['LS_person_schedule_view']) $this->filter_section_select('mo_schedule','График:',2,$_SESSION['ARR_mo_schedule_status'],array('use_id_plus_1'=>1)) ;
                    ?>
                </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[t]" value="1" <?if ($this->filter['t']) 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[cancelTimeout]" value="1" <?if ($this->filter['cancelTimeout']) 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_old()
 {?><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 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">
                  <?
                    $this->filter_section_input_text('name','ФИО:',2,array('auto_complete'=>"autocomplette_person_with_mo_name")) ;
                    $this->filter_section_input_text('propusk','Пропуск:',2,array('LANG'=>'LAT')) ;
                    //$this->filter_section_select_multiple('org_ids','Организация:',2,$arr_orgs_ids) ;
                    //$this->filter_section_select_multiple('otdel_ids','Подразделение:',4,$arr_otdel_ids) ;
                    $this->filter_section_select('tk','Тип контроля:',2,$_SESSION['ARR_mo_tk_type'],array('use_id_plus_1'=>1)) ;
                  ?>
                </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 setting_small_shortcut() {
     if ($GLOBALS['LS_doctor_workspace_shortcut_allow_interval']) {
         unset($this->filter['cur_smena']);
         $this->filter['time_from']=time()-$GLOBALS['LS_setting_auto_mo_allow_interval']*60*60;
     }
     ?><div id="panel_filter">
       <form id="sky-form" class="sky-form">
            <input type="hidden" name="filter_dir" value="<?echo $this->url_report?>">
            <input type="hidden" name="filter[<?if ($GLOBALS['LS_doctor_workspace_shortcut_allow_interval']) echo 'mo_allow_interval'; else echo 'cur_smena';?>]" value="1">
            <fieldset>
                <div class="row">
                    <section class="col col-3">
                        <label class="label">Пропуск:</label>
                        <label class="input"><input type="text" id="propusk_autofocus" name="filter[propusk]" LANG="LAT" value=""></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(['button_apply_id'=>'button_apply']);?>
        </form>
     </div>
     <script type="text/javascript">
         $j(document).ready(function()
         {
             $j('#propusk_autofocus').select() ;
             $j('#propusk_autofocus').focus();
             $j('body').everyTime(1000,'set_focus',function(){$j('#propusk_autofocus').focus();})
             $j('#propusk_autofocus').on('keyup',function()
             {   console.log('propusk length='+$j(this).val().length) ;
                 if ($j(this).val().length==<?echo $GLOBALS['LS_ticket_pass_number_length']?>) send_ajax_request({cmd:"set_filter",
                     filter_dir:'/cab/rmv/',
                     'filter[propusk]':$j(this).val(),
                     'filter[<?if ($GLOBALS['LS_doctor_workspace_shortcut_allow_interval']) echo 'mo_allow_interval'; else echo 'cur_smena';?>]':1
                 }) ;
             }) ;
         });
     </script>
     <?
 }

 function setting_small_master()
 {
     //$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() ;
     $arr_orgs_ids=PERSONAL()->get_arr_orgs_to_cur_account() ;
     $arr_otdel_ids=(_sizeof($this->filter['org_ids']))? PERSONAL()->get_arr_otdels_to_cur_account($this->filter['org_ids']):array() ;
     $arr_terminals=ESMO()->get_list_terminals(MEMBER()->cur_group_id) ;

     ?><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_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')) ;
                 if ($GLOBALS['LS_person_schedule_view']) $this->filter_section_select('mo_schedule','График:',2,$_SESSION['ARR_mo_schedule_status'],array('use_id_plus_1'=>1)) ;
                 ?>
             </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>
             </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 ($GLOBALS['LS_doctor_workspace_shortcut_allow_interval'] and $GLOBALS['LS_doctor_workspace_shortcut'] and $this->filter['propusk']) $info['Режим']='МО с '.date('d.m.Y H:i',(time()-$GLOBALS['LS_setting_auto_mo_allow_interval']*60*60));
   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 ($this->filter['reader'])                          $info['Reader']=$this->filter['reader']  ;
   if ($this->filter['intrusion']==1)                    $info['FaceControl']='Пройден'  ;
   if ($this->filter['intrusion']==2)                    $info['FaceControl']='Не пройден'  ;

   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)
 { //damp_array($this->filter,1,-1) ;
   $options_select=array() ;
   if (is_array($this->filter['dopusk']) and _sizeof($this->filter['dopusk']))
   { $arr=array() ;
     foreach($this->filter['dopusk'] as $dopusk_id=>$value)  $arr[]=$dopusk_id ;
     $options_select['dopusk']=implode(',',$arr) ;

     //$options_select['status']='2,3' ;  // только завершенные МО
     $options_select['only_model']='all' ;  // только конечные МО с моделью
   }
   else if ($this->filter['dopusk'])
   {
     $options_select['dopusk']=$this->filter['dopusk'];
     //$options_select['status']='2,3' ;  // только завершенные МО
     $options_select['only_model']='all' ;  // только конечные МО с моделью
   }

   if ($this->filter['uklon'])
   {
       $options_select['dopusk']=3;
       //$options_select['status']='2,3' ;  // только завершенные МО
       //$options_select['only_model']='all' ;  // только конечные МО с моделью
       //$options_select['no_reason']='cancelTimeout' ;  // не учитывать МО с выходом по таймауту

   }

   if ($this->filter['status'])    $options_select['status']=$this->filter['status'] ;
   if ($this->filter['group_id'])  $options_select['group_id']=$this->filter['group_id'] ;
   if ($this->filter['group_ids'])  $options_select['group_ids']=$this->filter['group_ids'] ;
   if ($this->filter['doctor_id']) $options_select['doctor_id']=$this->filter['doctor_id'] ;
   if ($this->filter['terminal_id']) $options_select['terminal_id_only']=$this->filter['terminal_id'] ;
   if ($this->filter['time_from']) $options_select['time_from']=$this->filter['time_from'] ;
   if ($this->filter['time_to'])   $options_select['time_to']=$this->filter['time_to'] ;
   if ($this->filter['data_from']) $options_select['data_from']=$this->filter['data_from'] ;
   if ($this->filter['data_to'])   $options_select['data_to']=$this->filter['data_to'] ;
   if ($this->filter['tk'])        $options_select['tk']=$this->filter['tk'] ;
   if ($this->filter['dep_id'])    $options_select['dep_id']=$this->filter['dep_id'] ;
   if ($this->filter['org_id'])    $options_select['org_id']=$this->filter['org_id'] ;
   if ($this->filter['org_id'])    $options_select['org_id']=$this->filter['org_id'] ;
   if ($this->filter['otdel_id'])  $options_select['otdel_id']=$this->filter['otdel_id'] ;
   if ($this->filter['org_ids'])  $options_select['org_ids']=$this->filter['org_ids'] ;
   if ($this->filter['otdel_ids']) $options_select['otdel_ids']=$this->filter['otdel_ids'] ;
   if ($this->filter['name'])      $options_select['name']=$this->filter['name'] ;
   if ($this->filter['propusk'])   $options_select['propusk']=$this->filter['propusk'] ;
   if ($this->filter['no_a'])      $options_select['res_stat']['no_a']=1 ; // когда надо найти все, кроме алкоголя
   if ($this->filter['a'])         $options_select['res_stat']['a']=1 ;
   if ($this->filter['d'])         $options_select['res_stat']['d']=1 ;
   if ($this->filter['p'])         $options_select['res_stat']['p']=1 ;
   if ($this->filter['t'])         $options_select['res_stat']['t']=1 ;
   if ($this->filter['q'])         $options_select['res_stat']['q']=1 ;
   if ($this->filter['n'])         $options_select['res_stat']['n']=1 ;
   if ($this->filter['v'])         $options_select['res_stat']['v']=1 ;
   //if ($this->filter['other'])     $options_select['res_stat']['other']=1 ;

   if ($this->filter['ef'])                 $options_select['reason'][]='equipmentFailure' ;
   if ($this->filter['equipmentError'])     $options_select['reason'][]='equipmentError';
   if ($this->filter['equipmentFailure'])   $options_select['reason'][]='equipmentFailure' ;
   if ($this->filter['cancelTimeout'])      $options_select['reason'][]='cancelTimeout' ;
   if ($this->filter['equipment'])          $options_select['equipment'][]=$this->filter['equipment'] ;

   if ($this->filter['intrusion'])          $options_select['intrusion']=$this->filter['intrusion'] ;
   if ($this->filter['reader'])          $options_select['reader']=$this->filter['reader'] ;
   if ($this->filter['mo_schedule'])        $options_select['mo_schedule']=$this->filter['mo_schedule'] ;
   if ($options['mo_ids'])          $options_select['mo_ids']=$options['mo_ids'] ;



   //damp_array($options_select) ;
   // начало смены или авторизация пользователя
   $now=getdate(time()) ;
   // для администратора - последние 24 часа
   if (MEMBER()->info['rol']==1)  $smena_from=mktime($now['hours']-24,$now['minutes'],0,$now['mon'],$now['mday'],$now['year']);
   // для остальных - с начала смены
   elseif (MEMBER()->info['smena_in']) $smena_from=MEMBER()->info['smena_in'] ;
   // если смена не начала - с момента авторизации
   else  $smena_from=MEMBER()->login_time ;

   if ($GLOBALS['LS_doctor_workspace_shortcut_allow_interval'] and $GLOBALS['LS_doctor_workspace_shortcut'] and $this->filter['propusk']) $smena_from=time()-$GLOBALS['LS_setting_auto_mo_allow_interval']*60*60;

   // условия skoro и cur_smena используют значения smena_from
   if ($this->filter['cur_smena']) $options_select['time_from']=$smena_from;
   // при использовании фильтра "скоро" нужно показывать только тех, кто не прошел МО в течении последних двух часов
   // остальные - уклонисты
   // 2 часа - время на которое происходит поиск предудущего МО
   $now=getdate() ;
   $start_day=mktime($now['hours']-$GLOBALS['LS_mo_session_lenght'],$now['minutes'],$now['seconds'],$now['mon'],$now['mday'],$now['year']);
   if ($this->filter['skoro'])     { $options_select['skoro']=$start_day; $options_select['time_from']=$start_day; }

   if (_sizeof($this->filter['model'])) $options_select['only_model']=implode(',',array_keys($this->filter['model'])) ;
   //elseif ($this->view_only_model)  $options_select['only_model']='all' ;
   if ($this->filter['mo_ids'])    { $options_select['mo_ids']=implode(',',array_keys($this->filter['mo_ids'])) ; unset($options_select['only_model']) ; }
   if ($this->filter['id_mo'])     $options_select['mo_ids']=$this->filter['id_mo'] ;

     
   // на РВМ должды быть видны все сотрудники, прошедшие МО независимо от организации
     $options_select['use_member_personal_filter']=$options['dont_use_member_personal_filter']?0:1 ; // учитывать персональные настройки аккаунта по отбору персонала

   // было OR, но это не позволяло делать корректные выборки при наличии нескольких условий
   if (_sizeof($options_select['_use_usl'])) $options_select['use_usl']='('.implode(' and ',$options_select['_use_usl']).')' ;
   //damp_array($this->filter) ;
   //damp_array($options_select) ;
   $options_select['debug']=0 ;
   $usl_res=ESMO()->get_usl_select_mo_by_filter($options_select) ;
   //if (_IS_SYSTEM_IP) echo $usl_res ;
   return($usl_res) ;
 }

  function get_cnt_items($usl,$options=array())
  { $options['debug']=0 ;
    $table_source=($this->filter['cur_smena'])?  ESMO()->table_mo_sessions_now:ESMO()->table_mo_sessions;
    $view_source=($this->filter['cur_smena'])?  ESMO()->view_mo_session_now:ESMO()->view_mo_session;
    if (isset($this->filter['org_ids']) or isset($this->filter['otdel_ids']) or isset($this->filter['name']) or strpos($usl,'personal_parent')!==false) $this->cnt_items=execSQL_value('select count(pkey) from '.$view_source.' where '.$usl,$options) ;
    else  $this->cnt_items=execSQL_value('select count(pkey) from '.$table_source.' 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'] ;
    $options['debug']=0 ;
    $view_source=($this->filter['cur_smena'])?  ESMO()->view_mo_session_now:ESMO()->view_mo_session;
    $recs=execSQL('select * from '.$view_source.' where '.$usl.$order.$limit,$options) ;
    $options['img_path_relative']=1;
    if (_sizeof($recs) and !$options['no_public_info']) foreach($recs as $id=>$rec) ESMO()->prepare_public_info_to_mo($recs[$id],$options) ;
    return($recs) ;
  }

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

  }

  // шаблон - вывод ссылками без разделитея
  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']:'' ;
     ?><script type="application/javascript" src="<?echo _CLASS_?>/aspmo_pp/script.js"></script>
       <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_mo="<?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">
                      <?
                      $arr_info=[];
                      $arr_info[]='<a class="new_window"  target="_blank" title="win_second" href="'.$rec['__href'].'">'.$rec['member_name'].'</a>';
                      $arr_info[]=$rec['_otdel_name'];
                      if (MEMBER()->rol==1) $arr_info[]=$rec['propusk'];
                      if ($GLOBALS['LS_person_schedule_view']) if ($rec['mo_schedule']) $arr_info[]=$GLOBALS['ARR_mo_schedule_status'][$rec['mo_schedule']] ;
                      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['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']?><?if ($rec['tk']==1 and $GLOBALS['LS_alternative_color_for_postshift_medexam']) echo " tk_".$rec['tk']?>">
                      <? echo $rec['_dopusk_status'] ;
                         if ($rec['status']==2 and !$rec['dopusk']) {?><button class="v2 button_green" cmd="aspmo_mo/mo_dopusk_allow" mo_id="<?echo $rec['pkey']?>">Допустить</button><?}
                         if ($options['show_button_dopusk'] and ESMO()->get_allow_view_button_hand_check_in_mo_tr($rec)) {?><button class="v1" window="sec_win" href="/cab/rmv/hand_mo/<?echo $rec['personal_id']?>/">Ручная проверка</button><?}
                      ?>
                  </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>

      <?
  }


}
?>
