<?php
session_start();
ob_start();
include('includes/config.php');
if($_SESSION['name'] == '')
 {
     header("location:index.php");
 }
    else{
        
        ?>


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
    	<meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Forcecrypto Admin</title>
        <link rel="stylesheet" href="css/bootstrap.min.css" media="screen" >
        <link rel="stylesheet" href="css/font-awesome.min.css" media="screen" >
        <link rel="stylesheet" href="css/animate-css/animate.min.css" media="screen" >
        <link rel="stylesheet" href="css/lobipanel/lobipanel.min.css" media="screen" >
        <link rel="stylesheet" href="css/prism/prism.css" media="screen" > <!-- USED FOR DEMO HELP - YOU CAN REMOVE IT -->
        <link rel="stylesheet" type="text/css" href="js/DataTables/datatables.min.css"/>
        <link rel="stylesheet" href="css/main.css" media="screen" >
        <script src="js/modernizr/modernizr.min.js"></script>
          <style>
        .errorWrap {
    padding: 10px;
    margin: 0 0 20px 0;
    background: #fff;
    border-left: 4px solid #dd3d36;
    -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
    box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
}
.succWrap{
    padding: 10px;
    margin: 0 0 20px 0;
    background: #fff;
    border-left: 4px solid #5cb85c;
    -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
    box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
}
        </style>
    </head>
    <body class="top-navbar-fixed">
        <div class="main-wrapper">

            <!-- ========== TOP NAVBAR ========== -->
   <?php include('includes/topbar.php');?> 
            <!-- ========== WRAPPER FOR BOTH SIDEBARS & MAIN CONTENT ========== -->
            <div class="content-wrapper">
                <div class="content-container">
<?php include('includes/leftbar.php');?>  

                    <div class="main-page">
                        <div class="container-fluid">
                            <div class="row page-title-div">
                                <div class="col-md-6">
                                    <h2 class="title">Child User</h2>
                                
                                </div>
                                
                                <!-- /.col-md-6 text-right -->
                            </div>
                            <!-- /.row -->
                            <div class="row breadcrumb-div">
                                <div class="col-md-6">
                                    
                                </div>
                             
                            </div>
                            <!-- /.row -->
                        </div>
                        <!-- /.container-fluid -->

                        <section class="section">
                            <div class="container-fluid">

                             

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

                                        <div class="panel">
                                            <div class="panel-heading">
                                                <div class="panel-title">
                                                    
                                                </div>
                                            </div>
<?php if($msg){?>
<div class="alert alert-success left-icon-alert" role="alert">
 <strong>Well done!</strong><?php echo htmlentities($msg); ?>
 </div><?php } 
else if($error){?>
    <div class="alert alert-danger left-icon-alert" role="alert">
                                            <strong>Oh snap!</strong> <?php echo htmlentities($error); ?>
                                        </div>
                                        <?php } ?>
                                            <div class="panel-body p-20">
                                                
                                                
                                <div class="tabbable-responsive">
        <div class="tabbable">
          <ul class="nav nav-tabs" id="myTab" role="tablist">
            <li class="nav-item active">
              <a class="nav-link active" id="first-tab" data-toggle="tab" href="#first" role="tab" aria-controls="first" aria-selected="true">Level 1</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" id="second-tab" data-toggle="tab" href="#second" role="tab" aria-controls="second" aria-selected="false">Level 2</a>
            </li>
            <!--<li class="nav-item">
              <a class="nav-link" id="third-tab" data-toggle="tab" href="#third" role="tab" aria-controls="second" aria-selected="false">Level 3 (0)</a>
            </li>-->
          </ul>
        </div>
      </div>                

                                                   <div class="card-body">
      <div class="tab-content">
        <div class="tab-pane fade show active in" id="first" role="tabpanel" aria-labelledby="first-tab">
          <div class="table-responsive">
              <table id="example" class="display table table-striped table-bordered" cellspacing="0" width="100%">
                <thead>
                  <tr>
                    
                    <th >ID</th>
                    <th >Phone</th>
                     <th scope="col">Commission</th>
                    <th >First Recharge</th>
                     <th >Total Recharge</th>
                    
                  </tr>
                </thead>
                <tbody>
                <?php 
      $userid=$_GET['ID'];
      $user=mysqli_query($com,"select * from `loginuser` where `id`='".$userid."'");
	  $userResult=mysqli_fetch_array($user);
	  $owncode=$userResult['owncode'];
	  $userlevel1=mysqli_query($com,"select * from `loginuser` where `code`='".$owncode."' order by id desc");
	  while($userlevel1Rows=mysqli_fetch_array($userlevel1))
	  {
	  
	  ?>
                  <tr>
                    
                    <td><?php echo $userlevel1Rows['id'];?></td>
                    <td><?php echo $userlevel1Rows['mobile'];?></td>
                    <td>
                    
                    <?php 
                    $id=$userlevel1Rows['id'];
                    $comsql =mysqli_query($com,"select * from  bonussummery  where level1id='$id'");
			        $comsqlResult=mysqli_fetch_array($comsql);
                    echo $comsqlResult['level1amount'];
                    
                    ?>
                    
                    </td>
                    <td>
                    <?php
            $id=$userlevel1Rows['id'];
            $firstrecharge=mysqli_query($com,"select * from  walletsummery  where userid='$id' and actiontype='recharge' and status='1'");
			$firstResult=mysqli_fetch_array($firstrecharge);
			// print_r($firstResult);exit;
            echo number_format($firstResult['amount'],2);
            ?></td>
            <td>
            <?php
            $id=$userlevel1Rows['id'];
            $firstrecharge12=mysqli_query($com,"select * from  walletsummery  where userid='$id' and actiontype='recharge' and status='1'");
            $rechtotalamount=0;
		while($firstResult12=mysqli_fetch_array($firstrecharge12))
		{
		 $rechtotalamount=$rechtotalamount+ $firstResult12['amount'];   
		}
            echo number_format($rechtotalamount,2);
            ?></td>
                    
                  </tr>
             <?php } ?>     
                </tbody>
              </table>
            </div>
        </div>
        
        <div class="tab-pane fade" id="second" role="tabpanel" aria-labelledby="second-tab">
          <div class="table-responsive nb">
              <table id="example1" class="display table table-striped table-bordered" cellspacing="0" width="100%">
                <thead>
                    
                  <tr>
                    
                    <th scope="col">ID</th>
                    <th scope="col">Phone</th>
                     <th scope="col">Commission</th>
                    <th >First Recharge</th>
                     <th >Total Recharge</th>
                    
                  </tr>
                  
                </thead>
                <tbody>
                    <?php 
      $userid=$_GET['ID'];
      $user=mysqli_query($com,"select * from `loginuser` where `id`='".$userid."'");
	  $userResult=mysqli_fetch_array($user);
	  $owncode=$userResult['owncode'];
	  $userlevel1=mysqli_query($com,"select * from `loginuser` where `code`='".$owncode."' order by id desc");
	  while($userlevel1Rows=mysqli_fetch_array($userlevel1))
	  {
	  $owncodeid=$userlevel1Rows['owncode'];
	  $userlevel2=mysqli_query($com,"select * from `loginuser` where `code`='".$owncodeid."' order by id desc");
	  
	  while($userlevel2Rows=mysqli_fetch_array($userlevel2))
	  {
	     
	  ?>
                  <tr>
                   <td><?php echo $userlevel2Rows['id'];?></td>
                    <td><?php echo $userlevel2Rows['mobile'];?></td>
                     <td>
                     <?php 
                    $id2=$userlevel2Rows['id'];
                    $comsql1 =mysqli_query($com,"select * from  bonussummery  where level2id='$id2'");
			        $comsqlResult1=mysqli_fetch_array($comsql1);
                    echo $comsqlResult1['level2amount'];
                    
                    ?></td>
                    <td>
                    <?php
            $id2=$userlevel2Rows['id'];
            $firstrecharge2=mysqli_query($com,"select * from  walletsummery  where userid='$id2' and actiontype='recharge' and status='1'");
			$firstResult2=mysqli_fetch_array($firstrecharge2);
			// print_r($firstResult);exit;
            echo number_format($firstResult2['amount'],2);
            ?></td>
            <td>
                    <?php
            $id2=$userlevel2Rows['id'];
            $firstrecharge2123=mysqli_query($com,"select * from  walletsummery  where userid='$id2' and actiontype='recharge' and status='1'");
			$rechtotalamount123=0;
			while($firstResult2123=mysqli_fetch_array($firstrecharge2123))
			{
			  $rechtotalamount123=$rechtotalamount123+ $firstResult2123['amount'];     
			}
			// print_r($firstResult);exit;
            echo number_format($rechtotalamount123,2);
            ?></td>
                    
                  </tr>
                 <?php } }?>  
                </tbody>
              </table>
            </div>
        </div>
        </div>
        </div>

                                         
                                                <!-- /.col-md-12 -->
                                            </div>
                                        </div>
                                    </div>
                                    <!-- /.col-md-6 -->

                                                               
                                                </div>
                                                <!-- /.col-md-12 -->
                                            </div>
                                        </div>
                                        <!-- /.panel -->
                                    </div>
                                    <!-- /.col-md-6 -->

                                </div>
                                <!-- /.row -->

                            </div>
                            <!-- /.container-fluid -->
                        </section>
                        <!-- /.section -->

                    </div>
                    <!-- /.main-page -->

                    

                </div>
                <!-- /.content-container -->
            </div>
            <!-- /.content-wrapper -->

        </div>
        <!-- /.main-wrapper -->

        <!-- ========== COMMON JS FILES ========== -->
        <script src="js/jquery/jquery-2.2.4.min.js"></script>
        <script src="js/bootstrap/bootstrap.min.js"></script>
        <script src="js/pace/pace.min.js"></script>
        <script src="js/lobipanel/lobipanel.min.js"></script>
        <script src="js/iscroll/iscroll.js"></script>

        <!-- ========== PAGE JS FILES ========== -->
        <script src="js/prism/prism.js"></script>
        <script src="js/DataTables/datatables.min.js"></script>

        <!-- ========== THEME JS ========== -->
        <script src="js/main.js"></script>
        <script>
            $(function($) {
                $('#example').DataTable();

                $('#example2').DataTable( {
                    "scrollY":        "300px",
                    "scrollCollapse": true,
                    "paging":         false
                } );

                $('#example3').DataTable();
            });
        </script>
        <script>
            $(function($) {
                $('#example1').DataTable();

                $('#example2').DataTable( {
                    "scrollY":        "300px",
                    "scrollCollapse": true,
                    "paging":         false
                } );

                $('#example3').DataTable();
            });
        </script>
    </body>
</html>
<?php } ?>

