<?php
    require'../connection.php';
    require'../functions.php';
    
    $userid    = $_GET['userid'];
	$token     = $_GET['token'];
	$Partnerid = $_GET['orderid'];
	$UsrMsg    = $_GET['UsrMsg'];
	
	$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"=>"NOTSUBMIT", "msg"=>"Invalid Userid Or API Token !");
		echo $myresult = json_encode($myresponse);
	}
	else
	{
	    $query8       = "SELECT * FROM recharge WHERE Userid='$userid' AND Partnerid='$Partnerid'";
		$result8      = mysqli_query($con,$query8);
		$getPartnerId = mysqli_num_rows($result8);
		if($getPartnerId!==1)
		{
		    $myresponse = array("status"=>"NOTSUBMIT", "msg"=>"Data Not Found For This Partner Id !");
		    echo $myresult = json_encode($myresponse);
		}
		else
		{
		    $data8      = mysqli_fetch_array($result8);
		    $Status     = $data8['Status'];
		    $LLPTxnId   = $data8['Id'];
		    $api        = $data8['Api'];
		    
		    if($Status=="SUCCESS")
		    {
		        $quDupComp   = "SELECT Id FROM complain WHERE Partnerid='$Partnerid' AND Status='SUBMIT'";
		        $reDupComp   = mysqli_query($con,$quDupComp);
		        $dataDupComp = mysqli_num_rows($reDupComp);
		        if($dataDupComp==0)
		        {
	    	        $quRegComp = "INSERT INTO complain (Date,Time,Userid,TxnId,PartnerId,UserMsg) VALUES ('$date','$time','$userid','$LLPTxnId','$Partnerid','$UsrMsg')";
		            if(mysqli_query($con,$quRegComp))
		            {
		                $compId = mysqli_insert_id($con);
		                
		                $apiFile    = "RegCompFile_".$api.".php";
						require '../LinkFile/'.$apiFile;
						
						$msg    = "Your Complaint Submitted Successfully, Your Complaint Id Is $compId";
						$mobile = "8410930786";
						require '../wmsg.php';
		                
		                $myresponse = array("status"=>"SUBMIT", "complainid"=>"$compId", "msg"=>"Complain Submitted Successfully !");
	    	            echo $myresult = json_encode($myresponse);
		            }
		            else
		            {
		                $myresponse = array("status"=>"NOTSUBMIT", "msg"=>"Not Submitted, Try Again !");
		                echo $myresult = json_encode($myresponse);
		            }
		        }
	            else
	            {
	                $myresponse = array("status"=>"NOTSUBMIT", "msg"=>"Complain Submitted Already For This Txn !");
	                echo $myresult = json_encode($myresponse);
	            }
		    }
		    elseif($Status=="PENDING")
		    {
	    	    $myresponse = array("status"=>"NOTSUBMIT", "msg"=>"This Txn Is PENDING !");
		        echo $myresult = json_encode($myresponse);
		    }
		    elseif($Status=="FAILED")
		    {
	    	    $myresponse = array("status"=>"NOTSUBMIT", "msg"=>"This Txn Is NOTSUBMIT Already !");
		        echo $myresult = json_encode($myresponse);
		    }
		    else
		    {
	    	    $myresponse = array("status"=>"NOTSUBMIT", "msg"=>"Something Error !");
		        echo $myresult = json_encode($myresponse);
		    }
		}
	}

?>