/
emailmanager.php
238 lines (235 loc) · 8.73 KB
/
emailmanager.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
<?php
/*
* Created on Oct 29, 2007
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
// Page requirements
define('LOGIN_REQUIRED', true);
define('PAGE_ACCESS_LEVEL', 1);
define('PAGE_TYPE', 'USER');
// Set for every page
require ('engine/common.php');
if ((isset($_POST['action'])) && ($_POST['action'] == "Send Email")) {
// If form does not validate, we need to return with errors.
if ($errors = validate_emailer_form()) {
handle_errors($errors);
//handle_reposts();
} else {
// If errors occur while trying to create user, we need to return with errors.
if ($errors = process_emailer_form($smarty)) {
handle_errors($errors);
//handle_reposts();
} else {
$success = array();
$success[] = 'Email Sent.';
handle_success($success);
}
}
}
$smarty->assign('page_name', 'Email Manager');
setup_email_groups();
$smarty->assign('senderName', $_SESSION['firstname'] . ' ' . $_SESSION['lastname']);
$smarty->assign('season_name', get_season_name($SEASON));
// Build the page
require ('global_begin.php');
$smarty->display('user/emailmanager.tpl');
require ('global_end.php');
/*
* ********************************************************************************
* ********************************************************************************
* **************************L O C A L F U N C T I O N S**************************
* ********************************************************************************
* ********************************************************************************
*/
function setup_email_groups() {
global $smarty;
//Goes to global functions to get team candidates
setup_team_candidates();
}
function validate_emailer_form() {
$errors = array();
return $errors;
}
function process_emailer_form() {
$to_email_array = get_email_addresses();
$subject = $_POST['sub'];
$message = $_POST['msg'];
if ((isset($_POST['omitName'])) && $_POST['omitName'] == 1) {
// Sender wishes to omit their name from the email message.
} else {
$message.= ' -' . $_POST['from'];
}
//email_message($to,$subject,$message);
send_bcc_email($to_email_array, $subject, $message);
}
/*
* Get email addresses
*/
function get_email_addresses() {
$toValue = $_POST['to'];
$webemail_array = array();
$webemail_array[] = TCSHL_EMAIL;
if ($toValue > 0) {
$addressArray = get_team_addresses($toValue);
} else if ($toValue == 'mass') {
$addressArray = get_every_address();
} else if ($toValue == 'all') {
$addressArray = get_all_player_addresses();
} else if ($toValue == 'rep') {
$addressArray = get_all_rep_addresses();
} else if ($toValue == 'ref') {
$addressArray = get_all_ref_addresses();
} else if ($toValue == 'site') {
$addressArray = get_all_registered_user_addresses();
} else if ($toValue == 'web') {
$addressArray = array();
$addressArray[] = WEBMASTER_EMAIL;
}
$webemail_array = array_merge($webemail_array, $addressArray);
return $webemail_array;
}
/*
* Team Email Addresses
*/
function get_team_addresses($TEAMID) {
global $SEASON;
$subQuery = 'SELECT registrationId FROM ' . PLAYER . ' WHERE seasonid=' . $SEASON;
$subQuery2 = 'SELECT playerid FROM ' . ROSTERSOFTEAMSOFSEASONS . ' WHERE teamID=' . $TEAMID . ' AND seasonID=' . $SEASON;
$select = 'SELECT eMail FROM ' . REGISTRATION;
$select.= ' WHERE seasonid=' . $SEASON;
$select.= ' AND registrationId IN (' . $subQuery . ')';
$select.= ' AND playerId IN (' . $subQuery2 . ')';
$select.= ' AND eMail IS NOT NULL';
$select.= ' AND eMail != ""';
$select.= ' GROUP BY eMail';
return emails($select);
}
/*
* Get All Addresses
*/
function get_every_address() {
$subQuery = 'SELECT eMail FROM ' . USER . ' WHERE accessLevel > 0 ORDER BY eMail';
$select = 'SELECT distinct eMail FROM ' . REGISTRATION;
$select.= ' WHERE eMail NOT IN (' . $subQuery . ')';
$select.= ' AND eMail IS NOT NULL';
$select.= ' AND eMail != ""';
$select.= ' AND eMail != "administrator@example.com"';
$select.= ' AND eMail != "board@example.com"';
$select.= ' AND eMail != "payment@example.com"';
$select.= ' AND eMail != "referees@example.com"';
$select.= ' AND eMail != "registration@example.com"';
$select.= ' AND eMail != "teamreps@example.com"';
$select.= ' AND eMail != "siteregistration@example.com"';
$select.= ' AND eMail != "stats@example.com"';
$select.= ' AND eMail != "tcshl@example.com"';
$select.= ' ORDER BY eMail';
$everyEmail = array_merge(emails($subQuery), emails($select));
return $everyEmail;
}
/*
* Get All Player Addresses
*/
function get_all_player_addresses() {
global $SEASON;
$subQuery = 'SELECT registrationId FROM ' . PLAYER . ' WHERE seasonid=' . $SEASON;
$select = 'SELECT eMail FROM ' . REGISTRATION;
$select.= ' WHERE seasonid=' . $SEASON;
$select.= ' AND registrationId IN (' . $subQuery . ')';
$select.= ' AND eMail IS NOT NULL';
$select.= ' AND eMail != ""';
$select.= ' GROUP BY eMail';
return emails($select);
}
/*
* Get All Team Rep Addresses
*/
function get_all_rep_addresses() {
global $SEASON;
$subQuery = 'SELECT teamRep FROM ' . TEAMSOFSEASONS . ' WHERE seasonID=' . $SEASON;
$select = 'SELECT eMail FROM ' . REGISTRATION;
$select.= ' WHERE seasonid=' . $SEASON;
$select.= ' AND playerId IN (' . $subQuery . ')';
$select.= ' AND eMail IS NOT NULL';
$select.= ' AND eMail != ""';
$select.= ' GROUP BY eMail';
return emails($select);
}
/*
* Get All Ref Addresses
*/
function get_all_ref_addresses() {
global $SEASON;
$subQuery = 'SELECT registrationId FROM ' . PLAYER . ' WHERE seasonid=' . $SEASON;
$subQuery2 = 'SELECT playerid FROM ' . REFEREESOFSEASONS . ' WHERE seasonID=' . $SEASON;
$select = 'SELECT eMail FROM ' . REGISTRATION;
$select.= ' WHERE seasonid=' . $SEASON;
$select.= ' AND registrationId IN (' . $subQuery . ')';
$select.= ' AND playerId IN (' . $subQuery2 . ')';
$select.= ' AND eMail IS NOT NULL';
$select.= ' AND eMail != ""';
$select.= ' GROUP BY eMail';
return emails($select);
}
/*
* Get All Site Registered User Addresses
*/
function get_all_registered_user_addresses() {
global $SEASON;
$select = 'SELECT eMail FROM ' . USER;
$select.= ' WHERE accessLevel > 0';
$select.= ' GROUP BY eMail';
return emails($select);
}
/*
* Returns email address string and takes a select as an argument
*/
function emails($select = "") {
global $Link;
$emailArray = array();
$addressResult = mysql_query($select, $Link) or die("sp_clubs (Line " . __LINE__ . "): " . mysql_errno() . ": " . mysql_error());
$emailAddresses = '';
if ($addressResult && mysql_num_rows($addressResult) > 0) {
while ($person = mysql_fetch_array($addressResult, MYSQL_ASSOC)) {
if (strlen($person['eMail']) > 0) {
$emailArray[] = $person['eMail'];
}
}
}
return $emailArray;
}
/*
* Send email
*/
function email_message($emailAddresses = "", $subject = "", $message = "") {
// Note these emails need to be Blind Carbon Coby
$from = TCSHL_EMAIL;
$replyTo = $_SESSION['email'];
//$headers = "From: ".$from. "\r\n";
//$headers .= "Reply-To: ".$replyTo. "\r\n";
//$headers .= "Bcc: ".$emailAddresses. "\r\n";
//$headers .= "X-Mailer: PHP/".phpversion();
$headers = 'From: ' . $from . "\r\n" . 'Reply-To: ' . $replyTo . "\r\n" . 'Bcc: ' . $emailAddresses . "\r\n" . 'Return-Path: ' . $from . "\r\n" . 'X-Mailer: PHP/' . phpversion();
//Send email
$emailSent = mail('', $subject, $message, $headers);
// If email does not send, need to send webmaster an email so he can debug it.
if (!$emailSent || get_site_variable_value("DEBUG_EMAIL") == 1) {
$debugSubject = "EmailManager example.com - debug info";
$debugFrom = TCSHL_EMAIL;
$debugReplyTo = WEBMASTER_EMAIL;
$debugHeaders = "From: " . $debugFrom . "\r\n";
$debugHeaders.= "Reply-To: " . $debugReplyTo . "\r\n";
$debugHeaders.= "X-Mailer: PHP/" . phpversion();
$debugDate = date("m-d-Y H:i e", time());
$debugMessage = "Message attempt by: " . $replyTo . "\r\n";
$debugMessage.= "Message attempt date: " . $debugDate . "\r\n";
$debugMessage.= "Message headers: \n" . $headers . "\r\n";
$debugMessage.= "Message subject: " . $subject . "\r\n";
$debugMessage.= "Message body: \n";
$debugMessage.= $message . "\r\n";
// Send mail to webmaster
mail(WEBMASTER_EMAIL, $debugSubject, $debugMessage, $debugHeaders);
}
}
?>