-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader.php
More file actions
83 lines (76 loc) · 2.75 KB
/
header.php
File metadata and controls
83 lines (76 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
include 'config.php';
session_start();
// Fetch the user's rank number from the database
if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];
}
// Fetch logo URL from the database
$stmt = $conn->prepare("SELECT value FROM settings WHERE name = 'logo_url'");
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$logo_url = $row['value'];
} else {
$logo_url = "/public/images/logo.png"; // Default logo URL in case it's not found in the database
}
// Fetch parent categories and their subcategories
$stmt = $conn->prepare("SELECT * FROM categories WHERE parent_id IS NULL");
$stmt->execute();
$parent_categories = $stmt->get_result();
function fetch_subcategories($conn, $parent_id) {
$stmt = $conn->prepare("SELECT * FROM categories WHERE parent_id = ?");
$stmt->bind_param("i", $parent_id);
$stmt->execute();
return $stmt->get_result();
}
// Fetch registration_enabled setting from the database
$stmt = $conn->prepare("SELECT value FROM settings WHERE name = 'registration_enabled'");
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$registration_enabled = $row['value'];
} else {
$registration_enabled = 1; // Default to enabled in case it's not found in the database
}
?>
<header>
<div class="header-container">
<div class="logo">
<a href="/index.php"><img src="<?php echo htmlspecialchars($logo_url); ?>" alt="Wiki Logo"></a>
</div>
<nav class="categories">
<ul>
<?php while ($parent = $parent_categories->fetch_assoc()): ?>
<li>
<a href="/categories.php?id=<?= $parent['id'] ?>"><?= $parent['name'] ?></a>
<?php $subcategories = fetch_subcategories($conn, $parent['id']); ?>
<?php if ($subcategories->num_rows > 0): ?>
<ul class="submenu">
<?php while ($sub = $subcategories->fetch_assoc()): ?>
<li><a href="/categories.php?id=<?= $sub['id'] ?>"><?= $sub['name'] ?></a></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
</li>
<?php endwhile; ?>
</ul>
</nav>
<nav class="user-actions">
<ul>
<?php if (isset($_SESSION['user_id'])): ?>
<li><a href="/admin/index.php">Dashboard</a></li>
<li><a href="/profile.php"><?php echo htmlspecialchars($_SESSION['username']); ?></a></li>
<li><a href="/auth/logout.php">Log Out</a></li>
<?php else: ?>
<li><a href="/auth/login.php">Login</a></li>
<?php if ($registration_enabled == 1): ?>
<li><a href="/auth/register.php">Register</a></li>
<?php endif; ?>
<?php endif; ?>
</ul>
</nav>
</div>
</header>