-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_results_doubles.php
executable file
·250 lines (224 loc) · 9.76 KB
/
edit_results_doubles.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
<?php
// edit_results_doubles.php
include 'header.php';
require_once 'conn.php';
require 'auth.php';
redirect_if_not_logged_in();
require_non_player();
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Database connection failed: " . $conn->connect_error);
}
// Define stages
$stages = ['Preliminary', 'Quarterfinal', 'Semifinal', 'Final', 'Champion'];
// Handle updates
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['edit_match'])) {
$match_id = $_POST['match_id'];
$stage = $_POST['stage'];
$match_date = $_POST['match_date'];
$match_time = $_POST['match_time'];
$set1_team1_points = $_POST['set1_team1_points'];
$set1_team2_points = $_POST['set1_team2_points'];
$set2_team1_points = $_POST['set2_team1_points'];
$set2_team2_points = $_POST['set2_team2_points'];
$set3_team1_points = $_POST['set3_team1_points'];
$set3_team2_points = $_POST['set3_team2_points'];
$update_query = "
UPDATE matches SET
stage = '$stage',
match_date = '$match_date',
match_time = '$match_time',
set1_team1_points = $set1_team1_points,
set1_team2_points = $set1_team2_points,
set2_team1_points = $set2_team1_points,
set2_team2_points = $set2_team2_points,
set3_team1_points = $set3_team1_points,
set3_team2_points = $set3_team2_points
WHERE id = $match_id
";
$conn->query($update_query);
}
if (isset($_POST['delete_match'])) {
$match_id = $_POST['match_id'];
$delete_query = "DELETE FROM matches WHERE id = $match_id";
$conn->query($delete_query);
}
}
// Fetch filters
$tournament_id = $_GET['tournament_id'] ?? '';
$category_id = $_GET['category_id'] ?? '';
$player_id = $_GET['player_id'] ?? '';
$match_date = $_GET['match_date'] ?? '';
$datetime = $_GET['datetime'] ?? '';
// Fetch data for dropdowns
$tournaments = $conn->query("SELECT id, name FROM tournaments");
$categories = $conn->query("SELECT id, name FROM categories");
$players = $conn->query("SELECT id, name FROM players");
$dates = $conn->query("SELECT DISTINCT match_date FROM matches ORDER BY match_date");
$datetimes = $conn->query("SELECT DISTINCT match_time FROM matches ORDER BY match_time");
// Build the query with optional filters
$query = "
SELECT
m.id AS match_id,
t.name AS tournament_name,
c.name AS category_name,
c.type AS category_type,
p1.name AS team1_player1_name,
p2.name AS team1_player2_name,
p3.name AS team2_player1_name,
p4.name AS team2_player2_name,
m.stage,
m.match_date,
m.match_time,
m.set1_team1_points,
m.set1_team2_points,
m.set2_team1_points,
m.set2_team2_points,
m.set3_team1_points,
m.set3_team2_points
FROM matches m
INNER JOIN tournaments t ON m.tournament_id = t.id
INNER JOIN categories c ON m.category_id = c.id
LEFT JOIN players p1 ON m.team1_player1_id = p1.id
LEFT JOIN players p2 ON m.team1_player2_id = p2.id
LEFT JOIN players p3 ON m.team2_player1_id = p3.id
LEFT JOIN players p4 ON m.team2_player2_id = p4.id
WHERE c.type IN ('doubles', 'mixed doubles')
";
if ($tournament_id) {
$query .= " AND m.tournament_id = $tournament_id";
}
if ($category_id) {
$query .= " AND m.category_id = $category_id";
}
if ($player_id) {
$query .= " AND (
m.team1_player1_id = $player_id OR
m.team1_player2_id = $player_id OR
m.team2_player1_id = $player_id OR
m.team2_player2_id = $player_id
)";
}
if ($match_date) {
$query .= " AND m.match_date = '$match_date'";
}
if ($datetime) {
$query .= " AND m.match_time = '$datetime'";
}
$query .= " ORDER BY m.id";
$result = $conn->query($query);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Doubles Match Results</title>
</head>
<body>
<h1>Doubles Match Results</h1>
<!-- Filter Form -->
<form method="get">
<label for="tournament_id">Tournament:</label>
<select name="tournament_id" id="tournament_id">
<option value="">All Tournaments</option>
<?php while ($row = $tournaments->fetch_assoc()): ?>
<option value="<?= $row['id'] ?>" <?= $tournament_id == $row['id'] ? 'selected' : '' ?>>
<?= $row['name'] ?>
</option>
<?php endwhile; ?>
</select>
<label for="category_id">Category:</label>
<select name="category_id" id="category_id">
<option value="">All Categories</option>
<?php while ($row = $categories->fetch_assoc()): ?>
<option value="<?= $row['id'] ?>" <?= $category_id == $row['id'] ? 'selected' : '' ?>>
<?= $row['name'] ?>
</option>
<?php endwhile; ?>
</select>
<label for="player_id">Player:</label>
<select name="player_id" id="player_id">
<option value="">All Players</option>
<?php while ($row = $players->fetch_assoc()): ?>
<option value="<?= $row['id'] ?>" <?= $player_id == $row['id'] ? 'selected' : '' ?>>
<?= $row['name'] ?>
</option>
<?php endwhile; ?>
</select>
<label for="match_date">Match Date:</label>
<select name="match_date" id="match_date">
<option value="">All Dates</option>
<?php while ($row = $dates->fetch_assoc()): ?>
<option value="<?= $row['match_date'] ?>" <?= $match_date == $row['match_date'] ? 'selected' : '' ?>>
<?= $row['match_date'] ? date("d-m-Y", strtotime($row['match_date'])) : 'N/A' ?>
</option>
<?php endwhile; ?>
</select>
<label for="datetime">Match Time:</label>
<select name="datetime" id="datetime">
<option value="">All Times</option>
<?php while ($row = $datetimes->fetch_assoc()): ?>
<option value="<?= $row['match_time'] ?>" <?= $datetime == $row['match_time'] ? 'selected' : '' ?>>
<?= $row['match_time'] ? date("h:i A", strtotime($row['match_time'])) : 'N/A' ?>
</option>
<?php endwhile; ?>
</select>
<button type="submit">Filter</button>
</form>
<!-- Results Table -->
<?php if ($result->num_rows > 0): ?>
<table>
<tr>
<th>Match ID</th>
<th>Tournament</th>
<th>Category</th>
<th>Team 1</th>
<th>Team 2</th>
<th>Stage</th>
<th>Match Date</th>
<th>Match Time</th>
<th>Set 1</th>
<th>Set 2</th>
<th>Set 3</th>
<th>Winner</th>
<th>Actions</th>
</tr>
<?php while ($row = $result->fetch_assoc()): ?>
<form method="post">
<tr>
<td><?= $row['match_id'] ?><input type="hidden" name="match_id" value="<?= $row['match_id'] ?>"></td>
<td><?= $row['tournament_name'] ?></td>
<td><?= $row['category_name'] ?></td>
<td class="team-column"><?= $row['team1_player1_name'] . " & " . $row['team1_player2_name'] ?></td>
<td class="team-column"><?= $row['team2_player1_name'] . " & " . $row['team2_player2_name'] ?></td>
<td>
<select name="stage">
<?php foreach ($stages as $stage): ?>
<option value="<?= $stage ?>" <?= $row['stage'] === $stage ? 'selected' : '' ?>>
<?= $stage ?>
</option>
<?php endforeach; ?>
</select>
</td>
<td><input type="date" name="match_date" value="<?= $row['match_date'] ?>"></td>
<td><input type="time" name="match_time" value="<?= $row['match_time'] ?>"></td>
<td class="set-column"><input type="number" name="set1_team1_points" value="<?= $row['set1_team1_points'] ?>"> - <input type="number" name="set1_team2_points" value="<?= $row['set1_team2_points'] ?>"></td>
<td class="set-column"><input type="number" name="set2_team1_points" value="<?= $row['set2_team1_points'] ?>"> - <input type="number" name="set2_team2_points" value="<?= $row['set2_team2_points'] ?>"></td>
<td class="set-column"><input type="number" name="set3_team1_points" value="<?= $row['set3_team1_points'] ?>"> - <input type="number" name="set3_team2_points" value="<?= $row['set3_team2_points'] ?>"></td>
<td><?= $row['set1_team1_points'] + $row['set2_team1_points'] + $row['set3_team1_points'] > $row['set1_team2_points'] + $row['set2_team2_points'] + $row['set3_team2_points'] ? "Team 1" : "Team 2" ?></td>
<td>
<button type="submit" name="edit_match">Edit</button>
<button type="submit" name="delete_match" onclick="return confirm('Are you sure you want to delete this match?')">Delete</button>
</td>
</tr>
</form>
<?php endwhile; ?>
</table>
<?php else: ?>
<p>No matches found for the selected filters.</p>
<?php endif; ?>
<?php $conn->close(); ?>
</body>
</html>