<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->

{% include './admin_header.html' %} 


<div class="app-main__outer">
    <div class="app-main__inner" id="product_info">
        <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-12">
                        <div class="main-card mb-3 card">
                            <div class="card-body" id="product_data">

                                {% if User_language=="ENGLISH" %}                                
                                <h5 class="card-title">Change Password</h5>
                                {% endif %}
                                {% if User_language=="GUJARATI" %}                                
                                <h5 class="card-title">પાસવર્ડ બદલો</h5>
                                {% endif %}

                                <div class="" method="post" id="product_detail">

                                    <div class="row">
                                        <div class="position-relative form-group col-md-4">
                                            {% if User_language=="ENGLISH" %}                                
                                            <label class="">Old Password</label>
                                            <input name="old_password" id="old_password" tabindex="1" placeholder="Old Password" type="password" class="form-control">
                                            {% endif %}
                                            {% if User_language=="GUJARATI" %}                                
                                            <label class="">જુનો પાસવર્ડ</label>
                                            <input name="old_password" id="old_password" tabindex="1" placeholder="જુનો પાસવર્ડ" type="password" class="form-control">
                                            {% endif %}

                                            <div id="msg_old_password"></div>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <div class="position-relative form-group col-md-4">
                                            {% if User_language=="ENGLISH" %}                                
                                            <label class="">New Password</label>
                                            <input name="new_password" id="new_password" tabindex="1" placeholder="New Password" type="password" class="form-control">
                                            {% endif %}
                                            {% if User_language=="GUJARATI" %}                                
                                            <label class="">નવો પાસવર્ડ</label>
                                            <input name="new_password" id="new_password" tabindex="1" placeholder="નવો પાસવર્ડ" type="password" class="form-control">
                                            {% endif %}

                                            <div id="msg_new_password"></div>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <div class="position-relative form-group col-md-4">
                                            {% if User_language=="ENGLISH" %}                                
                                            <label class="">Confirm Password</label>
                                            <input name="confirm_password" id="confirm_password" tabindex="1" placeholder="Confirm Password" type="password" class="form-control">
                                            {% endif %}
                                            {% if User_language=="GUJARATI" %}                                
                                            <label class="">કન્ફ્ર્મ પાસવર્ડ</label>
                                            <input name="confirm_password" id="confirm_password" tabindex="1" placeholder="કન્ફ્ર્મ પાસવર્ડ" type="password" class="form-control">
                                            {% endif %}

                                            <div id="msg_confirm_password"></div>
                                        </div>
                                    </div>

                                    <div style="text-align: left">
                                        {% if User_language=="ENGLISH" %}                                
                                        <button type="button" class="btn btn-success btnsave" id="btn-submit" tabindex="4">Change</button>
                                        <button type="reset" class="btn btn-primary clear" tabindex="5">Clear</button>
                                        {% endif %}
                                        {% if User_language=="GUJARATI" %}                                
                                        <button type="button" class="btn btn-success btnsave" id="btn-submit" tabindex="4">પાસવર્ડ બદલો</button>
                                        <button type="reset" class="btn btn-primary clear" tabindex="5">કલીયર</button>
                                        {% endif %}

                                        <span id="msg_success" style="display:none;font-size: 16px;color: green;padding: 5px">
                                            * Data Insert Successfully!
                                        </span>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">

    $(document).ready(function () {

        $(document.body).on('blur', '#old_password', function (e) {
//        $("#product_type").blur(function () {
            e.preventDefault();
            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);
            }
        });

        $(document.body).on('blur', '#new_password', function (e) {
//        $("#product_type").blur(function () {
            e.preventDefault();
            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);
            }
        });

        $(document.body).on('blur', '#confirm_password', function (e) {
//        $("#product_type").blur(function () {
            e.preventDefault();
            if ($("#confirm_password").val() == "")
            {
                $("#msg_confirm_password").fadeIn(500);
                $("#msg_confirm_password").html("* Confirm Password Is Empty").css({'color': 'red'});
                $("#msg_confirm_password").focusin();
            } else
            {
                $("#msg_confirm_password").fadeOut(1000);
                var confirm_pwd = $("#confirm_password").val();
                var new_pwd = $("#new_password").val();
                if (confirm_pwd == new_pwd) {
                    $("#msg_confirm_password").fadeOut(1000);
                } else {
                    $("#msg_confirm_password").fadeIn(500);
                    $("#msg_confirm_password").html("* Confirm Password Not Match To New Password").css({'color': 'red'});
                    $("#msg_confirm_password").focusin();
                }
            }
        });

        function clear()
        {
            $("#old_password").val('');
            $("#new_password").val('');
            $("#confirm_password").val('');
        }


        $(document.body).on('click', '.btnsave', function (e) {
            debugger;
            var old_password = $("#old_password").val();
            var new_password = $("#new_password").val();
            var confirm_password = $("#confirm_password").val();


//        alert('year_id '+year_id+' std_id '+std_id+' class_name '+class_name);
            if (old_password == '')
            {
                $("#msg_old_password").fadeIn(500);
                $("#msg_old_password").html("* Old Password Is Empty").css({'color': 'red'});
                $("#msg_old_password").focusin();
            } else if (new_password == '')
            {
                $("#msg_new_password").fadeIn(500);
                $("#msg_new_password").html("* New Password Is Empty").css({'color': 'red'});
                $("#msg_new_password").focusin();
            } else if (confirm_password == '')
            {
                $("#msg_confirm_password").fadeIn(500);
                $("#msg_confirm_password").html("*Confirm Password Is Empty").css({'color': 'red'});
                $("#msg_confirm_password").focusin();
            } else
            {
                var confirm_pwd = $("#confirm_password").val();
                var new_pwd = $("#new_password").val();

                if (confirm_pwd == new_pwd) {
                    $("#msg_confirm_password").fadeOut(1000);

//            alert('Success ');
                    var data = {};
                    data.username = 'admin';
                    data.old_password = old_password;
                    data.new_password = new_password;
                    data.confirm_password = confirm_password;

                    $.ajax({
                        type: 'POST',
                        data: JSON.stringify(data),
                        contentType: 'application/json',
                        url: '/adminpanel/change_admin_password',
                        success: function (data) {
                            debugger;
//                            alert('data ' + data);
//                            $('#msg_success').fadeIn(500);
//                            $('#msg_success').text('* Data Insert Successfully!');
//                            $('#msg_success').fadeOut(5000);

                            if (data == 'LOGIN')
                            {
//                                    alert('if Login ');
                                $('#msg_success').fadeIn(500);
                                $('#msg_success').html(' * Password Change Successfully ');
                                $('#msg_success').css({'color': 'green'});
                                $('#msg_success').fadeOut(5000);
                                setTimeout(function () {
//                                        window.location.reload();
                                    window.location.href = "/";
                                }, 1000);
                            } else if (data == 'NOT_LOGIN')
                            {
//                                    alert('else Not Login ');
                                $('#msg_success').fadeIn(500);
                                $('#msg_success').html(' * Username and Password not match !');
                                $('#msg_success').css({'color': 'red'});
                                $('#msg_success').fadeOut(5000);
                                $('#old_password').focus();
                            }


                        }, error: function (xhr, err) {
                            alert('Error ' + err.message);
                        }
                    });
                } else {
                    $("#msg_confirm_password").fadeIn(500);
                    $("#msg_confirm_password").html("* Confirm Password Not Match To New Password").css({'color': 'red'});
                    $("#msg_confirm_password").focusin();
                }
            }
        });


    });

    function add_product() {
        window.location.href = '/';
    }

</script>


{% include './admin_footer.html' %}

<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <!--<button type="button" class="close" data-dismiss="modal">&times;</button>-->
                <h4 class="modal-title">Confirmation Message</h4>
            </div>
            <div class="modal-body">
                <p style="color: red"> Are you sure to delete this record ? </p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger delete" data-dismiss="modal">Delete</button>
                <button type="button" class="btn btn-primary close_model" data-dismiss="modal">Cancel</button>
            </div>
        </div>

    </div>
</div>

<div class="modal fade" id="myModal_msg" role="dialog">
    <div class="modal-dialog">

        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <!--<button type="button" class="close" data-dismiss="modal">&times;</button>-->
                <h4 class="modal-title">Message</h4>
            </div>
            <div class="modal-body">
                <p style="color: green"> * Record Delete Successfully. </p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-dismiss="modal">Ok</button>
            </div>
        </div>

    </div>
</div>
