<?
include "header.php";

if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = "login"; }



if($task == "login_do") {

$user_sent = $_POST['user_sent'];
$pass_sent = $_POST['pass_sent'];

if($user_sent == $admin_info[login_name] AND $pass_sent == $admin_info[password]) {

$user_sent = encrypt($user_sent);
$pass_sent = encrypt($pass_sent);
$admin_key = encrypt($admin_info[special_code]);
setcookie("admin_cookie", "$user_sent", 0, "/");
setcookie("pass_cookie", "$pass_sent", 0, "/");
setcookie("admk_cookie", "$admin_key", 0, "/");
header("Location: index.php");
exit();
} else {

$response = "The login information you provided was invalid. Please try again.";

}
}



echo "
<html>
<head>
<title>IMS Administration Console</title>
<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">
<link rel=\"STYLESHEET\" type=\"text/css\" href=\"../styles.css\">
<script language=\"javascript\">
<!--
function focus() { document.login.user_sent.focus(); }
// -->
</script>
</head>
<body onLoad=\"focus()\" style='margin: 0px;'>
<br><br><br><br><br><br><br><br><br><br><br><br><br>
<center>
<img src='../icons/admin_title.gif' border='0'><br>
<table width='100%' cellpadding='0' cellspacing='0'>
<form name='login' action='login.php' method='POST'>
<tr><td style='border-top: 1px solid #AAAAAA; border-bottom: 1px solid #AAAAAA; background: #EEEEEE; padding: 5px;'>
   <table cellpadding='0' cellspacing='0' align='center'>
   <tr>
   <td><font class='small'>Username<br><input class='text' type='text' name='user_sent'>&nbsp;&nbsp;</td>
   <td><font class='small'>Password<br><input class='text' type='password' name='pass_sent'>&nbsp;&nbsp;</td>
   <td valign='bottom'><input class='button' type='submit' value='Login' style='margin-bottom: 3px;'></td>
   </tr>
   <tr><td colspan='3'>$response</td></tr>
   </table>
</td></tr>
<input type='hidden' name='task' value='login_do'>
</form>
</table>
</center>
</body>
</html>
";

?>