Repository navigation
Expand file tree
/
Copy pathheader.php
More file actions
233 lines (210 loc) · 10.2 KB
/
Copy pathheader.php
File metadata and controls
233 lines (210 loc) · 10.2 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
// Include security functions first
include_once './includes/security.inc.php';
// Include freemium system for guest usage tracking
include_once './includes/freemium.inc.php';
// Initialize secure session (this handles all session configuration and startup)
initializeSecureSession();
// Generate CSRF token if not exists
if (!isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = generateCSRFToken();
}
// Check session validity for protected pages (admin-only pages)
$current_page = basename($_SERVER['PHP_SELF']);
$protected_pages = ['dashboard_admin.php', 'update.php']; // Remove add.php to allow guest access
if (in_array($current_page, $protected_pages) && !isValidSession()) {
// Destroy invalid session
session_unset();
session_destroy();
header('Location: signin.php?error=sessionexpired');
exit();
}
// Guest usage tracking for navigation
$is_guest = !isset($_SESSION['userId']);
$guest_usage_stats = null;
$show_guest_upgrade = false;
if ($is_guest) {
try {
$client_ip = get_client_ip();
$guest_usage_stats = get_usage_stats($client_ip);
if ($guest_usage_stats &&
isset($guest_usage_stats['current_usage']) &&
isset($guest_usage_stats['daily_limit']) &&
$guest_usage_stats['daily_limit'] > 0) {
// Show upgrade prompt if usage is at 80% or above
$usage_percentage = ($guest_usage_stats['current_usage'] / $guest_usage_stats['daily_limit']) * 100;
$show_guest_upgrade = $usage_percentage >= 80;
} else {
// Reset variables if data is incomplete
$guest_usage_stats = null;
$show_guest_upgrade = false;
}
} catch (Exception $e) {
// Silently handle any freemium errors in navigation
error_log("Guest usage tracking error in header: " . $e->getMessage());
$guest_usage_stats = null;
$show_guest_upgrade = false;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="This is a Admin Dashboard About Covid19 Records." />
<meta name="keywords" content="Dashboard, Covid19, HTML, CSS, JavaScript, Web Design" />
<meta name="author" content="Reymar" />
<title>COVID-19 Daily Health Declaration</title>
<!-- Favico -->
<link rel="icon" type="image/x-icon" href='./assets/images/virus-solid.svg'>
<!-- CSS -->
<link rel="stylesheet" href="./styles/styles.css" />
<link rel="stylesheet" href="./styles/header.css?v=6">
<?php if ($current_page === 'index.php'): ?>
<link rel="stylesheet" href="./styles/index-minimal.css?v=1">
<?php else: ?>
<link rel="stylesheet" href="./styles/dasboard-admin.css?v=5" />
<link rel="stylesheet" href="./styles/index.css?v=5">
<link rel="stylesheet" href="./styles/add.css?v=5">
<link rel="stylesheet" href="./styles/profile.css?v=1">
<link rel="stylesheet" href="./styles/settings.css?v=1">
<?php endif; ?>
<!-- <link rel="stylesheet" href="./styles/freemium.css?v=1"> TEMPORARILY DISABLED -->
<link rel="stylesheet" href="./styles/about.css?v=5">
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<!-- Icons -->
<script src="https://kit.fontawesome.com/444873800b.js" crossorigin="anonymous"></script>
<script src="./scripts/main.js" defer></script>
</head>
<body>
<nav id="navbar" class="navbar">
<div class="nav-container">
<!-- Logo Section -->
<div id="nav-logo-section" class="nav-section">
<a href="./index.php" class="nav-logo" aria-label="COVID-19 Health Declaration Home">
<i class="fa-solid fa-virus" aria-hidden="true"></i>
<!-- <span class="nav-brand">COVID-19 Health</span> -->
</a>
</div>
<!-- Desktop Navigation Links -->
<div id="nav-link-section" class="nav-section">
<a href="./index.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'index.php' ? 'active' : ''; ?>">
<i class="fa-solid fa-house" aria-hidden="true"></i>
<span>Home</span>
</a>
<?php if (isset($_SESSION['userId'])): ?>
<a href="./dashboard_admin.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'dashboard_admin.php' ? 'active' : ''; ?>">
<i class="fa-solid fa-chart-line" aria-hidden="true"></i>
<span>Dashboard</span>
</a>
<a href="./add.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'add.php' ? 'active' : ''; ?>">
<i class="fa-solid fa-plus" aria-hidden="true"></i>
<span>New Record</span>
</a>
<div class="nav-user-menu">
<button class="nav-user-btn" id="userMenuBtn" aria-expanded="false" aria-haspopup="true">
<i class="fa-solid fa-user-circle" aria-hidden="true"></i>
<span><?php echo htmlspecialchars($_SESSION['userUid']); ?></span>
<i class="fa-solid fa-chevron-down nav-dropdown-icon" aria-hidden="true"></i>
</button>
<div class="nav-user-dropdown" id="userDropdown">
<a href="./profile.php" class="nav-dropdown-link">
<i class="fa-solid fa-user" aria-hidden="true"></i>
Profile
</a>
<a href="./settings.php" class="nav-dropdown-link">
<i class="fa-solid fa-cog" aria-hidden="true"></i>
Settings
</a>
<hr class="nav-dropdown-divider">
<form method="post" action="./includes/logout.inc.php" class="nav-logout-form">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?? ''; ?>">
<button type="submit" class="nav-dropdown-link logout-btn">
<i class="fa-solid fa-sign-out-alt" aria-hidden="true"></i>
Logout
</button>
</form>
</div>
</div>
<?php else: ?>
<!-- No usage display for guests - clean navigation -->
<a href="./about.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'about.php' ? 'active' : ''; ?>">
<i class="fa-solid fa-info-circle" aria-hidden="true"></i>
<span>About</span>
</a>
<?php if ($show_guest_upgrade): ?>
<a href="./signup.php" class="nav-link nav-upgrade <?php echo basename($_SERVER['PHP_SELF']) == 'signup.php' ? 'active' : ''; ?>">
<i class="fa-solid fa-crown" aria-hidden="true"></i>
<span>Sign Up</span>
</a>
<?php endif; ?>
<a href="./signin.php" class="nav-link nav-cta <?php echo basename($_SERVER['PHP_SELF']) == 'signin.php' ? 'active' : ''; ?>">
<i class="fa-solid fa-sign-in-alt" aria-hidden="true"></i>
<span>Sign In</span>
</a>
<?php endif; ?>
</div>
<!-- Mobile Menu Toggle -->
<div class="nav-mobile-toggle">
<button class="nav-hamburger" id="navToggle" aria-label="Toggle navigation menu" aria-expanded="false">
<span class="hamburger-line"></span>
<span class="hamburger-line"></span>
<span class="hamburger-line"></span>
</button>
</div>
</div>
<!-- Mobile Navigation Menu -->
<div class="nav-mobile-menu" id="mobileMenu">
<div class="nav-mobile-content">
<a href="./index.php" class="nav-mobile-link <?php echo basename($_SERVER['PHP_SELF']) == 'index.php' ? 'active' : ''; ?>">
<i class="fa-solid fa-house" aria-hidden="true"></i>
Home
</a>
<?php if (isset($_SESSION['userId'])): ?>
<a href="./dashboard_admin.php" class="nav-mobile-link <?php echo basename($_SERVER['PHP_SELF']) == 'dashboard_admin.php' ? 'active' : ''; ?>">
<i class="fa-solid fa-chart-line" aria-hidden="true"></i>
Dashboard
</a>
<a href="./add.php" class="nav-mobile-link <?php echo basename($_SERVER['PHP_SELF']) == 'add.php' ? 'active' : ''; ?>">
<i class="fa-solid fa-plus" aria-hidden="true"></i>
New Record
</a>
<div class="nav-mobile-user">
<div class="nav-mobile-user-info">
<i class="fa-solid fa-user-circle" aria-hidden="true"></i>
<span><?php echo htmlspecialchars($_SESSION['userUid']); ?></span>
</div>
<a href="./profile.php" class="nav-mobile-link">
<i class="fa-solid fa-user" aria-hidden="true"></i>
Profile
</a>
<a href="./settings.php" class="nav-mobile-link">
<i class="fa-solid fa-cog" aria-hidden="true"></i>
Settings
</a>
<form method="post" action="./includes/logout.inc.php" class="nav-mobile-logout">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?? ''; ?>">
<button type="submit" class="nav-mobile-link logout-btn">
<i class="fa-solid fa-sign-out-alt" aria-hidden="true"></i>
Logout
</button>
</form>
</div>
<?php else: ?>
<!-- Clean mobile navigation for guests -->
<a href="./about.php" class="nav-mobile-link <?php echo basename($_SERVER['PHP_SELF']) == 'about.php' ? 'active' : ''; ?>">
<i class="fa-solid fa-info-circle" aria-hidden="true"></i>
About
</a>
<a href="./signin.php" class="nav-mobile-link nav-cta <?php echo basename($_SERVER['PHP_SELF']) == 'signin.php' ? 'active' : ''; ?>">
<i class="fa-solid fa-sign-in-alt" aria-hidden="true"></i>
Sign In
</a>
<?php endif; ?>
</div>
</div>
</nav>