<?php
include_once("c_personal_person.php");
class c_page_cab_personal_person_passcard extends c_page_cab_personal_person
{
  public $h1='Карточка сотрудника - печать пропуска' ;

 function get_cur_page_meta_tags()
 {
   if ($this->rec_personal['pkey']) $this->h1='Печать пропуска '.$this->rec_personal['obj_name'] ;
 }


 function _block_main()
 { $this->page_title() ;
      include_once(_DIR_EXT.'/aspmo_personal/report_personal_passcard.php') ;
      $report_obj=new report_personal_passcard() ;
      $report_obj->filter['personal_id']=$this->rec_personal['pkey'];
      $report_obj->filter['order']='pkey desc';
      //echo $report_obj->panel_info_filter() ;
      $report_obj->view_as_HTML() ;
    }    
    
 function block_main()
 { $this->page_title() ;
   //$rec=PERSONAL()->get_personal_by_id($this->rec_personal['pkey'],array('debug'=>0)) ;
   ob_start() ;
   $this->HTML_report_body() ;
   $html=ob_get_clean() ;
   $file_name='temp_'.md5(rand(1,100000)) ;
   $doc_file_name=$this->create_PDF_file($file_name,$this->title,$html) ;
   $doc_file_path=_TEMP_PATH.$doc_file_name;
   ?><iframe src="<?echo $doc_file_path?>"  style="width:100%; height:700px;margin-top:20px;" frameborder="0"></iframe><?
 }

 // сохраняем отчет в виде PDF
 function create_PDF_file($doc_name,$report_title,$html,$report_info='',$options=array())
 {  // Include the main TCPDF library (search for installation path).
   require_once(_DIR_TO_ROOT.'/AddOns/tcpdf/tcpdf.php');

   // create new PDF document
   $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

   // set document information
   $pdf->SetCreator(PDF_CREATOR);
   $pdf->SetAuthor('ESMO');
   $pdf->SetTitle($report_title);
   $pdf->setPrintHeader(false);
   $pdf->setPrintFooter(false);

   $pdf->SetMargins(5, 5, 5,5);
   $pdf->SetHeaderMargin(0);
   $pdf->SetFooterMargin(0);

   $pdf->SetAutoPageBreak(TRUE, 0);
   $pdf->setImageScale(2);
   // set font
   $pdf->SetCellPadding(0);
   $pdf->SetFont('dejavusans', '', 9.5); // любой шрифт из папки /AddOns/tcpdf/fonts/

   // add a page
   $pdf->AddPage('L', 'A7');

   $pdf->writeHTML($html, true, false, true, false, '');

   // QRCODE,H : QR-CODE Best error correction
   $style = array('border' => false,'padding' => 0,'fgcolor' => array(0,0,0),'bgcolor' => false);
   $pdf->write2DBarcode($this->rec_personal[$GLOBALS['LS_person_field_to_qrcode']], 'QRCODE,H', 7, 20, 32, 32, $style, 'N');
   //
   //$pdf->Text(40, 25, $this->rec_pass['_to_zone_name']);
   //$pdf->Text(40, 25, $this->rec_pass['_to_zone_name']);

   //Close and output PDF document
   $doc_file_name=$doc_name.'.pdf' ;
   $doc_dir=_TEMP_DIR.$doc_file_name ;

   $pdf->Output($doc_dir, 'F');

   return($doc_file_name) ;
}


    function HTML_report_body($options=array())
     {   $arr_name=explode(' ',$this->rec_personal['obj_name']) ;
         ?><div id="panel_propusk_view">
             <table class="account_info">
             <tr>
                 <td class="img">
                     <div class="photo"></div>
                     <br><br><br><br><br><br><br><br><br><br><br>
                     <font size="8"><?echo $this->rec_personal['propusk']?></font>
                 </td>
                 <td class="info"><br><br><br>
                     <font size="12"><strong><?echo $arr_name[0].' '.$arr_name[1]?></strong></font><br>
                     <font size="12"><strong><?echo $arr_name[2]?></strong></font><br><br>
                     <font size="8"><strong><?echo $this->rec_personal['_org_name']?></strong></font><br>
                     <font size="8"><strong><?echo $this->rec_personal['_work_name']?></strong></font><br>
              </td>
             </tr>
             </table>
                </div>
         <style>
             div#panel_propusk_view{width:480px;position:relative;}
             div#panel_propusk_view div.title{font-weight:bold;text-align:center;}
             div#panel_propusk_view p{margin:0;padding:0;}
             div#panel_propusk_view table.account_info{width:100%;}
             div#panel_propusk_view table.account_info td.img{width:180px; text-align:center;}
             div#panel_propusk_view table.account_info td.info{width:auto; text-align:right;}
         </style>
         <?
         //damp_array($rec) ;

     }

}



?>