<?PHP
	include'session.php';
	include'connection.php';
	include'../Retailers/functions.php';
	include'time.php';
	include'../Admin1/insertDiff.php';
	
	$dataUsr=getUser($userid);
	$parentId=$dataUsr['Parentid'];
	getCBT($parentId);
?>
<html>
<head>
	<title>Dashboard</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:#f7f7f7;
			width:50%;
			height:500px;
			float:left;
			text-align:center;
			padding:10px;
		}
		.div1 table{
			width:94%;
			text-align:center;
			font-size:13px;
			border-collapse:collapse;
			margin:10px;
			padding:2px 10px;
		}
		.div1 hr{
			margin:5px 10px;
			padding:0 10px;
		}
		table th{
			background:#6b5127;
			color:white;
			height:40px;
			border:solid white 1px;
			padding:2px;
		}
		table td{
			background:white;
			height:40px;
			border:solid black 1px;
			padding:2px 4px;
		}
		.div1 hr{width:94%;}
		.div1 input,select, textarea{
			width:90%;
			height:45px;
			margin:5px 10px;
			padding:2px 10px;
			border-radius:5px;
			border:1px solid #6b5127;
			font-size:18px;
		}
		#BalGreen{background:green; color:white; padding:4px 10px; border-radius:5px;}
		#BalRed{background:red; color:white; padding:4px 10px; border-radius:5px;}
		
		.subdiv1{background:; margin:10px 5%; width:90%;}
		.subdiv1 button{background:white; width:27%; height:30px; margin:5px; font-size:17px; border-radius:8px 0px 8px 0px;}
		.subdiv1 button i{font-size:20px;}
		#prepaid{background:lime;}
		#List1,#sbmt1{display:inline;}
		#List2,#sbmt2{display:none;}
		#List3,#sbmt3{display:none;}
		
		
		textarea{
			height:100px;
			padding:5px 10px;
		}
		input[type=submit]{
			background:#6b5127;
			color:white;
			font-size:30px;
			transition:1s;
		}
		input[type=radio]{
			width:25%;
			font-size:30px;
		}
		input[type=submit]:hover{
			background:white;
			color:#6b5127;
			border:1px solid #6b5127;
			cursor:pointer;
			transition:1s;
		}
		
		#planlink1{background:green; color:white; padding:5px 10px; border-radius:3px;float:right; margin:10px 5% 5px 0; display:none; cursor:pointer;}
		
		#speOfferDiv{background:white; width:90%; height:80vh; margin:10vh 5%; position:fixed; z-index:9999999; border:solid black 1px; display:none;}
		#speOfferDiv i{float:right; font-size:25px; margin:5px 50px 5px 0px;}
		#offerRecordDiv{background:white; width:100%; height:74vh; margin:5vh 0 1vh 0; border-top:none; padding:0px 20px 10px 20px; overflow:auto;}
		#SpeOff{background:green; color:white; padding:5px 10px; border-radius:3px; float:left; margin:10px 0px 5px 5%; display:none; cursor:pointer;}
		
		
		.planMainDiv{background:white; width:90%; height:80vh; margin:10vh 5%; position:fixed; z-index:9999999; border:solid black 1px; display:none;}
		.planMainDiv button{background:white; color:black; float:left; font-size:20px; margin:10px; padding:5px 10px;}
		#btn1{background:green; color:white;}
		.planMainDiv i{float:right; font-size:25px; margin:10px;}
		#planRecordDiv1,#planRecordDiv2,#planRecordDiv3,#planRecordDiv4{background:white; width:100%; height:65vh; margin:10vh 0 5vh 0; border-top:none; padding:20px; overflow:auto;}
		#planRecordDiv2,#planRecordDiv3,#planRecordDiv4{display:none;}
		#planDetails{background:#F4F1F1; width:100%; height:100px; float:left; margin-top:10px;}
		#divAmt{background:gray; width:150px; height:90px; float:left; padding:10px; margin:5px; color:white; border-radius:4px; cursor:pointer;}
		#divAmt i{float:left; font-size:18px; margin:0 0 0 10px;}
		#divAmt h4{float:right; margin-right:10px;}
		#divAmt p{float:left; font-size:15px;}
		
		#desc{height:90px; margin:5px; padding:10px; overflow:auto;}
		#desc p{font-size:12px; margin-right:10px;}
		
		 
		
		#circle{background:white; width:90%; height:80vh; margin:10vh 5%; position:fixed; border:solid black 1px; display:none; z-index:9;}
		#circle select{background:; width:100%; height:100%; margin:0; padding:0; border-radius:0;}
		#circle select option {background:; margin:5px 30px; padding:5px 10px; border-bottom:solid 1px gray;}
		
		@media(max-width:768px)
		{
			.div1{
				width:100%;
				height:auto;
			}
			.nav,.container{
				height:auto;
			}
		}
	</style>
	<link rel="stylesheet" href="css/mediaStyle.css">
</head>
<body>
    <script>
        
        function speOfferLink()
        {
            
            var opValue = document.getElementById("List1").value;
            var mobile1 = document.getElementById("mobile1").value;
            var mobileLength = mobile1.length;
            var mobile2 = document.getElementById("mobile2").value;
            
            if(opValue!="--Select Operator--" && mobile1 == mobile2 && mobileLength == 10)
            {
                document.getElementById("SpeOff").style.display = "block";
            }
            else
            {
               document.getElementById("SpeOff").style.display = "none"; 
            }
        }
        
        function showSpeOfferDiv()
		{
		    
		    document.getElementById("speOfferDiv").style.display = "block";
		    var mobile1 = document.getElementById("mobile1").value;
		    var opCode = document.getElementById("List1").value;
		    if(opCode == 1){
		        var op = "Airtel";
		    }else if(opCode == 2){
		        var op = "Idea";
		    }else if(opCode == 3 || opCode == 4){
		        var op = "BSNL";
		    }else if(opCode == 7){
		        var op = "Vodafone";
		    }else if(opCode == 10){
		        var op = "Jio";
		    }
		    
		    
		    var xmlhttpState = new XMLHttpRequest();
			xmlhttpState.open("GET","ajax_specialOffer.php?mobile="+mobile1+"&op="+op, false)
			xmlhttpState.send(null);
			document.getElementById("speOfferDiv").innerHTML = xmlhttpState.responseText;
		}
        
        function hideOfferDiv()
        {   
            var divCondition = document.getElementById("speOfferDiv").style.display = "none";
        }
        
        
        function showPlanLink(Arg)
        {
            var opValue = document.getElementById("List1").value;
            
            if(opValue!="--Select Operator--" && Arg == 1)
            {
                document.getElementById("planlink1").style.display = "block";
            }
            else
            {
               document.getElementById("planlink1").style.display = "none"; 
            }
        }
    
        function showCircleDiv()
        {
            document.getElementById("circle").style.display = "block";
        }
        
        function showPlanDiv()
		{
		    document.getElementById("planMainDivId").style.display = "block";
		    document.getElementById("circle").style.display = "none";
		    
		    var circle = document.getElementById("circleArea").value;
		    var opCode = document.getElementById("List1").value;
		    if(opCode == 1){
		        var op = "Airtel";
		    }else if(opCode == 2){
		        var op = "Idea";
		    }else if(opCode == 3 || opCode == 4){
		        var op = "BSNL";
		    }else if(opCode == 7){
		        var op = "Vodafone";
		    }else if(opCode == 10){
		        var op = "Jio";
		    }
		    
		    
		    var xmlhttpState = new XMLHttpRequest();
			xmlhttpState.open("GET","ajax_plan_api.php?circle="+circle+"&op="+op, false)
			xmlhttpState.send(null);
			document.getElementById("planMainDivId").innerHTML = xmlhttpState.responseText;
		}
        
        function hidePlanDiv()
        {   
            var divCondition = document.getElementById("planMainDivId").style.display = "none";
        }
        
        function showPlanDiv2()
        {
            var divCondition = document.getElementById("planMainDivId");
            divCondition.style.display = "block";
        }
        
        function showRecordDiv(Arg)
        {
            var btnNum = Arg;
        
            for(let i = 1; i < 10; i++)
            {
                var divId = "planRecordDiv"+i;
                var btnId = "btn"+i;
                
                if (i === btnNum)
                {
                    var showDiv = document.getElementById(divId).style.display = "block";
                    var showDiv = document.getElementById(btnId).style.background = "green";
                    var showDiv = document.getElementById(btnId).style.color = "white";
                }
                else
                {
                    var hideDiv = document.getElementById(divId).style.display = "none";
                    var showDiv = document.getElementById(btnId).style.background = "white";
                    var showDiv = document.getElementById(btnId).style.color = "black";
                }
            }

        }
        
        
        
         function useAmt(Arg)
         {
             var Amount = Arg;
             hidePlanDiv();
             hideOfferDiv();
             document.getElementById("AmtInput").value = Amount;

         }
        
    </script>
    
        <div id="speOfferDiv">
            This Is Special offer Div
        </div>
    <div id="circle">
        <select id="circleArea" onchange="showPlanDiv()" size="20">
            <option>Chennai</option>
            <option>Delhi NCR</option>
            <option>Gujarat</option>
            <option>Haryana</option>
            <option>Himachal Pradesh</option>
            <option>Jammu Kashmir</option>
            <option>Karnataka</option>
            <option>Kerala</option>
            <option>Kolkata</option>
            <option>Madhya Pradesh Chhattisgarh</option>
            <option>Maharashtra Goa</option>
            <option>Mumbai</option>
            <option>North East</option>
            <option>Orissa</option>
            <option>Punjab</option>
            <option>Rajasthan</option>
            <option>Tamil Nadu</option>
            <option>UP East</option>
            <option>UP West</option>
            <option>West Bengal</option>
        </select>
    </div>
	<div class="planMainDiv" id="planMainDivId">
	</div>
	<!--Header Divison-->
	<?php
		require'header.php';
	?>
	
	<!--Container Division-->
	<div class="container">
		<?php
			include'menu.php';
			if(isset($_POST['submit1']))
	        {
		        $opOwnCode = $_POST['op1'];
		        include'recharge_code.php';
	        }
	        elseif(isset($_POST['submit2']))
	        {
		        $opOwnCode = $_POST['op2'];
		        include'recharge_code.php';
	        }
	        elseif(isset($_POST['submit3']))
	        {
		        $opOwnCode = $_POST['op3'];
		        include'recharge_code.php';
	        }
		?>
		<div class="content">
			<div class="head">
				<div class="title"><p>Dashboard :-</p></div>
				<div class="msg"><marquee><?php include'msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
			    <script>
			        function serviceType(Arg)
			        {
			            if(Arg==1)
			            {
			                document.getElementById("prepaid").style.background = "lime";
			                document.getElementById("dth").style.background = "white";
			                document.getElementById("postpaid").style.background = "white";
			                
			                document.getElementById("List1").style.display = "inline";
			                document.getElementById("List2").style.display = "none";
			                document.getElementById("List3").style.display = "none";
			                
			                document.getElementById("sbmt1").style.display = "inline";
			                document.getElementById("sbmt2").style.display = "none";
			                document.getElementById("sbmt3").style.display = "none";
			                
			                speOfferLink();
			                showPlanLink();
			            }
			            else if(Arg==2)
			            {
			                document.getElementById("prepaid").style.background = "white";
			                document.getElementById("dth").style.background = "lime";
			                document.getElementById("postpaid").style.background = "white";
			                
			                document.getElementById("List1").style.display = "none";
			                document.getElementById("List2").style.display = "inline";
			                document.getElementById("List3").style.display = "none";
			                
			                document.getElementById("sbmt1").style.display = "none";
			                document.getElementById("sbmt2").style.display = "inline";
			                document.getElementById("sbmt3").style.display = "none";
			                
			                document.getElementById("SpeOff").style.display = "none";
			                document.getElementById("planlink1").style.display = "none";
			            }
			            else if(Arg==3)
			            {
			                document.getElementById("prepaid").style.background = "white";
			                document.getElementById("dth").style.background = "white";
			                document.getElementById("postpaid").style.background = "lime";
			                
			                document.getElementById("List1").style.display = "none";
			                document.getElementById("List2").style.display = "none";
			                document.getElementById("List3").style.display = "inline";
			                
			                document.getElementById("sbmt1").style.display = "none";
			                document.getElementById("sbmt2").style.display = "none";
			                document.getElementById("sbmt3").style.display = "inline";
			                
			                document.getElementById("SpeOff").style.display = "none";
			                document.getElementById("planlink1").style.display = "none";
			            }   
			            
			        }
			    </script>
				<form method="post">
					<div class="div1">
					    <br><b>My Wallet Balance : 
					        <?php
					            if($usrBal<500){
					                $bId="BalRed";
					            }else{
					                $bId="BalGreen";
					           }
					           echo "<b id='".$bId."'><i class='fa fa-inr'></i> ".number_format($usrBal, 2)."</b>" ?>
					     </b><br><br>
					    <div class="subdiv1">
					        <button type="button" name="service" id="prepaid" onclick='serviceType(1)'><i class="fa fa-mobile"></i> PREPAID</button>
					        <button type="button" name="service" id="dth"  onclick='serviceType(2)'><i class="fa fa-television"></i> DTH</button>
					        <button type="button" name="service" id="postpaid"  onclick='serviceType(3)'><i class="fa fa-mobile"></i> POSTPAID</button>
					    </div>
						    <select name="op1" id="List1" onchange="showPlanLink(1), speOfferLink()">
						        <option>--Select Operator--</option>
						    <?php
						        $quGetRet="SELECT * FROM operator WHERE Serviceid='1' AND Active='0'";
						        $reGetRet=mysqli_query($con,$quGetRet);
						        while($dataGetRet=mysqli_fetch_array($reGetRet))
						        {
						            if($dataGetRet['OwnApiCode']!=31 && $dataGetRet['OwnApiCode']!=32)
						            {
						                echo "<option value='".$dataGetRet['OwnApiCode']."'>".$dataGetRet['Operator']."</option>";
						            }
						        }
						        
						        
						    ?>
						</select>
						    <select name="op2" id="List2" onchange="showPlanLink(2)">
						        <option>--Select Operator--</option>
						    <?php
						        $quGetRet="SELECT * FROM operator WHERE Serviceid='2' AND Active='0'";
						        $reGetRet=mysqli_query($con,$quGetRet);
						        while($dataGetRet=mysqli_fetch_array($reGetRet))
						        {
						            echo "<option value='".$dataGetRet['OwnApiCode']."'>".$dataGetRet['Operator']."</option>";
						        }
						        
						        
						    ?>
						</select>
						    <select name="op3" id="List3" onchange="showPlanLink(3)">
						        <option>--Select Operator--</option>
						    <?php
						        $quGetRet="SELECT * FROM operator WHERE Serviceid='3' AND Active='0'";
						        $reGetRet=mysqli_query($con,$quGetRet);
						        while($dataGetRet=mysqli_fetch_array($reGetRet))
						        {
						            echo "<option value='".$dataGetRet['OwnApiCode']."'>".$dataGetRet['Operator']."</option>";
						        }
						        
						        
						    ?>
						</select>
						<input type="number" name="mobileNo1" placeholder="Enter Mobile/DTH Number..." id="mobile1" onkeyup="speOfferLink()">
						<input type="number" name="mobileNo2" placeholder="Confirm Mobile/DTH Number..." id="mobile2" onkeyup="speOfferLink()">
						<input type="number" name="amount" id="AmtInput" placeholder="Enter Amount...">
						<input type="submit" Action="recharge_code.php" id="sbmt1" name="submit1" value="Recharge Now"  onclick='showLoader()'>
						<input type="submit" Action="recharge_code.php" id="sbmt2" name="submit2" value="Recharge Now"  onclick='showLoader()'>
						<input type="submit" Action="recharge_code.php" id="sbmt3" name="submit3" value="Recharge Now"  onclick='showLoader()'>
						<a id="SpeOff" onclick="showSpeOfferDiv()">Special Offer</a>   <a onclick="showCircleDiv()" id="planlink1">View Plan</a> 
					</div>
				</form>
				<div class="div1">
					<center><h1>Recent Transaction</h1></center><hr>
					<table cellpadding="20" border="2">
						<tr>
							<th>Order Id</th>
							<th>Discription</th>
							<th>Status</th>
						</tr>
						<?php
							$quGetTxn="SELECT * FROM recharge WHERE Userid='$userid' ORDER BY Id DESC LIMIT 10";
							$reGetTxn=mysqli_query($con,$quGetTxn);
							while($dataGetTxn=mysqli_fetch_array($reGetTxn))
							{
								if($dataGetTxn['Status']=="FAILED")
								{
									$color="red";
								}
								elseif($dataGetTxn['Status']=="SUCCESS")
								{
									$color="green";
								}
								else
								{
									$color="blue";
								}
								echo "<tr>";
									echo "<td>".$dataGetTxn['Id']."</td>";
									echo "<td>".$dataGetTxn['Mobile']." - ".$dataGetTxn['Companyname']." - <i class='fa fa-inr'></i>".$dataGetTxn['Amount']." - ".$dataGetTxn['Operatorid']."</td>";
									echo "<td><p id='".$color."'>".$dataGetTxn['Status']."</p></td>";
								echo "</tr>";
							}
						?>
					</table>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>