<?php
require_once './PHP_Code/connection.php';
require_once './admin_header.php';
?>


<div class="app-main__outer">
    <div class="app-main__inner">
        <div class="tab-content">
            <div class="tab-pane tabs-animation fade show active" id="tab-content-0" role="tabpanel">
                <div class="row">
                    <div class="col-md-6">
                        <div class="main-card mb-3 card">
                            <div class="card-body"><h5 class="card-title">Change Password</h5>
                                <form class="" method="post">

                                    <div class="position-relative form-group">
                                        <label for="Old Password" class="">Old Password</label>
                                        <input name="Old Password" id="old_password" placeholder="Old Password" tabindex="1" type="password" class="form-control">
                                        <div id="msg_old_password"></div>
                                    </div>
                                    <div class="position-relative form-group">
                                        <label for="New Password" class="">New Password</label>
                                        <input name="New Password" id="new_password" placeholder="New Password" tabindex="2" type="password" class="form-control">
                                        <div id="msg_new_password"></div>
                                    </div>
                                    <div class="position-relative form-group">
                                        <label for="Confirm Password" class="">Confirm Password</label>
                                        <input name="Confirm Password" id="confirm_password" placeholder="Confirm Password" tabindex="3" type="password" class="form-control">
                                        <div id="msg_confirm_password"></div>
                                    </div>

                                    <button type="button" class="mt-1 btn btn-primary" tabindex="4" id="btn_change_password">Submit</button>
                                    <div id="msg_show"></div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

<script type="text/javascript">

    $(document).ready(function () {
//        alert('hello');
        $("#old_password").blur(function () {
            if ($("#old_password").val() == "")
            {
                $("#msg_old_password").fadeIn(500);
                $("#msg_old_password").html("* Old Password is Empty.").css({'color': 'red'});
                $("#msg_old_password").focusin();
            } else
            {
                $("#msg_old_password").fadeOut(1000);
            }
        });

        $("#new_password").blur(function () {
            if ($("#new_password").val() == "")
            {
                $("#msg_new_password").fadeIn(500);
                $("#msg_new_password").html("* New Password is Empty.").css({'color': 'red'});
                $("#msg_new_password").focusin();
            } else
            {
                $("#msg_new_password").fadeOut(1000);
            }
        });

        $("#confirm_password").blur(function () {
            var pass2 = $("#confirm_password").val();
            $("#msg_confirm_password").fadeIn(1000);
            if (pass2 == "")
            {
                $("#msg_confirm_password").html("Please Confirm Password").css("color", "#F00");
                $("#msg_confirm_password").fadeOut(5000);
            } else if ($("#new_password").val() == $("#confirm_password").val())

            {

                $("#msg_confirm_password").html("Confirmed Succesfully !").css("color", "green");
                $("#msg_confirm_password").fadeOut(5000);
            } else

            {
                $("#msg_confirm_password").html("Not Matching ! Please Recheck Password").css("color", "#F00");
//                $("#msg_confirm_password").fadeOut(5000);
            }
        })




        $('#btn_change_password').click(function () {
            alert('click');
            var old_password = $("#old_password").val();
            var new_password = $("#new_password").val();
            var confirm_password = $("#confirm_password").val();

            var send = {'old_password': old_password, 'new_password': new_password, 'confirm_password': confirm_password};

            if (old_password == '')
            {
                $("#msg_old_password").html(" * Old Password is Empty").css({'color': 'red'});
            } else if (new_password == '')
            {
                $("#msg_new_password").html(" * New Password is Empty").css({'color': 'red'});
            } else if (confirm_password == '')
            {
                $("#msg_confirm_password").html(" * Confirm Password is Empty").css({'color': 'red'});
            } else
            {
                debugger;
                if ($("#new_password").val() == $("#confirm_password").val())
                {

                    $.ajax({
                        url: './PHP_Code/session_destroy.php',
                        type: 'POST',
                        data: send,
                        success: function (data)
                        {
                            debugger;
//                            alert('data ' + data);
                            var trimStr = $.trim(data);
                            if (trimStr == 'Record updated successfully')
                            {
                                debugger;
                                $('#msg_show').html(data).css({'color': 'green'});
                                window.location.href = "http://localhost/E_Bill_Software/login.php";
                            }else
                            {
                                $('#msg_show').html(data).css({'color': 'red'});
                            }
                        },
                        error: function (err) {
                            alert('error ' + err);
                        }
                    });

                } else
                {
                    $("#msg_confirm_password").html("Not Matching ! Please Recheck Password").css("color", "#F00");
//                $("#msg_confirm_password").fadeOut(5000);
                }
            }
        });
    });

</script>


<?php
require_once './admin_footer.php';
?>

