<?php 
	session_start();
	include ('../config.php');
	include ('secureadmin.php');
	
	$sitequery = 'select * from settings;';
	$siteresult = mysql_query($sitequery,$connection) or die(mysql_error());
	
	//Create site settings variables		
	$siteinfo = mysql_fetch_array($siteresult);
	$sitetitle = $siteinfo['title'];
	$siteurl = $siteinfo['url'];
	$logo = $siteinfo['logourl'];
	$statcode = $siteinfo['statcode'];

				
	$query = "select * from admins;"; 
	$result = mysql_query($query,$connection) or die(mysql_error());
	$info = mysql_fetch_assoc($result);
	$oldemail = $info['email'];
	$oldusername = $info['username'];
	$oldname = $info['name'];
	$avatar = $info['avatar'];

	
if(isset($_POST['update'])) { 
	
		$name = mysql_real_escape_string($_POST['name']);
		$email = mysql_real_escape_string($_POST['email']);
		$pass1 = $_POST['pass1'];
		$pass2 = $_POST['pass2'];
		$avatar = "http://www.gravatar.com/avatar/".md5( strtolower( trim( $email ) ) )."?d=".$siteurl."/images/avatar.png&s=90";
		
	
	if ($pass1 == NULL) {  
// New Pass Blank --- Ignore Password Changes...	
	$sql1 = "UPDATE `admins` SET `name`='".$name."', `email`='".$email."', `avatar`='".$avatar."' WHERE `id`=1";
	$query1 = mysql_query($sql1);
	
	$sql2 = "UPDATE `authors` SET `fname`='".$name."', `displayname`='".$name."',  `email`='".$email."', `gravatar`='".$avatar."' WHERE `id`=1";
	$query2 = mysql_query($sql2);

	header('Location: adminsettings.php?settingsupdate=true');
	exit();
			
	} else {
// Change Password Also	
		if ($pass1 == $pass2) {
		$sql1 = "UPDATE `admins` SET `name`='".$name."', `email`='".$email."', `avatar`='".$avatar."', 
					`password`='".md5($pass1)."' WHERE `id`=1";
		$query1 = mysql_query($sql1);
		
		$sql2 = "UPDATE `authors` SET `fname`='".$name."', `displayname`='".$name."', `email`='".$email."', `gravatar`='".$avatar."', 
					`password`='".md5($pass1)."' WHERE `id`=1";
		$query2 = mysql_query($sql2);

		header('Location: adminsettings.php?settingsupdate=true');
		exit();
	} else {
			header('Location: adminsettings.php?settingsupdate=passnomatch');
			exit();
	}
}
	
}
	$metatitle = "Admin Account Settings - Admin Control Panel";
	include ('includes/document_head.php');

?>
		<div id="wrapper">
			<?php include 'includes/topbar.php'?>		
			<?php include 'includes/sidebar.php'?>
			
			<div class="main_container container_1 clearfix">
				
					
			<div class="flat_area grid_16">
			
				<h2>Admin Account Settings</h2>
				<p>Use this page to manage your admin account. </p>
				<br/>
				
				
		<div class="box grid_16 round_all">
				<h2>Update Your Admin Settings</h2>
					<div class="block">
	
			
			<?php 
	if($_GET["settingsupdate"] == "passnomatch") 
		echo '<p  style=" padding-left: 15px; color: red;">Passwords didn\'t Match</p>';
	if($_GET["settingsupdate"] == "true") 
		echo '<p  style="padding-left: 15px; color: red;">Settings updated!</p>';
?>

	<form style="padding-left: 15px;" name="submission" enctype="multipart/form-data" method="POST" action="adminsettings.php">

	<b>Name:</b><br/>
	<input type="text" name="name" style="width: 250px;" value="<?php echo $oldname; ?>">
	
	<b>Email:</b><br/>
	<input type="text" name="email" style="width: 250px;" value="<?php echo $oldemail; ?>">
	
	<b>New Password:</b><br/>
	<p>(Leave the password fields blank to retain old password)</p>
	<input type="password" name="pass1" style="width: 250px;">

	<b>New Password (again):</b><br/>
	<input type="password" name="pass2" style="width: 250px;">

	
	<div style="clear:both"></div>


	<input name="update" type="hidden" id="update" />
	<button type="submit" id="submitstyle" name="save" class="button_colour round_all"><img height="24" width="24" alt="Bended Arrow Right" src="images/icons/small/white/Bended Arrow Right.png"><span>Update Settings</span></button>

</form>

<br/><br/><br/>
					
						<p style="padding: 15px 0;"><b>Your Current Avatar:</b><br/><br/>
<img style="border:2px solid #999; margin: 6px 6px 8px 0; float: left;" src="<?php echo $avatar; ?>" />This site uses Gravatars - global avatars tied to your email address. To learn more about Gravatars, or to update your image, visit <a href="http://gravatar.com">Gravatar.com</a> and register with the email address you use to access this site. Your image will be updated across your directory.</p>

					</div>
				</div>








	</div>



			</div>
			
			
			
		</div>	
<?php include 'includes/closing_items.php'?>