<?

include_once("db.php");
include_once("auth.php");


if(isset($uid) && isset($pwd)) {
	$user_data = get_user_by_uid($uid);
	if($user_data && $user_data[password] == $pwd) {
		$sid = create_session($user_data);
		if($user_data[type]=='Student')
			header("Location: student_main.php?sid=$sid");
		else if($user_data[type]=='Teacher')
			header("Location: teacher_main.php?sid=$sid");
		else if($user_data[type]=='Admin')
			header("Location: admin_main.php?sid=$sid");
		else
			unset($sid);

		exit();
	}
}

#if(!isset($sid)) {
	$SECTION_COLOR = "#330066";
	$SECTION_TITLE = "Login";


function page_trail()
{
	echo "Login";
}

function page_menu()
{
?>
	<p>
	Welcome to Bessie, the Annihilator!
	</p>

	<p>
	Copyright &copy; 2002, Devin Bunker
	</p>
<?
}


function page_body()
{
?>
	<h1>Login</h1>
	<form method="post" action="index.php">
	<table>
	 <tr>
	  <td>User name:</td>
	  <td><input type="text" size="20" name="uid"></td>
	 </tr>
	 <tr>
	  <td>Password:</td>
	  <td><input type="password" size="20" name="pwd"></td>
	 </tr>
	 <tr>
	  <td colspan="2" align="center"><input type="submit" value="Login"></td>
	 </tr>
	</table>
	</form>
<?
}


	include("template.php");
#}
?>
