-
Notifications
You must be signed in to change notification settings - Fork 1
/
reminder.php
333 lines (261 loc) · 7.27 KB
/
reminder.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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?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';
include 'php/params.php';
include 'php/hcp_message.php';
$Connection = opendatabase(false, false);
// Remember about player we can't email to bleat at team captain about instead
class aboutplayer {
public $player; // Player we are talking about
public $opp; // His/her opponent
public $match; // Match info
public $game; // Game info
public $reason; // Reason not emailed
public function __construct($p, $o, $m, $g, $r) {
$this->player = $p;
$this->opp = $o;
$this->match = $m;
$this->game = $g;
$this->reason = $r;
}
}
// Stuff to remember to tell team captains about
class tcrems {
public $Capt; // The poor sucker
public $Unalloc; // Unallocated matches
public $Oppunalloc; // Opponents unallocated
public $Noemail; // No emails to players
public function __construct($c) {
$this->Capt = $c;
$this->Unalloc = array();
$this->Oppunalloc = array();
$this->Noemail = array();
}
public function adduamatch($m) {
array_push($this->Unalloc, $m);
}
public function addoppuamatch($m) {
array_push($this->Oppunalloc, $m);
}
public function addgame($p) {
array_push($this->Noemail, $p);
}
public function othercapt($m) {
if ($this->Capt->is_same($m->Hteam->Captain))
return $m->Ateam->Captain;
return $m->Hteam->Captain;
}
}
// Allocate a new tcrem structure if needed
function gettcrem($tc) {
global $Captains;
$cn = $tc->display_name(false);
if (!array_key_exists($cn, $Captains))
$Captains[$cn] = new tcrems($tc);
return $Captains[$cn];
}
// Generate a mail message to the player about impending match
// or thinking of a reason why not
function mailplayer($play, $opp, $col, $mt, $ot, $m, $g)
{
global $pars;
if (strlen($play->Email) == 0)
return new aboutplayer($play, $opp, $m, $g, "has given no email address");
if (!$play->OKemail)
return new aboutplayer($play, $opp, $m, $g, "has not agreed to auto-email");
$oppname = $opp->display_name(false);
$dest = $play->Email;
$fh = popen("mail -s 'Online league match reminder' $dest", "w");
$mess = <<<EOT
Dear {$play->display_name(false)}
PLEASE NOTE that this is an automatically-generated message. Please DO NOT
reply to the apparent sender - thank you!
Please can we remind you that your are due to play in the online league match
playing for {$mt->display_name()} against {$ot->display_name()}.
Your opponent is $oppname {$opp->display_rank()}.
You are playing as $col.
EOT;
fwrite($fh, $mess);
$onl = $opp->display_online();
if ($onl == '-')
$mess = <<<EOT
Sorry, but we have no record of an online name for $oppname.
EOT;
else
$mess = <<<EOT
The online name for $oppname is $onl.
EOT;
fwrite($fh, $mess);
$hcp = hcp_message($g, $pars);
if ($hcp)
fwrite($fh, "\nPlease note this game is played with $hcp\n");
if (strlen($opp->Email) != 0)
$mess = <<<EOT
$oppname has an email address of {$opp->Email}.
EOT;
else
$mess = <<<EOT
Sorry we have no email address for $oppname.
EOT;
fwrite($fh, $mess);
$phone = $opp->display_phone(true);
if (strlen($phone) != 0) {
$mess = <<<EOT
You can reach $oppname on the phone at $phone.
EOT;
fwrite($fh, $mess);
}
$nts = $opp->Notes;
if (strlen($nts) != 0) {
$mess = <<<EOT
$oppname has provided the following notes: $nts
EOT;
fwrite($fh, $mess);
}
$capt = $mt->Captain;
if (!$capt->is_same($play)) {
$mess = <<<EOT
If you have any questions, please contact your team captain, {$capt->display_name(false)},
whose email address is {$capt->Email}.
EOT;
fwrite($fh, $mess);
}
pclose($fh);
return false;
}
// Get parameters to include handicap info
$pars = new Params();
$pars->fetchvalues();
// Array of team captains to bleat to
$Captains = array();
$ret = $Connection->query("SELECT ind FROM lgmatch WHERE result!='H' AND result!='A' AND matchdate < DATE_ADD(CURRENT_DATE(),INTERVAL 30 DAY) ORDER BY divnum,matchdate,result");
if ($ret && $ret->num_rows > 0) {
while ($row = $ret->fetch_array()) {
$ind = $row[0];
$mtch = new Match($ind);
$mtch->fetchdets();
try {
$mtch->fetchteams();
$mtch->fetchgames();
}
catch (MatchException $e) {
continue;
}
$ht = $mtch->Hteam;
$at = $mtch->Ateam;
$hc = $ht->Captain;
$ac = $at->Captain;
if ($mtch->is_allocated()) {
// Match is allocated, find each unplayed game
foreach ($mtch->Games as $g) {
if ($g->Result != 'N')
continue;
if ($g->Wteam->is_same($ht)) {
$hp = $g->Wplayer;
$ap = $g->Bplayer;
$hcol = "White";
$acol = "Black";
}
else {
$hp = $g->Bplayer;
$ap = $g->Wplayer;
$hcol = "Black";
$acol = "White";
}
$r = mailplayer($hp, $ap, $hcol, $ht, $at, $mtch, $g);
if ($r)
gettcrem($hc)->addgame($r);
$r = mailplayer($ap, $hp, $acol, $at, $ht, $mtch, $g);
if ($r)
gettcrem($ac)->addgame($r);
}
}
else {
if ($mtch->team_allocated($ht))
gettcrem($hc)->addoppuamatch($mtch);
else
gettcrem($hc)->adduamatch($mtch);
if ($mtch->team_allocated($at))
gettcrem($ac)->addoppuamatch($mtch);
else
gettcrem($ac)->adduamatch($mtch);
}
}
}
foreach ($Captains as $capt) {
$dest = $capt->Capt->Email;
$fh = popen("mail -s 'Go League match reminder' $dest", "w");
$mess = <<<EOT
Dear {$capt->Capt->display_name(false)},
This is an auto-reminder from the BGA online league software.
Please do not reply to this!
EOT;
fwrite($fh, $mess);
if (count($capt->Unalloc) != 0) {
$mess = <<<EOT
Please can you complete the allocation of teams to the following matches.
EOT;
fwrite($fh, $mess);
foreach ($capt->Unalloc as $m) {
$oth = $capt->othercapt($m);
$mess = <<<EOT
Date: {$m->Date->display_month()}
Between: {$m->Hteam->display_name()} -v- {$m->Ateam->display_name()}
Other team captain: ({$oth->display_name(false)} {$oth->Email} {$oth->Phone})
EOT;
fwrite($fh, $mess);
}
}
if (count($capt->Oppunalloc) != 0) {
$mess = <<<EOT
Please can you chase the opposing team captain to complete his/her allocation
of teams to the following matches.
EOT;
fwrite($fh, $mess);
foreach ($capt->Oppunalloc as $m) {
$oth = $capt->othercapt($m);
$mess = <<<EOT
Date: {$m->Date->display_month()}
Between: {$m->Hteam->display_name()} -v- {$m->Ateam->display_name()}
Other team captain: ({$oth->display_name(false)} {$oth->Email} {$oth->Phone})
EOT;
fwrite($fh, $mess);
}
}
if (count($capt->Noemail) != 0) {
$mess = <<<EOT
Please can you encourage your team members to play the following games,
I couldn't email them directly for the reasons given.
EOT;
fwrite($fh, $mess);
foreach ($capt->Noemail as $noem) {
$m = $noem->match;
$pl = $noem->player;
$opp = $noem->opp;
$mess = <<<EOT
Date: {$m->Date->display_month()}
Match: {$m->Hteam->display_name()} -v- {$m->Ateam->display_name()}
Game: {$pl->display_name(false)} -v- {$opp->display_name(false)}
Reason: Player {$noem->reason}
EOT;
fwrite($fh, $mess);
}
}
$mess = <<<EOT
If you have allocated teams/played matches listed above please enter them
on the website.
Thanks - league auto-reminder service.
EOT;
fwrite($fh, $mess);
pclose($fh);
}
?>