<?php 	

require_once '../../Server/connection.php';

$valid['success'] = array('success' => false, 'messages' => array());

if($_POST) {	

	$editFirstName = addslashes(strtoupper($_POST['editFirstName']));
	$editMiddleName = addslashes(strtoupper($_POST['editMiddleName']));
	$editLastName = addslashes(strtoupper($_POST['editLastName']));
	$editEmail = addslashes(strtolower($_POST['editEmail']));
	$editPhoneNumber = $_POST['editPhoneNumber'];
	$editRole = $_POST['role_id'];
	$editDept = $_POST['dept_id'];
	
	
	$n = substr($editPhoneNumber,3);
    $n1 = '0';
    $editPhoneNumber11 = $n1.$n;
	
	
    $staffId = $_POST['editCategoriesId'];

	$sql = "UPDATE staff SET firstname = '$editFirstName',middlename='$editMiddleName',lastname='$editLastName',email='$editEmail',phone_number='$editPhoneNumber11',dept_id='$editDept' WHERE staff_id = '$staffId'";
	
	$sql1 = "UPDATE users SET role_id = '$editRole',dept_id='$editDept' WHERE staff_id = '$staffId'";

	if($conn->query($sql) === TRUE&&$conn->query($sql1) === TRUE) {
	 	$valid['success'] = true;
		$valid['messages'] = "Successfully Updated";	
	} else {
	 	$valid['success'] = false;
	 	$valid['messages'] = "Error while updating the Department";
	}
	 
	$conn->close();

	echo json_encode($valid);
 
} // /if $_POST