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
|
<?php
/**
*
* @package acp
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @package acp
*/
class acp_email
{
var $u_action;
function main($id, $mode)
{
global $config, $db, $user, $auth, $template, $cache;
global $SID, $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
$user->add_lang('acp/email');
$this->tpl_name = 'acp_email';
$this->page_title = 'ACP_MASS_EMAIL';
// Set some vars
$submit = (isset($_POST['submit'])) ? true : false;
$error = array();
$usernames = request_var('usernames', '');
$group_id = request_var('g', 0);
// Do the job ...
if ($submit)
{
// Error checking needs to go here ... if no subject and/or no message then skip
// over the send and return to the form
$subject = html_entity_decode(request_var('subject', '', true));
$message = html_entity_decode(request_var('message', '', true));
$use_queue = (isset($_POST['send_immediatly'])) ? false : true;
$priority = request_var('mail_priority_flag', MAIL_NORMAL_PRIORITY);
if (!$subject)
{
$error[] = $user->lang['NO_EMAIL_SUBJECT'];
}
if (!$message)
{
$error[] = $user->lang['NO_EMAIL_MESSAGE'];
}
if (!sizeof($error))
{
if ($usernames)
{
$usernames = implode(', ', preg_replace('#^[\s]*?(.*?)[\s]*?$#e', "\"'\" . \$db->sql_escape('\\1') . \"'\"", explode("\n", $usernames)));
$sql = 'SELECT username, user_email, user_jabber, user_notify_type, user_lang
FROM ' . USERS_TABLE . "
WHERE username IN ($usernames)
AND user_allow_massemail = 1
ORDER BY user_lang, user_notify_type"; // , SUBSTRING(user_email FROM INSTR(user_email, '@'))
}
else
{
if ($group_id)
{
$sql = 'SELECT u.user_email, u.username, u.user_lang, u.user_jabber, u.user_notify_type
FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
WHERE ug.group_id = $group_id
AND ug.user_pending <> 1
AND u.user_id = ug.user_id
AND u.user_allow_massemail = 1
ORDER BY u.user_lang, u.user_notify_type";
}
else
{
$sql = 'SELECT username, user_email, user_jabber, user_notify_type, user_lang
FROM ' . USERS_TABLE . '
WHERE user_allow_massemail = 1
ORDER BY user_lang, user_notify_type';
}
}
$result = $db->sql_query($sql);
if (!($row = $db->sql_fetchrow($result)))
{
trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action));
}
$db->sql_freeresult($result);
$i = $j = 0;
// Send with BCC, no more than 50 recipients for one mail (to not exceed the limit)
$max_chunk_size = 50;
$email_list = array();
$old_lang = $row['user_lang'];
$old_notify_type = $row['user_notify_type'];
do
{
if (($row['user_notify_type'] == NOTIFY_EMAIL && $row['user_email']) ||
($row['user_notify_type'] == NOTIFY_IM && $row['user_jabber']) ||
($row['user_notify_type'] == NOTIFY_BOTH && $row['user_email'] && $row['user_jabber']))
{
if ($i == $max_chunk_size || $row['user_lang'] != $old_lang || $row['user_notify_type'] != $old_notify_type)
{
$i = 0;
$j++;
$old_lang = $row['user_lang'];
$old_notify_type = $row['user_notify_type'];
}
$email_list[$j][$i]['lang'] = $row['user_lang'];
$email_list[$j][$i]['method'] = $row['user_notify_type'];
$email_list[$j][$i]['email'] = $row['user_email'];
$email_list[$j][$i]['name'] = $row['username'];
$email_list[$j][$i]['jabber'] = $row['user_jabber'];
$i++;
}
}
while ($row = $db->sql_fetchrow($result));
$db->sql_freeresult($result);
// Send the messages
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
$messenger = new messenger($use_queue);
$errored = false;
for ($i = 0, $size = sizeof($email_list); $i < $size; $i++)
{
$used_lang = $email_list[$i][0]['lang'];
$used_method = $email_list[$i][0]['method'];
for ($j = 0, $list_size = sizeof($email_list[$i]); $j < $list_size; $j++)
{
$email_row = $email_list[$i][$j];
$messenger->{((sizeof($email_list[$i]) == 1) ? 'to' : 'bcc')}($email_row['email'], $email_row['name']);
$messenger->im($email_row['jabber'], $email_row['name']);
}
$messenger->template('admin_send_email', $used_lang);
$messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
$messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
$messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
$messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
$messenger->subject($subject);
$messenger->replyto($config['board_email']);
$messenger->set_mail_priority($priority);
$messenger->assign_vars(array(
'SITENAME' => $config['sitename'],
'CONTACT_EMAIL' => $config['board_contact'],
'MESSAGE' => $message)
);
if (!($messenger->send($used_method)))
{
$errored = true;
}
}
unset($email_list);
$messenger->save_queue();
if ($group_id)
{
$sql = 'SELECT group_name
FROM ' . GROUPS_TABLE . "
WHERE group_id = $group_id";
$result = $db->sql_query($sql);
$group_name = (string) $db->sql_fetchfield('group_name');
$db->sql_freeresult($result);
}
else
{
// Not great but the logging routine doesn't cope well with localising
// on the fly
$group_name = $user->lang['ALL_USERS'];
}
add_log('admin', 'LOG_MASS_EMAIL', $group_name);
$message = (!$errored) ? $user->lang['EMAIL_SENT'] : sprintf($user->lang['EMAIL_SEND_ERROR'], '<a href="' . $phpbb_admin_path . "index.$phpEx$SID&i=logs&mode=critical" . '">', '</a>');
trigger_error($message . adm_back_link($this->u_action));
}
}
// Initial selection
$sql = 'SELECT group_id, group_type, group_name
FROM ' . GROUPS_TABLE . '
ORDER BY group_type DESC, group_name ASC';
$result = $db->sql_query($sql);
$select_list = '<option value="0"' . ((!$group_id) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_USERS'] . '</option>';
$select_list .= group_select_options($group_id);
$s_priority_options = '<option value="' . MAIL_LOW_PRIORITY . '">' . $user->lang['MAIL_LOW_PRIORITY'] . '</option>';
$s_priority_options .= '<option value="' . MAIL_NORMAL_PRIORITY . '" selected="selected">' . $user->lang['MAIL_NORMAL_PRIORITY'] . '</option>';
$s_priority_options .= '<option value="' . MAIL_HIGH_PRIORITY . '">' . $user->lang['MAIL_HIGH_PRIORITY'] . '</option>';
$template->assign_vars(array(
'S_WARNING' => (sizeof($error)) ? true : false,
'WARNING_MSG' => (sizeof($error)) ? implode('<br />', $error) : '',
'U_ACTION' => $this->u_action,
'S_GROUP_OPTIONS' => $select_list,
'USERNAMES' => $usernames,
'U_FIND_USERNAME' => $phpbb_root_path . "memberlist.$phpEx$SID&mode=searchuser&form=acp_email&field=usernames",
'SUBJECT' => request_var('subject', ''),
'MESSAGE' => request_var('message', ''),
'S_PRIORITY_OPTIONS' => $s_priority_options)
);
}
}
/**
* @package module_install
*/
class acp_email_info
{
function module()
{
return array(
'filename' => 'acp_email',
'title' => 'ACP_MASS_EMAIL',
'version' => '1.0.0',
'modes' => array(
'email' => array('title' => 'ACP_MASS_EMAIL', 'auth' => 'acl_a_email'),
),
);
}
function install()
{
}
function uninstall()
{
}
}
?>
|