-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage_tournaments.php
434 lines (358 loc) · 12.7 KB
/
manage_tournaments.php
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<?php
// manage_tournaments.php
// Include necessary files and initialize the session
error_reporting(E_ALL);
ini_set('display_errors', '1');
session_start();
require_once "./connect_db.php"; // Connect to your database
// Check if the admin is logged in
if (!isset($_SESSION['admin_username'])) {
echo "Unauthorized access. Please log in as an admin.";
header("Location: ./admin.php");
exit();
}
$tournament_id = isset($_GET['tournament_id']) ? $_GET['tournament_id'] : null;
// Check if a valid tournament ID is provided
if ($tournament_id === null) {
echo "Invalid tournament ID.";
exit();
}
// Fetch tournament from the database
$tournament_query = $conn->prepare("SELECT * FROM tournament WHERE tournament_id = ?");
$tournament_query->bind_param('i', $tournament_id);
$tournament_query->execute();
$tournament_result = $tournament_query->get_result();
if (!$tournament_result) {
echo "Error fetching tournament: " . $conn->error;
exit();
}
$error_msg = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$action = isset($_POST['action']) ? $_POST['action'] : '';
if ($action === 'edit') {
// Handle tournament edit
$edited_tournament_name = $_POST['tournament_name'];
$edited_start_date = isset($_POST['start_date']) ? $_POST['start_date'] : null;
$edited_tournament_type = isset($_POST['tournament_type']) ? $_POST['tournament_type'] : null;
// Build the query based on provided data
$query_tournament = "UPDATE tournament SET ";
$updates = array();
if (!empty($edited_tournament_name)) {
$updates[] = "tournament_name = '$edited_tournament_name'";
}
if (!is_null($edited_start_date) && $edited_start_date !== '') {
$updates[] = "start_date = '$edited_start_date'";
}
if (!is_null($edited_tournament_type)) {
$updates[] = "model = '$edited_tournament_type'";
}
if (!empty($updates)) {
$query_tournament .= implode(', ', $updates);
$query_tournament .= " WHERE tournament_id = $tournament_id";
// Update the tournament
if ($conn->query($query_tournament) === TRUE) {
$error_msg = "Tournament updated successfully: '$edited_tournament_name'";
header("Location: manage_tournaments.php?tournament_id=$tournament_id"); // Redirect to the admin dashboard
exit();
} else {
$error_msg = "Error updating the tournament: " . $conn->error;
}
} else {
$error_msg = "No updates provided.";
}
} elseif ($action === 'status') {
// Handle tournament status change (stop/start)
$registration_open = isset($_POST['stop']) ? 0 : 1;
$query_tournament = "UPDATE tournament SET registration_open = $registration_open WHERE tournament_id = $tournament_id";
if ($conn->query($query_tournament) === TRUE) {
$error_msg = "Tournament registration status updated successfully.";
} else {
$error_msg = "Error updating tournament registration status: " . $conn->error;
}
}
}
$conn->close(); // Close the database connection
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Tournament</title>
<link rel="stylesheet" href="./styles/admin-general.css">
<link rel="stylesheet" href="./styles/general.css">
<style>
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
z-index:2;
}
th, td {
border: 1px solid #ccc;
padding: 10px;
text-align: left;
}
th {
background-color: #f0f0f0;
}
th:nth-child(1), th:nth-child(5),
td:nth-child(1), td:nth-child(5) {
width: 10%;
}
td a {
margin-right: 10px;
}
.card {
border: 1px solid #ccc;
padding: 20px;
margin: 10px 0;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
display:flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.card h3 {
margin-top: 0;
}
.card p {
margin-bottom: 0;
}
/* */
/* body {
font-family: Arial, sans-serif;
background: linear-gradient(to bottom, #fffafa, #848482);
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
} */
.register {
max-width: 350px;
padding: 20px;
/* box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); */
border-radius: 10px;
background-color: white;
text-align: center;
}
.card h2 {
margin-bottom: 20px;
color: #333;
}
.card input,
.card select {
width: calc(100% - 20px);
padding: 10px;
margin-bottom: 15px;
border-radius: 5px;
border: 1px solid #ccc;
box-sizing: border-box;
}
/* .card input:focus,
.card select:focus {
outline: blue;
} */
.card select {
background-color: white;
}
.card input[type="submit"] {
background-color: #007BFF;
color: white;
border: none;
cursor: pointer;
}
.card input[type="submit"]:hover {
background-color: #0056b3;
}
.card p {
color: #555;
font-size: 14px;
}
.card a {
color: #007BFF;
text-decoration: none;
cursor: pointer;
}
.card a:hover {
text-decoration: underline;
}
.error-msg {
background-color: #f8f9fa;
/* Light gray background */
color: green;
/* Green text */
font-weight: bold;
display: none;
}
.edit-card,
.delete-card,
.stop-card{
display:none;
}
.slide-in {
animation: slide-in 0.3s forwards;
}
/* Define a class for slide-out effect */
.slide-out {
animation: slide-out 0.3s forwards;
}
@keyframes slide-in {
from {
transform: translateX(-50%);
}
to {
transform: translateX(0);
}
}
@keyframes slide-out {
from {
transform: translate(0);
}
to {
transform: translateX(100%);
}
}
</style>
</head>
<body>
<header>
<div class="header-card1">
<h1>Manage Tournament</h1>
<a href="logout.php">Log out</a>
</div>
</header>
<main>
<section>
<h2>Tournaments List</h2>
<table>
<thead>
<tr>
<th>Tourney ID</th>
<th>Tourney Name</th>
<th>Tourney Type</th>
<th>Start Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
// Display tournament details and options
while ($row = $tournament_result->fetch_assoc()) {
echo "<tr>
<td>{$row['tournament_id']}</td>
<td>{$row['tournament_name']}</td>
<td>{$row['model']}</td>
<td>{$row['start_date']}</td>
<td>
<a onclick='showEditCard();'>Edit</a><br>
<a onclick='showStopCard();'>Stop</a>
</td>
</tr>";
}
if ($tournament_result->num_rows == 0) {
echo "<tr><td colspan='5'>No data available</td></tr>";
}
// <a onclick='showDeleteCard();'>Delete</a><br>
?>
</tbody>
</table>
<div class="card edit-card" id="editCard">
<button onclick="hideEditCard();" class="card-close-btn" id=""><img src="./images/x-lg.svg" class="close-img"></button>
<!-- Tournament edit card content -->
<div class="card">
<div class="register">
<h2>Tournament Edit</h2>
<!-- Your registration form here -->
<form action="" method="POST">
<input type="text" id="tournament_name" name="tournament_name" placeholder="Tournament Name"
><br>
<input type="date" id="start_date" name="start_date" placeholder="Edit Start Date" ><br>
<select class="select" name="tournament_type" >
<option value="" disabled selected>Select Your Tournament Type</option>
<option value="league">league</option>
<option value="knockout">knockout</option>
</select>
<input type="hidden" name="action" value="edit"> <!-- Hidden field to indicate registration -->
<input type="submit" value="Edit">
</form>
<?php echo "<p class='error-msg' style='color:red;'>$error_msg </P>" ?>
</div>
</div>
</div>
<!-- <div class="card delete-card" id="deleteCard">
Tournament delete card content
<button onclick="hideDeleteCard();" class="card-close-btn" id=""><img src="images/x-lg.svg" class="close-img"></button>
<div class="card">
<p>Are you sure you want to delete the tournament?
<form action="" method="post">
<input type="hidden" name="action" onclick="alert('are you sure ?')">
<button name="delete" value="delete">yes</button>
<button >no</button>
</form>
</p>
</div>
</div> -->
<div class="card stop-card" id="stopCard">
<button onclick="hideStopCard();" class="card-close-btn" id=""><img src="./images/x-lg.svg" class="close-img"></button>
<!-- Tournament stop card content -->
<div class="card">
card stop registeration to tournament
<form action="" method="post">
<input type="hidden" name="action" value="status">
<button type="submit" name="stop" value="stop">Stop</button>
<button type="submit" name="start" value="start">Start</button>
</form>
</div>
</div>
</section>
</main>
<a href="tournament_home.php?tournament_id=<?php echo $tournament_id; ?>">
<button class="return" style="background-color:lightblue"><img src="./images/x-lg.svg" class="close-img" > </button>
</a>
<script>
function showEditCard() {
const editCard = document.getElementById('editCard');
editCard.classList.add('slide-in');
editCard.style.display = 'block';
}
function hideEditCard() {
const editCard = document.getElementById('editCard');
editCard.classList.add('slide-out');
setTimeout(() => {
editCard.style.display = 'none';
editCard.classList.remove('slide-out');
}, 300);
}
function showDeleteCard() {
const deleteCard = document.getElementById('deleteCard');
deleteCard.classList.add('slide-in');
deleteCard.style.display = 'block';
}
function hideDeleteCard() {
const deleteCard = document.getElementById('deleteCard');
deleteCard.classList.add('slide-out');
setTimeout(() => {
deleteCard.style.display = 'none';
deleteCard.classList.remove('slide-out');
}, 300);
}
function showStopCard() {
const stopCard = document.getElementById('stopCard');
stopCard.classList.add('slide-in');
stopCard.style.display = 'block';
}
function hideStopCard() {
const stopCard = document.getElementById('stopCard');
stopCard.classList.add('slide-out');
setTimeout(() => {
stopCard.style.display = 'none';
stopCard.classList.remove('slide-out');
}, 300);
}
</script>
</body>
</html>