<?
session_start();

$_SESSION['Xpreviousurl']=$_SERVER['PHP_SELF'];

require_once('../includes.php');

//echo $_POST['job'];
//return;

$invalidaccess=msg_n_goto("../index.php",_Security._SecurityWarning.'\n'._EngineBlowOff);

if ($_GET['job']!=NULL){
	$myjob=$_GET['job'];
} else {
	$myjob=$_POST['job'];
}

$invalidaccess=msg_n_goto("../index.php",_Security._SecurityWarning.'\n'._EngineBlowOff.$myjob);
//echo $myjob;
//return;

// NOTE: job MUST NEVER CONTAIN SQL KEYWORDS LIKE insert, update, delete, union, etc.
// OR THEY WILL BE STRIPPED OFF!!

switch($myjob):

	//-------------login----------------
	case "general_login":
		$l=new login($_POST['username'],$_POST['password'],$_POST['language']);
	break;

	//-------------logout----------------
	case "general_logout":
		$l=new logout(md5("logoutuser"));
	break;	


	//-------------project---------------

	case "project_edit":
		require_once('../models/projectModel.php');
		$myprojectModelPMS=new projectModelPMS;
		$opresult=$myprojectModelPMS->updatedata_projectinhouse($_POST['projectpkey'], $_POST['projectinhouse'], $_POST['projectco'], 
							$_POST['personnelpkey1'], $_POST['personnelname1'], $_POST['personnelphone1'], $_POST['personnelpkey2'], $_POST['personnelname2'], $_POST['personnelphone2'], $_POST['personnelpkey3'], $_POST['personnelname3'], $_POST['personnelphone3'], $_POST['personnelpkey4'], $_POST['personnelname4'], $_POST['personnelphone4'], $_POST['personnelpkey5'], $_POST['personnelname5'], $_POST['personnelphone5'], $_POST['personnelpkey6'], $_POST['personnelname6'], $_POST['personnelphone6'], $_POST['personnelpkey7'], $_POST['personnelname7'], $_POST['personnelphone7'], $_POST['personnelpkey8'], $_POST['personnelname8'], $_POST['personnelphone8'], $_POST['personnelpkey9'], $_POST['personnelname9'], $_POST['personnelphone9'], $_POST['personnelpkey10'], $_POST['personnelname10'], $_POST['personnelphone10']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=project&task=view","Project Information updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update Project Information!");
			echo $e;
		}
	break;

	case "project_add":
		require_once('../models/projectModel.php');
		$myprojectModelPMS=new projectModelPMS;
		$opresult=$myprojectModelPMS->insertdata_projectfull($_POST['projectpkey'], $_POST['projectid'], $_POST['projectname1'], $_POST['projectdescription'], $_POST['projectclientname'], $_POST['projectclientphone'], $_POST['projectvalue'], $_POST['projectcommencementdate'], $_POST['projectcompletiondate'], $_POST['projectqsname'], $_POST['projectqsphone'], $_POST['projectpmname'], $_POST['projectpmphone'], $_POST['projectinhouse'], $_POST['projectco'], $_POST['projectmanual'],
							$_POST['personnelpkey1'], $_POST['personnelname1'], $_POST['personnelphone1'], $_POST['personnelpkey2'], $_POST['personnelname2'], $_POST['personnelphone2'], $_POST['personnelpkey3'], $_POST['personnelname3'], $_POST['personnelphone3'], $_POST['personnelpkey4'], $_POST['personnelname4'], $_POST['personnelphone4'], $_POST['personnelpkey5'], $_POST['personnelname5'], $_POST['personnelphone5'], $_POST['personnelpkey6'], $_POST['personnelname6'], $_POST['personnelphone6'], $_POST['personnelpkey7'], $_POST['personnelname7'], $_POST['personnelphone7'], $_POST['personnelpkey8'], $_POST['personnelname8'], $_POST['personnelphone8'], $_POST['personnelpkey9'], $_POST['personnelname9'], $_POST['personnelphone9'], $_POST['personnelpkey10'], $_POST['personnelname10'], $_POST['personnelphone10']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=project&task=open&itemid=".$opresult,"New Project added successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to add New Project!");
			echo $e;
		}
	break;

	case "project_editfull":
		require_once('../models/projectModel.php');
		$myprojectModelPMS=new projectModelPMS;
		$opresult=$myprojectModelPMS->updatedata_projectfull($_POST['projectpkey'], $_POST['projectid'], $_POST['projectname1'], $_POST['projectdescription'], $_POST['projectclientname'], $_POST['projectclientphone'], $_POST['projectvalue'], $_POST['projectcommencementdate'], $_POST['projectcompletiondate'], $_POST['projectqsname'], $_POST['projectqsphone'], $_POST['projectpmname'], $_POST['projectpmphone'], $_POST['projectinhouse'], $_POST['projectco'], $_POST['projectmanual'],
							$_POST['personnelpkey1'], $_POST['personnelname1'], $_POST['personnelphone1'], $_POST['personnelpkey2'], $_POST['personnelname2'], $_POST['personnelphone2'], $_POST['personnelpkey3'], $_POST['personnelname3'], $_POST['personnelphone3'], $_POST['personnelpkey4'], $_POST['personnelname4'], $_POST['personnelphone4'], $_POST['personnelpkey5'], $_POST['personnelname5'], $_POST['personnelphone5'], $_POST['personnelpkey6'], $_POST['personnelname6'], $_POST['personnelphone6'], $_POST['personnelpkey7'], $_POST['personnelname7'], $_POST['personnelphone7'], $_POST['personnelpkey8'], $_POST['personnelname8'], $_POST['personnelphone8'], $_POST['personnelpkey9'], $_POST['personnelname9'], $_POST['personnelphone9'], $_POST['personnelpkey10'], $_POST['personnelname10'], $_POST['personnelphone10']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=project&task=view","Project Information updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update Project Information!");
			echo $e;
		}
	break;

	case "project_remove":
		require_once('../models/projectModel.php');
		$myprojectModelPMS=new projectModelPMS;
		$opresult=$myprojectModelPMS->deletedata_project($_POST['projectpkey']);
		if ($opresult!=false) {
			$_SESSION['Xprojectpkey']="";
			$_SESSION['Xprojectid']="";
			$_SESSION['Xprojectname']="";
			$_SESSION['Xprojectdesc']="";
			$m=msg_n_goto("../index.php?module=project&task=select","Project Information deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete Project Information!");
			echo $e;
		}
	break;

	case "project_personneladd":
		require_once('../models/projectModel.php');
		$myprojectModelPMS=new projectModelPMS;
		$opresult=$myprojectModelPMS->insertdata_personnel($_POST['personnelpkey'], $_POST['personnelprojectpkey'], $_POST['personnelname'], $_POST['personnelphone']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=project&task=personnel","Project Personnel saved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to save new Project Personnel!");
			echo $e;
		}
	break;

	case "project_personneledit":
		require_once('../models/projectModel.php');
		$myprojectModelPMS=new projectModelPMS;
		$opresult=$myprojectModelPMS->updatedata_personnel($_POST['personnelpkey'], $_POST['personnelprojectpkey'], $_POST['personnelname'], $_POST['personnelphone']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=project&task=personnel","Project Personnel updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update Project Personnel!");
			echo $e;
		}
	break;

	case "project_personnelremove":
		require_once('../models/projectModel.php');
		$myprojectModelPMS=new projectModelPMS;
		$opresult=$myprojectModelPMS->deletedata_personnel($_POST['personnelpkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=project&task=personnel","Project Personnel deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete Project Personnel!");
			echo $e;
		}
	break;


	//-------------supplier---------------

	case "supplier_add":
		require_once('../models/supplierModel.php');
		$mysupplierModel=new supplierModel;
		$opresult=$mysupplierModel->insertdata_supplierfull($_POST['supplier_pkey'], $_POST['supplier_regid'], $_POST['supplier_regno'], $_POST['supplier_name'], $_POST['supplier_address'], $_POST['supplier_phone'], $_POST['supplier_fax'], $_POST['supplier_email'], $_POST['supplier_directors'], $_POST['supplier_pic'], $_POST['supplier_picphone'], $_POST['supplier_ct'], $_POST['supplier_nob'], $_POST['supplier_products'], $_POST['supplier_bgratio'], $_POST['supplier_personalamount'], $_POST['supplier_regdate'], $_POST['supplier_approved'], $_POST['supplier_status'], 
								    $_POST['contact_pkey0'], $_POST['contact_supplierpkey0'], $_POST['contact_name0'], $_POST['contact_designation0'], $_POST['contact_phone0'], $_POST['contact_email0'], $_POST['contact_pkey1'], $_POST['contact_supplierpkey1'], $_POST['contact_name1'], $_POST['contact_designation1'], $_POST['contact_phone1'], $_POST['contact_email1'], $_POST['contact_pkey2'], $_POST['contact_supplierpkey2'], $_POST['contact_name2'], $_POST['contact_designation2'], $_POST['contact_phone2'], $_POST['contact_email2'], $_POST['contact_main'], 
								    $_POST['bg_pkey0'], $_POST['bg_supplierpkey0'], $_POST['bg_bankamount0'], $_POST['bg_projectname0'], $_POST['bg_startdate0'], $_POST['bg_enddate0'], $_POST['bg_bankname0'], $_POST['bg_pkey1'], $_POST['bg_supplierpkey1'], $_POST['bg_bankamount1'], $_POST['bg_projectname1'], $_POST['bg_startdate1'], $_POST['bg_enddate1'], $_POST['bg_bankname1'], $_POST['bg_pkey2'], $_POST['bg_supplierpkey2'], $_POST['bg_bankamount2'], $_POST['bg_projectname2'], $_POST['bg_startdate2'], $_POST['bg_enddate2'], $_POST['bg_bankname2'], $_POST['bg_pkey3'], $_POST['bg_supplierpkey3'], $_POST['bg_bankamount3'], $_POST['bg_projectname3'], $_POST['bg_startdate3'], $_POST['bg_enddate3'], $_POST['bg_bankname3'], $_POST['bg_pkey4'], $_POST['bg_supplierpkey4'], $_POST['bg_bankamount4'], $_POST['bg_projectname4'], $_POST['bg_startdate4'], $_POST['bg_enddate4'], $_POST['bg_bankname4']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=supplier&task=main","Supplier saved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to save new Supplier!");
			echo $e;
		}
	break;

	case "supplier_edit":
		require_once('../models/supplierModel.php');
		$mysupplierModel=new supplierModel;
		$opresult=$mysupplierModel->updatedata_supplierfull($_POST['supplier_pkey'], $_POST['supplier_regid'], $_POST['supplier_regno'], $_POST['supplier_name'], $_POST['supplier_address'], $_POST['supplier_phone'], $_POST['supplier_fax'], $_POST['supplier_email'], $_POST['supplier_directors'], $_POST['supplier_pic'], $_POST['supplier_picphone'], $_POST['supplier_ct'], $_POST['supplier_nob'], $_POST['supplier_products'], $_POST['supplier_bgratio'], $_POST['supplier_personalamount'], $_POST['supplier_regdate'], $_POST['supplier_approved'], $_POST['supplier_status'], 
								    $_POST['contact_pkey0'], $_POST['contact_supplierpkey0'], $_POST['contact_name0'], $_POST['contact_designation0'], $_POST['contact_phone0'], $_POST['contact_email0'], $_POST['contact_pkey1'], $_POST['contact_supplierpkey1'], $_POST['contact_name1'], $_POST['contact_designation1'], $_POST['contact_phone1'], $_POST['contact_email1'], $_POST['contact_pkey2'], $_POST['contact_supplierpkey2'], $_POST['contact_name2'], $_POST['contact_designation2'], $_POST['contact_phone2'], $_POST['contact_email2'], $_POST['contact_main'], 
								    $_POST['bg_pkey0'], $_POST['bg_supplierpkey0'], $_POST['bg_bankamount0'], $_POST['bg_projectname0'], $_POST['bg_startdate0'], $_POST['bg_enddate0'], $_POST['bg_bankname0'], $_POST['bg_pkey1'], $_POST['bg_supplierpkey1'], $_POST['bg_bankamount1'], $_POST['bg_projectname1'], $_POST['bg_startdate1'], $_POST['bg_enddate1'], $_POST['bg_bankname1'], $_POST['bg_pkey2'], $_POST['bg_supplierpkey2'], $_POST['bg_bankamount2'], $_POST['bg_projectname2'], $_POST['bg_startdate2'], $_POST['bg_enddate2'], $_POST['bg_bankname2'], $_POST['bg_pkey3'], $_POST['bg_supplierpkey3'], $_POST['bg_bankamount3'], $_POST['bg_projectname3'], $_POST['bg_startdate3'], $_POST['bg_enddate3'], $_POST['bg_bankname3'], $_POST['bg_pkey4'], $_POST['bg_supplierpkey4'], $_POST['bg_bankamount4'], $_POST['bg_projectname4'], $_POST['bg_startdate4'], $_POST['bg_enddate4'], $_POST['bg_bankname4']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=supplier&task=main","Supplier updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update Supplier!");
			echo $e;
		}
	break;

	case "supplier_remove":
		require_once('../models/supplierModel.php');
		$mysupplierModel=new supplierModel;
		$opresult=$mysupplierModel->deletedata_supplier($_POST['supplier_pkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=supplier&task=main","Supplier deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete Supplier!");
			echo $e;
		}
	break;

	case "supplier_bgadd":
		require_once('../models/supplierModel.php');
		$mysupplierModel=new supplierModel;
		$opresult=$mysupplierModel->insertdata_bankguarantee($_POST['bg_pkey'], $_POST['bg_supplierpkey'], $_POST['bg_bankamount'], $_POST['bg_projectname'], $_POST['bg_startdate'], $_POST['bg_enddate'], $_POST['bg_bankname']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=supplier&task=listbg&itemid=".$_POST['bg_supplierpkey'],"Bank Guarantee saved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to save new Bank Guarantee!");
			echo $e;
		}
	break;

	case "supplier_bgedit":
		require_once('../models/supplierModel.php');
		$mysupplierModel=new supplierModel;
		$opresult=$mysupplierModel->updatedata_bankguarantee($_POST['bg_pkey'], $_POST['bg_supplierpkey'], $_POST['bg_bankamount'], $_POST['bg_projectname'], $_POST['bg_startdate'], $_POST['bg_enddate'], $_POST['bg_bankname']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=supplier&task=listbg&itemid=".$_POST['bg_supplierpkey'],"Bank Guarantee updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update Bank Guarantee!");
			echo $e;
		}
	break;

	case "supplier_bgremove":
		require_once('../models/supplierModel.php');
		$mysupplierModel=new supplierModel;
		$opresult=$mysupplierModel->deletedata_bankguarantee($_POST['bg_pkey'], $_POST['bg_supplierpkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=supplier&task=listbg&itemid=".$_POST['bg_supplierpkey'],"Bank Guarantee deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete Bank Guarantee!");
			echo $e;
		}
	break;

	case "supplier_approvaladd":
		require_once('../models/supplierModel.php');
		$mysupplierModel=new supplierModel;
		$opresult=$mysupplierModel->insertdata_approval($_POST['approval_pkey'], $_POST['approval_supplierpkey'], $_POST['approval_type'], $_POST['approval_userpkey'], $_POST['approval_officername'], $_POST['approval_date'], $_POST['approval_status'], $_POST['approval_remarks']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=supplier&task=main","Supplier recommended/approved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to recommend/approve Supplier!");
			echo $e;
		}
	break;


	//-------------trades---------------

	case "trade_add":
		require_once('../models/tradeModel.php');
		$mytradeModel=new tradeModel;
		$opresult=$mytradeModel->insertdata_trade($_POST['tradepkey'], $_POST['tradeparentpkey'], $_POST['tradelevel'], $_POST['tradecode'], $_POST['tradedescription'], $_POST['tradetype'], $_POST['tradeunit'], $_POST['tradesubcontype'], $_POST['traderemarks'], $_POST['tradereceivedsetting'], $_POST['tradestatus']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=trade&task=main","Category saved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to save new Category!");
			echo $e;
		}
	break;

	case "trade_edit":
		require_once('../models/tradeModel.php');
		$mytradeModel=new tradeModel;
		$opresult=$mytradeModel->updatedata_trade($_POST['tradepkey'], $_POST['tradeparentpkey'], $_POST['tradelevel'], $_POST['tradecode'], $_POST['tradedescription'], $_POST['tradetype'], $_POST['tradeunit'], $_POST['tradesubcontype'], $_POST['traderemarks'], $_POST['tradereceivedsetting'], $_POST['tradestatus']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=trade&task=main&babi=".$_POST['tradereceivedsetting'],"Category updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update Category!");
			echo $e;
		}
	break;

	case "trade_remove":
		require_once('../models/tradeModel.php');
		$mytradeModel=new tradeModel;
		$opresult=$mytradeModel->deletedata_trade($_POST['tradepkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=trade&task=main","Category deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete Category!");
			echo $e;
		}
	break;


	//-------------mbl---------------

	case "mbl_add":
		require_once('../models/mblModel.php');
		$mymblModel=new mblModel;
		$opresult=$mymblModel->insertdata_mblitem($_POST['item_pkey'], $_POST['item_projectpkey'], $_POST['item_subtradepkey'], $_POST['item_subsubtradepkey'], $_POST['item_level'], $_POST['item_code'], $_POST['item_description'], $_POST['item_unit'], $_POST['item_quantity'], $_POST['item_rate'], $_POST['item_amount']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=mbl&task=list","MBL Item saved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to save new MBL Item!");
			echo $e;
		}
	break;

	case "mbl_edit":
		require_once('../models/mblModel.php');
		$mymblModel=new mblModel;
		$opresult=$mymblModel->updatedata_mblitem($_POST['item_pkey'], $_POST['item_projectpkey'], $_POST['item_subtradepkey'], $_POST['item_subsubtradepkey'], $_POST['item_level'], $_POST['item_code'], $_POST['item_description'], $_POST['item_unit'], $_POST['item_quantity'], $_POST['item_rate'], $_POST['item_amount']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=mbl&task=list","MBL Item updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update MBL Item!");
			echo $e;
		}
	break;

	case "mbl_remove":
		require_once('../models/mblModel.php');
		$mymblModel=new mblModel;
		$opresult=$mymblModel->deletedata_mblitem($_POST['item_pkey'], $_POST['item_projectpkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=mbl&task=list","MBL Item deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete MBL Item!");
			echo $e;
		}
	break;

	case "mbl_submit":
		require_once('../models/mblModel.php');
		$mymblModel=new mblModel;
		$opresult=$mymblModel->insertdata_approval("", "1", $_POST['userpkey'], $_POST['officername'], $_POST['date'], $_POST['status'], $_POST['remarks']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=mbl&task=view","MBL submitted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to submit MBL!");
			echo $e;
		}
	break;

	case "mbl_approve":
		require_once('../models/mblModel.php');
		$mymblModel=new mblModel;
		$opresult=$mymblModel->insertdata_approval("", "3", $_POST['userpkey'], $_POST['officername'], $_POST['date'], $_POST['status'], $_POST['remarks']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=mbl&task=view","MBL approved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to approve MBL!");
			echo $e;
		}
	break;


	//-------------mro---------------

	case "mro_add":
		require_once('../models/mroModel.php');
		$mymroModel=new mroModel;
		$opresult=$mymroModel->insertdata_mro($_POST['mro_pkey'], $_POST['mro_projectpkey'], $_POST['mro_type'], $_POST['mro_id'], $_POST['mro_subtradepkey'], $_POST['mro_subconref'], $_POST['mro_clientref'], $_POST['mro_requestdate'], $_POST['mro_deliverydate'], $_POST['mro_debitaccount'], $_POST['mro_remarks'], $_POST['mro_subcons'], $_POST['mro_status']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=mro&task=edit&itemid=".$opresult,"MRO saved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to save new MRO!");
			echo $e;
		}
	break;

	case "mro_edit":
		require_once('../models/mroModel.php');
		$mymroModel=new mroModel;
		$opresult=$mymroModel->updatedata_mro($_POST['mro_pkey'], $_POST['mro_projectpkey'], $_POST['mro_type'], $_POST['mro_id'], $_POST['mro_subtradepkey'], $_POST['mro_subconref'], $_POST['mro_clientref'], $_POST['mro_requestdate'], $_POST['mro_deliverydate'], $_POST['mro_debitaccount'], $_POST['mro_remarks'], $_POST['mro_subcons'], $_POST['mro_status']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=mro&task=edit&itemid=".$opresult,"MRO updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update MRO!");
			echo $e;
		}
	break;

	case "mro_remove":
		require_once('../models/mroModel.php');
		$mymroModel=new mroModel;
		$opresult=$mymroModel->deletedata_mro($_POST['mro_pkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=mro&task=list","MRO deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete MRO!");
			echo $e;
		}
	break;

	case "mro_additem":
		require_once('../models/mroModel.php');
		$mymroModel=new mroModel;
		$opresult=$mymroModel->insertdata_mroitem($_POST['item_pkey'], $_POST['item_mropkey'], $_POST['item_no'], $_POST['item_code'], $_POST['item_maintradepkey'], $_POST['item_submaintradepkey'], $_POST['item_subtradepkey'], $_POST['item_subsubtradepkey'], $_POST['item_trisubtradepkey'], $_POST['item_description'], $_POST['item_unit'], $_POST['item_quantity'], $_POST['item_totalexceed'], $_POST['item_purpose'], $_POST['item_remarks'], $_POST['projectpkey'], $_POST['mrotype'], $_POST['mro_exceedpkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=mro&task=edit&itemid=".$_POST['item_mropkey'],"MRO Item saved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to save new MRO Item!");
			echo $e;
		}
	break;

	case "mro_edititem":
		require_once('../models/mroModel.php');
		$mymroModel=new mroModel;
		$opresult=$mymroModel->updatedata_mroitem($_POST['item_pkey'], $_POST['item_mropkey'], $_POST['item_no'], $_POST['item_code'], $_POST['item_maintradepkey'], $_POST['item_submaintradepkey'], $_POST['item_subtradepkey'], $_POST['item_subsubtradepkey'], $_POST['item_trisubtradepkey'], $_POST['item_description'], $_POST['item_unit'], $_POST['item_quantity'], $_POST['item_totalexceed'], $_POST['item_purpose'], $_POST['item_remarks'], $_POST['projectpkey'], $_POST['mrotype'], $_POST['mro_exceedpkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=mro&task=edit&itemid=".$_POST['item_mropkey'],"MRO Item updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update MRO Item!");
			echo $e;
		}
	break;

	case "mro_removeitem":
		require_once('../models/mroModel.php');
		$mymroModel=new mroModel;
		$opresult=$mymroModel->deletedata_mroitem($_POST['item_pkey'], $_POST['item_mropkey'], $_POST['projectpkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=mro&task=edit&itemid=".$_POST['item_mropkey'],"MRO Item deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete MRO Item!");
			echo $e;
		}
	break;

	case "mro_approve":
		require_once('../models/mroModel.php');
		$mymroModel=new mroModel;
		$opresult=$mymroModel->insertdata_approval("", $_POST['mropkey'], $_POST['type'], $_POST['userpkey'], $_POST['officername'], $_POST['date'], $_POST['status'], $_POST['remarks']);
		if ($opresult!=false) {
			if ($_POST['status']=="1") {
				if ($_POST['type']=="2") {
					$m=msg_n_goto("../index.php?module=mro&task=list","MRO Recommended successfully!");
				} else if ($_POST['type']=="3") {
					$m=msg_n_goto("../index.php?module=mro&task=list","MRO Approved successfully!");
				}
			} else if ($_POST['status']=="2") {
				$m=msg_n_goto("../index.php?module=mro&task=list","MRO Cancelled successfully!");
			} else if ($_POST['status']=="3") {
				$m=msg_n_goto("../index.php?module=mro&task=list","MRO Rejected successfully!");
			}
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to approve/reject/cancel MRO!");
			echo $e;
		}
	break;


	//-------------itq---------------

	case "itq_add":
		require_once('../models/itqModel.php');
		$myitqModel=new itqModel;
		$opresult=$myitqModel->insertdata_itq($_POST['itq_pkey'], $_POST['itq_mropkey'], $_POST['itq_subtradepkey'], $_POST['itq_date'], $_POST['itq_from'], $_POST['itq_type'], $_POST['itq_returndate'], $_POST['itq_supppkey'], $_POST['itq_approvealert']);
		if ($opresult!=false) {
			//$m=msg_n_goto("../index.php?module=itq&task=list&itemid=".$opresult,"ITQ generated successfully!");
			$m=msg_n_goto("../index.php?module=itq&task=printall&itemid=".$opresult,"ITQ generated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to generate ITQ!");
			echo $e;
		}
	break;

	case "itq_edit":
		require_once('../models/itqModel.php');
		$myitqModel=new itqModel;
		$opresult=$myitqModel->updatedata_itq($_POST['itq_pkey'], $_POST['itq_mropkey'], $_POST['itq_subtradepkey'], $_POST['itq_date'], $_POST['itq_from'], $_POST['itq_type'], $_POST['itq_returndate'], $_POST['itq_supppkey'], $_POST['itq_approvealert']);
		if ($opresult!=false) {
			//$m=msg_n_goto("../index.php?module=itq&task=list","ITQ updated successfully!");
			$m=msg_n_goto("../index.php?module=itq&task=printall&itemid=".$opresult,"ITQ updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update ITQ!");
			echo $e;
		}
	break;

	// used for evaluation, review and approval (NOT ANY MORE! - 24 april 2010)
	case "itq_saveeval":
		require_once('../models/itqModel.php');
		$myitqModel=new itqModel;
		$opresult=$myitqModel->insertdata_itqevaluation($_POST['eval_itqpkey'], $_POST['eval_mropkey'], $_POST['eval_itempkeys'], $_POST['eval_supplierpkeys'], $_POST['eval_supplierrates'], $_POST['eval_awardedquantities'], $_POST['eval_supplierremarks'], $_POST['eval_supplierselected'], $_POST['eval_zikayrates'], $_POST['eval_transportrates'], $_POST['eval_approvaltype']);
		$ztotal = "UPDATE zikay_pmsv5.mro_items SET zikaytotal ='".$_POST['zikaytotal']."' WHERE item_mropkey = '".$_POST['eval_mropkey']."'";
		mysql_query($ztotal);
		if ($opresult!=false) {
			//$m=msg_n_goto("../index.php?module=itq&task=list","Quotation Evaluation updated successfully!");
			//$m=msg_n_goto("../index.php?module=itq&task=approve&itemid=" .$_POST['eval_mropkey']. "","Quotation Evaluation updated successfully!");
			$m=msg_n_goto("../index.php?module=itq&task=evaluate&itemid=" .$_POST['eval_mropkey']. "","Quotation Evaluation updated successfully!");
			
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update Quotation Evaluation!");
			echo $e;
		}
	break;

	case "itq_approve":
		require_once('../models/itqModel.php');
		$myitqModel=new itqModel;
		//$opresult=$myitqModel->updatedata_approval("", $_POST['itqpkey'], $_POST['mropkey'], $_POST['type'], $_POST['userpkey'], $_POST['officername'], $_POST['date'], $_POST['status'], $_POST['remarks']);
		//if ($opresult!=false) {
			if ($_POST['status']=="1") {
				$opresult=$myitqModel->updatedata_approval("", $_POST['itqpkey'], $_POST['mropkey'], $_POST['type'], $_POST['userpkey'], $_POST['officername'], $_POST['date'], $_POST['status'], $_POST['remarks']);
		
					$m=msg_n_goto("../index.php?module=itq&task=list","RFQ Approved successfully!");
				
			} else if ($_POST['status']=="2") {
			    $opresult=$myitqModel->updatedata_approval("", $_POST['itqpkey'], $_POST['mropkey'], $_POST['type'], $_POST['userpkey'], $_POST['officername'], $_POST['date'], $_POST['status'], $_POST['remarks']);
		
				$m=msg_n_goto("../index.php?module=itq&task=list","RFQ Cancelled successfully!");
			} else if ($_POST['status']=="3") {
				$opresult=$myitqModel->updatedata_approval("", $_POST['itqpkey'], $_POST['mropkey'], $_POST['type'], $_POST['userpkey'], $_POST['officername'], $_POST['date'], $_POST['status'], $_POST['remarks']);
		
				$m=msg_n_goto("../index.php?module=itq&task=list","RFQ Rejected successfully!");
			} else if ($_POST['status']=='4'){
			
			$rek = "UPDATE zikay_pmsv5.itq_details SET itq_approval1 ='".$_SESSION['Xstaffname']."', rekemen_remark ='".$_POST['remarks']."' WHERE itq_mropkey ='".$_POST['mropkey']."'";
			mysql_query($rek);
			//echo $rek;
			$m=msg_n_goto("../index.php?module=itq&task=list","RFQ Recommended successfully!");
			}
			echo $m;
		//} else {
			//$e=error_n_goto(-1,"Error: Failed to approve/reject/cancel RFQ!");
			//$e=error_n_goto(-1,"Approve: Successfull");
			//echo $e;
		//}
	break;


	//-------------po---------------

	case "po_add":
		require_once('../models/poModel.php');
		$mypoModel=new poModel;
		$opresult=$mypoModel->insertdata_po($_POST['po_pkey'], $_POST['po_projectpkey'], $_POST['po_mropkey'], $_POST['po_itqpkey'], $_POST['po_supplierpkey'], $_POST['po_no'], $_POST['po_date'], $_POST['po_top'], $_POST['po_attn'], $_POST['po_literaltotal'], $_POST['po_co'], $_POST['po_personnelpkey'], $_POST['po_contactperson'], $_POST['po_contactnumber'], $_POST['po_requestor'], $_POST['po_approver']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=po&task=edit&itemid=".$opresult,"PO saved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to save new PO!");
			echo $e;
		}
	break;

	case "po_edit":
		require_once('../models/poModel.php');
		$mypoModel=new poModel;
		$opresult=$mypoModel->updatedata_po($_POST['po_pkey'], $_POST['po_projectpkey'], $_POST['po_mropkey'], $_POST['po_itqpkey'], $_POST['po_supplierpkey'], $_POST['po_no'], $_POST['po_date'], $_POST['po_top'], $_POST['po_attn'], $_POST['po_literaltotal'], $_POST['po_co'], $_POST['po_personnelpkey'], $_POST['po_contactperson'], $_POST['po_contactnumber'], $_POST['po_requestor'], $_POST['po_approver']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=po&task=view&itemid=".$opresult,"PO updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update PO!");
			echo $e;
		}
	break;

	case "po_remove":
		require_once('../models/poModel.php');
		$mypoModel=new poModel;
		$opresult=$mypoModel->deletedata_po($_POST['po_pkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=po&task=list","PO deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete PO!");
			echo $e;
		}
	break;

	case "po_additem":
		require_once('../models/poModel.php');
		$mypoModel=new poModel;
		$opresult=$mypoModel->insertdata_poitem($_POST['item_pkey'], $_POST['item_popkey'], $_POST['item_no'], $_POST['item_subsubtradepkey'], $_POST['item_code'], $_POST['item_description'], $_POST['item_unit'], $_POST['item_quantity'], $_POST['item_rate'], $_POST['item_remarks']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=po&task=edit&itemid=".$_POST['item_popkey'],"PO Item saved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to save new PO Item!");
			echo $e;
		}
	break;

	case "po_edititem":
		require_once('../models/poModel.php');
		$mypoModel=new poModel;
		$opresult=$mypoModel->updatedata_poitem($_POST['item_pkey'], $_POST['item_popkey'], $_POST['item_no'], $_POST['item_subsubtradepkey'], $_POST['item_code'], $_POST['item_description'], $_POST['item_unit'], $_POST['item_quantity'], $_POST['item_rate'], $_POST['item_remarks']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=po&task=edit&itemid=".$_POST['item_popkey'],"PO Item updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update PO Item!");
			echo $e;
		}
	break;

	case "po_removeitem":
		require_once('../models/poModel.php');
		$mypoModel=new poModel;
		$opresult=$mypoModel->deletedata_poitem($_POST['item_pkey'], $_POST['item_popkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=po&task=edit&itemid=".$_POST['item_popkey'],"PO Item deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete PO Item!");
			echo $e;
		}
	break;

	case "po_approve":
		require_once('../models/poModel.php');
		$mypoModel=new poModel;
		$opresult=$mypoModel->insertdata_approval("", $_POST['popkey'], $_POST['type'], $_POST['userpkey'], $_POST['officername'], $_POST['date'], $_POST['status'], $_POST['remarks']);
		if ($opresult!=false) {
			if ($_POST['status']=="1") {
				$m=msg_n_goto("../index.php?module=po&task=main","PO Approved successfully!");
			} else if ($_POST['status']=="2") {
				$m=msg_n_goto("../index.php?module=po&task=main","PO Cancelled successfully!");
			} else if ($_POST['status']=="3") {
				$m=msg_n_goto("../index.php?module=po&task=main","PO Item Cancelled successfully!");
			}
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to approve/reject/cancel PO!");
			echo $e;
		}
	break;

	
	//-------------do---------------

	case "do_add":
		require_once('../models/doModel.php');
		$mydoModel=new doModel;
		//$opresult=$mydoModel->insertdata_do($_POST['do_pkey'], $_POST['do_projectpkey'], $_POST['do_supplierpkey'], $_POST['do_no'], $_POST['do_date'], $_POST['do_sono'], $_POST['do_accountno'], $_POST['do_address'], $_POST['do_lorryno'], $_POST['do_transportco'], $_POST['do_drivername'], $_POST['do_drivericno'], $_POST['do_receiverco'], $_POST['do_receivername'], $_POST['do_receivericno'], $_POST['do_remarks']);
		$opresult=$mydoModel->insertdata_do($_POST['po_pkey'], $_POST['po_projectpkey'], $_POST['po_supplierpkey'], $_POST['do_actions'], $_POST['do_pkeys'], $_POST['do_nos'], $_POST['do_dates'], $_POST['do_items'], $_POST['do_quantities'], $_POST['do_remarks']);
		if ($opresult!=false) {
			//$m=msg_n_goto("../index.php?module=do&task=edit&itemid=".$opresult,"DO saved successfully!");
			//$m=msg_n_goto("../index.php?module=do&task=main","DO updated successfully!");
			if ($opresult=="complete") {
				$m=msg_n_goto("../index.php?module=po&task=main&tabid=1","PO is Complete and has been Closed automatically!");
			} else {
				$m=msg_n_goto("../index.php?module=do&task=add&itemid=".$_POST['po_pkey'],"DO(s) updated successfully!");
			}
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update DO(s)!");
			echo $e;
		}
	break;

	case "do_edit":
		require_once('../models/doModel.php');
		$mydoModel=new doModel;
		$opresult=$mydoModel->updatedata_do($_POST['do_pkey'], $_POST['do_projectpkey'], $_POST['do_supplierpkey'], $_POST['do_no'], $_POST['do_date'], $_POST['do_sono'], $_POST['do_accountno'], $_POST['do_address'], $_POST['do_lorryno'], $_POST['do_transportco'], $_POST['do_drivername'], $_POST['do_drivericno'], $_POST['do_receiverco'], $_POST['do_receivername'], $_POST['do_receivericno'], $_POST['do_remarks']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=do&task=edit&itemid=".$opresult,"DO updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update DO!");
			echo $e;
		}
	break;

	case "do_remove":
                /*
		require_once('../models/doModel.php');
		$mydoModel=new doModel;
		$opresult=$mydoModel->deletedata_do($_POST['do_pkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=do&task=list","DO deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete DO!");
			echo $e;
		}
		*/
		require_once('../models/doModel.php');
		$mydoModel=new doModel;
		$opresult=$mydoModel->deletedata_do($_POST['po_pkey'], $_POST['po_projectpkey'], $_POST['po_supplierpkey'], $_POST['do_actions'], $_POST['do_pkeys'], $_POST['do_nos'], $_POST['do_dates'], $_POST['do_items'], $_POST['do_quantities'], $_POST['do_remarks']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=do&task=add&itemid=".$_POST['po_pkey'],"DO updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update DO!");
			echo $e;
		}
	break;

	case "do_additem":
		require_once('../models/doModel.php');
		$mydoModel=new doModel;
		$opresult=$mydoModel->insertdata_doitem($_POST['item_pkey'], $_POST['item_dopkey'], $_POST['item_popkey'], $_POST['item_no'], $_POST['item_subsubtradepkey'], $_POST['item_description'], $_POST['item_unit'], $_POST['item_quantity'], $_POST['item_accepted']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=do&task=edit&itemid=".$_POST['item_dopkey'],"DO Item saved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to save new DO Item!");
			echo $e;
		}
	break;

	case "do_edititem":
		require_once('../models/doModel.php');
		$mydoModel=new doModel;
		$opresult=$mydoModel->updatedata_doitem($_POST['item_pkey'], $_POST['item_dopkey'], $_POST['item_popkey'], $_POST['item_no'], $_POST['item_subsubtradepkey'], $_POST['item_description'], $_POST['item_unit'], $_POST['item_quantity'], $_POST['item_accepted']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=do&task=edit&itemid=".$_POST['item_dopkey'],"DO Item updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update DO Item!");
			echo $e;
		}
	break;

	case "do_removeitem":
		require_once('../models/doModel.php');
		$mydoModel=new doModel;
		$opresult=$mydoModel->deletedata_doitem($_POST['item_pkey'], $_POST['item_dopkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=do&task=edit&itemid=".$_POST['item_dopkey'],"DO Item deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete DO Item!");
			echo $e;
		}
	break;

	case "do_closepo":
		require_once('../models/poModel.php');
		$mypoModel=new poModel;
		$opresult=$mypoModel->updatestatus_po($_POST['po_pkey'], "3");
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=po&task=main&tabid=1","PO Closed successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to Close PO!");
			echo $e;
		}
	break;


	//-------------invoice-----------------------

	/*
	case "invoice_add":
		require_once('../models/invoiceModel.php');
		$myinvoiceModel=new invoiceModel;
		$opresult=$myinvoiceModel->insertdata_invoice($_POST['invoice_pkey'], $_POST['invoice_projectpkey'], $_POST['invoice_popkeylist'], $_POST['invoice_dopkeylist'], $_POST['invoice_sono'], $_POST['invoice_no'], $_POST['invoice_date'], $_POST['invoice_terms'], $_POST['invoice_salesman'], $_POST['invoice_currency'], $_POST['invoice_customerno']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=invoice&task=edit&itemid=".$opresult,"Invoice saved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to save new Invoice!");
			echo $e;
		}
	break;
	*/

	case "invoice_add":
		require_once('../models/invoiceModel.php');
		$myinvoiceModel=new invoiceModel;
		$opresult=$myinvoiceModel->insertdata_invoice($_POST['po_pkey'], $_POST['po_projectpkey'], $_POST['po_supplierpkey'], $_POST['invoice_actions'], $_POST['invoice_pkeys'], $_POST['invoice_nos'], $_POST['invoice_dates'], $_POST['invoice_items'], $_POST['invoice_quantities'], $_POST['invoice_rates'], $_POST['invoice_debitnotes']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=invoice&task=main","Invoice(s) updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update Invoice(s)!");
			echo $e;
		}
	break;

	case "invoice_edit":
		require_once('../models/invoiceModel.php');
		$myinvoiceModel=new invoiceModel;
		$opresult=$myinvoiceModel->updatedata_invoice($_POST['invoice_pkey'], $_POST['invoice_projectpkey'], $_POST['invoice_popkeylist'], $_POST['invoice_dopkeylist'], $_POST['invoice_sono'], $_POST['invoice_no'], $_POST['invoice_date'], $_POST['invoice_terms'], $_POST['invoice_salesman'], $_POST['invoice_currency'], $_POST['invoice_customerno']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=invoice&task=edit&itemid=".$opresult,"Invoice updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update Invoice!");
			echo $e;
		}
	break;

	case "invoice_remove":
		require_once('../models/invoiceModel.php');
		$myinvoiceModel=new invoiceModel;
		$opresult=$myinvoiceModel->deletedata_invoice($_POST['invoice_pkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=invoice&task=list","Invoice deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete Invoice!");
			echo $e;
		}
	break;

	case "invoice_additem":
		require_once('../models/invoiceModel.php');
		$myinvoiceModel=new invoiceModel;
		$opresult=$myinvoiceModel->insertdata_invoiceitem($_POST['item_pkey'], $_POST['item_invoicepkey'], $_POST['item_no'], $_POST['item_id'], $_POST['item_subsubtradepkey'], $_POST['item_description'], $_POST['item_unit'], $_POST['item_quantity'], $_POST['item_rate']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=invoice&task=edit&itemid=".$_POST['item_invoicepkey'],"Invoice Item saved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to save new Invoice Item!");
			echo $e;
		}
	break;

	case "invoice_edititem":
		require_once('../models/invoiceModel.php');
		$myinvoiceModel=new invoiceModel;
		$opresult=$myinvoiceModel->updatedata_invoiceitem($_POST['item_pkey'], $_POST['item_invoicepkey'], $_POST['item_no'], $_POST['item_id'], $_POST['item_subsubtradepkey'], $_POST['item_description'], $_POST['item_unit'], $_POST['item_quantity'], $_POST['item_rate']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=invoice&task=edit&itemid=".$_POST['item_invoicepkey'],"Invoice Item updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update Invoice Item!");
			echo $e;
		}
	break;

	case "invoice_removeitem":
		require_once('../models/invoiceModel.php');
		$myinvoiceModel=new invoiceModel;
		$opresult=$myinvoiceModel->deletedata_invoiceitem($_POST['item_pkey'], $_POST['item_invoicepkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=invoice&task=edit&itemid=".$_POST['item_invoicepkey'],"Invoice Item deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete Invoice Item!");
			echo $e;
		}
	break;

	// sample: $e=error_n_goto(-1,"Error: Unable to initiate Crawl!\\n".$_SESSION['Xerrormessage']);


	//-------------users (+staff!!)--------------

	case "user_add":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->insertdata_staff($_POST['staff_pkey'], $_POST['staff_no'], $_POST['staff_nricno'], $_POST['staff_title'], $_POST['staff_name'], $_POST['staff_phone'], $_POST['staff_email'], $_POST['staff_role'], $_POST['staff_designation'], $_POST['staff_category'], $_POST['staff_userpkey'], $_POST['user_pkey'], $_POST['user_grouppkey'], $_POST['user_type'], $_POST['user_name'], $_POST['user_password'], $_POST['user_role'], $_POST['user_status']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=list","User Profile added successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to add User Profile!");
			echo $e;
		}
	break;

	case "user_edit":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->updatedata_staff($_POST['staff_pkey'], $_POST['staff_no'], $_POST['staff_nricno'], $_POST['staff_title'], $_POST['staff_name'], $_POST['staff_phone'], $_POST['staff_email'], $_POST['staff_role'], $_POST['staff_designation'], $_POST['staff_category'], $_POST['staff_userpkey'], $_POST['user_pkey'], $_POST['user_grouppkey'], $_POST['user_type'], $_POST['user_name'], $_POST['user_password'], $_POST['user_role'], $_POST['user_status']);
		if ($opresult!=false) {
			if ($_SESSION['Xuserrole']>=2) {
				$m=msg_n_goto("../index.php?module=user&task=list","User Profile updated successfully!");
			} else {
				$m=msg_n_goto("../index.php","Your Profile has been updated successfully!");
			}
			echo $m;
		} else {
			if ($_SESSION['Xuserrole']>=2) {
				$e=error_n_goto(-1,"Error: Failed to update User Profile!");
			} else {
				$e=error_n_goto(-1,"Error: Failed to update Your Profile!");
			}
			echo $e;
		}
	break;

	case "user_remove":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->deletedata_staff($_POST['user_pkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=list","User Profile deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete User Profile!");
			echo $e;
		}
	break;

	case "user_changepwd":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->changepwd_user($_POST['user_pkey'], $_POST['pwd_current'], $_POST['pwd_new'], $_POST['pwd_confirm']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php","User Password changed successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to change User Password!\\n".$_SESSION['Xerrormessage']);
			echo $e;
		}
	break;

	case "user_resetpwd":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->resetpwd_user($_POST['user_pkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=edit&itemid=".$_POST['user_pkey'],"User Password reset successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to reset User Password!");
			echo $e;
		}
	break;

	case "user_projectaccess":
		require_once('../models/projectModel.php');
		$myprojectModelPMS=new projectModelPMS;
		$opresult=$myprojectModelPMS->insertdata_useraccess($_POST['user_pkey'], $_POST['projectpkeys']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=list","User Project Access updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update User Project Access!");
			echo $e;
		}
	break;

	//-------------User Access Groups----------------

	case "user_groupadd":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->insertdata_usergroup($_POST['group_pkey'], $_POST['group_name'], $_POST['group_description'], $_POST['group_level'], $_POST['access_grouppkey'], $_POST['access_project_edit'], $_POST['access_project_delete'], $_POST['access_mbl_view'], $_POST['access_mbl_edit'], $_POST['access_mbl_approve'], $_POST['access_mro_view'], $_POST['access_mro_edit'], $_POST['access_mro_approvenormal'], $_POST['access_mro_recommendvariance'], $_POST['access_mro_approvevariance'], $_POST['access_mro_cancel'], $_POST['access_itq_view'], $_POST['access_itq_edit'], $_POST['access_itq_invite'], $_POST['access_itq_evaluate'], $_POST['access_itq_review'], $_POST['access_itq_approve50k'], $_POST['access_itq_approve100k'], $_POST['access_itq_approve1m'], $_POST['access_itq_approveall'], $_POST['access_itq_cancel'],
							     $_POST['access_po_view'], $_POST['access_po_close'], $_POST['access_po_cancel'], $_POST['access_do_view'], $_POST['access_do_edit'], $_POST['access_invoice_view'], $_POST['access_invoice_edit'], $_POST['access_reports_all'], $_POST['access_reports_mbl'], $_POST['access_reports_qv'], $_POST['access_reports_po'], $_POST['access_reports_sp'], $_POST['access_reports_bm'], $_POST['access_reports_pmc'], $_POST['access_reports_scm'], $_POST['access_reports_iqa'], $_POST['access_supplier_view'], $_POST['access_supplier_edit'], $_POST['access_supplier_recommend'], $_POST['access_supplier_approve'], $_POST['access_supplier_activate'], $_POST['access_trade_edit'], $_POST['access_client_view'], $_POST['access_client_edit'], $_POST['access_subcon_view'], $_POST['access_subcon_edit'], 
							     $_POST['access_system_managenews'], $_POST['access_system_manageusers'], $_POST['access_system_manageaccess']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=groups","User Access Group added successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to add User Access Group!");
			echo $e;
		}
	break;

	case "user_groupedit":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->updatedata_usergroup($_POST['group_pkey'], $_POST['group_name'], $_POST['group_description'], $_POST['group_level'], $_POST['access_grouppkey'], $_POST['access_project_edit'], $_POST['access_project_delete'], $_POST['access_mbl_view'], $_POST['access_mbl_edit'], $_POST['access_mbl_approve'], $_POST['access_mro_view'], $_POST['access_mro_edit'], $_POST['access_mro_approvenormal'], $_POST['access_mro_recommendvariance'], $_POST['access_mro_approvevariance'], $_POST['access_mro_cancel'], $_POST['access_itq_view'], $_POST['access_itq_edit'], $_POST['access_itq_invite'], $_POST['access_itq_evaluate'], $_POST['access_itq_review'], $_POST['access_itq_approve50k'], $_POST['access_itq_approve100k'], $_POST['access_itq_approve1m'], $_POST['access_itq_approveall'], $_POST['access_itq_cancel'],
							     $_POST['access_po_view'], $_POST['access_po_close'], $_POST['access_po_cancel'], $_POST['access_do_view'], $_POST['access_do_edit'], $_POST['access_invoice_view'], $_POST['access_invoice_edit'], $_POST['access_reports_all'], $_POST['access_reports_mbl'], $_POST['access_reports_qv'], $_POST['access_reports_po'], $_POST['access_reports_sp'], $_POST['access_reports_bm'], $_POST['access_reports_pmc'], $_POST['access_reports_scm'], $_POST['access_reports_iqa'], $_POST['access_supplier_view'], $_POST['access_supplier_edit'], $_POST['access_supplier_recommend'], $_POST['access_supplier_approve'], $_POST['access_supplier_activate'], $_POST['access_trade_edit'], $_POST['access_client_view'], $_POST['access_client_edit'], $_POST['access_subcon_view'], $_POST['access_subcon_edit'], 
							     $_POST['access_system_managenews'], $_POST['access_system_manageusers'], $_POST['access_system_manageaccess']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=groups","User Access Group updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update User Access Group!");
			echo $e;
		}
	break;

	case "user_groupremove":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->deletedata_usergroup($_POST['group_pkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=groups","User Access Group deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete User Access Group!");
			echo $e;
		}
	break;

	//-------------Staff Profiles----------------

	case "user_staffadd":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->insertdata_staff($_POST['staff_pkey'], $_POST['staff_no'], $_POST['staff_nricno'], $_POST['staff_title'], $_POST['staff_name'], $_POST['staff_phone'], $_POST['staff_email'], $_POST['staff_role'], $_POST['staff_designation'], $_POST['staff_divpkey'], $_POST['staff_deptpkey'], $_POST['staff_category'], $_POST['staff_userpkey'], $_POST['user_pkey'], $_POST['user_grouppkey'], $_POST['user_type'], $_POST['user_name'], $_POST['user_password'], $_POST['user_role'], $_POST['user_status']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=staff","Staff Profile added successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to add Staff Profile!");
			echo $e;
		}
	break;

	case "user_staffedit":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->updatedata_staff($_POST['staff_pkey'], $_POST['staff_no'], $_POST['staff_nricno'], $_POST['staff_title'], $_POST['staff_name'], $_POST['staff_phone'], $_POST['staff_email'], $_POST['staff_role'], $_POST['staff_designation'], $_POST['staff_divpkey'], $_POST['staff_deptpkey'], $_POST['staff_category'], $_POST['staff_userpkey'], $_POST['user_pkey'], $_POST['user_grouppkey'], $_POST['user_type'], $_POST['user_name'], $_POST['user_password'], $_POST['user_role'], $_POST['user_status']);
		if ($opresult!=false) {
			if ($_SESSION['Xuserrole']>=2) {
				$m=msg_n_goto("../index.php?module=user&task=staff","Staff Profile updated successfully!");
			} else {
				$m=msg_n_goto("../index.php","Your Profile has been updated successfully!");
			}
			echo $m;
		} else {
			if ($_SESSION['Xuserrole']>=2) {
				$e=error_n_goto(-1,"Error: Failed to update Staff Profile!");
			} else {
				$e=error_n_goto(-1,"Error: Failed to update Your Profile!");
			}
			echo $e;
		}
	break;

	case "user_staffremove":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->deletedata_staff($_POST['staff_pkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=staff","Staff Profile deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete Staff Profile!");
			echo $e;
		}
	break;

	//-------------Departments----------------

	case "user_deptadd":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->insertdata_department($_POST['dept_pkey'], $_POST['dept_divpkey'], $_POST['dept_code'], $_POST['dept_name'], $_POST['dept_description']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=depts","Department added successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to add Department!");
			echo $e;
		}
	break;

	case "user_deptedit":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->updatedata_department($_POST['dept_pkey'], $_POST['dept_divpkey'], $_POST['dept_code'], $_POST['dept_name'], $_POST['dept_description']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=depts","Department updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update Department!");
			echo $e;
		}
	break;

	case "user_deptremove":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->deletedata_department($_POST['dept_pkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=depts","Department deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete Department!");
			echo $e;
		}
	break;

	//-------------Divisions----------------

	case "user_divadd":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->insertdata_division($_POST['div_pkey'], $_POST['div_code'], $_POST['div_name'], $_POST['div_description']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=divs","Division added successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to add Division!");
			echo $e;
		}
	break;

	case "user_divedit":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->updatedata_division($_POST['div_pkey'], $_POST['div_code'], $_POST['div_name'], $_POST['div_description']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=divs","Division updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update Division!");
			echo $e;
		}
	break;

	case "user_divremove":
		require_once('../models/userModel.php');
		$myuserModel=new userModel;
		$opresult=$myuserModel->deletedata_division($_POST['div_pkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=user&task=divs","Division deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete Division!");
			echo $e;
		}
	break;

	//-------------admin: patm foreword------------------

	case "system_forewordadd":
		require_once('../models/systemModel.php');
		$mysystemModel=new systemModel;
		$opresult=$mysystemModel->insertdata_foreword($_POST['foreword_pkey'], $_POST['foreword_text'], $_POST['foreword_background'], $_POST['foreword_photo']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php","Welcome Note updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update Welcome Note!");
			echo $e;
		}
	break;

	//-------------news------------------

	case "news_add":
		require_once('../models/newsModel.php');
		$mynewsModel=new newsModel;
		$opresult=$mynewsModel->insertdata_news($_POST['news_pkey'], $_POST['news_date'], $_POST['news_time'], $_POST['news_expirydate'], $_POST['news_title'], $_POST['news_text'], $_POST['news_relatedurl']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=news&task=list","News Bulletin added successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to add News Bulletin!");
			echo $e;
		}
	break;

	case "news_edit":
		require_once('../models/newsModel.php');
		$mynewsModel=new newsModel;
		$opresult=$mynewsModel->updatedata_news($_POST['news_pkey'], $_POST['news_date'], $_POST['news_time'], $_POST['news_expirydate'], $_POST['news_title'], $_POST['news_text'], $_POST['news_relatedurl']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=news&task=list","News Bulletin updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update News Bulletin!");
			echo $e;
		}
	break;

	case "news_remove":
		require_once('../models/newsModel.php');
		$mynewsModel=new newsModel;
		$opresult=$mynewsModel->deletedata_news($_POST['news_pkey']);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=news&task=list","News Bulletin deleted successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete News Bulletin!");
			echo $e;
		}
	break;

	//-------------Reports----------------

	case "report_print":
		require_once('../models/reportModel.php');
		$myreportModel=new reportModel;
		if ($_POST['reporttype']=="mbl") {
  			$opresult=$myreportModel->processreport_mbl($_POST['rpt_projectpkey'], $_POST['rpt_datefrom'], $_POST['rpt_dateto']);
		} else if ($_POST['reporttype']=="qv") {
  			$opresult=$myreportModel->processreport_qv($_POST['rpt_projectpkey'], $_POST['rpt_datefrom'], $_POST['rpt_dateto']);
		} else if ($_POST['reporttype']=="po") {
  			$opresult=$myreportModel->processreport_po($_POST['rpt_projectpkey'], $_POST['rpt_supplierpkey'], $_POST['rpt_pono'], $_POST['rpt_podate'], $_POST['rpt_subtradepkey'], $_POST['rpt_subsubtradepkey'], $_POST['rpt_datefrom'], $_POST['rpt_dateto']);
		} else if ($_POST['reporttype']=="sp") {
			if ($_POST['rpt_supplierpkey']=="") {
	  			$opresult=$myreportModel->processreport_sp($_POST['rpt_projectpkey'], $_POST['rpt_datefrom'], $_POST['rpt_dateto'], $_POST['rpt_supplierpkey']);
			} else {
	  			$opresult=$myreportModel->processreport_sps($_POST['rpt_projectpkey'], $_POST['rpt_datefrom'], $_POST['rpt_dateto'], $_POST['rpt_supplierpkey']);
			}
		} else if ($_POST['reporttype']=="sps") {
  			$opresult=$myreportModel->processreport_sps($_POST['rpt_projectpkey'], $_POST['rpt_datefrom'], $_POST['rpt_dateto'], $_POST['rpt_supplierpkey']);
		} else if ($_POST['reporttype']=="bm") {
  			$opresult=$myreportModel->processreport_bm($_POST['rpt_projectpkey'], $_POST['rpt_datefrom'], $_POST['rpt_dateto']);
		} else if ($_POST['reporttype']=="pmc") {
  			$opresult=$myreportModel->processreport_pmc($_POST['rpt_projectpkey'], $_POST['rpt_pono'], $_POST['rpt_datefrom'], $_POST['rpt_dateto']);
		} else if ($_POST['reporttype']=="scm") {
  			$opresult=$myreportModel->processreport_scm($_POST['rpt_projectpkey'], $_POST['rpt_datefrom'], $_POST['rpt_dateto'], $_POST['rpt_subconpkey']);
		} else if ($_POST['reporttype']=="iqa") {
  			$opresult=$myreportModel->processreport_iqa();
		} else if ($_POST['reporttype']=="sup") {
			$opresult=$myreportModel->processreport_supplierlist("1");
		}
		//if (($_POST['reporttype']!="pmc")&&($_POST['reporttype']!="scm")&&($_POST['reporttype']!="bm")&&($_POST['reporttype']!="sp")&&($_POST['reporttype']!="mbl")) {
			//return;
		//}
		echo "<script type='text/javascript'>";
		if ($_POST['reporttype']=="mbl") {
  			echo "window.open('../views/rpt_mbl.php?userid=".$_SESSION['Xuserpkey']."','reportwindow');";
		} else if ($_POST['reporttype']=="qv") {
  			echo "window.open('../views/rpt_qv.php?userid=".$_SESSION['Xuserpkey']."','reportwindow');";
		} else if ($_POST['reporttype']=="po") {
  			echo "window.open('../views/rpt_pos.php?userid=".$_SESSION['Xuserpkey']."','reportwindow');";
		} else if ($_POST['reporttype']=="sp") {
			if ($_POST['rpt_supplierpkey']=="") {
	  			echo "window.open('../views/rpt_sp.php?userid=".$_SESSION['Xuserpkey']."','reportwindow');";
			} else {
	  			echo "window.open('../views/rpt_sps.php?userid=".$_SESSION['Xuserpkey']."','reportwindow');";
			}
		} else if ($_POST['reporttype']=="sps") {
  			echo "window.open('../views/rpt_sps.php?userid=".$_SESSION['Xuserpkey']."','reportwindow');";
		} else if ($_POST['reporttype']=="bm") {
  			echo "window.open('../views/rpt_bm.php?userid=".$_SESSION['Xuserpkey']."','reportwindow');";
		} else if ($_POST['reporttype']=="pmc") {
  			echo "window.open('../views/rpt_pmc.php?userid=".$_SESSION['Xuserpkey']."','reportwindow');";
		} else if ($_POST['reporttype']=="scm") {
  			echo "window.open('../views/rpt_scm.php?userid=".$_SESSION['Xuserpkey']."','reportwindow');";
		} else if ($_POST['reporttype']=="iqa") {
  			echo "window.open('../views/rpt_iqa.php?userid=".$_SESSION['Xuserpkey']."','reportwindow');";
		} else if ($_POST['reporttype']=="sup") {
  			echo "window.open('../views/rpt_supplierlist.php?userid=".$_SESSION['Xuserpkey']."&suppliername=".$filtersuppliername."','reportwindow');";
		}
		echo "</script>";
		//return;
		if ($_POST['reporttype']=="sup") {
			$m=goto("../index.php?module=supplier&task=main");
		} else {
			$m=goto("../index.php?module=report&task=".$_POST['reporttype']."&supplierid=".$_POST['rpt_supplierpkey']."&subconid=".$_POST['rpt_subconpkey']."&pono=".$_POST['rpt_pono']."&podate=".$_POST['rpt_podate']."&subtradeid=".$_POST['rpt_subtradepkey']."&subsubtradeid=".$_POST['rpt_subsubtradepkey']."&datefrom=".$_POST['rpt_datefrom']."&dateto=".$_POST['rpt_dateto']);
		}
		echo $m;
	break;

	//-------------system----------------

	case "system_settingsedit":
		require_once('../models/systemModel.php');
		$mysystemModel=new systemModel;
		$opresult=$mysystemModel->insertdata_systemsettings($_POST['fullsettings'], $_POST['fullvalues']);
		//echo $_POST['fullsettings']."~".$_POST['fullvalues'];
		//return;
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=system&task=settings","System Settings updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Unable to save System Settings!");
			echo $e;
		}
	break;

	case "system_purgedb":
		require_once('../models/systemModel.php');
		$mysystemModel=new systemModel;
		$opresult=$mysystemModel->purgedata_db();
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=system&task=settings","Purge Pages in Database operation complete!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Unable to purge pages in Database!");
			echo $e;
		}
	break;

	case "system_purgecache":
		require_once('../models/systemModel.php');
		$mysystemModel=new systemModel;
		$opresult=$mysystemModel->purgedata_cache();
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=system&task=settings","Purge Pages in Cache operation complete!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Unable to purge pages in Cache!");
			echo $e;
		}
	break;


	//-------------profile--------------

	case "profile_addstudent":
		$addresult=profile_addstudent($_POST['studentcountry'], $_POST['studentserviceno'], $_POST['studentcategory'], $_POST['studentrank'], $_POST['studentname'], $_POST['studentnametoaddress'], $_POST['studentnameontag'], $_POST['studentdob'], $_POST['studentage'], $_POST['studentpob'], $_POST['studentcitizenship'], $_POST['studentrace'], $_POST['studentreligion'], 
                                              $_POST['educationsecondaryschool1'], $_POST['educationsecondarylocation1'], $_POST['educationsecondaryyear1'], $_POST['educationsecondaryqualification1'], $_POST['educationsecondaryschool2'], $_POST['educationsecondarylocation2'], $_POST['educationsecondaryyear2'], $_POST['educationsecondaryqualification2'], $_POST['educationsecondaryschool3'], $_POST['educationsecondarylocation3'], $_POST['educationsecondaryyear3'], $_POST['educationsecondaryqualification3'], 
                                              $_POST['educationhighercourse1'], $_POST['educationhigherschool1'], $_POST['educationhigherlocation1'], $_POST['educationhigheryear1'], $_POST['educationhigherqualification1'], $_POST['educationhighercourse2'], $_POST['educationhigherschool2'], $_POST['educationhigherlocation2'], $_POST['educationhigheryear2'], $_POST['educationhigherqualification2'], $_POST['educationhighercourse3'], $_POST['educationhigherschool3'], $_POST['educationhigherlocation3'], $_POST['educationhigheryear3'], $_POST['educationhigherqualification3'], $_POST['educationhighercourse4'], $_POST['educationhigherschool4'], $_POST['educationhigherlocation4'], $_POST['educationhigheryear4'], $_POST['educationhigherqualification4'], 
                                              $_POST['studentaddress'], $_POST['studentphone'], $_POST['studentmobile'], $_POST['studentfax'], $_POST['studentemail'], $_POST['studentfamilyaddress'], $_POST['studentfamilyphone'], $_POST['studentfamilymobile'], $_POST['studentfamilyfax'], $_POST['studentfamilyemail'], $_POST['studentkinname'], $_POST['studentkinrelationship'], $_POST['studentkinaddress'], $_POST['studentkinphone'], $_POST['studentkinmobile'], $_POST['studentkinfax'], $_POST['studentkinemail']);
	break;
	case "profile_editstudent":
		$editresult=profile_editstudent($_POST['studentpkey'], $_POST['studentcountry'], $_POST['studentserviceno'], $_POST['studentcategory'], $_POST['studentrank'], $_POST['studentname'], $_POST['studentnametoaddress'], $_POST['studentnameontag'], $_POST['studentdob'], $_POST['studentage'], $_POST['studentpob'], $_POST['studentcitizenship'], $_POST['studentrace'], $_POST['studentreligion'], 
                                                $_POST['educationsecondaryschool1'], $_POST['educationsecondarylocation1'], $_POST['educationsecondaryyear1'], $_POST['educationsecondaryqualification1'], $_POST['educationsecondaryschool2'], $_POST['educationsecondarylocation2'], $_POST['educationsecondaryyear2'], $_POST['educationsecondaryqualification2'], $_POST['educationsecondaryschool3'], $_POST['educationsecondarylocation3'], $_POST['educationsecondaryyear3'], $_POST['educationsecondaryqualification3'], 
                                                $_POST['educationhighercourse1'], $_POST['educationhigherschool1'], $_POST['educationhigherlocation1'], $_POST['educationhigheryear1'], $_POST['educationhigherqualification1'], $_POST['educationhighercourse2'], $_POST['educationhigherschool2'], $_POST['educationhigherlocation2'], $_POST['educationhigheryear2'], $_POST['educationhigherqualification2'], $_POST['educationhighercourse3'], $_POST['educationhigherschool3'], $_POST['educationhigherlocation3'], $_POST['educationhigheryear3'], $_POST['educationhigherqualification3'], $_POST['educationhighercourse4'], $_POST['educationhigherschool4'], $_POST['educationhigherlocation4'], $_POST['educationhigheryear4'], $_POST['educationhigherqualification4'], 
                                                $_POST['studentaddress'], $_POST['studentphone'], $_POST['studentmobile'], $_POST['studentfax'], $_POST['studentemail'], $_POST['studentfamilyaddress'], $_POST['studentfamilyphone'], $_POST['studentfamilymobile'], $_POST['studentfamilyfax'], $_POST['studentfamilyemail'], $_POST['studentkinname'], $_POST['studentkinrelationship'], $_POST['studentkinaddress'], $_POST['studentkinphone'], $_POST['studentkinmobile'], $_POST['studentkinfax'], $_POST['studentkinemail']);
	break;
	case "profile_deletestudent":
		$deleteresult=profile_deletestudent($_POST['studentpkey']);
	break;

	case "profile_addstaff":
		$addresult=profile_addstaff($_POST['staffno'], $_POST['staffnricno'], $_POST['staffrank'], $_POST['staffname'], $_POST['staffphone'], $_POST['staffrole'], $_POST['staffdivision'], $_POST['staffcategory'], $_POST['staffsubjectpkeys'], $_POST['staffusername']);
	break;
	case "profile_editstaff":
		$editresult=profile_editstaff($_POST['staffpkey'], $_POST['staffno'], $_POST['staffnricno'], $_POST['staffrank'], $_POST['staffname'], $_POST['staffphone'], $_POST['staffrole'], $_POST['staffdivision'], $_POST['staffcategory'], $_POST['staffsubjectpkeys']);
	break;
	case "profile_deletestaff":
		$deleteresult=profile_deletestaff($_POST['staffpkey']);
	break;

	case "profile_chgpwd":
		$chgpwd=users_chgpwd($_POST['currentpwd'], $_POST['newpwd'], $_POST['confirmpwd']);
	break;
	case "profile_remindpwd":
		$checkuser=users_validusername($_POST['username']);
		if ($checkuser==true) {
			$m=goto("../index.php?module=login&task=pwdquestion");
			echo $m;			
		} else {
			$e=error_n_goto("-1","Ralat: Nama Pengguna yang dimasukkan adalah tidak sah!");
			echo $e;
		}
	break;
	case "profile_pwdquestion":
		$checkanswer=users_validanswer($_POST['tempuserpkey'], $_POST['userpasswordanswer']);
		if ($checkanswer==true) {
			$m=goto("../index.php?module=login&task=sendpwd");
			echo $m;			
		} else {
			$e=error_n_goto("-3","Ralat: Jawapan yang diberikan untuk Soalan Keselamatan tidak sama dengan jawapan yang diberikan semasa pendaftaran!");
			echo $e;
		}
	break;

	//-------------users--------------
	/*
	case "user_add":
		$addresult=users_add($_POST['usergrouppkey'], $_POST['username'], $_POST['userpassword'], $_POST['userpasswordquestion'], $_POST['userpasswordanswer'], $_POST['userfullname'], $_POST['useralternateemail'], $_POST['userrole'], $_POST['useraccesslevelpkey'], $_POST['useravatar'], $_POST['userbosspkey'], $_POST['userstatus']);
	break;
        case "user_edit":
		$editresult=users_edit($_POST['userpkey'], $_POST['usergrouppkey'], $_POST['username'], $_POST['userfullname'], $_POST['useralternateemail'], $_POST['userrole'], $_POST['useraccesslevelpkey'], $_POST['useravatar'], $_POST['userbosspkey'], $_POST['userstatus']);
	break;
	case "user_resetpwd":
		$resetresult=users_resetpwd($_POST['userpkey']);
	break;
	*/

	//-------------access levels--------------
	case "accesslevel_add":
		$addresult=alevel_add($_POST['accesslevelusergrouppkey'], $_POST['accesslevelname'], $_POST['accessleveldescription'], $_POST['accessnewsview'], $_POST['accessnewsedit'], $_POST['accessnewseditbrief'], $_POST['accessannouncementview'], $_POST['accessannouncementedit'], $_POST['accessgalleryview'], $_POST['accessgalleryedit'], $_POST['accessgalleryeditalbums'], $_POST['accesswebcalview'], $_POST['accesswebcaleditevent'], $_POST['accesswebcaleditholiday'], $_POST['accesswebcaleditactivity'], $_POST['accesswebcalcompare'], $_POST['accessdloadview'], $_POST['accessdloadeditdocs'], $_POST['accessdloadeditgroups'], $_POST['accesslinksview'], $_POST['accesslinkseditlinks'], $_POST['accesslinkseditgroups'], $_POST['accessforumparticipate'], 
		$_POST['accessforumedit'], $_POST['accessforumdeleteposts'], $_POST['accesschatparticipate'], $_POST['accesschateditrooms'], $_POST['accesschatmanageuser'], $_POST['accesssurveyview'], $_POST['accesssurveyedit'], $_POST['accessemailparticipate'], $_POST['accesscontactsemergencyview'], $_POST['accesscontactsemergencyedit'], $_POST['accesscontactspublicview'], $_POST['accesscontactspublicedit'], $_POST['accesscontactsstaffview'], $_POST['accesscontactsstaffedit'], $_POST['accesscontactspersonal'], $_POST['accessfoldersparticipate'], $_POST['accessfolderseditsubfolder'], $_POST['accessfoldersmanage'], $_POST['accessprefs'], $_POST['accessprofileview'], $_POST['accessprofileedit'], $_POST['accessdesignationview'], $_POST['accessdesignationedit'], 
		$_POST['accessrankview'], $_POST['accessrankedit'], $_POST['accessdivisionview'], $_POST['accessdivisionedit'], $_POST['accessdepartmentview'], $_POST['accessdepartmentedit'], $_POST['accessuserlist'], $_POST['accessuseredituser'], $_POST['accessuserview'], $_POST['accessusereditadmin'], $_POST['accessaccesslevelview'], $_POST['accessaccessleveledit'], $_POST['accessportalusage'], $_POST['accessportaldatastats'], $_POST['accessportalaudittrail'], $_POST['accessportalarchiveaudit'], $_POST['accessportalbackupdb'], $_POST['accessportalarchivedb']);
	break;
        case "accesslevel_edit":
		$editresult=alevel_edit($_POST['accesslevelpkey'], $_POST['accesslevelusergrouppkey'], $_POST['accesslevelname'], $_POST['accessleveldescription'], $_POST['accessnewsview'], $_POST['accessnewsedit'], $_POST['accessnewseditbrief'], $_POST['accessannouncementview'], $_POST['accessannouncementedit'], $_POST['accessgalleryview'], $_POST['accessgalleryedit'], $_POST['accessgalleryeditalbums'], $_POST['accesswebcalview'], $_POST['accesswebcaleditevent'], $_POST['accesswebcaleditholiday'], $_POST['accesswebcaleditactivity'], $_POST['accesswebcalcompare'], $_POST['accessdloadview'], $_POST['accessdloadeditdocs'], $_POST['accessdloadeditgroups'], $_POST['accesslinksview'], $_POST['accesslinkseditlinks'], $_POST['accesslinkseditgroups'], 
		$_POST['accessforumparticipate'], $_POST['accessforumedit'], $_POST['accessforumdeleteposts'], $_POST['accesschatparticipate'], $_POST['accesschateditrooms'], $_POST['accesschatmanageuser'], $_POST['accesssurveyview'], $_POST['accesssurveyedit'], $_POST['accessemailparticipate'], $_POST['accesscontactsemergencyview'], $_POST['accesscontactsemergencyedit'], $_POST['accesscontactspublicview'], $_POST['accesscontactspublicedit'], $_POST['accesscontactsstaffview'], $_POST['accesscontactsstaffedit'], $_POST['accesscontactspersonal'], $_POST['accessfoldersparticipate'], $_POST['accessfolderseditsubfolder'], $_POST['accessfoldersmanage'], $_POST['accessprefs'], $_POST['accessprofileview'], $_POST['accessprofileedit'], $_POST['accessdesignationview'], 
		$_POST['accessdesignationedit'], $_POST['accessrankview'], $_POST['accessrankedit'], $_POST['accessdivisionview'], $_POST['accessdivisionedit'], $_POST['accessdepartmentview'], $_POST['accessdepartmentedit'], $_POST['accessuserlist'], $_POST['accessuseredituser'], $_POST['accessuserview'], $_POST['accessusereditadmin'], $_POST['accessaccesslevelview'], $_POST['accessaccessleveledit'], $_POST['accessportalusage'], $_POST['accessportaldatastats'], $_POST['accessportalaudittrail'], $_POST['accessportalarchiveaudit'], $_POST['accessportalbackupdb'], $_POST['accessportalarchivedb']);
	break;

	//-------------admin: pmat------------------
	case "public_pmatadd":
		$addresult=public_pmatadd($_POST['docbillno'], $_POST['docdescription'], $_POST['docremarks'], $_POST['dockeywords'], $_POST['docfilename'], $_POST['docyear']);
	break;
	case "public_pmatedit":
		$editresult=public_pmatedit($_POST['docpkey'], $_POST['docbillno'], $_POST['docdescription'], $_POST['docremarks'],$_POST['dockeywords'], $_POST['docfilename'], $_POST['doccurrentfile'], $_POST['docyear']);
	break;
	case "public_pmatremove":
		$deleteresult=public_pmatdelete($_POST['docpkey']);
	break;

	//-------------hod foreword------------------
	case "hod_editforeword":
		$editresult=foreword_edithod($_POST['forewordpkey'], $_POST['forewordusergrouppkey'], $_POST['forewordtext'], $_POST['forewordbackground'], $_POST['forewordphoto']);
	break;

	case "":
	break;
  
  # myapit issue no 4
  # TODO: myapit input validation
  //-------------subcon---------------

	case "subcon_add":
		require_once('../models/subconModel.php');
		$mysubconModel=new subconModel;
    
    $p_subconmasterpkey = md5(microtime()); //"";//$_POST ['subconmasterpkey']; 
    $p_subconname = $_POST ['subconname']; 
    $p_subconpic = $_POST ['subconpic']; 
    $p_subconpicdesignation = $_POST ['subconpicdesignation']; 
    $p_subconpicphone = $_POST ['subconpicphone']; 
    $p_subconpicext = $_POST ['subconpicext']; 
    $p_subconpicmobile = $_POST ['subconpicmobile']; 
    $p_subconaddress = $_POST ['subconaddress']; 
    $p_subconphone1 = $_POST ['subconphone1']; 
    $p_subconphone2 = $_POST ['subconphone2']; 
    $p_subconfax = $_POST ['subconfax'];
    
		$opresult=$mysubconModel->insertdata_subcon(
                              $p_subconmasterpkey, 
                              $p_subconname, 
                              $p_subconpic, 
                              $p_subconpicdesignation, 
                              $p_subconpicphone, 
                              $p_subconpicext, 
                              $p_subconpicmobile, 
                              $p_subconaddress, 
                              $p_subconphone1, 
                              $p_subconphone2, 
                              $p_subconfax);
		if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=subcon&task=main","Sub Contractor saved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to save new Sub Contractor !");
			echo $e;
		}
	break;
  
	case "subcon_edit":
	  require_once('../models/subconModel.php');
	  $mysubconModel=new subconModel;
	  
    $p_subconmasterpkey = $_POST ['subconmasterpkey']; 
    $p_subconname = $_POST ['subconname']; 
    $p_subconpic = $_POST ['subconpic']; 
    $p_subconpicdesignation = $_POST ['subconpicdesignation']; 
    $p_subconpicphone = $_POST ['subconpicphone']; 
    $p_subconpicext = $_POST ['subconpicext']; 
    $p_subconpicmobile = $_POST ['subconpicmobile']; 
    $p_subconaddress = $_POST ['subconaddress']; 
    $p_subconphone1 = $_POST ['subconphone1']; 
    $p_subconphone2 = $_POST ['subconphone2']; 
    $p_subconfax = $_POST ['subconfax'];
	  $opresult=$mysubconModel->updatedata_subcon(
	                            $p_subconmasterpkey, 
	                            $p_subconname, 
	                            $p_subconpic, 
	                            $p_subconpicdesignation,  
	                            $p_subconpicphone, 
	                            $p_subconpicext, 
	                            $p_subconpicmobile, 
	                            $p_subconaddress, 
	                            $p_subconphone1, 
	                            $p_subconphone2, 
	                            $p_subconfax);

    if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=subcon&task=main","Sub Contractor updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to update Sub Contractor !");
			echo $e;
		}                          
	  break;
	  
	case "subcon_remove":
	  require_once('../models/subconModel.php');
	  $mysubconModel=new subconModel;
	  $p_subconmasterpkey = $_POST ['subconmasterpkey'];
	 // echo $p_subconmasterpkey;
	  $opresult=$mysubconModel->deletedata_subcon($p_subconmasterpkey);
	  
	  if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=subcon&task=main","Sub Contractor delete successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete Sub Contractor !");
			echo $e;
		} 
	  break;
  # myapit end
  //----- client information ----
	# myapit begin -- client information -> master data
	case "client_save":
	  require_once '../models/clientModel.php';
	  $myclientModel = new clientModel;
	  
	  $p_clientpkey=$_POST['clientpkey'];
    $p_clientname=$_POST['clientname'];
    $p_clientaddress=$_POST['clientaddress'];
    $p_clientphone1=$_POST['clientphone1'];
    $p_clientphone2=$_POST['clientphone2'];
    $p_clientfax=$_POST['clientfax'];
    $p_clientpic=$_POST['clientpic'];
    $p_clientpicdesignation=$_POST['clientpicdesignation'];
    $p_clientmobile1=$_POST['clientmobile1'];
    $p_clientmobile2=$_POST['clientmobile2'];
    
    $opresult=$myclientModel->insertdata_client(
                              $p_clientpkey, 
                              $p_clientname, 
                              $p_clientpic, 
                              $p_clientpicdesignation, 
                              $p_clientaddress, 
                              $p_clientphone1, 
                              $p_clientphone2, 
                              $p_clientmobile1, 
                              $p_clientmobile2, 
                              $p_clientfax);

    if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=client&task=main","Client Information saved successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to save client information !");
			echo $e;
		}                
		
	  //foreach($_POST as $key=>$value){
	  //  echo "$".$key."=\$_POST['".$key."'];<br>";
	  //}
	  break;
	  
  case "client_save_edit":
	  require_once '../models/clientModel.php';
	  $myclientModel = new clientModel;
	  
	  $p_clientpkey=$_POST['clientpkey'];
    $p_clientname=$_POST['clientname'];
    $p_clientaddress=$_POST['clientaddress'];
    $p_clientphone1=$_POST['clientphone1'];
    $p_clientphone2=$_POST['clientphone2'];
    $p_clientfax=$_POST['clientfax'];
    $p_clientpic=$_POST['clientpic'];
    $p_clientpicdesignation=$_POST['clientpicdesignation'];
    $p_clientmobile1=$_POST['clientmobile1'];
    $p_clientmobile2=$_POST['clientmobile2'];
    
    $opresult=$myclientModel->updatedata_client(
                              $p_clientpkey, 
                              $p_clientname, 
                              $p_clientpic, 
                              $p_clientpicdesignation, 
                              $p_clientaddress, 
                              $p_clientphone1, 
                              $p_clientphone2, 
                              $p_clientmobile1, 
                              $p_clientmobile2, 
                              $p_clientfax);

    if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=client&task=main","Client Information updated successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to updated client information !");
			echo $e;
		} 
		break;
		
  case "client_remove":
	  require_once '../models/clientModel.php';
	  $myclientModel = new clientModel;
	  $p_clientpkey=$_POST['clientpkey'];;
	  $opresult=$myclientModel->deletedata_client($p_clientpkey);
	  
	  if ($opresult!=false) {
			$m=msg_n_goto("../index.php?module=client&task=main","Client Information delete successfully!");
			echo $m;
		} else {
			$e=error_n_goto(-1,"Error: Failed to delete Client Information !");
			echo $e;
		} 
	  break;
	# myapit end client info
	
	default:
	echo $invalidaccess;
	
endswitch;

if (is_null($myjob)){
	echo $invalidaccess;
}
?>
