<?php
include 'include/db.php';
error_reporting(0);

$top=$_REQUEST['root_id'];

//$top='B00001';
//   fetch top left & top right through top id
$qry1="select * from tree_data where position_id='$top' ";
//$qry1="select * from tree_data inner join registration on tree_data.position_id=registration.unique_user_id where tree_data.position_id='$top' ";
$con1=mysqli_query($conn,$qry1);
if(mysqli_num_rows($con1)>0)
{
    while($rw1=mysqli_fetch_array($con1))
    {
       $top_left=$rw1['position_left'];
       $top_right=$rw1['position_right'];
    }
}
 
//   fetch top left left & top left right
$qry2="select * from tree_data where position_id='$top_left' ";
$con2=mysqli_query($conn,$qry2);
if(mysqli_num_rows($con2)>0)
{
    while($rw2=mysqli_fetch_array($con2))
    {
       $top_left_left=$rw2['position_left'];
       $top_left_right=$rw2['position_right'];
    }
}

//   fetch top right left & top right right
$qry3="select * from tree_data where position_id='$top_right' ";
$con3=mysqli_query($conn,$qry3);
if(mysqli_num_rows($con3)>0)
{
    while($rw3=mysqli_fetch_array($con3))
    {
       $top_right_left=$rw3['position_left'];
       $top_right_right=$rw3['position_right'];
    }
}
   
/*******************************/

    //  function call to get the user details
    $top1=get_top_chiled($top);
    $t1=get_top_chiled($top_left);
    $t2=get_top_chiled($top_right);
    $t11=get_top_chiled($top_left_left);
     $t21=get_top_chiled($top_left_right);
     $t111=get_top_chiled($top_right_left);
     $t211=get_top_chiled($top_right_right);
    
    function get_top_chiled($val)
           {
               include 'include/db.php';
                $slt_active="select * from registration inner join wallet_balance on registration.unique_user_id=wallet_balance.balance_user_id where registration.unique_user_id='$val'";
                $con23=mysqli_query($conn,$slt_active);
                if(mysqli_num_rows($con23))
                {
                    while($rw11=mysqli_fetch_array($con23))
                    {
                        return $rw11['user_name']. '+' .str_replace('+','- ',$rw11['user_address']). '+' .str_replace('+',' ',$rw11['user_mobile']). '+' .$rw11['gender']. '+' .$rw11['dob']. '+' .$rw11['position']. '+' .$rw11['refferance_id']. '+' .$rw11['created_date']. '+' .$rw11['active_deactive']. '+' .$rw11['rank']. '+' .$rw11['bv_balance'] ; 
                    }
                }
           }
           
          //  explode all registration tables details from function return 
          $a=explode('+',$top1);
          $a1=explode('+',$t1);
          $a2=explode('+',$t2);
          $a11=explode('+',$t11);
          $a12=explode('+',$t21);
          $a21=explode('+',$t111);
          $a22=explode('+',$t211);
/*echo '<pre>';       
print_r($a);
die;*/
?>
		<!----  top  ------>
		<div class="" style="width: 100%">
				<div class="" style="">
					<p align="center">
					    <?php
    					if(!EMPTY($top) && $top!='no user')
    					{
    					    $date=explode(' ',$a['7']);
    					    if($a['8'] != 1)
    					    {
    					        
    					?>
    					  <a class="xx" id="<?php echo $top; ?>"  onmouseover="Tip(&#39;Name : <?php echo $a['0']?> &lt;BR&gt;&lt;BR&gt; Gender : <?php echo $a['3']?> &lt;BR&gt;&lt;BR&gt; Date of Joining : <?php echo $date['0']?>  &#39;)" onmouseout="UnTip()" style="text-decoration: none; cursor: pointer; cursor: pointer" ?="">
    						<img border="0" src="tree_image/5.png">   <!---  no purchase[yellow color]   ---->
    					  </a><br>
    						 <?php echo $top; ?><br>
    						<?php echo $a['0'];?><br>
    					   <img border="0" src="tree_image/first.png" width="50%" height="90">   <!---  tree image   ---->
    					<?php
    					    }
    					    else
    					    {
    					?>
    					    <a class="xx" id="<?php echo $top; ?>"  onmouseover="Tip(&#39;Name : <?php echo $a['0']?> &lt;BR&gt;&lt;BR&gt; Gender : <?php echo $a['3']?> &lt;BR&gt;&lt;BR&gt; Date of Joining : <?php echo $date['0']?>  &#39;)" onmouseout="UnTip()" style="text-decoration: none; cursor: pointer; cursor: pointer" ?="">
    						<img border="0" src="tree_image/1.png">     <!---  purchased[red color]   ---->
    					  </a><br>
    						<?php echo $top;?><br>
    						<?php echo $a['0'];?><br>
    					   <img border="0" src="tree_image/first.png" width="50%" height="90">  
    					<?php
    					    }
    					}
    					else
    					{
    					?>
    					    <a onmouseover="Tip(&#39; None &#39;)" onmouseout="UnTip()" style="text-decoration: none; cursor: pointer; cursor: pointer" ?="">
    						<img border="0" src="tree_image/0.png">      <!---  no user image   ---->
    					  </a><br>
    						<?php echo $top;?><br>
    						<?php echo $a['0'];?><br>
    					   <img border="0" src="tree_image/first.png" width="50%" height="90">
    					<?php
    					}
    					?>
					</p>
				</div>
			</div>
			<!----  top left   ---->
			<div class="" style="width: 100%">
			   <?php
				if(!EMPTY($top_left))
				{
				    $date=explode(' ',$a1['7']);
				    if($a1['8'] !=1 )
				    {
				?>
    				<div class="" style="float: left; text-align: center; width: 50%">
    					<a class="xx" id="<?php echo $top_left; ?>"  onmouseover="Tip(&#39;Name : <?php echo $a1['0']?> &lt;BR&gt;&lt;BR&gt; Gender : <?php echo $a1['3']?> &lt;BR&gt;&lt;BR&gt; Date of Joining : <?php echo $date['0']?>  &#39;)" onmouseout="UnTip()" style="text-decoration: none;cursor: pointer" ?="">
    						<img border="0" src="tree_image/5.png">
    					</a><br>
    					<?php echo $top_left;?><br>
    					<?php echo $a1['0'];?><br>
    					<img border="0" src="tree_image/second.png" width="89%" height="75"> 	
    				</div>
    			<?php
				    }
				    else
				    {
    			?>
				    <div class="" style="float: left; text-align: center; width: 50%">
    					<a class="xx" id="<?php echo $top_left; ?>"  onmouseover="Tip(&#39;Name : <?php echo $a1['0']?> &lt;BR&gt;&lt;BR&gt; Gender : <?php echo $a1['3']?> &lt;BR&gt;&lt;BR&gt; Date of Joining : <?php echo $date['0']?>  &#39;)" onmouseout="UnTip()" style="text-decoration: none;cursor: pointer" ?="">
    						<img border="0" src="tree_image/1.png">
    					</a><br>
    					<?php echo $top_left;?><br>
    					<?php echo $a1['0'];?><br>
    					<img border="0" src="tree_image/second.png" width="89%" height="75"> 	
    				</div>
    			<?php
				    }
				}
				else
				{
    			?>
    			    <div class="" style="float: left; text-align: center; width: 50%">
    					<a onmouseover="Tip(&#39; None &#39;)" onmouseout="UnTip()" style="text-decoration: none; cursor: pointer; cursor: pointer">
    						<img border="0" src="tree_image/0.png">
    					</a><br>
    					<?php echo $top_left;?><br>
    					<?php echo $a1['0'];?><br>
    					<img border="0" src="tree_image/second.png" width="89%" height="75"> 	
    				</div>
    			<?php
				}
    			?>
			</div>
	
			
			
			<div class="" style="width: 100%">
				<!---  top right  ---->
				<?php
    				if(!EMPTY($top_right))
    				{
    				    $date=explode(' ',$a2['7']);
    				   if($a2['8'] != 1)
    				    {
				?>
        				<div class="" style="float: left; text-align: center; width: 50%">
        					<a class="xx" id="<?php echo $top_right; ?>"  onmouseover="Tip(&#39;Name : <?php echo $a2['0']?> &lt;BR&gt;&lt;BR&gt; Gender : <?php echo $a2['3']?> &lt;BR&gt;&lt;BR&gt; Date of Joining : <?php echo $date['0']?>  &#39;)" onmouseout="UnTip()" style="text-decoration: none;cursor: pointer" ?="">
    						<img border="0" src="tree_image/5.png">
    					</a><br>
        					<?php echo $top_right;?><br>
        					<?php echo $a2['0'];?><br>
        					<img border="0" src="tree_image/second.png" width="89%" height="75"> 	
        				</div>
        		<?php
    				    }
    				    else
    				    {
        		?>
        		        	<div class="" style="float: left; text-align: center; width: 50%">
        					<a class="xx" id="<?php echo $top_right; ?>"  onmouseover="Tip(&#39;Name : <?php echo $a2['0']?> &lt;BR&gt;&lt;BR&gt; Gender : <?php echo $a2['3']?> &lt;BR&gt;&lt;BR&gt; Date of Joining : <?php echo $date['0']?>  &#39;)" onmouseout="UnTip()" style="text-decoration: none;cursor: pointer" ?="">
    						<img border="0" src="tree_image/1.png">
    					</a><br>
        					<?php echo $top_right;?><br>
        					<?php echo $a2['0'];?><br>
        					<img border="0" src="tree_image/second.png" width="89%" height="75"> 	
        				    </div>
        			<?php
    				    }
    				}
    				else
    				{
        			?>
        			        <div class="" style="float: left; text-align: center; width: 50%">
        					<a onmouseover="Tip(&#39; None &#39;)" onmouseout="UnTip()" style="text-decoration: none; cursor: pointer; cursor: pointer">
        						<img border="0" src="tree_image/0.png">
        					</a><br>
        					<?php echo $top_right;?><br>
        					<?php echo $a2['0'];?><br>
        					<img border="0" src="tree_image/second.png" width="89%" height="75"> 	
        				    </div>
        			<?php
    				}
        			?>
        				
        				
			</div>
			
			<div class="" style="width: 100%">
				<!---  top left left  ---->
				<?php
    				if(!EMPTY($top_left_left))
    				{
    				    $date=explode(' ',$a11['7']);
    				   if($a11['8'] !=1)
    				    {
				?>
        				<div class="" style="float: left; text-align: center; width: 25%">
        					<a class="xx" id="<?php echo $top_left_left; ?>"  onmouseover="Tip(&#39;Name : <?php echo $a11['0']?> &lt;BR&gt;&lt;BR&gt; Gender : <?php echo $a11['3']?> &lt;BR&gt;&lt;BR&gt; Date of Joining : <?php echo $date['0']?>  &#39;)" onmouseout="UnTip()" style="text-decoration: none;cursor: pointer" ?="">
    						<img border="0" src="tree_image/5.png">
    					</a><br>
        					<?php echo $top_left_left;?><br>
        					<?php echo $a11['0'];?><br>
        				</div>
        		<?php
    				    }
    				    else
    				    {
        		?>
        		        	<div class="" style="float: left; text-align: center; width: 25%">
        					<a class="xx" id="<?php echo $top_left_left; ?>"  onmouseover="Tip(&#39;Name : <?php echo $a11['0']?> &lt;BR&gt;&lt;BR&gt; Gender : <?php echo $a11['3']?> &lt;BR&gt;&lt;BR&gt; Date of Joining : <?php echo $date['0']?>  &#39;)" onmouseout="UnTip()" style="text-decoration: none;cursor: pointer" ?="">
    						<img border="0" src="tree_image/1.png">
    					</a><br>
        					<?php echo $top_left_left;?><br>
        						<?php echo $a11['0'];?><br>
        				    </div>
        			<?php
    				    }
    				}
    				else
    				{
        			?>
        			        <div class="" style="float: left; text-align: center; width: 25%">
        					<a onmouseover="Tip(&#39; None &#39;)" onmouseout="UnTip()" style="text-decoration: none; cursor: pointer; cursor: pointer">
        						<img border="0" src="tree_image/0.png">
        					</a><br>
        					<?php echo $top_left_left;?><br>
        						<?php echo $a11['0'];?><br>
        				    </div>
        			<?php
    				}
        			?>
        			
        			<!---  top left right  ---->
				<?php
    				if(!EMPTY($top_left_right))
    				{
    				    $date=explode(' ',$a12['7']);
    				   if($a12['8'] !=1)
    				    {
				?>
        				<div class="" style="float: left; text-align: center; width: 25%">
        					<a class="xx" id="<?php echo $top_left_right; ?>"  onmouseover="Tip(&#39;Name : <?php echo $a12['0']?> &lt;BR&gt;&lt;BR&gt; Gender : <?php echo $a12['3']?> &lt;BR&gt;&lt;BR&gt; Date of Joining : <?php echo $date['0']?>  &#39;)" onmouseout="UnTip()" style="text-decoration: none;cursor: pointer" ?="">
    						<img border="0" src="tree_image/5.png">
    					</a><br>
        					<?php echo $top_left_right;?><br>
        						<?php echo $a12['0'];?><br>
        				</div>
        		<?php
    				    }
    				    else
    				    {
        		?>
        		        	<div class="" style="float: left; text-align: center; width: 25%">
        					<a class="xx" id="<?php echo $top_left_right; ?>"  onmouseover="Tip(&#39;Name : <?php echo $a12['0']?> &lt;BR&gt;&lt;BR&gt; Gender : <?php echo $a12['3']?> &lt;BR&gt;&lt;BR&gt;  Date of Joining : <?php echo $date['0']?>  &#39;)" onmouseout="UnTip()" style="text-decoration: none;cursor: pointer" ?="">
    						<img border="0" src="tree_image/1.png">
    					</a><br>
        					<?php echo $top_left_right;?><br>
        					<?php echo $a12['0'];?><br>
        				    </div>
        			<?php
    				    }
    				}
    				else
    				{
        			?>
        			        <div class="" style="float: left; text-align: center; width: 25%">
        					<a onmouseover="Tip(&#39; None &#39;)" onmouseout="UnTip()" style="text-decoration: none; cursor: pointer; cursor: pointer">
        						<img border="0" src="tree_image/0.png">
        					</a><br>
        					<?php echo $top_left_right;?><br>
        					<?php echo $a12['0'];?><br>
        				    </div>
        			<?php
    				}
        			?>
        			
        			<!---  top right left  ---->
				<?php
    				if(!EMPTY($top_right_left))
    				{
    				    $date=explode(' ',$a21['7']);
    				   if($a21['8'] !=1)
    				    {
				?>
        				<div class="" style="float: left; text-align: center; width: 25%">
        				<a class="xx" id="<?php echo $top_right_left; ?>"  onmouseover="Tip(&#39;Name : <?php echo $a21['0']?> &lt;BR&gt;&lt;BR&gt; Gender : <?php echo $a21['3']?> &lt;BR&gt;&lt;BR&gt;  Date of Joining : <?php echo $date['0']?>  &#39;)" onmouseout="UnTip()" style="text-decoration: none;cursor: pointer" ?="">
    						<img border="0" src="tree_image/5.png">
    					</a><br>
        					<?php echo $top_right_left;?><br>
        					<?php echo $a21['0'];?> <br>
        				</div>
        		<?php
    				    }
    				    else
    				    {
        		?>
        		        	<div class="" style="float: left; text-align: center; width: 25%">
        						<a class="xx" id="<?php echo $top_right_left; ?>"  onmouseover="Tip(&#39;Name : <?php echo $a21['0']?> &lt;BR&gt;&lt;BR&gt; Gender : <?php echo $a21['3']?> &lt;BR&gt;&lt;BR&gt;  Date of Joining : <?php echo $date['0']?>  &#39;)" onmouseout="UnTip()" style="text-decoration: none;cursor: pointer" ?="">
    						<img border="0" src="tree_image/1.png">
    					</a><br>
        					<?php echo $top_right_left;?><br>
        					<?php echo $a21['0'];?><br>
        				    </div>
        			<?php
    				    }
    				}
    				else
    				{
        			?>
        			        <div class="" style="float: left; text-align: center; width: 25%">
        					<a onmouseover="Tip(&#39; None &#39;)" onmouseout="UnTip()" style="text-decoration: none; cursor: pointer; cursor: pointer">
        						<img border="0" src="tree_image/0.png">
        					</a><br>
        					<?php echo $top_right_left;?><br>
        					<?php echo $a21['0'];?><br>
        				    </div>
        			<?php
    				}
        			?>
        			
        				<!---  top right right ---->
				<?php
    				if(!EMPTY($top_right_right))
    				{
    				     $date=explode(' ',$a22['7']);
    				   if($a22['8'] !=1)
    				    {
				?>
        				<div class="" style="float: left; text-align: center; width: 25%">
        					<a class="xx" id="<?php echo $top_right_right; ?>"  onmouseover="Tip(&#39;Name : <?php echo $a22['0']?> &lt;BR&gt;&lt;BR&gt; Gender : <?php echo $a22['3']?> &lt;BR&gt;&lt;BR&gt;  Date of Joining : <?php echo $date['0']?>  &#39;)" onmouseout="UnTip()" style="text-decoration: none;cursor: pointer" ?="">
    						<img border="0" src="tree_image/5.png">
    					</a><br>
        					<?php echo $top_right_right;?><br>
        					<?php echo $a22['0'];?><br>
        				</div>
        		<?php
    				    }
    				    else
    				    {
        		?>
        		        	<div class="" style="float: left; text-align: center; width: 25%">
        						<a class="xx" id="<?php echo $top_right_right; ?>"  onmouseover="Tip(&#39;Name : <?php echo $a22['0']?> &lt;BR&gt;&lt;BR&gt; Gender : <?php echo $a22['3']?> &lt;BR&gt;&lt;BR&gt;  Date of Joining : <?php echo $date['0']?>  &#39;)" onmouseout="UnTip()" style="text-decoration: none;cursor: pointer" ?="">
    						<img border="0" src="tree_image/1.png">
    					</a><br>
        					<?php echo $top_right_right;?><br>
        					<?php echo $a22['0'];?><br>
        				    </div>
        			<?php
    				    }
    				}
    				else
    				{
        			?>
        			        <div class="" style="float: left; text-align: center; width: 25%">
        					<a onmouseover="Tip(&#39; None &#39;)" onmouseout="UnTip()" style="text-decoration: none; cursor: pointer">
        						<img border="0" src="tree_image/0.png">
        					</a><br>
        					<?php echo $top_right_right;?><br>
        					<?php echo $a22['0'];?><br>
        				    </div>
        			<?php
    				}
        			?>
        			
        			
        				
        				
			</div>
			
			
			
				