<?php include_once('../function/__data_app_db.php');
$signup_tkn = substr(str_shuffle(str_repeat("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-@", 128)), 0, 128);
$_SESSION['signup_token'] = $signup_tkn;
if(isset($_SESSION['user_login'])){
    if($_SESSION['user_login'] == 'true') { ?>
        <script language="javascript">
            document.location="dashboard";
        </script>
    <?php }} ?>

<!DOCTYPE html>
<html class="loading" lang="en" data-textdirection="ltr">
  <!-- BEGIN: Head-->
  <head>
    <?php include_once('head.php');?>
    <!-- BEGIN: Page CSS -->
    <link rel="stylesheet" type="text/css" href="../../app-assets/css/pages/authentication.css">
    <!-- END: Page CSS -->
    <!-- BEGIN: Custom CSS -->
    <link rel="stylesheet" type="text/css" href="../../assets/css/style.css?<?php echo $currentTime;?>">
    <!-- END: Custom CSS -->
  </head>
  <!-- END: Head -->

  <!-- BEGIN: Body -->
  <body class="vertical-layout vertical-menu-modern 1-column  navbar-sticky footer-static bg-full-screen-image dark-layout blank-page blank-page" data-open="click" data-menu="vertical-menu-modern" data-col="1-column">
    <!-- BEGIN: Content-->
    <div class="app-content content">
      <div class="content-overlay"></div>
      <div class="content-wrapper">
        <div class="content-header row">
        </div>
        <div class="content-body"><!-- register section starts -->
            <section id="auth-login" class="row flexbox-container">
                <div class="col-xl-8 col-11">
                    <div class="card bg-authentication mb-0">
                        <div class="row m-0">
                            <!-- left section-login -->
                            <div class="col-md-6 col-12 px-0">
                                <div class="card disable-rounded-right mb-0 p-2 h-100 d-flex justify-content-center">
                                    <div class="card-header pb-1">
                                        <div class="card-title text-center">
                                            <h4 class="text-center mb-2">ADMIN LOGIN</h4>
                                            <img src="../../full_logo.png" style="border-radius: 5px; margin-bottom: 30px; width: 100%">
                                        </div>
                                    </div>
                                    <div class="card-content">
                                        <div class="card-body">
                                            <div class="divider">
                                                <div class="divider-text text-uppercase text-muted"><small>login with username</small>
                                                </div>
                                            </div>
                                            <form action="function/log_in" id="data-form">
                                                <div class="form-group mb-50">
                                                    <label class="text-bold-600" for="exampleInputEmail1">Username</label>
                                                    <input type="text" class="form-control" placeholder="Username" name="user_name" value="<?php if(ISSET($_COOKIE['user_name'])){echo $_COOKIE['user_name'];}?>" autofocus required></div>
                                                <div class="form-group">
                                                    <label class="text-bold-600" for="password">Password</label>
                                                    <input type="password" class="form-control" placeholder="Password" name="password" id="password" value="<?php if(ISSET($_COOKIE['user_password'])){echo $_COOKIE['user_password'];}?>" required>
                                                </div>
                                                <div class="form-group d-flex flex-md-row flex-column justify-content-between align-items-center">
                                                    <div class="text-left">
                                                        <div class="checkbox checkbox-sm">
                                                            <input type="checkbox" class="form-check-input" id="remember" name="remember" <?php if(ISSET($_COOKIE['user_name'])){echo 'checked';}?>>
                                                            <label class="checkboxsmall" for="remember"><small>Keep me logged in</small></label>
                                                        </div>
                                                    </div>
                                                </div>
                                                <input type="hidden" name="tkn" value="<?php echo $_SESSION['signup_token'];?>">
                                                <button class="btn btn-primary position-relative w-100 ladda-button submit-btn" data-style="zoom-in" type="submit" name="action"><span class="ladda-label">SIGN IN</span> <span class="ladda-spinner"></span> <i id="icon-arrow" class="bx bx-right-arrow-alt"></i>
                                                </button>
                                            </form>
                                            <hr>
                                            <div class="text-center"><div class="text-center">
                                                    <p>Powered by <a href="https://jsnj.in" class="text-info"><img src="../../jsnj_icon32x32.png" width="32px" class="bg-white" style="border-radius: 5px"> <b class="text-white">JAI SHREE NATH JI INFOMEDIA</b> </a></p>
                                                </div></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- right section image -->
                            <div class="col-md-6 d-md-block d-none text-center align-self-center p-3">
                                <div class="card-content">
                                    <img class="img-fluid" src="../../app-assets/images/pages/login.png" alt="branding logo">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
<!-- register section endss -->
        </div>
      </div>
    </div>
    <!-- END: Content-->


    <!-- BEGIN: Vendor JS-->
    <script src="../../app-assets/vendors/js/vendors.min.js"></script>
    <script src="../../app-assets/fonts/LivIconsEvo/js/LivIconsEvo.tools.min.js"></script>
    <script src="../../app-assets/fonts/LivIconsEvo/js/LivIconsEvo.defaults.min.js?1"></script>
    <script src="../../app-assets/fonts/LivIconsEvo/js/LivIconsEvo.min.js"></script>
    <!-- BEGIN Vendor JS-->

    <!-- BEGIN: Page Vendor JS-->
    <!-- END: Page Vendor JS-->

    <!-- BEGIN: Theme JS-->
    <script src="../../app-assets/js/scripts/parsley.min.js"></script>
    <script src="../../app-assets/plugin/ladda-button/spin.min.js"></script>
    <script src="../../app-assets/plugin/ladda-button/ladda.min.js"></script>
    <script src="../../app-assets/plugin/notify.js"></script>
    <script src="../../app-assets/plugin/sweetalert/sweetalert.min.js"></script>
    <script src="../../app-assets/js/scripts/configs/vertical-menu-light.min.js"></script>
    <script src="../../app-assets/js/core/app-menu.min.js"></script>
    <script src="../../app-assets/js/core/app.min.js"></script>
    <script src="../../app-assets/js/scripts/components.min.js"></script>
    <script src="../../app-assets/js/scripts/footer.min.js"></script>
    <!-- END: Theme JS-->
    <script type="text/javascript">
        $('form').parsley();
        $('form#data-form').submit(function (e) {
            e.preventDefault();
            var action = $(this).attr('action');
            var m_form_data = new FormData(this);
            if($(this).parsley().isValid()){
                var l = Ladda.create(document.querySelector('.submit-btn'));
                l.start();
                $.ajax({
                    type: "POST",
                    url: action,
                    data: m_form_data,
                    cache: false,
                    dataType:"json",
                    enctype: 'multipart/form-data',
                    processData: false,  // tell jQuery not to process the data
                    contentType: false,   // tell jQuery not to set contentType
                    success: function(data){
                        //alert(data);
                        l.stop();
                        var goTo ='';
                        var notify_type = data.notif_type;
                        var notify_title = data.notif_title;
                        var notify_desc = data.notif_desc;
                        $.notify({
                            // options
                            title: notify_title,
                            message: notify_desc,
                        },{
                            // settings
                            type: notify_type
                        });
                        if(data.res == 'true'){
                            goTo = data.goTo;
                            window.setTimeout(function(){
                                window.location.href = goTo;
                            }, 500);
                        }
                    },
                    error: function (jqXHR, exception) {
                        var msg = '';
                        if (jqXHR.status === 0) {
                            msg = "oops error";
                        } else if (jqXHR.status === 404) {
                            msg = "404 error";
                        } else if (jqXHR.status === 500) {
                            msg = "505 error";
                        } else if (exception === 'parsererror') {
                            msg = "error";
                        } else if (exception === 'timeout') {
                            msg = "timeout";
                        } else if (exception === 'abort') {
                            msg = "abort";
                        } else {
                            msg = "oops somthing want wrong"
                        }
                        l.stop();
                        alert(msg);
                    }
                });
            };
        });
    </script>
  </body>
  <!-- END: Body-->
</html>