<?
include_once('report_mo3.php') ;
class report_mo_sess2 extends report_mo3
{
 var $title='Журнал МО - сеансы МО списком' ;
 var $view_only_model=0 ;
 var $mo_sort='pkey desc' ;
 var $recs_doctor=array() ;
    var $allow_export_to_csv=1 ;

 // шаблон - вывод ссылками без разделитея
 function print_template_HTML($list_recs,$options=array())
 {     //print_2x_arr($list_recs) ;
       $id=($options['id'])? 'id='.$options['id']:'' ;
       //$arr_member_views=
       ?><div class=list_mo_sessions_report <?echo $id?>>
         <table class="report_mo_sess" >
           <colgroup><col id="c0"><col id="c1"><col id="c3"><col id="c4"><col id="c11"><col id="c12"><col id="c13"></colgroup>
           <tr><th>№</th>
               <th>Дата время</th>
               <th>ID сесии МО</th>
               <th>Тип контроля</th>
               <th>Тип МО</th>
               <th>Модель</th>
               <th>ФИО<br>сотрудника</th>
               <th>Дата рождения</th>
               <th>Возраст</th>
               <th>Пол</th>
               <th>Пропуск</th>
               <th>Терминал/Врач</th>
               <th>Давление</th>
               <th>Пульс</th>
               <th>Температура</th>
               <th>Алкоголь</th>
               <th>ЦНС</th>
               <th>Жалобы</th>
               <th>Результат осмотра<br>на терминале</th>
               <th>Признаки заболевания<br>и пониженной<br>работоспособности</th>
               <th>Комментарий врача</th>
               <th>Результат осмотра</th>
               <th>Допуск</th>
           </tr><?
           $i=$this->first_obj ;
           if (_sizeof($list_recs)) foreach($list_recs as $rec)
           {  $this->view_tr_item($i,$rec) ;
              $i++ ;
           }
         ?></table></div>
           <style>
              table.report_mo_sess{}
              table.report_mo_sess td.dopusk_1{color:green;}
              table.report_mo_sess td.dopusk_2{color:#D70300;}
              table.report_mo_sess td.name a{color:black;text-decoration:none;}
              table.report_mo_sess td.name a:hover{text-decoration:underline;}
              table.report_mo_sess tr.history td{background-color:rgba(185, 221, 253, 0.15);;}
           </style>
        <?
        //damp_array($rec,1,-1) ;
     }

     function view_tr_item($i,$rec,$options=array())
     {   if (!isset($recs_doctor[$rec['doctor_id']])) $this->recs_doctor[$rec['doctor_id']]=ACCOUNTS()->get_member_by_id($rec['hand_check_user_id']) ;

         ?><tr class="item <?echo $options['tr_class']?>">
            <td><?echo $i ;?></td>
            <td><?echo date('d.m.Y H:i:s',$rec['c_data'])?></td>
            <td><?echo '<a href="/cab/mo/'.$rec['pkey'].'/" target=_blank>'.$rec['pkey'].'</a>'?></td>
            <td><?echo $_SESSION['ARR_mo_tk_type'][$rec['tk']];?></td>
            <td><?echo $_SESSION['ARR_mo_type'][$rec['mo_type']]?></td>
            <td><?echo $_SESSION['ARR_model_osmotr'][$rec['model']]?></td>

            <td class="name"><?if ($rec['member_id']) echo '<a href="/cab/personal/person/'.$rec['member_id'].'/">'.$rec['member_name'].'</a></strong>'?></td>
            <td class="center"><?if ($rec['member_dr']) echo $rec['member_dr']?></td>
            <td class="center"><?if ($rec['member_dr']) echo $rec['age']?></td>
            <td class="center"><?if ($rec['member_id']) echo ($rec['member_pol'])? 'Женский':'Мужской'?></td>
            <td class="center"><?if ($rec['member_id']) echo $rec['propusk']?></td>

            <td><?if ($rec['terminal_id']) echo $rec['terminal_id'] ;
                  if ($rec['hand_check_user_id']) echo $this->recs_doctor[$rec['hand_check_user_id']]['obj_name'] ;
                ?>
            </td>
            <td><?if ($rec['tonometer']) echo (($rec['systolic'])? $rec['systolic']:'-').' / '.(($rec['diastolic'])? $rec['diastolic']:'-')?></td>
            <td><?if ($rec['pulsometer']) echo ($rec['pulse'])? $rec['pulse']:'-';?></td>
            <td><?if ($rec['thermometer']) echo ($rec['temperature']>0)? $rec['temperature']:'-';?></td>
            <td><?echo ($rec['alko']>0)? '<span class="red bold">Есть</span>'.(($rec['alko_value']>0)? ' ('.$rec['alko_value'].')':''):($rec['alcotester']? 'Нет':'-');?></td>
            <td><?if ($rec['pupilometer']) echo ($rec['narko'])? '<span class="red bold">Не пройден</span>':'Нет';?></td>
            <td><? if ($rec['status']>=2 and $rec['status']<=3) echo ($rec['question'])? '<span class="red bold">Есть</span>':'Нет' ; else echo '-' ;
                   if ($rec['question_comment']) echo '<br>'.$rec['question_comment'] ;
                ?>
            </td>
            <td class="comment"><? if ($rec['_comment']) echo '<div class=red>'.$rec['_comment'].'</div>' ; ?></td>
            <td><?echo ($rec['simptoms'])? '<span class="red bold">Есть</span>':''?><br><?echo _IL('IL_diagnoz')->recs[$rec['simptoms']]['obj_name']?></td>
            <td><?echo ($rec['doctor_comment'])? $rec['doctor_comment']:''?></td>
            <td><? echo $rec['_status_name'] ; ?></td>
            <td class="dopusk_<?echo $rec['dopusk']?>"><? echo $rec['_dopusk_status']?></td>
        </tr><?
     }

    function print_template_XLS($list_recs,$options=array())
        {  $this->fields=array( 'date'=>array('title'=>'Дата','width'=>10,'align'=>'left'),
                                'session_id'=>array('title'=>'ID сесии МО','width'=>10,'align'=>'left'),
                                'mo_type'=>array('title'=>'Тип контроля','width'=>10,'align'=>'left'),
                                'model'=>array('title'=>'Модель','width'=>10,'align'=>'left'),
                                'FIO'=>array('title'=>'ФИО сотрудника','width'=>40,'align'=>'left'),
                                'dr'=>array('title'=>'ДатаРожд','width'=>10,'align'=>'center'),
                                'age'=>array('title'=>'Возраст','width'=>10,'align'=>'center'),
                                'pol'=>array('title'=>'Пол','width'=>10,'align'=>'center'),
                                'propusk'=>array('title'=>'Пропуск','width'=>10,'align'=>'center'),
                                'term'=>array('title'=>'Терминал/Врач','width'=>15,'align'=>'center'),
                                'sd'=>array('title'=>'Давление','width'=>10,'align'=>'center'),
                                'p'=>array('title'=>'Пульс','width'=>10,'align'=>'center'),
                                't'=>array('title'=>'Температура','width'=>10,'align'=>'center'),
                                'a'=>array('title'=>'Алкоголь','width'=>10,'align'=>'center'),
                                'n'=>array('title'=>'ЦНС','width'=>10,'align'=>'center'),
                                'q'=>array('title'=>'Жалобы','width'=>30,'align'=>'center'),
                                'res_mo'=>array('title'=>'Результат осмотра<br>на терминале','width'=>50,'align'=>'center'),
                                'pzipr'=>array('title'=>'ПЗиПР','width'=>50,'align'=>'center'),
                                'comm_doc'=>array('title'=>'Комментарий врача','width'=>50,'align'=>'center'),
                                'res'=>array('title'=>'Результат осмотра','width'=>50,'align'=>'center'),
                                'dopusk'=>array('title'=>'Допуск','width'=>10,'align'=>'center')
                               ) ;

          // шапка таблицы
          $this->XLS_print_table_header() ;
          // данные таблицы
          if (_sizeof($list_recs)) foreach($list_recs as $rec)
            { $cur_col_char=$this->first_col_char ;
              if (_sizeof($this->fields)) foreach($this->fields as $fname=>$options)
              {  $value='' ;
                 switch($fname)
                  { case 'date':        $value=date('d.m.Y',$rec['c_data']) ;  break ;
                    case 'session_id':  $value=$rec['pkey'] ; break ;
                    case 'mo_type':     $value=$_SESSION['ARR_mo_type'][$rec['mo_type']] ; break ;
                    case 'model':       $value=$_SESSION['ARR_model_osmotr'][$rec['model']] ; break ;
                    case 'FIO':         $value=$rec['member_name'] ; break ;
                    case 'dr':          $value=$rec['member_dr'] ;   break ;
                    case 'age':         $value=$rec['age'] ;   break ;
                    case 'pol':         $value=($rec['member_pol'])? 'Женский':'Мужской' ;   break ;
                    case 'propusk':     $value=$rec['propusk'] ;   break ;
                    case 'term':        $value=($rec['hand_check_user_id'])? $this->recs_doctor[$rec['hand_check_user_id']]['obj_name']:$rec['terminal_id']  ;   break ;
                    case 'sd':          if ($rec['tonometer']) $value=(($rec['systolic'])? $rec['systolic']:'-').' / '.(($rec['diastolic'])? $rec['diastolic']:'-') ;   break ;
                    case 'p':           if ($rec['pulsometer']) $value=($rec['pulse'])? $rec['pulse']:'-';  break ;
                    case 't':           if ($rec['thermometer']) $value= ($rec['temperature']>0)? $rec['temperature']:'-';;   break ;
                    case 'a':           $value=($rec['alko']>0)? 'Есть'.(($rec['alko_value']>0)? ' ('.$rec['alko_value'].')':''):($rec['alcotester']? 'Нет':'-') ;   break ;
                    case 'n':           if ($rec['pupilometer'])  $value=($rec['narko'])? 'Не пройден':'Нет' ;   break ;
                    case 'q':           if ($rec['status']>=2 and $rec['status']<=3) $value=($rec['question'])? 'Есть':'Нет' ; else $value='-' ;
                                        if ($rec['question_comment']) $value.=' '.$rec['question_comment'] ;
                                        break ;
                    case 'res_mo':      if ($rec['_comment']) $value=strip_tags($rec['_comment']) ;  break ;
                    case 'pzipr':       $value=($rec['simptoms'])? 'Есть':'' ;
                                        $value.=_IL('IL_diagnoz')->recs[$rec['simptoms']]['obj_name'] ;
                                        break ;
                    case 'comm_doc':    $value=($rec['doctor_comment'])? $rec['doctor_comment']:'';   break ;
                    case 'res':         $value=strip_tags($rec['_status_name'])  ;   break ;
                    case 'dopusk':      $value=strip_tags($rec['_dopusk_name']) ;   break ;
                  }

                $col_char=iconv('windows-1251','UTF-8',chr($cur_col_char)) ;
                //$this->aSheet->setCellValueByColumnAndRow($col_char,$this->cur_row,$value);
                $this->aSheet->setCellValue($col_char.$this->cur_row,$value);
                if ($options['align']=='center') $this->aSheet->getStyle($col_char.$this->cur_row)->applyFromArray($this->style['center']);
                if ($options['align']=='left')   $this->aSheet->getStyle($col_char.$this->cur_row)->applyFromArray($this->style['left']);
                $cur_col_char++ ;
              }

              $this->cur_row++ ;
            }

        }

    function print_template_CSV($list_recs,$options=array())
        { $i=$options['from'] ;
          if (_sizeof($list_recs)) foreach($list_recs as $rec)
            { $data=array() ;
              $data['Дата']=date('d.m.Y',$rec['c_data']) ;
              $data['ID сесcии МО']=$rec['pkey'] ;
              $data['Тип контроля']=$_SESSION['ARR_mo_type'][$rec['mo_type']] ;
              $data['Модель']=$_SESSION['ARR_model_osmotr'][$rec['model']] ;
              $data['ФИО сотрудника']=$rec['member_name'] ;
              $data['ДатаРожд']=$rec['member_dr'] ;
              $data['Возраст']=$rec['age'] ;
              $data['Пол']=($rec['member_pol'])? 'Женский':'Мужской' ;
              $data['Пропуск']='"'.$rec['propusk'].'"';
              $data['Терминал/Врач']=($rec['hand_check_user_id'])? $this->recs_doctor[$rec['hand_check_user_id']]['obj_name']:$rec['terminal_id']  ;
              $data['Давление']=($rec['tonometer'])? (($rec['systolic'])? $rec['systolic']:'-').' / '.(($rec['diastolic'])? $rec['diastolic']:'-'):''  ;
              $data['Пульс']=($rec['pulsometer'])? (($rec['pulse'])? $rec['pulse']:'-'):'';  ;
              $data['Температура']=($rec['thermometer'])? (($rec['temperature']>0)? $rec['temperature']:'-'):'';  ;
              $data['Алкоголь']=($rec['alko']>0)? 'Есть'.(($rec['alko_value']>0)? ' ('.$rec['alko_value'].')':''):($rec['alcotester']? 'Нет':'-')  ;
              $data['Жалобы']=($rec['status']>=2 and $rec['status']<=3)? ($rec['question'])? 'Есть':'Нет':'-'   ;
                              if ($rec['question_comment']) $data['Жалобы'].=' '.$rec['question_comment'] ;
              $data['Результат осмотра на терминале']=($rec['_comment'])? strip_tags($rec['_comment']):'-'   ;
              $data['ПЗиПР']=(($rec['simptoms'])? 'Есть':'')._IL('IL_diagnoz')->recs[$rec['simptoms']]['obj_name'] ;
              $data['Комментарий врача']=($rec['doctor_comment'])? $rec['doctor_comment']:'' ;
              $data['Результат осмотра']=strip_tags($rec['_status_name']);
              $data['Допуск']=strip_tags($rec['_dopusk_name']);


              $this->put_data_to_CSV($data,$i) ;
              $i++ ;
            }

        }



}

?>
