<?
include_once('report_poll_sessions.php') ;
class report_poll_sess extends report_poll_sessions
{
 var $title='Журнал опроса - сеансы' ;
 var $mo_sort='pkey desc' ;
 var $recs_doctor=array() ;

 // шаблон - вывод ссылками без разделитея
 function print_template_HTML($list_recs,$options=array())
 {     //print_2x_arr($list_recs) ;
       $id=($options['id'])? 'id='.$options['id']:'' ;

        $recs=execSQL('select * from poll_result where poll_id in ('.implode(',',array_keys($list_recs)).') order by pkey desc') ;
                 $poll_results=array() ;
                 if (_sizeof($recs)) foreach($recs as $rec)
                   { $poll_results[$rec['poll_id']]['cnt_questions']++ ;
                     $poll_results[$rec['poll_id']]['cnt_correct']+=$rec['correct'] ;
                   }

       //$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>Время</th>
               <th>Группа</th>
               <th>Терминал</th>
               <th>МО</th>
               <th>ФИО<br>сотрудника</th>
               <th>ДР</th>
               <th>Организация</th>
               <th>Подразделение</th>
               <th>Должность</th>
               <th>Число вопросов</th>
               <th>Число правильных ответов</th>
               <th>Результат проверки</th>
           </tr><?
           $i=$this->first_obj ;
           if (_sizeof($list_recs)) foreach($list_recs as $rec)
           {  $poll_res=$poll_results[$rec['pkey']] ;
               ?><tr class="item <?echo $options['tr_class']?>">
                   <td><?echo $i ;?></td>
                   <td><?echo date('d.m.Y',$rec['c_data'])?></td>
                   <td><?echo date('H:i:s',$rec['c_data'])?></td>
                   <td><?echo $rec['terminal_name']?></td>
                   <td><?echo $rec['group_name']?></td>
                   <td><?echo ($rec['mo_id']>0)? $rec['mo_id']:''?></td>
                   <td><?echo '<strong><a href="/cab/personal/person/'.$rec['personal_id'].'/" target="_blank">'.$rec['personal_name'].'</a></strong>'?></td>
                   <td><?if ($rec['personal_dr']) echo $rec['personal_dr']?></td>
                   <td><?echo $rec['_org_name']?></td>
                   <td><?echo $rec['_otdel_name']?></td>
                   <td><?echo $rec['_work_name']?></td>
                   <td><?echo $poll_res['cnt_questions']?></td>
                   <td><?echo $poll_res['cnt_correct']?></td>
                   <td><?echo $rec['_status_name'] ; if ($rec['_comment']) echo '<br>'.$rec['_comment']?></td>
               </tr><?
               $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 print_template_CSV($list_recs,$options=array())
         { $i=$options['from'] ;
           if (_sizeof($list_recs)) foreach($list_recs as $rec)
             { $data=array() ;
               $data['MO ID']=$rec['pkey'] ;
               $data['Дата']=date('d.m.Y',$rec['c_data']) ;
               $data['Время']=date('H:i:s',$rec['c_data']) ;
               $data['Терминал']=$rec['terminal_id'] ;
               $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++ ;
             }

         }


}

?>
