<?php

require __dir__ . '/init.php';


if(isset($_POST['change'])){

	$_POST = help::sanitize($_POST);
	
    if($_POST['pin'] != $__user['pin']){

        $status = !($msg = "Incorrect Old Pin!");

    }else{
		
		$sql1 = "UPDATE tbl_users SET pin='{$_POST['npin']}' WHERE id='{$__user['id']}'";
		
		$status = mysqli_query($link, $sql1);
		
		if( $status ) {
			$msg = "Pin Changed Successfully!";
			$_SESSION['pin'] = $_POST['npin'];
		} else $msg = "Cannot Change pin! ";
		
	};
	
} else $status = null;


template::get_header();


?>

	<?php template::title( "My Pin Settings" ); ?>

    <div class="row">
		<div class="col-lg-12">
		
			<div class="sparkline12-list shadow-reset mg-t-30 card">
                <div class="sparkline12-graph card-body">
					<div class="basic-login-form-ad">
					
						<div class="row">
							<div class="col-lg-12">
								<div class="all-form-element-inner">
										
                                    <form action="cpin.php" method="post">
									
										<?php template::alert( $msg, $status ); ?>
										
										<div class="form-group">
											<div class="row">
												<div class="col-lg-3">
													<label class="login2 pull-right pull-right-pro">Old Pin</label>
												</div>
												<div class="col-lg-3">
													<input type="text" name="pin" placeholder="Enter old pin"  class="form-control" />
												</div>
											</div>
										</div>

										<input type="hidden" name="account" value="<?php echo $row['acctno'];?>" class="form-control" />

										<div class="form-group">
											<div class="row">
												<div class="col-lg-3">
													<label class="login2 pull-right pull-right-pro">New Pin</label>
												</div>
												
												<div class="col-lg-3">
													<input type="text" name="npin" placeholder="Enter new pin"  class="form-control" />
												</div>
											</div>
										</div>
										
										<div class="form-group">
											<div class="row">
												<div class="col-lg-3">
													
												</div>
												<div class="col-lg-3">
													<input type="submit" name="change" value="Change pin"  class="btn btn-info" />
												</div>
											</div>
										</div>
										
									</form>
											
								</div>
							</div>
							
					</div>
				</div>	
			</div>
				
		</div>
	</div>
               

<?php template::get_footer(); ?> 