<?php
/**
 * HTML Change Password Form
 *
 * PHP version 7.3
 *
 * @package        SMS
 * @version        Release 1.0.0
 * @create_by      Mohammad aljaouni
 * @create_date    17-08-2020
 * @edited_by
 * @last_edit_date
 * @todo           Nothing
 */
ob_start();
session_start();
$chain = "AWdrh78y892Djk*^523*%$#ghgHGHia&%$*)AsfdsLJnLaad";
include("validateLogin.php");
include("includeInformation.php");
include("header.php");
?>
<!-- Start Dashboard page -->
    <!-- start main-content -->
    <div class="main-content">
        <!-- Start Page-content -->
        <div class="page-content">
        <!-- Page-Title -->
        <div class="page-title-box">
            <div class="container-fluid">
                <div class="row align-items-center">
                    <?php echo breadcrumbs(basename($_SERVER['PHP_SELF']));?>
                </div>
            </div>
        </div>
        <!-- end page title end breadcrumb -->
        <div class="page-content-wrapper">
            <div class="container-fluid">
                <div class="row justify-content-center align-items-center">
                    <div class="col-sm-12 col-lg-4 ">
                        <div class="card">
                            <div class="card-body">
                                <h5 class="mb-5 text-center"><?php echo $changePasswordLBL["changePassword"];?></h5>
                                <form name="changePassForm" method="POST" action="changePassword2.php" onsubmit="return checkChangePass();">
                                    <div class="row">
                                        <?php
                                        if(!empty($_GET["res"]))
                                            echo result($_GET["res"]);
                                        ?>
                                        <div class="col-md-12">
                                            <div class="form-group form-group-custom mb-4">
                                                <input type="password" class="form-control" value="" name="oldPass" id="oldPassId" autocomplete="off" onchange="this.setAttribute('value', this.value);">
                                                <label for="oldPassword"><?php echo $changePasswordLBL["oldPassword"]?></label>
                                            </div>

                                            <div class="form-group form-group-custom mb-4">
                                                <input type="password" class="form-control" value="" name="newPass" id="newPassId" autocomplete="off" onchange="this.setAttribute('value', this.value);">
                                                <label for="newPassword"><?php echo $changePasswordLBL["newPassword"]?></label>
                                            </div>

                                            <div class="form-group form-group-custom mb-4">
                                                <input type="password" class="form-control" value="" name="newPass2" id="newPass2Id" autocomplete="off" onchange="this.setAttribute('value', this.value);">
                                                <label for="confirmPassword"><?php echo $changePasswordLBL["confirmPassword"]?></label>
                                            </div>

                                            <div class="mt-4">
                                                <button class="btn btn-success btn-block waves-effect waves-light" type="submit"><?php echo $button["change"]?></button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- end row -->
            </div>
            <!-- end container-fluid -->
        </div>
        <!-- end page-content-wrapper -->
    </div>
        <!-- End Page-content -->
</div>
    <!-- end main content -->
<!-- End Dashboard page -->
<script type="text/javascript">
function checkChangePass()
{
	if($('#oldPassId').val() == "")
	{
		alert("<?php echo sprintf($insert,$changePasswordLBL["oldPassword"]);?>");
		$('#oldPassId').focus();
		return false;
	}
	if($('#newPassId').val() == "")
	{
		alert("<?php echo sprintf($insert,$changePasswordLBL["newPassword"]);?>");
		$('#newPassId').focus();
		return false;
	}
	if($('#newPass2Id').val() == "")
	{
		alert("<?php echo sprintf($insert,$changePasswordLBL["confirmPassword"]);?>");
		$('#newPass2Id').focus();
		return false;
	}
	if($('#newPassId').val() != $('#newPass2Id').val())
	{
		alert("<?php echo $changePasswordLBL["passNotMatch"];?>");
		$('#newPass2Id').focus();
		return false;
	}								
	return true;
}
</script>
<script>
    document.addEventListener("DOMContentLoaded", function(event) {
        $.validator.addMethod("confirmPassword",function(value, element) {
            if($("#newPassword").val() !== value)
                return false;
            else
                return true;
        });

        $("#changePasswordForm").validate({
            rules: {
                oldPassword: {
                    required: true,
                    minlength: 6
                },
                newPassword: {
                    required: true,
                    minlength: 6
                },
                confirmPassword: {
                    required: true,
                    confirmPassword: true,
                    minlength: 6
                }
            },
            messages: {
                oldPassword: {
                    required: msg.changePassword.oldPassword,
                    minlength: msg.changePassword.oldPasswordMinlength
                },
                newPassword: {
                    required: msg.changePassword.newPassword,
                    minlength: msg.changePassword.newPasswordMinlength
                },
                confirmPassword: {
                    required: msg.changePassword.confirmPassword,
                    confirmPassword: msg.changePassword.confirmPassword,
                    minlength: msg.changePassword.confirmPasswordMinlength
                }
            },
            errorElement: 'div',
            errorPlacement: function (error, element) {
                error.addClass('invalid-feedback');
                element.closest('.form-group').append(error);
            },
            highlight: function (element, errorClass, validClass) {
                $('#changePasswordForm').addClass('was-validated');
                element.setCustomValidity("is-invalid");
                $(element).addClass('is-invalid');
            },
            unhighlight: function (element, errorClass, validClass) {
                $('#changePasswordForm').addClass('was-validated');
                element.setCustomValidity("");
                $(element).removeClass('is-invalid');
            },
            invalidHandler: function(event, validator) {
                $('#changePasswordForm').addClass('was-validated');
            }
            /*,
           submitHandler: function() {
               alert("ok");
           }*/
        });
    });
</script>
<?php
include("footer.php");
ob_end_flush();
?>
