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

include_once('report_kt_monitor.php') ;
class report_kt_small extends report_kt_monitor
{
 var $title='Журнал КТ (кратко)' ;
 var $order='pkey desc' ;

 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',KT()->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,$_SESSION['ARR_mo_tk_type'],array('use_id_plus_1'=>1)) ;
                       $this->filter_section_select('terminal_id','Терминал:',2,$arr_terminals,array('key_fname'=>'id')) ;
                    ?>
                    <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>
                </div>
            </fieldset>
            <?$this->panel_buttons();?>
        </form>
     </div>
  <?
}

 function panel_info_filter()
 { $_str=array() ; $info=array() ; $title='' ;
   if ($this->filter['data_from'])                       $info['c']=$this->filter['data_from'] ;
   if ($this->filter['data_to'])                         $info['по']=$this->filter['data_to'] ;
   if ($this->filter['group_id'])                        $info['Группа']=ACCOUNTS()->get_member_name_by_id($this->filter['group_id'])  ;
   if ($this->filter['dep_id'])                          $info['Подразделение']=PERSONAL()->get_full_dep_name_by_dep_id($this->filter['dep_id'])  ;
   if ($this->filter['org_id'])                          $info['организация']=PERSONAL()->get_name_by_id($this->filter['org_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['otdel_id'])                        $info['подразделение']=PERSONAL()->get_name_by_id($this->filter['otdel_id']) ;
   if ($this->filter['name'])                            $info['ФИО']='"'.$this->filter['name'].'"' ;
   if ($this->filter['propusk'])                         $info['Пропуск']='"'.$this->filter['propusk'].'"' ;
   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']))                  foreach($this->filter['dopusk'] as $dopusk_id=>$value) $info['Допуск'][]=KT()->ARR_status_dopusk[$dopusk_id]  ;
   else if ($this->filter['dopusk'])                     $info['Допуск']=KT()->ARR_status_dopusk[$this->filter['dopusk']]  ;
   if ($this->filter['a'])                               $info['Причина отказа'][]='Алкоголь'  ;
   if ($this->filter['d'])                               $info['Причина отказа'][]='Давление'  ;
   if ($this->filter['p'])                               $info['Причина отказа'][]='Пульс'  ;
   if ($this->filter['t'])                               $info['Причина отказа'][]='Температура'  ;
   if ($this->filter['q'])                               $info['Причина отказа'][]='Жалобы'  ;
   if ($this->filter['n'])                               $info['Причина отказа'][]='ПП'  ;
   if ($this->filter['v'])                               $info['Причина отказа'][]='ТКТ'  ;
   if ($this->filter['other'])                            $info['Причина отказа'][]='Другое'  ;
   if ($this->filter['other2'])                            $info['Причина отказа'][]='Другое'  ;
   if ($this->filter['ef'])                               $info['Ошибка оборудования'][]='Да'  ;
   if ($this->filter['equipmentErrorOrCancelTimeout'])    $info['Не удалось провести измерение'][]='Да'  ;
   if ($this->filter['equipmentFailure'])                $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>' ;
   $this->report_info=$info ;
   return $title ;

 }

 // шаблон - вывод ссылками без разделитея
  function print_template_HTML($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;
    ?><table class="basic fz_small full auto" <?echo $id?>>
          <tr><th>ID</th><th>Дата/время</th><th>Терминал</th><th>Алкоголь</th><th>Результат осмотра</th><th>Допуск</th></tr><?
          if (_sizeof($list_recs)) foreach($list_recs as $rec)
          { ?><tr class="item">
                  <td><a href="<?echo $rec['__href']?>"><?echo $rec['pkey']?></a></td>
                  <td><?echo date('d.m.Y H:i',$rec['c_data'])?></td>
                  <td><?echo ($rec['hand_check_user_id'])? '<img src="/images/doctor2.png"><br>'.$rec['_hand_check_user_name']:$rec['terminal_name']?></td>
                  <td><? echo $rec['_alko'];?></td>
                  <td class="comment"><? echo '<div class=status_'.$rec['status'].'>'.$rec['_status_name'].'</div>' ; echo $rec['_comment']?></td>
                  <td class="dopusk_<?echo $rec['dopusk']?>"><? echo $rec['_dopusk_status']?></td>
              </tr><?
          }
    ?></table><?
  }

}
?>
