1 | <?php
|
---|
2 | /**
|
---|
3 | *
|
---|
4 | * @package acp
|
---|
5 | * @version $Id$
|
---|
6 | * @copyright (c) 2006 phpBB Group
|
---|
7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
---|
8 | *
|
---|
9 | */
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * @ignore
|
---|
13 | */
|
---|
14 | if (!defined('IN_PHPBB'))
|
---|
15 | {
|
---|
16 | exit;
|
---|
17 | }
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * @package acp
|
---|
21 | */
|
---|
22 | class acp_inactive
|
---|
23 | {
|
---|
24 | var $u_action;
|
---|
25 | var $p_master;
|
---|
26 |
|
---|
27 | function acp_inactive(&$p_master)
|
---|
28 | {
|
---|
29 | $this->p_master = &$p_master;
|
---|
30 | }
|
---|
31 |
|
---|
32 | function main($id, $mode)
|
---|
33 | {
|
---|
34 | global $config, $db, $user, $auth, $template;
|
---|
35 | global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
|
---|
36 |
|
---|
37 | include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
|
---|
38 |
|
---|
39 | $user->add_lang('memberlist');
|
---|
40 |
|
---|
41 | $action = request_var('action', '');
|
---|
42 | $mark = (isset($_REQUEST['mark'])) ? request_var('mark', array(0)) : array();
|
---|
43 | $start = request_var('start', 0);
|
---|
44 | $submit = isset($_POST['submit']);
|
---|
45 |
|
---|
46 | // Sort keys
|
---|
47 | $sort_days = request_var('st', 0);
|
---|
48 | $sort_key = request_var('sk', 'i');
|
---|
49 | $sort_dir = request_var('sd', 'd');
|
---|
50 |
|
---|
51 | $form_key = 'acp_inactive';
|
---|
52 | add_form_key($form_key);
|
---|
53 |
|
---|
54 | // We build the sort key and per page settings here, because they may be needed later
|
---|
55 |
|
---|
56 | // Number of entries to display
|
---|
57 | $per_page = request_var('users_per_page', (int) $config['topics_per_page']);
|
---|
58 |
|
---|
59 | // Sorting
|
---|
60 | $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
|
---|
61 | $sort_by_text = array('i' => $user->lang['SORT_INACTIVE'], 'j' => $user->lang['SORT_REG_DATE'], 'l' => $user->lang['SORT_LAST_VISIT'], 'd' => $user->lang['SORT_LAST_REMINDER'], 'r' => $user->lang['SORT_REASON'], 'u' => $user->lang['SORT_USERNAME'], 'p' => $user->lang['SORT_POSTS'], 'e' => $user->lang['SORT_REMINDER']);
|
---|
62 | $sort_by_sql = array('i' => 'user_inactive_time', 'j' => 'user_regdate', 'l' => 'user_lastvisit', 'd' => 'user_reminded_time', 'r' => 'user_inactive_reason', 'u' => 'username_clean', 'p' => 'user_posts', 'e' => 'user_reminded');
|
---|
63 |
|
---|
64 | $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
|
---|
65 | gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
|
---|
66 |
|
---|
67 | if ($submit && sizeof($mark))
|
---|
68 | {
|
---|
69 | if ($action !== 'delete' && !check_form_key($form_key))
|
---|
70 | {
|
---|
71 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
---|
72 | }
|
---|
73 |
|
---|
74 | switch ($action)
|
---|
75 | {
|
---|
76 | case 'activate':
|
---|
77 | case 'delete':
|
---|
78 |
|
---|
79 | $sql = 'SELECT user_id, username
|
---|
80 | FROM ' . USERS_TABLE . '
|
---|
81 | WHERE ' . $db->sql_in_set('user_id', $mark);
|
---|
82 | $result = $db->sql_query($sql);
|
---|
83 |
|
---|
84 | $user_affected = array();
|
---|
85 | while ($row = $db->sql_fetchrow($result))
|
---|
86 | {
|
---|
87 | $user_affected[$row['user_id']] = $row['username'];
|
---|
88 | }
|
---|
89 | $db->sql_freeresult($result);
|
---|
90 |
|
---|
91 | if ($action == 'activate')
|
---|
92 | {
|
---|
93 | // Get those 'being activated'...
|
---|
94 | $sql = 'SELECT user_id, username' . (($config['require_activation'] == USER_ACTIVATION_ADMIN) ? ', user_email, user_lang' : '') . '
|
---|
95 | FROM ' . USERS_TABLE . '
|
---|
96 | WHERE ' . $db->sql_in_set('user_id', $mark) . '
|
---|
97 | AND user_type = ' . USER_INACTIVE;
|
---|
98 | $result = $db->sql_query($sql);
|
---|
99 |
|
---|
100 | $inactive_users = array();
|
---|
101 | while ($row = $db->sql_fetchrow($result))
|
---|
102 | {
|
---|
103 | $inactive_users[] = $row;
|
---|
104 | }
|
---|
105 | $db->sql_freeresult($result);
|
---|
106 |
|
---|
107 | user_active_flip('activate', $mark);
|
---|
108 |
|
---|
109 | if ($config['require_activation'] == USER_ACTIVATION_ADMIN && !empty($inactive_users))
|
---|
110 | {
|
---|
111 | include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
---|
112 |
|
---|
113 | $messenger = new messenger(false);
|
---|
114 |
|
---|
115 | foreach ($inactive_users as $row)
|
---|
116 | {
|
---|
117 | $messenger->template('admin_welcome_activated', $row['user_lang']);
|
---|
118 |
|
---|
119 | $messenger->to($row['user_email'], $row['username']);
|
---|
120 |
|
---|
121 | $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
|
---|
122 | $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
|
---|
123 | $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
|
---|
124 | $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
|
---|
125 |
|
---|
126 | $messenger->assign_vars(array(
|
---|
127 | 'USERNAME' => htmlspecialchars_decode($row['username']))
|
---|
128 | );
|
---|
129 |
|
---|
130 | $messenger->send(NOTIFY_EMAIL);
|
---|
131 | }
|
---|
132 |
|
---|
133 | $messenger->save_queue();
|
---|
134 | }
|
---|
135 |
|
---|
136 | if (!empty($inactive_users))
|
---|
137 | {
|
---|
138 | foreach ($inactive_users as $row)
|
---|
139 | {
|
---|
140 | add_log('admin', 'LOG_USER_ACTIVE', $row['username']);
|
---|
141 | add_log('user', $row['user_id'], 'LOG_USER_ACTIVE_USER');
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | // For activate we really need to redirect, else a refresh can result in users being deactivated again
|
---|
146 | $u_action = $this->u_action . "&$u_sort_param&start=$start";
|
---|
147 | $u_action .= ($per_page != $config['topics_per_page']) ? "&users_per_page=$per_page" : '';
|
---|
148 |
|
---|
149 | redirect($u_action);
|
---|
150 | }
|
---|
151 | else if ($action == 'delete')
|
---|
152 | {
|
---|
153 | if (confirm_box(true))
|
---|
154 | {
|
---|
155 | if (!$auth->acl_get('a_userdel'))
|
---|
156 | {
|
---|
157 | trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
|
---|
158 | }
|
---|
159 |
|
---|
160 | foreach ($mark as $user_id)
|
---|
161 | {
|
---|
162 | user_delete('retain', $user_id, $user_affected[$user_id]);
|
---|
163 | }
|
---|
164 |
|
---|
165 | add_log('admin', 'LOG_INACTIVE_' . strtoupper($action), implode(', ', $user_affected));
|
---|
166 | }
|
---|
167 | else
|
---|
168 | {
|
---|
169 | $s_hidden_fields = array(
|
---|
170 | 'mode' => $mode,
|
---|
171 | 'action' => $action,
|
---|
172 | 'mark' => $mark,
|
---|
173 | 'submit' => 1,
|
---|
174 | 'start' => $start,
|
---|
175 | );
|
---|
176 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
|
---|
177 | }
|
---|
178 | }
|
---|
179 |
|
---|
180 | break;
|
---|
181 |
|
---|
182 | case 'remind':
|
---|
183 | if (empty($config['email_enable']))
|
---|
184 | {
|
---|
185 | trigger_error($user->lang['EMAIL_DISABLED'] . adm_back_link($this->u_action), E_USER_WARNING);
|
---|
186 | }
|
---|
187 |
|
---|
188 | $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type, user_regdate, user_actkey
|
---|
189 | FROM ' . USERS_TABLE . '
|
---|
190 | WHERE ' . $db->sql_in_set('user_id', $mark) . '
|
---|
191 | AND user_inactive_reason';
|
---|
192 |
|
---|
193 | $sql .= ($config['require_activation'] == USER_ACTIVATION_ADMIN) ? ' = ' . INACTIVE_REMIND : ' <> ' . INACTIVE_MANUAL;
|
---|
194 |
|
---|
195 | $result = $db->sql_query($sql);
|
---|
196 |
|
---|
197 | if ($row = $db->sql_fetchrow($result))
|
---|
198 | {
|
---|
199 | // Send the messages
|
---|
200 | include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
---|
201 |
|
---|
202 | $messenger = new messenger();
|
---|
203 | $usernames = $user_ids = array();
|
---|
204 |
|
---|
205 | do
|
---|
206 | {
|
---|
207 | $messenger->template('user_remind_inactive', $row['user_lang']);
|
---|
208 |
|
---|
209 | $messenger->to($row['user_email'], $row['username']);
|
---|
210 | $messenger->im($row['user_jabber'], $row['username']);
|
---|
211 |
|
---|
212 | $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
|
---|
213 | $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
|
---|
214 | $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
|
---|
215 | $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
|
---|
216 |
|
---|
217 | $messenger->assign_vars(array(
|
---|
218 | 'USERNAME' => htmlspecialchars_decode($row['username']),
|
---|
219 | 'REGISTER_DATE' => $user->format_date($row['user_regdate'], false, true),
|
---|
220 | 'U_ACTIVATE' => generate_board_url() . "/ucp.$phpEx?mode=activate&u=" . $row['user_id'] . '&k=' . $row['user_actkey'])
|
---|
221 | );
|
---|
222 |
|
---|
223 | $messenger->send($row['user_notify_type']);
|
---|
224 |
|
---|
225 | $usernames[] = $row['username'];
|
---|
226 | $user_ids[] = (int) $row['user_id'];
|
---|
227 | }
|
---|
228 | while ($row = $db->sql_fetchrow($result));
|
---|
229 |
|
---|
230 | $messenger->save_queue();
|
---|
231 |
|
---|
232 | // Add the remind state to the database
|
---|
233 | $sql = 'UPDATE ' . USERS_TABLE . '
|
---|
234 | SET user_reminded = user_reminded + 1,
|
---|
235 | user_reminded_time = ' . time() . '
|
---|
236 | WHERE ' . $db->sql_in_set('user_id', $user_ids);
|
---|
237 | $db->sql_query($sql);
|
---|
238 |
|
---|
239 | add_log('admin', 'LOG_INACTIVE_REMIND', implode(', ', $usernames));
|
---|
240 | unset($usernames);
|
---|
241 | }
|
---|
242 | $db->sql_freeresult($result);
|
---|
243 |
|
---|
244 | // For remind we really need to redirect, else a refresh can result in more than one reminder
|
---|
245 | $u_action = $this->u_action . "&$u_sort_param&start=$start";
|
---|
246 | $u_action .= ($per_page != $config['topics_per_page']) ? "&users_per_page=$per_page" : '';
|
---|
247 |
|
---|
248 | redirect($u_action);
|
---|
249 |
|
---|
250 | break;
|
---|
251 | }
|
---|
252 | }
|
---|
253 |
|
---|
254 | // Define where and sort sql for use in displaying logs
|
---|
255 | $sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
|
---|
256 | $sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
|
---|
257 |
|
---|
258 | $inactive = array();
|
---|
259 | $inactive_count = 0;
|
---|
260 |
|
---|
261 | $start = view_inactive_users($inactive, $inactive_count, $per_page, $start, $sql_where, $sql_sort);
|
---|
262 |
|
---|
263 | foreach ($inactive as $row)
|
---|
264 | {
|
---|
265 | $template->assign_block_vars('inactive', array(
|
---|
266 | 'INACTIVE_DATE' => $user->format_date($row['user_inactive_time']),
|
---|
267 | 'REMINDED_DATE' => $user->format_date($row['user_reminded_time']),
|
---|
268 | 'JOINED' => $user->format_date($row['user_regdate']),
|
---|
269 | 'LAST_VISIT' => (!$row['user_lastvisit']) ? ' - ' : $user->format_date($row['user_lastvisit']),
|
---|
270 |
|
---|
271 | 'REASON' => $row['inactive_reason'],
|
---|
272 | 'USER_ID' => $row['user_id'],
|
---|
273 | 'POSTS' => ($row['user_posts']) ? $row['user_posts'] : 0,
|
---|
274 | 'REMINDED' => $row['user_reminded'],
|
---|
275 |
|
---|
276 | 'REMINDED_EXPLAIN' => $user->lang('USER_LAST_REMINDED', (int) $row['user_reminded'], $user->format_date($row['user_reminded_time'])),
|
---|
277 |
|
---|
278 | 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=overview')),
|
---|
279 | 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
|
---|
280 | 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
|
---|
281 |
|
---|
282 | 'U_USER_ADMIN' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&mode=overview&u={$row['user_id']}"),
|
---|
283 | 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id={$row['user_id']}&sr=posts") : '',
|
---|
284 | ));
|
---|
285 | }
|
---|
286 |
|
---|
287 | $option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
|
---|
288 | if ($config['email_enable'])
|
---|
289 | {
|
---|
290 | $option_ary += array('remind' => 'REMIND');
|
---|
291 | }
|
---|
292 |
|
---|
293 | $template->assign_vars(array(
|
---|
294 | 'S_INACTIVE_USERS' => true,
|
---|
295 | 'S_INACTIVE_OPTIONS' => build_select($option_ary),
|
---|
296 |
|
---|
297 | 'S_LIMIT_DAYS' => $s_limit_days,
|
---|
298 | 'S_SORT_KEY' => $s_sort_key,
|
---|
299 | 'S_SORT_DIR' => $s_sort_dir,
|
---|
300 | 'S_ON_PAGE' => on_page($inactive_count, $per_page, $start),
|
---|
301 | 'PAGINATION' => generate_pagination($this->u_action . "&$u_sort_param&users_per_page=$per_page", $inactive_count, $per_page, $start, true),
|
---|
302 | 'USERS_PER_PAGE' => $per_page,
|
---|
303 |
|
---|
304 | 'U_ACTION' => $this->u_action . '&start=' . $start,
|
---|
305 | ));
|
---|
306 |
|
---|
307 | $this->tpl_name = 'acp_inactive';
|
---|
308 | $this->page_title = 'ACP_INACTIVE_USERS';
|
---|
309 | }
|
---|
310 | }
|
---|
311 |
|
---|
312 | ?>
|
---|