<?php include("../Header/Session.php"); ?>
<?php include("../Header/Connection.php"); ?>

<!DOCTYPE html>
<html lang="en">

<body class="skin-default fixed-layout">

<!-- Main wrapper - style you can find in pages.scss -->
<div id="main-wrapper">    




<!-- Include This MLM CSS to this page only -->
<link rel="stylesheet" href="../Assets/css/style_mlm_view.css" type="text/css" media="all">

	<?php
	$agent_id = $_GET['agent_id'];
	if ($agent_id != "")
	{
	    $user_id = $agent_id;
	}


	$sql = "SELECT *
	FROM user 
	where status='1'
	ORDER BY sponsor_id";
	$result = mysqli_query($conn, $sql) or die("database error:". mysqli_error($conn));
	// Create an array to conatin a list of items and parents
	$menus = array
	(
		'items' => array(),
		'sponsor_ids' => array()
	);
	// Builds the array lists with data from the SQL result
	while ($items = mysqli_fetch_assoc($result)) 
	{
		// Create current menus item id into array
		$menus['items'][$items['id']] = $items;
		// Creates list of all items with children
		$menus['sponsor_ids'][$items['sponsor_id']][] = $items['id'];
	}
	?>
	
	<?php
	$sql_user = "SELECT * FROM user 
	WHERE id='$user_id'
	And status='1'";
	$result_user = $mysqli-> query($sql_user);
	if ($result_user -> num_rows > 0)
	{
		$row_user = $result_user ->fetch_assoc();
		$ref_code = $row_user['ref_code'];
		$type_of_user = $row_user['type_of_user'];
		$name = $row_user['name'];
	}
	?>

	<span style='background-color:#212529;color:white;padding-left:10px;padding-right:10px;padding-top:10px;padding-bottom:10px;border-radius:25px;'>
	<font size="3px"><?php echo $ref_code; ?> | <?php echo $name; ?> | <?php echo $type_of_user; ?> 
	<!--a href="add_new_user.php?sponsor_code=<?php echo $ref_code; ?>"><font color='white'>Register</font></a--></span><br><br>
	<font size="1px"><a href="team_geonology.php"> Back To Normal Mode</a></font>
	<?php 
	// Print all tree view menus 
	echo createTreeView($user_id, $menus);
	?>			
</div>


<?php
// function to create dynamic treeview menus
function createTreeView($sponsor_id, $menu) 
{
   $html = "";
   if (isset($menu['sponsor_ids'][$sponsor_id])) 
   {
      $html .= "
      <ol class='tree'>";
       foreach ($menu['sponsor_ids'][$sponsor_id] as $itemId) 
	   {
          
          if(isset($menu['sponsor_ids'][$itemId]))
		  {
             $html .= "
             <li style='background-color:#212529;color:white;padding-left:25px;padding-right:10px;padding-top:10px;padding-bottom:10px;border-radius:25px;' >
			 <label for='subfolder2'><font size='7px'>
			 &nbsp; Rank: ".$menu['items'][$itemId]['type_of_user']."
			 | Package: ".$menu['items'][$itemId]['package_type']."
			 | Member ID: ".$menu['items'][$itemId]['ref_code']."
			 | Email: ".$menu['items'][$itemId]['email']."
			 | Tel No: ".$menu['items'][$itemId]['phone_number']."
			 | Join Date: ".$menu['items'][$itemId]['created_date']."
			  <!--a href='add_new_user.php?sponsor_code=".$menu['items'][$itemId]['ref_code']."'><font color='white'>Register</font></a-->
			 | <a href='team_geonology.php?agent_id=".$menu['items'][$itemId]['id']."'><font color='white'>View More</font></a>
			 </font></label>
			 <input type='checkbox' name='subfolder2'/>";
             $html .= createTreeView($itemId, $menu);
             $html .= "</li>";
          }
		  if(!isset($menu['sponsor_ids'][$itemId])) 
		  {
             $html .= "<li style='background-color:#212529;color:white;padding-left:10px;padding-right:10px;padding-top:10px;padding-bottom:5px;border-radius:25px;' >
			 <label for='subfolder2'><font size='7px'>
			  &nbsp; Rank: ".$menu['items'][$itemId]['type_of_user']."
			 | Package: ".$menu['items'][$itemId]['package_type']."
			 | Member ID: ".$menu['items'][$itemId]['ref_code']."
			 | Email: ".$menu['items'][$itemId]['email']."
			 | Tel No: ".$menu['items'][$itemId]['phone_number']."
			 | Join Date: ".$menu['items'][$itemId]['created_date']."
			 | <a href='add_new_user.php?sponsor_code=".$menu['items'][$itemId]['ref_code']."'><font color='white'>Register</font></a>
			 | <!--a href='team_geonology.php?agent_id=".$menu['items'][$itemId]['id']."'><font color='white'>View More</font></a-->
			 </font></label>
			 <input type='checkbox' name='subfolder2'/>
			 </li>";
          }
       }
       $html .= "</ol>";
   }
   return $html;
}
?>



</div>
</div>                      
</div>
</div>
<!-- ============================================================== -->
<!-- End PAge Content -->

</div>
<!-- End Container fluid  -->
</div>
<!-- End Page wrapper  -->

</div>
<!-- End Wrapper -->
<!-- All Jquery -->
    

<!-- All Jquery Start-->
<?php include ("../Header/all_jquery.php"); ?>
<!-- All Jquery End-->

</body>

</html>