-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage_fixtures.php
196 lines (156 loc) · 5.68 KB
/
manage_fixtures.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
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
session_start();
require_once "./connect_db.php"; // Connect to your database
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;
if ($tournament_id === null) {
echo "Invalid tournament ID.";
exit();
}
function getTeamsForTournament($tournament_id, $conn) {
$query = "SELECT team_id FROM teams WHERE tournament_id = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("i", $tournament_id);
$stmt->execute();
$result = $stmt->get_result();
$team_ids = [];
while ($row = $result->fetch_assoc()) {
$team_ids[] = $row['team_id'];
}
return $team_ids;
}
$query = "SELECT team_id, club_id FROM teams WHERE tournament_id = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("i", $tournament_id);
$stmt->execute();
$result = $stmt->get_result();
$clubs = [
"1" => ["image" => 'images/psg.webp', "clubName" => "P-S-G"],
"2" => ["image" => 'images/Fcb.webp', "clubName" => "FC Barcelona"],
"3" => ["image" => 'images/real_madrid.webp', "clubName" => "Real Madrid"],
"4" => ["image" => 'images/Manchester-United-Logo.webp', "clubName" => "Manchester United"],
"5" => ["image" => 'images/m-city.webp', "clubName" => "Manchester City"],
"6" => ["image" => 'images/benfica.webp', "clubName" => "Benfica"],
"7" => ["image" => 'images/napoli.webp', "clubName" => "Napoli"],
"8" => ["image" => 'images/ac-milan-logo.webp', "clubName" => "AC Milan"],
"9" => ["image" => 'images/arsenal-logo-0.webp', "clubName" => "Arsenal"],
"10" => ["image" => 'images/Chelsea-Logo.webp', "clubName" => "Chelsea"],
"11" => ["image" => 'images/new-castle.webp', "clubName" => "New Castle"],
"12" => ["image" => 'images/bayern.webp', "clubName" => "Bayern"],
"13" => ["image" => 'images/logo-de-juventus.webp', "clubName" => "Juventus"],
"14" => ["image" => 'images/new-castle.webp', "clubName" => "New Castle"],
"15" => ["image" => 'images/inter-logo.webp', "clubName" => "Inter Milan"],
"16" => ["image" => 'images/liverpool-fc-logo.webp', "clubName" => "Liverpool"],
];
$position = 0;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Main Page</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
h1 {
text-align: center;
margin-bottom: 20px;
}
.actions {
text-align: center;
margin-bottom: 20px;
}
.actions button {
padding: 10px 20px;
font-size: 18px;
margin: 0 10px;
}
.fixtures {
margin-left: 20px;
}
.fixtures h2 {
margin-top: 20px;
}
.fixtures h3 {
margin-top: 10px;
}
.fixtures ul {
list-style-type: none;
padding: 0;
}
.fixtures ul li {
margin-bottom: 10px;
}
</style>
</head>
<body>
<h1>Main Page</h1>
<!-- Buttons to trigger actions -->
<div class="actions">
<form action="manage_the_fixtures.php?tournament_id=<?php echo $tournament_id; ?>" method="post" style="display: inline;">
<input type="hidden" name="action" value="generate">
<button type="submit" name="perform_action" value="true">Generate Fixtures</button>
</form>
<form action="manage_the_fixtures.php?tournament_id=<?php echo $tournament_id; ?>" method="post" style="display: inline;">
<input type="hidden" name="action" value="update">
<button type="submit" name="perform_action" value="true">Update Fixtures</button>
</form>
</div>
<div class="fixtures">
<table>
<thead>
<tr>
<th>Position</th>
<th>Team ID</th>
<th>Club ID</th>
<th>Club Name</th>
<th>Logo</th>
</tr>
<thead>
<tbody>"
<!-- Display generated fixtures here -->
<?php
$team_ids = getTeamsForTournament($tournament_id, $conn);
echo "<h2>Teams for Tournament</h2>";
echo "<ul>";
foreach ($team_ids as $team_id) {
echo "<li>Team $team_id </li>";
}
while ($row = $result->fetch_assoc()) {
$team_id = $row['team_id'];
$club_id = $row['club_id'];
// Check if the club ID exists in the $clubs array
if (array_key_exists($club_id, $clubs)) {
$clubInfo = $clubs[$club_id];
$image = $clubInfo["image"];
$clubName = $clubInfo["clubName"];
} else {
// Use default values if the club ID is not recognized
$image = 'images/logo.webp';
$clubName = "Unknown Club";
}
$position++;
echo "<tr>";
// Output the team information
echo "<td>$position</td>";
echo "<td>Team $team_id</td>";
echo "<td>$clubName</td>";
echo "<td>$club_id</td>";
echo "<td><img src='$image' alt='$clubName' width='50' height='50'></td>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
</body>
</html>