<?php
	include'session.php';
	include'connection.php';
	include'functions.php';
	
	if(isset($_POST['submit']))
	{
		$oldPwd = $_POST['oldPwd'];
		$newPwd = $_POST['newPwd'];
		$cNewPwd = $_POST['cNewPwd'];
		
		$reOldPwd=mysqli_query($con,"SELECT * FROM retailer WHERE Userid='$userid'");
		$dataOldPwd=mysqli_fetch_array($reOldPwd);
		$getOldPwd=$dataOldPwd['Password'];
		
		if(empty($oldPwd) || empty($newPwd) || empty($cNewPwd))
		{
		    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>Fill All Field Please !</h3><br>
				        <i class='fa fa-ban' aria-hidden='true' id='NotokIcon'></i><br><br>
				        <button type='submit' class='btnPopup'>OK</button><br><br>
			        </form>
		        </div>";
		}
		elseif($oldPwd!==$getOldPwd)
		{
		    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>Old Password Not Matched !</h3><br>
				        <i class='fa fa-ban' aria-hidden='true' id='NotokIcon'></i><br><br>
				        <button type='submit' class='btnPopup'>OK</button><br><br>
			        </form>
		        </div>";
		}
		elseif($newPwd!==$cNewPwd)
		{
		    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>Password And Confirm Password Not Matched !</h3><br>
				        <i class='fa fa-ban' aria-hidden='true' id='NotokIcon'></i><br><br>
				        <button type='submit' class='btnPopup'>OK</button><br><br>
			        </form>
		        </div>";
		}
		else
		{
			if($reUpdatePwd=mysqli_query($con, "UPDATE retailer SET Password='$newPwd' WHERE Userid='$userid'"))
			{
				echo "<div class='msg-div'>
						<form method='post'>
						<h3>Password has been changed successfully !</h3><br>
						<i class='fa fa-check-circle' aria-hidden='true' id='okIcon'></i><br><br>
						<button type='submit' class='btnPopup'>OK</button><br><br>
						</form>
					</div>";
			}
			
		}
	}
?>
<html>
<head>
	<title>Change Password</title>
	<!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
	<link rel="icon" href="images/logo.png" type="image/gif" sizes="16x16">
	
	<!-- Admin CSS File Link -->
	<link rel="stylesheet" href="css/style.css">
	
	<!-- User JAVA SCRIPT File Link -->
	<script type="text/javascript" src="js/script.js"></script>

	
	<!-- Font Awesome Icone -->
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
	
	<style>
		.div1{
			background:#f7f7f7;
			width:50%;
			height:500px;
			float:right;
			text-align:center;
			padding-top:50px;
		}
		.div1 i{
			font-size:300px;
			color:#6b5127;
			margin:0 10px;
			
		}
		.div1 input{
			width:90%;
			height:55px;
			margin:10px;
			padding:2px 10px;
			border-radius:5px;
			border:1px solid #6b5127;
			font-size:19px;
		}
		input[type=submit]{
			background:#6b5127;
			color:white;
			font-size:30px;
			transition:1s;
		}
		input[type=submit]:hover{
			background:white;
			color:#6b5127;
			border:1px solid #6b5127;
			cursor:pointer;
			transition:1s;
		}
		
		@media(max-width:768px)
		{
			.div1{
				width:100%;
				height:auto;
			}
			.nav,.container{
				height:auto;
			}
		}
	</style>
	<link rel="stylesheet" href="css/mediaStyle.css">
</head>
<body>
	<!--Header Divison-->
	<?php
		require'header.php';
	?>
	
	<!--Container Division-->
	<div class="container">
		<?php
			include'menu.php';
		?>
		<div class="content">
			<div class="head">
				<div class="title"><p>Change Password :-</p></div>
				<div class="msg"><marquee><?php include'msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
				<form method="post">
					<div class="div1">
						<i class="fa fa-lock"></i>
					</div>
					<div class="div1">
						<input type="text" name="oldPwd" placeholder="Old Password..." >
						<input type="text" name="newPwd" placeholder="New Password..."  >
						<input type="text" name="cNewPwd" placeholder="Confirm New Password..."  >
						<input type="submit" name="submit" value="Submit"  onclick='showLoader()'>
					</div>
				</form>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>