<?php
	session_start();
	if($_SESSION['rid'])
	{
		$userid= $_SESSION['rid'];
	}
	else
	{
		header('location:../login.php');
	}
?>
<?php
	include'connection.php';
		
		$query8="select * from wallet where Userid='$userid' order by Id desc";
		$result8=mysqli_query($con,$query8);
		$data8=mysqli_fetch_array($result8);
		$currentbal= $data8['Balance'];
		
		$query2="select * from retailer where Userid='$userid'";
		$result2=mysqli_query($con,$query2);
		$databal=mysqli_fetch_array($result2);
		$username=$databal['Name'];
		$parentid=$databal['Parentid'];
	
?>
<html>
<title>LLP Recharge</title>
<head>
<style>
body{background:url('bg.jpg'); background-size:cover; width:1580px; margin:0px;}

.head{background:; width:1500px; height:85px; margin:0px;}
#p1{font-size:34px; float:left; Margin:10 0 0 45px; color:#996420; font-weight:bold;}
#p2{font-size:20px; float:left; margin:28 0 0 -8px; color:#eaa040; font-family:Courier;}
#p3{font-size:15px; font-family:Comic Sans MS; float:left; color:#996420; margin-top:48px; margin-left:-153px;}
.h2{background:white; width:400px; height:70px; margin:10 200px;}
#link1{float:right; margin:10 30 0 0px; font-size:20px; text-decoration:none;
 color:white; background:red; padding:5px; border-radius:4px;}
 #link2{float:right; margin:10 30 0 0px; font-size:20px; background:white;color:Green; padding:5px; border-radius:4px;}
 #link3{float:right; margin:25 40 0 0px;}
#link1:hover{ padding:5px; border-radius:4px; color:black;}
	
.menu{background:#996420; height:40px; width:1400px; margin-left:10px; padding:0; line-height:40px;}
.menu ul{padding:0; margin:0; position:relative; display:inline-block;}
.menu ul li{list-style:none; float:left; width:170px; line-height:40px; text-align:center; font-size:15px; margin:0px; padding:0; color:white;}
.menu ul li ul {display:none;}
.menu ul li:hover{background:#d1994a; cursor:pointer;}
.menu ul li:hover ul {display:block; z-index:2;}
.menu ul li:hover ul li{background:#d1994a; border-top:solid white 0.1px;}
.menu ul li ul li:hover{background:#996420; color:white;}
.menu ul li ul li:hover a{ color:white;}
.menu ul li a{ text-decoration:none; color:white;}
 #a1{border:none; color:white;}
 .menu{letter-spacing:1px;}
 #bal:hover{background:#996420; cursor:text;}
 

.dmorq{background:#565450; color:white; width:1200px; margin:10 0 0 50px; line-height:40px; z-index:0; border-radius:18px; font-size:24px; font-family:sans-serif;}
.rech{width:550px; margin:10 0 0 80px;}
table{width:550px; font-size:20px;}
#tdfl{float:right; margin-right:15px;}
#greenbal{background:green; color:white; font-size:22px; border-radius:5px; text-align:center; height:30px; width:180px; line-height:30px; border:2px solid white;}
#redbal{background:red; color:white; font-size:22px; border-radius:5px; text-align:center; height:30px; width:180px; line-height:30px; border:2px solid white;}
#inpset{width:180px; border-radius:2px; border:1px solid #996420; padding:4px; font-size:20px;}
#inpset1{width:180px; border-radius:2px; border:1px solid #996420; padding:4px; font-size:16px;}

#rechbtn{background:green; border:none; color:white; font-size:20px; border-radius:5px; cursor:pointer;
 padding:6px 10px; border:2px solid white; width:180px;}
#rechbtn:focus{outline:none;}
#rechbtn:hover{ background:#c7fac8; color:black; border:2px solid black; width:180px;}
.trarepo{height:30px; background:#996420; width:1450px; margin:0 0 0 20px; padding:0px;  line-height:30px;}
.trarepo p{font-size:20px; margin-left:20px; color:white;}
.addiv{ width:300px; height:300px; float:left; position:absolute; top:240px; left:800px; text-align:center; line-height:250px;}
#paytmimg{width:200px; height:200px; position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); transition:1s;}
#paytmimg:hover{width:250px; height:250px; transition:1s;}


.rechreport{width:1450px; margin:0 0 0 20px; padding:0px;}

#t1{ width:1450px; text-align:center; border-collapse:collapse; border-color:black; }
#t1 th{font-family:calibri; background:#94928f; color:white; }
#t1 td{font-family:calibri;}
#t1 tr:nth-child(odd){background:#f6f0e8;}
#t1 tr:nth-child(even){background:white; }
#green{color:#19dc42;}
#red{color:red;}
#blue{color:blue;}

.foot{margin:50px;}
</style>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: "ca-pub-8510562507020545",
    enable_page_level_ads: true
  });
</script>

</head>
<body>
	<div class="head">
		<p id="p1">LLP</p>
		<p id="p2">Recharge</p>
		<p id="p3">The Complete Solution</p>
		<a id="link1" href="logout.php">Log Out</a>
		<p id="link2"><?php echo "Welcome Dear- ".$username." [ ".$userid." ]";  ?></p>
		<p id="link3">
		  <iframe src="http://free.timeanddate.com/clock/i6g7kcjv/n44/fs24/fc077104/tct/pct/ftbi/tt0/th2" frameborder="0" width="568" height="30" allowTransparency="true"></iframe>

		</p>
	</div>
	<div class="menu">
		<ul>
			<li><a href="recharge_home.php" id="a1">Home</a></li>
			<li>Reports
				<ul>
					<li><a href="recharge_history.php">Recharge History</a></li>
					<li><a href="account_reports.php">Account Reports</a></li>
					<li><a href="check_status.php">Check Status</a></li>
				</ul>
			</li>
			<li>Documents
				<ul>
					<li><a href="my_commission.php">My Commission</a></li>
					<li><a href="commision.php">Get Commission</a></li>
					<li><a href="complain.php">Complain</a></li>
				</ul>
			</li>
			<li>Profile
				<ul>
					<li><a href="change_profile.php">Change Profile</a></li>
					<li><a href="change_pwd.php">Change Password</a></li>
				</ul>
			</li>
			<li>Payment Request
				<ul>
					<li><a href="payment_request.php">Update Payment</a></li>
					<li><a href="bank_list.php">Bank List</a></li>
				</ul>
			</li>
		</ul>
	</div>
	<div class="dmorq">
		<?php
			$querymsg="select * from messege";
			$resultmsg=mysqli_query($con,$querymsg);
			$datamsg=mysqli_fetch_array($resultmsg);
		?>
		<marquee scrollamount="3" onmouseover="stop()" onmouseout="start()">
		<?php
			echo $datamsg['Messege'];
		?>
		</marquee>
	</div>

	<?php
	include'connection.php';
    if($_SESSION['rid'])
    {	
    	$query2="select * from distributer where Userid='$parentid'";
    	$result2=mysqli_query($con,$query2);
    	$datad=mysqli_fetch_array($result2);
    	$username=$datad['Name'];
    	$grandparentid=$datad['Parentid'];
    
        $tmpOpId=rand(10000000,99999999);
		if(isset($_POST['submit']))
		{
			$operator=$_POST['operator'];
			$mnum=$_POST['mnum'];
			$cmnum=$_POST['cmnum'];
			$amount=$_POST['amount'];
			date_default_timezone_set("asia/Kolkata");
			$datetime= Date("Y-m-d - h:i:s A");
			$time= Date("h:i:s A");
			$date= Date("Y-m-d");
			
			$opcodequery="select * from operator where Operator='$operator'";
			$opcoderesult=mysqli_query($con,$opcodequery);
			$opcodedata=mysqli_fetch_array($opcoderesult);
			$opcode=$opcodedata['Value'];
			$myApiOpCode=$opcodedata['MyApiValue'];
			$QuickApiOpCode=$opcodedata['Quick_API'];
			$columName=$opcodedata['Commision_Column'];
			
			
			$querygetcom="select * from commision where Userid='$userid'";
			$rsultgetcom=mysqli_query($con,$querygetcom);
			$data=mysqli_fetch_array($rsultgetcom);
			$usercommvalue=$data[$columName];
			
			$parentq="select * from commision where Userid='$parentid'";
			$parentcomm=mysqli_query($con,$parentq);
			$dataparcomm=mysqli_fetch_array($parentcomm);
			$parcommvalue=$dataparcomm[$columName];
			$parbalcomm= $parcommvalue-$usercommvalue;
			
			$gparentq="select * from commision where Userid='$grandparentid'";
			$gparentcomm=mysqli_query($con,$gparentq);
			$gdataparcomm=mysqli_fetch_array($gparentcomm);
			$gparcommvalue=$gdataparcomm[$columName];
			$gparbalcomm= $gparcommvalue-$parcommvalue;
	
			if($operator=="--Select Operator--")	
			{
				echo "";
				echo "<h1 align='center'><font color='#ff0000'> &#x2716; You Did Not Select Any Operator !</font></h1>";
			}
			else
			{
				if(empty($operator) || empty($mnum) || empty($cmnum) || empty($amount))
				{
					echo "<h1 align='center'><font color='#ff0000'> &#x2716; Please Fill All Field !</font></h1>";
				}
				else
				{
					
					if($mnum==$cmnum)
					{
						if($amount<=$currentbal)
						{
							$quGetSameRech="select * from recharge where Companyname='$operator' and Mobile='$mnum' and Amount='$amount' and Status='PENDING' and Rechargedate='$date'";
							$reGetsameRech=mysqli_query($con,$quGetSameRech);
							$dataGetSameRech=mysqli_num_rows($reGetsameRech);
							
							 $quGetSameRech1="select * from recharge where Companyname='$operator' and Mobile='$mnum' and Amount='$amount' and Status='SUCCESS' and Rechargedate='$date'";
							 $reGetsameRech1=mysqli_query($con,$quGetSameRech1);
							 $dataGetSameRech1=mysqli_num_rows($reGetsameRech1);
							 
							 $quGetSameRech2="select * from recharge where Companyname='$operator' and Mobile='$mnum' and Amount='$amount' and Status='' and Rechargedate='$date'";
							 $reGetsameRech2=mysqli_query($con,$quGetSameRech2);
							 $dataGetSameRech2=mysqli_num_rows($reGetsameRech2);
							 
							if($dataGetSameRech>='1' || $dataGetSameRech1>='1' || $dataGetSameRech2>='1')
							{
								echo "<h1 align='center'><font color='#ff0000'> &#x2716; Same Recharge Not Allow Now !</font></h1>";
							}
							else
							{
								$commision=$amount*$usercommvalue/100;
								$actual=$amount-$commision;
									
									$insertq="insert into recharge(Userid,Parentid,Grandparentid,Rechargedate,Time,Agentname,Companyname,Mobile,Amount,Debitamount,Status)
									values('$userid','$parentid','$grandparentid','$date','$time','$username','$operator','$mnum','$amount','$actual','PENDING')";
									if(mysqli_query($con,$insertq))
									{   
										$querytetsrechid="select * from recharge order by Id desc";
										$rs=mysqli_query($con,$querytetsrechid);
										$rechiddata=mysqli_fetch_array($rs);
										$newrechid=$rechiddata['Id'];
										
										$query4="select * from wallet where Userid='$userid' order by Id desc";
										$result4=mysqli_query($con,$query4);
										$data4=mysqli_fetch_array($result4);
										$oldbalance= $data4['Balance'];
										$newbal=$oldbalance-$actual;
										
										$query5="insert into wallet(Userid,Openingbalance,Debit,Remarks,Balance,Date,Time,Transactiontype,Paynrechid,Operator,Mobile,Amount)
										values('$userid','$oldbalance','$actual','Recharge','$newbal','$date','$time','Recharge','$newrechid','$operator','$mnum','$amount')";
										
										if(mysqli_query($con,$query5))
										{
											
											$query9="update retailer set Balance='$newbal' where Userid='$userid'";
											mysqli_query($con,$query9);
											
											$parcommbal=$amount*$parbalcomm/100;
											$gparcommbal=$amount*$gparbalcomm/100;
											
											$insertparcomm="insert into commwallet(Userid,Balance,Date,Time,Rechargeid,Mobile,Amount,Operator,Retailer,Retailername)
											values('$parentid','$parcommbal','$date','$time','$newrechid','$mnum','$amount','$operator','$userid','$username')";
											mysqli_query($con,$insertparcomm);
											
											$insertgparcomm="insert into commwallet(Userid,Balance,Date,Time,Rechargeid,Mobile,Amount,Operator,Retailer,Retailername)
											values('$grandparentid','$gparcommbal','$date','$time','$newrechid','$mnum','$amount','$operator','$userid','$username')";
											mysqli_query($con,$insertgparcomm);
											
											$query6="select * from wallet where Userid='$userid' order by Id desc";
											$result6=mysqli_query($con,$query6);
											$data6=mysqli_fetch_array($result6);
											$ewalletid=$data6['Id'];
											
											$query7="update recharge set Balance='$newbal',Ewalletid='$ewalletid' where Id='$newrechid'";
											mysqli_query($con,$query7);
											
											$query10="update retailer set Lastrechdate='$date' where Userid='$userid'";
											mysqli_query($con,$query10);
											
											$query8="select * from wallet where Userid='$userid' order by Id desc";
											$result8=mysqli_query($con,$query8);
											$data8=mysqli_fetch_array($result8);
											$currentbal= $data8['Balance'];
											
											$quGetUseApi="select * from operator where Operator='$operator'";
											$reGetUseApi=mysqli_query($con,$quGetUseApi);
											$dataGetUseApi=mysqli_fetch_array($reGetUseApi);
											$UseApi=$dataGetUseApi['UseAPI'];
											
											if($UseApi=="My_API")
											{
												$token="VnseJ5rWQB5t4mwrpLI9EdSSyKt5%2bkeUUTqhvHq8H0w%3d";
												$url="https://www.vastwebindia.com/API/API/Recharge?Mobile=$mnum&OptCode=$myApiOpCode&Amount=$amount&Token=$token&Userid=sameermansuri111@gmail.com&rch_id=$newrechid";
												$request_timeout = 60; // 60 seconds timeout
												$ch = curl_init();
												curl_setopt($ch, CURLOPT_URL, $url);
												curl_setopt($ch, CURLOPT_TIMEOUT, $request_timeout);
												curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $request_timeout);
												curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
												$output = curl_exec($ch);
												$curl_error = curl_errno($ch);
												$getserver= curl_getinfo($ch);
												curl_close($ch);
												if($getserver["http_code"]==200)
												{
												
													$xml = simplexml_load_string($output);
													$orderId=$xml->rechargeno;
													$status1=$xml->Status;
													$mobile=$xml->mobile;
													$amount=$xml->amount;
													$operatorId=$xml->operatorid;
													$error_code=$xml->error_code;
													$service=$xml->service;
													$resText=$xml->resText;
													
													if($status1=="PENDING" || $status1=="SUCCESS")
													{
														$queryUpadateOrderId="update recharge set Transactionid='$orderId', API='My_API' where Id='$newrechid'";
														mysqli_query($con,$queryUpadateOrderId);
														echo "<h1 align='center'><font color='#008000'> &#x2714; Your Request Submit Successfull !</font></h1><br>";
													}
												
												}
												elseif($curl_error=="28"){
													$pendingquery="update recharge set Status='$status1', Transactionid='$orderId', Operatorid='$resText', Responsetxt='$resText' where Id='$newrechid'";
													mysqli_query($con,$pendingquery);
													
													echo "<h1 align='center'><font color='#3339FF'> &#x00BB; Your Recharge Request Has Been Pending Now !</font></h1><br>";
												}
											}
											elseif($UseApi=="Quick_API")
											{
											    $quUpdateStatus="update recharge set Status='SUCCESS' where Id='$newrechid'";
											    mysqli_query($con,$quUpdateStatus);
											    
												$apiUserId="9897095971";
												$apiPwd="1234567890";
												$apiPin="7255";
												$curl = curl_init();
												
												curl_setopt_array($curl, array(
												CURLOPT_URL => "https://www.quickrecharge.in/recharge_api/recharge",
												CURLOPT_RETURNTRANSFER => true,
												CURLOPT_ENCODING => "",
												CURLOPT_MAXREDIRS => 10,
												CURLOPT_TIMEOUT => 30,
												CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
												CURLOPT_CUSTOMREQUEST => "POST",
												CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data;
												name=\"member_id\"\r\n\r\n$apiUserId\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data;
												name=\"api_password\"\r\n\r\n$apiPwd\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data;
												name=\"api_pin\"\r\n\r\n$apiPin\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data;
												name=\"opcode\"\r\n\r\n$QuickApiOpCode\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data;
												name=\"number\"\r\n\r\n$mnum\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data;
												name=\"amount\"\r\n\r\n$amount\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data;
												name=\"request_id\"\r\n\r\n$newrechid\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
												CURLOPT_HTTPHEADER => array(
													"cache-control: no-cache",
													"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
													"postman-token: c8e4ba10-998b-162c-6e71-0bbaa6cc5e42"
												),
												));
												
												$response = curl_exec($curl);
												$err = curl_error($curl);
												
												curl_close($curl);
												
												if ($err)
												{
													echo "cURL Error #:" . $err;
												}
												else
												{
													$data2=json_decode($response);
											
													$status1 = $data2->STATUS;
													$resText = $data2->MESSAGE;
											
												
													if($status1=="PENDING" || $status1=="SUCCESS")
													{
														$queryUpadateOrderId="update recharge set Transactionid='$orderId', API='Quick_API' where Id='$newrechid'";
														mysqli_query($con,$queryUpadateOrderId);
														echo "<h1 align='center'><font color='#008000'> &#x2714; Your Request Submit Successfull !</font></h1><br>";
													}
													else
													{
														$refundquery="select * from wallet where Userid='$userid' order by Id desc";
														$refundresult=mysqli_query($con,$refundquery);
														$refunddata=mysqli_fetch_array($refundresult);
														$refundoldbal=$refunddata['Balance'];
														$refundnewbal=$refundoldbal+$actual;
														
														$refundaddbalquery="insert into wallet(Userid,Openingbalance,Credit,Remarks,Balance,Date,Time,Transactiontype,Paynrechid,Operator,Mobile,Amount,Status)
														values('$userid','$refundoldbal','$actual','Recharge_Refund','$refundnewbal','$date','$time','Recharge_Refund','$newrechid','$operator','$mnum','$amount','$status')";
														if(mysqli_query($con,$refundaddbalquery))
														{
															$getrefundewalletid="select * from wallet where Userid='$userid' order by Id desc";
															$resultrefundewalletid=mysqli_query($con,$getrefundewalletid);
															$datarefundewalletid=mysqli_fetch_array($resultrefundewalletid);
															$refundewalletid=$datarefundewalletid['Id'];
															
															$failedquery="update recharge set Creditewalletid='$refundewalletid', Status='$status1', Transactionid='$orderId', Operatorid='$resText', Responsetxt='$resText', API='Quick_API' where Id='$newrechid'";
															mysqli_query($con,$failedquery);
															
															$deletecomm="delete from commwallet where Rechargeid='$newrechid'";
															mysqli_query($con,$deletecomm);
															
															$query9="update retailer set Balance='$refundnewbal' where Userid='$userid'";
															mysqli_query($con,$query9);
															
															
															echo "<h1 align='center'><font color='#ff0000'> &#x2716; Your Recharge Request Has Been Failed Now !</font></h1>";
														
														}
													}
												}
											}
											else
											{
												$token="Q21c5rsQorimWRxSCtds";
												$url="http://api.rechapi.com/recharge.php?format=xml&token=$token&mobile=$mnum&amount=$amount&opid=$opcode&urid=$newrechid";
												$request_timeout = 60; // 60 seconds timeout
												$ch = curl_init();
												curl_setopt($ch, CURLOPT_URL, $url);
												curl_setopt($ch, CURLOPT_TIMEOUT, $request_timeout);
												curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $request_timeout);
												curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
												$output = curl_exec($ch);
												$curl_error = curl_errno($ch);
												$getserver= curl_getinfo($ch);
												curl_close($ch);
												if($getserver["http_code"]==200)
												{
												
													$xml = simplexml_load_string($output);
													$orderId=$xml->orderId;
													$status1=$xml->status;
													$mobile=$xml->mobile;
													$amount=$xml->amount;
													$operatorId=$xml->operatorId;
													$error_code=$xml->error_code;
													$service=$xml->service;
													$resText=$xml->resText;
													if($status1=="PENDING" || $status1=="SUCCESS")
													{
														$queryUpadateOrderId="update recharge set Transactionid='$orderId', API='Rech_API' where Id='$newrechid'";
														mysqli_query($con,$queryUpadateOrderId);
														echo "<h1 align='center'><font color='#008000'> &#x2714; Your Request Submit Successfull !</font></h1><br>";
													}
													else
													{
														$refundquery="select * from wallet where Userid='$userid' order by Id desc";
														$refundresult=mysqli_query($con,$refundquery);
														$refunddata=mysqli_fetch_array($refundresult);
														$refundoldbal=$refunddata['Balance'];
														$refundnewbal=$refundoldbal+$actual;
														
														$refundaddbalquery="insert into wallet(Userid,Openingbalance,Credit,Remarks,Balance,Date,Time,Transactiontype,Paynrechid,Operator,Mobile,Amount,Status)
														values('$userid','$refundoldbal','$actual','Recharge_Refund','$refundnewbal','$date','$time','Recharge_Refund','$newrechid','$operator','$mnum','$amount','$status')";
														if(mysqli_query($con,$refundaddbalquery))
														{
															$getrefundewalletid="select * from wallet where Userid='$userid' order by Id desc";
															$resultrefundewalletid=mysqli_query($con,$getrefundewalletid);
															$datarefundewalletid=mysqli_fetch_array($resultrefundewalletid);
															$refundewalletid=$datarefundewalletid['Id'];
															
															$failedquery="update recharge set Creditewalletid='$refundewalletid', Status='$status1', Transactionid='$orderId', Operatorid='$resText', Responsetxt='$resText', API='Rech_API' where Id='$newrechid'";
															mysqli_query($con,$failedquery);
															
															$deletecomm="delete from commwallet where Rechargeid='$newrechid'";
															mysqli_query($con,$deletecomm);
															
															$query9="update retailer set Balance='$refundnewbal' where Userid='$userid'";
															mysqli_query($con,$query9);
															
															
															echo "<h1 align='center'><font color='#ff0000'> &#x2716; Your Recharge Request Has Been Failed Now !</font></h1>";
														
														}
													}
													
												
												}
												elseif($curl_error=="28"){
													$pendingquery="update recharge set Status='$status1', Transactionid='$orderId', Operatorid='$resText', Responsetxt='$resText' where Id='$newrechid'";
													mysqli_query($con,$pendingquery);
													
													echo "<h1 align='center'><font color='#3339FF'> &#x00BB; Your Recharge Request Has Been Pending Now !</font></h1><br>";
												}
											
											}
										}
										else
										{
											echo "<h1 align='center'><font color='#ff0000'> &#x2716; Error 5 !</font></h1>";
										}
									
									}
									else
									{
										echo "<h1 align='center'><font color='#ff0000'> &#x2716; Error For Insert Data !</font></h1>";
									}
							}	
						}	
						else	
						{
							echo "<h1 align='center'><font color='#ff0000'> &#x2716; Your Balance Is Low !</font></h1>";
						}
					}
					else
					{
						echo "<h1 align='center'><font color='#ff0000'> &#x2716; Mobile Number And Confirm Number Does Not Match !</font></h1>";
					}
				}
			}		
			echo "<META HTTP-EQUIV ='Refresh' Content ='20' >";
		}
    }
    else
    {
    	header('location:../login.php');
    }
       
    
?>
<div class="rech">
<form method='post'>
	<table border="0" cellpadding="10">
	    <tr>
	        <td id="tdfl">Balance : </td>
	        <?php
	        if($currentbal>=500)
	        {
	            $colorBal="greenbal";
	        }
	        else
	        {
	            $colorBal="redbal";
	        }
	        
	    echo "<td><p id=".$colorBal.">".$currentbal."</p></td>"; ?>
	   </tr>
		<tr>
			<td id="tdfl">Recharge: </td>
			<td >
			<?php
			include'connection.php';
			$querygetservic="select * from service";
			$resultgetservic=mysqli_query($con,$querygetservic);
			?>
			<script>
				function onchange_event(arg)
				{
					var xmlhttp = new XMLHttpRequest();
					xmlhttp.open("GET","ajax.php?sid="+arg,false);
					xmlhttp.send(null);
					document.getElementById("divop").innerHTML=xmlhttp.responseText;
				
				}
			</script>
			
			<input type='radio' name='gen' onchange='onchange_event(1)'/>Mobile
			<input type='radio' name='gen' onchange='onchange_event(2)'/>DTH
			<input type='radio' name='gen' onchange='onchange_event(3)'/>Postpaid
				
			</td>
		</tr>


			<tr>
				<td id="tdfl">Operator: </td> 
				
				<td>
				<div id="divop">
				<select name="operator"  id="inpset1">
						<option id="opfont">--Select Operator--</option>
					</select>
				</div></td>
			</tr>
			
			<tr>
				<td id="tdfl">DTH / Mobile No:</td>
				<td><input type="number" name="mnum" id="inpset"></td>
			<tr>
				<td id="tdfl">Confirm No:</td>
				<td><input type="number" name="cmnum" id="inpset"></td>
			</tr>	
			<tr>
				<td id="tdfl">Amount:</td>
				<td><input type="number" name="amount" id="inpset"></td>
			</tr>
			<tr>
				<td></td>
				<td><input type="submit" name="submit" id="rechbtn" value="Recharge Now"></td>
			</tr>
			
			</form>
		</table>
	</div>
	<div class="addiv">
	    <a href="payment_request.php" target="_blank"><img src="../paytmicon.png" id="paytmimg"></img></a>
	 </div>
	<div class="trarepo">
		<p>Transaction Reports</p>
	</div>
	<div class="rechreport">
		<?php
			echo "<table width='100%' border='1' id='t1' cellpadding='5'>";
				echo "<tr>";
					echo "<th>";
						echo "Sl No.";
					echo "</th>";
					echo "<th>";
						echo "Recharge Id";
					echo "</th>";
					echo "<th>";
						echo "Ewallet Id";
					echo "</th>";
					echo "<th>";
						echo "Operator Id";
					echo "</th>";
					echo "<th>";
						echo "Company";
					echo "</th>";
					
					echo "<th>";
						echo "Mobile No";
					echo "</th>";
					
					echo "<th>";
						echo "Amount";
					echo "</th>";
					
					echo "<th>";
						echo "Status";
					echo "</th>";
					
					echo "<th>";
						echo "Date | Time";
					echo "</th>";
				echo "</tr>";
				$sl=0;
				$getrechhistq="select * from recharge where Userid='$userid' order by Id desc limit 20";
				$resultgetrechhid=mysqli_query($con,$getrechhistq);
				while($row=mysqli_fetch_array($resultgetrechhid))
				{
					$sl=$sl+1;
					if($row['Status']=="SUCCESS")
					{
						$colorid="green";
					}
					elseif($row['Status']=="FAILED")
					{
						$colorid="red";
					}
					else
					{
					    $colorid="blue";
					}
					echo "<tr>";
						echo "<td>".$sl."</td>";
						echo "<td>".$row['Id']."</td>";
						echo "<td>".$row['Ewalletid']." , ".$row['Creditewalletid']."</td>";
						echo "<td>".$row['Operatorid']."</td>";
						echo "<td>".$row['Companyname']."</td>";
						echo "<td>".$row['Mobile']."</td>";
						echo "<td>".$row['Amount']."</td>";
						echo "<td id='$colorid'>".$row['Status']."</td>";
						echo "<td>".$row['Rechargedate']." | ".$row['Time']."</td>";
						
					echo "</tr>";
				}
				
			echo "</table>";
		
		?>
	</div>
	<div class="foot">
		<p>Copyright &copy; 2018 Long Life Product Pvt. Ltd.</p>
	</div>
	
</body>
</html>