-
Notifications
You must be signed in to change notification settings - Fork 0
/
players.php
233 lines (212 loc) · 6.35 KB
/
players.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
<?php
// TODO: refactor
require_once 'private_php/p_global.php';
require_once 'private_php/p_html_functions.php';
abstract class GradeType {
const Standard = 0;
const Rapid = 1;
const LrcaRapid = 2;
}
$clubID = @$_GET['cid'];
// make sure the club ID exists, and get the name of the club
if ($clubID) {
if (!is_numeric($clubID)) errorPage(404);
$clubID = (int) $clubID;
$stmt = $Database->prepare('SELECT name FROM club WHERE club_id = ?');
$stmt->execute([$clubID]);
if (!!($row = $stmt->fetch())) {
$pageTitle = $row['name'] . ' Player List';
} else {
errorPage(404);
}
} else {
$pageTitle = 'Player List';
}
if (isset($_GET['ps'])) {
$playerStatusFilter = $_GET['ps'];
// string must be a comma-separated list containing only 0/1/2
if (!preg_match('/^[0-2](,[0-2])*$/', $playerStatusFilter)) errorPage(404);
} else {
// default to active only
$playerStatusFilter = '1';
}
$season = @(int) $_GET['season'];
if (!($season == Season::Winter || $season == Season::Summer)) {
switch (SystemSettings::$currentSeason) {
case Season::BothDefaultWinter: $season = Season::Winter; break;
case Season::BothDefaultSummer: $season = Season::Summer; break;
default: $season = SystemSettings::$currentSeason;
}
}
$chooseSeason
= SystemSettings::$currentSeason == Season::BothDefaultWinter
|| SystemSettings::$currentSeason == Season::BothDefaultSummer;
pageHeader($pageTitle);
?>
<div id="subNav">
<!--<ul><li><a href="barred">Barred Players</a></li></ul>-->
<form method="get" action="./">
<p>Club:<br />
<select name="cid"><?php
renderSelectOption('', $clubID, 'All');
$stmt = $Database->query('SELECT club_id, name FROM club WHERE status = 1 ORDER BY name');
while (!!($row = $stmt->fetch())) {
renderSelectOption($row['club_id'], $clubID, $row['name']);
}
?></select>
</p>
<p>Players to show:<br />
<select name="ps"><?php
renderSelectOption('0,1,2', $playerStatusFilter, 'Active and Inactive');
renderSelectOption('1', $playerStatusFilter, 'Active Only');
renderSelectOption('0,2', $playerStatusFilter, 'Inactive Only');
?></select>
</p>
<?php if ($chooseSeason) { ?>
<p>Grades to show:<br />
<select name="season"><?php
if (SystemSettings::$summerYear <= SystemSettings::$winterYear) {
renderSelectOption(Season::Summer, $season, 'January ' . SystemSettings::$summerYear);
renderSelectOption(Season::Winter, $season, 'July ' . SystemSettings::$winterYear);
} else {
renderSelectOption(Season::Winter, $season, 'July ' . SystemSettings::$winterYear);
renderSelectOption(Season::Summer, $season, 'January ' . SystemSettings::$summerYear);
}
?></select>
</p>
<?php } ?>
<p><input type="submit" value="Filter" /></p>
</form>
</div>
<div id="subBody">
<h2><?php echo htmlspecialchars($pageTitle); ?></h2>
<h3 class="sub">With <?php
switch ($season) {
case Season::Winter:
echo 'July ', SystemSettings::$winterYear;
break;
case Season::Summer:
echo 'January ', SystemSettings::$summerYear;
break;
}
?> Grades</h3>
<table class="players">
<colgroup><col class="ecfCode" /></colgroup>
<colgroup><col class="name" /></colgroup>
<?php if (!$clubID) { ?>
<colgroup><col class="club" /></colgroup>
<?php } ?>
<colgroup><col class="grade" /><col class="cat" /></colgroup>
<colgroup><col class="grade" /><col class="cat" /></colgroup>
<colgroup><col class="grade" /></colgroup>
<thead>
<tr>
<th rowspan="2">ECF Code</th>
<th rowspan="2">Name</th>
<?php if (!$clubID) { ?>
<th rowspan="2">Club</th>
<?php } ?>
<th colspan="2">Standard</th>
<th colspan="2">Rapid</th>
<th>LRCA Rapid</th>
</tr>
<tr>
<th>Grade</th>
<th>Cat</th>
<th>Grade</th>
<th>Cat</th>
<th>Grade</th>
</tr>
</thead>
<tbody><?php
$sql = "
SELECT p.player_id, p.forename, p.surname, p.ecf_grading_code, c.name AS club_name
FROM player p JOIN club c ON p.club_id = c.club_id
WHERE p.status IN ($playerStatusFilter)";
if ($clubID) {
$sql .= " AND c.club_id = $clubID"; // this is safe, as $clubID has been forced to integer type
}
$sql .= ' ORDER BY p.surname, p.forename';
$stmtPlayer = $Database->query($sql);
// OPTIMISE: cut number of calls to db
$stmtGrade = $Database->prepare('
SELECT g1.type, g1.effective_from, NullIf(g1.grade, 0) AS grade, g1.category
FROM grade g1
LEFT JOIN grade g2
ON g1.player_id = g2.player_id
AND g1.season = g2.season
AND g1.type = g2.type
AND g1.effective_from < g2.effective_from
AND g2.effective_from <= ?
WHERE g1.effective_from <= ?
AND g1.player_id = ? AND g1.season = ?
AND g2.grade_id IS NULL');
$today = date('c');
while ($player = $stmtPlayer->fetch()) {
$stmtGrade->execute([$today, $today, $player['player_id'], $season]);
$grade = $stmtGrade->fetch();
?>
<tr>
<td><?php
$ecfCode = $player['ecf_grading_code'];
if ($ecfCode) {
echo "<a href='http://www.ecfgrading.org.uk/new/player.php?PlayerCode=$ecfCode'>$ecfCode</a>";
}
?></td>
<td>
<a href="<?php echo $player['player_id']; ?>">
<?php echo htmlspecialchars($player['surname']), ', ', htmlspecialchars($player['forename']); ?>
</a>
</td>
<?php
if (!$clubID) {
?>
<td><?php echo htmlspecialchars($player['club_name']); ?></td>
<?php
}
// render the player's grades
if ($grade && $grade['type'] == GradeType::Standard) {
?>
<td class="grade"><?php echo $grade['grade']; ?></td>
<td class="cat"><?php echo $grade['category']; ?></td>
<?php
$grade = $stmtGrade->fetch();
} else {
?>
<td class="grade"></td>
<td class="cat"></td>
<?php
}
if ($grade && $grade['type'] == GradeType::Rapid) {
?>
<td class="grade"><?php echo $grade['grade']; ?></td>
<td class="cat"><?php echo $grade['category']; ?></td>
<?php
$grade = $stmtGrade->fetch();
} else {
?>
<td class="grade"></td>
<td class="cat"></td>
<?php
}
if ($grade && $grade['type'] == GradeType::LrcaRapid) {
?>
<td class="grade"><?php echo $grade['grade']; ?></td>
<?php
$grade = $stmtGrade->fetch();
} else {
?>
<td class="grade"></td>
<?php
}
?>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<?php
pageFooter();
?>