|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @package acp
|
|
|
4c79b5 |
* @version $Id: acp_email.php 8479 2008-03-29 00:22:48Z naderman $
|
|
|
4c79b5 |
* @copyright (c) 2005 phpBB Group
|
|
|
4c79b5 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* @ignore
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
if (!defined('IN_PHPBB'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
exit;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* @package acp
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
class acp_email
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var $u_action;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function main($id, $mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $config, $db, $user, $auth, $template, $cache;
|
|
|
4c79b5 |
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$user->add_lang('acp/email');
|
|
|
4c79b5 |
$this->tpl_name = 'acp_email';
|
|
|
4c79b5 |
$this->page_title = 'ACP_MASS_EMAIL';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$form_key = 'acp_email';
|
|
|
4c79b5 |
add_form_key($form_key);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Set some vars
|
|
|
4c79b5 |
$submit = (isset($_POST['submit'])) ? true : false;
|
|
|
4c79b5 |
$error = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$usernames = request_var('usernames', '', true);
|
|
|
4c79b5 |
$group_id = request_var('g', 0);
|
|
|
4c79b5 |
$subject = utf8_normalize_nfc(request_var('subject', '', true));
|
|
|
4c79b5 |
$message = utf8_normalize_nfc(request_var('message', '', true));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Do the job ...
|
|
|
4c79b5 |
if ($submit)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Error checking needs to go here ... if no subject and/or no message then skip
|
|
|
4c79b5 |
// over the send and return to the form
|
|
|
4c79b5 |
$use_queue = (isset($_POST['send_immediately'])) ? false : true;
|
|
|
4c79b5 |
$priority = request_var('mail_priority_flag', MAIL_NORMAL_PRIORITY);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!check_form_key($form_key))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['FORM_INVALID'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$subject)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['NO_EMAIL_SUBJECT'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$message)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['NO_EMAIL_MESSAGE'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($usernames)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// If giving usernames the admin is able to email inactive users too...
|
|
|
4c79b5 |
$sql = 'SELECT username, user_email, user_jabber, user_notify_type, user_lang
|
|
|
4c79b5 |
FROM ' . USERS_TABLE . '
|
|
|
4c79b5 |
WHERE ' . $db->sql_in_set('username_clean', array_map('utf8_clean_string', explode("\n", $usernames))) . '
|
|
|
4c79b5 |
AND user_allow_massemail = 1
|
|
|
4c79b5 |
ORDER BY user_lang, user_notify_type'; // , SUBSTRING(user_email FROM INSTR(user_email, '@'))
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($group_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT u.user_email, u.username, u.username_clean, u.user_lang, u.user_jabber, u.user_notify_type
|
|
|
4c79b5 |
FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . ' ug
|
|
|
4c79b5 |
WHERE ug.group_id = ' . $group_id . '
|
|
|
4c79b5 |
AND ug.user_pending = 0
|
|
|
4c79b5 |
AND u.user_id = ug.user_id
|
|
|
4c79b5 |
AND u.user_allow_massemail = 1
|
|
|
4c79b5 |
AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')
|
|
|
4c79b5 |
ORDER BY u.user_lang, u.user_notify_type';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT username, username_clean, user_email, user_jabber, user_notify_type, user_lang
|
|
|
4c79b5 |
FROM ' . USERS_TABLE . '
|
|
|
4c79b5 |
WHERE user_allow_massemail = 1
|
|
|
4c79b5 |
AND user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')
|
|
|
4c79b5 |
ORDER BY user_lang, user_notify_type';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$i = $j = 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Send with BCC, no more than 50 recipients for one mail (to not exceed the limit)
|
|
|
4c79b5 |
$max_chunk_size = 50;
|
|
|
4c79b5 |
$email_list = array();
|
|
|
4c79b5 |
$old_lang = $row['user_lang'];
|
|
|
4c79b5 |
$old_notify_type = $row['user_notify_type'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
do
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (($row['user_notify_type'] == NOTIFY_EMAIL && $row['user_email']) ||
|
|
|
4c79b5 |
($row['user_notify_type'] == NOTIFY_IM && $row['user_jabber']) ||
|
|
|
4c79b5 |
($row['user_notify_type'] == NOTIFY_BOTH && $row['user_email'] && $row['user_jabber']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($i == $max_chunk_size || $row['user_lang'] != $old_lang || $row['user_notify_type'] != $old_notify_type)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$i = 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($email_list))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$j++;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$old_lang = $row['user_lang'];
|
|
|
4c79b5 |
$old_notify_type = $row['user_notify_type'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$email_list[$j][$i]['lang'] = $row['user_lang'];
|
|
|
4c79b5 |
$email_list[$j][$i]['method'] = $row['user_notify_type'];
|
|
|
4c79b5 |
$email_list[$j][$i]['email'] = $row['user_email'];
|
|
|
4c79b5 |
$email_list[$j][$i]['name'] = $row['username'];
|
|
|
4c79b5 |
$email_list[$j][$i]['jabber'] = $row['user_jabber'];
|
|
|
4c79b5 |
$i++;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result));
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Send the messages
|
|
|
4c79b5 |
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
|
|
4c79b5 |
include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
|
|
|
4c79b5 |
$messenger = new messenger($use_queue);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$errored = false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
for ($i = 0, $size = sizeof($email_list); $i < $size; $i++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$used_lang = $email_list[$i][0]['lang'];
|
|
|
4c79b5 |
$used_method = $email_list[$i][0]['method'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
for ($j = 0, $list_size = sizeof($email_list[$i]); $j < $list_size; $j++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$email_row = $email_list[$i][$j];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$messenger->{((sizeof($email_list[$i]) == 1) ? 'to' : 'bcc')}($email_row['email'], $email_row['name']);
|
|
|
4c79b5 |
$messenger->im($email_row['jabber'], $email_row['name']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$messenger->template('admin_send_email', $used_lang);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
|
|
|
4c79b5 |
$messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
|
|
|
4c79b5 |
$messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
|
|
|
4c79b5 |
$messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$messenger->subject(htmlspecialchars_decode($subject));
|
|
|
4c79b5 |
$messenger->set_mail_priority($priority);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$messenger->assign_vars(array(
|
|
|
4c79b5 |
'CONTACT_EMAIL' => $config['board_contact'],
|
|
|
4c79b5 |
'MESSAGE' => htmlspecialchars_decode($message))
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!($messenger->send($used_method)))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errored = true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($email_list);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$messenger->save_queue();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($usernames)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$usernames = explode("\n", $usernames);
|
|
|
4c79b5 |
add_log('admin', 'LOG_MASS_EMAIL', implode(', ', utf8_normalize_nfc($usernames)));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($group_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$group_name = get_group_name($group_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Not great but the logging routine doesn't cope well with localising on the fly
|
|
|
4c79b5 |
$group_name = $user->lang['ALL_USERS'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('admin', 'LOG_MASS_EMAIL', $group_name);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$errored)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$message = ($use_queue) ? $user->lang['EMAIL_SENT_QUEUE'] : $user->lang['EMAIL_SENT'];
|
|
|
4c79b5 |
trigger_error($message . adm_back_link($this->u_action));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$message = sprintf($user->lang['EMAIL_SEND_ERROR'], '', '');
|
|
|
4c79b5 |
trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Exclude bots and guests...
|
|
|
4c79b5 |
$sql = 'SELECT group_id
|
|
|
4c79b5 |
FROM ' . GROUPS_TABLE . "
|
|
|
4c79b5 |
WHERE group_name IN ('BOTS', 'GUESTS')";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$exclude = array();
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$exclude[] = $row['group_id'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$select_list = '<option value="0"' . ((!$group_id) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_USERS'] . '</option>';
|
|
|
4c79b5 |
$select_list .= group_select_options($group_id, $exclude);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$s_priority_options = '<option value="' . MAIL_LOW_PRIORITY . '">' . $user->lang['MAIL_LOW_PRIORITY'] . '</option>';
|
|
|
4c79b5 |
$s_priority_options .= '<option value="' . MAIL_NORMAL_PRIORITY . '" selected="selected">' . $user->lang['MAIL_NORMAL_PRIORITY'] . '</option>';
|
|
|
4c79b5 |
$s_priority_options .= '<option value="' . MAIL_HIGH_PRIORITY . '">' . $user->lang['MAIL_HIGH_PRIORITY'] . '</option>';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_WARNING' => (sizeof($error)) ? true : false,
|
|
|
4c79b5 |
'WARNING_MSG' => (sizeof($error)) ? implode(' ', $error) : '',
|
|
|
4c79b5 |
'U_ACTION' => $this->u_action,
|
|
|
4c79b5 |
'S_GROUP_OPTIONS' => $select_list,
|
|
|
4c79b5 |
'USERNAMES' => $usernames,
|
|
|
4c79b5 |
'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=acp_email&field=usernames'),
|
|
|
4c79b5 |
'SUBJECT' => $subject,
|
|
|
4c79b5 |
'MESSAGE' => $message,
|
|
|
4c79b5 |
'S_PRIORITY_OPTIONS' => $s_priority_options)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
?>
|