<?php
///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//   Program Name         : ProPhotoHost                                     //
//   Release Version      : 1.0                                              //
//   Home Page            : http://www.prophotohost.com                      //
//   Program Author       : Jake P                                           //
//   Supplied by          : drew010                                          //
//   Nullified by         : CyKuH [WTN]                                      //
//   Distribution         : via WebForum, ForumRU and associated file dumps  //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
session_start();
session_register("preference_name");
session_register("preference_email");
session_register("preference_newsletter");

include('i.setup.php');
include('i.connection.php');
include('i.function.php');

if($mode == "update") {
	
	$preference_name = $member_name;
	$preference_email = $member_email;
	
	$before = $member_email;
	$member_email = strtoupper($member_email);
	
	if($member_newsletter == 1) {
		$preference_newsletter = "Y";
	}
	else {
		$preference_newsletter = "N";
	}
	
	if($current_email != $member_email) {
		$result = mysql_query("SELECT member_email FROM member WHERE member_email = '$member_email'", $db);
		$rows = mysql_num_rows($result);
		if($rows > 0) {
			header("location: " . $PHP_SELF . "?error=email&member_email=" . $before);
			exit;
		}
	}
	
	$query = mysql_query("SELECT member_password FROM member WHERE member_id = '$session_member_id'");
	$data = mysql_fetch_object($query, $db);
	
	if($member_new_password != "") {
		if($data->member_password != MD5($member_old_password)) {
			header("location: " . $PHP_SELF . "?error=password&member_email=" . $member_email);
			exit;
		}
	}
	
	$member_password = MD5($member_new_password);
	
	$date = now();
	
	$member_email = strtoupper($member_email);
	
	if($member_new_password != "") {
		$sql = "UPDATE member SET member_name='$member_name', member_email='$member_email', member_password='$member_password', member_newsletter='$preference_newsletter', updated_on='$date' WHERE member_id = '$session_member_id'";
		$result = mysql_query($sql);
	}
	else {
		$sql = "UPDATE member SET member_name='$member_name', member_email='$member_email', member_newsletter='$preference_newsletter', updated_on='$date' WHERE member_id = '$session_member_id'";
		$result = mysql_query($sql);
	}
	
	session_unregister("preference_name");
	session_unregister("preference_email");
	session_unregister("preference_newsletter");
	
	header("location: ./confirmation.php?confirm=preference");
	
}
?>

<html>

<head>
<title><?php print($page_title); ?></title>

<?php include('i.style.php'); ?>

<script language="javascript">
	
	function js_preference() {
		if(document.preference.member_name.value == "") {
			alert("Please enter a member name.");
			return false;
		}
		if(document.preference.member_email.value == "") {
			alert("Please enter your e-mail address.");
			return false;
		}
		if(document.preference.member_new_password.value != "" || document.preference.member_confirm_new_password.value != "") {
			if(document.preference.member_old_password.value == "") {
				alert("Please enter your old password.");
				return false;
			}
			if(document.preference.member_new_password.value == "") {
				alert("Please enter a new password.");
				return false;
			}
			if(document.preference.member_confirm_new_password.value == "") {
				alert("Please confirm your new password.");
				return false;
			}
			if(document.preference.member_new_password.value != document.preference.member_confirm_new_password.value) {
				alert("Your passwords do not match.");
				return false;
			}
		}
	}
	
</script>

</head>

<body <?php if($session_access == false) { ?>onload="document.login.email.focus();"<?php } ?> marginwidth="0" marginheight="0" leftmargin="0" topmargin="0" rightmargin="0">
	
	<table width="100%" cellpadding="0" cellspacing="0">
		
		<?php include('i.header.php'); ?>
		
		<tr>
			
			<td valign="top">
				
				<table cellpadding="0" cellspacing="0">
					
					<tr>
						
						<td><font face="verdana" size="1">&nbsp;&nbsp;&nbsp;</font></td>
						
					</tr>
					
				<tr>
					
					<td><font face="verdana" size="1">&nbsp;&nbsp;&nbsp;</font></td>
					
					<td valign="top">
						
						<table cellpadding="0" cellspacing="0">
							
							<?php include('i.tab.php'); ?>
							
						</table>
						
					</td>
					
					<td><font face="verdana" size="1">&nbsp;&nbsp;</font></td>
					
					<td valign="top" width="100%">
						
						<table width="100%" cellpadding="0" cellspacing="0">
							
							<tr>
								
								<td><font face="verdana" size="1">&nbsp;</font></td>
								
								<td width="100%">
									
									<table width="100%" cellpadding="0" cellspacing="0">
										
										<tr>
											
											<td><img src="./images/heading.preference.gif"></td>
											
										</tr>
										
										<tr>
											
											<td height="8" background="images/hr.gif"></td>
											
										</tr>
										
										<tr>
											
											<td><font face="verdana" size="1">&nbsp;</font></td>
											
										</tr>
										
										<form name="preference" method="post" onsubmit="return js_preference();" action="<?php print($PHP_SELF); ?>?mode=update">
										
										<tr>
											
											<td>
												
												<table>
													
													<?php
													$query = mysql_query("SELECT member_name, member_email, member_newsletter FROM member WHERE member_id = '$session_member_id'");
													$data = mysql_fetch_object($query, $db);
													?>
													
													<tr>
														
														<td><font face="verdana" size="1">Name: </font></td>
														<td><input type="text" name="member_name" class="form" style="width: 300px;" value="<?php print($data->member_name); ?>"></td>
														
													</tr>
													
													<?php if($error == "email") { ?>
													
													<tr>
														
														<td>&nbsp;</td>
														<td><font face="verdana" size="1">Please choose another e-mail address, <?php print($member_email); ?> is taken.</font></td>
														
													</tr>
													
													<?php } ?>
													
													<input type="hidden" name="current_email" value="<?php print($data->member_email); ?>">
													
													<tr>
														
														<td><font face="verdana" size="1">E-mail: </font></td>
														<td><input type="text" name="member_email" class="form" style="width: 300px;" value="<?php print($data->member_email); ?>"></td>
														
													</tr>
													
													<?php if($error == "password") { ?>
													
													<tr>
														
														<td>&nbsp;</td>
														<td><font face="verdana" size="1">The password you entered was incorrect, please try again.</font></td>
														
													</tr>
													
													<?php } ?>
													
													<tr>
														
														<td><font face="verdana" size="1">Old Password: </font></td>
														<td><input type="password" name="member_old_password" class="form" style="width: 300px;"></td>
														
													</tr>
													
													<tr>
														
														<td><font face="verdana" size="1">New Password: </font></td>
														<td><input type="password" name="member_new_password" class="form" style="width: 300px;"></td>
														
													</tr>
													
													<tr>
														
														<td><font face="verdana" size="1">Confirm New Password: </font></td>
														<td><input type="password" name="member_confirm_new_password" class="form" style="width: 300px;"></td>
														
													</tr>
													
													<tr>
														
														<td><font face="verdana" size="1">Newsletter: </font></td>
														
														<?php if($preference_newsletter == "Y" or $preference_newsletter == "N") { ?>
															
															<td><input type="checkbox" name="member_newsletter" class="form" value="1" <?php if($preference_newsletter == "Y") { ?>checked<?php } ?>></td>
															
														<?php } else { ?>
															
															<td><input type="checkbox" name="member_newsletter" class="form" value="1" <?php if($data->member_newsletter == "Y") { ?>checked<?php } ?>></td>
															
														<?php } ?>
														
													</tr>
													
													<tr>
														
														<td>&nbsp;</td>
														<td align="right"><input type="image" src="./images/bu.update.gif" name="update_button"></td>
														
													</tr>
													
													<tr>
														
														<td><font face="verdana" size="1"></font></td>
														<td><font face="verdana" size="1"><a href="./confirmation.php?confirm=cancel">Click here</a> to cancel your membership.</font></td>
														
													</tr>
													
												</table>
												
											</td>
											
										</tr>
										
										</form>
										
										<tr>
											
											<td><font face="verdana" size="1">&nbsp;</font></td>
											
										</tr>
										
										<tr>
											
											<td height="8" background="images/hr.gif"></td>
											
										</tr>
										
									</table>
									
								</td>
								
								<td><font face="verdana" size="1">&nbsp;</font></td>
								
							</tr>
							
						</table>
						
					</td>
					
				</tr>
				
			</table>
			
		</td>
		
	</tr>
	
	<?php include('i.footer.php'); ?>
	
	</table>
	
</body>

</html>