source: trunk/forum/includes/acp/acp_email.php

Last change on this file was 702, checked in by george, 15 years ago
  • Upraveno: Aktualizace fóra.
File size: 7.9 KB
Line 
1<?php
2/**
3*
4* @package acp
5* @version $Id$
6* @copyright (c) 2005 phpBB Group
7* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8*
9*/
10
11/**
12* @ignore
13*/
14if (!defined('IN_PHPBB'))
15{
16 exit;
17}
18
19/**
20* @package acp
21*/
22class acp_email
23{
24 var $u_action;
25
26 function main($id, $mode)
27 {
28 global $config, $db, $user, $auth, $template, $cache;
29 global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
30
31 $user->add_lang('acp/email');
32 $this->tpl_name = 'acp_email';
33 $this->page_title = 'ACP_MASS_EMAIL';
34
35 $form_key = 'acp_email';
36 add_form_key($form_key);
37
38 // Set some vars
39 $submit = (isset($_POST['submit'])) ? true : false;
40 $error = array();
41
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));
46
47 // Do the job ...
48 if ($submit)
49 {
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);
54
55 if (!check_form_key($form_key))
56 {
57 $error[] = $user->lang['FORM_INVALID'];
58 }
59
60 if (!$subject)
61 {
62 $error[] = $user->lang['NO_EMAIL_SUBJECT'];
63 }
64
65 if (!$message)
66 {
67 $error[] = $user->lang['NO_EMAIL_MESSAGE'];
68 }
69
70 if (!sizeof($error))
71 {
72 if ($usernames)
73 {
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, '@'))
80 }
81 else
82 {
83 if ($group_id)
84 {
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';
93 }
94 else
95 {
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';
101 }
102 }
103 $result = $db->sql_query($sql);
104 $row = $db->sql_fetchrow($result);
105
106 if (!$row)
107 {
108 $db->sql_freeresult($result);
109 trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
110 }
111
112 $i = $j = 0;
113
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'];
119
120 do
121 {
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'])))
125 {
126 if ($i == $max_chunk_size || $row['user_lang'] != $old_lang || $row['user_notify_type'] != $old_notify_type)
127 {
128 $i = 0;
129
130 if (sizeof($email_list))
131 {
132 $j++;
133 }
134
135 $old_lang = $row['user_lang'];
136 $old_notify_type = $row['user_notify_type'];
137 }
138
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'];
144 $i++;
145 }
146 }
147 while ($row = $db->sql_fetchrow($result));
148 $db->sql_freeresult($result);
149
150 // Send the messages
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);
154
155 $errored = false;
156
157 for ($i = 0, $size = sizeof($email_list); $i < $size; $i++)
158 {
159 $used_lang = $email_list[$i][0]['lang'];
160 $used_method = $email_list[$i][0]['method'];
161
162 for ($j = 0, $list_size = sizeof($email_list[$i]); $j < $list_size; $j++)
163 {
164 $email_row = $email_list[$i][$j];
165
166 $messenger->{((sizeof($email_list[$i]) == 1) ? 'to' : 'bcc')}($email_row['email'], $email_row['name']);
167 $messenger->im($email_row['jabber'], $email_row['name']);
168 }
169
170 $messenger->template('admin_send_email', $used_lang);
171
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);
176
177 $messenger->subject(htmlspecialchars_decode($subject));
178 $messenger->set_mail_priority($priority);
179
180 $messenger->assign_vars(array(
181 'CONTACT_EMAIL' => $config['board_contact'],
182 'MESSAGE' => htmlspecialchars_decode($message))
183 );
184
185 if (!($messenger->send($used_method)))
186 {
187 $errored = true;
188 }
189 }
190 unset($email_list);
191
192 $messenger->save_queue();
193
194 if ($usernames)
195 {
196 $usernames = explode("\n", $usernames);
197 add_log('admin', 'LOG_MASS_EMAIL', implode(', ', utf8_normalize_nfc($usernames)));
198 }
199 else
200 {
201 if ($group_id)
202 {
203 $group_name = get_group_name($group_id);
204 }
205 else
206 {
207 // Not great but the logging routine doesn't cope well with localising on the fly
208 $group_name = $user->lang['ALL_USERS'];
209 }
210
211 add_log('admin', 'LOG_MASS_EMAIL', $group_name);
212 }
213
214 if (!$errored)
215 {
216 $message = ($use_queue) ? $user->lang['EMAIL_SENT_QUEUE'] : $user->lang['EMAIL_SENT'];
217 trigger_error($message . adm_back_link($this->u_action));
218 }
219 else
220 {
221 $message = sprintf($user->lang['EMAIL_SEND_ERROR'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=logs&amp;mode=critical') . '">', '</a>');
222 trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING);
223 }
224 }
225 }
226
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);
232
233 $exclude = array();
234 while ($row = $db->sql_fetchrow($result))
235 {
236 $exclude[] = $row['group_id'];
237 }
238 $db->sql_freeresult($result);
239
240 $select_list = '<option value="0"' . ((!$group_id) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_USERS'] . '</option>';
241 $select_list .= group_select_options($group_id, $exclude);
242
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>';
246
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&amp;form=acp_email&amp;field=usernames'),
254 'SUBJECT' => $subject,
255 'MESSAGE' => $message,
256 'S_PRIORITY_OPTIONS' => $s_priority_options)
257 );
258
259 }
260}
261
262?>
Note: See TracBrowser for help on using the repository browser.