<?php 
session_start();

$pagetitle = "Author Profile - Author Control Panel";
include('../config.php');
include('security.php');

// Initial DB Connect (Can't use header)
	$query = 'select * from authors ' 
			 ."where username ='".$_SESSION['valid_user']."'";
				 
	$result = mysql_query($query,$connection) or die(mysql_error());
	
	//Create user data variables		
	$info = mysql_fetch_array($result);
	$id = $info['id'];
	$username = $info['username'];
	$password = $info['password'];
	$url = $info['url'];
	$fname = htmlspecialchars($info['fname']);
	$email = htmlspecialchars($info['email']);
	$displayname = htmlspecialchars($info['displayname']);
	$bio = addslashes($info['bio']);
	$gravatar = $info['gravatar'];
	$mailopt = $info['mailopt']; //0 == checked


// Update the settings 
if(isset($_POST['profileupdate'])) { 

	if(get_magic_quotes_gpc()) {
		$updatedisplay = $_POST['displayname'];
		$updateurl = $_POST['url'];
		$updatebio = $_POST['bio'];
	} else {
		$updatedisplay = mysql_real_escape_string($_POST['displayname']);
		$updateurl = mysql_real_escape_string($_POST['url']);
		$updatebio = mysql_real_escape_string($_POST['bio']);
	}	
	
	$sql = "UPDATE `authors` SET `displayname`='".$updatedisplay."', `url`='".$updateurl."', `bio`='".$updatebio."' WHERE `id`=".$id;
			$query = mysql_query($sql);
			header('Location: profile.php?profileupdate=true');
			exit();
}

include('header.php'); ?>




<!-- LEFT SIDEBAR -->
<?php include('../sidebar.php'); ?>

<!-- CONTENT AREA -->
<div id="content-full">	


<h1>Update Your Author Profile</h1>

<br/>

<!-- Confirmations -->

<?php if($_GET["profileupdate"] == "true") {
	echo '<div class="alert" style="text-align: center;"><b>Settings updated!</b></div>';
} 
?>


<table>
<tr><td valign="top" style="width:450px; padding:0 20px 0 10px; border-right: 3px solid #F3F1E9;">
<form method="post" action="profile.php">
<table><tr><td style="width:150px;">Pen Name:</td>
<td><input type="text" name="displayname" value="<?php echo $displayname; ?>" style="width: 250px;"></td></tr>
<tr><td>Homepage:</td>
<td><input type="text" name="url" value="<?php echo $url; ?>" style="width: 250px;"></td></tr>
<tr><td><br/>Bio:</td>
<td><br/><textarea name="bio" style="width: 200px; height: 220px;"><?php echo $bio; ?></textarea></td></tr>
<tr><td colspan="2" align="center">
<br/><input type="submit" value="Update" id="submitstyle"></td></tr>
<input name="profileupdate" type="hidden" id="profileupdate" />
</table></form>


</td>
<td style="padding:0 0 0 20px;" valign="top">
<p><b>Your Current Avatar:</b><br/><br/>
<img style="border:2px solid #999; margin: 6px 6px 8px 0; float: left;" src="<?php echo $gravatar; ?>" />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 this site.</p>

</td></tr></table>
<br/>

<div style="clear:both; width: 100%; padding-top: 15px; border-bottom: 3px solid #F3F1E9;"></div>



</div> <!-- End Content -->


<?php include('../footer.php'); ?>