<?php

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

	require_once('includes/API_Config.php');
    
	$obj = new API_Config;
	$data = array();
	$data['referID'] = $_SESSION['refer_id'];
	$response = json_decode($obj->call_API("API_network_list2.php", $data), true);
	$data_list = $response['data'];
	$srNo =0;

	//var_dump($data_list);


?>

			<div class="card">
            <div class="card-body">
              <h4 class="card-title">My Network</h4>
              <div class="row">
                <div class="col-12 table-responsive">
                  <table id="order-listing" class="table">
                    <thead>
                      <tr>
                          <th>Sr No.</th>
                          <th>Member Name</th>
                          <th>Member ID</th>
                          <th>Joining Date</th>
                          <th>Purchased PV</th>
                      </tr>
                    </thead>
                    <tbody>
					<?php if(!empty($data_list)): ?>
					<?php foreach($data_list as $list):?>
						<?php //getNetworkList($list); ?>
						<tr class="odd gradeX">
						<td><?php echo ++$srNo; ?>
						<td><?php echo ucwords($list['name'].' '.$list['last_name']); ?></td>
						<td><?php echo $list['refer_id'] ?></td>
						<td><?php echo isset($list['date_entered']) ? $list['date_entered'] : 'N.A' ?></td>
						<td><?php echo isset($list['total_PV']) ? $list['total_PV'] : 0 ?></td>
						
						</tr>
						<?php if(!empty($list['d']))
								viewData($list['d']); ?>
					   
					<?php endforeach; ?> 
					
					<?php endif; ?>
					 <?php  
							function viewData($binaryList)
						{
							global $srNo;;

							for($i=0; $i<count($binaryList);$i++)
							{
								echo "<tr>";
								echo "<td>" . ++$srNo . "</td>";

								echo "<td>" .  ucwords($binaryList[$i]['name'] . " " . $binaryList[$i]['last_name']) . "</td>";
								echo "<td>" .  $binaryList[$i]['refer_id'] . "</td>";
								
								echo "<td>";
								echo isset($binaryList[$i]['date_entered']) ? $binaryList[$i]['date_entered']  :'N.A';
								echo "</td>";

								echo "<td>";
								echo isset($binaryList[$i]['total_PV']) ? $binaryList[$i]['total_PV'] : 0;
								echo "</td>";

																
								if(isset($binaryList[$i]['d']))
									viewData($binaryList[$i]['d']);
							}


						}
						?>


                      
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
          </div>


<?php
	include 'footer.php';
?>