<?php 
include ("connection/conn.php");

	if($_SESSION['adminuser']=='')
		{
			header("location:index.php");
		}
	if(isset($_POST['submit']))
		{
			$opassword=$_POST['opassword'];
			$npassword=$_POST['npassword'];
			$cpassword=$_POST['cpassword'];
			if($opassword=="")
			{
				$error_msg.="Please enter old password.<br>";
			}
			if($npassword=="")
			{
				$error_msg.="Please enter new password.<br>";
			}
			if($cpassword=="")
			{
				$error_msg.="Please enter confirm new password.<br>";
			}
			if($npassword!=$cpassword)
			{
				$error_msg.="Both password do not match.<br>";
			}
			if($error_msg=="")
			{
				$query_pass="SELECT * from admin where pass='$opassword'";
				$result_pass=mysqli_query($link,$query_pass);
				$row_pass=mysqli_fetch_array($result_pass);
				if($row_pass>0)
				{
					$query_update="UPDATE admin set pass='".$cpassword."' where pass='$opassword'";
					$result_up=mysqli_query($link,$query_update);
					$succ_msg="Password has been changed successfully."; 
				}
			 
				  else
				   {
					 $error_msg.="Invalid old password.";
				    } 
			   }
		  }

?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Administrator | Vision Creators Pvt. Ltd.</title>
		<link href="css/bootstrap.css" rel="stylesheet" />
		<link href="css/font-awesome.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
		<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
	</head>
	
	<body>
		<div id="wrapper">
			<?php
				include("top-header.php");
				include("right-sec.php");
			?>
			<div id="page-wrapper" >
				<div id="page-inner">
					<div class="row">
						<div class="col-md-12">
							<h3 class="page-header">
								Change Password<small></small>
							</h3>
							<div class="password-box">
								<form name="pnews" id="pnews" method="post" action="">
								<div style="color:#FF0000; margin-left:100px; padding-bottom:10px;"><?php echo $error_msg;?></div>
	<?php
    if($succ_msg!="")
    {
    ?>
    <div style="color:#009966; margin-left:100px; padding-bottom:10px;"><?php echo $succ_msg;?></div>
    <?php
    }
    ?>
									<div class="row">
										<div class="col-md-12 col-xs-12">	
											<div class="form-group form-select">
												<label>Old Password <span>*</span></label>
												<input class="form-control" type="password" name="opassword" placeholder="Old Password">
											</div>		
										</div>										
										<div class="col-md-12 col-xs-12">	
											<div class="form-group form-select">
												<label>New Password <span>*</span></label>
												<input class="form-control" type="password" name="npassword"  placeholder="New Password">
											</div>		
										</div>										
										<div class="col-md-12 col-xs-12">	
											<div class="form-group form-select">
												<label>Confirm Password <span>*</span></label>
												<input class="form-control" type="password" name="cpassword"  placeholder="Confirm Password">
											</div>		
										</div>
										<div class="col-md-6 col-xs-6">	
											<div class="form-group form-select">
												<input type="submit" name="submit" class="primary-btn text-uppercase" value="Submit">
											</div>
										</div>
									</div>
								</form>
							</div>
						</div>
					</div> 
				</div>
			</div>
			<footer class="footer-sec">
				<div class="container">
					<div class="row">
						<div class="col-md-12">
							<p class="text-center">All right reserved. Template Design by: <a href="">Anshul Chittouria</a></p>
						</div>
					</div>
				</div>
			</footer>
		</div>
		
		
		<!-- jQuery Js -->
		<script src="js/jquery-1.10.2.js"></script>
		<script src="js/bootstrap.min.js"></script>
		<script src="js/jquery.metisMenu.js"></script>
		<script src="js/custom-scripts.js"></script>
	</body>
</html>
