<?php
	include'session.php';
	include'../connection.php';
	include'../functions.php';
?>
<html>
<head>
	<title>Failed Recharge</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:15px;
			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=checkbox]{
			width:150px;
		}
		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>Failed Recharge :-</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">
<?PHP
	$rechId=$_GET['rechId'];
	
	if(isset($_POST['submit']))
	{
	    $msg=$_POST['msg'];
	    $solved=$_POST['solved'];
	    
    	$query="SELECT * FROM recharge WHERE Id=$rechId";
	    $result=mysqli_query($con,$query);
	    $data=mysqli_fetch_array($result);
	
	    $uid       = $data['Userid'];
	    $Debit     = $data['Debit'];
	    $Mobile    = $data['Mobile'];
	    $Amount    = $data['Amount'];
	    $PartnerId = $data['PartnerId'];
	    $Status    = $data['Status'];
	    
	    if($Status=="FAILED")
	    {
	        echo "<h1 align='center'><font color='red'> &#x2714; Transaction Failed Already !</font></h1><br>";
	        exit();
	    }
	    $dataUser = getUser($uid);
	    $UsrType  = $dataUser['Type'];
	    
	    $OpBal   = getBal($uid);
	    $ClBal   = $OpBal+$Debit;
	
	    $quRefund="INSERT INTO wallet (Date,Time,Userid,OpBal,Txn,ClBal,TxnId,TxnType,TxnWith,Remarks)
	    VALUES ('$date','$time','$uid','$OpBal','$Debit','$ClBal','$rechId','Recharge_Refund','$IP','Recharge_Refund')";
	    if(mysqli_query($con,$quRefund))
	    {   
		    $ewalletid=mysqli_insert_id($con);
		    
	    	$quFailed="UPDATE recharge SET Status='FAILED', ApiBal='$ApiBal', OpId='$msg' WHERE Id='$rechId'";
	        mysqli_query($con,$quFailed);
	    
		    $query5="DELETE FROM comm_wallet WHERE TxnId='$rechId'";
		    mysqli_query($con,$query5);
		    
		    if(!empty($solved))
		    {
		        $UpdateComp="UPDATE complain SET R_Date='$date', R_Time='$time', RespoMsg='Refunded', Status='REFUND' WHERE TxnId='$rechId'";
		        mysqli_query($con,$UpdateComp);
		        echo "<h1 align='center'><font color='blue'> &#x2714; Complain Closed Successfully !</font></h1><br>";
		    }
		    
		    if($UsrType=="API")
	        {
	            /*
	            $status="FAILED";
	            
	            $CallBackUrl = str_replace(" ","", $CallBackUrl);

        		$url = "$CallBackUrl?partnertid=$Partnerid&status=$status&orderid=$rechId&opid=$msg&errmsg=$msg";
                $curl = curl_init();
            
                curl_setopt_array($curl, array(
                CURLOPT_URL => $url,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => "",
                CURLOPT_CONNECTTIMEOUT => 60,
                CURLOPT_TIMEOUT => 60,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => "GET",
                CURLOPT_HTTPHEADER => array(
                "cache-control: no-cache"
                    ),
                ));

                $response = curl_exec($curl);
                $hhtpCode =curl_getinfo($curl, CURLINFO_HTTP_CODE);
                $err = curl_error($curl);

                curl_close($curl);
                
                if ($err)
                {
                        //$do=mysql_query("INSERT INTO kwk_cbhis (oid,uid,status_code,msg,url)VALUES(paste your values)");
                }
                else
                {
                    //$do=mysql_query("INSERT INTO kwk_cbhis (oid,uid,status_code,msg,url)VALUES(paste your values)");
                }
                $insertCBH="INSERT INTO cbhis (oid,uid,status_code,msg,url)VALUES('$rechId','$uid','$hhtpCode','$response','$url')";
                mysqli_query($con,$insertCBH);
                
                */
	       }
		    echo "<div class='msg-div'>
				    <form method='post'>
					    <h3>Recharge Failed Successfully !</h3><br>
						<i class='fa fa-check-circle' aria-hidden='true' id='okIcon'></i><br><br>
						<a href='Pending_Recharge.php' class='btnPopup'>OK</a><br><br>
					</form>
				</div>";
	    }
	}						    
?>	
				    <form method="post">
					    <table cellpadding="20" border="2"> 
		    				<tr>
		    				    <th>Print Msg</th>
		    				    <th>Close Complain</th>
    						</tr>
                            <tr>
                                <td>
                                    <select name="msg" id="msg">
                                        <option>Failed !</option>
                                        <option>Invalid Number Or Operator !</option>
                                        <option>Invalid Number Or Amount !</option>
                                        <option>Invalid Amount !</option>
                                        <option>Operator Down !</option>
                                        <option>Refund !</option>
                                        <option>You can only select other than prime plan for recharge.	</option>
                                    </select>
                                </td>
                                <td><input type="checkbox" value="solved" name="solved" id="msg"></td>
			    		</table>
				    	<input type='submit' value='Solve' name='submit'>
					</form>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>