<?php
include_once(_DIR_TO_CLASS."/c_page.php");
class c_page_cab_personal_person extends c_page
{
  public $h1='Карточка сотрудника' ;
  public $rec_mo=array() ;
  public $rec_kt=array() ;
  public $rec_personal=array() ;
  public $use_auto_complete=1 ;

 //function check_access() { return(1) ;}

 function select_obj_info()
 { if (_CUR_ID)
   { $this->rec_personal=PERSONAL()->get_personal_by_id(_CUR_ID,array('get_ext_info'=>1,'check_uid'=>1)) ;
     if (!$this->rec_personal['pkey']) $this->result=404 ;
     else
     { // проверяем наличие записи по СО для ФЛ
       PERSONAL()->sync_workers_by_persons($this->rec_personal['pkey']) ;
     }
   }
   if ($_GET['from_mo'])
   { $this->rec_mo=ESMO()->get_mo_by_id($_GET['from_mo']) ;
     $this->menu_url_params='?from_mo='.$this->rec_mo['pkey'] ;
   }
   if ($_GET['from_kt'])
   { $this->rec_kt=KT()->get_mo_by_id($_GET['from_kt']) ;
     $this->menu_url_params='?from_kt='.$this->rec_kt['pkey'] ;
   }
 }

 function set_head_tags()
 { parent::set_head_tags() ;
   //damp_array($this->allow_menu_items) ;
   if (!$this->check_access() and isset($this->allow_menu_items['c_page_cab_personal_person_card'])) redirect_301_to('/cab/personal/person/'.$this->rec_personal['pkey'].'/card/');
   if (!$this->check_access() and isset($this->allow_menu_items['c_page_cab_personal_person'])) redirect_301_to('/cab/personal/person/'.$this->rec_personal['pkey'].'/');
 }


 function panel_main_menu_title()
 {   if ($this->rec_mo['pkey'])
     {
         ?><li aria-haspopup="true"><a href="<?echo $this->rec_mo['__href']?>"><strong>Медицинский осмотр</strong><br>№ <?echo $this->rec_mo['pkey']?><br><?echo date('d.m.Y H:i',$this->rec_mo['c_data'])?></a></li><?
     }
     if ($this->rec_kt['pkey'])
     {
         ?><li aria-haspopup="true"><a href="<?echo $this->rec_kt['__href']?>"><strong>Контроль трезвости</strong><br>№ <?echo $this->rec_kt['pkey']?><br><?echo date('d.m.Y H:i',$this->rec_kt['c_data'])?></a></li><?
     }
     if ($this->rec_personal['pkey'])
     {   $arr=explode(' ',$this->rec_personal['obj_name']) ;
         $arr[0]='<strong>'.$arr[0].'</strong>' ;
         ?><li aria-haspopup="true"><a href="<?echo $this->rec_personal['__href'].$this->menu_url_params?>"><?echo implode('<br>',$arr)?></a></li><?
     }
 }

 function menu_config()
 { // вкладки для сотрудника
   if ($this->rec_personal['pkey'])
      { $this->menu[$this->rec_personal['__href']]='Карточка сотрудника' ;
        $this->menu[$this->rec_personal['__href'].'card/']='Медицинская карточка' ;
        //if (function_exists('terapevt')) $this->menu['/cab/esmo_ct/person/'.$this->rec_personal['pkey'].'/terapia/']='История приемов' ;
        //$this->menu[$this->rec_personal['__href'].'graf/']='Графики' ;
        if ($this->rec_personal['_ext_info'])        $this->menu[$this->rec_personal['__href'].'ext/']='Дополнительная информация' ;
        if (function_exists('PP') and $this->rec_personal['_pupilomeria_cnt']) $this->menu[$this->rec_personal['__href'].'pp/']='Пупиллометрия' ;
        //if ($this->rec_personal['_mo_cnt'])          $this->menu[$this->rec_personal['__href'].'mo_session/']='Сессии МО' ;
        if ($this->rec_personal['_mo_cnt'])          $this->menu[$this->rec_personal['__href'].'mo/']='История МО' ;
        //$this->menu[$this->rec_personal['__href'].'passcard/']='Пропуск' ;
        //$this->menu[$this->rec_personal['__href'].'sv/']='Подписи' ;
        $this->menu[$this->rec_personal['__href'].'messages/']='Сообщения' ;
        if (function_exists('QUIZ')) $this->menu[$this->rec_personal['__href'].'quiz/']='Контроль знаний' ;
        if (function_exists('EVENTS')) $this->menu[$this->rec_personal['__href'].'events/']='Мероприятия' ;
        $this->menu[$this->rec_personal['__href'].'docs/']='Документы' ;
        $this->menu[$this->rec_personal['__href'].'history/']='История изменений' ;
        $this->menu[$this->rec_personal['__href'].'log_events/']='Журнал событий' ;
        $this->menu[$this->rec_personal['__href'].'db/']='Исходные данные' ;


        //damp_array($this->rec_personal) ;
        $this->page_type='window' ;
      }
   else parent::menu_config() ;
 }

 function second_menu_config()
 { $this->second_menu[$this->rec_personal['__href']]=array('title'=>'Карточка сотрудника') ;
   $this->second_menu[$this->rec_personal['__href'].'passcard/']='Пропуск' ;
   if (function_exists('OT')) $this->second_menu[$this->rec_personal['__href'].'ot/']='Охрана труда' ;
   if (function_exists('EVENTS')) $this->second_menu[$this->rec_personal['__href'].'pmo/']='ПМО' ;
   if (function_exists('EVENTS')) $this->second_menu[$this->rec_personal['__href'].'opo/']='ОПО' ;
   $this->second_menu[$this->rec_personal['__href'].'sv/']='Подписи сотрудника' ;
 }

 function get_cur_page_meta_tags()
 {
   if ($this->rec_personal['pkey']) $this->h1='Карточка сотрудника '.$this->rec_personal['obj_name'] ;
 }

 function block_main()
 { $this->page_title() ;
   $this->panel_card_personal_view() ;
   if (isset($_SESSION['make_personal_photo'])) {
       ?><script type="text/javascript">$j(document).ready(function(){$j('button#make_photo').click();});</script><?
       unset($_SESSION['make_personal_photo']);
   }
 }

 function panel_card_personal_view()
 { include_once('panel_personal_info.php') ;
   $img_href=img_clone($this->rec_personal,'200');
   $img_href_relative = str_replace(_PATH_TO_SITE,'',$img_href);
   ?><div id="panel_card_personal_view">
       <table class="cols3">
         <tr><td class="img">
                 <div class="main_image" style="position:relative;">
                     <img class="shadow main" src="<?echo $img_href_relative?>">
                     <? if ($GLOBALS['LS_faceid_view_info'] and FACEID()->check_faceid_photo($this->rec_personal['pkey'])) {?><img class="certificat_faceid" title="FaceID фото" src="/<?echo _CLASS_?>/ext/faceid/images/certificate.png" style="position:absolute;top:10px;right:33px;"><?}?>
                 </div>
                             <img class=qrcode src="/services/qrcode/<?echo $this->rec_personal['propusk']?>/"/>
                             <?if (!$this->rec_personal['enabled']){?><div class="personal_fired">Уволен</div><?} ;
                               if ($this->rec_personal['enabled'] and $this->rec_personal['fired_data_pause']>0){?><div class="personal_fired_pause">Отложенное увольнение<br><span>до <?echo date('d.m.Y',$this->rec_personal['fired_data_pause'])?></span></div><?}
                  /*else if (is_member_right('personal_change_info')) {?><button class="v2 fa fa-pencil-square-o" cmd="aspmo_personal/get_panel_delete_personal" id="<?echo $this->rec_personal['pkey']?>">Удалить сотрудника</button><?}*/
                 ?>
             </td>
             <td class="info"><?panel_personal_info($this->rec_personal,array('button'=>array('change_info'=>1,'change_photo'=>1)));
             ?></td>
             <td class="info"><?panel_personal_working($this->rec_personal);?></td>
         </tr>
       </table>
       <?
            echo 'Дата создания карточки: '.date('d.m.Y H:i:s',$this->rec_personal['c_data']).'<br>' ;
            echo 'Дата последнего редактирования карточки: '.date('d.m.Y H:i:s',$this->rec_personal['r_data']).'<br>' ;
       ?>
    </div>
  <?
 }


  function CMD_upload_photo()
  { $recs_img=conver_FILES_to_recs($_FILES['upload_img']) ;
    $upload_fdir=$recs_img[0]['tmp_name'];
    if (file_exists($upload_fdir)) PERSONAL()->personal_upload_image($this->rec_personal['pkey'],$upload_fdir,array('fname'=>$recs_img[0]['name'],'source_action'=>'Загрузка изображения файлом с карточки сотрудника')) ;
    $this->rec_personal=PERSONAL()->get_personal_by_id(_CUR_ID,array('get_ext_info'=>1)) ;
  }

  function panel_log_events()
  { include_once(_DIR_EXT.'/log/report_log_events.php') ;
    $report_obj=new report_log_events() ;
   // $report_obj->filter['reffer']=$this->rec_personal['_reffer'];
    $report_obj->filter['personal_id']=$this->rec_personal['pkey'];
    $report_obj->filter['order']='pkey desc';
   // $report_obj->setting() ;
    $report_obj->view_as_HTML(array('limit'=>'limit 0,10')) ;
  }

}



?>
