/
updmatch.php
260 lines (232 loc) · 7.18 KB
/
updmatch.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
<?php
// Copyright 2011-2021 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/>.
// This is for when an admin wants to edit the match details - members of
// teams selected on each side for a match
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/teammemb.php';
include 'php/match.php';
include 'php/matchdate.php';
include 'php/game.php';
$Connection = opendatabase(true);
$mtch = new Match();
try {
$mtch->fromget();
$mtch->fetchdets();
$mtch->fetchteams();
$mtch->fetchgames();
}
catch (MatchException $e) {
wrongentry($e->getMessage());
}
lg_html_header("Eedit Match");
print <<<EOT
<script language="javascript">
function checkteamsvalid() {
var form = document.matchform;
var force = form.forceass.checked;
var hplayers = new Array(3);
var aplayers = new Array(3);
for (var n = 0; n < 3; n++) {
var el = form["htm" + n];
if (el.selectedIndex <= 0) {
alert("No team 1 player " + (n+1) + " selected");
return false;
}
var opt = el.options;
hplayers[n] = opt[el.selectedIndex].value;
el = form["atm" + n];
if (el.selectedIndex <= 0) {
alert("No team 2 player " + (n+1) + " selected");
return false;
}
opt = el.options;
aplayers[n] = opt[el.selectedIndex].value;
if (force && form["colours" + n].selectedIndex <= 0) {
alert("No colours selected for board " + (n+1));
return false;
}
}
for (var p1 = 0; p1 < 2; p1++) {
for (var p2 = p1 + 1; p2 < 3; p2++) {
if (hplayers[p1] == hplayers[p2]) {
alert("Team 1 players " + (p1+1) + " and " + (p2+1) + " are the same");
return false;
}
if (aplayers[p1] == aplayers[p2]) {
alert("Team 2 players " + (p1+1) + " and " + (p2+1) + " are the same");
return false;
}
}
}
return true;
}
</script>
EOT;
lg_html_nav();
// Load members of team and at the same time check we've got enough
function checkteam($team) {
$result = $team->list_members();
if (count($result) < 3) {
print <<<EOT
<h1>Edit Match</h1>
<p>
Sorry but there are not enough members in {$team->display_name()} yet to
make up a match with.</p>
<p>Please <a href="javascript:history.back()">click here</a> to go back
or <a href="teamsupd.php">here</a> to update teams.</p>
EOT;
lg_html_footer();
exit(0);
}
foreach ($result as $p) {
$p->fetchdets();
}
return $result;
}
$Htmemb = checkteam($mtch->Hteam);
$Atmemb = checkteam($mtch->Ateam);
print <<<EOT
<h1>Edit Match</h1>
EOT;
// Output select team member and if recorded display W or B
function selectmemb($ha, $n, $mch, $team, $membs) {
$colour = 0;
$matchm = false;
if (count($mch->Games) > $n) {
$g = $mch->Games[$n];
// We might have half-allocated teams in which case
// the White or Black team is not defined
if ($g->Wteam && $g->Wteam->is_same($team)) {
$matchm = $g->Wplayer;
$colour = 1;
}
elseif ($g->Bteam) {
$matchm = $g->Bplayer;
$colour = 2;
}
$readonly = $g->Result != 'N';
}
// If readonly is set we can't produce a selection box because
// that isn't transmitted if it's disabled so we have to make a
// hidden one instead
if ($readonly) {
print <<<EOT
<td>{$matchm->display_name(false)} ({$matchm->display_rank()})
<input type="hidden" name="$ha$n" value="{$matchm->selof()}">
</td>
EOT;
}
else {
print <<<EOT
<td>
<select name="$ha$n"$readonly>
<option value="-">-</option>
EOT;
foreach ($membs as $memb) {
$val = $memb->selof();
$selms = $matchm && $matchm->is_same($memb)? " selected": "";
print <<<EOT
<option value="$val"$selms>
{$memb->display_name(false)} ({$memb->display_rank()})
</option>
EOT;
}
print <<<EOT
</select>
</td>
EOT;
}
return $colour; // 0 nigiri 1 white 2 black
}
print <<<EOT
<p>This match is between {$mtch->Hteam->display_name()} ({$mtch->Hteam->display_description()})
and {$mtch->Ateam->display_name()} ({$mtch->Ateam->display_description()}).</p>
<form name="matchform" action="updmatch2.php" method="post" enctype="application/x-www-form-urlencoded" onsubmit="javascript:return checkteamsvalid()">
{$mtch->save_hidden()}
<p>
EOT;
$mtch->Date->dateopt("Date set for");
print "with";
$mtch->slackdopt();
print <<<EOT
days to play the games.</p>
<table class="updmatch">
<tr><th colspan="3" align="center">Player assignments</th></tr>
<tr>
<th align="center">{$mtch->Hteam->display_name()}</th>
<th align="center">Colours</th>
<th align="center">{$mtch->Ateam->display_name()}</th>
</tr>
EOT;
$cols = array("Nigiri", "White-Black", "Black-White");
$played = 0;
for ($row = 0; $row < 3; $row++) {
print "<tr>\n";
$col = selectmemb("htm", $row, $mtch, $mtch->Hteam, $Htmemb);
if (count($mtch->Games) > $row && $mtch->Games[$row]->Result != 'N') {
$played++;
print <<<EOT
<td>
$cols[$col]
<input type="hidden" name="colours$row" value="$col">
</td>
EOT;
}
else {
print "<td><select name=\"colours$row\">\n";
for ($c = 0; $c < 3; $c++) {
$s = $c == $col? " selected": "";
print "<option$s value=$c>$cols[$c]</option>\n";
}
print "</select></td>\n";
}
selectmemb("atm", $row, $mtch, $mtch->Ateam, $Atmemb);
print "</tr>\n";
}
print "</table>\n";
if ($played == 0)
$played = "";
else
$played = " checked readonly";
print <<<EOT
<p><input type="checkbox" name="forceass"$played>
<b>Check this</b> to force board assignments and colours rather than sorting into rank order.</p>
<p>Make any adjustments and <input type="submit" value="Click here"> or <input type="reset" value="Reset form"></p>
<p>Set colours to "Nigiri" throughout to randomly pick a colour which will be assigned to boards
1 and 3 and the opposite to board 2.</p>
</form>
<h2>Defaulting whole matches</h2>
<p>If you want to default a match please select one of the following. Note that this will
wipe all game records already played so it is fairly irreversible! If you mean to just
default a single game this is not the right place.</p>
<p>To default the match against {$mtch->Hteam->display_name()}
and in favour of {$mtch->Ateam->display_name()},
<a href="defaultmatch.php?{$mtch->urlof()}&w=H">click here</a>.</p>
<p>To default the match against {$mtch->Ateam->display_name()}
and in favour of {$mtch->Hteam->display_name()},
<a href="defaultmatch.php?{$mtch->urlof()}&w=A">click here</a>.</p>
EOT;
lg_html_footer();
?>