<?php
/*
* @author Istvan Franko
* @copyright 2014
*/
ob_start();
session_start();
?>

<html>
 
<head>
<title>Natty Notebooks Inc.</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>

<body>

<div id="container">

	<div id="header">
	<! header picture in css >
	</div>
	
	<div id="navigation">
		<?php include 'admin-nav-bar.php'; ?>
	</div>
	
<div id="aside">
	<!--Links for navigation-->
	<a href="../index.php"><p style="text-align:center">Public Page</a></p>
	
	<fieldset style="width:85%"><legend>HELP</legend>
	<p>If you haven't an account yet or can not log in please contact the system administrators.</p>
	</fieldset><br>
</div>

<div id="content">

<?php

 // define variables and set to empty values
$AdminErr = $PasswordErr = "";
$Admin = $Password = "";

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
  if (empty($_POST["Admin"]))
    {$AdminErr = "(Admin name is required)";}
  else
    {$Admin = test_input($_POST["Admin"]);}
	
  if (empty($_POST["Password"]))
    {$PasswordErr = "(Password is required)";}
  else
    {$Password = test_input($_POST["Password"]);}
	  
}

function test_input($data)
{
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}


if ($Admin != "" AND $Password != "")
{

$con = mysql_connect("localhost","*****","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}


mysql_select_db("university", $con);

$sql="SELECT * FROM admins WHERE AdminUserName='$Admin' AND AdminPassword='$Password' ";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $user and $password, table row must be 1 row
if($count==1)
{
$_SESSION['adminlogin'] = '1';
header('Location: admin.php');
}
else 
{
echo "<br>";
echo "<h1>Wrong Username or Password</h1><br>";
}

//close the connection to the database.
mysql_close($con);
}
ob_end_flush()
?>

<br>
<fieldset style="width:70%"><legend>LOG-IN HERE</legend>
<p><span class="error">* required fields</span></p>
<form  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

User: <span class="error">*</span><span class="error"> <?php echo $AdminErr;?> </span>
<br><input type="text" name="Admin" size="40" value="<?php echo $Admin; ?>"><br><br>

Password: <span class="error">*</span><span class="error"> <?php echo $PasswordErr;?> </span>
<br><input type="password" name="Password" size="40"><br>

<input id="button" type="submit" name="submit" value="Log-In">
</form>
</fieldset>

</div>

<div id="footer">
<p align="center">Copyright &#169; Istvan Franko, 2014</p>
</div>
	

</div>
</body>
</html>