<?php
	include'session.php';
	include'connection.php';
	include'../Retailers/functions.php';
?>
<html>
<head>
	<title>Complain Solve</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:;
			width:98%;
			margin:1%;
			padding:10px;
			overflow:auto;
		}
		.div1 input, .div1 select{
			height:35px;
			width:auto;
			font-size:14px;
			padding:4px 8px;
			border-radius:5px;
			border:solid #6b5127 1px;
			overflow:hidden;
			margin:0px;
		}
		input[type=submit]{
			background:#6b5127;
			color:white;
			transition:1s;
			cursor:pointer;
			float:right;
			width:150px;
			margin-right:100px;
		}
		input[type=submit]:hover{
			background:white;
			color:#6b5127;
			transition:1s;
		}
		.div1 table{
			width:96%;
			text-align:center;
			font-size:15px;
			border-collapse:collapse;
			padding:2px 10px;
			margin:2%;
		}
		table th{
			background:#6b5127;
			color:white;
			height:40px;
			border:solid white 1px;
			padding:2px 5px;
		}
		table td{
			background:white;
			height:50;
			border:solid black 1px;
			padding:5px 8px;
		}
		
		@media(max-width:768px)
		{
			.div1{
				background:;
				width:100%;
				height:auto;
				margin:10px 0 0 0;
				padding:0;
				text-align:center;
			}
			.div1 input, .div1 select{
				width:90%;
				margin:10px;
			}
			.div2{
				width:100%;
				margin:10px 0 0 0;
				padding:0px;
				text-align:center;
			}
		}
		#inpRef{display:none;}

	</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 List :-</p></div>
				<div class="msg"><marquee><?php include'msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
			    <script>
			        function response()
			        {
			            var rType = document.getElementById("responType").value;
			            
			            if(rType=="Transaction Successful, Contact Costumer Care With Reference Id")
			            {
			                document.getElementById("inpRef").style.display = "inline";
			            }
			            else
			            {
			                document.getElementById("inpRef").style.display = "none";
			            }
			        }
			    </script>
				<div class="div1">
				    <form method="post">
					    <table cellpadding="20" border="2"> 
		    				<tr>
	    						<th colspan='2'>Response Type</th>
			    				<th>Comp.Id</th>
				    			<th>Rechargeid</th>
					    		<th>User</th>
						    	<th>Messege</th>
							    <th>Status</th>
    						</tr>
	    					<?PHP
							    $compId=$_GET['compId'];
							    
							    if(isset($_POST['submit']))
							    {
							        $respoMsg = $_POST['repoType'];
							        $opRefId = $_POST['opId'];
							        
							        if($respoMsg=="--SELECT--")
							        {
							            echo "<div class='msg-div'>
			                                    <form method='post'>
			                            	        <h3>Please Select Response Messege !</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($respoMsg=="Transaction Successful, Contact Costumer Care With Reference Id")
							        {
							            $printRespoMsg=$respoMsg." ".$opRefId;
							        }
							        else
							        {
							            $printRespoMsg=$respoMsg;
							        }
							        
							        if($respoMsg!="--SELECT--")
							        {
    							        $updateComp="UPDATE complain SET Responsemsg='$printRespoMsg', Status='Solved', Active='1' WHERE Id='$compId'";
	    						        if(mysqli_query($con,$updateComp))
		    					        {
			    				            echo "<div class='msg-div'>
				    			                    <form method='post'>
					    		                        <h3>Complain Solved Successfully !</h3><br>
						    	                        <i class='fa fa-check-circle' aria-hidden='true' id='okIcon'></i><br><br>
							                            <a href='complain_list.php' class='btnPopup'>OK</a><br><br>
							                        </form>
						                    </div>";
    							        }
	    						        else
		    					        {
			    				            echo "<div class='msg-div'>
			                                        <form method='post'>
			                                	        <h3>Something Error !</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>";
							            }
							        }
							    }
							    
							    
								$sl=0;
								$quPayment="SELECT * FROM complain WHERE Id='$compId'";
								$rePayment=mysqli_query($con,$quPayment);
								$dataPayment=mysqli_fetch_array($rePayment);
								$rechId=$dataPayment['Rechargeid'];
								$quRech="SELECT Operatorid FROM recharge WHERE Id='$rechId'";
								$reRech=mysqli_query($con,$quRech);
								$dataRech=mysqli_fetch_array($reRech);
								$opRefId=$dataRech['Operatorid'];
								
								if($dataPayment['Status']=="Solved" || $dataPayment['Status']=="Closed")
								{
								    $color="green";
								}
								else
								{
								    $color="blue";
								}
									
								$usrName=getName($dataPayment['Userid']);
								echo"<tr>";
									echo "<td>";
									    echo "<select name='repoType' id='responType' onchange='response()'>";
									        echo "<option>--SELECT--</option>";
									        echo "<option>Refunded</option>";
									        echo "<option>Transaction Successful</option>";
									        echo "<option>Transaction Successful, Contact Costumer Care With Reference Id </option>";
									        echo "<option>Order Id Invalid, Please Insert Correct Order Id.</option>";
									    echo "</select>";
									echo "</td>";
									echo "<td><input type='text' value='".$opRefId."' name='opId' id='inpRef'></td>";
									echo "<td>".$compId."</td>";
									echo "<td>".$rechId."</td>";
									echo "<td>".$usrName." [".$dataPayment['Userid']."]</td>";
									echo "<td><p>".$dataPayment['Messege']."</p></td>";
									echo "<td><p id='$color'>".$dataPayment['Status']."</p></td>";
								echo"</tr>";
								
						    
		    				?>
			    		</table>
				    	<input type='submit' value='Solve' name='submit'>
					</form>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>