<?php
if(isset($_GET['username'])){
    $username =  $_GET['username'];
    $pass =  $_GET['password'];
}
?>
<!DOCTYPE html>
<html lang="en" class="light-style customizer-hide" dir="ltr" data-theme="theme-default" data-template="vertical-menu-template-free">
    <head>
		<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"/>
        <title>Cherry Dashboard</title>
        <meta name="description" content="" />
        <!-- Favicon -->
        <link rel="icon" type="image/x-icon" href="assets/login/assets3/img/favicon/favicon.ico" />

        <!-- Fonts -->
        <link rel="preconnect" href="https://fonts.googleapis.com" />
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
        <link href="https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap" rel="stylesheet"/>

        <!-- Icons. Uncomment required icon fonts -->
        <link rel="stylesheet" href="assets/login/assets3/vendor/fonts/boxicons.css" />

        <!-- Core CSS -->
        <link rel="stylesheet" href="assets/login/assets3/vendor/css/core.css" class="template-customizer-core-css" />
        <link rel="stylesheet" href="assets/login/assets3/vendor/css/theme-default.css" class="template-customizer-theme-css" />
        <link rel="stylesheet" href="assets/login/assets3/css/demo.css" />

        <!-- Vendors CSS -->
        <link rel="stylesheet" href="assets/login/assets3/vendor/libs/perfect-scrollbar/perfect-scrollbar.css" />

        <!-- Page CSS -->
        <!-- Page -->
        <link rel="stylesheet" href="assets/login/assets3/vendor/css/pages/page-auth.css" />
        <!-- Helpers -->
        <script src="assets/login/assets3/vendor/js/helpers.js"></script>

        <!--! Template customizer & Theme config files MUST be included after core stylesheets and helpers.js in the <head> section -->
        <!--? Config:  Mandatory theme config file contain global vars & default theme options, Set your preferred theme option in this file.  -->
        <script src="assets/login/assets3/js/config.js"></script>
        <style>
          body
          {
              font-family: 'Roboto', sans-serif !important;
              background-color: #E4ECF3;
          }
          .bg-imgX
          {
            position: absolute;
            right: 0%;
            height: 450px;
            /* width: 900px; */
            top: 10%;
          }
          .authentication-wrapper.authentication-basic.container-p-y
          {
            position:fixed;
          }
          .authentication-wrapper.authentication-basic .authentication-inner:before 
          {
            background-image:none;
          }
          .light-style .authentication-wrapper.authentication-basic .authentication-inner:after
          {
            background-image:none;
          }
          .authentication-wrapper.authentication-basic .authentication-inner 
          {
            position: absolute;
            left: 10%;
            top: 10%;
          }
        </style>
    </head>

  <body>
    <!-- Content -->
    <div class="container-xxl">
      <img src="assets/images/nlogo.png" style="margin-top:30px;height:50px;margin-left:20px"alt="">
      <img class="bg-imgX" src="assets/images/login_bg2.png" alt="">
      <div class="authentication-wrapper authentication-basic container-p-y">
        <div class="authentication-inner">
        <h4 class="mb-3 text-center" style="color:#0551A3"><b>Sign into your dashboard</b></h4>
          <!-- Register -->
          <div class="card">
            <div class="card-body">
              <!-- Logo -->
              
              
              <form id="loginForm" class="mb-3">
                <div class="mb-3">
                    <label for="email" class="form-label" style="color:#003266;font-size:1rem">Email or Username</label>
                    <input type="text" autocomplete="off" class="form-control" id="username" name="username" placeholder="Enter your email or username" autofocus style="color:#003266"/>
                </div>
                <div class="mb-3 form-password-toggle">
                    <div class="d-flex justify-content-between">
                    <label class="form-label" for="password" style="color:#003266;font-size:1rem">Password</label>
                    
                    </div>
                    <div class="input-group input-group-merge">
                    <input type="password" id="password" class="form-control" name="password" placeholder="&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;" aria-describedby="password" style="color:#003266"/>
                    <span class="input-group-text cursor-pointer"><i class="bx bx-hide"></i></span>
                    </div>
                </div>
                
                <div class="mb-3" id="msgX">
                    
                </div>
                <div class="mb-3">
                    <button class="btn d-grid w-100" type="submit" style="background-color:#0551A3;color:white">Submit</button>
                </div>
              </form>
            </div>
          </div>
          <!-- /Register -->
        </div>
      </div>
      
    </div>
    <script src="assets/login/assets3/vendor/libs/jquery/jquery.js"></script>
    <script src="assets/login/assets3/vendor/libs/popper/popper.js"></script>
    <script src="assets/login/assets3/vendor/js/bootstrap.js"></script>
    <script src="assets/login/assets3/vendor/libs/perfect-scrollbar/perfect-scrollbar.js"></script>

    <script src="assets/login/assets3/vendor/js/menu.js"></script>
    
    <script src="assets/login/assets3/js/main.js"></script>

    <script async defer src="https://buttons.github.io/buttons.js"></script>
    <script>
        $(document).ready(function(){
            
            var username = '<?php if(isset($username)){echo $username;} ?>';
            var password = '<?php if(isset($pass)){echo $pass;} ?>';
            
            if(username.replace(/['"]+/g, '') != '' && password.replace(/['"]+/g, '') != ''){
                $('#username').val(username);
                $('#password').val(password);
                $('#loginType').val('link');
                $('#loginForm').submit();
                
            }
        });
        $('#loginForm').submit(function(e) {
            e.preventDefault();
            var submit = true;
            if (submit) {
                
                
                    var user = $('#username').val();
                    var pass = $('#password').val();
                
                $.ajax({
                    url: "user-handler.php",
                    type: "POST",
                    data: {
                        'uname': user,
                        'password': pass
                    },
                    success: function(response) {
                        debugger; 
                        if (jQuery.trim(response) == "success") {
                            $("#username").val(user);
                            window.location.href = "home.php";
                        } 
                        else if (jQuery.trim(response) == "Invalid Username and/or Passwordsuccess"){
                          var ms = '';
                          ms += '<h5 style="color:red">User has no record in waves</h5>';
                          $("#msgX").empty().append(ms);
                          setTimeout(function(){location.reload();},1500);
                        }
                        else {
                            setTimeout(function(){location.reload();},1000);
                            $('#errorModal #msg').text(`Credential Wrong!!`);
                            $('#errorModal').modal('toggle');
                        }
                    }
                });
            }
            return false;
        });
    </script>
  </body>
</html>
