<?php $cathead = 0;
include('config.php');
session_start();

if (isset($_POST['userid']) && isset($_POST['password'])) {
	// if the user has just tried to log in 
	$username = $_POST['userid']; 
	$password = $_POST['password'];
	
	$query = 'select * from authors ' 
			 ."where username ='$username' "
			 ." and password = md5('$password')";
				 
	$result = mysql_query($query,$connection) or die(mysql_error());

		
	if (mysql_num_rows($result)) {
		// if they are in the database register the user id 
		$_SESSION['valid_user'] = $username;
	}
	 
} 

if (isset($_SESSION['valid_user'])) {
	 if ($_POST['remember']) { // Set cookie if user checked remember me
	 	setcookie("cookname", $username, time()+60*60*24*100, "/");
    	setcookie("cookpass", md5($password), time()+60*60*24*100, "/");
    }
	header ("Location: author/index.php"); 
} 
	
include('header.php'); 
?>


<?php include('sidebar.php'); ?>

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

<table>
<tr><td valign="top" style="width:300px; padding:0 30px 0 40px; border-right: 3px solid #F3F1E9;"><h1 id="title">Login to Your Account</h1>
Login to access your author control panel:<br/><br/>
	<?
	if (isset($userid)) {
	// if they've tried and failed to log in 
	echo '<div class="warning" style="width:255px;">Incorrect Username or password</div>';
	} 
	?>	

	<form method="post" action="login.php">
	<table>
	<tr><td style="width:100px;">Username:</td>
	<td><input type="text" name="userid" style="width:150px;"></td></tr>
	<tr><td>Password:</td>
	<td><input type="password" name="password" style="width:150px;"></td></tr>
	<tr><td>Remember Me:</td>
	<td><input type="checkbox" name="remember"></td></tr>
	<tr><td colspan="2" align="center">
	<input type="submit" id="submitstyle" value="Log in"></td></tr>
	</table></form>
	<br/>
	<p><a href="forgot.php">Forgot Password?</a></p>
</td>

<td style="padding:0 0 0 55px;" valign="top">

<?php 
	if($_GET["account"] == "new") {
		echo '
		<h1>Success!</h1> 
		<div class="alert" style="text-align: center; width:100%;">
		Your Account has been Created. You may login to the left.</div>';
		} else {
?>

<h1>Don't have an account?</h1>
Signup now to submit your own articles:


<!-- Registration Validation -->
<script type="text/javascript" src="js/validate_reg.js"></script>


<?php 
	if($_GET["error"] == "email") 
		echo '<div class="alert"  style="text-align: center; width:280px;">That email address is already in use!</div>';
	if($_GET["error"] == "user") 
		echo '<div class="alert"  style="text-align: center; width:280px;">That username address is already in use!</div>';
?>

		<form action="doregister.php" method="post" name="submission" onsubmit="return validateReg( );">
		
		<table>
		<tr><td style="width:130px;">Username:</td>
			<td><input id="username" name="username" type="text" style="width:150px;"/></td></tr>

		<tr><td>Full Name:</td>
			<td><input id="fname" name="fname" type="text" style="width:150px;"/></td></tr>

		<tr><td>Email:</td>
			<td><input id="email" name="email" type="text" style="width:150px;"/></td></tr>
						
		<tr><td>Password:</td>
			<td><input id="pWord" name="pWord" type="password" style="width:150px;"/></td></tr>

		<tr><td><label for="cpWord">Password (again):</td>
			<td><input id="cpWord" name="cpWord" type="password" style="width:150px;"/></td></tr>
		<br/>
		
		<tr><td colspan="2" align="center">
		<input type="hidden" name="register" id="register">
		<button class="submit" id="submitstyle" type="submit">Register</button></td></tr>
		</table></form>

<?php } ?>
</td></tr></table>


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


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