/
sendilp2.php
125 lines (98 loc) · 3.12 KB
/
sendilp2.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
<?php
// Copyright 2012-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/>.
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';
$Connection = opendatabase(true);
$subj = $_POST["subject"];
$emailrep = $_POST["emailrep"];
$mess = $_POST["messagetext"];
$admins = isset($_POST["admintoo"]);
$active = $_POST["active"];
$paid = $_POST["paid"];
$cc = $_POST["ccto"];
// Need number of divisions to run over
$ml = max_ildivision();
$allilpl = array();
for ($d = 1; $d <= $ml; $d++) {
$pl = list_players_ildiv($d);
foreach ($pl as $p)
array_push($allilpl, $p);
}
// This will be the list of email addresses to send to
$mlist = array();
foreach ($allilpl as $p) {
// Get details of player
$p->fetchdets();
// If no email, nothing to do
if (strlen($p->Email) == 0)
continue;
// If person has paid and we are only messaging unpaid or vice versa, skip him
if ($p->ILpaid) {
if ($paid == 'U')
continue;
}
elseif ($paid == 'P')
continue;
// If we are sending to active or inactive players, we have to get scores
if ($active != "A") {
$p->get_scores();
$ng = $p->played_games(true, 'I');
if ($ng == 0) { // Nothing played
if ($active == 'P') // Skip him if he's played some
continue;
}
elseif ($active == 'I') // Played, skip if he hasn't
continue;
}
// Record player by email address
$mlist[$p->Email] = 1;
}
// Add in CC to
if (strlen($cc) != 0) {
foreach (preg_split("/[\s,]+/", $cc) as $m)
$mlist[$m] = 1;
}
// Add in admins if required
if ($admins) {
$la = list_admins();
foreach ($la as $p)
if (strlen($p->Email) != 0)
$mlist[$p->Email] = 1;
}
// Set up reply to address.
$rt = "";
if (strlen($emailrep) != 0)
$rt = "REPLYTO='$emailrep' ";
foreach (array_keys($mlist) as $dest) {
$fh = popen("{$rt}mail -s 'Go League email - $subj' $dest", "w");
fwrite($fh, "$mess\n");
pclose($fh);
}
lg_html_header("Message Sent to individual league players");
lg_html_nav();
print <<<EOT
<h1>Message sent to individual league players</h1>
<p>I think your message was sent OK to individual league players.</p>
EOT;
lg_html_footer();
?>