<?php include_once('../function/__data_app_db.php'); ?>
<!DOCTYPE html>

<html class="loading" lang="en" data-textdirection="ltr">
  <!-- BEGIN: Head-->
<?php include_once('head.php');?>
  <!-- END: Head-->

  <!-- BEGIN: Body-->
  <body class="vertical-layout vertical-menu-modern 2-columns navbar-sticky footer-static menu-expanded pace-done dark-layout" data-open="click" data-menu="vertical-menu-modern" data-col="2-columns">

    <!-- BEGIN: Header-->
    <?php include_once('header.php');?>
    <!-- END: Header-->

    <!-- BEGIN: Main Menu-->
    <?php include_once('sidemenu.php');?>
    <!-- END: Main Menu-->

    <!-- 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">
            <section id="basic-input">
                <div class="row">
                    <div class="col-md-6">
                        <form id="data-form" action="function/insert/change_password">
                            <div class="row">
                                <div class="col-md-12 from_input">
                                    <div class="form-group">
                                        <label for="doc_name">New Password</label>
                                        <input type="password" id="password" name="password" class="form-control form-main" placeholder="New Password" required>
                                    </div>
                                </div>
                                <div class="col-md-12 from_input">
                                    <div class="form-group">
                                        <label for="doc_name">Confirm Password</label>
                                        <input type="password" id="cpassword" name="cpassword" class="form-control form-main" placeholder="Confirm Password" required>
                                    </div>
                                </div>
                            </div><!-- /.row -->
                            <input type="hidden" value="<?php echo $_SESSION['signup_token'];?>" name="tkn">


                            <div class="row">
                                <div class="col-md-6 offset-md-6">
                                    <button class="btn btn-success position-relative w-100 ladda-button submit-btn" data-style="zoom-in" type="submit" name="action"><span class="ladda-label">CHANGE PASSWORD</span> <span class="ladda-spinner"></span> <i id="icon-arrow" class="bx bx-right-arrow-alt"></i></button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </section>
        </div>
      </div>
    </div>
    <!-- END: Content-->

    <!-- BEGIN: Footer-->
    <?php include_once('footer.php');?>
    <!-- END: Footer-->

    <?php include_once('foot.php');?>
    <script type="text/javascript">
        $('form').parsley();
        $('body').on('submit','form#data-form',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;
                            }, 1000);
                        }
                    },
                    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>