<?php
	include("../core/config.php");
	include("../core/validations.php");

	if($user->signed) redirect();

	
	//Proccess Registration
	if(count($_POST)){
		//Register User
		
		//modify on_email_list to 1 or zero of checked
		$_POST['on_email_list'] = (isset($_POST['on_email_list']) ? 1:0);

		$hash = $user->register($_POST,true);
		
		//Display Error
		if(!$hash){
			$_SESSION['ErrorMsgs'] = $user->error();
			$_SESSION["regData"] = $_POST;
			redirect($user->page_rel_path ."?page=register");		
		}else{
			
			//Send Activation email 
			$activation_email = $user->activation_email($_POST["email"],$_POST["first_name"],$hash);
			if(!$activation_email) {
				$wb_admin_email = $user->wb_admin['admin_email'];
				$user_email = $_POST["email"];
				$_SESSION['ErrorMsgs'][] = "Activation email could not be sent";
				$_SESSION['ErrorMsgs'][] = "Please contact the web admin to complete your registration <a class=\"white\" href=\"mailto:$wb_admin_email?subject=Email Activation Failure
&body=Hello,%0D%0A%0D%0AA problem with the web server prevented me from receiving the activation email.%0D%0A%0D%0A I registered using the email address: $user_email.%0D%0A%0D%0APlease contact me to complete my activation. \">Contact Web Admin</a> ";
				
				$_SESSION["regData"] = $_POST;
				redirect($user->page_rel_path ."?page=login");
				
			} else {
				$_SESSION['NoteMsgs'][] = "User Registered Successfully";
				$_SESSION['NoteMsgs'][] = "Please check your email for activation instructions";
				redirect($user->page_rel_path ."?page=login");	
			}
		}
	}else{
		redirect();
	}
	
?>
