<?
ob_start();
session_start();
include("../var.php");

$pageTitle = "تسجيل الدخول";

$login = "";
if(isset($_POST['login'])){ $login = $_POST['login']; }
if ($login !== "")
{
	$user = $_POST['user'];
	$pass = $_POST['pass'];
	$con = mysqli_connect($DBHOST,$DBUSER,$DBPASS,$DBNAME) or die("Some error occurred during connection " . mysqli_error($con));  
	mysqli_query($con, "SET CHARACTER SET 'utf8'");
	$RES = mysqli_query($con, "SELECT * FROM `admin` WHERE `user`='$user' AND `pass`='$pass'");
	if(mysqli_num_rows($RES) == 1)
	{
		$sessionid = uniqid();
		$RES = mysqli_query($con, "UPDATE `admin` SET `session`='$sessionid',`lastlogin`=CURRENT_TIMESTAMP WHERE `user`='$user'");
		$_SESSION['admin'] = $user;
		$_SESSION['session'] = $sessionid;
		header("location:index.php");
	}
	else
	{
		$error = "خطا فى كلمة المرور او اسم المستخدم";
	}
	mysqli_close($con);
}

include("header.php");
?>


<form method="post" action="">
<table align="center" cellpadding="6" cellspacing="6" style="border:1px solid #006291; background:url(img/lock.jpg) left bottom no-repeat;">
<tr class="tablehead"><td colspan="2">تسجيل الدخول</td></tr>
<tr><td width="150" align="right">اسم المستخدم</td>
	<td width="200"><input type="text" name="user"></td>
</tr>
<tr><td align="right">كلمة المرور</td>
	<td><input type="password" name="pass"></td>
</tr>
<tr><td>&nbsp;</td>
	<td><input type="submit" name="login" value="تسجيل الدخول"></td>
</tr>
</table>
</form>
<?
include("footer.php");
?>