<!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 Panel</title>
  <meta content="" name="description">
  <meta content="" name="keywords">

  <!-- Favicons -->
  <link href="assets/img/logo/logo22222.png" rel="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>

  <!-- ======= Header ======= -->
  <?php include 'element/header.php'; ?>
  <!-- ======= Sidebar ======= -->
    <?php      include 'element/sidebar.php' ;      ?>

  <main id="main" class="main">

    <div class="pagetitle">
      <h1>Dashboard</h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="index.html">Home</a></li>
          <li class="breadcrumb-item active">Dashboard</li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

    <section class="section dashboard">
      <div class="row">

        <!-- Left side columns -->
        <div class="col-lg-8">
          <div class="row">

            <!-- Sales Card -->
            <div class="col-xxl-4 col-md-6">
              <div class="card info-card sales-card">

                <div class="card-body"> 
                    <?php
                                         $user_data=mysqli_fetch_array(mysqli_query($conn,"SELECT count(user_id) total_user FROM `users`"));
                 
                                        ?>
                    
                  <h5 class="card-title">Users <span>| Total</span></h5>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-cart"></i>
                    </div>
                    <div class="ps-3">
                      <h6><?php echo $user_data['total_user'] ?></h6>
                      

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

              </div>
            </div><!-- End Sales Card -->

            <!-- Revenue Card -->
            <div class="col-xxl-4 col-md-6">
              <div class="card info-card revenue-card">

                

                <div class="card-body">
                  <h5 class="card-title">Downline <span></span></h5>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-menu-button-wide"></i>
                    </div>
                    <div class="ps-3">
                      <h6><?php echo $user_data['total_user'] ?></h6>
                      

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

              </div>
            </div>
              
              <div class="col-xxl-4 col-md-6">
              <div class="card info-card sales-card">

                <div class="card-body"> 
                    <?php
                                    $user_data=mysqli_fetch_array(mysqli_query($conn,"SELECT count(user_id) total_user FROM `users` WHERE `status`='0'"));
                                  ?>
                    
                  <h5 class="card-title">Active Users</h5>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-cart"></i>
                    </div>
                    <div class="ps-3">
                      <h6><?php echo $user_data['total_user'] ?></h6>
                      

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

              </div>
            </div><!-- End Sales Card -->

            <!-- Revenue Card -->
            <div class="col-xxl-4 col-md-6">
              <div class="card info-card revenue-card">
<?php
                                    $user_data=mysqli_fetch_array(mysqli_query($conn,"SELECT count(user_id) total_user FROM `users` WHERE `status`='1'"));
                                  ?>
                

                <div class="card-body">
                  <h5 class="card-title">Blocked User <span></span></h5>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-menu-button-wide"></i>
                    </div>
                    <div class="ps-3">
                      <h6><?php echo $user_data['total_user'] ?></h6>
                      

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

              </div>
            </div><!-- End Revenue Card -->

            <!-- End Sales Card -->

            <!-- Revenue Card -->
            <div class="col-xxl-4 col-md-6">
              <div class="card info-card revenue-card">
<?php
                                      $user_data=mysqli_fetch_array(mysqli_query($conn,"SELECT sum(no_of_pair) total_pair FROM `pair_count` WHERE `status`='1'"));
                                     ?>

                <div class="card-body">
                  <h5 class="card-title">1Total Paid Pair <span></span></h5>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-menu-button-wide"></i>
                    </div>
                    <div class="ps-3">
                      <h6><?php echo $user_data['total_pair'] ?></h6>
                      

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

              </div>
            </div><!-- End Revenue Card -->

            <!-- End Sales Card -->

            <!-- Revenue Card -->
            <div class="col-xxl-4 col-md-6">
              <div class="card info-card revenue-card">
<?php
                                      $user_data=mysqli_fetch_array(mysqli_query($conn,"SELECT count(pin_value) total_pin FROM `pin`"));
                                     ?>

                <div class="card-body">
                  <h5 class="card-title">1Total Pin <span></span></h5>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-menu-button-wide"></i>
                    </div>
                    <div class="ps-3">
                      <h6><?php echo $user_data['total_pin'] ?></h6>
                      

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

              </div>
            </div><!-- End Revenue Card -->
            
              <div class="col-xxl-4 col-md-6">
              <div class="card info-card sales-card">

                <div class="card-body"> 
                  <?php
                                      $user_data=mysqli_fetch_array(mysqli_query($conn,"SELECT count(pin_value) total_pin FROM `pin` WHERE `status`='0'"));
                                     ?>
                    
                  <h5 class="card-title">Total Unused Pin</h5>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-cart"></i>
                    </div>
                    <div class="ps-3">
                      <h6><?php echo $user_data['total_pin'] ?></h6>
                      

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

              </div>
            </div><!-- End Sales Card -->

            <!-- Revenue Card -->
            <div class="col-xxl-4 col-md-6">
              <div class="card info-card revenue-card">
 <?php
                                      $user_data=mysqli_fetch_array(mysqli_query($conn,"SELECT count(pin_value) total_pin FROM `pin` WHERE `status`='1'"));
                                     ?>

                <div class="card-body">
                  <h5 class="card-title">1Total Used Pin <span></span></h5>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-menu-button-wide"></i>
                    </div>
                    <div class="ps-3">
                      <h6><?php echo $user_data['total_pin'] ?></h6>
                      

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

              </div>
            </div>
              <div class="col-xxl-4 col-md-6">
              <div class="card info-card sales-card">

                <div class="card-body"> 
                  <?php
                                      $user_data=mysqli_fetch_array(mysqli_query($conn,"SELECT sum(amt) total_amt FROM `witdrawl` WHERE `status`='1'"));
                                     ?>
                    
                  <h5 class="card-title">Total Transfer Amount</h5>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-cart"></i>
                    </div>
                    <div class="ps-3">
                      <h6><?php echo $user_data['total_amt'] ?></h6>
                      

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

              </div>
            </div><!-- End Sales Card -->

            <!-- Revenue Card -->
            <!-- End Revenue Card -->
            <!-- Customers Card -->
            <div class="col-xxl-4 col-xl-12">

              <div class="card info-card customers-card">

                

                <div class="card-body">
                  <h5 class="card-title">Direct Customers <span></span></h5>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-people"></i>
                    </div>
                    <div class="ps-3">
                      <h6><?php echo mysqli_num_rows(mysqli_query($conn,"SELECT * FROM `users` WHERE `sponsor_id`='$my_id'")) ?></h6>
                   

                    </div>
                  </div>

                </div>
              </div>

            </div><!-- End Customers Card -->

            <!-- Reports -->
            <div class="col-12">
              <div class="card">

                <div class="card-body">
                  <h5 class="card-title">Reports <span></span></h5>

                  <!-- Line Chart -->
                  <div id="reportsChart"></div>

                  <script>
                    document.addEventListener("DOMContentLoaded", () => {
                      new ApexCharts(document.querySelector("#reportsChart"), {
                        series: [{
                          name: 'Income',
                          data: [10, , , , , , <?php echo $user_data['wallet'] ?>],
                        }, {
                          name: 'Downline',
                          data: [10, , , , , , <?php echo $user_data['left_count']+$user_data['right_count'] ?>]
                        }, {
                          name: 'Direct Customers',
                          data: [10 ,, , ,, , <?php echo mysqli_num_rows(mysqli_query($conn,"SELECT * FROM `users` WHERE `sponsor_id`='$my_id'")) ?>]
                        }],
                        chart: {
                          height: 350,
                          type: 'area',
                          toolbar: {
                            show: false
                          },
                        },
                        markers: {
                          size: 4
                        },
                        colors: ['#4154f1', '#2eca6a', '#ff771d'],
                        fill: {
                          type: "gradient",
                          gradient: {
                            shadeIntensity: 1,
                            opacityFrom: 0.3,
                            opacityTo: 0.4,
                            stops: [0, 90, 100]
                          }
                        },
                        dataLabels: {
                          enabled: false
                        },
                        stroke: {
                          curve: 'smooth',
                          width: 2
                        },
                        tooltip: {
                          x: {
                            format: 'dd/MM/yy HH:mm'
                          },
                        }
                      }).render();
                    });
                  </script>
                  <!-- End Line Chart -->

                </div>

              </div>
            </div><!-- End Reports -->

            <!-- Recent Sales -->
            <div class="col-12">
              <div class="card recent-sales overflow-auto">
<?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="card-body">
                  <h5 class="card-title">Recent Sales <span></span></h5>

                  <table class="table table-borderless datatable">
                    <thead>
                      <tr>
                        <th scope="col">#</th>
                        <th scope="col">Customer Name</th>
                        <th scope="col">User Id</th>
                        <th scope="col">Phone No.</th>
                        <th scope="col">Status</th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr>
                          <?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)) {
                                                                      ?>
                        <th scope="row"><a href="#"><?php echo $a; ?></a></th>
                        <td><?php echo $user_detail['name'] ?></td>
                        <td><a href="#" class="text-primary"><?php echo $user_detail['user_id'] ?></a></td>
                        <td><span>+91 </span><?php echo $user_detail['mobile'] ?></td>
                        <td><a href="level.php?user_id=<?php echo $user_detail['user_id'] ?>"><span class="badge bg-success">Downline</span></a></td>
                      </tr>
                     <?php
                                                                      ++$a;
                                                                    }
                                                                  } else {
                                                                    ?> <tr>
                                                                      <td colspan="4" class="text-center"> Data Not Available</td>
                                                                    </tr> <?php
                                                                  }
                                                                ?>
                    </tbody>
                  </table>

                </div>

              </div>
            </div><!-- End Recent Sales -->

          </div>
        </div><!-- End Left side columns -->

        <!-- Right side columns -->
        <div class="col-lg-4">

          <!-- Recent Activity -->
          <div class="card">
            <div class="filter">
              <a class="icon" href="#" data-bs-toggle="dropdown"><i class="bi bi-three-dots"></i></a>
              <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                <li class="dropdown-header text-start">
                  <h6>Filter</h6>
                </li>

                <li><a class="dropdown-item" href="#">Today</a></li>
                <li><a class="dropdown-item" href="#">This Month</a></li>
                <li><a class="dropdown-item" href="#">This Year</a></li>
              </ul>
            </div>

            <div class="card-body">

              <h5 class="card-title">Downline <span></span></h5>

              <div class="activity">
<?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)) {
                                                                      ?>
                <div class="activity-item d-flex">
                  <div class="activite-label"><?php echo $a; ?></div>
                  <i class='bi bi-circle-fill activity-badge text-success align-self-start'></i>
                  <div class="activity-content">
                  <?php echo $user_detail['name'] ?> <br><a href="#" class="fw-bold text-dark"><?php echo $user_detail['user_id'] ?></a>
                  </div>
                </div><!-- End activity item-->
           <?php
                                                                      ++$a;
                                                                    }
                                                                  } else {
                                                                    ?> <tr>
                                                                      <td colspan="4" class="text-center"> Data Not Available</td>
                                                                    </tr> <?php
                                                                  }
                                                                ?>
              </div>

            </div>
          </div><!-- End Recent Activity -->

          <!-- Website Traffic -->
          <div class="card">
        
            <div class="card-body pb-0">
              <h5 class="card-title">Sale Reports <span></span></h5>

              <div id="trafficChart" style="min-height: 400px;" class="echart"></div>

              <script>
                document.addEventListener("DOMContentLoaded", () => {
                  echarts.init(document.querySelector("#trafficChart")).setOption({
                    tooltip: {
                      trigger: 'item'
                    },
                    legend: {
                      top: '5%',
                      left: 'center'
                    },
                    series: [{
                      name: 'Access From',
                      type: 'pie',
                      radius: ['40%', '70%'],
                      avoidLabelOverlap: false,
                      label: {
                        show: false,
                        position: 'center'
                      },
                      emphasis: {
                        label: {
                          show: true,
                          fontSize: '18',
                          fontWeight: 'bold'
                        }
                      },
                      labelLine: {
                        show: false
                      },
                      data: [{
                          value: <?php echo $user_data['wallet'] ?>,
                          name: 'Income'
                        },
                        {
                          value: <?php echo $user_data['left_count']+$user_data['right_count'] ?>,
                          name: 'Downline'
                        },
                        {
                          value: <?php echo mysqli_num_rows(mysqli_query($conn,"SELECT * FROM `users` WHERE `sponsor_id`='$my_id'")) ?>,
                          name: 'Customers'
                        }
                      ]
                    }]
                  });
                });
              </script>

            </div>
          </div><!-- End Website Traffic -->

         

        </div><!-- End Right side columns -->

      </div>
    </section>

  </main><!-- End #main -->

  <!-- ======= Footer ======= -->
  <footer id="footer" class="footer">
    <div class="copyright">
      &copy; Copyright <strong><span>Healthy Life Mission</span></strong>. All Rights Reserved
    </div>
    <div class="credits">
      <!-- All the links in the footer should remain intact. -->
      <!-- You can delete the links only if you purchased the pro version. -->
      <!-- Licensing information: https://bootstrapmade.com/license/ -->
      <!-- Purchase the pro version with working PHP/AJAX contact form: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/ -->
      Designed by <a href="https://antiradiationchip.in/">Healthy Life Mission</a>
    </div>
  </footer><!-- End 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>

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

</body>

</html>