<?php

	include 'header.php';
	include 'navbar.php';

	require_once('../../panel/includes/API_Config.php');

	$obj = new API_Config;
	$data = array();
	$data['refer_id'] = '233791797';
	$details = "";


	if(!empty($_SESSION['treeID']))
	{
		
		//$data['tree_from_refer_id'] = $_SESSION['treeID'];
		$data['refer_id'] = $_SESSION['treeID'];

		//$details = json_decode(callAPI("API_blockbooster_tree_v3.php?","referID=". $_SESSION['refer_id'] . "&tree_from_refer_id=". $_SESSION['treeID'])); 
		//$details2 = json_decode(callAPI("API_blockbooster_check_refer_id.php?","refer_id=" . $_SESSION['treeID']));
		$details = json_decode($obj->call_API("API_tree.php", $data));

		if($details->status==0)
		{
			if(!empty($_SESSION['treeID']))
			//echo $_SESSION['treeID'];
			unset($_SESSION['treeID']);
			echo "<script type=\"text/javascript\">alert(\" User not found in your network.\");location.reload();</script>";
		}
		
	}

	else
	{
		$details = json_decode($obj->call_API("API_tree.php", $data));
		//$details = json_decode($obj->call_API("API_tree.php", $data));

	}
	

	
?>

     
	<div class= "row">
	    <div class="col-md-12 grid-margin stretch-card">
          <div class="card">
            <div class="card-body">
				<div class="row">
					<div class="col-md-3 col-md-offset-2">	
						<div class="form-group chart-search-box">
							<div class="input-group">
							  <input type="text" class="form-control" placeholder="Search User ID" id="txtUserID" required />
							  <div class="input-group-append bg-primary border-primary">
								<button id="btnSearch" class="bg-primary border-primary" type="submit"><span class="input-group-btn"><i class="mdi mdi-magnify text-white"></i></span></button>
							  </div>
							</div>
						</div>
					</div>
					<div class="col-md-2">
						 <a href="member-tree.php"><button class="btn btn-primary btn-rounded btn-fw" style="width: 60px;">TOP</button></a>
					</div>
				</div>

				<section class="management-hierarchy">
					<div class="hv-container">
					  	<div class="hv-wrapper">
							<!-- Key component -->
							<div class="hv-item">

								<div class="hv-item-parent">
									<?php if(!empty($_SESSION['treeID'])){?><a href="javascript:void(0)"><img class="tree_up_icon" id="<?php echo $_SESSION['treeID'];?>" src="../images/up.png" width="16px" height="16px"/></a><?php }?>
									
									<div class="person">
										
										<a href="javascript:void(0)">
										<?php if($details->personal_info->total_token){ if($details->personal_info->booster) echo "<img src=\"../images/booster.png\"";
										else echo "<img src=\"../images/active-icon.png\"";} else echo "<img src=\"../images/inactive-icon.png\""; ?> id="<?php echo $details->personal_info->refer_id ?>" alt="" data-toggle="tooltip" data-html="true" data-placement="bottom" title="" data-original-title="<table><tbody><tr><td><strong>Name:</strong></td><td><?php echo ucwords($details->personal_info->name);?></td></tr><tr><td><strong>User ID:</strong></td><td><?php echo $details->personal_info->refer_id;?></td></tr><tr><td><strong>Purchase:</strong></td><td><?php echo $details->personal_info->total_token?></td></tr><tr><td><strong>Purchase PV:</strong></td><td><?php echo $details->personal_info->total_pv?></td></tr><tr><td><strong>Left PV:</strong></td><td><?php echo $details->personal_info->left_node_token?></td></tr><tr><td><strong>Right PV:</strong></td><td><?php echo $details->personal_info->right_node_token?></td></tr> </tbody></table>">
										</a>				
										<p class="name">
											 <?php if(!empty($_SESSION['treeID'])) echo $_SESSION['treeID']; else echo "You";?>
										</p>



									</div>
									



								</div>

								<div class="hv-item-children">
								<?php

								if(!empty($details->data))
								{	
									
									if($details->data[0]->right_node==1)
									{
									
										 if(count($details->data)==1)
										 {
											if(!empty($_SESSION['treeID']))
											{
												echo "<div class=\"hv-item-child\"><div class=\"person\"><a href=\"javascript:void(0)\"><img src=\"../images/add.png\" class=\"add\" leg=\"left\" id=\"" .	$_SESSION['treeID'] . "\" alt=\"\" type=1></a><p class=\"name\">No Member</p></div></div>";
											}

											else
											{
												echo "<div class=\"hv-item-child\"><div class=\"person\"><a href=\"javascript:void(0)\"><img src=\"../images/add.png\" class=\"add\" leg=\"left\" id=\"" .	$_SESSION['refer_id'] . "\" alt=\"\" type=1></a><p class=\"name\">No Member</p></div></div>";
											}
										 
										 }
										  
										  for($i=count($details->data); $i>0; $i--)
											{
											   if(!empty($details->data[$i-1]->d))
												{
													echo "<div class=\"hv-item-child\"><div class=\"hv-item\"><div class=\"hv-item-parent\">									<div class=\"person\"><a href=\"javascript:void(0)\">";

													if($details->data[$i-1]->total_bb_token)
													{
														echo "<img src=\"../images/active-icon.png\"";
													}
													else
														echo "<img src=\"../images/inactive-icon.png\"";
													
													echo " class=\"listTree\" id=\"". $details->data[$i-1]->refer_id . "\"alt=\"\"  data-toggle=\"tooltip\" data-html=\"true\" data-placement=\"top\" title=\"\"	data-original-title=\"<table><tbody><tr><td><strong>Name:</strong></td><td>" . ucwords($details->data[$i-1]->name) .			"</td></tr><tr><td><strong>User ID:</strong></td><td>". $details->data[$i-1]->refer_id ."</td></tr><tr><td><strong>Purchase:</strong></td><td>" .  $details->data[$i-1]->total_bb_token . "</td></tr><td><strong>Purchase PV:</strong></td><td>". $details->data[$i-1]->total_pv . "</td></tr><tr><td><strong>Left PV:</strong></td><td>" .  $details->data[$i-1]->left_node_token . "</td></tr><tr><td><strong>Right PV:</strong></td><td>" .  $details->data[$i-1]->right_node_token . "</td></tr></tbody></table>\"></a><p class=\"name\">" . $details->data[$i-1]->refer_id . "</p></div></div><div 	class=\"hv-item-children\">";
													showChild2($details->data[$i-1]->d);
													echo "</div></div>";
												}

												else
												{
													echo "<div class=\"hv-item-child\"><div class=\"person\"><a href=\"javascript:void(0)\">";
													
													
													if($details->data[$i-1]->total_bb_token)
													{
														echo "<img src=\"../images/active-icon.png\"";
													}

													else
														echo "<img src=\"../images/inactive-icon.png\"";
													 
													echo " class=\"listTree\" id=\"" .	$details->data[$i-1]->refer_id . "\" alt=\"\" data-toggle=\"tooltip\" data-html=\"true\" data-placement=\"top\"	title=\"\" data-original-title=\"<table><tbody><tr><td><strong>Name:</strong></td><td>" . ucwords($details->data[$i-1]->name) . "</td></tr><tr><td><strong>User ID:</strong></td><td>". $details->data[$i-1]->refer_id ."</td></tr><tr><td><strong>Purchase:</strong></td><td>" .  $details->data[$i-1]->total_bb_token . "</td></tr><td><strong>Purchase PV:</strong></td><td>". $details->data[$i-1]->total_pv . "</td></tr><tr><td><strong>Left PV:</strong></td><td>" .  $details->data[$i-1]->left_node_token . "</td></tr><tr><td><strong>Left PV:</strong></td><td>" .  $details->data[$i-1]->right_node_token . "</td></tr></tbody></table>\"></a><p class=\"name\">" . $details->data[$i-1]->refer_id . "</p></div></div>";
												}
												
												
											}

									}

									else
									{
										
										for($i=0; $i<count($details->data); $i++)
										{
											if(!empty($details->data[$i]->d))
											{
												echo "<div class=\"hv-item-child\"><div class=\"hv-item\"><div class=\"hv-item-parent\"><div class=\"person\"><a href=\"javascript:void(0)\">";									
												
												if($details->data[$i]->total_bb_token)
												{
													echo "<img src=\"../images/active-icon.png\"";
												}

												else
													echo "<img src=\"../images/inactive-icon.png\"";
													
												echo " class=\"listTree\"  id=\"". $details->data[$i]->refer_id  ."\" alt=\"\" data-toggle=\"tooltip\" data-html=\"true\" data-placement=\"top\" title=\"\" data-original-title=\"<table><tbody><tr><td><strong>Name:</strong></td><td>" . ucwords($details->data[$i]->name) .				 "</td></tr><tr><td><strong>User ID:</strong></td><td>". $details->data[$i]->refer_id ."</td></tr><tr><td><strong>Purchase:</strong></td><td>" .  $details->data[$i]->total_bb_token . "</td></tr><td><strong>Purchase PV:</strong></td><td>". $details->data[$i]->total_pv . "</td></tr><tr><td><strong>Left PV:</strong></td><td>" .  $details->data[$i]->left_node_token . "</td></tr><tr><td><strong>Right PV:</strong></td><td>" .  $details->data[$i]->right_node_token . "</td></tr></tbody></table>\"></a><p class=\"name\">" .	$details->data[$i]->refer_id . "</p></div></div><div class=\"hv-item-children\">";
												showChild2($details->data[$i]->d);
												echo "</div></div>";

											}


											else 
											{
												echo "<div class=\"hv-item-child\"><div class=\"person\"><a href=\"javascript:void(0)\">";
												
												if($details->data[$i]->total_bb_token)
												{
													echo "<img src=\"../images/active-icon.png\"";
												}

												else
													echo "<img src=\"../images/inactive-icon.png\"";

												echo " class=\"listTree\"  id=\"".	 $details->data[$i]->refer_id   ."\" alt=\"\"  data-toggle=\"tooltip\" data-html=\"true\" data-placement=\"top\" title=\"\"	data-original-title=\"<table><tbody><tr><td><strong>Name:</strong></td><td>" . ucwords($details->data[$i]->name) .	"</td></tr><tr><td><strong>User ID:</strong></td><td>". $details->data[$i]->refer_id ."</td></tr><tr><td><strong>Purchase:</strong></td><td>" .  $details->data[$i]->total_bb_token . "</td></tr><td><strong>Purchase PV:</strong></td><td>". $details->data[$i]->total_pv . "</td></tr><tr><td><strong>Left PV:</strong></td><td>" .  $details->data[$i]->left_node_token . "</td></tr><tr><td><strong>Right PV:</strong></td><td>" .  $details->data[$i]->right_node_token . "</td></tr></tbody></table>\"></a>       <p class=\"name\">" . $details->data[$i]->refer_id . "</p></div></div>";
											}
										

										}

										
										 if(count($details->data)==1)
										 {

											if(!empty($_SESSION['treeID']))
											{
												echo "<div class=\"hv-item-child\"><div class=\"person\"><a href=\"javascript:void(0)\"><img src=\"../images/add.png\" class=\"add\" leg=\"right\" id=\"" .	$_SESSION['treeID'] . "\" alt=\"\" type=1></a><p class=\"name\">No Member</p></div></div>";
											}

											else
											{
												echo "<div class=\"hv-item-child\"><div class=\"person\"><a href=\"javascript:void(0)\"><img src=\"../images/add.png\" class=\"add\" leg=\"right\" id=\"" .	$_SESSION['refer_id'] . "\" alt=\"\" type=1></a><p class=\"name\">No Member</p></div></div>";
											}

										 }
										

									}


								}
								
								
								else
								{
									if(!empty($_SESSION['treeID']))
									{
										echo "<div class=\"hv-item-child\"><div class=\"person\"><a href=\"javascript:void(0)\"><img src=\"../images/add.png\" class=\"add\" leg=\"left\" id=\"".	$_SESSION['treeID']   ."\" alt=\"\" type=1></a><p class=\"name\">Add Here</p></div></div>";

										echo "<div class=\"hv-item-child\"><div class=\"person\"><a href=\"javascript:void(0)\"><img src=\"../images/add.png\" class=\"add\" leg=\"right\" id=\"".	$_SESSION['treeID']   ."\" alt=\"\" type=1></a><p class=\"name\">No Member</p></div></div>";
									}

									else
									{
										echo "<div class=\"hv-item-child\"><div class=\"person\"><a href=\"javascript:void(0)\"><img src=\"../images/add.png\" class=\"add\" leg=\"left\" id=\"".	$_SESSION['refer_id']   ."\" alt=\"\" type=1></a><p class=\"name\">No Member</p></div></div>";

										echo "<div class=\"hv-item-child\"><div class=\"person\"><a href=\"javascript:void(0)\"><img src=\"../images/add.png\" class=\"add\" leg=\"right\" id=\"".	$_SESSION['refer_id']   ."\" alt=\"\" type=1></a><p class=\"name\">No Member</p></div></div>";

									}
								}






								function showChild2($childRow)
								{
									
									if(!empty($childRow))
									{

										if($childRow[0]->right_node==1)
										{

											if(count($childRow)==1)
											{
												echo "<div class=\"hv-item-child\"><div class=\"person\"><a href=\"javascript:void(0)\"><img src=\"../images/add.png\" class=\"add\" leg=\"left\" id=\"". $childRow[0]->refer_id  ."\" alt=\"\" type=2></a><p class=\"name\">No Member</p></div></div>";
											}
									
											for($i=count($childRow);$i>0;$i--)
											{

												if(!empty($childRow[$i-1]->d))
												{
													echo "<div class=\"hv-item-child\"><div class=\"hv-item\"><div class=\"hv-item-parent\"><div class=\"person\"><a href=\"javascript:void(0)\">";
													
													if($childRow[$i-1]->total_bb_token)
													{
														echo "<img src=\"../images/active-icon.png\"";
													}
													else
														echo "<img src=\"../images/inactive-icon.png\"";

													echo " class=\"listTree\"  id=\"" .  $childRow[$i-1]->refer_id   . "\" alt=\"\" data-toggle=\"tooltip\" data-html=\"true\" data-placement=\"top\" title=\"\"									data-original-title=\"<table><tbody><tr><td><strong>Name:</strong></td><td>" . ucwords($childRow[$i-1]->name) .				"</td></tr><tr><td><strong>User ID:</strong></td><td>". $childRow[$i-1]->refer_id . "</td></tr><tr><td><strong>Purchase:</strong></td><td>" . $childRow[$i-1]->total_bb_token . "</td></tr><td><strong>Purchase PV:</strong></td><td>".	  $childRow[$i-1]->total_pv . "</td></tr><tr><td><strong>Left PV:</strong></td><td>" .  $childRow[$i-1]->left_node_token . "</td></tr><tr><td><strong>Right PV:</strong></td><td>" .  $childRow[$i-1]->right_node_token . "</td></tr></tbody></table>\"></a><p class=\"name\">" .	$childRow[$i-1]->refer_id . "</p></div></div><div class=\"hv-item-children\">";
													showChild2($childRow[$i-1]->d);
													echo "</div></div>";
												}


												else
												{
													echo "<div class=\"hv-item-child\"><div class=\"person\"><a href=\"javascript:void(0)\">";

													if($childRow[$i-1]->total_bb_token)
													{
														echo "<img src=\"../images/active-icon.png\"";
													}

													else
														echo "<img src=\"../images/inactive-icon.png\"";
													
													echo " class=\"listTree\"  id=\"" . $childRow[$i-1]->refer_id . "\" alt=\"\" data-toggle=\"tooltip\" data-html=\"true\" data-placement=\"top\" title=\"\" data-original-title=\"<table><tbody><tr><td><strong>Name:</strong></td><td>" . ucwords($childRow[$i-1]->name) .	"</td></tr><tr><td><strong>User ID:</strong></td><td>". $childRow[$i-1]->refer_id . "</td></tr><tr><td><strong>Purchase:</strong></td><td>" .  $childRow[$i-1]->total_bb_token . "</td></tr><td><strong>Purchase PV:</strong></td><td>".	  $childRow[$i-1]->total_pv . "</td></tr><tr><td><strong>Left PV:</strong></td><td>" .  $childRow[$i-1]->left_node_token . "</td></tr><tr><td><strong>Right PV:</strong></td><td>" .  $childRow[$i-1]->right_node_token . "</td></tr></tbody></table>\"></a><p class=\"name\">" . $childRow[$i-1]->refer_id . "</p></div></div>";

												}

											}

										
										}

										else
										{
																			

										
											for($i=0;$i<count($childRow);$i++)
											{
												
												if(!empty($childRow[$i]->d))
												{
													echo "<div class=\"hv-item-child\"><div class=\"hv-item\"><div class=\"hv-item-parent\"><div class=\"person\"><a href=\"javascript:void(0)\">";

													if($childRow[$i]->total_bb_token)
													{
														echo "<img src=\"../images/active-icon.png\"";
													}

													else
														echo "<img src=\"../images/inactive-icon.png\"";
													
													echo " class=\"listTree\"  id=\"" . $childRow[$i]->refer_id . "\" alt=\"\" data-toggle=\"tooltip\" data-html=\"true\" data-placement=\"top\" title=\"\"										data-original-title=\"<table><tbody><tr><td><strong>Name:</strong></td><td>" . ucwords($childRow[$i]->name) .					"</td></tr><tr><td><strong>User ID:</strong></td><td>". $childRow[$i]->refer_id . "</td></tr><tr><td><strong>Purchase:</strong></td><td>" .  $childRow[$i]->total_bb_token . "</td></tr><td><strong>Purchase PV:</strong></td><td>".	  $childRow[$i]->total_pv . "</td></tr><tr><td><strong>Left PV:</strong></td><td>" .  $childRow[$i]->left_node_token . "</td></tr><tr><td><strong>Right PV:</strong></td><td>" .  $childRow[$i]->right_node_token . "</td></tr></tbody></table>\"></a><p class=\"name\">" . $childRow[$i]->refer_id . "</p></div></div><div class=\"hv-item-children\">";
													showChild2($childRow[$i]->d);
													echo "</div></div>";
												}


												else
												{
													echo "<div class=\"hv-item-child\"><div class=\"person\"><a href=\"javascript:void(0)\">";

													if($childRow[$i]->total_bb_token)
													{
														echo "<img src=\"../images/active-icon.png\"";
													}
													else
														echo "<img src=\"../images/inactive-icon.png\"";
													
													echo " class=\"listTree\" id=\"". $childRow[$i]->refer_id ."\" alt=\"\" data-toggle=\"tooltip\" data-html=\"true\" data-placement=\"top\" title=\"\" data-original-title=\"<table><tbody><tr><td><strong>Name:</strong></td><td>" . ucwords($childRow[$i]->name) . "</td></tr><tr><td><strong>User ID:</strong></td><td>". $childRow[$i]->refer_id . "</td></tr><tr><td><strong>Purchase:</strong></td><td>" .  $childRow[$i]->total_bb_token . "</td></tr><td><strong>Purchase PV:</strong></td><td>".	  $childRow[$i]->total_pv . "</td></tr><tr><td><strong>Left PV:</strong></td><td>" .  $childRow[$i]->left_node_token . "</td></tr><tr><td><strong>Right PV:</strong></td><td>" .  $childRow[$i]->right_node_token . "</td></tr></tbody></table>\"></a><p class=\"name\">".	$childRow[$i]->refer_id . "</p></div></div>";

												}

											}

											if(count($childRow)==1)
											{
												echo "<div class=\"hv-item-child\"><div class=\"person\"><a href=\"javascript:void(0)\"><img src=\"../images/add.png\" class=\"add\" leg=\"right\" id=\"".	$childRow[0]->refer_id  ."\" alt=\"\" type=2></a><p class=\"name\">No Member</p></div></div>";
											}



										}


									}

									echo "</div>";

								}



							?>
										  

								</div>
							</div>
						</div>
					</div>
				</section>

				<form name="frmTree" id="frmTree" method="POST" action="includes/changetreeview.php" enctype="multipart/form-data" autocomplete=false hidden>
					<div class="form-group">
						<div class="row">
							<div class="col-5">
								<input type="text" class="form-control" name="txtNextID" id="txtNextID" required>
							</div>
							<div class="col-7">
								<input type="text" class="form-control" name="txtPrevID" id="txtPrevID" readonly>
							</div>
						</div>
					</div>
				</form>

		</div>
		</div>
		<div>
    </div>
    </div>

</div>

<?php

	include 'footer.php';

	if(!empty($_SESSION['treeID']))
	{
		//echo $_SESSION['treeID'];
		unset($_SESSION['treeID']);
	}


?>


 <script type="text/javascript">


				$(function () {
					$('[data-toggle="tooltip"]').tooltip()
				})

				
				/*$(".add").click(function(){
					 window.top.location.href = "includes/addNode.php?txtType=" + $(this).attr('type') + "&txtMemberID=" + $(this).attr('id') + "&txtLeg=" +  $(this).attr('leg');
				});*/

			    $(".listTree").click(function(){
					$("#txtNextID").val($(this).attr('id'));
					$("#frmTree").submit();
				});

				$(".tree_up_icon").click(function(){
					$("#txtPrevID").val($(this).attr('id'));
					$("#frmTree").submit();
				});

				$("#btnSearch").click(function(){
                   
				    var memberID = $("#txtUserID").val();

     				if($.isNumeric(memberID))
					{
						$("#txtNextID").val(memberID);
						$("#frmTree").submit();
	
					}

				});

				


	//window.top.location.href = 'index.html';
</script>
