<?php
$Docout = getDocout($whereclause, $limitclause);
if (isset($_POST['type'])) {
	for ($i = 0; $i < count($_POST['type']); $i++) {	
				
		$doc_id = mysql_real_escape_string(stripslashes($_POST['id'][$i]));
		$remark = mysql_real_escape_string(stripslashes($_POST['remark'][$i]));
		
		if ($_POST['id'][$i] != "") {
			//echo $_POST['type'][$i];
			
			switch ($_POST['type'][$i]) {				
				case "added" :	
					
					
				break;
				
				case "edited":	
					if(isset($_POST['back'][$i])){
						$back = "checked";
						//echo "$i. UPDATE tbl_in_out_document SET back='$back', remark='$remark', back_date=NOW() WHERE doc_id=$doc_id AND doc_status=2";
						$bool = mysql_query("UPDATE tbl_in_out_document SET back='$back', remark='$remark', back_date=NOW() WHERE doc_id=$doc_id AND doc_status=2 ");
					}else{
						$back = "";
						//echo "$i. UPDATE tbl_in_out_document SET back='$back', remark='$remark', back_date=NULL WHERE doc_id=$doc_id AND doc_status=2";
						$bool = mysql_query("UPDATE tbl_in_out_document SET back='$back', remark='$remark', back_date=NULL WHERE doc_id=$doc_id AND doc_status=2");
					} 
					
					if($bool){
						$err = "<script>document.getElementById('msgwar').innerHTML = \"<span>ແກ້ໄຂຂໍ້ມູນສໍາເລັດ....! </span>\"</script>";
					}else{
						$err = "<script>document.getElementById('msgwar').innerHTML = \"<span class='error'>ແກ້ໄຂຂໍ້ມູນລົ້ມເຫຼວ,​ ກະລຸນາລອງໃໝ່.....! </span>\"</script>";
					}
				break;
				
			}
			if($bool) header("Location: ?d=document/docout/docout&start=".$_GET['start']);
		}
	}
}
/*------------------- Delete option ------------------------*/
if($_GET['action'] == "del" && $_GET['doc_id'] != "" && ($_SESSION['orgunitid_r']==null ||  $_SESSION['sys_type']=="counter" || $_SESSION['sys_type']=="secretary") ){
	$doc_id = mysql_real_escape_string(stripslashes($_GET['doc_id']));
	$start = $_GET['start'];

	$rs=mysql_query("DELETE FROM tbl_in_out_document WHERE doc_id = $doc_id AND doc_status=2");
	mysql_query("DELETE FROM tbl_manage_doc WHERE doc_id = $doc_id");

	if($rs){
		header("Location: ?d=document/docout/docout&start=$start");
	}else{
		echo "<h2>ERROR Delete</h2>";
	}
}
	
	