<?php

require __dir__ . '/init.php';


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

	$_POST = help::sanitize($_POST);
	$status = false;
	
	if( md5($_POST['opassword']) != $admin['password'] ) $msg = "Old Password is wrong";
	
	else {
		
		$SQL = sQuery::update( 'admin', array(
			"password" => md5($_POST['password'])
		), "id='{$_POST['id']}'");
		
		$status = $link->query( $SQL );
		
		if( $status ) {
			$msg = "Password successfully changed";
		} else $msg = "Password Update Failed";
		
	}

}


template::get_header();

?>


	<?php template::title( "CHANGE PASSWORD" ); ?>
   

	<div class='row'>
		<div class="col-md-12 col-sm-12 col-sx-12">
		
			<div class="card">
				<div class="card-body">
				
					<h4 align="center" class=''>
						<i class="fa fa-refresh"></i> PASSWORD UPDATE
					</h4>
					
					<hr>
					
					<?php template::alert( $msg, $status ?? null ); ?>

					<form class="form-horizontal" action="password.php" method="POST" >
						<div class="form-group">
							<input type="password" name="opassword" placeholder="Old Password" class="form-control" required>
						</div>
						<div class="form-group">
							<input type="password" name="password" placeholder="New Password" class="form-control" required>
						</div>
						<input type="hidden"  name="id"  value="<?php  echo $admin['id']?>">
						<div class="form-group">
							<input type="submit"  name="submit" value="Change Password" class="btn btn-warning">
						</div>
					</form>
					
				</div>
			</div>
			
		</div>
	</div>

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