root/admin/admin_mass_email.php

Revision 324, 6.0 kB (checked in by Nafania, 1 year ago)

Много мелких изменений. Если используется xbtt, то надо обязательно скачать новую версию на форуме.
Добавлен файл cron.php - если есть возможность, то пускайте cron таски через него. Особенно если используете массовую рассылку почты.

Line 
1 <?php
2 /***************************************************************************</span>
3 <span class="code-comment">*                             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.7 2003/05/03 23:24:01 acydburn 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 if( !empty($setmodules) )</span>
23 <span class="code-keyword">{
24     $filename = basename(__FILE__);
25     $module['general']['mass_email'] = $filename;
26
27     return;
28 }
29
30 define('IN_PHPBB', 1);
31
32 //</span>
33 <span class="code-comment">// Load default header
34 //
35 $no_page_header = TRUE;
36 $root_path = './../';</span>
37 <span class="code-lang">require_once($root_path . 'extension.inc');
38 require_once('./pagestart.' . $phpEx);
39
40 //</span>
41 <span class="code-comment">// Increase maximum execution time in case of a lot of users, but don't complain about it if it isn't
42 // allowed.
43 //
44 @set_time_limit(0);</span>
45 <span class="code-keyword">@ignore_user_abort(true);
46 @ini_set('memory_limit', -1);
47
48 $message = '';
49 $subject = '';
50 $error = FALSE;
51
52 //</span>
53 <span class="code-comment">// Do the job ...
54 //
55 if ( isset($_POST['submit']) ) {</span>
56 <span class="code-keyword">    $subject = ( STRIP ? stripslashes(trim($_POST['subject'])) : trim($_POST['subject']) );
57     $message = ( STRIP ? stripslashes(trim($_POST['message'])) : trim($_POST['message']) );
58
59     $use_queue = ( isset($_POST['imediatly_send']) ? false : true );
60     $priority = ( isset($_POST['priority']) ? intval($_POST['priority']) : MAIL_NORMAL_PRIORITY );
61
62     $error = FALSE;
63     $error_msg = '';
64
65     if ( empty($subject) ) {
66         $error = true;
67         $error_msg .= ( !empty($error_msg) ) ? '<br />' . $lang['empty_subject'] : $lang['empty_subject'];
68     }
69
70     if ( empty($message) ) {
71         $error = true;
72         $error_msg .= ( !empty($error_msg) ) ? '<br />' . $lang['empty_message'] : $lang['empty_message'];
73     }
74
75     $group_id = ( isset($_POST[POST_GROUPS_URL]) ? intval($_POST[POST_GROUPS_URL]) : 0 );
76
77     $sql = ( $group_id != -1 ) ? "SELECT u.email FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug WHERE ug.group_id = $group_id AND u.uid = ug.user_id" : "SELECT email FROM " . USERS_TABLE;
78     $result = $db->sql_query($sql);
79
80     if ( ( $row = $db->sql_fetchrow($result) ) && !$error ) {
81
82         $i = $j = 0;
83
84         // Send with BCC, no more than 50 recipients for one mail (to not exceed the limit)
85         $max_chunk_size = 150;
86         $email_list = array();
87
88         do
89         {
90             if ( $i == $max_chunk_size )
91             {
92                 $i = 0;
93
94                 if (sizeof($email_list))
95                 {
96                     $j++;
97                 }
98             }
99
100             $email_list[$j][$i]['email']    = $row['email'];
101             $i++;
102         }
103         while ($row = $db->sql_fetchrow($result));
104         $db->sql_freeresult($result);
105
106         // Send the messages
107         include_once($root_path . 'include/functions_messenger.' . $phpEx);
108         $messenger = new messenger($use_queue);
109
110         $errored = false;
111
112         for ($i = 0, $size = sizeof($email_list); $i < $size; $i++)
113         {
114             $send_to = false;
115             for ($j = 0, $list_size = sizeof($email_list[$i]); $j < $list_size; $j++)
116             {
117                 $email_row = $email_list[$i][$j];
118
119                 if ( sizeof($email_list[$i]) == 1 ) {
120                     $messenger->to($email_row['email']);
121                 }
122                 else {
123                     $messenger->bcc($email_row['email']);
124                     $send_to = true;
125                 }
126             }
127             if ( $send_to ) {
128                 $messenger->to($config['sitemail']);
129             }
130             $messenger->template('admin_send_email');
131             $messenger->subject($subject);
132             $messenger->set_mail_priority($priority);
133
134              $messenger->assign_vars(array(
135                 'BOARD_EMAIL' => $config['sitemail'],
136                 'MESSAGE' => $message
137             ));
138             unset($email_list[$i]);
139
140             $messenger->send(NOTIFY_EMAIL);
141
142         }
143
144         $messenger->save_queue();
145
146
147         trigger_error($lang['email_sent'] . '<br /><br />' . sprintf($lang['click_return_admin_index'],  '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>'));
148         return;
149      }
150      else {
151         $message = ( $group_id != -1 ) ? $lang['group_not_exist'] : $lang['no_such_user'];
152
153         $error = true;
154         $error_msg .= ( !empty($error_msg) ) ? '<br />' . $message : $message;
155      }
156 }
157
158 if ( $error )
159 {
160     $template->set_filenames(array(
161         'reg_header' => '../admin/error_body.tpl'
162     ));
163
164     $template->assign_vars(array(
165         'ERROR_MESSAGE' => $error_msg)
166     );
167     $tpl = $template->assign_display('reg_header');
168
169     $template->assign_vars(array(
170         'ERROR_BOX' => $tpl
171     ));
172 }
173
174 //</span>
175 <span class="code-comment">// Initial selection
176 //
177
178 $sql = "SELECT group_id, group_name</span>
179 <span class="code-lang">    FROM ".GROUPS_TABLE . "
180     WHERE group_single_user <> 1";
181 $result = $db->sql_query($sql);
182
183 $select_list = '<select name = "' . POST_GROUPS_URL . '"><option value = "-1">' . $lang['all_users'] . '</option>';</span>
184 <span class="code-lang">if ( $row = $db->sql_fetchrow($result) )
185 {
186     do
187     {
188         $select_list .= '<option value = "' . $row['group_id'] . '">' . $row['group_name'] . '</option>';
189     }
190     while ( $row = $db->sql_fetchrow($result) );
191 }
192 $select_list .= '</select>';
193
194 $priority_options = '';</span>
195 <span class="code-lang">foreach ( array( $lang['normal'] => MAIL_NORMAL_PRIORITY, $lang['low'] => MAIL_LOW_PRIORITY, $lang['high'] => MAIL_HIGH_PRIORITY) AS $name => $value ) {
196     $priority_options .= '<option value="' . $value . '">' . $name . '</option>';
197 }
198
199 //</span>
200 <span class="code-comment">// Generate page
201 //
202 include('./page_header_admin.'.$phpEx);
203
204 $template->set_filenames(array(</span>
205 <span class="code-lang">    'body' => '../admin/user_email_body.tpl')
206 );
207
208 $template->assign_vars(array(</span>
209 <span class="code-lang">    'MESSAGE' => $message,
210     'SUBJECT' => $subject,
211
212     'L_EMAIL_TITLE' => $lang['email'],
213     'L_EMAIL_EXPLAIN' => $lang['mass_email_explain'],
214     'L_EMAIL_SUBJECT' => $lang['subject'],
215     'L_EMAIL_MSG' => $lang['message'],
216
217     'S_USER_ACTION' => append_sid('admin_mass_email.'.$phpEx),
218     'S_GROUP_SELECT' => $select_list,
219     'S_PRIORITY_OPTIONS' => $priority_options )
220 );
221
222 $template->display('body');</span>
223 <span class="code-lang">
224 include('./page_footer_admin.'.$phpEx);
225
226 ?>
Note: See TracBrowser for help on using the browser.