<?php session_start(); ob_start(); ?>

   <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="style.css">
<title> Customer Login</title>
<?php  include("header.php");  ?>
<?php 



   $strError= array();

   if (isset($_POST['submit_btn'])) {

    
        
          $username = intval(mysqli_real_escape_string($connection, $_POST['username']));
		  
          if (empty($username)) {
            $strError[]= "Please enter booking ID...!!";
          }
          $password = intval(mysqli_real_escape_string($connection, $_POST['password']));
		  
          if (empty($password)) {
             $strError[]= "Please enter mobile no...!!";
          }

		  
	      
	
		  
		  
          if (empty($strError)) {
			  
           
		    
            $sqlSelect = "SELECT * FROM bookings WHERE booking_id = '".$username."'" ;

            $result = mysqli_query($connection,$sqlSelect);
            $count = mysqli_num_rows($result);

            while ($list = mysqli_fetch_assoc($result)) {
             
              $pass=$list['cell_1'];
               $_SESSION['LOGINID'] = $list['booking_id'];
              $_SESSION['LOGINNM'] = $list['email'];
            }
            
           

if ($password==$pass) {
    
    
   
     
    if($count > 0){

              $ip_address = $_SERVER['REMOTE_ADDR'];
              $browser_name = explode(" ",$_SERVER['HTTP_USER_AGENT']) ;
              $mybrowser = $browser_name[6];

                $lg_id=$_SESSION['LOGINID'];      


               $insertQry = "INSERT INTO `login_log` (`id`, `user_id`, `ip_address`, `browser_name`, `login_time`) VALUES (NULL, '$lg_id', '$ip_address', '$mybrowser', CURRENT_TIMESTAMP);";	
               
             /* echo $sqlUpdate;
              exit;*/

              $sqlUpdated = mysqli_query($connection, $insertQry);     
                header("Location:dashboard.php?flag=success");
                
              
            }

} 


            
            else{
              $strError[]= "Invalid Booking ID Or Mobile No !! ";
            }

          }
          

  }



?>
<body class="bg-default">
<div class="container">
    <div class="login_main clearfix">
        <div class="login_wrap clearfix">
            <?php   
                // Setting the value of logout variable
                if(isset($_GET['logout'])){
                         $logout = $_GET['logout'] ;
                }else{
                  $logout = "";
                }
                

                if( $logout == "success"){ ?>

            <div class="alert alert-success">
                <p>You are logged out!</p>
                <?php header("refresh:2 , url=index.php"); ?>
            </div>
            <?php } ?>

            <?php 
                //Setting the value of the logout variable
                if(isset($_GET['admin'])){
                       $logout = $_GET['admin'] ;
                }else{
                        $logout = "";
                }
                

                if( $logout == "updated"){ ?>

            <div class="alert alert-success">
                <p>Admin credentials updated successfully!</p>
                <?php header("refresh:2 , url=index.php"); ?>
            </div>
            <?php } ?>
            <div class="col-md-6 col-md-offset-3">
                   <h3 class="panel-title"> <center>
						 <img src="assets/images/logo_wd.png" width="30%" />
						 </center>
						 </h3>
                <div class="panel panel-primary">
                    <div class="panel-heading">
					     
                        <h3 class="panel-title">Customer Login</h3>
                    </div>
                    <div class="panel-body">
                        <?php for($i=0; $i< count($strError) ; $i++) { ?>


                        <div class="alert alert-danger">
                            <?php echo $strError[$i].nl2br("\n"); ?>
                        </div>

                        <?php } ?>

                        <form action="<?php echo $_SERVER['PHP_SELF'];  ?>" method="post">
                            <div class="form-group">
                                <div class="row">
                                    <div class="col-md-3">
                                        <label for="username"><p>Booking ID:</p></label>
                                    </div>
                                    <div class="col-md-9">
                                        <input type="text" class="form-control" placeholder="Enter Booking ID" name="username">
                                    </div>
                                </div>


                            </div>
                            <div class="form-group">
                                <div class="row">
                                    <div class="col-md-3">
                                        <label for="password"><p>Mobile No:</p></label>
                                    </div>
                                    <div class="col-md-9">
                                        <input type="password" class="form-control" placeholder="Enter Mobile No" name="password">
                                    </div>
                                </div>


                            </div>
                            <div class="form-group">
                                <div class="row">
                                    <div class="col-md-3">

                                    </div>
                                    <div class="col-md-9">
                                        <button type="submit" name="submit_btn" class="btn btn-primary">Submit</button>
                                    </div>
                                </div>


                            </div>


                        </form>
                    </div>
                </div>
               



            </div>

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