<?php
	include'connection.php';
	$downlineUsr = $_GET['downlineUsr'];
	$userid = $_GET['usrid'];
	
    function getUserData($usr)
    {
        include'connection.php';
        $quGetName="SELECT * FROM user WHERE Userid='$usr'";
        $reGetName=mysqli_query($con,$quGetName);
        $dataGetName=mysqli_fetch_array($reGetName);
        
        return $dataGetName;
    }
	echo"<table cellpadding='20' border='2'> 
		<tr>
			<th>Sl.</th>
			<th>Join Date</th>
			<th>Userid</th>
			<th>Name</th>
			<th>Mobile No.</th>
			<th>City</th>
			<th>Sponsor</th>
			<th>Parent</th>
			<th>Level</th>
		</tr>";
	if($downlineUsr=="All")
	{
	    $quDownline="SELECT * FROM user WHERE SponserId='$userid'";
	}
	else
	{
	    $quDownline="SELECT * FROM user WHERE $downlineUsr='$userid' AND SponserId='$userid'";
	}
	$reDownline=mysqli_query($con,$quDownline);
	$countDownline=mysqli_num_rows($reDownline);
	if($countDownline>0)
	{   
	    $sl=0;
	    while($dataDownline=mysqli_fetch_array($reDownline))
	    {
		    $sl=$sl+1;
			if($dataDownline['Parent1']==$userid){
				$level = "Level 1";
			}elseif($dataDownline['Parent2']==$userid){
				$level = "Level 2";
			}elseif($dataDownline['Parent3']==$userid){
				$level = "Level 3";
			}elseif($dataDownline['Parent4']==$userid){
				$level = "Level 4";
			}elseif($dataDownline['Parent5']==$userid){
				$level = "Level 5";
			}elseif($dataDownline['Parent6']==$userid){
				$level = "Level 6";
			}elseif($dataDownline['Parent7']==$userid){
				$level = "Level 7";
			}elseif($dataDownline['Parent8']==$userid){
				$level = "Level 8";
			}
									
			$sponserData=getUserData($dataDownline['SponserId']);
			$parentData=getUserData($dataDownline['Parent1']);
									
			echo "<tr>";
				echo "<td>".$sl."</td>";
				echo "<td>".$dataDownline['Date']."</td>";
				echo "<td>".$dataDownline['Userid']."</td>";
				echo "<td>".$dataDownline['Name']."</td>";
				echo "<td>".$dataDownline['Mobile']."</td>";
				echo "<td>".$dataDownline['District']."</td>";
				echo "<td>".$sponserData['Name']."</td>";
				echo "<td>".$parentData['Name']."</td>";
				echo "<td>".$level."</td>";
			echo "</tr>";
	    }
	}
	else
	{
		echo "<tr><td colspan='9'><p style='color:red;'>Data Not Found !</p></td></tr>";
	}
?>	
	<script>
	    hideLoader();
	</script>