5
* @version $Id: acp_email.php,v 1.32 2007/10/05 14:36:32 acydburn Exp $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
14
if (!defined('IN_PHPBB'))
26
function main($id, $mode)
28
global $config, $db, $user, $auth, $template, $cache;
29
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
31
$user->add_lang('acp/email');
32
$this->tpl_name = 'acp_email';
33
$this->page_title = 'ACP_MASS_EMAIL';
35
$form_key = 'acp_email';
36
add_form_key($form_key);
39
$submit = (isset($_POST['submit'])) ? true : false;
42
$usernames = request_var('usernames', '', true);
43
$group_id = request_var('g', 0);
44
$subject = utf8_normalize_nfc(request_var('subject', '', true));
45
$message = utf8_normalize_nfc(request_var('message', '', true));
50
// Error checking needs to go here ... if no subject and/or no message then skip
51
// over the send and return to the form
52
$use_queue = (isset($_POST['send_immediately'])) ? false : true;
53
$priority = request_var('mail_priority_flag', MAIL_NORMAL_PRIORITY);
55
if (!check_form_key($form_key))
57
$error[] = $user->lang['FORM_INVALID'];
62
$error[] = $user->lang['NO_EMAIL_SUBJECT'];
67
$error[] = $user->lang['NO_EMAIL_MESSAGE'];
74
// If giving usernames the admin is able to email inactive users too...
75
$sql = 'SELECT username, user_email, user_jabber, user_notify_type, user_lang
76
FROM ' . USERS_TABLE . '
77
WHERE ' . $db->sql_in_set('username_clean', array_map('utf8_clean_string', explode("\n", $usernames))) . '
78
AND user_allow_massemail = 1
79
ORDER BY user_lang, user_notify_type'; // , SUBSTRING(user_email FROM INSTR(user_email, '@'))
85
$sql = 'SELECT u.user_email, u.username, u.username_clean, u.user_lang, u.user_jabber, u.user_notify_type
86
FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . ' ug
87
WHERE ug.group_id = ' . $group_id . '
88
AND ug.user_pending = 0
89
AND u.user_id = ug.user_id
90
AND u.user_allow_massemail = 1
91
AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')
92
ORDER BY u.user_lang, u.user_notify_type';
96
$sql = 'SELECT username, username_clean, user_email, user_jabber, user_notify_type, user_lang
97
FROM ' . USERS_TABLE . '
98
WHERE user_allow_massemail = 1
99
AND user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')
100
ORDER BY user_lang, user_notify_type';
103
$result = $db->sql_query($sql);
104
$row = $db->sql_fetchrow($result);
108
$db->sql_freeresult($result);
109
trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
114
// Send with BCC, no more than 50 recipients for one mail (to not exceed the limit)
115
$max_chunk_size = 50;
116
$email_list = array();
117
$old_lang = $row['user_lang'];
118
$old_notify_type = $row['user_notify_type'];
122
if (($row['user_notify_type'] == NOTIFY_EMAIL && $row['user_email']) ||
123
($row['user_notify_type'] == NOTIFY_IM && $row['user_jabber']) ||
124
($row['user_notify_type'] == NOTIFY_BOTH && $row['user_email'] && $row['user_jabber']))
126
if ($i == $max_chunk_size || $row['user_lang'] != $old_lang || $row['user_notify_type'] != $old_notify_type)
130
if (sizeof($email_list))
135
$old_lang = $row['user_lang'];
136
$old_notify_type = $row['user_notify_type'];
139
$email_list[$j][$i]['lang'] = $row['user_lang'];
140
$email_list[$j][$i]['method'] = $row['user_notify_type'];
141
$email_list[$j][$i]['email'] = $row['user_email'];
142
$email_list[$j][$i]['name'] = $row['username'];
143
$email_list[$j][$i]['jabber'] = $row['user_jabber'];
147
while ($row = $db->sql_fetchrow($result));
148
$db->sql_freeresult($result);
151
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
152
include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
153
$messenger = new messenger($use_queue);
157
for ($i = 0, $size = sizeof($email_list); $i < $size; $i++)
159
$used_lang = $email_list[$i][0]['lang'];
160
$used_method = $email_list[$i][0]['method'];
162
for ($j = 0, $list_size = sizeof($email_list[$i]); $j < $list_size; $j++)
164
$email_row = $email_list[$i][$j];
166
$messenger->{((sizeof($email_list[$i]) == 1) ? 'to' : 'bcc')}($email_row['email'], $email_row['name']);
167
$messenger->im($email_row['jabber'], $email_row['name']);
170
$messenger->template('admin_send_email', $used_lang);
172
$messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
173
$messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
174
$messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
175
$messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
177
$messenger->subject(htmlspecialchars_decode($subject));
178
$messenger->set_mail_priority($priority);
180
$messenger->assign_vars(array(
181
'CONTACT_EMAIL' => $config['board_contact'],
182
'MESSAGE' => htmlspecialchars_decode($message))
185
if (!($messenger->send($used_method)))
192
$messenger->save_queue();
196
$usernames = explode("\n", $usernames);
197
add_log('admin', 'LOG_MASS_EMAIL', implode(', ', utf8_normalize_nfc($usernames)));
203
$group_name = get_group_name($group_id);
207
// Not great but the logging routine doesn't cope well with localising on the fly
208
$group_name = $user->lang['ALL_USERS'];
211
add_log('admin', 'LOG_MASS_EMAIL', $group_name);
216
$message = ($use_queue) ? $user->lang['EMAIL_SENT_QUEUE'] : $user->lang['EMAIL_SENT'];
217
trigger_error($message . adm_back_link($this->u_action));
221
$message = sprintf($user->lang['EMAIL_SEND_ERROR'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=logs&mode=critical') . '">', '</a>');
222
trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING);
227
// Exclude bots and guests...
228
$sql = 'SELECT group_id
229
FROM ' . GROUPS_TABLE . "
230
WHERE group_name IN ('BOTS', 'GUESTS')";
231
$result = $db->sql_query($sql);
234
while ($row = $db->sql_fetchrow($result))
236
$exclude[] = $row['group_id'];
238
$db->sql_freeresult($result);
240
$select_list = '<option value="0"' . ((!$group_id) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_USERS'] . '</option>';
241
$select_list .= group_select_options($group_id, $exclude);
243
$s_priority_options = '<option value="' . MAIL_LOW_PRIORITY . '">' . $user->lang['MAIL_LOW_PRIORITY'] . '</option>';
244
$s_priority_options .= '<option value="' . MAIL_NORMAL_PRIORITY . '" selected="selected">' . $user->lang['MAIL_NORMAL_PRIORITY'] . '</option>';
245
$s_priority_options .= '<option value="' . MAIL_HIGH_PRIORITY . '">' . $user->lang['MAIL_HIGH_PRIORITY'] . '</option>';
247
$template->assign_vars(array(
248
'S_WARNING' => (sizeof($error)) ? true : false,
249
'WARNING_MSG' => (sizeof($error)) ? implode('<br />', $error) : '',
250
'U_ACTION' => $this->u_action,
251
'S_GROUP_OPTIONS' => $select_list,
252
'USERNAMES' => $usernames,
253
'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=acp_email&field=usernames'),
254
'SUBJECT' => $subject,
255
'MESSAGE' => $message,
256
'S_PRIORITY_OPTIONS' => $s_priority_options)
b'\\ No newline at end of file'