<?PHP
	include'session.php';
	include'../connection.php';
	include'../functions.php';
	
	if(isset($_POST['submit']))
	{
		$orderId = $_POST['orderId'];
		$msg     = $_POST['msg'];
		
		if(empty($orderId))
		{
		    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>Order Id Must Be Enter 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>";
		}
		else
		{	
			$quDupTxn="SELECT * FROM complain WHERE TxnId='$orderId'";
			$reDupTxn=mysqli_query($con,$quDupTxn);
			$countDupTxn=mysqli_num_rows($reDupTxn);
			
			$quTxnStatus="SELECT * FROM recharge WHERE Id='$orderId'";
			$reTxnStatus=mysqli_query($con,$quTxnStatus);
			$dataTxnStatus=mysqli_fetch_array($reTxnStatus);
			
			
			if($countDupTxn>=1)
			{
			    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>Duplicate Complain Not Allowed !</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($dataTxnStatus['Status']=="PENDING")
			{
			    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>Complain Will Be Not Raised For Pending Recharge!</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($dataTxnStatus['Status']=="FAILED")
			{
			    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>This Recharge Is Already Refund !</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
			{
			    echo $quInsertRequest="INSERT INTO complain(Date,Time,Userid,TxnId,UserMsg) VALUES ('$date','$time','$userid','$orderId','$msg')";
				if(mysqli_query($con,$quInsertRequest))
				{
					echo "<div class='msg-div'>
							<form method='post'>
							<h3>Complain Raised 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>Complain</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:left;
			text-align:center;
			padding:10px;
		}
		.div1 table{
			width:94%;
			text-align:center;
			font-size:17px;
			border-collapse:collapse;
			margin:10px;
			padding:2px 10px;
		}
		.div1 hr{
			margin:5px 10px;
			padding:0 10px;
		}
		table th{
			background:#6b5127;
			color:white;
			height:40px;
			border:solid white 1px;
		}
		table td{
			background:white;
			height:40px;
			border:solid black 1px;
		}
		.div1 hr{width:94%;}
		.div1 input,select, textarea{
			width:90%;
			height:45px;
			margin:5px 10px;
			padding:2px 10px;
			border-radius:5px;
			border:1px solid #6b5127;
			font-size:18px;
		}
		textarea{
			height:100px;
			padding:5px 10px;
		}
		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>Complain :-</p></div>
				<div class="msg"><marquee><?php include'../msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
				<form method="post">
					<div class="div1">
						<input type="number" name="orderId" placeholder="Enter OrderId..." required>
						<textarea name="msg" placeholder="Type your message hear..(optional)"></textarea>
						<input type="submit" name="submit" value="Submit"  onclick='showLoader()'>
					</div>
				</form>
				<div class="div1">
					<center><h1>Recent Complain</h1></center><hr>
					<table cellpadding="20" border="2">
						<tr>
							<th>Comp. Id</th>
							<th>Order Id</th>
							<th>Response Message</th>
							<th>Status</th>
						</tr>
						<?php
							$quGetTxn="SELECT * FROM complain WHERE Userid='$userid' ORDER BY Id DESC LIMIT 10";
							$reGetTxn=mysqli_query($con,$quGetTxn);
							while($dataGetTxn=mysqli_fetch_array($reGetTxn))
							{
								if($dataGetTxn['Status']=="PENDING")
								{
									$color="blue";
								}
								elseif($dataGetTxn['Status']=="CLOSED")
								{
									$color="green";
								}
								echo "<tr>";
									echo "<td>".$dataGetTxn['Id']."</td>";
									echo "<td>".$dataGetTxn['TxnId']."</td>";
									echo "<td style='width:50%'><p>".$dataGetTxn['RespoMsg']."</p></td>";
									echo "<td style='color:".$color."'>".$dataGetTxn['Status']."</td>";
								echo "</tr>";
							}
						?>
					</table>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>