<?php
class doc_event_personal_status extends c_doc
{
   var $title='Ведомость прохождения мероприятия' ;
   public $PDF_page_orientation='L' ; // L P
   public $PDF_page_format='A4' ;

   var $event_pass_id ;
   var $rec_event_pass ;
   var $rec_personal ;
   var $rec_event ;
   var $obj_event ;

   public $h1='Участники мероприятия - информация' ;

    function setting($options=array())
    {
      //damp_array(ENGINE()->reports_list['napravlenie']['']) ;
         ?><div id="panel_filter">
                <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="<?echo _CUR_REPORT_DIR?>">
                     <?$this->panel_buttons();?>
                 </form>
          </div><br>
        <?
    }

    function panel_buttons()
        { ?><div id="panel_buttons"><?
          if (!$this->editing)
          {?><!--<button class="button v2" cmd="docs/doc_create">Сохранить в документах</button>&nbsp;&nbsp;-->
                               <button class="button v2" cmd="report/view_as_html">HTML</button>&nbsp;&nbsp;
                               <button class="button v2" cmd="report/view_as_pdf" mode="HTML2PDF">PDF</button>&nbsp;&nbsp;
                               <button class="button v2" cmd="report/to_print">Печать</button>&nbsp;&nbsp;
                             <?}
          ?></div><?
        }


   function init($options=array())
   {    if (!$this->event_pass_id) return ;
        $this->rec_event_pass=execSQL_van('select * from obj_site_events_pass where pkey='.$this->event_pass_id) ;
        $this->rec_personal=execSQL_van('select * from view_personals where pkey='.$this->rec_event_pass['personal_id']) ;
        $this->rec_event=execSQL_van('select * from obj_site_events_schedule where pkey='.$this->rec_event_pass['event_id']) ;
        $this->obj_event=EVENTS()->get_event_obj_by_ext($this->rec_event['ext']) ;
        $this->h1=$this->obj_event->name.', прохождение сотрудником '.$this->rec_personal['obj_name'] ;
   }



   function view_as_HTML($options=array())
   { //$this->page_title() ;
    //damp_array($this->rec_event,1,-1) ;
    //damp_array($this->rec_event_pass,1,-1) ;
    //damp_array($this->obj_event,1,-1) ;
    ?><table class="info">
         <tr><th>Наименование мероприятия:</th><td class="left"><?echo $this->obj_event->name.' "'.$this->rec_event['obj_name'].'"'?></td></tr>
         <tr><th>ФИО сотрудника:</th><td class="left"><?echo $this->rec_personal['obj_name']?></td></tr>
         <tr><th>Дата рождения:</th><td class="left"><?echo $this->rec_personal['dr']?></td></tr>
         <tr><th>Организация:</th><td class="left"><?echo $this->rec_personal['_org_name']?></td></tr>
         <tr><th>Подразделение:</th><td class="left"><?echo $this->rec_personal['_othel_name']?></td></tr>
         <tr><th>Должность:</th><td class="left"><?echo $this->rec_personal['_work_name']?></td></tr>
      </table>
      <style type="text/css">
        table.info{width:100%;margin-bottom:20px;}
        table.info th:first-child{text-transform:uppercase;font-weight:normal;width:200px;text-align:right;font-size:11px;}
        table.info td{text-align:left;padding-left:10px;font-size:16px;font-weight:normal;text-transform: none;}
      </style>
      <h2>Ведомость прохождения инструктажа сотрудником</h2>
    <? // темы инструктажа
       $recs_themes=EVENTS()->get_themes_of_events($this->rec_event['pkey']) ; $recs_lession=array() ;
       // записи посещений занятий сотрудником
       $recs_lession_personals=execSQL('select t1.parent as lession_id,t1.c_data,t1.account_id,t1.status,t1.sign_fname,
                                        t2.time_from,t2.time_to,t2.status as lession_status,
                                        t3.obj_name as lektor_name
                                        from obj_site_lession_persons t1
                                        left join obj_site_lession t2 on t2.pkey=t1.parent
                                        left join obj_site_account t3 on t3.pkey=t1.account_id
                                        where t1.event_id='.$this->rec_event['pkey'].' and t1.personal_id='.$this->rec_personal['pkey']);
       if (_sizeof($recs_lession_personals))
       { // список занятий, в которых учавствовал сотрудник
         $recs_lession=execSQL('select * from obj_site_lession where pkey in ('.implode(',',array_keys($recs_lession_personals)).')') ;
         // список тем, которые прослушал сотрудник, учавствующих в занятиях
         $recs_lession_themes=execSQL_row('select theme_id,parent from obj_site_lession_themes where parent in ('.implode(',',array_keys($recs_lession_personals)).')');

       }
       //print_2x_arr($recs_themes) ;
       if (_sizeof($recs_themes))
       { ?><table class="basic fz_small">
             <tr>
               <th>Название темы</th>
               <th>Дата занятия</th>
               <th>Лектор</th>
               <th>Статус занятия</th>
               <th>Статус сотрудника</th>
               <th>Роспись сотрудника</th>
             </tr>
         <?
         foreach($recs_themes as $rec)
         {   $cur_lession=(isset($recs_lession_themes[$rec['pkey']]))?  $recs_lession_personals[$recs_lession_themes[$rec['pkey']]]:array() ;
             ?><tr>
                <td style="width:50%;" class="left"><?echo $rec['obj_name']?></td>
                <td><?if ($cur_lession['lession_id']) echo date('d.m.Y',$cur_lession['time_from']).'<br><span class=nowrap>'.date('H:i',$cur_lession['time_from']).' - '.date('H:i',$cur_lession['time_to']).'</span>'?></td>
                <td><?if ($cur_lession['lession_id']) echo $cur_lession['lektor_name']?></td>
                <td><?if ($cur_lession['lession_id']) echo $this->obj_event->arr_status_lession[$cur_lession['lession_status']]?></td>
                <td><?if ($cur_lession['lession_id']) echo $this->obj_event->arr_status_lession_person[$cur_lession['status']]?></td>
                <td><?if ($cur_lession['sign_fname']) echo '<img src="'._PATH_TO_SITE.'/public/instruktions_sign/'.$cur_lession['sign_fname'].'" width=200>' ?></td>
              </tr><?

         }



         ?></table>
           <style type="text/css">
                   table.basic.fz_small{font-size:12px;}
          </style>

         <?
       }

       //damp_array($cur_lession,1,-1);




    }



}

?>
