<?php
	$params = base64_decode(SableSystem::sableDecode($_SERVER['argv'][1]));
	$delim = strpos($params, '|')?'|':'%7C';
	$code=explode($delim, $params);
	$email 	= base64_decode($code[0]);
	$hash 	= base64_decode($code[1]);
	$ucode 	= SableDBFunctions::getUserCodeFromEmail($email);
	require(SABLE_WORKING_PATH.'login/login_func.php');
	
	$sql = 'select user_code, concat(user_name, " ", user_surname) as user_full_name 
			from user 
			where (user_email = "'.$email.'") or (user_cell = "'.$email.'") or (user_phone = "'.$email.'")';
	$user = $sableDB->getRow($sql);	
	$userName = $user['user_full_name'];
	$row = $sableDB->getRow('select * from user__request where user_code = '.$user['user_code'].' and hash = "'.$hash.'" and expires is not null');
	$expires = $row['expires'];
	$now = date('Y-m-d H:i:s');
	if (empty($expires) || ($now > $expires))
	{
?>
<div class="forms_" style="display:block">
    <!--// header -->
    <div class="container forms-grids">
            <div class="col-md-8 forms-grids">
                <h3 class="title"><i class="fa fa-lock" aria-hidden="true"></i></i>&nbsp;Request Expired</h3>
                <p>Hello <b><?php echo($userName) ?></b>. <br />For security reasons your request for a password reset has expired. <a href="<?php echo(SableSystem::getCallPageLink('/login/forgotten.php')); ?>" class="link_contrast_">Click here to submit a new password reset request.</a> The request will only be available for 24 hours.</p>
                <div class="clearfix"> </div>
            </div>
    </div>
</div>
<?php
	}
	else
	{
?>
<script src="<?php echo(SABLE_URL_ROOT.'login/reset.js'); ?>"></script>
<form id="Login" name="Login" autocomplete="off">
	<input id="sId" type="hidden" value="<?php echo(SableSystem::sableEncode($_SESSION['ID'])); ?>">
	<div class="forms" style="display:block">
    	<!--// header -->
		<div class="container forms-grids">
			<div class="row forms-grids">
				<div class="col-md-8">
					<h3 class="title"><i class="fa fa-unlock-alt" aria-hidden="true"></i></i>&nbsp;Reset Password</h3>
					<p>Hello <b><?php echo($userName) ?></b>. <br />Please enter a new password and confirm it below:</p>
					<div class="clearfix"> </div>
				</div>
			</div>
  
			<!-- header //-->
			<!--// user name -->

			<div class="row forms-grids">
				<div class="col-md-4 forms-grid">
                        <input name="edtPassword" type="password" id="edtPassword" autocomplete="off"
                            onfocus="showHint('edtPassword')"
                            onblur="hideHint('edtPassword'); validate_edtPassword()" 
                            onkeypress="handleEnter(event)" placeholder="password"/>
				</div>
                <div class="col-md-4">
                    <div class="fieldHint" id="hint_edtPassword">Please enter your NEW password.</div>
                </div>                
				<div class="clearfix"> </div>
			</div>

        <!-- user name //-->
        <p></p>
        <!--// password -->

			<div class="row forms-grids">
				<div class="col-md-4 forms-grid">
                    <input type="password" name="edtConfirm" id="edtConfirm" onfocus="showHint('edtConfirm')" 
                    onblur="hideHint('edtConfirm'); validate_edtConfirm()" onkeypress="handleEnter(this, event)" placeholder="confirm password"/>
				</div>
                <div class="col-md-4 forms-grid">
                    <div class="fieldHint" id="hint_edtConfirm">Please confirm your new password.</div>
                </div>                
				<div class="clearfix"> </div>
			</div>
    
        <!-- password //-->
        <p></p>
        <!--// buttons -->
        	<div class="row forms-grids">
                <div class="col-md-2  forms-grid">                            
                    <input type="button" id="btnOk" value="Change" class="submit" onclick="resetPassword(<?php echo("'".$email."'"); ?>)"/> 
                </div>
                <div class="col-md-2  forms-grid">                            
                	<input type="button" id="btnCancel" value="Cancel" class="submit" 
						   onclick="window.location = '<?php echo(SABLE_URL_ROOT); ?>'"/>
                </div>
            </div>                                            
        <!-- buttons //-->

        	<div class="row forms-grids">
                <div class="col-md-6  forms-grid">         
                 <p><i class="fa fa-arrow-circle-left" aria-hidden="true"></i>&nbsp;<a href="<?php echo(SableSystem::getCallPageLink('/login/')); ?>" class="link_contrast">Click here to return to the login page.</a></p>       
                 </div>
            </div>
        </div>
	</div>
</form>
<?php } ?>