<?php
if (isset($_POST['type'])) {
	for ($i = 0; $i < count($_POST['type']); $i++) {	
		$pid = mysql_real_escape_string(stripslashes($_POST['id'][$i]));
		$name_la = mysql_real_escape_string(stripslashes($_POST['typename_la'][$i]));
		$name_eng = mysql_real_escape_string(stripslashes($_POST['typename_eng'][$i])); 
		$orgid = mysql_real_escape_string(stripslashes($_POST['orgid'][$i])); 
	
		/*--------------------------------------------------------------*/
		
		if ($_POST['typename_la'][$i] != "" ) {	
			//echo $_POST['type'][$i]."<br>";
			switch ($_POST['type'][$i]) {	
				case "added" :	
					if (mysql_num_rows(mysql_query("SELECT * FROM orgunittype WHERE unittypename = '$name_la' AND unittypenameeng='$name_eng'")) == 0) {
						sql_execute("INSERT INTO orgunittype(unittypename, unittypenameeng, orgid) VALUES('$name_la', '$name_eng', $orgid) ");
					}
				break;
					
				case "edited":		
					sql_execute("UPDATE orgunittype SET unittypename = '$name_la', unittypenameeng = '$name_eng', orgid = $orgid WHERE unittypeid = $pid");
				break;
			}
		}	
	}
}

$result = LoadEq($whereclause, $limitclause);
if(isset($_GET["del_id"]) && $_SESSION['role_id'] == 1){
	//$usered = $_SESSION['user_id'];
	$pid = mysql_real_escape_string(stripslashes($_GET['del_id']));
	
	$sql = "UPDATE orgunittype SET isdeleted = 1 WHERE unittypeid =$pid ";
	$result = mysql_query($sql, $conn);	
	if($result){
		header("Location: ?d=webmaster/manage/unittype");
	}else{
		echo "<h2 class='error'>ERROR Delete</h2>";
	}
}
