<?php
    include'connection.php';
    include'functions.php';
    
   	$apiKey="d1db51a3a6a8ef6078fd8bf623dd0008";
	$circle=$_GET['circle'];
	$operator=$_GET['op'];
	
	$url="https://www.mplan.in/api/plans.php?";

	$ch = curl_init();

    if (!$ch)
    {
        die("Couldn't initialize a cURL handle");
    }
    curl_setopt($ch, CURLOPT_URL,$url); // Target URL
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_POST, 1);
    
	$apiUrl="apikey=$apiKey&cricle=$circle&operator=$operator";
	
    curl_setopt($ch, CURLOPT_POSTFIELDS,$apiUrl);
    $result = curl_exec ($ch); 
    
    $result = json_decode($result,true);
    $records=$result["records"];
    
    $TOPUP=$records["TOPUP"];
    $data3g4g=$records["3G/4G"];
    $Romaing=$records["Romaing"];
    $COMBO=$records["COMBO"];
    
    
	echo "<button onclick='showRecordDiv(1)' id='btn1'>TOPUP</button>
	    <button onclick='showRecordDiv(2)' id='btn2'>3G/4G</button>
	    <button onclick='showRecordDiv(3)' id='btn3'>Romaing</button>
	    <button onclick='showRecordDiv(4)' id='btn4'>Unlimited</button>
	    <i class='fa fa-close' style='color:red' onclick='hidePlanDiv()'></i>
	    <div Id='planRecordDiv1'>";
    	    foreach($TOPUP as $key => $TOPUPval)
            {
                $rs=$TOPUPval["rs"];
                $desc=$TOPUPval["desc"];
                $validity=$TOPUPval["validity"];
            
                echo "<div id='planDetails'>
                        <div id='divAmt' onclick='useAmt($rs)'>
                            <i class='fa fa-inr'></i> <h4>".$rs."</h4><br><br><br>
                            <p>Validity</p> : <h4>".$validity."</h4>
                        </div>
                        <div id='desc'>
                            <p>".$desc."</p>
                        </div>
                     </div><br><br><hr>";
            }   
	    echo "</div>
	    <div Id='planRecordDiv2'>";
    	    foreach($data3g4g as $key => $data3g4gVal)
            {
                $rs=$data3g4gVal["rs"];
                $desc=$data3g4gVal["desc"];
                $validity=$data3g4gVal["validity"];
            
                echo "<div id='planDetails'>
                        <div id='divAmt' onclick='useAmt($rs)'>
                            <i class='fa fa-inr'></i> <h4>".$rs."</h4><br><br><br>
                            <p>Validity</p> : <h4>".$validity."</h4>
                        </div>
                        <div id='desc'>
                            <p>".$desc."</p>
                        </div>
                     </div><br><br><hr>";
            }   
	    echo "</div>
	    <div Id='planRecordDiv3'>";
	        foreach($Romaing as $key => $RomaingVal)
            {
                $rs=$RomaingVal["rs"];
                $desc=$RomaingVal["desc"];
                $validity=$RomaingVal["validity"];
            
                echo "<div id='planDetails'>
                        <div id='divAmt' onclick='useAmt($rs)'>
                            <i class='fa fa-inr'></i> <h4>".$rs."</h4><br><br><br>
                            <p>Validity</p> : <h4>".$validity."</h4>
                        </div>
                        <div id='desc'>
                            <p>".$desc."</p>
                        </div>
                     </div><br><br><hr>";
            }   
	    echo "</div>
	    <div Id='planRecordDiv4'>";
    	    foreach($COMBO as $key => $COMBOVal)
            {
                $rs=$COMBOVal["rs"];
                $desc=$COMBOVal["desc"];
                $validity=$COMBOVal["validity"];
            
                echo "<div id='planDetails'>
                        <div id='divAmt' onclick='useAmt($rs)'>
                            <i class='fa fa-inr'></i> <h4>".$rs."</h4><br><br><br>
                            <p>Validity</p> : <h4>".$validity."</h4>
                        </div>
                        <div id='desc'>
                            <p>".$desc."</p>
                        </div>
                     </div><br><br><hr>";
            }   
	    echo "</div>";
    
    
    
    
    
?>