<?php include("../Header/Session.php"); ?>
<?php include("../Header/Connection.php"); ?>
<?php
$user_activation_status = $_GET['activation_status'];

if ( $user_activation_status == '1')
{
     $Title = "List Of Members";
}
else
if ( $user_activation_status == '0')
{
     $Title = "List of Unactive Members";
}
else
if ( $user_activation_status == '101')
{
     $Title = "List of Unlist Members";
}

?>
<!DOCTYPE html>
<html lang="en">
<?php include ("../Header/head.php"); ?>
<body class="skin-default fixed-layout">

<!-- Main wrapper - style you can find in pages.scss -->
<div id="main-wrapper">    
<?php include ("../Header/header.php"); ?>
<?php include ("../Header/left_menu.php"); ?>
<?php include ("../Header/right_sidebar.php"); ?>
        
<!-- Page wrapper  -->
<div class="page-wrapper">
<!-- Container fluid  -->
<div class="container-fluid">
<!-- Bread crumb and right sidebar toggle -->
<!--?php include ("../Header/breadcumb.php"); ?-->
<br><br>
<!-- End Bread crumb and right sidebar toggle -->
    
    
                
    
<!-- Start Page Content -->
<!-- ============================================================== -->
<div class="row">
<div class="col-12">
    <div class="card">
        <div class="card-body">
            <h4 class="card-title"><?php echo $Title; ?></h4>
            <h6 class="card-subtitle">Export data to Copy, CSV, Excel, PDF & Print</h6>
            <div class="table-responsive m-t-40">
                <form method="post" action="../Controller/Database_sql.php" enctype="multipart/form-data">
                <table id="example23"
                    class="display nowrap table table-hover table-striped table-bordered"
                    cellspacing="0" width="100%">
                    <thead>
                        <tr>
                            <th>Action</th>
                            <th>ID</th>
                            <th>Member ID</th>
                            <th>Sponsor ID</th>
                            <th>Total Investment</th>
                            <?php
                            if ($user_activation_status == '1')
                            {
                            ?>
                                <th>Level 1 Group Sale</th>
                                <th>Total Group Sale</th>
                            <?php
                            }
                            ?>
                            <th>Name</th>
                            <th>Email</th>
                            <th>Phone Number</th>
                            <th>Verification Status</th>
                            <th>Registered Date</th>   
                        </tr>
                    </thead>                                      
                    <tbody>
                        <?php       
                        if ($level == '1')
                        {
                            if ($user_activation_status == '0')
                            {
                                //Find user that not being activate yet
                                $sql_user = "SELECT * 
						        FROM user
                                Where level ='2'
                                And status = '1'
                                And activation_status = '$user_activation_status'
						        order by id Desc";
						    }
                            else if ($user_activation_status == '1')
                            {
                                $sql_user = "SELECT * 
						        FROM user
                                Where level ='2'
                                And status = '1'
                                And activation_status = '$user_activation_status'
						        order by id Desc";
						    }
                            else if ($user_activation_status == '101')
                            {
                                $sql_user = "SELECT * 
						        FROM user
                                Where level ='2'
                                And status = '0'
                                And activation_status = '0'
						        order by id Desc";
						    }
						}
                        else
                        {
                            if ( $user_activation_status == '0')
                            {
                                //Find user that not being activate yet
                                $sql_user = "SELECT * 
						        FROM user
                                Where sponsor_code = '$ref_code'
                                And level ='2'
                                And status = '1'
                                And activation_status = '$user_activation_status'
						        order by id Desc";
						    }
                            else
                            {
                                $sql_user = "SELECT * 
						        FROM user
                                Where sponsor_code = '$ref_code'
                                And level ='2'
                                And status = '1'
                                And activation_status = '$user_activation_status'
						        order by id Desc";
						    }
						}
                        
                        $result_user = $mysqli->query($sql_user);
                        if ($result_user->num_rows > 0)
                        {
                        while($record = $result_user -> fetch_assoc())
                        {
						    $id = $record['id'];
                            $ref_code = $record['ref_code'];
                            $sponsor_code = $record['sponsor_code'];
                            $type_of_user = $record['type_of_user'];
						    $name = $record['name'];
						    $email = $record['email'];
						    $password = $record['password'];
						    $phone_number = $record['phone_number'];
                            $status = $record['status'];
                            $member_activation_status = $record['activation_status'];
                            $member_verification_status = $record['verification_status'];
                            
                            $created_date = $record['created_date'];
                            $created_date = date('d-m-Y', strtotime($created_date));   
                            
                            if ($member_verification_status == '1')
                            {
                                $member_verification_status_display = "Verified";
							}
                            else
                            {
                                $member_verification_status_display = "Unverified";
							}

                            $sql_total_investment =
                            "SELECT SUM(package_price) As num 
                            FROM package_sale
                            WHERE ref_code = '$ref_code'
                            AND status = '1'
                            AND withdraw_status !='1'";    
                            $result_total_investment = $mysqli->query($sql_total_investment);
                            if ($result_total_investment->num_rows > 0)
                            {
                                $row_total_investment = $result_total_investment->fetch_assoc();
                                $full_total_investment = number_format($row_total_investment['num'],2);
							}

                            if ($user_activation_status == '1')
                            {
                                $sql = "SELECT * 
                                FROM user
                                WHERE ref_code='$ref_code'
                                And status='1'";
                                $result = $mysqli->query($sql);
	                            if ($result->num_rows > 0)
	                            {
		                            $row = $result ->fetch_assoc();
		                            $user_id = $row['user_id'];
	                            }


                                if ($user_id != "")
                                {
                                    date_default_timezone_set("Asia/Kuala_Lumpur");
                                    $from_date = "2020-01-01 18:55:55";
                                    $to_date = date('Y-m-d H:i:s');
    
                                    $group_sale_looping = array("1", "2", "3", "4", "5", "6");

                                    foreach ($group_sale_looping as $group_sale_looping_list) 
                                    {
                                        if ($group_sale_looping_list == '1')
                                        {
                                            $array = Check_Group_Sale($user_id, $group_sale_looping_list, $from_date, $to_date, $level);

                                            $My_downlinelvl1 = $array[0];
                                            $total_invest_lvl1 = $array[1];
	                                    }
                                        else
                                        if ($group_sale_looping_list == '2')
                                        {
                                            if ($My_downlinelvl1 != "")
                                            {
                                                $array = Check_Group_Sale($My_downlinelvl1, $group_sale_looping_list, $from_date, $to_date, $level);

                                                $My_downlinelvl2 = $array[0];
                                                $total_invest_lvl2 = $array[1];
                                            }
            
	                                    }
                                        else
                                        if ($group_sale_looping_list == '3')
                                        {
                                            if ($My_downlinelvl2 != "")
                                            {
                                                $array = Check_Group_Sale($My_downlinelvl2, $group_sale_looping_list, $from_date, $to_date, $level);

                                                $My_downlinelvl3 = $array[0];
                                                $total_invest_lvl3 = $array[1];
                                            }
            
	                                    }
                                        else
                                        if ($group_sale_looping_list == '4')
                                        {
                                            if ($My_downlinelvl3 != "")
                                            {
                                                $array = Check_Group_Sale($My_downlinelvl3, $group_sale_looping_list, $from_date, $to_date, $level);

                                                $My_downlinelvl4 = $array[0];
                                                $total_invest_lvl4 = $array[1];
                                            }  
	                                    }
                                        else
                                        if ($group_sale_looping_list == '5')
                                        {
                                            if ($My_downlinelvl4 != "")
                                            {
                                                $array = Check_Group_Sale($My_downlinelvl4, $group_sale_looping_list, $from_date, $to_date, $level);

                                                $My_downlinelvl5 = $array[0];
                                                $total_invest_lvl5 = $array[1];
			                                }
            
	                                    }
                                        else
                                        if ($group_sale_looping_list == '6')
                                        {
                                            if ($My_downlinelvl5 != "")
                                            {
                                                $array = Check_Group_Sale($My_downlinelvl5, $group_sale_looping_list, $from_date, $to_date, $level);

                                                $My_downlinelvl6 = $array[0];
                                                $total_invest_lvl6 = $array[1];
                                            }
            
	                                    }
                                    }

                                    $total_invest = $total_invest_lvl1 + $total_invest_lvl2 + $total_invest_lvl3 + $total_invest_lvl4 + $total_invest_lvl5 + $total_invest_lvl6;
                                    $total_invest_display = number_format($total_invest,2);
                                }
                            }
                        ?>
                        <tr>
                            <td>
                                <?php
                                if ( $level == '1')
                                {
                                ?>
                                    <?php if ($user_activation_status == "101")
                                    {
                                    ?>
                                        <a href="https://system.mygoldsdnbhd.com/System/Page/U/Form-Verification.php?ref_code=<?php echo $ref_code;?>" class="btn btn-success"><i class="fa fa-podcast"></i>&nbsp; List Member</a> 
                                    <?php
									}
                                    else
                                    {
                                    ?>
                                        <a href="user_detail.php?user_ref_code=<?php echo $ref_code;?>" class="btn btn-success"><i class="fa fa-podcast"></i>&nbsp; View</a> 
                                    <?php
									}
                                    ?>
                                    
                                
                                    <a href="../Controller/Database_sql.php?form_name_Delete_User=Delete_User&id=<?php echo $id;?>&ref_code=<?php echo $ref_code;?>&activation_status=<?php echo $status;?>" 
                                    onClick="javascript: return confirm('Do you want to proceed?');" class="btn btn-danger"><i class="fa fa-trash"></i>&nbsp; Delete</a>
                                <?php
								}
                                ?>
                                <!--a href="../Controller/Database_sql.php?form_name_Activate_User=Activate_User&id=<?php echo $id;?>&activation_status=<?php echo $status;?>" 
                                class="btn btn-success"><i class="fa fa-podcast"></i>&nbsp; Activate</a-->

                            </td>
                            <td><?php echo $id;?></td>
                            <td><a href="profile.php?ref_code=<?php echo $ref_code;?>"><?php echo $ref_code;?></a></td>
                            <td><?php echo $sponsor_code;?></td>
                            <td>USD <?php echo $full_total_investment;?></td>
                            <?php
                            if ($user_activation_status == '1')
                            {
                            ?>
                                <td>USD<?php echo number_format($total_invest_lvl1,2);?></td>
                                <td>USD<?php echo $total_invest_display;?></td>
                            <?php
                            }
                            ?>
                            <td><?php echo $name;?></td>
                            <td><?php echo $email;?></td>
                            <td><?php echo $phone_number;?></td>
                            <td><?php echo $member_verification_status_display;?></td>  
                            <td><?php echo $created_date;?></td>    
                            <input type="hidden" class="form-control"  name="id" value="<?php echo $id; ?>"> 
                        </tr>
                        <?php 
                        } 
                        }
                        ?>
                    </tbody>
                </table>
                </form>
            </div>
        </div>
    </div>                      
</div>
</div>
<!-- ============================================================== -->
<!-- End PAge Content -->

</div>
<!-- End Container fluid  -->
</div>
<!-- End Page wrapper  -->

<!-- Footer Start-->
<?php include ("../Footer/footer.php"); ?>
<!-- Footer End-->

</div>
<!-- End Wrapper -->
<!-- All Jquery -->
    

<!-- All Jquery Start-->
<?php include ("../Header/all_jquery.php"); ?>
<!-- All Jquery End-->

    

</body>

</html>