/
osmatches.php
300 lines (270 loc) · 7.27 KB
/
osmatches.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
<?php
// Copyright 2011-7 John Collins
// *********************************************************************
// Please do not edit the live file directly as it will break the "Git"
// mechanism to update the live files automatically when a new version
// is pushed. Thanks!
// *********************************************************************
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
include 'php/html_blocks.php';
include 'php/error_handling.php';
include 'php/connection.php';
include 'php/opendatabase.php';
include 'php/club.php';
include 'php/rank.php';
include 'php/player.php';
include 'php/team.php';
include 'php/match.php';
include 'php/matchdate.php';
include 'php/game.php';
include 'php/params.php';
include 'php/hcp_message.php';
$Connection = opendatabase(true);
$asuser = $Connection->userid;
if ($Connection->admin && strlen($_GET["asuser"]) != 0)
$asuser = $_GET["asuser"];
// Get parameters to include handicap info
$pars = new Params();
$pars->fetchvalues();
$player = new Player();
try {
$player->fromid($asuser);
}
catch (PlayerException $e) {
wrongentry($e->getMessage());
}
// Get the teams this player is captain of
try {
$captain_of = list_teams_captof($player);
}
catch (TeamException $e) {
wrongentry($e->getMessage());
}
$unalloc_matches = array();
$oppunalloc_matches = array();
$unplayed_matches = array();
// Do each team in turn it's easier to code
foreach ($captain_of as $team) {
$ret = $Connection->query("SELECT ind FROM lgmatch WHERE (result='N' OR result='P') AND ({$team->queryof('hteam')} OR {$team->queryof('ateam')}) ORDER BY matchdate");
if ($ret && $ret->num_rows > 0) {
while ($row = $ret->fetch_array()) {
try {
$mtch = new Match($row[0]);
$mtch->fetchdets();
$mtch->fetchteams();
$mtch->fetchgames();
if ($mtch->is_allocated()) {
array_push($unplayed_matches, $mtch);
}
elseif ($mtch->team_allocated($team)) {
array_push($oppunalloc_matches, $mtch);
}
else {
array_push($unalloc_matches, $mtch);
}
}
catch (MatchException $e) {
continue;
}
}
}
}
lg_html_header("Outstanding Matches");
lg_html_nav();
if (count($captain_of) > 0 && (count($unplayed_matches) > 0 || count($unalloc_matches) > 0 || count($oppunalloc_matches) > 0)) {
$tnames = array();
foreach ($captain_of as $team) {
array_push($tnames, $team->display_name());
}
$tnames = join(', ', $tnames);
print <<<EOT
<h1>Team captain tasks</h1>
<p>In your capacity as team captain of $tnames please complete the following:</p>
EOT;
if (count($unalloc_matches) > 0) {
print <<<EOT
<h2>Matches to have teams allocated</h2>
<p>Please can you allocate teams to the following matches</p>
<table class="matchesosd">
<tr>
<th>Date</th>
<th>Team A</th>
<th>Team B</th>
<th>Status</th>
</tr>
EOT;
foreach ($unalloc_matches as $mtch) {
$c = $mtch->is_captain($username);
$href = $aref = $hndref = $andref = '';
$ht = $mtch->Hteam->display_name();
$at = $mtch->Ateam->display_name();
if ($c == 'H' || $c == 'B') {
$href = "<a href=\"tcupdmatch.php?{$mtch->urlof()}&hora=H\" class=\"noundm\">";
$hndref = "</a>";
}
if ($c == 'A' || $c == 'B') {
$aref = "<a href=\"tcupdmatch.php?{$mtch->urlof()}&hora=A\" class=\"noundm\">";
$andref = "</a>";
}
print <<<EOT
<tr>
<td>{$mtch->Date->display_month()}</td>
<td>$href$ht$hndref</td>
<td>$aref$at$andref</td>
<td>TBA</td>
</tr>
EOT;
}
print "</table>\n";
}
if (count($oppunalloc_matches) > 0) {
print <<<EOT
<h2>Matches to have teams allocated by opponents</h2>
<p>I know that you have allocated teams to the following matches, but please
can you chase your opponents to do so in the following matches</p>
<table class="matchesosd">
<tr>
<th>Date</th>
<th>Team A</th>
<th>Team B</th>
<th>Status</th>
</tr>
EOT;
foreach ($oppunalloc_matches as $mtch) {
$c = $mtch->is_captain($username);
$href = $aref = $hndref = $andref = '';
$ht = $mtch->Hteam->display_name();
$at = $mtch->Ateam->display_name();
if ($c == 'H') {
$href = "<a href=\"tcupdmatch.php?{$mtch->urlof()}&hora=H\" class=\"noundm\">";
$hndref = "</a>";
}
else {
$aref = "<a href=\"tcupdmatch.php?{$mtch->urlof()}&hora=A\" class=\"noundm\">";
$andref = "</a>";
}
print <<<EOT
<tr>
<td>{$mtch->Date->display_month()}</td>
<td>$href$ht$hndref</td>
<td>$aref$at$andref</td>
<td>TBA</td>
</tr>
EOT;
}
print "</table>\n";
}
if (count($unplayed_matches) > 0) {
print <<<EOT
<h2>Unfinished matches</h2>
<p>Please can you organise for the following matches to be completed</p>
<table class="matchesosd">
<tr>
<th>Date</th>
<th>Team A</th>
<th>Team B</th>
<th>Status</th>
</tr>
EOT;
foreach ($unplayed_matches as $mtch) {
$href = $aref = $hndref = $andref = '';
$ht = $mtch->Hteam->display_name();
$at = $mtch->Ateam->display_name();
if ($mtch->Result == 'H')
$ht = "<b>$ht</b>";
else if ($mtch->Result == 'A')
$at = "<b>$at</b>";
$ref = "<a href=\"showmtch.php?{$mtch->urlof()}\" class=\"noundd\">";
if ($mtch->Result == 'P') {
$res = "Part played ({$mtch->summ_score()})";
}
else
$res = "Not played";
print <<<EOT
<tr>
<td>{$mtch->Date->display_month()}</td>
<td>$ref$ht</a></td>
<td>$ref$at</a></td>
<td>$res</td>
</tr>
EOT;
}
print "</table>\n";
}
}
// Now for user's games
print <<<EOT
<h1>Outstanding games for {$player->display_name(false)}</h1>
EOT;
$osgames = array();
$ret = $Connection->query("SELECT ind FROM game WHERE result='N' AND (({$player->queryof('w')}) OR ({$player->queryof('b')})) ORDER BY matchdate");
if ($ret && $ret->num_rows > 0) {
while ($row = $ret->fetch_array()) {
try {
$g = new Game($row[0]);
$g->fetchdets();
if (!$g->Wteam || !$g->Bteam)
continue;
array_push($osgames, $g);
}
catch (GameException $e) {
continue;
}
}
}
if (count($osgames) == 0)
print <<<EOT
<p>You currently do not have any outstanding games to play.</p>
EOT;
else {
print <<<EOT
<table class="showmatch">
<tr>
<th colspan="4" align="center">White</th>
<th colspan="4" align="center">Black</th></tr>
<tr>
<th>Player</th>
<th>Rank</th>
<th>Online</th>
<th>Team</th>
<th>Player</th>
<th>Rank</th>
<th>Online</th>
<th>Team</th>
<th>Hcp</th>
</tr>
EOT;
foreach ($osgames as $g) {
$hcp = hcp_message($g, $pars);
if (!$hcp)
$hcp = "None";
print <<<EOT
<tr>
<td>{$g->Wplayer->display_name()}</td>
<td>{$g->Wplayer->display_rank()}</td>
<td>{$g->Wplayer->display_online()}</td>
<td>{$g->Wteam->display_name()}</td>
<td>{$g->Bplayer->display_name()}</td>
<td>{$g->Bplayer->display_rank()}</td>
<td>{$g->Bplayer->display_online()}</td>
<td>{$g->Bteam->display_name()}</td>
<td>$hcp</td>
<td>{$g->display_result(true)}</td>
</tr>
EOT;
}
print <<<EOT
</table>
EOT;
}
lg_html_footer();
?>