<?php
class doc_event_personal_history 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 $rec_history ;
   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->rec_history=execSQL('select * from obj_site_events_pass_status where event_id='.$this->rec_event_pass['event_id'].' and personal_id='.$this->rec_event_pass['personal_id'].' order by pkey') ;
        $this->h1=$this->obj_event->name.', прохождение сотрудником '.$this->rec_personal['obj_name'] ;
        if ($this->rec_event_pass['doc_id'])  $this->rec_doc=DOCS()->get_doc_by_id($this->rec_event_pass['doc_id']) ;
        if ($this->rec_event_pass['scan_id'])  $this->rec_scan=DOCS()->get_scan_by_id($this->rec_event_pass['scan_id']) ;
   }



   function view_as_HTML($options=[])
   { //$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) ;
    if (!$options['no_view_person_info'])
    {
        ?><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>
             <tr><th>Текущий статус прохождения мероприятия:</th><td class="left"><?echo $this->obj_event->arr_status[$this->rec_event_pass['status']]?></td></tr>
             <? if ($this->rec_event_pass['data_from']) {?><tr><th>Срок действия статуса, от:</th><td class="left"><?echo date('d.m.Y H:i',$this->rec_event_pass['data_from'])?></td></tr><?} ?>
             <? if ($this->rec_event_pass['data_to']) {?><tr><th>Срок действия статуса, до:</th><td class="left"><?echo date('d.m.Y H:i',$this->rec_event_pass['data_to'])?></td></tr><?} ?>
             <? if ($this->rec_doc['pkey']) {?><tr><th>Документ:</th><td class="left"><a href="<?echo $this->rec_doc['__href']?>" class="new_window"><?echo $this->rec_doc['obj_name']?></td></tr><?} ?>
             <? if ($this->rec_scan['pkey']) {?><tr><th>Скан документа:</th><td class="left"><a href="<?echo $this->rec_scan['__href']?>" class="new_window"><?echo $this->rec_scan['obj_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>
       <table class="basic fz_small full auto"><tr>
               <th>ID</th><th>Дата</th><th>Действие</th><th>Статус</th><th>Место проведения</th>
               <th>ФИО</th><th>Организация</th><th>Подразделение</th><th>Должность</th>
               <th>Комментарий</th>
           </tr>
                  <tr><td>-</td><td><?echo date('d.m.Y H:i:s',$this->rec_event_pass['c_data'])?></td><td class="left">Добавлен в мероприятие</td><td class="left"></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
             <?
             if (_sizeof($this->rec_history)) foreach($this->rec_history as $rec)
             {  //$rec['doc_id']='1' ; $rec['scan_id']='2' ; $rec['data_from']=time() ;$rec['data_to']=time()+1000000 ;
               ?><tr>
                 <td><?echo $rec['pkey']?></td>
                 <td><?echo date('d.m.Y H:i:s',$rec['c_data'])?></td>
                 <td class="left"><?echo $rec['obj_name']?></td>
                 <td class="left"><?echo $this->obj_event->arr_status[$rec['status_new']]?></td>
                 <td class="left"><? if ($rec['group_id']) echo ACCOUNTS()->get_group_name($rec['group_id'])?></td>
                 <td class="left"><? if ($rec['person_name']) echo $rec['person_name']?></td>
                 <td class="left"><? if ($rec['person_org']) echo $rec['person_org']?></td>
                 <td class="left"><? if ($rec['person_otdel']) echo $rec['person_otdel']?></td>
                 <td class="left"><? if ($rec['person_working']) echo $rec['person_working']?></td>
                 <td class="left"><? $arr=array() ;
                        if ($rec['doc_id']) $arr[]='<span style="white-space:nowrap;">Документ ID: <strong>'.$rec['doc_id'].'</strong></span>' ;
                        if ($rec['scan_id']) $arr[]='<span style="white-space:nowrap;">Скан ID: <strong>'.$rec['scan_id'].'</strong></span>' ;
                        if ($rec['data_from'] or $rec['data_to'])
                        { $arr['srok']='' ;
                          if ($rec['data_from']) $arr['srok']='от <strong>'.date('d.m.Y H:i',$rec['data_from']).'</strong> ' ;
                          if ($rec['data_to'])   $arr['srok'].='до  <strong>'.date('d.m.Y H:i',$rec['data_to']).'</strong>' ;
                          if ($arr['srok']) $arr['srok']='<span style="white-space:nowrap;">Срок действия: '.$arr['srok'].'</span>' ;
                        }
                        if (_sizeof($arr)) echo implode('<br>',$arr) ;
                     ?>
                 </td>
               </tr><?
             }
             ?></table>
          <style type="text/css">
                   table.basic.fz_small{font-size:12px;}
          </style>

         <?

    }



}

?>
