<?php
include_once '../resource/sessions.php';
require_once '../db/Config.php';
require_once 'model/UsersModel.php';
$UsersObj = new UsersModel();

$userid = filter_input(INPUT_GET, 'id', FILTER_UNSAFE_RAW);

?>
<!DOCTYPE html>
<html class="no-js" lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Reset Password</title>
    <!-- plugins:css -->

    <?php require('../imports/importcss.php'); ?>
    <!-- End plugin css for this page -->
    <!-- inject:css -->
    <link rel="stylesheet" href="../assets/css/style.css">
    <!-- endinject -->

    <!--google chart-->
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>




</head>

<body class="with-welcome-text">

    <div class="container-scroller">
        <!-- partial:partials/_navbar.html -->
        <?php require("../sections/header.php") ?>
        <!-- partial -->
        <div class="container-fluid page-body-wrapper">
            <!-- partial:partials/_sidebar.html -->
            <?php require("../sections/navbar.php") ?>

            <!-- partial -->
            <div class="main-panel">
                <div class="content-wrapper">
                   
            <div class="card">
                <div class="body">
                    <div class="container">
                        <h4 class="dashboard-title">New Users</h4>


                        <form class="form-horizontal Users_form" method="post" class="" enctype="multipart/form-data" accept-charset="utf-8">


                            <div class="row">
                                            
                                            <input type="hidden" class="status" name="status" value="reset_pswd">
                                            
                                            <input type="hidden" class="userid" name="userid" value="<?=$userid?>">

                                            <div class="col-md-6">
                                                <!-- Account Account details Start -->
                                                <div class="dashboard-content__input">
                                                    <label class="form-label-02">New Password</label>
                                                    <input type="password" class="form-control" name="pswd_new" id="pswd_new" minlength="5" required>
                                                </div>
                                                <!-- Account Account details End -->
                                            </div>
                                            <div class="col-md-6">
                                                <!-- Account Account details Start -->
                                                <div class="dashboard-content__input">
                                                    <label class="form-label-02">Confirm New Password</label>
                                                    <input type="password" class="form-control" name="pswd_repeat" id="pswd_repeat" minlength="5" required>
                                                </div>
                                                <!-- Account Account details End -->
                                            </div>
                            </div>

                                    
                                    <!-- Dashboard Settings Info End -->

                                
                            <br>
                            <div class="dashboard-settings__btn">
                                <button type="submit" class="btn btn-primary btn-hover-secondary">Reset Password</button>
                            </div>

                        </form>
                    </div>
                </div>
            </div>
                </div>
                <!-- page-body-wrapper ends -->
            </div>
        <!-- Dashboard Content End -->
        </div>
                <!-- page-body-wrapper ends -->
            </div>
        <!-- Dashboard Content End -->


    </main>
    <!-- Dashboard Main Wrapper End -->


    <?php require "../imports/importjs.php" ?>
    <script src="../../assets/js/beeps.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {

            $('.Users_form').submit(function(event) {
                event.preventDefault();

             

                $.ajax({
                    url: 'model/UsersController.php',
                    type: 'POST',
                    data: new FormData(this),
                    contentType: false,
                    cache: false,
                    processData: false,
                    beforeSend: function() {
                        $('.btn_submit_Users').attr("disabled", "disabled");
                        $('.Users_form').css("opacity", ".5");
                    },
                    success: function(result) {
                        $('.Users_form').css("opacity", "");
                        $(".btn_submit_Users").removeAttr("disabled");
                        var fields = result.split('|');
                        var id = fields[0];
                        var msg = fields[1];
                       
                        if (id == 1) {
                            alert("Password Updated")
                            $('.select').val(null).trigger('change');
                            $('.Users_form')[0].reset();

                        } else if (id == 2) {
                            alert(msg);
                        }
                    },
                    error: function(err) {
                        alert(err);
                        $('.Users_form').css("opacity", "");
                        $(".btn_submit_Users").removeAttr("disabled");
                    }
                });
            });
            //ENd of form
        });
    </script>
</body>

</html>