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