2 /***************************************************************************
5 * begin : Thu May 31, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: admin_mass_email.php,v 1.15.2.7 2003/05/03 23:24:01 acydburn Exp $
11 ****************************************************************************/
13 /***************************************************************************
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 ***************************************************************************/
22 define('IN_PHPBB', 1);
24 if( !empty($setmodules) )
26 $filename = basename(__FILE__);
27 $module['General']['Mass_Email'] = $filename;
33 // Load default header
35 $no_page_header = TRUE;
36 $phpbb_root_path = './../';
37 require($phpbb_root_path . 'extension.inc');
38 require('./pagestart.' . $phpEx);
41 // Increase maximum execution time in case of a lot of users, but don't complain about it if it isn't
44 @set_time_limit(1200);
52 if ( isset($HTTP_POST_VARS['submit']) )
54 $subject = stripslashes(trim($HTTP_POST_VARS['subject']));
55 $message = stripslashes(trim($HTTP_POST_VARS['message']));
60 if ( empty($subject) )
63 $error_msg .= ( !empty($error_msg) ) ? '<br />' . $lang['Empty_subject'] : $lang['Empty_subject'];
66 if ( empty($message) )
69 $error_msg .= ( !empty($error_msg) ) ? '<br />' . $lang['Empty_message'] : $lang['Empty_message'];
72 $group_id = intval($HTTP_POST_VARS[POST_GROUPS_URL]);
74 $sql = ( $group_id != -1 ) ? "SELECT u.user_email FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug WHERE ug.group_id = $group_id AND ug.user_pending <> " . TRUE . " AND u.user_id = ug.user_id" : "SELECT user_email FROM " . USERS_TABLE;
75 if ( !($result = $db->sql_query($sql)) )
77 message_die(GENERAL_ERROR, 'Could not select group members', '', __LINE__, __FILE__, $sql);
80 if ( $row = $db->sql_fetchrow($result) )
85 $bcc_list[] = $row['user_email'];
87 while ( $row = $db->sql_fetchrow($result) );
89 $db->sql_freeresult($result);
93 $message = ( $group_id != -1 ) ? $lang['Group_not_exist'] : $lang['No_such_user'];
96 $error_msg .= ( !empty($error_msg) ) ? '<br />' . $message : $message;
101 include($phpbb_root_path . 'includes/emailer.'.$phpEx);
104 // Let's do some checking to make sure that mass mail functions
105 // are working in win32 versions of php.
107 if ( preg_match('/[c-z]:\\\.*/i', getenv('PATH')) && !$board_config['smtp_delivery'])
109 $ini_val = ( @phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var';
111 // We are running on windows, force delivery to use our smtp functions
112 // since php's are broken by default
113 $board_config['smtp_delivery'] = 1;
114 $board_config['smtp_host'] = @$ini_val('SMTP');
117 $emailer = new emailer($board_config['smtp_delivery']);
119 $emailer->from($board_config['board_email']);
120 $emailer->replyto($board_config['board_email']);
122 for ($i = 0; $i < count($bcc_list); $i++)
124 $emailer->bcc($bcc_list[$i]);
127 $email_headers = 'X-AntiAbuse: Board servername - ' . $board_config['server_name'] . "\n";
128 $email_headers .= 'X-AntiAbuse: User_id - ' . $userdata['user_id'] . "\n";
129 $email_headers .= 'X-AntiAbuse: Username - ' . $userdata['username'] . "\n";
130 $email_headers .= 'X-AntiAbuse: User IP - ' . decode_ip($user_ip) . "\n";
132 $emailer->use_template('admin_send_email');
133 $emailer->email_address($board_config['board_email']);
134 $emailer->set_subject($subject);
135 $emailer->extra_headers($email_headers);
137 $emailer->assign_vars(array(
138 'SITENAME' => $board_config['sitename'],
139 'BOARD_EMAIL' => $board_config['board_email'],
140 'MESSAGE' => $message)
145 message_die(GENERAL_MESSAGE, $lang['Email_sent'] . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>'));
151 $template->set_filenames(array(
152 'reg_header' => 'error_body.tpl')
154 $template->assign_vars(array(
155 'ERROR_MESSAGE' => $error_msg)
157 $template->assign_var_from_handle('ERROR_BOX', 'reg_header');
164 $sql = "SELECT group_id, group_name
165 FROM ".GROUPS_TABLE . "
166 WHERE group_single_user <> 1";
167 if ( !($result = $db->sql_query($sql)) )
169 message_die(GENERAL_ERROR, 'Could not obtain list of groups', '', __LINE__, __FILE__, $sql);
172 $select_list = '<select name = "' . POST_GROUPS_URL . '"><option value = "-1">' . $lang['All_users'] . '</option>';
173 if ( $row = $db->sql_fetchrow($result) )
177 $select_list .= '<option value = "' . $row['group_id'] . '">' . $row['group_name'] . '</option>';
179 while ( $row = $db->sql_fetchrow($result) );
181 $select_list .= '</select>';
186 include('./page_header_admin.'.$phpEx);
188 $template->set_filenames(array(
189 'body' => 'admin/user_email_body.tpl')
192 $template->assign_vars(array(
193 'MESSAGE' => $message,
194 'SUBJECT' => $subject,
196 'L_EMAIL_TITLE' => $lang['Email'],
197 'L_EMAIL_EXPLAIN' => $lang['Mass_email_explain'],
198 'L_COMPOSE' => $lang['Compose'],
199 'L_RECIPIENTS' => $lang['Recipients'],
200 'L_EMAIL_SUBJECT' => $lang['Subject'],
201 'L_EMAIL_MSG' => $lang['Message'],
202 'L_EMAIL' => $lang['Email'],
203 'L_NOTICE' => $notice,
205 'S_USER_ACTION' => append_sid('admin_mass_email.'.$phpEx),
206 'S_GROUP_SELECT' => $select_list)
209 $template->pparse('body');
211 include('./page_footer_admin.'.$phpEx);