<?php
    $page = "v_login" ;
    include 'head.php';
    session_start();
    date_default_timezone_set('Asia/Kolkata');
    
if((isset($_GET['ch']) && !empty($_GET['ch']))){
    $reset_link = $_GET['ch'];
    $sql = $config->query("SELECT * FROM user_reset WHERE reset_link = '$reset_link' AND status = 1");
    if($sql->num_rows > 0){
        $res = $sql->fetch_assoc();
        $id = $res['id'];
        $mas_id = $res['user_id'];
    }else header('Location:forgot-password.php');
}

?>
	<body class="account-page">

		<!-- Main Wrapper -->
		<div class="main-wrapper">
		
			<!-- Header -->
			<?php include('./header.php') ?>
			<!-- /Header -->
			
			<!-- Page Content -->
			<div class="content">
				<div class="container-fluid">
					
					<div class="row">
						<div class="col-md-8 offset-md-2">
							
							<!-- Login Tab Content -->
							<div class="account-content">
								<div class="row align-items-center justify-content-center">
									<div class="col-md-7 col-lg-6 login-left">
										<img src="assets/img/login-banner.png" class="img-fluid" alt="Doccure Login">	
									</div>
									<div class="col-md-12 col-lg-6 login-right">
										<div class="login-header">
											<h3>Reset Password<span></span></h3>
										</div>
										<form>
											<div class="form-group form-focus">
												<input type="password" class="form-control floating" id="password" value="<?php	if(isset($_SESSION['tmp_pass'])){ echo $_SESSION['tmp_pass'] ; unset($_SESSION['tmp_pass']); } ?>" > 
												<i class="fas fa-eye-slash show-icon" id="pass-icon" onclick="showhide()"></i>
												<label class="focus-label">New Password</label>
											</div>
											<div class="form-group form-focus">
												<input type="password" class="form-control floating" id="c_password" value="<?php	if(isset($_SESSION['tmp_cpass'])){ echo $_SESSION['tmp_cpass'] ; unset($_SESSION['tmp_cpass']); } ?>" >
												<input type="hidden" id="reset_link" value="<?= $mas_id ?>" >
                                                <input type="hidden" id="passid" value="<?= $id ?>" >
												<label class="focus-label">Confirm Password</label>
											</div>
											<button class="btn btn-primary btn-block btn-lg login-btn" type="button" id="reset_pass">Submit</button>
											<span class="text-danger" id="passerr"></span>
										</form>
									</div>
								</div>
							</div>
							<!-- /Login Tab Content -->
								
						</div>
					</div>

				</div>

			</div>		
			<!-- /Page Content -->
   
			<!-- Footer -->
			<?php include('./footer.php') ?>
			<!-- /Footer -->
		   
		</div>
		<!-- /Main Wrapper -->
	    <!-- custom style -->
	    <style>
	        .show-icon{
                position: absolute;
                cursor: pointer;
                right: 10px;
                top: 50%;
                transform: translateY(-50%);
                font-size: 13px;
                color: #9d9b9b;
            }
	    </style>
	    <!-- custom script -->
        <script>
            const password = document.getElementById('password');
            const icon = document.getElementById('pass-icon');
            function showhide(){
                if(password.type === "password"){
                    password.setAttribute("type","text");
                    icon.setAttribute("class","fas fa-eye show-icon");
                }else{
                    password.setAttribute("type","password");
                    icon.setAttribute("class","fas fa-eye-slash show-icon");
                }
            }
            
        </script>
		<!-- jQuery -->
		<script src="assets/js/jquery.min.js"></script>
		
		<!-- Bootstrap Core JS -->
		<script src="assets/js/popper.min.js"></script>
		<script src="assets/js/bootstrap.min.js"></script>
		
		<!-- Custom JS -->
		<script src="assets/js/script.js"></script>
		<script>
            $('#reset_pass').click(()=>{
                let pass = $('#password').val();
                let cpass = $('#c_password').val();
                let uid = $('#reset_link').val();
                let id = $('#passid').val();
                if(pass.length >= 8){
                    if(cpass == pass){
                        $('#passerr').text('');
                        $.ajax({
                            type: "POST",
                            url: "ajax.php",
                            data: {password:pass,uid:uid,id:id,action:'reset'},
                            dataType: "json",
                            success: function(data){
                                if(data.success == 1){
                                    window.location.href=data.url;
                                }else{
                                    $('#passerr').text('Error');
                                }
                            }
                        });
                    }else{
                        $('#passerr').text('Password And Confirm Password Not Matched.');
                    }
                }else{
                    $('#passerr').text('Minimum 8 Characters');
                }
            })
        </script>
	</body>

<!-- doccure/login.html  30 Nov 2019 04:12:20 GMT -->
</html>