<?php
    require'../connection.php';
    require'../functions.php';
    
    $userid  = $_GET['userid'];
	$token   = $_GET['token'];
	$compId  = $_GET['complainid'];
	
    $QuGetUser = "SELECT * FROM api_user WHERE Userid='$userid' AND Token='$token'";
	$ReGetUser = mysqli_query($con,$QuGetUser);
	$GetUser   = mysqli_num_rows($ReGetUser);
	
	if($GetUser!=1)
	{    
		$myresponse = array("status"=>"FAILED", "msg"=>"Invalid Userid Or API Token !");
		echo $myresult = json_encode($myresponse);
	}
	else
	{
	    $IJcNr     = "INNER JOIN recharge ON complain.TxnId=recharge.Id";
	    $where1    = "complain.Id='$compId'";
	    $data1     = "complain.Status,";
	    $data2     = "recharge.OpId";
	    $quComp    = "SELECT $data1 $data2 FROM complain $IJcNr WHERE $where1";
		$reComp    = mysqli_query($con,$quComp);
		$dataComp  = mysqli_fetch_array($reComp);
		$C_Status  = $dataComp[0]; 
		$OpId      = $dataComp[1];
		    
		$countComp = mysqli_num_rows($reComp);
		if($countComp!=1)
		{
		    $myresponse = array("status"=>"FAILED", "msg"=>"Data Not Found For This Complain Id !");
		    echo $myresult = json_encode($myresponse);
		}
		else
		{	
		    if($C_Status=="SUBMIT")
		    {
		        $myresponse = array("status"=>"SUCCESS", "msg"=>"The case is in proccessing, Wait Please !");
		        echo $myresult = json_encode($myresponse);
		    }
		    elseif($C_Status=="REFUND")
		    {
		        $RespoMsg = "Recharge Has Been Refunded";
		        $myresponse = array("status"=>"SUCCESS", "comp_status"=>"$C_Status", "opid"=>"Failed !", "msg"=>"$RespoMsg");
		        echo $myresult = json_encode($myresponse);
		    }
		    else
		    {
	    	    $RespoMsg   = "Recharge Is Successfull";
                $myresponse = array("status"=>"SUCCESS", "comp_status"=>"$C_Status", "opid"=>"$OpId", "msg"=>"$RespoMsg");
		        echo $myresult = json_encode($myresponse);
		    }
		}
	}

?>