<?php
	include("../core/config.php");
	
	//Proccess Update
	if(count($_POST)){
		$res = $user->pass_reset($_POST['email']);
		
		if($res){
			//Hash succesfully generated
			
			//Send an email to the user
			$password_reset_email = $user->password_reset_email($res["email"],$res["first_name"],$res['hash']);
			if(!$password_reset_email) {
				$wb_admin_email = $user->wb_admin['admin_email'];
				$user_email = $res["email"];
				$_SESSION['ErrorMsgs'][] = "Password Reset email could not be sent";
				$_SESSION['ErrorMsgs'][] = "If you continue to have problems, please contact the web admin. <a class=\"white\" href=\"mailto:$wb_admin_email?subject=Password Reset Failure
&body=Hello,%0D%0A%0D%0AA problem with the web server prevented me from receiving the password reset email.%0D%0A%0D%0A I registered using the email address: $user_email.%0D%0A%0D%0APlease contact me to complete my password reset. \">Contact Web Admin</a> ";
				$_SESSION["regData"] = $_POST;
				redirect($user->page_rel_path ."?page=forgot-password");
			
			//$url = $user->page_rel_path . "?page=change-password&c=" . $res['hash'];
			//$_SESSION["NoteMsgs"][] = "You may change your password";
			//Redirect
			//redirect($url);
			} else {
				$_SESSION['NoteMsgs'][] = "Password Reset Successfully";
				$_SESSION['NoteMsgs'][] = "Please check your email for password reset instructions";
				redirect($user->page_rel_path ."?page=login");	
			}
			
		}else{
			$_SESSION["ErrorMsgs"] = $user->error();
			
			redirect();
		}
	}
	
?>
