Path : /var/www/html/smart_kpp2_v2/modules/person/
File Upload :
Current File : /var/www/html/smart_kpp2_v2/modules/person/export_to_excel.php

<?php
header("Content-Type: application/vnd.ms-excel");
header('Content-Disposition: attachment; filename="person.xls"');# ชื่อไฟล์ 
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</HEAD>

<BODY>
<?php
require_once "../../amssplus_connect.php";	
require_once("../../include/time_inc.php");

//บุคลากรในสำนักงาน
$sql = "select * from person_position order by position_code";
$dbquery = mysqli_query($connect,$sql);
While ($result = mysqli_fetch_array($dbquery)){
	$position_ar[$result['position_code']]=$result['position_name'];
}
$sql = "select * from person_position_class order by code";
$dbquery = mysqli_query($connect,$sql);
While ($result = mysqli_fetch_array($dbquery)){
	$position_class_ar[$result['code']]=$result['name'];
}
$sql = "select * from person_education_class order by code";
$dbquery = mysqli_query($connect,$sql);
While ($result = mysqli_fetch_array($dbquery)){
	$education_class_ar[$result['code']]=$result['name'];
}
$sql = "select * from system_workgroup order by workgroup_order";
$dbquery = mysqli_query($connect,$sql);
While ($result = mysqli_fetch_array($dbquery)){
	$department_ar[$result['workgroup']]=$result['workgroup_desc'];
}

echo "<table><Tr><Td align='center'>ที่</Td><Td align='center'>ชื่อ</Td><Td align='center'>ตำแหน่ง</Td><Td align='center'>กลุ่ม/โรงเรียน</Td><Td align='center'>วิทยฐานะ/ระดับ</Td><Td align='center'>วันเกิด</Td><Td align='center'>บรรจุครั้งแรก</Td><Td align='center'>เกษียณอายุ</Td><Td align='center'>วุฒิการศึกษาสูงสุด</Td><Td align='center'>อีเมล์</Td><Td align='center'>โทรศัพท์</Td><Td align='center'>เว็บไซต์</Td></Tr>";
$sql = "select * from person_main, person_detail where person_main.person_id=person_detail.person_id and person_main.status='0' order by department,position_code,person_order";
$dbquery = mysqli_query($connect,$sql);
$N=1;
While ($result = mysqli_fetch_array($dbquery)){
	$id = $result['id'];
	$person_id = $result['person_id'];
	$prename=$result['prename'];
	$name= $result['name'];
	$surname = $result['surname'];
	$department= $result['department'];
	$education_class= $result['education_class'];
	$position_class= $result['position_class'];
	$position_code= $result['position_code'];
	$birth_day=thai_date_full($result[birth_day]);
	$start_day=thai_date_full($result[start_day]);
	$end_day=thai_date_full($result[end_day]);
	$email= $result['email'];
	$tel= $result['tel'];
	$url= $result['url'];
	
	echo "<Tr><Td align='center'>$N</Td><Td align='left'>$prename&nbsp;$name&nbsp;&nbsp;$surname</Td><Td align='left'>";
	if(isset($position_ar[$position_code])){
		echo $position_ar[$position_code];
	}
	echo "</Td><Td align='left'>";
	if(isset($department_ar[$department])){
		echo $department_ar[$department];
	}
	echo "</Td><Td align='left'>";
	if(isset($position_class_ar[$position_class])){
		echo $position_class_ar[$position_class];
	}
	echo "</Td>";
	echo "<Td align='left'>$birth_day</Td><Td align='left'>$start_day</Td><Td align='left'>$end_day</Td>";
	echo "<Td align='left'>";
	if(isset($education_class_ar[$education_class])){
		echo $education_class_ar[$education_class];
	}
	echo "<Td align='left'>$email</Td><Td align='left'>$tel</Td><Td align='left'>$url</Td>";
	echo "</Tr>";
	$N++;
}

//บุคลากรในโรงเรียน
$sql = "select * from person_sch_position order by position_code";
$dbquery = mysqli_query($connect,$sql);
While ($result = mysqli_fetch_array($dbquery)){
	$position_sch_ar[$result['position_code']]=$result['position_name'];
}
$sql = "select * from system_school";
$dbquery = mysqli_query($connect,$sql);
While ($result = mysqli_fetch_array($dbquery)){
	$school_ar[$result['school_code']]=$result['school_name'];
}

$sql = "select * from person_sch_main, person_detail where person_sch_main.person_id=person_detail.person_id and person_sch_main.status='0' order by school_code, position_code,person_order";
$dbquery = mysqli_query($connect,$sql);
While ($result = mysqli_fetch_array($dbquery)){
	$id = $result['id'];
	$person_id = $result['person_id'];
	$prename=$result['prename'];
	$name= $result['name'];
	$surname = $result['surname'];
	$position_code= $result['position_code'];
		$school_code= $result['school_code'];
		$person_order= $result['person_order'];
	$education_class= $result['education_class'];
	$position_class= $result['position_class'];

	$birth_day=thai_date_full($result[birth_day]);
	$start_day=thai_date_full($result[start_day]);
	$end_day=thai_date_full($result[end_day]);
	$email= $result['email'];
	$tel= $result['tel'];
	$url= $result['url'];
	
	echo "<Tr><Td align='center'>$N</Td><Td align='left'>$prename&nbsp;$name&nbsp;&nbsp;$surname</Td><Td align='left'>";
	if(isset($position_sch_ar[$position_code])){
		echo $position_sch_ar[$position_code];
	}
	echo "</Td><Td align='left'>";
	if(isset($school_ar[$school_code])){
		echo $school_ar[$school_code];
	}
	echo "</Td><Td align='left'>";
	if(isset($position_class_ar[$position_class])){
		echo $position_class_ar[$position_class];
	}
	echo "</Td>";
	echo "<Td align='left'>$birth_day</Td><Td align='left'>$start_day</Td><Td align='left'>$end_day</Td>";
	echo "<Td align='left'>";
	if(isset($education_class_ar[$education_class])){
		echo $education_class_ar[$education_class];
	}
	echo "<Td align='left'>$email</Td><Td align='left'>$tel</Td><Td align='left'>$url</Td>";
	echo "</Tr>";
	$N++;
}

echo "</Table>";

?>
</BODY>
</HTML>