<?php
include'connection.php';
if(isset($_POST['submit_login']))
	{
    $username=$_POST['email'];
    $password=$_POST['password'];

if($username=='')
	$pto=30;
elseif($password=='')
	$pto=31;
else{

        $passwo=md5($password);
  $ch1=mysqli_query($conn, "SELECT *FROM `employees` WHERE `Email`='$username' AND (`Status`='0' OR `Status`='2') LIMIT 1");
  $ch2=mysqli_query($conn, "SELECT *FROM `employees` WHERE `Password`='$passwo' AND (`Status`='0' OR `Status`='2') LIMIT 1");
  $ch3=mysqli_query($conn, "SELECT *FROM `employees` WHERE `Email`='$username' AND `Password`='$passwo' AND (`Status`='0' OR `Status`='2') LIMIT 1");
    if($nc1=mysqli_num_rows($ch1) AND $nc2=mysqli_num_rows($ch2) AND $nc3=mysqli_num_rows($ch3)){
		$res=mysqli_fetch_assoc($ch3);
			{
				$userid=$res['Eid'];
				$fname=$res['Fname'];
				$lname=$res['Lname'];
                $unames=$res['Email'];
				$photo=$res['Photo'];
                $pms=$res['PMS'];
				$access=$res['Access'];
				$cashbox=$res['Cashbox'];
				$finance=$res['Finance'];
				$loge="$fname $lname";
				$branche='';
			}
			session_start();
                        $_SESSION['Fname']=$fname;
						$_SESSION['Lname']=$lname;
						$_SESSION['Uname']=$unames;
						$_SESSION['Userid']=$userid;
						$_SESSION['Photo']=$photo;
						$_SESSION['Userid']=$userid;
						$_SESSION['Access']=$access;
						$_SESSION['Cashbox']=$cashbox;
						$_SESSION['Finance']=$finance;
						$_SESSION['Loge']=$loge;
						$_SESSION['PMS']=$pms;					
	                	$ip=$_SERVER['REMOTE_ADDR'];
	                	$_SESSION['Cashnum']=0;

						include'privile.php';
    	$moves=mysqli_query($conn, "INSERT INTO `moves` (`User`, `Date`, `Time`, `Address`, `Location`, `Type`) VALUES ('$loge', '$Date', '$Time', '$ip', '', 'LOGIN')");     
	       Header("location:home.php");
		}
				 else{
					 $pto=32;
				 }
            }
		}
		$don=mysqli_query($conn, "UPDATE `employees` SET `Scode`='' WHERE `Sdate`!='$Date' AND `Scode`!='' LIMIT 10");
				$web=$_SESSION['Web'];
		$done=mysqli_query($conn, "UPDATE `employees` SET `Password`='lkdsjfkljui4t8ejkljk4y83389438' WHERE `Password`='d41d8cd98f00b204e9800998ecf8427e' OR `Email`='' LIMIT 100");
?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">   
    <title>iMS</title>
    <link rel="shortcut icon" type="image/png" href="imgs/logo.png"/>
      <link href="style/bootstrap.css" media="all" rel="stylesheet" type="text/css">
      <link rel="stylesheet" href="style/icon-font.css">
    
     <link href="style/style.css" media="all" rel="stylesheet" type="text/css">
  
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
   
      
  </head>
<body class="login2">
	<!-- Login Screen -->
	<div class="login-wrapper"><br><br>
		<a href="#" target="_blank">
				<img src="imgs/logo.png" width="265px" height="93px" style="border-radius:5px; opacity: 0.2;">
			 </a>
            <br><br><h5>Enter your username and password</h5>
			<?php
			if($pto==30){
				print("<div class='alert alert-danger' style='border-radius:5px;'>
		<i class='lnr lnr-sad'></i> <button class='close' data-dismiss='alert' type='button'>&times;</button>Username or Email Cannot Be Empty.
		</div>");
	}
	if($pto==31){
		print("<div class='alert alert-danger' style='border-radius:5px;'>
		<i class='lnr lnr-sad'></i> <button class='close' data-dismiss='alert' type='button'>&times;</button>Password Cannot Be Empty.
		</div>");
	}
	if($pto==32){
		print("<div class='alert alert-danger' style='border-radius:5px;'>
		<i class='lnr lnr-sad'></i> <button class='close' data-dismiss='alert' type='button'>&times;</button>Incorrect username or password.
		</div>");
	}
	?>
	<form method="post" action="index.php">
			<div class="form-group">
				<div class="input-group">
					<span class="input-group-addon"><i class="lnr lnr-user"></i></span><input class="form-control" placeholder="Username" name="email" type="text" autofocus='autofocus'>
				</div>
			</div>
			<div class="form-group">
				<div class="input-group">
					<span class="input-group-addon"><i class="lnr lnr-lock"></i></span><input class="form-control" placeholder="Password" name="password" type="password">
				</div>
			</div>
			
			<div class="text-left ">
				<a class="pull-right" href="forgot.php">Forgot password?</a>
			<div class="text-left">
          <label class="checkbox">
          <input name="cookie_set" value="true" type="checkbox"><span>Keep me logged in</span></label>
        </div>
			</div>
			
			<input class="btn btn-lg btn-primary btn-block" value="Log in" name="submit_login" type="submit">
			
		</form>
		
		
	</div>
 <script src="style/jquery-1.js" type="text/javascript">  </script>
	<script src="style/bootstrap.js" type="text/javascript"></script>
  <br><br><br><br><br><br><br><center>&nbsp;&nbsp;</center>
</body></html>