<?php
$title = 'THAY ĐỔI MẬT KHẨU | ' . $DVR->site('title');
$body['header'] = '

';
$body['footer'] = '

';
require_once __DIR__ . '/../../../core/is_user.php';
require_once __DIR__ . '/header.php';
require_once __DIR__ . '/nav.php';
CheckLogin();
?>
<div id="main" class="main">
        <div class="container">
        <div class="row">
            <div class="col-12">
                <div class="section-breadcrumb">
                    <ol class="breadcrumb">
                                                <li class="breadcrumb-item">
                            <a href="/">Trang chủ</a>
                        </li>
                                                <li class="breadcrumb-item">
                            <a href="">Profile <?=$getUser['username'];?></a>
                        </li>
                                            </ol>
                </div>
            </div>
        </div>
    </div>

        <div class="container">
            
            <div class="card rounded-sm bg-white pt-3">
                <div class="card-header bg-transparent rounded-0 border-0">
                    <div class="section-heading text-center">
                        <div class="heading-title">
                            Đổi mật khẩu
                        </div>
                    </div>
                </div>
                <div class="card-body">
                    <div class="information-form" id="passwordFrom">
                        <form action="" method="POST">
                              <input type="hidden" class="form-control" id="token" value="<?= $getUser['token'] ?>" readonly>                         <div class="row align-items-center no-gutters pb-3 mb-3">
                                <div class="col-md-4">
                                    <label for="passwordold" class="mb-3 mb-md-0 font-weight-bold">
                                        Mật khẩu hiện tại
                                    </label>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-group mb-0">
                                        <input id="old_password" type="password" class="form-control" name="old_password" required="" placeholder="Mật khẩu hiện tại">
                                    </div>
                                </div>
                            </div>
                            <div class="row align-items-center no-gutters pb-3 mb-3">
                                <div class="col-md-4">
                                    <label for="passwordnew" class="mb-3 mb-md-0 font-weight-bold">
                                        Mật khẩu mới
                                    </label>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-group mb-0">
                                        <input id="new_password" type="password" class="form-control" name="new_password" required="" placeholder="Mật khẩu mới">
                                    </div>
                                </div>
                            </div>
                            <div class="row align-items-center no-gutters pb-3 mb-3">
                                <div class="col-md-4">
                                    <label for="confirmpasswordnew" class="mb-3 mb-md-0 font-weight-bold">
                                        Xác nhận mật khẩu
                                    </label>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-group mb-0">
                                        <input id="confirm_new_password" type="password" class="form-control" name="confirm_new_password" required="" placeholder="Xác nhận mật khẩu">
                                    </div>
                                </div>
                            </div>
                            <div class="mt-5 pt-4 border-top text-center text-md-left">
                                <button id="changePass" class="btn btn-success btn-sm template-1-btn">Đổi Mật Khẩu
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="loading-pure" style="display: none">
                    <div></div>
                    <div></div>
                    <div></div>
                    <div></div>
                </div>
            </div>
        </div>
</div>

<script type="text/javascript">
    $("#changePass").on("click", function() {
        $('#changePass').html('<i class="fa fa-spinner fa-spin"></i> Đang xử lý...').prop(
            'disabled',
            true);
        $.ajax({
            url: "<?=BASE_URL('ajaxs/client/changePassword.php');?>",
            method: "POST",
            dataType: "JSON",
            data: {
                token: $("#token").val(),
                action: "ChangePassword",
                password: $("#old_password").val(),
                newpassword: $("#new_password").val(),
                renewpassword: $("#confirm_new_password").val()
            },
            success: function(respone) {
                if (respone.status == 'success') {
                    cuteToast({
                        type: "success",
                        message: respone.msg,
                        timer: 5000
                    });
                    setTimeout("location.href = '<?=BASE_URL('profile/change-password');?>';", 100);
                } else {
                    cuteToast({
                        type: "error",
                        message: respone.msg,
                        timer: 5000
                    });
                }
                $('#changePass').html('ĐỔI MẬT KHẨU').prop('disabled',
                    false);
            },
            error: function() {
                cuteToast({
                    type: "error",
                    message: 'Không thể xử lý',
                    timer: 5000
                });
                $('#changePass').html('ĐỔI MẬT KHẨU').prop('disabled',
                    false);
            }

        });
    });
</script>
<?php require_once __DIR__ . '/footer.php'; ?>