<?php
session_start();
include("../db.php");

extract($_GET);
if(isset($submit)) {
      // username and password sent from form 
      
       $myusername = $userid;
      $mypassword = $password; 
      
      $sql = mysqli_query($conn,"SELECT * FROM `user` WHERE (email='$myusername' or mobile='$myusername') and password ='$mypassword'");

      $row = mysqli_fetch_array($sql,MYSQLI_ASSOC);
      $dbname=$row['name'];
      $dbemail=$row['email'];
      $dbnumber=$row['mobile'];
      $dbpassword=$row['password'];
      $idd=$row['id'];
      
       $count = mysqli_num_rows($sql);
      
      // If result matched $myusername and $mypassword, table row must be 1 row
    
      if($count == 1) {
        date_default_timezone_set("Asia/Calcutta");
         $today = date("Y-m-d h:i:s");
         // $today = date("Y-m-d H:i:s");
         // session_register("myusername");
          $_SESSION['time2'] = $today;
          $_SESSION['email2']=$dbemail;
          $_SESSION['number2']=$dbnumber;
          $_SESSION['password2']=$dbpassword;
          $_SESSION['name2']=$dbname;
          $_SESSION['id2']=$idd;
          // header("location:add_product.phqqq
echo '<script>window.location.assign("index.php");</script>';
  } else{
echo '<script>alert("User id or password is wrong.");</script>';

$error="<div class='alert alert-danger'><b>There was a problem</b>
We cannot find an account with that Email and Password</div>";
}
   }

?>
<!DOCTYPE html>
<html lang="en">
<head> 
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<meta name="description-gambolthemes" content="">
	<meta name="author-gambolthemes" content="">
	<title>Admin login</title>
	<link href="css/styles.css" rel="stylesheet">
	<link href="css/admin-style.css" rel="stylesheet">
	
	<!-- Vendor Stylesheets -->
	<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
	<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet">
	
</head>

    <body class="bg-sign">
        <div id="layoutAuthentication">
            <div id="layoutAuthentication_content">
                <main>
                    <div class="container">
                        <div class="row justify-content-center">
                            <div class="col-lg-5">
                                <div class="card shadow-lg border-0 rounded-lg mt-5">
                                    <div class="card-header card-sign-header">
										<h3 class="text-center font-weight-light my-4">Admin Login</h3>
                                        <?php if(isset($error)) { echo $error; } ?>
									</div>
                                    <div class="card-body">
                                        <form>
                                            <div class="form-group">
												<label class="form-label" for="inputEmailAddress">Mobile no | Email ID*</label>
												<input class="form-control py-3" name="userid" id="inputEmailAddress" type="text" placeholder="Enter Mobile number" value="<?php if(isset($_COOKIE["member_login"])) { echo $_COOKIE["member_login"]; } ?>">
											</div>
                                            <div class="form-group">
												<label class="form-label" for="inputPassword">Password*</label>
												<input class="form-control py-3" name="password" id="inputPassword" type="password" placeholder="Enter password">
											</div>
                                            <div class="form-group">
                                                <div class="custom-control custom-checkbox">
													<input class="custom-control-input" id="rememberPasswordCheck" type="checkbox" name="remember" <?php if(isset($_COOKIE["member_login"])) { ?> checked <?php } ?>/>
													<label class="custom-control-label"  for="rememberPasswordCheck">Remember password</label>
												</div>
                                            </div>
                                            <div class="form-group d-flex align-items-center justify-content-between mt-4 mb-0">
												<button class="btn btn-sign hover-btn" name="submit" value="login">Login</button>
											
                                            </div>
                                        </form><br>
                                       <center> <a href="../index.php" class="btn btn-danger hover-btn " name="submit" value="login">Go back</a></center>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </main>
            </div>
        </div>
		 <script src="js/jquery-3.4.1.min.js"></script>
        <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
        <script src="js/scripts.js"></script>		
		
    </body>
</html>
