<?php     
session_start();
if(!isset($_SESSION)){

 header('location: login.php');
 
} 
?>
<!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, maximum-scale=1, shrink-to-fit=no">
    <title>Stock Inspection - Oliac</title>
    <link rel="icon" type="image/x-icon" href="assets/img/favicon.ico"/>
    <!-- BEGIN GLOBAL MANDATORY STYLES -->
    <link href="https://fonts.googleapis.com/css?family=Quicksand:400,500,600,700&display=swap" rel="stylesheet">
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/plugins.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/authentication/form-1.css" rel="stylesheet" type="text/css" />
    <!-- END GLOBAL MANDATORY STYLES -->
    <link rel="stylesheet" type="text/css" href="assets/css/forms/theme-checkbox-radio.css">
    <link rel="stylesheet" type="text/css" href="assets/css/forms/switches.css">
      <!-- toastr -->
    <link href="plugins/notification/snackbar/snackbar.min.css" rel="stylesheet" type="text/css" />
</head>

 
<body class="form">
     
    <div class="form-container">
        <div class="form-form">
            <div class="form-form-wrap">
                <div class="form-container">
                    <div class="form-content">

                        <h1 class="">Log In to <a ><span class="brand-name">Oliac Stock Insepection Dashboard</span></a></h1>
                      
                        <!-- <p class="signup-link">New Here? <a href="auth_register.html">Create an account</a></p>
                       -->
                        <form class="text-left"  onsubmit="return false">
                            <div class="form">

                                <div id="username-field" class="field-wrapper input">
                                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>
                                    <input id="username" name="username" type="text" class="form-control" placeholder="Username"  >
                                    <div class="invalid-feedback">
                                     Please fill the userID
                                    </div>
                                </div>

                                <div id="password-field" class="field-wrapper input mb-2">
                                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-lock"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>
                                    <input id="password" name="password" type="password" class="form-control" placeholder="Password">
                                    <div class="invalid-feedback">
                                     Please fill the Password
                                    </div>
                                </div>
                                <div class="d-sm-flex justify-content-between">
                                    <div class="field-wrapper toggle-pass">
                                        <p class="d-inline-block">Show Password</p>
                                        <label class="switch s-primary">
                                            <input type="checkbox" id="toggle-password" class="d-none">
                                            <span class="slider round"></span>
                                        </label>
                                    </div>
                                    <div class="field-wrapper">
                                        <button type="submit" class="btn btn-primary" id="btnLogin" value="">Log In</button>
                                    </div>
                                    
                                </div>

                                <!-- <div class="field-wrapper text-center keep-logged-in">
                                    <div class="n-chk new-checkbox checkbox-outline-primary">
                                        <label class="new-control new-checkbox checkbox-outline-primary">
                                          <input type="checkbox" class="new-control-input">
                                          <span class="new-control-indicator"></span>Keep me logged in
                                        </label>
                                    </div>
                                </div> -->

                                <!-- <div class="field-wrapper">
                                    <a href="auth_pass_recovery.html" class="forgot-pass-link">Forgot Password?</a>
                                </div> -->

                            </div>
                        </form>                        
                       <p class="terms-conditions">© 2022 All Rights Reserved. <a href="http://oliac.com/">Stock Inspection</a> is a product of Oliac.
                        <!-- < <a href="javascript:void(0);">Cookie Preferences</a>, <a href="javascript:void(0);">Privacy</a>, and <a href="javascript:void(0);">Terms</a>. -->
                    </p>

                    </div>                    
                </div>
            </div>
        </div>
        <div class="form-image">
            <div class="l-image">
            </div>
        </div>
    </div>

    
    <!-- BEGIN GLOBAL MANDATORY SCRIPTS -->
    <script src="assets/js/libs/jquery-3.1.1.min.js"></script>
    <script src="bootstrap/js/popper.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
    
    <!-- END GLOBAL MANDATORY SCRIPTS -->
    <script src="assets/js/authentication/form-1.js"></script>

  
    <script src="plugins/notification/snackbar/snackbar.min.js"></script>
    <!-- END PAGE LEVEL PLUGINS -->

    <!--  BEGIN CUSTOM SCRIPTS FILE  -->
    <script src="assets/js/components/notification/custom-snackbar.js"></script>

    <script>

        
        $("#btnLogin").on("click",function(){
           
           
          
            if($("#username").val().length > 0  ){
                
                if($("#password").val().length>0){
                  
                
                    $.ajax({
                    type:'POST',
                    dataType: "json",
                    data : {

                        user: $("#username").val(),
                        
                        password: $("#password").val()

                    },
                    url:'DB/login.php',
                    success:function success(data){
                      
                        if(data.status){
                       
                        // console.log(data.data[0]) 
                        // document.cookie = "userID" + "=" +data.data[0].id;
                        // document.cookie = "username" + "=" +data.data[0].userID;
                        // document.cookie = "isLogin" + "=" +true;
                    
                         localStorage.setItem('userID',data.data[0].id)
                         localStorage.setItem('username',data.data[0].userID)
                         localStorage.setItem('isLogin',true)
                        
                        //localStorage.setItem('sessionDate',true)
                        
                        window.location.replace("index.php")

                        }else{
                        Snackbar.show({
                        text: data.response,
                        pos: 'top-center'
                        });
                    }
                    
                    }
       
                }) 
 

                }else{
                       Snackbar.show({
                        text: 'Password is required',
                        pos: 'top-center'
                    });
                     
                }
            }else{
                  Snackbar.show({
                        text: 'User name is required',
                        pos: 'top-center'
                    });
            }
        });


    </script>
</body>
</html>