<?php
	include("../core/config.php");
	include("../core/validations.php");
	
	//Proccess Update
	if(count($_POST)){
		
		//modify on_email_list to 1 or zero of checked
		$_POST['on_email_list'] = (isset($_POST['on_email_list']) ? 1:0);
		
		foreach($_POST as $name=>$val){
			if($user->data[$name] == $val){
			
				unset($_POST[$name]);
			}
		}
		
		if(count($_POST)){
			//Update info
			$user->update($_POST);
		}else{
			//Nothing has changed
			$_SESSION['NoteMsgs'][0] = "No need to update!";
		}
		
		//If there are errors
		if($user->has_error()){
			//There were errors while updating information
			$_SESSION['ErrorMsgs'] = $user->error();
		}elseif(count($_POST)){
			//Updates have been saved successfully!
			$_SESSION['NoteMsgs'][0] = "Information Updated!";
		}
	}
	
	redirect($user->page_rel_path ."?page=account_update");
	
?>