<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hostel Management | Admin Forgot Password</title>
	<link rel="icon" type="image/x-icon" href="<?php echo base_url(); ?>assets-hms/fav.png">
    <!--styles links-->
    <link rel="stylesheet" href="<?php echo base_url(); ?>assets-hms/css/bootstrap.min.css">
    <link rel="stylesheet" href="<?php echo base_url(); ?>assets-hms/css/font-family.css">
    <link rel="stylesheet" href="<?php echo base_url(); ?>assets-hms/css/all.css">
    <link rel="stylesheet" href="<?php echo base_url(); ?>assets-hms/css/style.css">
    <link rel="stylesheet" href="<?php echo base_url(); ?>assets-hms/css/responsive.css">

	<style>
	.error-message p{
		font-size:13px !important;
		color:red !important;
		margin-bottom:2% !important;
	}
	</style>
</head>
<body>
	<div class="containers">
		<div class="main-logo">
		<img src="<?php echo base_url(); ?>assets-hms/<?php echo $school_info['color_logo']; ?>">
		</div>
		
		<?php
			$isResetPasswordSuccess = 'No';
			if($this->session->userdata('isResetPasswordSuccess')){
				$isResetPasswordSuccess = 'Yes';
				$this->session->unset_userdata('isResetPasswordSuccess');
			}
		?>
		
		<?php
			$pwd = ''; $conf_pwd = '';
			if(count($_POST) > 0)
			{
				$pwd = $_POST['password'];
				$conf_pwd = $_POST['conf_password'];			
			}
		?>
	
		<div class="containers">
			<form action="<?php echo base_url().'reset-password/'.$encodedEmailId;?>" id="resetPasswordForm" method="post">
			<div class="row login-row">
				<div class="col-md-7 col-lg-7 login-bg">
					<img src="<?php echo base_url(); ?>assets-hms/images/login/login-bg.svg" class="lg-img" alt="">
				</div>
				<div class="col-md-4 col-lg-4 login-right">
					<div class="forgot-box">
						<div class="forgot-fields">
							<h3>Forgot Password</h3>
							<p>Your email address is verified successfully. You can now reset your password here.</p>
							
							<?php if($this->session->flashdata('danger')){?>
							<div class="alert alert-danger alert-dismissible fade show" role="alert">
								<p><?php echo $this->session->flashdata('danger') ?></p>
								<button type="button" class="close" data-dismiss="alert" aria-label="Close">
								<span aria-hidden="true">&times;</span>
								</button>
							</div>
							<?php } ?>
							
							<div class="rp-eye-pos">
							<p class="input-label">New Password*</p>
							<input type="password" name="password" id="password" placeholder="Enter new passwod" class="form-control reset-input" >
                            <span class="rp-eye-one rp-eye-one-icon"><i class="far fa-eye"></i></span>
							<p class="error-message" id='password_error'></p>
							<span class="error-message"><?php echo form_error('password'); ?></span>
							</div>
							
							<div class="rp-eye-pos">
							<p class="input-label">Re-type New Password*</p>
							<input type="password" name="conf_password" id="conf_password" placeholder="Retype new password" class="form-control reset-input" >
                            <span class="rp-eye-two rp-eye-two-icon"><i class="far fa-eye"></i></span>
							<p class="error-message" id='conf_password_error'></p>
							<span class="error-message"><?php echo form_error('conf_password'); ?></span>
							</div>
							
							<div class="forgot-button">
								<button  class="forgot-btn" type='button' onclick='validate_rp_form()'>Reset Password</button>
							</div>
                          
							<div class="forgot-redirection">
								<a href="<?php echo base_url().'admin';?>">Go back to Login</a>
							</div>
						</div>
					</div>
				</div>
			</div>
			</form>
		</div>
	</div>

	<div class="modal fade" id="passwordChangeModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true" data-backdrop="static" data-keyboard="false">
		<div class="modal-dialog modal-dialog-centered" role="document">
			<div class="modal-content">        
				<div class="modal-body">
					<img src="<?php echo base_url(); ?>assets-hms/images/login/modal-check.svg" alt="">
					<h4>Success</h4>
					<p>
						Your password has been reset successfully. You can now login with new password.
					</p>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn modal-btn" onclick='go_to_admin_login()'>Go to Login</button>
				</div>
			</div>
		</div>
	</div>
    
    <script src="<?php echo base_url(); ?>assets-hms/js/jquery-3.4.1.min.js"></script>
    <script src="<?php echo base_url(); ?>assets-hms/js/popper.min.js"></script>
    <script src="<?php echo base_url(); ?>assets-hms/js/bootstrap.min.js"></script>
    <script defer src="<?php echo base_url(); ?>assets-hms/js/all.js"></script>
	<script defer src="<?php echo base_url(); ?>assets-hms/js/main.js"></script>
	
	<script type="text/javascript">
	$(".rp-eye-one").click(function() {
		$(".rp-eye-one").toggleClass("rp-eye-one-icon");

		var input = $('#password');
		if (input.attr("type") == "password")
		  input.attr("type", "text");
		else
		  input.attr("type", "password");
	});

	$(".rp-eye-two").click(function() {
		$(".rp-eye-two").toggleClass("rp-eye-two-icon");

		var input = $('#conf_password');
		if (input.attr("type") == "password")
		  input.attr("type", "text");
		else
		  input.attr("type", "password");
	});

	var isResetPasswordSuccess = '<?php echo $isResetPasswordSuccess;?>';
	if(isResetPasswordSuccess == 'Yes'){
		$('#passwordChangeModal').modal('show');
	}
	
	function go_to_admin_login()
	{
		window.location = '<?php echo base_url()."admin";?>';
	}

	$(document).ready(function(){		
		$(document).on('keypress', function(e){
			if(e.which==13)
			{
				//if(js_status != 'Not Verified')
				validate_rp_form();
			}
		});	
		
	});

	function hide_all_rp_errors()
	{        
		$('#password_error').hide();
		$('#conf_password_error').hide(); 
	}
	
		
	function validate_rp_form()
	{        
		hide_all_rp_errors();
	  
		var errArr = new Array();	
	
		var pwd = $('#password').val().trim();
		var conf_password = $('#conf_password').val().trim();
	   
		if(pwd==''){
			errArr.push('password_Sep@Str_Please enter your new password.');
		}
		else{
			var regPwdReg = /(?=.*[a-zA-Z0-9])(?=.*?\W).{6,}/;
			if(!regPwdReg.test($('#password').val()))
				errArr.push('password_Sep@Str_Password should be minimum 6 characters and should have atleast one special character.');
		}
		
		if(conf_password==''){
			errArr.push('conf_password_Sep@Str_Please re-enter your new password.');
		}
		  
		if($('#password').val()!='' && $('#conf_password').val()!='' && ($('#password').val() != $('#conf_password').val()) )
			errArr.push('conf_password_Sep@Str_Password & Retype Password does not match.');
	
		if(errArr.length>0)
		{
			for(i=0; i<errArr.length; i++)
			{
				var resArr = errArr[i].split("_Sep@Str_");
				$("#"+resArr[0]+"_error").html(resArr[1]);;
				$("#"+resArr[0]+"_error").show();
			}		
			var xxxVal = errArr[0].split('_Sep@Str_');		
			$('#'+xxxVal[0]).focus();		
			return false;
		}
		else{
			$('#resetPasswordForm').submit();
		}
	}
	</script>
</body>
</html>