<?php
//not for distributor login
session_start();


include "../conn.php";
include ("../sanitize.php");
sanitizeit();
if (isset($_POST["submit"]))
{
	$username = $_POST["username"];
	$password = $_POST["password"];

	$query = "select userID from theusers where userName='$username' and passwd='$password'";
	$result = mysql_query($query);

	if (mysql_num_rows($result) > 0)
	{
		while ($row = mysql_fetch_row($result)) 
		{
			$userID = $row[0];
		}
		
		$query = "delete from loginusers where userID='$userID'";
		mysql_query($query) or die(mysql_error());
		
		$query = "insert into loginusers values('$userID', NOW(), '";
		$query .= session_id();
		$query .= "')";
		
		//echo $query;
		mysql_query($query) or die(mysql_error());
		
		$_SESSION["denglu"] = 1;
		header ("location: index.php");
	}
	else
	{
		$err = "invalid username and password combination";
	}
}

?>
<html>
<head>
<title>Log in</title>
</head>
<body>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
<script language=JavaScript>
<!--

//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com

var message="Function Disabled!";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
//alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
//alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("return false")

// --> 
</script>
  <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="42%" id="AutoNumber1" height="109" bgcolor="#C0C0C0" align="center">
    <tr>
      <td width="100%" height="19"> 
        <div align="center">
          <font face="Verdana, Arial, Helvetica, sans-serif" size="-1"><b>Administrator Login</b></font>
        </div>
      </td>
  </tr>
  <tr>
      <td width="100%" height="130" bgcolor="#FFFFFF"> 
			<br>
        <table width="75%" border="0" align="center">
 
          <tr> 
            <td colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="red"><?php echo ($err?$err:"&nbsp;"); ?></font></td>
          </tr>
 
		  <tr> 
            <td width="38%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">User 
              ID:</font></td>
            <td width="62%"> 
              <input name="username" size="20" maxlength="50" value="">
            </td>
          </tr>
          <tr> 
            <td width="38%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Password: 
              </font></td>
            <td width="62%"> 
              <input type="password" name="password" size="20" maxlength="15" value="">
            </td>
          </tr>
          <tr> 
            <td width="38%">&nbsp;</td>
            <td width="62%">&nbsp;</td>
          </tr>
          <tr> 
            <td align="right" width="38%">&nbsp; </td>
            <td width="62%"> 
              <input type="submit" value="Login" name="submit">
            </td>
          </tr>
        </table>
        
      </td>
  </tr>
</table>
</form>
</body></html>