<?php

require __dir__ . '/init.php';

$status = null;

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

	$_POST = help::sanitize( $_POST, true );
	
    if($_POST['password'] != $__user['pwd']){

        $status = !($msg = "Incorrect Old Password!");
		
    }else{
		  
		$sql1 = "UPDATE tbl_users SET pwd='{$_POST['npassword']}' WHERE id='{$__user['id']}'";
		$status = mysqli_query($link, $sql1);
		$msg = $status ? "Password Changed Successfully!" : "Cannot Change password!";
		
    };
	
}

template::get_header();

?>
	
	<?php template::title("My Password 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="cpassword.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 Password</label>
												</div>
												<div class="col-lg-3">
													<input type="text" name="password" placeholder="Enter old password"  class="form-control" />
												</div>
											</div>
										</div>
									
										<div class="form-group">
											<div class="row">
												<div class="col-lg-3">
													<label class="login2 pull-right pull-right-pro">New Password</label>
												</div>
												<div class="col-lg-3">
													<input type="text" name="npassword" placeholder="Enter new password"  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 password"  class="btn btn-info" />
												</div>
											</div>
										</div>
										
									</form>
									
								</div>
							</div>
						</div>
								
					</div>
				</div>
						
			</div>
		</div>
	</div>
	
<?php template::get_footer(); ?> 