<?php
$loc = 2;	//1 = laptop, 2 = server

//if a zip code is passed to the page

if ($_GET['x'] == "") {
	if ($_POST['Password']) {
		//connect to DB 
			$db = mysql_connect("localhost", "newalexandria", "523i12"); 			
			mysql_select_db("newalexandria",$db);	//make active
	
	// select rec
		$sql = "SELECT User_ID, Name, Login, Password FROM users WHERE Password = '".$_POST['Password']."' AND Login = '".$_POST['Login']."'";

	//init db vars
		$result = mysql_query($sql);
		
	//if there's no records
	if (mysql_affected_rows($db)>0) {
		$curRow = mysql_fetch_array($result);
	
		setcookie("User_ID", $curRow["User_ID"],time()+14400);

		// add record of the login	
//		$sql = "INSERT INTO Logins (User_ID, Login_Date) VALUES (".$curRow['User_ID'].", '".date("Y-m-d h:m:s")."')";
		$result = mysql_query($sql);

		// initialize the forwarding page, if one does not exist
		if ($_POST['page']) { $page = $_POST['page'];} else { $page = "home.php";}
		
		// goto the page
		header("Location: ".$page);	
		}
	} else {  // there must have been an error
	?>
	<HTML><HEAD>
		<link rel="Stylesheet" type="text/css" href="style.css">
	<TITLE>Error</TITLE></HEAD>
	<body bgcolor="#ffffff" style="	background-image: none;">
	
	<?php if ($_GET['err']==1) { ?>
	There was a problem with your login information.  Please try to login again.
	<?php } else if ($_GET['err']==2) { ?>
	There was a problem displaying the page.  Please try to login again.
	<?php } ?>
	<BR><BR>
	If the problem persists, please contact the administrator.</font>
	<?php
	}
} elseif ($_GET['x'] == 0) {  // log the user out of the system
		setcookie("User_ID", "",time()+00);
	?>
	<HTML><HEAD>
		<link rel="Stylesheet" type="text/css" href="style.css">
	<TITLE>Logout</TITLE></HEAD>
	<BODY>
	You have been successfully logged out.<BR /><BR />
<?php } 

// ....and either way, display fields to try login again
?>

	<form action="login.php" method="post">
	<table border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td><span class="text">Login:</span></td>
		<td><input type="text" name="Login" size="15" maxlength="20" tabindex="2" accesskey="p"></td>
	</tr><tr>
		<td><span class="text">Password:</span></td>
		<td><input type="password" name="Password" size="15" maxlength="30" tabindex="2" accesskey="p"></td>
	</tr><tr>
		<td><input type="submit" name="submit" value="Login"></td>
	</tr>
</table>
</form>

<BODY></HTML>
