-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
344 lines (304 loc) · 9.66 KB
/
admin.php
File metadata and controls
344 lines (304 loc) · 9.66 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
<?php
session_start();
if (!isset($_SESSION["status"]) || ($_SESSION['status'] != getenv('LOGIN_STATUS'))) { //Check whether the admin has logged in
header("Location: login.php");
exit;
}
if (isset($_POST['logout'])) {
session_destroy();
header("Location: /");
exit;
}
include_once 'php/sourceFinal.php';
$dbConn = getDBConnection();
/*admin report*/
/* average number of conventions per state */
function getConAvg()
{
global $dbConn;
$sql = "SELECT ROUND(COUNT(*) / COUNT(DISTINCT (state))) as result
FROM convention";
$ans = preExeFetNOPARA($sql);
//print_r($ans);
return $ans;
}
function displayConAvg($num)
{
foreach ($num as $digit) {
echo $digit['result'] . " ";
}
}
/* number of conventions per state greater than four*/
function getConByState()
{
global $dbConn;
$sql = "SELECT state, c
FROM
(SELECT state, COUNT(*) AS c
FROM convention AS t1
GROUP BY state
ORDER BY c DESC) AS t2
WHERE t2.c > 4";
$list = preExeFetNOPARA($sql);
//print_r($list);
return $list;
}
function displayConByState($list)
{
foreach ($list as $item) {
echo $item['state'] . " " . $item['c'] . "<br>";
}
}
/* total convention */
function getConTot()
{
global $dbConn;
$sql = "SELECT count(*) as conTotal FROM convention";
$tot = preExeFetNOPARA($sql);
//print_r($tot);
return $tot;
}
function displayConTot($tot)
{
foreach ($tot as $part) {
echo $part['conTotal'] . " ";
}
}
/* list of the upcoming conventions based on date, one or more */
function getNextCon()
{
global $dbConn;
$sql = "SELECT COUNT(*) as c
FROM
(SELECT
id, STR_TO_DATE(CONCAT(start_date, ' ', year), '%M %d %Y') AS result
FROM convention
ORDER BY result IS NULL , result ASC) AS t1
WHERE
result > CURRENT_DATE()
GROUP BY result
ORDER BY result ASC
limit 1";
$stmt = $dbConn->prepare($sql);
$stmt->execute();
$records = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($records as $item) {
$limit = $item['c'];
}
$sql = "SELECT *, STR_TO_DATE(CONCAT(start_date, ' ', year), '%M %d %Y') AS r
FROM convention
WHERE STR_TO_DATE(CONCAT(start_date, ' ', year), '%M %d %Y') > CURRENT_DATE()
ORDER BY r IS NULL , r ASC limit " . $limit;
$stmt = $dbConn->prepare($sql);
$stmt->execute();
$records = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $records;
}
/* convention display with update and delete buttons for each */
function displayConAdmin($convention)
{
foreach ($convention as $eachCon) {
$newDate = dateDisplay($eachCon['start_date'], $eachCon['end_date']);
echo "<tr>";
echo "<td>" . $eachCon['conName'] . "</td>";
echo "<td>
<a href='conUpdate.php?id=" . $eachCon['id'] . "'>
<button type=\"button\" class=\"btn\">
<span class=\"glyphicon glyphicon-pencil\" aria-hidden=\"true\"></span> Update
</button>
</a>";
echo "</td>";
echo "<td>
<a href='deleteCon.php?id=" . $eachCon['id'] . "' onclick= 'return confirmDelete(\"" . $eachCon['conName'] . "\")' >
<button type=\"button\" class=\"btn\">
<span class=\"glyphicon glyphicon-remove\" aria-hidden=\"true\"></span> Delete
</button>
</a>";
echo "</td>";
echo "<td>" . $newDate . "</td>";
echo "<td>" . $eachCon['year'] . "</td>";
echo "<td>" . $eachCon['event_location'] . "</td>";
echo "<td>" . $eachCon['city'] . "</td>";
echo "<td>" . $eachCon['state'] . "</td>";
echo "<td>" . $eachCon['country'] . "</td>";
echo "<td> <a href='https://" . $eachCon['website'] . "' target='_blank' rel='noopener noreferrer'>" . $eachCon['website'] . "</a> </td>";
echo "</tr>";
}
}
include_once 'header.inc';
?>
<script>
function confirmDelete(userFullName) {
var confirmDelete = confirm("Do you really want to delete: " + userFullName + "");
if (!confirmDelete) {
return false;
} else {
return true;
}
}
</script>
<!-- Collect the nav links, forms, and other content for toggling -->
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="collection.php">Collection</a>
</li>
<li class="nav-item">
<a class="nav-link" href="graphicNovel.php">Graphic Novels</a>
</li>
<li class="nav-item">
<a class="nav-link" href="convention.php">Conventions</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="login.php">Admin<span class="visually-hidden">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="conInsert.php">New Convention</a>
</li>
<li class="nav-item">
<a class="nav-link" href="conUpdate.php">Update Convention</a>
</li>
</ul>
<?php
if (isset($_SESSION["status"])) {
echo '<form method ="POST" id="one" >';
echo '<input type="submit" value="Logout" class="btn" name="logout" style="box-shadow: none !important;"/>';
echo '</form>';
}
?>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<br>
<main id="main-content">
<div class="wrapper form-display">
<h6>
Welcome <?= $_SESSION['name'] ?>
</h6>
<br>
<form method="POST" name="conForm" id="middlePage" class="row gx-4 gy-3 align-items-center">
<div class="col-auto">
<div class="input-group">
<div class="input-group-text">Name</div>
<input type="text" name="conName" placeholder="Enter Convention Name" />
</div>
</div>
<div class="col-auto">
<input type="submit" value="Search" name="filterForm" class="btn" />
</div>
<div class="col-auto">
<a href="conInsert.php" class="btn">Add New Con!</a>
</div>
<div class="col-auto">
<!-- Button trigger modal -->
<button type="button" class="btn" data-bs-toggle="modal" data-bs-target="#myModal">
Admin Reports
</button>
</div>
</form>
</div>
<br><br>
<div class="wrapper form-display" style="overflow: auto;">
<table class="table table-sm table-striped table-hover display nowrap" id="adminDisplay" style="width:100%;">
<caption>Admin Conventions</caption>
<!--https://www.w3schools.com/bootstrap/bootstrap_tables.asp-->
<thead class='table-dark'>
<tr>
<th>Name</th>
<th>Alter</th>
<th>Remove</th>
<th>Date</th>
<th>Year</th>
<th>Location</th>
<th>City</th>
<th>State</th>
<th>Country</th>
<th>Official</th>
</tr>
</thead>
<tbody>
<?php
if (isset($_POST['filterForm'])) {
$filterCon = goSQLcon("convention");
displayConAdmin($filterCon);
} else {
$convention = getConData("convention");
displayConAdmin($convention);
}
?>
</tbody>
</table>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title fs-5" id="myModalLabel">Admin Report</h6>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" style="overflow: auto;">
<p>Average number of conventions per State:
<?php $num = getConAvg();
displayConAvg($num); ?></p>
<p>The States with more than four convention in descending order:<br>
<?php $list = getConByState();
displayConByState($list); ?></p>
<p>Total overall conventions:
<?php $cnt = getConTot();
displayConTot($cnt); ?> </p>
<p>One or more upcoming conventions based on today's date:</p>
<table class="table table-sm table-striped table-hover display nowrap" id="summaryDisplay" style="width:100%;">
<caption>Admin Upcoming Convention Summary</caption>
<thead class='table-dark'>
<tr>
<th>Name</th>
<th>Date</th>
<th>Year</th>
<th>Location</th>
<th>City</th>
<th>State</th>
<th>Country</th>
<th>Official</th>
</tr>
</thead>
<tbody>
<?php
$groupCons = getNextCon();
displayCon($groupCons);
?>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php include_once 'footer.inc' ?>
<script>
//https://datatables.net/reference/option
new DataTable('#adminDisplay', {
lengthMenu: [8, 16],
searching: false,
ordering: false,
responsive: true,
pagingType: 'simple'
});
new DataTable('#summaryDisplay', {
lengthMenu: [5, 10],
searching: false,
ordering: false,
responsive: true,
pagingType: 'simple'
});
$('#myModal').on('shown.bs.modal', function() {
var table = $('#summaryDisplay').DataTable();
table.columns.adjust();
});
</script>
</body>
</html>