<?php
if (isset($_POST["editUser"]))
{
	$fName = sanitize($_POST['fName']);
	$lName = sanitize($_POST['lName']);
	// $uName = sanitize($_POST['uName']);
	$pswd1 = sanitize($_POST['pswd1']);
	$pswd2 = sanitize($_POST['pswd2']);
	$security = sanitize($_POST['security']);
	$emailA = sanitize($_POST['emailA']);

	if ($fName == "")
	{
		$boolValidate = 0;
		$strValidation .= "A first name is required.<br />";
	}
	if ($lName == "")
	{
		$boolValidate = 0;
		$strValidation .= "A last name is required.<br />";
	}
	if ($emailA == "")
	{
		$boolValidate = 0;
		$strValidation .= "An email address is required.<br />";
	}
	else
	{
		//verify email is in right format
		if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $emailA)) 
		{
			// $emailA = mysql_real_escape_string (strtolower($emailA));
		} 
		else 
		{
			$strValidation .= 'Please enter a valid email address<br />';
			$boolValidate = 0;
		}	
	}
	if ($pswd2 == "")
	{
		$boolValidate = 0;
		$strValidation .= "A password is required.<br />";
	}
	else
	{
	
		if ($pswd1 == $pswd2) 
		{
			// $p = mysql_real_escape_string ($pswd1);
			$p = sha1($pswd1);
		} 
		else 
		{
			$strValidation .= 'Your passwords did not match.<br />';
			$boolValidate = 0;
		}
		
	}
	
	if ($security == 0)
	{
		$strValidation .= 'Please select a security level<br />';
	}
	
	

	if ($boolValidate == 1)
	{
		// echo 'all good';
		$sql =  "INSERT into tblUsers (strFirstName, strLastName, strUsername, strPassword, intSecurityLevel, dateEntered, intAddedBy, intModifiedBy) VALUES ('$fName','$lName', '$emailA', '$p', '$security', NOW(), '$user_id', '$user_id')";
		$result = getFromDatabase($sql);

		// echo "$sql";
		// mysqli_query($dbc,$sql) or die(mysqli_error($dbc));

		header("location:user-listing.php");

	}
}
?>