<?php
session_start();

if (isset($_SESSION['username']) == true) {
	include 'master.php';
	$username = $_SESSION['username'];
}else{
	header("location:login");
}
?>
		<!--page-wrapper-->
		<div class="page-wrapper">
			<!--page-content-wrapper-->
			<div class="page-content-wrapper">
				<div class="page-content">
					<!--breadcrumb-->
					<div class="page-breadcrumb d-none d-md-flex align-items-center mb-3">
						<div class="breadcrumb-title pr-3">Members</div>
						<div class="pl-3">
							<nav aria-label="breadcrumb">
								<ol class="breadcrumb mb-0 p-0">
									<li class="breadcrumb-item"><a href="javascript:;"><i class='bx bx-home-alt'></i></a>
									</li>
									<li class="breadcrumb-item active" aria-current="page">Member's Data</li>
								</ol>
							</nav>
						</div>
						<div class="ml-auto">
							<div class="btn-group">
								<button type="button" class="btn btn-primary">Active</button>
							</div>
						</div>
					</div><br><br>
					<div class="card">
						<div class="card-body">
							<div class="card-title">
								<h4 class="mb-0">Member's Data Import</h4>
							</div>
							<hr/>
							<div class="table-responsive">
								<table id="example" class="table table-striped table-bordered" style="width:100%">
									<thead>
										<tr>
											<th>S/N</th>
											<th>Profile Imagei</th>
											<th>Full Name</th>
											<th>Email</th>
											<th>Phone Number</th>
											<th>OTPs</th> 
											<th>Account No</th>
											<th>Balance</th>
											<th>Password</th>
											<th>Status</th>
											<th>Dated Added</th>
											<th colspan="2" class="text-center">Action</th>
										</tr>
									</thead>
									<tbody>
										<tr>
										<?php
											$sel_post = $conn->query("SELECT * FROM users ORDER BY id DESC ");
											$i=1;
											if ($sel_post->num_rows == 0) {
												echo "<td style='color:red; text-align:center;'>No Users Registered Yet</td>";
											}
											foreach ($sel_post as $key) {
												$id = $key['id'];
												$acc_no = $key['acc_no'];
												$otp = $key['otp'];

												$user_img = $key['profile_img'];
												$img_src = !empty($user_img)
													? '../uploads/profile_pictures/' . htmlspecialchars($user_img)
													: '../uploads/profile_pictures/default.jpg';
										?>
											<td><?php echo $i;?></td>
											<td>
												<img style="border-radius:50%;" width="40" height="40"
													src="<?php echo $img_src; ?>" alt=""
													onerror="this.src='../uploads/profile_pictures/default.jpg'">
											</td>
											<td><?php echo $key['fullname'];?></td>
											<td><?php echo $key['email'];?></td>
											<td><?php echo $key['phone_number'];?></td>
										<td><?php echo $key['otp'];?></td>
											<td><?php echo $key['acc_no'];?></td>
											<td><?php echo currencySymbol($key['currency'] ?? 'USD') . number_format((float)$key['balance'], 2); ?></td>
											<th><?php echo $key['confirm_password'];?></th>
											<th><?php echo $key['account_status'];?></th>
											<td><?php echo $key['date_added'];?></td>
											<td><a href="add_fund?account_number=<?php echo $acc_no; ?>" class="btn btn-success">Add Funds</a>&nbsp;&nbsp;
												<a href="delete_member?id=<?php echo $id; ?>" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete?')">Delete</a>&nbsp;&nbsp;<a href="edit_member?id=<?php echo $id; ?>" class="btn btn-secondary">Edit</a>
											</td>
										</tr>
										<?php $i++;
										}	?>
									</tbody>
									<tfoot>
										<tr>
											<th>S/N</th>
											<th>Profile Image</th>
											<th>Full Name</th>
											<th>Email</th>
											<th>Phone Number</th>
											 <th>OTPs</th>
											<th>Account No</th>
											<th>Balance</th>
											<th>Password</th>
											<th>Status</th>
											<th>Dated Added</th>
											<th colspan="2" class="text-center">Action</th>
										</tr>
									</tfoot>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!--end page-content-wrapper-->
		</div>
		<!--end page-wrapper-->
		<!--start overlay-->
		<div class="overlay toggle-btn-mobile"></div>
		<!--end overlay-->
		<!--Start Back To Top Button--> <a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>
		<!--End Back To Top Button-->

<script>
		$(document).ready(function () {
			//Default data table
			$('#example').DataTable();
			// var table = $('#example2').DataTable({
			// 	lengthChange: false,
			// 	buttons: ['copy', 'excel', 'pdf', 'print', 'colvis']
			// });
			// table.buttons().container().appendTo('#example2_wrapper .col-md-6:eq(0)');
		});
	</script>
<?php
include 'footer.php';