169 lines
6.4 KiB
PHP
169 lines
6.4 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'auth.php';
|
|
require_once 'db/config.php';
|
|
|
|
if (!is_logged_in()) {
|
|
header("Location: login.php");
|
|
exit;
|
|
}
|
|
|
|
$db = db();
|
|
|
|
// Function to recursively fetch the downline tree
|
|
function get_downline_tree($userId, $db) {
|
|
$tree = [];
|
|
$stmt = $db->prepare("SELECT id, name, email, agent_tier FROM users WHERE sponsor_id = :sponsor_id ORDER BY name");
|
|
$stmt->execute([':sponsor_id' => $userId]);
|
|
$downline = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
foreach ($downline as $member) {
|
|
$member['downline'] = get_downline_tree($member['id'], $db);
|
|
$tree[] = $member;
|
|
}
|
|
|
|
return $tree;
|
|
}
|
|
|
|
// Function to recursively display the tree as a nested list
|
|
function display_tree_node($node) {
|
|
echo '<li>';
|
|
echo '<div class="card member-card">';
|
|
echo '<div class="card-body">';
|
|
echo '<h5>' . htmlspecialchars($node['name']) . '</h5>';
|
|
echo '<p class="mb-1"><small>' . htmlspecialchars($node['email']) . '</small></p>';
|
|
echo '<span class="badge bg-info text-dark"> ' . htmlspecialchars($node['agent_tier']) . '</span>';
|
|
echo '</div>';
|
|
echo '</div>';
|
|
|
|
if (!empty($node['downline'])) {
|
|
echo '<ul>';
|
|
foreach ($node['downline'] as $child) {
|
|
display_tree_node($child);
|
|
}
|
|
echo '</ul>';
|
|
}
|
|
|
|
echo '</li>';
|
|
}
|
|
|
|
|
|
$stmt = $db->prepare("SELECT * FROM users WHERE id = :id");
|
|
$stmt->execute([':id' => $_SESSION['user_id']]);
|
|
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
$genealogy_tree = get_downline_tree($user['id'], $db);
|
|
|
|
$site_name = 'Kutumbh Infra';
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Genealogy Tree - <?php echo htmlspecialchars($site_name); ?></title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet">
|
|
<link href="assets/css/dashboard.css" rel="stylesheet">
|
|
<style>
|
|
.genealogy-tree ul {
|
|
padding-left: 20px;
|
|
list-style: none;
|
|
position: relative;
|
|
}
|
|
.genealogy-tree ul li {
|
|
margin-top: 10px;
|
|
position: relative;
|
|
}
|
|
.genealogy-tree ul li::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: -10px;
|
|
left: -20px;
|
|
border-left: 1px solid #ddd;
|
|
border-bottom: 1px solid #ddd;
|
|
width: 20px;
|
|
height: 27px;
|
|
}
|
|
.genealogy-tree > ul > li::before {
|
|
border: none;
|
|
}
|
|
.genealogy-tree ul li:last-child::before {
|
|
height: 27px;
|
|
}
|
|
.member-card {
|
|
border-left: 3px solid #0dcaf0;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="sidebar">
|
|
<a href="index.php" class="logo"><?php echo htmlspecialchars($site_name); ?></a>
|
|
<ul class="nav flex-column">
|
|
<li class="nav-item"><a class="nav-link" href="dashboard.php"><i class="bi bi-grid"></i> Dashboard</a></li>
|
|
|
|
<?php if (is_agent()): ?>
|
|
<li class="nav-item"><a class="nav-link" href="submit_booking.php"><i class="bi bi-journal-plus"></i> Submit Booking</a></li>
|
|
<?php endif; ?>
|
|
|
|
<li class="nav-item"><a class="nav-link active" href="genealogy.php"><i class="bi bi-diagram-3"></i> Genealogy Tree</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="ledger.php"><i class="bi bi-receipt"></i> Ledger</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="withdraw.php"><i class="bi bi-cash-coin"></i> Withdraw</a></li>
|
|
|
|
<?php if (is_admin() || is_super_admin()): ?>
|
|
<li class="nav-item"><hr></li>
|
|
<li class="nav-item-header">Admin Menu</li>
|
|
<li class="nav-item"><a class="nav-link" href="admin/bookings.php"><i class="bi bi-calendar-check"></i> Manage Bookings</a></li>
|
|
<?php endif; ?>
|
|
|
|
<?php if (is_super_admin()): ?>
|
|
<li class="nav-item"><a class="nav-link" href="admin_dashboard.php"><i class="bi bi-people"></i> User Management</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="edit_content.php"><i class="bi bi-pencil-square"></i> Edit Content</a></li>
|
|
<?php endif; ?>
|
|
|
|
<li class="nav-item"><hr></li>
|
|
<li class="nav-item"><a class="nav-link" href="logout.php"><i class="bi bi-box-arrow-left"></i> Logout</a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="main-content">
|
|
<header class="header">
|
|
<h1 class="h3 mb-0">Genealogy Tree</h1>
|
|
<div class="dropdown">
|
|
<a href="#" class="d-block link-dark text-decoration-none dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<i class="bi bi-person-circle fs-4"></i> <span class="d-none d-sm-inline mx-1"><?php echo htmlspecialchars($user['name']); ?></span>
|
|
</a>
|
|
<ul class="dropdown-menu text-small dropdown-menu-end">
|
|
<li><span class="dropdown-item-text"><strong><?php echo htmlspecialchars($user['name']); ?></strong><br><small><?php echo htmlspecialchars($user['role']); ?></small></span></li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<li><a class="dropdown-item" href="logout.php">Sign out</a></li>
|
|
</ul>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="container-fluid">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="mb-0">Your Downline</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="genealogy-tree">
|
|
<ul>
|
|
<?php if (empty($genealogy_tree)): ?>
|
|
<p>You have no users in your downline yet.</p>
|
|
<?php else: ?>
|
|
<?php foreach ($genealogy_tree as $node): ?>
|
|
<?php display_tree_node($node); ?>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|