1 rizwank 1.1 <?php
2 /***************************************************************************
3 * admin_mass_email.php
4 * -------------------
5 * begin : Thu May 31, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
8 *
9 * $Id: admin_mass_email.php,v 1.15.2.5 2002/05/20 00:52:18 psotfx Exp $
10 *
11 ****************************************************************************/
12
13 /***************************************************************************
14 *
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.
19 *
20 ***************************************************************************/
21
22 rizwank 1.1 define('IN_PHPBB', 1);
23
24 if( !empty($setmodules) )
25 {
26 $filename = basename(__FILE__);
27 $module['General']['Mass_Email'] = $filename;
28
29 return;
30 }
31
32 //
33 // Load default header
34 //
35 $no_page_header = TRUE;
36 $phpbb_root_path = './../';
37 require($phpbb_root_path . 'extension.inc');
38 require('./pagestart.' . $phpEx);
39
40 //
41 // Increase maximum execution time in case of a lot of users, but don't complain about it if it isn't
42 // allowed.
43 rizwank 1.1 //
44 @set_time_limit(1200);
45
46 $message = '';
47 $subject = '';
48
49 //
50 // Do the job ...
51 //
52 if ( isset($HTTP_POST_VARS['submit']) )
53 {
54 $subject = stripslashes(trim($HTTP_POST_VARS['subject']));
55 $message = stripslashes(trim($HTTP_POST_VARS['message']));
56
57 $error = FALSE;
58 $error_msg = '';
59
60 if ( empty($subject) )
61 {
62 $error = true;
63 $error_msg .= ( !empty($error_msg) ) ? '<br />' . $lang['Empty_subject'] : $lang['Empty_subject'];
64 rizwank 1.1 }
65
66 if ( empty($message) )
67 {
68 $error = true;
69 $error_msg .= ( !empty($error_msg) ) ? '<br />' . $lang['Empty_message'] : $lang['Empty_message'];
70 }
71
72 $group_id = intval($HTTP_POST_VARS[POST_GROUPS_URL]);
73
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)) )
76 {
77 message_die(GENERAL_ERROR, 'Could not select group members', '', __LINE__, __FILE__, $sql);
78 }
79
80 if ( $row = $db->sql_fetchrow($result) )
81 {
82 $bcc_list = '';
83 do
84 {
85 rizwank 1.1 $bcc_list .= ( ( $bcc_list != '' ) ? ', ' : '' ) . $row['user_email'];
86 }
87 while ( $row = $db->sql_fetchrow($result) );
88
89 $db->sql_freeresult($result);
90 }
91 else
92 {
93 $message = ( $group_id != -1 ) ? $lang['Group_not_exist'] : $lang['No_such_user'];
94
95 $error = true;
96 $error_msg .= ( !empty($error_msg) ) ? '<br />' . $message : $message;
97 }
98
99 if ( !$error )
100 {
101 include($phpbb_root_path . 'includes/emailer.'.$phpEx);
102
103 //
104 // Let's do some checking to make sure that mass mail functions
105 // are working in win32 versions of php.
106 rizwank 1.1 //
107 if ( preg_match('/[c-z]:\\\.*/i', getenv('PATH')) && !$board_config['smtp_delivery'])
108 {
109 $ini_val = ( @phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var';
110
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');
115 }
116
117 $emailer = new emailer($board_config['smtp_delivery']);
118
119 $email_headers = 'Return-Path: ' . $userdata['board_email'] . "\nFrom: " . $board_config['board_email'] . "\n";
120 $email_headers .= 'X-AntiAbuse: Board servername - ' . $board_config['server_name'] . "\n";
121 $email_headers .= 'X-AntiAbuse: User_id - ' . $userdata['user_id'] . "\n";
122 $email_headers .= 'X-AntiAbuse: Username - ' . $userdata['username'] . "\n";
123 $email_headers .= 'X-AntiAbuse: User IP - ' . decode_ip($user_ip) . "\n";
124 $email_headers .= "Bcc: $bcc_list\n";
125
126 $emailer->use_template('admin_send_email');
127 rizwank 1.1 $emailer->email_address($board_config['board_email']);
128 $emailer->set_subject($subject);
129 $emailer->extra_headers($email_headers);
130
131 $emailer->assign_vars(array(
132 'SITENAME' => $board_config['sitename'],
133 'BOARD_EMAIL' => $board_config['board_email'],
134 'MESSAGE' => $message)
135 );
136 $emailer->send();
137 $emailer->reset();
138
139 message_die(GENERAL_MESSAGE, $lang['Email_sent'] . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>'));
140 }
141 }
142
143 if ( $error )
144 {
145 $template->set_filenames(array(
146 'reg_header' => 'error_body.tpl')
147 );
148 rizwank 1.1 $template->assign_vars(array(
149 'ERROR_MESSAGE' => $error_msg)
150 );
151 $template->assign_var_from_handle('ERROR_BOX', 'reg_header');
152 }
153
154 //
155 // Initial selection
156 //
157
158 $sql = "SELECT group_id, group_name
159 FROM ".GROUPS_TABLE . "
160 WHERE group_single_user <> 1";
161 if ( !($result = $db->sql_query($sql)) )
162 {
163 message_die(GENERAL_ERROR, 'Could not obtain list of groups', '', __LINE__, __FILE__, $sql);
164 }
165
166 $select_list = '<select name = "' . POST_GROUPS_URL . '"><option value = "-1">' . $lang['All_users'] . '</option>';
167 if ( $row = $db->sql_fetchrow($result) )
168 {
169 rizwank 1.1 do
170 {
171 $select_list .= '<option value = "' . $row['group_id'] . '">' . $row['group_name'] . '</option>';
172 }
173 while ( $row = $db->sql_fetchrow($result) );
174 }
175 $select_list .= '</select>';
176
177 //
178 // Generate page
179 //
180 include('./page_header_admin.'.$phpEx);
181
182 $template->set_filenames(array(
183 'body' => 'admin/user_email_body.tpl')
184 );
185
186 $template->assign_vars(array(
187 'MESSAGE' => $message,
188 'SUBJECT' => $subject,
189
190 rizwank 1.1 'L_EMAIL_TITLE' => $lang['Email'],
191 'L_EMAIL_EXPLAIN' => $lang['Mass_email_explain'],
192 'L_COMPOSE' => $lang['Compose'],
193 'L_RECIPIENTS' => $lang['Recipients'],
194 'L_EMAIL_SUBJECT' => $lang['Subject'],
195 'L_EMAIL_MSG' => $lang['Message'],
196 'L_EMAIL' => $lang['Email'],
197 'L_NOTICE' => $notice,
198
199 'S_USER_ACTION' => append_sid('admin_mass_email.'.$phpEx),
200 'S_GROUP_SELECT' => $select_list)
201 );
202
203 $template->pparse('body');
204
205 include('./page_footer_admin.'.$phpEx);
206
207 ?>
|