<?php
session_start();
// error_reporting();
include("include/dbConfig.php");



$error = '';

// FETCHING SITENAME
// 


if (isset($_SESSION['ulogin'])) {

    if(strlen($_SESSION['ulogin'])!=0){
        echo '<script>window.location="index.php"</script>';  
    }
        

}
    else
{


    // echo 'no';
    if(isset($_POST['submit']))
    {
        // echo 'form ';

        $username=$_POST['email'];
        echo $_POST['email']. $_POST['password'];
        $password=$_POST['password'];
        $Loginusername='';
        $q = "SELECT * FROM agents WHERE agent_email = '$username' AND agent_pass='$password'";
        // echo $q;

        $ret=$db->query($q);
        while($row =$ret->fetch_assoc()){
            $Loginusername=$row['agent_name'];
            $loginuserid = $row['agent_id'];
        }
        echo $Loginusername;
        $num=mysqli_num_rows($ret);
      
        if($num>0)
        {
            
            $extra="index.php";
            $_SESSION['ulogin']=$Loginusername;
            $_SESSION['userid']=$loginuserid;
            // $host=$_SERVER['HTTP_HOST'];
            // $uri=rtrim(dirname($_SERVER['PHP_SELF']),'/\\');
            //   echo ' yes';
            // header("Location: http://$host$uri/$extra"); 
            echo '<script>window.location.href="index.php"</script>';
            


        }
        else
        {
        $_SESSION['login_err'] ="Invalid username or password";
        // echo $error;
         // die();
        $extra="sign-in.php";
        
        echo '<script>window.location.href="login.php"</script>';

        exit();
        }
    }
    
    
?><!doctype html>
<html lang="en">

    
<!-- Mirrored from themesbrand.com/symox/layouts/auth-login.html by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 14 Jan 2022 05:58:51 GMT -->
<head>
        
        <meta charset="utf-8" />
        <title>Login</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta content="Premium Multipurpose Admin & Dashboard Template" name="description" />
        <meta content="Themesbrand" name="author" />
        <!-- App favicon -->
        <link rel="shortcut icon" href="assets/images/favicon.ico">

        <!-- Bootstrap Css -->
        <link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
        <!-- Icons Css -->
        <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
        <!-- App Css-->
        <link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" />

    </head>

    <body data-layout="horizontal" data-topbar="dark">

    <div class="authentication-bg min-vh-100">
        <div class="bg-overlay"></div>
        <div class="container">
            <div class="d-flex flex-column min-vh-100 px-3 pt-4">
                <div class="row justify-content-center my-auto">
                    <div class="col-md-8 col-lg-6 col-xl-5">

                       <div class="text-center mb-4">
                            <a href="index.html">
                                <img src="assets/images/logo-sm.svg" alt="" height="22"> <span class="logo-txt">Create Orders</span>
                            </a>
                       </div>

                        <div class="card">
                            <div class="card-body p-4"> 
                                <div class="text-center mt-2">
                                    <h5 class="text-primary">Welcome!</h5>
                                    <p class="text-muted">Sign in to continue.</p>
                                </div>
                                <div class="p-2 mt-4">
                                    <form action="" method="post">
        
                                        <div class="mb-3">
                                            <label class="form-label" for="username">Username</label>
                                            <input type="email" class="form-control" id="username" placeholder="Enter username" name="email" required>
                                        </div>
                
                                        <div class="mb-3">
                                           
                                            <label class="form-label" for="userpassword">Password</label>
                                            <input type="password" class="form-control" id="userpassword" placeholder="Enter password" name="password" required>
                                        </div>
                
                                         <p class="text-danger text-center"><?php if(isset($_SESSION['login_err'])) {
                                            echo $_SESSION['login_err'];$_SESSION['login_err'] = '';

                                    } ?></p>
                                        <div class="mt-3 text-end">
                                            <button class="btn btn-primary w-sm waves-effect waves-light" type="submit" name="submit">Log In</button>
                                        </div>

                                        

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

                    </div><!-- end col -->
                </div><!-- end row -->

                <div class="row">
                    <div class="col-lg-12">
                        <div class="text-center text-muted p-4">
                            <p class="text-white-50">© <script>document.write(new Date().getFullYear())</script> Create Orders. Made with <i class="mdi mdi-heart text-danger"></i> by Zohaib @ Eclosol</p>
                        </div>
                    </div>
                </div>

            </div>
        </div><!-- end container -->
    </div>
    <!-- end authentication section -->

        <!-- JAVASCRIPT -->
        <script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
        <script src="assets/libs/metismenujs/metismenujs.min.js"></script>
        <script src="assets/libs/simplebar/simplebar.min.js"></script>
        <script src="assets/libs/feather-icons/feather.min.js"></script>

    </body>

<!-- Mirrored from themesbrand.com/symox/layouts/auth-login.html by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 14 Jan 2022 05:58:51 GMT -->
</html>
<?php } ?>