Open selfclose opened 7 years ago
require_once(INTERN_DIR.'/vendor/fpdf181/fpdf.php');
class intern_PDF
{
protected $user_id;
protected $education;
protected $title;
protected $header_education = [
[
'width' => 20,
'text' => 'ปีการศึกษา',
'align' => 'C',
],
[
'width' => 50,
'text' => 'สถานศึกษา',
'align' => 'C',
],
[
'width' => 40,
'text' => 'ปีที่ศึกษา',
'align' => 'C',
],
[
'width' => 40,
'text' => 'GPA',
'align' => 'C',
],
[
'width' => 40,
'text' => 'หมายเหตุ',
'align' => 'C',
],
];
protected $header_skill = [
[
'width' => 10,
'text' => 'ที่',
'align' => 'C',
],
[
'width' => 50,
'text' => 'ความสามารถ',
'align' => 'C',
],
[
'width' => 60,
'text' => 'ความถนัด',
'align' => 'C',
],
[
'width' => 40,
'text' => 'หมายเหตุ',
'align' => 'C',
],
];
protected $cell_height = 9;
/**
* @return int
*/
public function getUserId() {
return $this->user_id;
}
/**
* @param int $user_id
*/
public function setUserId( $user_id ) {
$this->user_id = $user_id;
}
/**
* @return array
*/
public function getEducation() {
return $this->education;
}
/**
* @param array $education
*/
public function setEducation( $education ) {
$this->education = $education;
}
/**
* @return string
*/
public function getTitle() {
return $this->title;
}
/**
* @param string $title
*/
public function setTitle( $title ) {
$this->title = $title;
}
//=========== GENERATE ZONE ============//
public function generate_Resume($style = 1)
{
if ($current_user = get_userdata($this->user_id)) {
$currentFont = 'THSarabun'; //angsa || THSarabun
//define('FPDF_FONTPATH', 'font/');
$pdf = new FPDF();
$pdf->SetTitle($this->getTitle(), true);
$pdf->AddPage();
$pdf->AddFont( $currentFont, '', 'THSarabun.php' );//ธรรมดา
$pdf->AddFont( $currentFont, 'B', 'THSarabun Bold.php' );//ธรรมดา
$pdf->AddFont( $currentFont, 'I', 'THSarabun Italic.php' );//ธรรมดา
$pdf->AddFont( $currentFont, 'BI', 'THSarabun BoldItalic.php' );//ธรรมดา
//----- photo ------//
$pdf->Image('http://s3.amazonaws.com/assets.prod.vetstreet.com/2a/cd/ee484be546418f40cc3cbc194b52/kitten-in-arms-thinkstockphotos-106397271-335lc070915jpg.jpg', 160, 6, 40);
//----- Head -----//
$pdf->SetFont($currentFont, 'B', 36);
$pdf->Cell( 0, 17, iconv( 'UTF-8', 'TIS-620', 'เรซูเม่' ), 0, 1, "C" );
$pdf->Line( 0, 42, 250, 42 );
$pdf->Ln();
//----- Intro -----//
$intro = [
['title' => 'ชื่อ-สกุล :', 'value' => $current_user->display_name],
['title' =>'Name :', 'value'=>$current_user->eng_name],
['title' => 'วันเกิด :', 'value' => $current_user->birth_date],
['title' => 'อายุ :', 'value' => $this->calculateAge($current_user->birth_date).' ปี'],
['title' => 'เพศ :', 'value' => $this->getGender($current_user->gender)],
['title' => 'ที่อยู่ :', 'value' => $current_user->address.' '.$current_user->province_id.' '.$current_user->zipcode],
['title' => 'เบอร์โทรศัพท์', 'value' => $current_user->tel],
];
$pdf->SetFillColor(240,240,240);
$pdf->SetTextColor(50, 50, 50);
$pdf->SetDrawColor(100,100,100); //border color
foreach ($intro as $tell) {
if (!empty($tell['value'])) {
$pdf->SetFont( $currentFont, 'B', 16 );
$pdf->Cell( 22, 12, iconv( 'UTF-8', 'TIS-620', $tell['title'] ), 0, 0, "R", true );
$pdf->SetFont( $currentFont, '', 16 );
$pdf->Cell( 140, 12, iconv( 'UTF-8', 'TIS-620', $tell['value'] ), 0, 1, "L" );
}
}
$pdf->Write(10, 'GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO');
$pdf->Text(90, 10, iconv( 'UTF-8', 'TIS-620','เอกสารเรซูเม่ สำหรับบริษัท AAAAAA'));
$pdf->Ln(2);
$pdf->SetFont($currentFont, 'B', 17);
$pdf->Cell( 190, 12, iconv( 'UTF-8', 'TIS-620', 'ประวัติการศึกษา'), 0, 1, "C", true );
$pdf->SetFont($currentFont, 'B', 14);
foreach ($this->header_education as $head) {
$pdf->Cell($head['width'], 11, iconv( 'UTF-8', 'TIS-620',$head['text']),1,0,$head['align'],true);
}
//------ ตาราง สถานศึกษา ------//
$pdf->Ln();
$pdf->SetFont($currentFont, '', 14);
for($i=0; $i<count($this->education); $i++) {
$pdf->Cell($this->header_education[0]['width'], $this->cell_height, "# ".($i+1),1,0,"R",true);
$pdf->Cell($this->header_education[1]['width'], $this->cell_height, iconv( 'UTF-8', 'TIS-620',$this->education[$i]->school_name),1,0,"L");
$pdf->Cell($this->header_education[2]['width'], $this->cell_height, iconv( 'UTF-8', 'TIS-620',$this->getEducation()[$i]->start_year.' - '.$this->getEducation()[$i]->end_year),1,0,"C");
$pdf->Cell($this->header_education[3]['width'], $this->cell_height, iconv( 'UTF-8', 'TIS-620',$this->getEducation()[$i]->gpa),1,0,"C");
if($this->getEducation()[$i]->honour > 0) {
$pdf->Cell($this->header_education[3]['width'], $this->cell_height, iconv('UTF-8', 'TIS-620', 'เกียรตินิยมอันดับ '.$this->getEducation()[$i]->honour), 1, 0, "C");
}
else
{
$pdf->Cell($this->header_education[3]['width'], $this->cell_height, iconv('UTF-8', 'TIS-620', ''), 1, 0, "C");
}
$pdf->Ln();
}
$pdf->Ln(5);
//------ ตาราง Skill ------//
$pdf->SetFont($currentFont, 'B', 16);
$pdf->Cell(190, $this->cell_height, iconv( 'UTF-8', 'TIS-620', 'ทักษะ & ความสามารถ'),0,0,"C");
$pdf->Ln();
foreach ($this->header_skill as $head) {
$pdf->Cell($head['width'], 12, iconv( 'UTF-8', 'TIS-620',$head['text']),1,0,$head['align'],true);
}
$pdf->SetFont( $currentFont, '', 24 );
$pdf->Cell( 190, 20, iconv( 'UTF-8', 'TIS-620', 'จัดขวา' ), 0, 1, "R" );
$pdf->Ln();
$pdf->Cell( 190, 20, iconv( 'UTF-8', 'TIS-620', 'จัดขวาoooooo' ), 0, 1, "R" );
//$pdf->Image('images/dwarf-kitten-01.jpg', 10, 60, 60);
$pdf->Output( "intbizth.pdf", "I" );
//->Output("MyPDF/intbizth.pdf","F"); //F = File, D = download link, I = Inline Browser
}
else {
echo "<h1>InternPDF Error!, Please login first</h1>";
}
}
public function generate_Company($style = 1)
{
}
private function printThai($text) {
return iconv( 'UTF-8','TIS-620',$text);
}
private function calcWidthPercent($numberArr)
{
$maxBase = 200;
}
private function calculateAge($date, $dateDob = 'Y-m-d')
{
$day = date($dateDob,strtotime($date));
$dobObject = new DateTime($day);
$nowObject = new DateTime();
$diff = $dobObject->diff($nowObject);
return $diff->y;
}
private function convertDate($date, $dateDob = 'Y-m-d') {
$day = date($dateDob,strtotime($date));
$months = ['มกราคม', 'กุมภาพัน', 'มีนาคม', 'เมษายน', 'มิถุนายน', 'กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤษจิกายน','ธันวาคม'];
//TODO: มาทำตัว convert ต่อ
}
private function getGender($value) {
$val=null;
switch ($value) {
case 'm': $val='ชาย'; break;
case 'f': $val='หญิง'; break;
case 'n': $val='ไม่ระบุ'; break;
}
return $val;
}
}
class PDF_MC_Table extends FPDF
{
var $widths;
var $aligns;
function SetWidths($w)
{
//Set the array of column widths
$this->widths=$w;
}
function SetAligns($a)
{
//Set the array of column alignments
$this->aligns=$a;
}
function Row($data)
{
//Calculate the height of the row
$nb=0;
for($i=0;$i<count($data);$i++)
$nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
$h=5*$nb;
//Issue a page break first if needed
$this->CheckPageBreak($h);
//Draw the cells of the row
for($i=0;$i<count($data);$i++)
{
$w=$this->widths[$i];
$a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
//Save the current position
$x=$this->GetX();
$y=$this->GetY();
//Draw the border
$this->Rect($x,$y,$w,$h);
//Print the text
$this->MultiCell($w,5,$data[$i],0,$a);
//Put the position to the right of the cell
$this->SetXY($x+$w,$y);
}
//Go to the next line
$this->Ln($h);
}
function CheckPageBreak($h)
{
//If the height h would cause an overflow, add a new page immediately
if($this->GetY()+$h>$this->PageBreakTrigger)
$this->AddPage($this->CurOrientation);
}
function NbLines($w,$txt)
{
//Computes the number of lines a MultiCell of width w will take
$cw=&$this->CurrentFont['cw'];
if($w==0)
$w=$this->w-$this->rMargin-$this->x;
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
$s=str_replace("\r",'',$txt);
$nb=strlen($s);
if($nb>0 and $s[$nb-1]=="\n")
$nb--;
$sep=-1;
$i=0;
$j=0;
$l=0;
$nl=1;
while($i<$nb)
{
$c=$s[$i];
if($c=="\n")
{
$i++;
$sep=-1;
$j=$i;
$l=0;
$nl++;
continue;
}
if($c==' ')
$sep=$i;
$l+=$cw[$c];
if($l>$wmax)
{
if($sep==-1)
{
if($i==$j)
$i++;
}
else
$i=$sep+1;
$sep=-1;
$j=$i;
$l=0;
$nl++;
}
else
$i++;
}
return $nl;
}
}
class PDF extends FPDF
{
// Load data
function LoadData($file)
{
// Read file lines
$lines = file($file);
$data = array();
foreach($lines as $line)
$data[] = explode(';',trim($line));
return $data;
}
// Simple table
function BasicTable($header, $data)
{
// Header
foreach($header as $col)
$this->Cell(40,7,$col,1);
$this->Ln();
// Data
foreach($data as $row)
{
foreach($row as $col)
$this->Cell(40,6,$col,1);
$this->Ln();
}
}
// Better table
function ImprovedTable($header, $data)
{
// Column widths
$w = array(40, 35, 40, 45);
// Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C');
$this->Ln();
// Data
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR');
$this->Cell($w[1],6,$row[1],'LR');
$this->Cell($w[2],6,number_format($row[2]),'LR',0,'R');
$this->Cell($w[3],6,number_format($row[3]),'LR',0,'R');
$this->Ln();
}
// Closing line
$this->Cell(array_sum($w),0,'','T');
}
// Colored table
function FancyTable($header, $data)
{
// Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
// Header
$w = array(40, 35, 40, 45);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Ln();
// Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = false;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,number_format($row[2]),'LR',0,'R',$fill);
$this->Cell($w[3],6,number_format($row[3]),'LR',0,'R',$fill);
$this->Ln();
$fill = !$fill;
}
// Closing line
$this->Cell(array_sum($w),0,'','T');
}