<?php
session_start();
if(!(isset($_SESSION['login_user_id']))){
exit();
}

if(isset($_GET['id'])){
	$id = $_GET['id'];
require('../amssplus_connect.php');
require('../modules/idocument/time_inc.php');

$sql = "Select * From idocument_main where id = $id";
$dbquery = mysqli_query($connect,$sql);
$dataDisplay = mysqli_fetch_assoc($dbquery);

$subject = iconv( 'UTF-8','cp874' , $dataDisplay['subject']);
$subjectH = iconv( 'UTF-8','cp874' , $dataDisplay['subject']);
$filename = $dataDisplay['subject'].".pdf";
$book_date = iconv( 'UTF-8','cp874' , $dataDisplay['book_date']);
$txtMemo = iconv( 'UTF-8','cp874' , 'บันทึกข้อความ' );
$txtContent1 = iconv( 'UTF-8','cp874//IGNORE' , htmlspecialchars_decode ($dataDisplay['content1']));
$txtContent2 = iconv( 'UTF-8','cp874//IGNORE' , htmlspecialchars_decode ($dataDisplay['content2']));
$txtContent3 = iconv( 'UTF-8','cp874//IGNORE' , htmlspecialchars_decode ($dataDisplay['content3'])); 

$txtworkgroup = iconv( 'UTF-8','cp874' , $dataDisplay['workgroup_txt'] );
$txtName = iconv( 'UTF-8','cp874' , '
( นายเจษฎา จันทสิงห์ )
ครู
12 กรกฎาคม 2561' );
$book_to = "ผู้อำนวยการ".$_SESSION['office_name'];
require('fpdf.php');
//require('mc_indent.php');
$InterLigne = 7;
$indent = 15;
//require_once("class.multicelltag.php");
$pdf = new FPDF();
//$txtContent3 = $txtContent3. " ";
$pdf->SetMargins(20,10,20);
//$pdf->SetLeftMargin(20);
//$pdf->SetTopMargin(20);
$pdf->AddFont('THSarabunNew','','THSarabunNew.php');
$pdf->AddFont('THSarabunNew','B','THSarabunNew Bold.php');
$pdf->AddPage();
//$pdf->SetTitle($dataDisplay['subject']);
//$pdf->SetTitle($subjectH);
$pdf->Image('krut.png',20,10,20,0);
$pdf->Ln(10);
$pdf->SetFont('THSarabunNew','B',20);
$pdf->MultiCell(185, 6, $txtMemo, 0, 'C', 0, 0, '', '', true);
$pdf->Ln();
$pdf->SetFont('THSarabunNew','B',16);
$pdf->Write(6,iconv( 'UTF-8','cp874' , 'ส่วนราชการ   '));
$pdf->SetFont('THSarabunNew','',16);
$pdf->MultiCell(185, 6, $txtworkgroup);
//$pdf->Ln();

$pdf->SetFont('THSarabunNew','B',16);
$dX = $pdf->GetX();
$dY = $pdf->GetY();
$pdf->MultiCell(185, 8,iconv( 'UTF-8','cp874' , 'ที่                                                                  วันที่   '), 0, '', 0, 0, '', '', 1);
$pdf->SetY($dY);
$pdf->SetX(120);
$pdf->MultiCell(185, 8, $book_date);
$pdf->SetFont('THSarabunNew','B',16);
$pdf->Write(8,iconv( 'UTF-8','cp874' , 'เรื่อง   '));
$pdf->SetFont('THSarabunNew','',16);
$pdf->MultiCell(185, 8, $subject);

$pdf->SetFont('THSarabunNew','B',16);
$pdf->Write(12,iconv( 'UTF-8','cp874' , 'เรียน   '));
$pdf->SetFont('THSarabunNew','',16);
$pdf->MultiCell(165, 12,iconv( 'UTF-8','cp874' , $book_to));
//$pdf->Cell(20,20);
$pdf->SetFont('THSarabunNew','',16);
$pdf->ln(6);
if(strlen($txtContent1)<115){
	$savX = $pdf->GetX();
	$pdf->SetX($savX+$indent);
	$pdf->MultiCell(0, $InterLigne, $txtContent1, 0, 'J', 0);
	$pdf->SetX($savX);
}else{
	$pdf->MultiCell(0, $InterLigne, $txtContent1, 0, 'J', 0, $indent);
}
$pdf->ln(6);
if(strlen($txtContent2)<115){
	$savX = $pdf->GetX();
	$pdf->SetX($savX+$indent);
	$pdf->MultiCell(0, $InterLigne, $txtContent2, 0, 'J', 0);
	$pdf->SetX($savX);
}else{
	$pdf->MultiCell(0, $InterLigne, $txtContent2, 0, 'J', 0, $indent);
}
$pdf->ln(6);
if(strlen($txtContent3)<115){
	$savX = $pdf->GetX();
	$pdf->SetX($savX+$indent);
	$pdf->MultiCell(0, $InterLigne, $txtContent3, 0, 'J', 0);
	$pdf->SetX($savX);
}else{
	$pdf->MultiCell(0, $InterLigne, $txtContent3, 0, 'J', 0, $indent);
}

$pdf->ln(6);

$pdf->MultiCell(60, 8,iconv( 'UTF-8','cp874' , 'ตรวจสอบเสนอ'), 0, 'C');
$pdf->Ln();
$pdf->MultiCell(60, 6,$txtName, 0, 'C');
$pdf->Ln();
if(isset($_GET['comment'])){
$Y= $pdf->GetY();
$pdf->SetY($Y);
$pdf->SetX(18);
$pdf->MultiCell(60, 16,$txtName, 1, '');
$pdf->SetY($Y);
$pdf->SetX(80);
$pdf->MultiCell(60, 16,$txtName, 1, '');
$pdf->SetY($Y);
$pdf->SetX(142);
$pdf->MultiCell(60, 16,$txtName, 1, '');
}
$pdf->Output();
}
?>	