-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.php
More file actions
370 lines (312 loc) · 11.9 KB
/
dashboard.php
File metadata and controls
370 lines (312 loc) · 11.9 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php
include('includes/config.php');
if (!isset($_SESSION['user_id'])) {
header("Location: index.php");
exit();
}
// $pageTitle = 'Dashboard';
//counter parts
function getTotalMembersCount()
{
global $conn;
$totalMembersQuery = "SELECT COUNT(*) AS totalMembers FROM members";
$totalMembersResult = $conn->query($totalMembersQuery);
if ($totalMembersResult->num_rows > 0) {
$totalMembersRow = $totalMembersResult->fetch_assoc();
return $totalMembersRow['totalMembers'];
} else {
return 0;
}
}
function getTotalMembershipTypesCount()
{
global $conn;
$totalMembershipTypesQuery = "SELECT COUNT(*) AS totalMembershipTypes FROM membership_types";
$totalMembershipTypesResult = $conn->query($totalMembershipTypesQuery);
if ($totalMembershipTypesResult->num_rows > 0) {
$totalMembershipTypesRow = $totalMembershipTypesResult->fetch_assoc();
return $totalMembershipTypesRow['totalMembershipTypes'];
} else {
return 0;
}
}
function getExpiringSoonCount()
{
global $conn;
$expiringSoonQuery = "SELECT COUNT(*) AS expiringSoon FROM members WHERE expiry_date BETWEEN CURDATE() AND CURDATE() + INTERVAL 7 DAY";
$expiringSoonResult = $conn->query($expiringSoonQuery);
if ($expiringSoonResult->num_rows > 0) {
$expiringSoonRow = $expiringSoonResult->fetch_assoc();
return $expiringSoonRow['expiringSoon'];
} else {
return 0;
}
}
// function getTotalRevenue()
// {
// global $conn;
// $totalRevenueQuery = "SELECT SUM(total_amount) AS totalRevenue FROM renew";
// $totalRevenueResult = $conn->query($totalRevenueQuery);
// if ($totalRevenueResult->num_rows > 0) {
// $totalRevenueRow = $totalRevenueResult->fetch_assoc();
// return $totalRevenueRow['totalRevenue'];
// } else {
// return 0;
// }
// }
function getTotalRevenueWithCurrency()
{
global $conn;
$currencyQuery = "SELECT currency FROM settings LIMIT 1";
$currencyResult = $conn->query($currencyQuery);
if ($currencyResult->num_rows > 0) {
$currencyRow = $currencyResult->fetch_assoc();
$currencySymbol = $currencyRow['currency'];
} else {
$currencySymbol = '$'; // Default currency symbol (you can change this as needed)
}
$totalRevenueQuery = "SELECT SUM(total_amount) AS totalRevenue FROM renew";
$totalRevenueResult = $conn->query($totalRevenueQuery);
if ($totalRevenueResult->num_rows > 0) {
$totalRevenueRow = $totalRevenueResult->fetch_assoc();
$totalRevenue = $totalRevenueRow['totalRevenue'];
} else {
$totalRevenue = 0;
}
return $currencySymbol . number_format($totalRevenue, 2);
}
function getNewMembersCount() {
global $conn;
// Visit codeastro.com for more projects
$twentyFourHoursAgo = time() - (24 * 60 * 60);
$newMembersQuery = "SELECT COUNT(*) AS newMembersCount FROM members WHERE created_at >= FROM_UNIXTIME($twentyFourHoursAgo)";
$newMembersResult = $conn->query($newMembersQuery);
if ($newMembersResult) {
$row = $newMembersResult->fetch_assoc();
return $row['newMembersCount'];
} else {
return 0;
}
}
// Function to display the total count of new members with HTML markup
function displayNewMembersCount() {
$newMembersCount = getNewMembersCount();
echo "<span class='info-box-number'>$newMembersCount</span>";
}
function getExpiredMembersCount() {
global $conn;
$expiredMembersQuery = "SELECT COUNT(*) AS expiredMembersCount FROM members WHERE (expiry_date IS NULL OR expiry_date < NOW())";
$expiredMembersResult = $conn->query($expiredMembersQuery);
if ($expiredMembersResult) {
$row = $expiredMembersResult->fetch_assoc();
return $row['expiredMembersCount'];
} else {
return 0;
}
}
function displayExpiredMembersCount() {
$expiredMembersCount = getExpiredMembersCount();
echo "<span class='info-box-number'>$expiredMembersCount</span>";
}
$fetchLogoQuery = "SELECT logo FROM settings WHERE id = 1";
$fetchLogoResult = $conn->query($fetchLogoQuery);
if ($fetchLogoResult->num_rows > 0) {
$settings = $fetchLogoResult->fetch_assoc();
$logoPath = $settings['logo'];
} else {
$logoPath = 'dist/img/default-logo.png';
}
// Visit codeastro.com for more projects
?>
<?php include('includes/header.php');?>
<body class="hold-transition sidebar-mini layout-fixed layout-navbar-fixed layout-footer-fixed">
<div class="wrapper">
<?php include('includes/nav.php');?>
<?php include('includes/sidebar.php');?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<?php include('includes/pagetitle.php');?>
<!-- Main content -->
<section class="content">
<div class="container-fluid">
<!-- Info boxes -->
<div class="row">
<div class="col-12 col-sm-6 col-md-3">
<div class="info-box">
<span class="info-box-icon bg-primary elevation-1"><i class="fas fa-users"></i></span>
<div class="info-box-content">
<span class="info-box-text">Total Members</span>
<span class="info-box-number">
<?php echo getTotalMembersCount(); ?>
</span>
</div>
<!-- /.info-box-content -->
</div>
<!-- /.info-box -->
</div>
<!-- /.col -->
<div class="col-12 col-sm-6 col-md-3">
<div class="info-box mb-3">
<span class="info-box-icon bg-danger elevation-1"><i class="fas fa-list"></i></span>
<div class="info-box-content">
<span class="info-box-text">Membership Types</span>
<span class="info-box-number"><?php echo getTotalMembershipTypesCount(); ?></span>
</div>
<!-- /.info-box-content -->
</div>
<!-- /.info-box -->
</div>
<!-- /.col -->
<!-- fix for small devices only -->
<div class="clearfix hidden-md-up"></div>
<div class="col-12 col-sm-6 col-md-3">
<div class="info-box mb-3">
<span class="info-box-icon bg-warning elevation-1"><i class="fas fa-hourglass-half"></i></span>
<div class="info-box-content">
<span class="info-box-text">Expiring Soon</span>
<span class="info-box-number"><?php echo getExpiringSoonCount(); ?></span>
</div>
<!-- /.info-box-content -->
</div>
<!-- /.info-box -->
</div>
<!-- /.col -->
<div class="col-12 col-sm-6 col-md-3">
<div class="info-box mb-3">
<span class="info-box-icon bg-success elevation-1"><i class="fas fa-coins"></i></span>
<div class="info-box-content">
<span class="info-box-text">Total Revenue</span>
<span class="info-box-number"><?php echo getTotalRevenueWithCurrency(); ?></span>
</div>
<!-- /.info-box-content -->
</div>
<!-- /.info-box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
<!-- Visit codeastro.com for more projects -->
<div class="row">
<div class="col-12 col-sm-6 col-md-3">
<div class="info-box mb-3">
<span class="info-box-icon bg-info elevation-1"><i class="fas fa-users"></i></span>
<div class="info-box-content">
<span class="info-box-text">New Members</span>
<span class="info-box-number"><?php displayNewMembersCount(); ?></span>
</div>
<!-- /.info-box-content -->
</div>
<!-- /.info-box -->
</div>
<!-- /.col -->
<div class="col-12 col-sm-6 col-md-3">
<div class="info-box mb-3">
<span class="info-box-icon bg-maroon elevation-1"><i class="fas fa-times"></i></span>
<div class="info-box-content">
<span class="info-box-text">Expired Membership</span>
<span class="info-box-number"><?php displayExpiredMembersCount(); ?></span>
</div>
<!-- /.info-box-content -->
</div>
<!-- /.info-box -->
</div>
<!-- /.col -->
</div>
<!-- Main row -->
<div class="row">
<div class="col-md-12">
<!-- Member LIST -->
<?php
// Fetch recently joined members
$recentMembersQuery = "SELECT * FROM members ORDER BY created_at DESC LIMIT 4";
$recentMembersResult = $conn->query($recentMembersQuery);
?>
<div class="card">
<div class="card-header">
<h3 class="card-title">Recently Joined Members</h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse">
<i class="fas fa-minus"></i>
</button>
<button type="button" class="btn btn-tool" data-card-widget="remove">
<i class="fas fa-times"></i>
</button>
</div>
</div>
<!-- Visit codeastro.com for more projects -->
<!-- /.card-header -->
<div class="card-body p-0">
<ul class="products-list product-list-in-card pl-2 pr-2">
<?php
while ($row = $recentMembersResult->fetch_assoc()) {
echo '<li class="item">';
echo '<div class="product-img">';
// Check if the member has a photo
if (!empty($row['photo'])) {
$photoPath = 'uploads/member_photos/' . $row['photo'];
echo '<img src="' . $photoPath . '" alt="Member Photo" class="img-size-50">';
} else {
echo '<img src="uploads/member_photos/default.jpg" alt="Default Photo" class="img-size-50">';
}
echo '</div>';
echo '<div class="product-info">';
echo '<a href="javascript:void(0)" class="product-title">' . $row['fullname'] . '</a>';
echo '<span class="product-description">';
echo '<span class="badge badge-dark float-right">' . getMembershipTypeName($row['membership_type']) . '</span>';
echo 'Membership Number: ' . ($row['membership_number']);
echo '</span>';
echo '</div>';
echo '</li>';
}
?>
</ul>
</div>
<!-- /.card-body -->
<div class="card-footer text-center">
<a href="manage_members.php" class="uppercase">View All Members</a>
</div>
<!-- /.card-footer -->
</div>
<?php
// Function to get membership type name based on membership type ID
function getMembershipTypeName($membershipTypeId)
{
global $conn;
$membershipTypeQuery = "SELECT type FROM membership_types WHERE id = $membershipTypeId";
$membershipTypeResult = $conn->query($membershipTypeQuery);
if ($membershipTypeResult->num_rows > 0) {
$membershipTypeRow = $membershipTypeResult->fetch_assoc();
return $membershipTypeRow['type'];
} else {
return 'Unknown';
}
}
?>
<!-- /.card -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</div><!--/. container-fluid -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<!-- Control Sidebar -->
<aside class="control-sidebar control-sidebar-dark">
<!-- Control sidebar content goes here -->
</aside>
<!-- /.control-sidebar -->
<!-- Main Footer -->
<footer class="main-footer">
<strong> © <?php echo date('Y');?> codeastro.com</a> -</strong>
All rights reserved.
<div class="float-right d-none d-sm-inline-block">
<b>Developed By</b> <a href="https://codeastro.com/">CodeAstro</a>
</div>
</footer>
</div>
<!-- ./wrapper -->
<?php include('includes/footer.php');?>
</body>
</html>