<?php 
session_start();

//Initial DB Query
	
	$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'];
	$fname = htmlspecialchars($info['fname']);
	$lname = htmlspecialchars($info['lname']);
	$email = htmlspecialchars($info['email']);
	$displayname = htmlspecialchars($info['displayname']);
	$bio = htmlspecialchars($info['bio']);
	$avatar = $info['avatar'];
	$mailopt = $info['mailopt']; //0 == checked
	
	
	$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'];
	
	if (is_file('seourls.php')) {
		include ('seourls.php');
		$seourls = 1;
	} else {
		$seourls = 0;
	}



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

	<title><?php echo $metatitle.$sitetitle; ?></title>
	<?php echo $metadesc; ?>
	
	<link href="<?php echo $siteurl; ?>/styles/main.css" media="all" rel="stylesheet" type="text/css" />
	<!--[if lte IE 6]><link href="<?php echo $siteurl; ?>/styles/ie.css" media="screen" rel="stylesheet" type="text/css" /><![endif]-->
	<!--[if lte IE 7]><link href="<?php echo $siteurl; ?>/styles/ie.css" media="screen" rel="stylesheet" type="text/css" /><![endif]-->
	
	<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script><script type="text/javascript">stLight.options({publisher:'377c8e5c-0cfb-4439-b65b-4543ab464d68'});</script>
	
</head>

<body>

<div id="container">

<!-- HEADER -->
<div id="header">
	<div id="logo"><a href="<?php echo $siteurl; ?>" >
	<?php if ($logo) { ?><img border="0" alt="<?php echo $sitetitle; ?>" src="<?php echo $siteurl;?>/admin/images/logo/<?php echo $logo; ?>" /></a> <? } else {
	echo "<h1 style=\"padding-left: 10px;\">".$sitetitle."</h1>"; } ?>
	</div>

<?php
session_start();
if (isset($_SESSION['valid_user'])) { ?>

<div id="login-area">
	Welcome, <?php echo $fname ?> (<a href="<?php echo $siteurl; ?>/author/logout.php">Logout</a>)
</div>


<?php } else { ?>

<div id="login-area">
	<a href="<?php echo $siteurl; ?>/login.php">Login</a> | <a href="<?php echo $siteurl; ?>/login.php">Submit Articles</a> | <a href="<?php echo $siteurl; ?>/login.php">Register</a>
</div>

<?php } ?>

<div id="searchbar">
<form name="search" method="get" action="<?php echo $siteurl; ?>/search.php" >
	<input type="text" name="s" style="width: 155px; padding: 4px; border: 1px solid gray; margin: 0;" /> 
	<input type="submit" id="searchsubmit" value="Search" />
</form>
</div>

<div class="clear"></div>

</div>

<div id="menu">
	<ul>
		<li><a href="<?php echo $siteurl; ?>">Home</a></li>
	<?php
	// Populates the Dropdown list with all pages
	$query = "select * from pages where onmenu=0;"; 
	$result = mysql_query($query,$connection) or die(mysql_error());
	$num_results = mysql_num_rows($result);
		
	for ($i=0; $i <$num_results; $i++) { 
		$row = mysql_fetch_assoc($result); 
		if ($seourls == 1) { $scrubtitle = generate_seo_link($row['title']); }
		
		if ($seourls == 1) { // With SEO URLS 
			echo "<li><a href=\"".$siteurl."/page/".$row['id']."/".$scrubtitle."/\">".$row['title']."</a></li>"; 
		} else {
			echo "<li><a href=\"".$siteurl."/page.php?p=".$row['id']."\">".$row['title']."</a></li>";
		}
	}
	?>
	</ul>
<br style="clear:left"/>
</div>

<?php 
	if($cathead == 1) { ?>
<div id="cat-head">
	<h2><?php echo $catheadtitle; ?></h2>
	
	<div id="ad">	<?php // PRINT OUT THE 468 x 60 code
	$query = "select * from adboxes where id=2;"; 
	$result = mysql_query($query,$connection) or die(mysql_error());
	$info = mysql_fetch_assoc($result);

	echo stripslashes($info['adcode']); 
	?>
</div>
	<div class="clear"></div>
</div> 
<?php } ?>

<div class="clear"></div>

