<?php
/*
* date last modified 28-11-2017
* Edited by PI-Digi Logical Solutions
* HTML Files - add_user.html.php
* Mysql Tables - tbl_designation, tbl_user
*/
include('includes/imgFunctions.php');
include('includes/functions.php'); # general functions

if(isset($_REQUEST['p']) && $_REQUEST['p']!=''){
	$p = trim($_REQUEST['p']);
} else {
	$p = 1;
}


if(isset($_REQUEST['id']) && $_REQUEST['id']!=''){		
	$editId = mysqli_real_escape_string($con, trim($_REQUEST['id']));	
	
	//disable
	if(isset($_REQUEST['action']) && $_REQUEST['action']=='disable'){		
		$update = mysqli_query($con, "UPDATE tbl_user SET status = 'Disabled' WHERE id = '".$editId."'");
		if($update){
			$success = 'User has been disabled';
		}		
	}
	
	//enable
	if(isset($_REQUEST['action']) && $_REQUEST['action']=='enable'){		
		$update = mysqli_query($con, "UPDATE tbl_user SET status = 'Active' WHERE id = '".$editId."'");
		if($update){
			$success = 'Status changed to active';
		}		
	}

	//delete image
	if(isset($_REQUEST['action']) && $_REQUEST['action']=='del_image'){
		$recImg = mysqli_fetch_array(mysqli_query($con, "SELECT image FROM tbl_user WHERE id = '".$editId."'"));
		if(($recImg['image']!='') && file_exists(USER_IMG_FOLDER.$recImg['image'])){
			unlink(USER_IMG_FOLDER.$recImg['image']);
			unlink(USER_IMG_FOLDER.'thumb/'.$recImg['image']);
		}
		$update = mysqli_query($con, "UPDATE tbl_user SET image = '' WHERE id = '".$editId."'");
		$success = 'Staff image has been deleted';
	}	
	
	$editRs = mysqli_query($con, "SELECT * FROM tbl_user WHERE id = '".$editId."'");
	if(mysqli_num_rows($editRs)>0){
		$resEdit = mysqli_fetch_array($editRs);
	} else {
		$error = 'Staff does not exist!';
	}

} 


?>