-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert_match_gd copy 2.php
executable file
·277 lines (246 loc) · 10.6 KB
/
insert_match_gd copy 2.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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
////require_once 'permissions.php';
include 'header.php';
require 'auth.php';
redirect_if_not_logged_in();
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
$message = '';
$lockedTournament = $_SESSION['locked_tournament'] ?? null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['lock_tournament'])) {
$lockedTournament = intval($_POST['tournament_id']);
$_SESSION['locked_tournament'] = $lockedTournament;
$stmt = $conn->prepare("SELECT name FROM tournaments WHERE id = ?");
$stmt->bind_param("i", $lockedTournament);
$stmt->execute();
$stmt->bind_result($lockedTournamentName);
$stmt->fetch();
$_SESSION['locked_tournament_name'] = $lockedTournamentName;
$stmt->close();
} elseif (isset($_POST['unlock_tournament'])) {
unset($_SESSION['locked_tournament'], $_SESSION['locked_tournament_name']);
$lockedTournament = null;
} else {
// Fetch inputs with default values to avoid warnings
$tournament_id = $lockedTournament ?? ($_POST['tournament_id'] ?? null);
$category_id = $_POST['category_id'] ?? null;
$team1_player1_id = $_POST['team1_player1_id'] ?? null;
$team1_player2_id = $_POST['team1_player2_id'] ?? null;
$team2_player1_id = $_POST['team2_player1_id'] ?? null;
$team2_player2_id = $_POST['team2_player2_id'] ?? null;
$stage = $_POST['stage'] ?? null;
$dateInput = $_POST['date'] ?? null;
$match_date = $dateInput ? DateTime::createFromFormat('Y-m-d', $dateInput) : null;
if ($match_date === false) {
$message = "Invalid date format!";
} else {
$match_date = $match_date ? $match_date->format('Y-m-d') : null;
}
$match_time = $_POST['time'] ?? null;
$set1_team1 = $_POST['set1_team1_points'] ?? null;
$set1_team2 = $_POST['set1_team2_points'] ?? null;
$set2_team1 = $_POST['set2_team1_points'] ?? null;
$set2_team2 = $_POST['set2_team2_points'] ?? null;
$set3_team1 = $_POST['set3_team1_points'] ?? 0;
$set3_team2 = $_POST['set3_team2_points'] ?? 0;
// Validate required fields
if (empty($tournament_id) || empty($category_id) || empty($stage) || empty($match_date) || empty($match_time)) {
$message = "Please fill in all required fields.";
} else {
// Insert match details into the database
$stmt = $conn->prepare("INSERT INTO matches (
tournament_id, category_id, team1_player1_id, team1_player2_id,
team2_player1_id, team2_player2_id, stage, match_date, match_time,
set1_team1_points, set1_team2_points, set2_team1_points,
set2_team2_points, set3_team1_points, set3_team2_points
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param(
"iiiiisssiiiiiii",
$tournament_id, $category_id, $team1_player1_id, $team1_player2_id,
$team2_player1_id, $team2_player2_id, $stage, $match_date, $match_time,
$set1_team1, $set1_team2, $set2_team1, $set2_team2, $set3_team1, $set3_team2
);
if ($stmt->execute()) {
$message = "Match added successfully!";
} else {
$message = "Error adding match: " . $stmt->error;
}
$stmt->close();
}
}
}
$tournaments = $conn->query("SELECT id, name FROM tournaments");
if ($lockedTournament) {
$stmt = $conn->prepare("
SELECT c.id, c.name, c.age_group, c.sex
FROM categories c
INNER JOIN tournament_categories tc ON c.id = tc.category_id
WHERE tc.tournament_id = ?
AND c.name LIKE '%GD%'
");
$stmt->bind_param("i", $lockedTournament);
$stmt->execute();
$categories = $stmt->get_result();
$stmt->close();
} else {
$categories = $conn->query("
SELECT id, name, age_group, sex
FROM categories
WHERE name LIKE '%GD%'
");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Insert Doubles Match</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f7f9fc;
margin: 0;
padding: 0;
color: #333;
}
.container {
max-width: 800px;
margin: 50px auto;
background: #ffffff;
padding: 20px 30px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
h1 {
text-align: center;
color: #007bff;
font-size: 24px;
margin-bottom: 20px;
}
form {
display: flex;
flex-direction: column;
gap: 15px;
}
label {
font-weight: bold;
margin-bottom: 5px;
color: #555;
}
select, input, button {
padding: 10px;
font-size: 16px;
border: 1px solid #ddd;
border-radius: 5px;
width: 100%;
}
select:focus, input:focus {
border-color: #007bff;
outline: none;
box-shadow: 0 0 8px rgba(0, 123, 255, 0.5);
}
button {
background-color: #007bff;
color: #fff;
border: none;
cursor: pointer;
font-weight: bold;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="container">
<h1>Insert Doubles Match</h1>
<?php if ($message): ?>
<p><?= htmlspecialchars($message) ?></p>
<?php endif; ?>
<?php if (!$lockedTournament): ?>
<form method="post">
<label for="tournament_id">Select Tournament:</label>
<select name="tournament_id" id="tournament_id" required>
<option value="">Select Tournament</option>
<?php while ($row = $tournaments->fetch_assoc()): ?>
<option value="<?= $row['id'] ?>"><?= htmlspecialchars($row['name']) ?></option>
<?php endwhile; ?>
</select>
<button type="submit" name="lock_tournament">Lock Tournament</button>
</form>
<?php else: ?>
<form method="post">
<p>Locked Tournament: <?= htmlspecialchars($_SESSION['locked_tournament_name'] ?? '') ?></p>
<button type="submit" name="unlock_tournament">Unlock Tournament</button>
</form>
<?php endif; ?>
<form method="post">
<label for="category_id">Category:</label>
<select name="category_id" id="category_id" required onchange="loadPlayers(this.value)">
<option value="">Select Category</option>
<?php while ($row = $categories->fetch_assoc()): ?>
<option value="<?= $row['id'] ?>"><?= htmlspecialchars($row['name']) ?> (<?= htmlspecialchars($row['age_group']) ?>, <?= htmlspecialchars($row['sex']) ?>)</option>
<?php endwhile; ?>
</select>
<label for="team1_player1_id">Team 1 - Player 1:</label>
<select name="team1_player1_id" id="team1_player1_id" required></select>
<label for="team1_player2_id">Team 1 - Player 2:</label>
<select name="team1_player2_id" id="team1_player2_id" required></select>
<label for="team2_player1_id">Team 2 - Player 1:</label>
<select name="team2_player1_id" id="team2_player1_id" required></select>
<label for="team2_player2_id">Team 2 - Player 2:</label>
<select name="team2_player2_id" id="team2_player2_id" required></select>
<label for="stage">Match Stage:</label>
<select name="stage" id="stage" required>
<option value="">Select Stage</option>
<option value="Pre Quarter Finals">Pre Quarter Finals</option>
<option value="Quarter Finals">Quarter Finals</option>
<option value="Semi Finals">Semi Finals</option>
<option value="Finals">Finals</option>
</select>
<label for="date">Match Date:</label>
<input type="date" name="date" id="date" required>
<label for="time">Match Time:</label>
<input type="time" name="time" id="time" required>
<label for="set1_team1_points">Set 1 Team 1 Points:</label>
<input type="number" name="set1_team1_points" id="set1_team1_points" required>
<label for="set1_team2_points">Set 1 Team 2 Points:</label>
<input type="number" name="set1_team2_points" id="set1_team2_points" required>
<label for="set2_team1_points">Set 2 Team 1 Points:</label>
<input type="number" name="set2_team1_points" id="set2_team1_points" required>
<label for="set2_team2_points">Set 2 Team 2 Points:</label>
<input type="number" name="set2_team2_points" id="set2_team2_points" required>
<label for="set3_team1_points">Set 3 Team 1 Points:</label>
<input type="number" name="set3_team1_points" id="set3_team1_points">
<label for="set3_team2_points">Set 3 Team 2 Points:</label>
<input type="number" name="set3_team2_points" id="set3_team2_points">
<button type="submit">Add Match</button>
</form>
</div>
<script>
function loadPlayers(categoryId) {
if (!categoryId) return;
fetch(`get_players.php?category_id=${categoryId}`)
.then(response => response.json())
.then(data => {
const playerSelects = ['team1_player1_id', 'team1_player2_id', 'team2_player1_id', 'team2_player2_id'];
playerSelects.forEach(selectId => {
const select = document.getElementById(selectId);
select.innerHTML = '<option value="">Select Player</option>';
data.forEach(player => {
const option = document.createElement('option');
option.value = player.id;
option.textContent = `${player.name} (${player.age} years, ${player.sex})`;
select.appendChild(option);
});
});
})
.catch(error => console.error('Error fetching players:', error));
}
</script>
</body>
</html>