<?php
	include'session.php';
	include'../connection.php';
	include'../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';
	
	    $compId    = $_GET['compId'];
	    
	    $data1     = "c.Userid, c.TxnId, c.PartnerId, c.UserMsg, c.Status,";
	    $data2     = "r.Status, r.OpId, r.Lapu, r.Date, r.Id, r.PartnerId,";
	    $data3     = "a.CallBack";
	    
	    $IJcNr     = "LEFT JOIN recharge AS r ON c.TxnId=r.Id";
	    $IJcNa     = "LEFT JOIN api_user AS a ON c.Userid=a.Userid";
	    
	    $where1    = "c.Id='$compId'";
	    
	    $quComp    = "SELECT $data1 $data2 $data3 FROM complain AS c $IJcNr $IJcNa WHERE $where1";
		$reComp    = mysqli_query($con,$quComp);
		$dataComp  = mysqli_fetch_array($reComp);
		$UsrId     = $dataComp[0];
		$LLPtxnId  = $dataComp[1];
		$PartnerId = $dataComp[2];
		$UserMsg   = $dataComp[3];
		$C_Status  = $dataComp[4];
		$R_Status  = $dataComp[5];
		$OpId      = $dataComp[6];
		$ApiNLapu  = $dataComp[7];
		$R_Date    = $dataComp[8];
		$RechId    = $dataComp[9];
		$PartnerId = $dataComp[10];
		$apiCBurl  = $dataComp[11];
								
						    
if(isset($_POST['submit']))
{
    $CompStatus = $_POST['CompStatus'];
    $OpRefId    = $_POST['OpRefId'];
    
    if($CompStatus=="REJECT")
    {
        $RespoMsg   = "Recharge Is Successfull";
        $updateRech = "UPDATE recharge SET OpId='$OpRefId' WHERE Id='$LLPtxnId'";
        mysqli_query($con,$updateRech);
    }
    elseif($CompStatus=="REFUND")
    {
        $RespoMsg = "Recharge Has Been Refunded";
    }
    
    $updateComp="UPDATE complain SET R_Date='$date', R_Time='$time', RespoMsg='$RespoMsg', Status='$CompStatus' WHERE Id='$compId'";
    if(mysqli_query($con,$updateComp))
    {
        if(!empty($apiCBurl))
        {
            $apiUrl = "$apiCBurl?status=$R_Status&partnertid=$PartnerId&orderid=$RechId&opid=$OpRefId&complain_id=$compId&comp_status=$CompStatus";
            
            $quApiHit = "INSERT INTO api_hit (Date,Time,TxnId,PartnerId,ApiName,Type,Disc) VALUES ('$date','$time','$compId','$PartnerId','$UsrId','COMPLAIN','$apiUrl')";
	        mysqli_query($con,$quApiHit);
            
            require'../LinkFile/curlGET.php';

        }
        
            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>";
    }
}
	?>						    
	<!--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>Id</th>
					    		<th>LLP T.Id</th>
							    <th>Api / Lapu</th>
							    <th>Action</th>
							    <th>OpId</th>
				    			<th>Userid</th>
						    	<th>PartnerId</th>
							    <th>UserMsg</th>
							    <th>C.Status</th>
							    <th>R.Status</th>
    						</tr>
    					<?php
    						echo "<tr>";
    						    echo "<td>".$compId."</td>";
    						    echo "<td><a href='check_txn_status.php?rechId=".$LLPtxnId."' target='_blank'>".$LLPtxnId."</a></td>";
    						    echo "<td><a href='recharge_by_lapu.php?rechId=".$LLPtxnId."&lapuNo=".$ApiNLapu."&rechDate=".$R_Date."' target='_blank'>".$ApiNLapu."</a></td>";
    						    echo "<td>";
    						        echo "<select name='CompStatus'>";
    						            echo "<option>REJECT</option>";
    						            echo "<option>REFUND</option>";
    						        echo "</select>";
    						    echo "</td>";
    						    echo "<td><input type='text' value='".$OpId."' name='OpRefId'></td>";
    						    echo "<td>".getName($UsrId)."<br>[ ".$UsrId." ]</td>";
    						    echo "<td>".$PartnerId."</td>";
    						    echo "<td><textarea style='padding:5px;'>".$UserMsg."</textarea></td>";
    						    echo "<td>".$C_Status."</td>";
    						    echo "<td>".$R_Status."</td>";
    						echo "</tr>";
    					?>
			    		</table>
				    	<input type='submit' value='Solve' name='submit'>
					</form>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>