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

<?php
/** ensure this file is being included by a parent file */
defined( '_VALID_' ) or die( 'Direct Access to this location is not allowed.' );
//admin modules /เจ้าหน้าที่เขต
if(!(($_SESSION['admin_person']=="person") or ($_SESSION['login_status']<=4 and ($result_permission['p1']==1 or $result_permission['p1']==2)))){	
exit();
}
?>

<script type="text/javascript">
function showResult(str) {
  if (str.length==0) { 
    document.getElementById("livesearch").innerHTML="";
    document.getElementById("livesearch").style.border="0px";
    return;
  }
  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  } else {  // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {
    if (this.readyState==4 && this.status==200) {
      document.getElementById("livesearch").innerHTML=this.responseText;
      document.getElementById("livesearch").style.border="1px solid #A5ACB2";
    }
  }
  xmlhttp.open("GET","modules/person/livesearch_2.php?q="+str,true);
  xmlhttp.send();
}
</script>

<?php
include("include/time_inc.php");
$officer=$_SESSION['login_user_id'];

if(!(isset($_REQUEST['workgroup']))){
$_REQUEST['workgroup']="";
}

if($result_permission['p1']==2){
	$_REQUEST['workgroup']=$_SESSION['login_workgroup'];
}

//ฟังชั่นupload
function file_upload() {
	$uploaddir = 'modules/person/picture/';      //ที่เก็บไไฟล์
	$uploadfile = $uploaddir.basename($_FILES['userfile']['name']);
	$basename = basename($_FILES['userfile']['name']);

		//เช็คนามสกุล
		$array_lastname = explode("." ,$basename) ;
		$c =count ($array_lastname) - 1 ;
		$lastname_file = strtolower ($array_lastname[$c]) ;

		//$lastname_file = "$lastname"; //ตัวแปรนามสกุล
		if($lastname_file == "jpg" or $lastname_file == "JPG" or $lastname_file == "png") {


	$pic_code=$_POST['person_id'];
	//ลบไฟล์เดิม
	$exists_file=$uploaddir.$pic_code.substr($basename,-4);
	if(file_exists($exists_file)){
		unlink($exists_file);
	}

	if (move_uploaded_file($_FILES['userfile']['tmp_name'],  $uploadfile))
		{
		$before_name  = $uploaddir.$basename;
		$changed_name = $uploaddir.$pic_code.substr($basename,-4) ;
		rename("$before_name" , "$changed_name");
		
		//ลดขนาดภาพ
		if(substr($basename,-3)=="JPG" or substr($basename,-3)=="jpg" or substr($basename,-4)=="jpeg" or substr($basename,-3)=="png" or substr($basename,-3)=="gif"){		
		//if(substr($basename,-3)=="JPG" or substr($basename,-3)=="jpg"){		
			$ori_file=$changed_name;
			$ori_size=getimagesize($ori_file);
			$ori_w=$ori_size[0];
			$ori_h=$ori_size[1];
			if($ori_w>500){
				$new_w=500;
				$new_h=round(($new_w/$ori_w)*$ori_h);
				switch (substr($basename,-3)){
					case "png";
					$ori_img=imagecreatefrompng($ori_file);
					break;
					case "gif";
					$ori_img=imagecreatefromgif($ori_file);
					break;
					default;
					$ori_img=imagecreatefromjpeg($ori_file);
					break;
				}
				$new_img=imagecreatetruecolor($new_w, $new_h);
				imagecopyresized($new_img, $ori_img,0,0, 0,0, $new_w, $new_h, $ori_w, $ori_h);
				$new_file=$ori_file;
				switch (substr($basename,-3)){
					case "png";
					imagepng($new_img, $new_file);
					break;
					case "gif";
					imagegif($new_img, $new_file);
					break;
					default;
					imagejpeg($new_img, $new_file);
					break;
				}
				imagedestroy($ori_img);
				imagedestroy($new_img);
			}	
		}						
		return  $changed_name;
			}
			
}else{ //ถ้าไม่ใช่เอกสารไม่ให้ผ่าน
			echo "<center><h1><font color ='red'>รูปแบบไฟล์ไม่ถูกต้อง ($lastname_file)</font></h1>";
			echo "<button onclick='history.back()'>กลับไปแก้ไข</button></center>";
			exit();
} //จบเช็คนามสกุล

} //จบฟังชั่นupload

$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 system_workgroup order by workgroup_order";
$dbquery = mysqli_query($connect,$sql);
while ($result = mysqli_fetch_array($dbquery)){
	$department_ar[$result['workgroup']]=$result['workgroup_desc'];
}

$sql = "select * from system_school";
$dbquery = mysqli_query($connect,$sql);
While ($result = mysqli_fetch_array($dbquery)){
$school_ar[$result['school_code']]=$result['school_name'];
}

echo "<br />";
if(!(($index==1) or ($index==1.1) or ($index==2) or ($index==5) or ($index==5.1) or ($index==5.2))){
//if(!(($index==1) or ($index==2) or ($index==5))){
echo "<table width='50%' border='0' align='center'>";
echo "<tr align='center'><td><font color='#006666' size='3'><strong>ข้อมูลครูและบุคลากรในสถานศึกษา (ปัจจุบัน)</strong></font></td></tr>";
echo "</table>";
echo "<br>";
}

//ส่วนเพิ่มข้อมูล
if($index==1){
echo "<form Enctype = multipart/form-data id='frm1' name='frm1'>";
echo "<Center>";
echo "<Font color='#006666' Size=3><B>เพิ่ม ข้อมูลบุคลากร</B></Font>";
echo "</Cener>";
echo "<Br><Br>";
echo "<Table width='60%' Border='0' class='myTableForm'>";
echo "<Tr align='left'><Td width=30></Td><Td align='right'>เลขประจำตัวประชาชน&nbsp;</Td><Td><Input Type='Text' Name='person_id' Size='13' maxlenght='13' onkeydown='integerOnly()'></Td></Tr>";
echo "<Tr align='left'><Td width=30></Td><Td align='right'>คำนำหน้าชื่อ&nbsp;</Td><Td><Input Type='Text' Name='prename' Size='15'></Td></Tr>";
echo "<Tr align='left'><Td ></Td><Td align='right'>ชื่อ&nbsp;</Td><Td><Input Type='Text' Name='name'  Size='40'></Td></Tr>";
echo "<Tr align='left'><Td ></Td><Td align='right'>นามสกุล&nbsp;</Td><Td><Input Type='Text' Name='surname'  Size='40'></Td></Tr>";

echo "<Tr align='left'><Td ></Td><Td align='right'>ตำแหน่ง&nbsp;</Td><Td>";
echo "<Select  name='position_code' size='1'>";
echo  "<option  value = ''>เลือก</option>" ;
$sql = "select * from  person_position order by position_code";
$dbquery = mysqli_query($connect,$sql);
While ($person_result = mysqli_fetch_array($dbquery)){
	echo  "<option  value ='$person_result[position_code]'>$person_result[position_code] $person_result[position_name]</option>" ;
}	
echo "</select>";
echo "</Td></Tr>";

echo "<Tr align='left'><Td ></Td><Td align='right'>กลุ่ม&nbsp;</Td><Td>";
echo "<Select  name='workgroup' size='1'>";
echo  "<option  value = ''>เลือก</option>" ;
$sql = "select * from  system_workgroup order by workgroup";
$dbquery = mysqli_query($connect,$sql);
While ($workgroup_result = mysqli_fetch_array($dbquery)){
	echo  "<option  value ='$workgroup_result[workgroup]'>$workgroup_result[workgroup_desc]</option>" ;
}	
echo "</select>";
echo "</Td></Tr>";

echo "<Tr align='left'><Td ></Td><Td align='right'>ลำดับบุคลากรในตำแหน่ง&nbsp;</Td><Td><Input Type='Text' Name='person_order'  Size='4'>&nbsp;(หากประสงค์เรียงลำดับ)</Td></Tr>";

echo  "<tr align='left'>";
echo  "<Td ></Td><td align='right'>ไฟล์รูปภาพ&nbsp;</td>";
echo  "<td align='left'><input name = 'userfile' type = 'file'></td>";
echo  "</tr>";

echo "<tr><td></td><td></td><td>";
echo "<INPUT TYPE='button' name='smb' value='ตกลง' onclick='goto_url(1)'>&nbsp;<INPUT TYPE='button' name='back' value='ย้อนกลับ' onclick='goto_url(0)'>";
echo "</td></tr>";
echo "</Table>";
echo "</form>";

}

//ส่วนกรอกข้อมูลรายละเอียดบุคลากร
if($index==1.1){
echo "<form Enctype = multipart/form-data id='frm1' name='frm1'>";
echo "<Center>";
echo "<Font color='#006666' Size=3><B>เพิ่ม ข้อมูลรายละเอียดบุคลากร</B></Font>";
echo "</Cener>";
$sql = "select * from person_main where person_id='$_GET[person_id]'";
$dbquery = mysqli_query($connect,$sql);
$result = mysqli_fetch_array($dbquery);
echo "<Table Border='0' align=center class='myTableForm' width=50%>";
echo "<Tr align='left'><Td align='right'><font color=#c0c0c0>เลขประจำตัวประชาชน</font> &nbsp;</Td><Td>$result[person_id]</Td></Tr>";
echo "<input type=hidden name=person_id value='$result[person_id]'>";
echo "<Tr><Td align='right'>คำนำหน้า</Td><Td><input type=text name=prename value=$result[prename]><TR>";
echo "<Tr><Td align='right'>ชื่อ</Td><Td><input type=text name=name value=$result[name]><TR>";
echo "<Tr><Td align='right'>สกุล</Td><Td><input type=text name=surname value=$result[surname]><TR>";

echo "<Tr><Td align='right'>ตำแหน่ง</Td><Td>";
echo "<select name=position_code>";
$sql="select * from person_position";
$dbquery=mysqli_query($connect,$sql);
while ($result_position = mysqli_fetch_array($dbquery)){
	if($result_position[position_code]==$result[position_code]){
		echo "<option value=$result_position[position_code] selected>$result_position[position_name]</option>";
	}else{
		echo "<option value=$result_position[position_code]>$result_position[position_name]</option>";
	}
}
echo "</select>";
echo "</Td></Tr>";

echo "<Tr><Td align='right'>กลุ่ม</Td><Td>";
$workgroup=$result[department];
echo "<select name=workgroup>";
$sql="select * from system_workgroup order by workgroup";
$dbquery=mysqli_query($connect,$sql);
while ($result_workgroup = mysqli_fetch_array($dbquery)){
	if($result_workgroup[workgroup]==$workgroup){
		echo "<option value=$result_workgroup[workgroup] selected>$result_workgroup[workgroup_desc]</option>";
	}else{
		echo "<option value=$result_workgroup[workgroup]>$result_workgroup[workgroup_desc]</option>";
	}
}
echo "</select>";
echo "</Td></Tr>";

echo  "<tr align='left'>";
echo  "<td align='right'>ไฟล์รูปภาพ</td>";
echo  "<td align='left'><input name='userfile' type='file'></td>";
echo  "</tr>";

echo "<tr><td align=right>เพศ</td><td>";
	echo "<input type=radio name=sex value=1> ชาย &nbsp;&nbsp; ";
	echo "<input type=radio name=sex value=2> หญิง";
echo "</Td></Tr>";
echo "<tr><td align=right>ชื่อเล่น</td><td><input type='text' name='nickname' style='width:100px;'></td></tr>";
$day=date("Y-m-d");
$today=getDatePickerThai($day);
echo "<tr><td align=right>วัน/เดือน/ปี (เกิด)</td><td>
	<input type=\"text\" name=\"birth_day\" id='datepicker-th-1' value='$today' style='width:100px;'>
	</td></tr>";
echo "<tr><td align=right>วัน/เดือน/ปี (บรรจุครั้งแรก)</td><td>
	<input type=\"text\" name=\"start_day\" id='datepicker-th-2' value='$today' style='width:100px;'>
	</td></tr>";
echo "<Tr align='left'><Td align='right'>วิทยฐานะ/ระดับ</Td><Td>";
echo "<select name='position_class' style='width:180px'>";
$sql = "select * from person_position_class order by code";
$dbquery = mysqli_query($connect,$sql);
while($result_position_class=mysqli_fetch_array($dbquery)){
	echo "<option value='$result_position_class[code]'>$result_position_class[name]</option>";
}
echo "</Td></Tr>";
echo "<Tr align='left'><Td align='right'>วุฒิการศึกษาสูงสุด</Td><Td>";
echo "<select name='education_class' style='width:180px'>";
$sql = "select * from person_education_class order by code";
$dbquery = mysqli_query($connect,$sql);
while($result_education_class=mysqli_fetch_array($dbquery)){
	echo "<option value='$result_education_class[code]'>$result_education_class[name]</option>";
}
echo "</Td></Tr>";
echo "<tr><td align=right>ชื่อวุฒิการศึกษา/วิชาเอก <font color=#ff8000>เช่น บริหารธุรกิจบัณฑิต(การบัญชี)</font></td><td><input type=text name=major size=30></td></tr>";
echo "<tr><td align=right valign=top>อีเมล์</td><td>";
	echo "<input type=text name=email_1 size=30><br>";
	echo "<input type=text name=email_2 size=30><br>";
	echo "<input type=text name=email_3 size=30>";
echo "</td></tr>";
echo "<tr><td align=right valign=top>หมายเลขโทรศัพท์</td><td>";
	echo "<input type=text name=tel_1 size=15><br>";
	echo "<input type=text name=tel_2 size=15><br>";
	echo "<input type=text name=tel_3 size=15>";
echo "</td></tr>";
echo "<tr><td align=right>เว็บไซต์</td><td><input type=text name=url size=30></td></tr>";

echo "<tr><td></td><td align=left>";
	echo "<Input Type=Hidden Name='person_id' Value='$_GET[person_id]'>";
	echo "<Input Type=Hidden Name='page' Value='$_GET[page]'>";
	echo "<INPUT TYPE='button' name='smb' value='ตกลง' onclick='goto_url(2)'>&nbsp;<INPUT TYPE='button' name='back' value='ย้อนกลับ' onclick='goto_url(0)'>";
echo "</td></tr>";
echo "</Table>";
echo "</form>";
}

//ส่วนยืนยันการลบข้อมูล
if($index==2) {
echo "<table width='500' border='0' align='center'>";
echo "<tr><td align='center'><font color='#990000' size='4'>โปรดยืนยันความต้องการลบข้อมูลอีกครั้ง</font><br></td></tr>";
echo "<tr><td align=center>";
echo "<INPUT TYPE='button' name='smb' value='ยืนยัน' onclick='location.href=\"?option=person&task=person&index=3&id=$_GET[id]&page=$_REQUEST[page]&school_code=$_REQUEST[school_code]\"'>
		&nbsp;<INPUT TYPE='button' name='back' value='ยกเลิก' onclick='location.href=\"?option=person&task=person&page=$_REQUEST[page]&school_code=$_REQUEST[school_code]\"'";
echo "</td></tr></table>";
}

//ส่วนลบข้อมูล
if($index==3){
$sql = "delete from person_main where person_id=$_GET[person_id]";
$dbquery = mysqli_query($connect,$sql);
}

if($index==3.1){
	foreach ($_POST as $person_id =>$person_value){
$sql = "delete from person_main where person_id='$person_id'";
$dbquery = mysqli_query($connect,$sql);
	}
}

//ส่วนเพิ่มข้อมูล
if($index==4){
$rec_date = date("Y-m-d");
$sql = "select * from person_main where  person_id='$_POST[person_id]' ";
$dbquery = mysqli_query($connect,$sql);
if(mysqli_num_rows($dbquery)>=1){
echo "<br /><div align='center'>มีเลขประจำตัวประชาชนซ้ำกับรายการที่มีอยู่แล้ว ตรวจสอบอีกครั้ง</div>";
exit();  
}

$basename = basename($_FILES['userfile']['name']);
if ($basename!="")
{
	$changed_name = file_upload();
}
if(!(isset($changed_name))){
	$changed_name="";
}
if(!(isset($_POST['other']))){
	$_POST['other']=0;
}
if($_POST['person_order']==""){
	$_POST['person_order']=0;
}
if($_POST['status']==""){
	$_POST['status']=0;
}

 $sql = "insert into person_main (person_id,prename,name,surname,position_code,pic,department,status,person_order,officer,rec_date) values ( '$_POST[person_id]','$_POST[prename]','$_POST[name]','$_POST[surname]','$_POST[position_code]','$changed_name','$_POST[workgroup]','$_POST[status]','$_POST[person_order]','$officer','$rec_date' )";
$dbquery = mysqli_query($connect,$sql);
}

//ส่วนเพิ่มรายละเอียดบุคลากร
if($index==4.1){
	$rec_date = date("Y-m-d");
	$basename = basename($_FILES['userfile']['name']);
	if ($basename!=""){
		$changed_name = file_upload();
		$sql = "update person_main set prename='$_POST[prename]', name='$_POST[name]', surname='$_POST[surname]', pic='$changed_name', position_code='$_POST[position_code]',officer='$officer',rec_date='$rec_date' where person_id='$_POST[person_id]'";
	}else{
		$sql = "update person_main set prename='$_POST[prename]', name='$_POST[name]', surname='$_POST[surname]', position_code='$_POST[position_code]', officer='$officer',rec_date='$rec_date' where person_id='$_POST[person_id]'";
	}
	$dbquery = mysqli_query($connect,$sql);

$birth_day=getDatePickerEng($_POST[birth_day]);
$start_day=getDatePickerEng($_POST[start_day]);
list($year_birth, $month_birth, $day)= explode("-",$birth_day); 
if($month_birth<=9){
	$year=$year_birth+60;
	$end_day=$year."-09-30";
}else{
	$year=$year_birth+61;
	$end_day=$year."-09-30";
}
if($_POST[email_1]!=''){ $email=$_POST[email_1]; }
if($_POST[email_2]!=''){ $email=$email."|".$_POST[email_2]; }
if($_POST[email_3]!=''){ $email=$email."|".$_POST[email_3]; }
$search = array(" ","-","(",")");
$replace="";
$email=str_replace($search,$replace,$email);
if($_POST[tel_1]!=''){ $tel=$_POST[tel_1]; }
if($_POST[tel_2]!=''){ $tel=$tel."|".$_POST[tel_2]; }
if($_POST[tel_3]!=''){ $tel=$tel."|".$_POST[tel_3]; }
$tel=str_replace($search,$replace,$tel);
//ตรวจสอบเลขประชาชนซ้ำ
$sql = "select * from person_detail where person_id='$_POST[person_id]' ";
$dbquery = mysqli_query($connect,$sql);
if(mysqli_num_rows($dbquery)>=1){
echo "<br /><div align='center'>มีเลขประจำตัวประชาชนซ้ำกับรายการที่มีอยู่แล้ว ตรวจสอบอีกครั้ง</div>";
exit();  
}

$sql = "insert into person_detail (person_id,position_class,education_class,major,sex,nickname,birth_day,start_day,end_day,email,tel,url) values ('$_POST[person_id]','$_POST[position_class]','$_POST[education_class]','$_POST[major]','$_POST[sex]','$_POST[nickname]','$birth_day','$start_day','$end_day','$email','$tel','$_POST[url]')";
$dbquery = mysqli_query($connect,$sql);
}

//ส่วนฟอร์มแก้ไขข้อมูล
if ($index==5){
echo "<form Enctype = multipart/form-data id='frm1' name='frm1'>";
echo "<Center>";
echo "<Font color='#006666' Size=3><B>แก้ไข ข้อมูลบุคลากร</B></Font>";
echo "</Cener>";
echo "<br>";
$sql = "select * from  person_main where id='$_GET[id]'";
$dbquery = mysqli_query($connect,$sql);
$result = mysqli_fetch_array($dbquery);
echo "<Table Border='0' align=center class='myTableForm' width=50%>";
echo "<Tr align='left'><Td align='right'><font color=#c0c0c0>ID</font> &nbsp;</Td><Td>$result[id]</Td></Tr>";
echo "<Tr align='left'><Td align='right'><font color=#c0c0c0>เลขประจำตัวประชาชน</font> &nbsp;</Td><Td>$result[person_id]</Td></Tr>";
echo "<input type=hidden name='person_id' value='$result[person_id]'>";
echo "<Tr><Td align='right'>คำนำหน้า</Td><Td><input type=text name='prename' value='$result[prename]'><TR>";
echo "<Tr><Td align='right'>ชื่อ</Td><Td><input type=text name='name' value='$result[name]'><TR>";
echo "<Tr><Td align='right'>สกุล</Td><Td><input type=text name='surname' value='$result[surname]'><TR>";

echo "<Tr><Td align='right'>ตำแหน่ง</Td><Td>";
echo "<select name='position_code'>";
$sql="select * from person_position order by position_code";
$dbquery=mysqli_query($connect,$sql);
while ($result_position = mysqli_fetch_array($dbquery)){
	if($result_position[position_code]==$result[position_code]){
		echo "<option value='$result_position[position_code]' selected>$result_position[position_name]</option>";
	}else{
		echo "<option value='$result_position[position_code]'>$result_position[position_name]</option>";
	}
}
echo "</select>";
echo "</Td></Tr>";

echo "<Tr><Td align='right'>กลุ่ม <font color=red>(ผอ./รอง ผอ.สพท. ไม่ต้องเลือกกลุ่ม)</font></Td><Td>";
echo "<select name='workgroup'>";
echo "<option value=''>เลือก</option>";
$sql = "select * from system_workgroup order by workgroup";
$dbquery=mysqli_query($connect,$sql);
while ($result_workgroup = mysqli_fetch_array($dbquery)){
	if($result_workgroup[workgroup]==$result[department]){
		echo "<option value=$result_workgroup[workgroup] selected>$result_workgroup[workgroup_desc]</option>";
	}else{
		echo "<option value=$result_workgroup[workgroup]>$result_workgroup[workgroup_desc]</option>";
	}
}
echo "</select>";
echo "</Td></Tr>";

echo  "<tr align='left'>";
echo  "<td align='right'>ไฟล์รูปภาพ&nbsp;</td>";
echo  "<td align='left'><input name='userfile' type='file'></td>";
echo  "</tr>";

echo "<tr><td></td><td align=left>"; 
echo "<Input Type=Hidden Name='id' Value='$result[id]'>";
echo "<Input Type=Hidden Name='page' Value='$_GET[page]'>";
echo "<INPUT TYPE='button' name='smb' value='ตกลง' onclick='goto_url_update(1)'>&nbsp;<INPUT TYPE='button' name='back' value='ย้อนกลับ' onclick='goto_url_update(0)'>";
echo "</td></tr>";
echo "</Table>";
echo "</form>";
}

//ส่วนฟอร์มแก้ไขข้อมูลบุคลากร
if ($index==5.1){
echo "<form id=='frm1' name='frm1'>";
echo "<Center>";
echo "<Font color='#006666' Size=3><B>แก้ไข สถานะบุคลากร</B></Font>";
echo "</Cener>";
echo "<Br><Br>";
$sql = "select * from  person_main where id='$_GET[id]'";
$dbquery = mysqli_query($connect,$sql);
$result = mysqli_fetch_array($dbquery);
echo "<Table Border='0' align=center>";
echo "<Tr align='left'><Td align='right'>เลขประจำตัวประชาชน&nbsp;</Td><Td>$result[person_id]</Td></Tr>";
echo "<Tr align='left'><Td align='right'>คำนำหน้าชื่อ&nbsp;</Td><Td>$result[prename]</Td></Tr>";
echo "<Tr align='left'><Td align='right'>ชื่อ&nbsp;</Td><Td>$result[name]</Td></Tr>";
echo "<Tr align='left'><Td align='right'>นามสกุล&nbsp;</Td><Td>$result[surname]</Td></Tr>";
echo "<Tr align='left'><Td align='right'>สถานะภาพ&nbsp;</Td><Td>";
echo "<Select  name='status' size='1'>";
echo  "<option  value = ''>เลือก</option>" ;
if($result['status']==0){
echo  "<option value ='0' selected>ปฏิบัติงานในสถานศึกษาปัจจุบัน</option>" ;
echo  "<option value ='1'>เคยปฏิบัติงานในสถานศึกษา</option>" ;
}
else{
echo  "<option value ='0'>ปฏิบัติงานในสถานศึกษาปัจจุบัน</option>" ;
echo  "<option value ='1' selected>เคยปฏิบัติงานในสถานศึกษา</option>" ;
}
echo "</select>";
echo "</Td></Tr>";

echo "<Tr align='left'><Td align='right'></Td><Td><br>";
echo "<input type='hidden' name='person_id' value='$result[person_id]'>";
echo "<input type='hidden' name='workgroup' value='$result[department]'>";
echo "<Input Type=Hidden Name='id' Value='$_GET[id]'>";
echo "<INPUT TYPE='button' name='smb' value='ตกลง' onclick='goto_url_update(2)'>&nbsp;<INPUT TYPE='button' name='back' value='ย้อนกลับ' onclick='goto_url_update(0)'>";
echo "</td></tr>";
echo "</Table>";
echo "<br>";
echo "<table align=center><tr><td><strong>หมายเหตุ</strong></td></tr>
	<tr><td>ใช้กรณี <font color=red>ย้ายออกนอกสังกัด, เกษียณ, ลาออก, เสียชีวิต ฯลฯ</font>&nbsp;</td></tr>
	<tr><td>การดำเนินการเปลี่ยนสถานะ จะไม่ลบข้อมูลออกจากระบบ</td></tr>
	<tr><td>เมื่อเปลี่ยนสถานะเป็นอดีตแล้วผู้นั้นจะไม่สามารถ Login และไม่ปรากฎชื่อเป็นบุคลากรปัจจุบัน</td></tr>
	</table>";
echo "</form>";
}

//ส่วนฟอร์มแก้ไขข้อมูลบุคลากร
if ($index==5.2){
echo "<form Enctype = multipart/form-data id='frm1' name='frm1'>";
echo "<Center>";
echo "<Font color='#006666' Size=3><B>แก้ไข ข้อมูลรายละเอียดบุคลากร</B></Font>";
echo "</Cener>";
echo "<br>";
$sql = "select * from person_detail left join person_main on person_detail.person_id=person_main.person_id where person_detail.person_id='$_GET[person_id]'";
$dbquery = mysqli_query($connect,$sql);
$result = mysqli_fetch_array($dbquery);
echo "<Table Border='0' align=center class='myTableForm' width=50%>";
echo "<Tr align='left'><Td align='right'><font color=#c0c0c0>ID</font> &nbsp;</Td><Td>$result[id]</Td></Tr>";
echo "<Tr align='left'><Td align='right'><font color=#c0c0c0>เลขประจำตัวประชาชน</font> &nbsp;</Td><Td>$result[person_id]</Td></Tr>";
echo "<input type=hidden name=person_id value='$result[person_id]'>";
echo "<Tr><Td align='right'>คำนำหน้า</Td><Td><input type=text name=prename value='$result[prename]'><TR>";
echo "<Tr><Td align='right'>ชื่อ</Td><Td><input type=text name=name value='$result[name]'><TR>";
echo "<Tr><Td align='right'>สกุล</Td><Td><input type=text name=surname value='$result[surname]'><TR>";

echo "<Tr><Td align='right'>ตำแหน่ง</Td><Td>";
echo "<select name=position_code>";
$sql="select * from person_position order by position_code";
$dbquery=mysqli_query($connect,$sql);
while ($result_position = mysqli_fetch_array($dbquery)){
	if($result_position[position_code]==$result[position_code]){
		echo "<option value='$result_position[position_code]' selected>$result_position[position_name]</option>";
	}else{
		echo "<option value='$result_position[position_code]'>$result_position[position_name]</option>";
	}
}
echo "</select>";
echo "</Td></Tr>";

echo "<Tr><Td align='right'>กลุ่ม <font color=red>(ผอ./รอง ผอ.สพท. ไม่ต้องเลือกกลุ่ม)</font></Td><Td>";
echo "<select name='workgroup'>";
echo "<option value=''>เลือก</option>";
$sql = "select * from system_workgroup order by workgroup";
$dbquery=mysqli_query($connect,$sql);
while ($result_workgroup = mysqli_fetch_array($dbquery)){
	if($result_workgroup[workgroup]==$result[department]){
		echo "<option value=$result_workgroup[workgroup] selected>$result_workgroup[workgroup_desc]</option>";
	}else{
		echo "<option value=$result_workgroup[workgroup]>$result_workgroup[workgroup_desc]</option>";
	}
}
echo "</select>";
echo "</Td></Tr>";

echo  "<tr align='left'>";
echo  "<td align='right'>ไฟล์รูปภาพ&nbsp;</td>";
echo  "<td align='left'><input name='userfile' type='file'></td>";
echo  "</tr>";

echo "<tr><td align=right>เพศ</td><td>";
if($result[sex]==1){ 
	echo "<input type=radio name=sex value='1' checked> ชาย &nbsp;&nbsp; ";
	echo "<input type=radio name=sex value='2'> หญิง";
}else{
	echo "<input type=radio name=sex value='1'> ชาย &nbsp;&nbsp; ";
	echo "<input type=radio name=sex value='2' checked> หญิง";
}
echo "</Td></Tr>";
echo "<tr><td align=right>ชื่อเล่น</td><td><input type='text' name='nickname' value='$result[nickname]' style='width:100px;'></td></tr>";
$birth_day=getDatePickerThai($result['birth_day']);
echo "<tr><td align=right>วัน/เดือน/ปี (เกิด)</td><td>";
	echo "<input type=\"text\" name=\"birth_day\" id='datepicker-th-1' value='$birth_day' style='width:100px;'>";
echo "</td></tr>";

$start_day=getDatePickerThai($result['start_day']);
echo "<tr><td align=right>วัน/เดือน/ปี (บรรจุครั้งแรก)</td><td>";
	echo "<input type=\"text\" name=\"start_day\" id='datepicker-th-2' value='$start_day' style='width:100px;'>";
echo "</td></tr>";

echo "<Tr align='left'><Td align='right'>วิทยฐานะ/ระดับ</Td><Td>";
echo "<select name='position_class' style='width:180px'>";
$sql="select * from person_position_class order by code";
$dbquery=mysqli_query($connect,$sql);
while($result_position_class=mysqli_fetch_array($dbquery)){
	if($result_position_class[code]==$result[position_class]){
		echo "<option value='$result_position_class[code]' selected>$result_position_class[name]</option>";
	}else{
		echo "<option value='$result_position_class[code]'>$result_position_class[name]</option>";
	}
}
echo "</Td></Tr>";
echo "<Tr align='left'><Td align='right'>วุฒิการศึกษาสูงสุด</Td><Td>";
echo "<select name='education_class' style='width:180px'>";
$sql="select * from person_education_class order by code";
$dbquery=mysqli_query($connect,$sql);
while($result_education_class=mysqli_fetch_array($dbquery)){
	if($result_education_class[code]==$result[education_class]){
		echo "<option value='$result_education_class[code]' selected>$result_education_class[name]</option>";
	}else{
		echo "<option value='$result_education_class[code]'>$result_education_class[name]</option>";
	}
}
echo "</Td></Tr>";
echo "<tr><td align=right>ชื่อวุฒิการศึกษา/วิชาเอก <font color=#ff8000>เช่น บริหารธุรกิจบัณฑิต(การบัญชี)</font></td><td><input type=text name=major value='$result[major]' size=30></td></tr>";
echo "<tr><td align=right valign=top>อีเมล์</td><td>";
$explode_email=explode("|",$result[email]);
for ( $i=0; $i<3; $i++ ) {
	echo "<input type=\"text\" name=\"email[]\" value=\"$explode_email[$i]\" size='30'><br>";
}
echo "</td></tr>";

echo "<tr><td align=right valign=top>หมายเลขโทรศัพท์</td><td>";
$explode_tel=explode("|",$result[tel]);
for ( $i=0; $i<3; $i++ ) {
	echo "<input type=\"text\" name=\"tel[]\" value=\"$explode_tel[$i]\" size='30'><br>";
}
echo "</td></tr>";

echo "<tr><td align=right>เว็บไซต์</td><td><input type=text name=url value='$result[url]' size=30></td></tr>";

echo "<tr><td></td><td align=left>"; 
echo "<Input Type=Hidden Name='id' Value='$result[id]'>";
echo "<Input Type=Hidden Name='page' Value='$_GET[page]'>";
echo "<INPUT TYPE='button' name='smb' value='ตกลง' onclick='goto_url_update(3)'>&nbsp;<INPUT TYPE='button' name='back' value='ย้อนกลับ' onclick='goto_url_update(0)'>";
echo "</td></tr>";
echo "</Table>";
echo "</form>";
}

//ส่วนปรับปรุงข้อมูล
if ($index==6){
/*
$sql = "select * from person_main where person_id='$_POST[person_id]' and id!='$_POST[id]' ";
$dbquery = mysqli_query($connect,$sql);
if(mysqli_num_rows($dbquery)>=1){
echo "<br /><div align='center'>มีเลขประจำตัวประชาชนซ้ำกับรายการที่มีอยู่แล้ว ตรวจสอบอีกครั้ง</div>";
exit();  
}
*/

	if($_POST['person_order']==''){
		$_POST['person_order'] = 0;
	}
	$rec_date = date("Y-m-d");
	$basename = basename($_FILES['userfile']['name']);
	if ($basename!=""){
		$changed_name = file_upload();
		if(!isset($changed_name)){
			$changed_name="";
		}
		$sql = "update person_main set person_id='$_POST[person_id]', prename='$_POST[prename]', name='$_POST[name]', surname='$_POST[surname]', pic='$changed_name', position_code='$_POST[position_code]', person_order='$_POST[person_order]',department='$_POST[workgroup]',officer='$officer',rec_date='$rec_date' where person_id='$_POST[person_id]'";
	}
	else{
		 $sql = "update person_main set person_id='$_POST[person_id]', prename='$_POST[prename]', name='$_POST[name]', surname='$_POST[surname]', position_code='$_POST[position_code]', person_order='$_POST[person_order]',department='$_POST[workgroup]',officer='$officer',rec_date='$rec_date' where person_id='$_POST[person_id]'";
	}
	$dbquery = mysqli_query($connect,$sql);
}

//ส่วนปรับปรุงข้อมูลสถานะ
if ($index==6.1){
 $sql = "update person_main set status='$_POST[status]' where person_id='$_POST[person_id]'";
$dbquery = mysqli_query($connect,$sql);
}

//ส่วนปรับปรุงข้อมูลบุคลากร
if ($index==6.2){
	$rec_date = date("Y-m-d");
	$basename = basename($_FILES['userfile']['name']);
	if ($basename!=""){
		$changed_name = file_upload();
		$sql = "update person_main set prename='$_POST[prename]', name='$_POST[name]', surname='$_POST[surname]', pic='$changed_name', position_code='$_POST[position_code]', department='$_POST[workgroup]', officer='$officer',rec_date='$rec_date' where person_id='$_POST[person_id]'";
	}else{
		$sql = "update person_main set prename='$_POST[prename]', name='$_POST[name]', surname='$_POST[surname]', position_code='$_POST[position_code]', department='$_POST[workgroup]', officer='$officer',rec_date='$rec_date' where person_id='$_POST[person_id]'";
	}
	$dbquery = mysqli_query($connect,$sql);

	$birth_day=getDatePickerEng($_POST[birth_day]);
	$start_day=getDatePickerEng($_POST[start_day]);
	list($year_birth, $month_birth, $day)= explode("-",$birth_day); 
	if($month_birth<=9){
		$year=$year_birth+60;
		$end_day=$year."-09-30";
	}else{
		$year=$year_birth+61;
		$end_day=$year."-09-30";
	}
	$search = array(" ","-","(",")");
	$replace="";
	for($i=0; $i<=count($_POST[email]); $i++){
		if($email[$i]!=''){
			$email_x=$email_y.$email[$i];
			$email_y=$email_x."|";
		}
	}
	$email_y=str_replace($search,$replace,$email_y);
	for($i=0; $i<=count($_POST[tel]); $i++){
		if($tel[$i]!=''){
			$tel_x=$tel_y.$tel[$i];
			$tel_y=$tel_x."|";
		}
	}
	$tel_y=str_replace($search,$replace,$tel_y);

	$sql = "UPDATE person_detail SET position_class='$_POST[position_class]', education_class='$_POST[education_class]', major='$_POST[major]', sex='$_POST[sex]', nickname='$_POST[nickname]', birth_day='$birth_day', start_day='$start_day', end_day='$end_day', email='$email_y', tel='$tel_y', url='$_POST[url]' WHERE person_id='$_POST[person_id]'";
	$dbquery = mysqli_query($connect,$sql);
}

//ส่วนการแสดงผล
if(!(($index==1) or ($index==1.1) or ($index==2) or ($index==5) or ($index==5.1) or ($index==5.2))){
$index="";
echo "<form id='frm1' name='frm1'>";
echo "<table width='95%' align='center' border=0><tr>";
echo "<td><INPUT TYPE='button' name='smb' value='เพิ่มข้อมูล' onclick='location.href=\"?option=person&task=person&index=1\"'>";
echo "</td><td align='right'>";
if($result_permission['p1']==1){
	echo "<select name=\"department\" onChange=location.href='?option=person&task=person&workgroup='+this.options[this.selectedIndex].value;>";
	echo "<option value=''>ทุกคน</option>";
	$sql = "select * from system_workgroup order by id";
	$dbquery = mysqli_query($connect,$sql);
	while ($result = mysqli_fetch_array($dbquery)){
		if($_REQUEST['workgroup']==""){
			echo "<option value=$result[workgroup]>$result[workgroup_desc]</option>"; 
		}else{
			if($_REQUEST['workgroup']==$result['workgroup']){
				echo "<option value=$result[workgroup] selected>$result[workgroup_desc]</option>"; 
			}else{
				echo "<option value=$result[workgroup]>$result[workgroup_desc]</option>"; 
			}
		}
	}
	echo "</select>";
}
echo "</td></tr></table>";

if( $_REQUEST['workgroup'] == "" ){
	$sql = "select * from person_main where status='0' order by department,position_code,person_order";
}else{
	$sql = "select * from person_main where department='$_REQUEST[workgroup]' and status='0' order by department,position_code,person_order";
}
$dbquery = mysqli_query($connect,$sql);

echo  "<table width='95%' align='center' class=myTableGreen>";
echo "<th width='70'>ที่</th><th>ชื่อ</th><th>ตำแหน่ง</th><th>กลุ่ม</th><th width='120'>รายละเอียดบุคลากร</th><th width='80'>สถานะภาพ</th><th width='80'>แก้ไข</th><th width='120'>ปรับปรุงข้อมูลบุคลากร</th>";
$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'];
	$position_code= $result['position_code'];
	$department= $result['department'];
	echo "<Tr><Td align=center>$N</Td><Td align='left'>$prename $name  $surname</Td><Td align='left'>";
	if(isset($position_ar[$position_code])){		
		echo $position_ar[$position_code];
	}
	echo "</Td><Td align='center'>";
	if(isset($department_ar[$department])){
		echo $department_ar[$department];
	}
	echo "</Td>";

	//ค้นหาว่ามีการสร้างข้อมูลหรือยัง
	$sql_detail="select * from person_detail where person_id='$person_id' ";
	$dbquery_detail=mysqli_query($connect,$sql_detail);
	$num=mysqli_num_rows($dbquery_detail);
	if($num==0){
		//ส่วนของรายละเอียด
		echo "<Td align='center'></Td>";
		//ส่วนของปรับปรุงข้อมูล เฉพาะ admin, เจ้าหน้าที่ระบบ กับเจ้าของข้อมูล
		echo "<Td align=center><a href=?option=person&task=person&index=5.1&id=$id&page=$page&workgroup=$department><img src=images/my-icons/no.png width=22 border='0' title='กำหนดสถานะภาพ'></a></Td>";
		echo "<Td align=center><a href=?option=person&task=person&index=5&id=$id&page=$page&workgroup=$department><img src=images/edit.png border='0' title='แก้ไข'></a></Td>";
		echo "<Td align=center>";
		echo "<a href='?option=person&task=person&index=1.1&person_id=$person_id&workgroup=$department'><img src=images/my-icons/plus.png width=22 border='0' title='เพิ่ม ข้อมูลบุคลากร'></a>";
		echo "</Td>";
	}else{
		//ส่วนของรายละเอียด
		echo "<Td align='center'><a href='modules/person/person_detail.php?person_id=$person_id' class='dialogify'><img src=images/my-icons/list.png width=28 border='0' title='รายละเอียด ข้อมูลบุคลากร'></a></Td>";
		//ส่วนของปรับปรุงข้อมูล เฉพาะ admin, เจ้าหน้าที่ระบบ กับเจ้าของข้อมูล
		echo "<Td align=center><a href=?option=person&task=person&index=5.1&id=$id&page=$page&workgroup=$department><img src=images/my-icons/no.png width=22 border='0' title='กำหนดสถานะภาพ'></a></Td>";
		echo "<Td align=center><a href=?option=person&task=person&index=5&id=$id&page=$page&workgroup=$department><img src=images/edit.png border='0' title='แก้ไข'></a></Td>";
		echo "<Td align=center>";
		echo "<a href='?option=person&task=person&index=5.2&person_id=$person_id&workgroup=$department'><img src=images/my-icons/interface-edit.png width=24 border='0' title='แก้ไข ข้อมูลบุคลากร'></a>";
		echo "</Td>";
	}
	echo "</Tr>";
	$N++;
}

echo "</Table>";

if($result_permission['p1']==1){
	$sql=  "select * from person_main where status='1' order by department, position_code ";
	$dbquery=mysqli_query($connect,$sql);
	echo "<br>";
	echo "<table align='center' class=myTableSky>";
	echo "<tr><td colspan=4>บุคลากรในอดีต /สถานะภาพ : ย้ายไปสังกัดหน่วยงานอื่น, เกษียณ, ลาออก, เสียชีวิต ฯลฯ</td></tr>";
	echo "<th>ชื่อ - สกุล</th><th>ตำแหน่ง</th><th>กลุ่ม</th><th>ยกเลิกสถานะภาพ</th>";
	while ($result=mysqli_fetch_array($dbquery)){
		$id=$result['id'];
		echo "<tr><td>$result[prename] $result[name]  $result[surname]</td>";
		echo "<td align=center>".$position_ar[$result['position_code']]."</td>";
		echo "<td align=center>".$department_ar[$result['department']]."</td>";
		echo "<td align=center><a href=\"?option=person&task=person&index=5.1&id=$id&page=$page&workgroup=$result[department]\"><img src=images/my-icons/no.png border='0' title='แก้ไข' width=22></a></td>";
		echo "</tr>";
	}
	echo "</table>";
}
echo "</form>";
}

?>
<script type="text/javascript">
function goto_url(val){
	if(val==0){
		callfrm("?option=person&task=person");   // page ย้อนกลับ 
	}else if(val==1){
		if(frm1.person_id.value == ""){
			alert("กรุณากรอกเลขประจำตัวประชาชน");
		}else if(frm1.prename.value==""){
			alert("กรุณากรอกคำนำหน้าชื่อ");
		}else if(frm1.name.value==""){
			alert("กรุณากรอกชื่อ");
		}else if(frm1.surname.value==""){
			alert("กรุณากรอกนามสกุล");
		}else if(frm1.position_code.value==""){
			alert("กรุณาเลือกตำแหน่ง");
		}else{
			callfrm("?option=person&task=person&index=4");   //page ประมวลผล
		}
	}
	else if(val==2){
		callfrm("?option=person&task=person&index=4.1");   //page ประมวลผล
	}
}

function goto_url_update(val){
	if(val==0){
		callfrm("?option=person&task=person");   // page ย้อนกลับ 
	}else if(val==1){
		if(frm1.person_id.value == ""){
			alert("กรุณากรอกเลขประจำตัวประชาชน");
		}else if(frm1.prename.value==""){
			alert("กรุณากรอกคำนำหน้าชื่อ");
		}else if(frm1.name.value==""){
			alert("กรุณากรอกชื่อ");
		}else if(frm1.surname.value==""){
			alert("กรุณากรอกนามสกุล");
		}else if(frm1.position_code.value==""){
			alert("กรุณาเลือกตำแหน่ง");
		}else{
			callfrm("?option=person&task=person&index=6");   //page ประมวลผล
		}
	}else if(val==2){
		if(frm1.person_id.value == ""){
			alert("กรุณากรอกเลขประจำตัวประชาชน");
		}else{
			callfrm("?option=person&task=person&index=6.1");   //page ประมวลผล
		}
	}else if(val==3){
		if(frm1.person_id.value == ""){
			alert("กรุณากรอกเลขประจำตัวประชาชน");
		}else if(frm1.prename.value==""){
			alert("กรุณากรอกคำนำหน้าชื่อ");
		}else if(frm1.name.value==""){
			alert("กรุณากรอกชื่อ");
		}else if(frm1.surname.value==""){
			alert("กรุณากรอกนามสกุล");
		}else if(frm1.position_code.value==""){
			alert("กรุณาเลือกตำแหน่ง");
		}else{
			callfrm("?option=person&task=person&index=6.2");   //page ประมวลผล
		}
	}
}

function goto_display(val){
	if(val==1){
		callfrm("?option=person&task=person&index=8"); 
	}
}

function goto_delete_all(){
	callfrm("?option=person&task=person&index=3.1"); 
}

function CheckAll() {
	for (var i = 0; i < document.frm1.elements.length; i++)
	{
	var e = document.frm1.elements[i];
	if (e.name != "allchk")
		if(e.value==1 && e.type=="checkbox"){
		e.checked = document.frm1.allchk.checked;
		}
	}
}
function check(val){
document.getElementById('wrong'+val).style.display="none";
document.getElementById('right'+val).style.display="block";
}
</script>

<link type="text/css" href="include/jquery.DatetimePicker/jquery.datetimepicker.css" rel="stylesheet" />	
<script type="text/javascript" src="include/jquery.DatetimePicker/jquery.min.js"></script>
<script type="text/javascript" src="include/jquery.DatetimePicker/jquery.datetimepicker.full.js"></script>

<script type="text/javascript">
$(function(){
	$.datetimepicker.setLocale('th'); // ต้องกำหนดเสมอถ้าใช้ภาษาไทย และ เป็นปี พ.ศ.
	// กรณีใช้แบบ input #datepicker-th-1
    $("#datepicker-th-1").datetimepicker({
        timepicker:false,
        format:'d-m-Y',  // กำหนดรูปแบบวันที่ ที่ใช้ เป็น 00-00-0000			
        lang:'th',  // ต้องกำหนดเสมอถ้าใช้ภาษาไทย และ เป็นปี พ.ศ.
		onSelectDate:function(dp,$input){
			var yearT=new Date(dp).getFullYear()-0;  
			var yearTH=yearT+543;
			var fulldate=$input.val();
			var fulldateTH=fulldate.replace(yearT,yearTH);
			$input.val(fulldateTH);
		},
    });
	// กรณีใช้กับ input ต้องกำหนดส่วนนี้ด้วยเสมอ เพื่อปรับปีให้เป็น ค.ศ. ก่อนแสดงปฏิทิน
	$("#datepicker-th-1").on("mouseenter mouseleave",function(e){
		var dateValue=$(this).val();
		if(dateValue!=""){
				var arr_date=dateValue.split("-"); // ถ้าใช้ตัวแบ่งรูปแบบอื่น ให้เปลี่ยนเป็นตามรูปแบบนั้น
				// ในที่นี้อยู่ในรูปแบบ 00-00-0000 เป็น d-m-Y  แบ่งด่วย - ดังนั้น ตัวแปรที่เป็นปี จะอยู่ใน array
				//  ตัวที่สอง arr_date[2] โดยเริ่มนับจาก 0 
				if(e.type=="mouseenter"){ var yearT=arr_date[2]-543; }		
				if(e.type=="mouseleave"){ var yearT=parseInt(arr_date[2])+543; }	
				dateValue=dateValue.replace(arr_date[2],yearT);
				$(this).val(dateValue);													
		}		
	});

	// กรณีใช้แบบ input #datepicker-th-2
    $("#datepicker-th-2").datetimepicker({
        timepicker:false,
        format:'d-m-Y',  // กำหนดรูปแบบวันที่ ที่ใช้ เป็น 00-00-0000			
        lang:'th',  // ต้องกำหนดเสมอถ้าใช้ภาษาไทย และ เป็นปี พ.ศ.
		onSelectDate:function(dp,$input){
			var yearT=new Date(dp).getFullYear()-0;  
			var yearTH=yearT+543;
			var fulldate=$input.val();
			var fulldateTH=fulldate.replace(yearT,yearTH);
			$input.val(fulldateTH);
		},
    });       
	// กรณีใช้กับ input ต้องกำหนดส่วนนี้ด้วยเสมอ เพื่อปรับปีให้เป็น ค.ศ. ก่อนแสดงปฏิทิน
	$("#datepicker-th-2").on("mouseenter mouseleave",function(e){
		var dateValue=$(this).val();
		if(dateValue!=""){
				var arr_date=dateValue.split("-"); // ถ้าใช้ตัวแบ่งรูปแบบอื่น ให้เปลี่ยนเป็นตามรูปแบบนั้น
				// ในที่นี้อยู่ในรูปแบบ 00-00-0000 เป็น d-m-Y  แบ่งด่วย - ดังนั้น ตัวแปรที่เป็นปี จะอยู่ใน array
				//  ตัวที่สอง arr_date[2] โดยเริ่มนับจาก 0 
				if(e.type=="mouseenter"){ var yearT=arr_date[2]-543; }		
				if(e.type=="mouseleave"){ var yearT=parseInt(arr_date[2])+543; }	
				dateValue=dateValue.replace(arr_date[2],yearT);
				$(this).val(dateValue);													
		}		
	});
});
</script>

	<link rel="stylesheet" href="./jquery/themes/ui-lightness/jquery.ui.all.css">
	<script src="./jquery/jquery-1.5.1.js"></script>
	<script src="./jquery/external/jquery.bgiframe-2.1.2.js"></script>
	<script src="./jquery/ui/jquery.ui.core.js"></script>
	<script src="./jquery/ui/jquery.ui.widget.js"></script>
	<script src="./jquery/ui/jquery.ui.mouse.js"></script>
	<script src="./jquery/ui/jquery.ui.draggable.js"></script>
	<script src="./jquery/ui/jquery.ui.position.js"></script>
	<script src="./jquery/ui/jquery.ui.resizable.js"></script>
	<script src="./jquery/ui/jquery.ui.dialog.js"></script>

	<script type="text/javascript">
		/*
		 * jQuery UI Dialog: Load Content via AJAX
		 * http://salman-w.blogspot.com/2013/05/jquery-ui-dialog-examples.html
		 */
		jQuery.noConflict();
		jQuery(function() {
			jQuery("#dialog").dialog({
			height: 600,
			width: 700,
			minHeight: 600,
			minWidth: 700,
			autoOpen: false,
			show: "blind",
			hide: "explode",
				modal: true,
				resizable: false,
			});
			jQuery(".dialogify").click(function(e) {
				e.preventDefault();
				jQuery("#dialog").html("");
				jQuery("#dialog").dialog("option", "title", "Loading...").dialog("open");
				jQuery("#dialog").load(this.href, function() {
					jQuery(this).dialog("option", "title", "ข้อมูลบุคลากร");
					//jQuery(this).dialog("option", "title", jQuery(this).find("h1").text());
					//jQuery(this).find("h1").remove();
				});
			});
		});	
	</script>
<div id="dialog"></div>