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

<?php
/** ensure this file is being included by a parent file */
defined( '_VALID_' ) or die( 'Direct Access to this location is not allowed.' );
if(!(($_SESSION['admin_person']=="person") or ($_SESSION['login_status']<=4 and $result_permission['p1']==1))){	
exit();
}

echo "<br />";
if(!(($index==1) or ($index==2) or ($index==5) or ($index==7))){
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>";
}
//ส่วนเพิ่มข้อมูล
if($index==1){
echo "<form id='frm1' name='frm1'>";
echo "<Center>";
echo "<Font color='#006666' Size='3'><B>เพิ่มวุฒิการศึกษา</B></Font>";
echo "</Cener>";
echo "<Br>";
echo "<Table   width='60%' Border='0'>";
echo "<Tr align='left'><Td width=20></Td><Td align='right'>รหัสวุฒิการศึกษา&nbsp;</Td><Td><Input Type='Text' Name='code' Size='5' onkeydown='integerOnly()'></Td></Tr>";

echo "<Tr align='left'><Td ></Td><Td align='right'>ชื่อวุฒิการศึกษา&nbsp;</Td><Td><Input Type='Text' Name='name' Size='40'></Td></Tr>";
echo "<Br>";
echo "</Table>";
echo "<Br>";
echo "<INPUT TYPE='button' name='smb' value='ตกลง' onclick='goto_url(1)'>
		&nbsp;&nbsp;<INPUT TYPE='button' name='back' value='ย้อนกลับ' onclick='goto_url(0)'>";

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=education_class&index=3&id=$_GET[id]\"'>
		&nbsp;&nbsp;<INPUT TYPE='button' name='back' value='ยกเลิก' onclick='location.href=\"?option=person&task=education_class\"'";
echo "</td></tr></table>";
}
//ส่วนลบข้อมูล
if($index==3){
$sql = "delete from person_education_class where id=$_GET[id]";
$dbquery = mysqli_query($connect,$sql);
}

//ส่วนเพิ่มข้อมูล
if($index==4){
$sql = "insert into person_education_class (code, name) values ( '$_POST[code]','$_POST[name]')";
$dbquery = mysqli_query($connect,$sql);
}
//ส่วนฟอร์มแก้ไขข้อมูล
if ($index==5){
echo "<form id='frm1' name='frm1'>";
echo "<Center>";
echo "<Font color='#006666' Size=3><B>แก้ไขวุฒิการศึกษา</B></Font>";
echo "</Cener>";
echo "<Br>";
$sql = "select * from  person_education_class where id='$_GET[id]'";
$dbquery = mysqli_query($connect,$sql);
$ref_result = mysqli_fetch_array($dbquery);

echo "<Table width='50%' Border='0'>";
echo "<Tr align='left'><Td width=20></Td><Td align='right'>รหัสวุฒิการศึกษา&nbsp;</Td><Td><Input Type='Text' Name='code' Size='5' value='$ref_result[code]' onkeydown='integerOnly()'></Td></Tr>";

echo "<Tr align='left'><Td ></Td><Td align='right'>ชื่อวุฒิการศึกษา&nbsp;</Td><Td><Input Type='Text' Name='name' Size='60' value='$ref_result[name]'></Td></Tr>";
echo "<Br>";
echo "</Table>";
echo "<Br><br>";
echo "<Input Type=Hidden Name='id' Value='$_GET[id]'>";
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 "</form>";
}

//ส่วนปรับปรุงข้อมูล
if ($index==6){
$sql = "update person_education_class set code='$_POST[code]',name='$_POST[name]' where id='$_POST[id]'";
$dbquery = mysqli_query($connect,$sql);
}

//ส่วนปรับปรุงวุฒิการศึกษา
if ($index==6.5){ 
$sql = "update person_sch_main set code='$_POST[code2]' where code='$_POST[code1]'";
$dbquery = mysqli_query($connect,$sql);
echo "<script>document.location.href='?option=person&task=person_sch';</script>\n";
}

if($index==7){
echo "<form id='frm1' name='frm1'>";
echo "<Center>";
echo "<Font color='#006666' Size='3'><B>ปรับปรุงรหัสวุฒิการศึกษา</B></Font>";
echo "</Cener>";
echo "<Br><Br>";
echo "<Table   width='30%' Border='0'>";
echo "<Tr align='left'><Td align='right'><b>รหัสวุฒิการศึกษาเดิม</b>&nbsp;&nbsp;</Td><Td><Input Type='Text' Name='code1' Size='5' onkeydown='integerOnly()'></Td></Tr>";
echo "<Tr align='left'><Td align='right'><b>รหัสวุฒิการศึกษาใหม่</b>&nbsp;&nbsp;</Td><Td><Input Type='Text' Name='code2' Size='5' onkeydown='integerOnly()'></Td></Tr>";
echo "<Tr align='left'><Td></Td><Td><Br><INPUT TYPE='button' name='smb' value='ตกลง' onclick='goto_url(2)'> <INPUT TYPE='button' name='back' value='ย้อนกลับ' onclick='goto_url(0)'></Td></Tr>";
echo "</Table>";

echo "</form>";
}

//ส่วนการแสดงผล
if(!(($index==1) or ($index==2) or ($index==5) or ($index==7))){

$sql = "select * from person_education_class order by code";
$dbquery = mysqli_query($connect,$sql);

echo  "<table width='50%' border='0' align='center'>";
echo "<Tr><Td align='left'><INPUT TYPE='button' name='smb' value='เพิ่มข้อมูล' onclick='location.href=\"?option=person&task=education_class&index=1\"'></Td><Td align='right'><INPUT TYPE='button' name='smb' value='ปรับปรุงรหัสวุฒิการศึกษา' onclick='location.href=\"?option=person&task=education_class&index=7\"'></Td></Tr>";
echo "</Table>";
echo  "<table width='50%' align='center' class='myTable'>";
echo "<th width='50'>ที่</th> <th>รหัส</th><th>วุฒิการศึกษา</th><th   width='50'>ลบ</th><th width='50'>แก้ไข</th>";
$N=1;
While ($result = mysqli_fetch_array($dbquery))
	{
		$id = $result['id'];
		$code= $result['code'];
		$name= $result['name'];
		echo "<Tr>
			<Td align=center>$N</Td>
			<Td align=center>$code</Td>
			<Td align=left>$name</Td>
			<Td align=center><a href=?option=person&task=education_class&index=2&id=$id><img src=images/drop.png border='0' alt='ลบ'></a></Td>
			<Td align=center><a href=?option=person&task=education_class&index=5&id=$id><img src=images/edit.png border='0' alt='แก้ไข'></a></Td>
		</Tr>";
$N++;  //*เกี่ยวข้องกับการแยกหน้า
	}
echo "</Table>";
}

?>
<script>
function goto_url(val){
	if(val==0){
		callfrm("?option=person&task=education_class");   // page ย้อนกลับ 
	}else if(val==1){
		if(frm1.code.value == ""){
			alert("กรุณากรอกรหัสวุฒิการศึกษา");
		}else if(frm1.name.value==""){
			alert("กรุณากรอกชื่อวุฒิการศึกษา");
		}else{
			callfrm("?option=person&task=education_class&index=4");   //page ประมวลผล
		}
	}else if(val==2){
		if(frm1.code1.value == ""){
			alert("กรุณากรอกรหัสเดิม");
		}else if(frm1.code2.value==""){
			alert("กรุณากรอกรหัสวุฒิการศึกษาใหม่");
		}else{
			callfrm("?option=person&task=education_class&index=6.5");   //page ประมวลผล
		}
	}
}

function goto_url_update(val){
	if(val==0){
		callfrm("?option=person&task=education_class");   // page ย้อนกลับ 
	}else if(val==1){
		if(frm1.code.value == ""){
			alert("กรุณากรอกรหัสวุฒิการศึกษา");
		}else if(frm1.name.value==""){
			alert("กรุณากรอกชื่อวุฒิการศึกษา");
		}else{
			callfrm("?option=person&task=education_class&index=6");   //page ประมวลผล
		}
	}
}
</script>