<!doctype html>
<html lang="en">
<?php
  include_once("../element/connection.php");
 ?>





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

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>Life X - Your Downline</title>
  <meta content="" name="description">
  <meta content="" name="keywords">

  <!-- Favicons -->
  <link href="assets/img/favicon.png" rel="icon">
  <link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">

  <!-- Google Fonts -->
  <link href="https://fonts.gstatic.com" rel="preconnect">
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">

  <!-- Vendor CSS Files -->
  <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
  <link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
  <link href="assets/vendor/quill/quill.snow.css" rel="stylesheet">
  <link href="assets/vendor/quill/quill.bubble.css" rel="stylesheet">
  <link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">
  <link href="assets/vendor/simple-datatables/style.css" rel="stylesheet">

  <!-- Template Main CSS File -->
  <link href="assets/css/style.css" rel="stylesheet">

  <!-- =======================================================
  * Template Name: NiceAdmin - v2.3.1
  * Template URL: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/
  * Author: BootstrapMade.com
  * License: https://bootstrapmade.com/license/
  ======================================================== -->
</head>

<body>
    
    <?php include 'element/header.php'; ?>
<?php include 'element/sidebar.php'; ?>
    
    <div class="dashboard-main-wrapper">

        <?php
        include_once("element/sidebar.php");
         ?>

        <main id="main" class="main">
        
         <div class="pagetitle">
      <h1>Dashboard</h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="pin.php">View Pin</a></li>
          <li class="breadcrumb-item active">Epin</li>
        </ol>
      </nav>
    </div>
        
            <div class="dashboard-main-wrapper">

	    <?php
      include_once("element/sidebar.php");
       ?>

	    <div class="dashboard-wrapper">
	        <div class="dashboard-influence">
	            <div class="container-fluid dashboard-content">
                <?php
                if (isset($_REQUEST['user_id'])) {
                  $level_sponsor=$_REQUEST['user_id'];
                  if (check_my_downline($level_sponsor,$my_id)) {
                    // code...
                  }else {
                    $level_sponsor=$my_id;
                  }
                } else {
                  $level_sponsor=$my_id;
                }

                 ?>
                  <div class="row">
                            <div class="col-md-12">


                                                 <div class="main-card mb-3 card">
                                                     <div class="card-header"></div>
                                                     <div class="table-responsive">
                                                         <table class="align-middle mb-0 table table-borderless table-striped table-hover">
                                                            <thead>
                                                             <tr>
                                                                 <th class="text-center">#</th>
                                                                 <th class="text-center">Name</th>
                                                                 <th class="text-center">Mobile</th>
                                                                 <th></th>
                                                             </tr>
                                                            </thead>
                                                            <tbody>
                                                              <?php
                                                                $data=mysqli_query($conn,"SELECT * FROM `users` WHERE `sponsor_id`='$level_sponsor'");
                                                                  $a=1;
                                                                  if (mysqli_num_rows($data)>0) {
                                                                    while ($user_detail=mysqli_fetch_array($data)) {
                                                                      ?><tr><td class="text-center text-muted"><?php echo $a; ?></td>
                                                                      <td class="text-center">
                                                                          <div class="widget-content p-0">
                                                                              <div class="widget-content-wrapper">
                                                                                  <div class="widget-content-left flex2">
                                                                                      <div class="widget-heading">
                                                                                        <?php echo $user_detail['name'] ?>
                                                                                      </div>
                                                                                      <div class="widget-subheading opacity-7"><?php echo $user_detail['user_id'] ?></div>
                                                                                  </div>
                                                                              </div>
                                                                          </div>
                                                                      </td>
                                                                      <td class="text-center"><?php echo $user_detail['mobile'] ?></td>
                                                                      <td class="text-center"> <a href="level.php?user_id=<?php echo $user_detail['user_id'] ?>">Downline</a> </td>
                                                                      </tr><?php
                                                                      ++$a;
                                                                    }
                                                                  } else {
                                                                    ?> <tr>
                                                                      <td colspan="4" class="text-center"> Data Not Available</td>
                                                                    </tr> <?php
                                                                  }
                                                                ?>


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




                            </div>
                  </div>

	                    <script src="assets/vendor/jquery/jquery-3.3.1.min.js"></script>
	                    <!-- bootstap bundle js -->
	                    <script src="assets/vendor/bootstrap/js/bootstrap.bundle.js"></script>
	                    <!-- slimscroll js -->
	                    <script src="assets/vendor/slimscroll/jquery.slimscroll.js"></script>
	                    <!-- main js -->
	                    <script src="assets/libs/js/main-js.js"></script>
	                    <!-- morris-chart js -->
	                    <script src="assets/vendor/charts/morris-bundle/raphael.min.js"></script>
	                    <script src="assets/vendor/charts/morris-bundle/morris.js"></script>
	                    <script src="assets/vendor/charts/morris-bundle/morrisjs.html"></script>
	                    <!-- chart js -->
	                    <script src="assets/vendor/charts/charts-bundle/Chart.bundle.js"></script>
	                    <script src="assets/vendor/charts/charts-bundle/chartjs.js"></script>
	                    <!-- dashboard js -->
	                    <script src="assets/libs/js/dashboard-influencer.js"></script>

                      <?php
                        function check_my_downline($user_id,$login_id){
                          global $conn;
                          $data=mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM `users` WHERE `user_id`='$user_id'"));
                          $spons_id=$data['sponsor_id'];
                          while ($spons_id!=0) {
                            if ($spons_id==$login_id) {
                              return true;
                            } else {
                              $data=mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM `users` WHERE `user_id`='$spons_id'"));
                              $spons_id=$data['sponsor_id'];
                            }
                          }
                          if ($spons_id==0) {
                            return false;
                          }
                        }
                       ?>
        
        </main>
    </div>
    
    
    
    

  <!-- ======= Footer ======= -->
  
  <a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>

  <!-- Vendor JS Files -->
  <script src="assets/vendor/apexcharts/apexcharts.min.js"></script>
  <script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="assets/vendor/chart.js/chart.min.js"></script>
  <script src="assets/vendor/echarts/echarts.min.js"></script>
  <script src="assets/vendor/quill/quill.min.js"></script>
  <script src="assets/vendor/simple-datatables/simple-datatables.js"></script>
  <script src="assets/vendor/tinymce/tinymce.min.js"></script>
  <script src="assets/vendor/php-email-form/validate.js"></script>
    <!-- Optional JavaScript -->
    <script src="assets/vendor/jquery/jquery-3.3.1.min.js"></script>
    <script src="assets/vendor/bootstrap/js/bootstrap.bundle.js"></script>
    <script src="assets/vendor/slimscroll/jquery.slimscroll.js"></script>
    <script src="assets/vendor/multi-select/js/jquery.multi-select.js"></script>
    <script src="assets/libs/js/main-js.js"></script>
    <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
    <script src="assets/vendor/datatables/js/dataTables.bootstrap4.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script>
    <script src="assets/vendor/datatables/js/buttons.bootstrap4.min.js"></script>
    <script src="assets/vendor/datatables/js/data-table.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.colVis.min.js"></script>
    <script src="https://cdn.datatables.net/rowgroup/1.0.4/js/dataTables.rowGroup.min.js"></script>
    <script src="https://cdn.datatables.net/select/1.2.7/js/dataTables.select.min.js"></script>
    <script src="https://cdn.datatables.net/fixedheader/3.1.5/js/dataTables.fixedHeader.min.js"></script>

  <!-- Template Main JS File -->
  <script src="assets/js/main.js"></script>

</body>

</html>