1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/acp/acp_inactive.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,306 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package acp
1.8 +* @version $Id$
1.9 +* @copyright (c) 2006 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* @package acp
1.24 +*/
1.25 +class acp_inactive
1.26 +{
1.27 + var $u_action;
1.28 + var $p_master;
1.29 +
1.30 + function acp_inactive(&$p_master)
1.31 + {
1.32 + $this->p_master = &$p_master;
1.33 + }
1.34 +
1.35 + function main($id, $mode)
1.36 + {
1.37 + global $config, $db, $user, $auth, $template;
1.38 + global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
1.39 +
1.40 + include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
1.41 +
1.42 + $user->add_lang('memberlist');
1.43 +
1.44 + $action = request_var('action', '');
1.45 + $mark = (isset($_REQUEST['mark'])) ? request_var('mark', array(0)) : array();
1.46 + $start = request_var('start', 0);
1.47 + $submit = isset($_POST['submit']);
1.48 +
1.49 + // Sort keys
1.50 + $sort_days = request_var('st', 0);
1.51 + $sort_key = request_var('sk', 'i');
1.52 + $sort_dir = request_var('sd', 'd');
1.53 +
1.54 + $form_key = 'acp_inactive';
1.55 + add_form_key($form_key);
1.56 +
1.57 + // We build the sort key and per page settings here, because they may be needed later
1.58 +
1.59 + // Number of entries to display
1.60 + $per_page = request_var('users_per_page', (int) $config['topics_per_page']);
1.61 +
1.62 + // Sorting
1.63 + $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']);
1.64 + $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']);
1.65 + $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');
1.66 +
1.67 + $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
1.68 + 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);
1.69 +
1.70 + if ($submit && sizeof($mark))
1.71 + {
1.72 + if ($action !== 'delete' && !check_form_key($form_key))
1.73 + {
1.74 + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
1.75 + }
1.76 +
1.77 + switch ($action)
1.78 + {
1.79 + case 'activate':
1.80 + case 'delete':
1.81 +
1.82 + $sql = 'SELECT user_id, username
1.83 + FROM ' . USERS_TABLE . '
1.84 + WHERE ' . $db->sql_in_set('user_id', $mark);
1.85 + $result = $db->sql_query($sql);
1.86 +
1.87 + $user_affected = array();
1.88 + while ($row = $db->sql_fetchrow($result))
1.89 + {
1.90 + $user_affected[$row['user_id']] = $row['username'];
1.91 + }
1.92 + $db->sql_freeresult($result);
1.93 +
1.94 + if ($action == 'activate')
1.95 + {
1.96 + // Get those 'being activated'...
1.97 + $sql = 'SELECT user_id, username' . (($config['require_activation'] == USER_ACTIVATION_ADMIN) ? ', user_email, user_lang' : '') . '
1.98 + FROM ' . USERS_TABLE . '
1.99 + WHERE ' . $db->sql_in_set('user_id', $mark) . '
1.100 + AND user_type = ' . USER_INACTIVE;
1.101 + $result = $db->sql_query($sql);
1.102 +
1.103 + $inactive_users = array();
1.104 + while ($row = $db->sql_fetchrow($result))
1.105 + {
1.106 + $inactive_users[] = $row;
1.107 + }
1.108 + $db->sql_freeresult($result);
1.109 +
1.110 + user_active_flip('activate', $mark);
1.111 +
1.112 + if ($config['require_activation'] == USER_ACTIVATION_ADMIN && !empty($inactive_users))
1.113 + {
1.114 + include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
1.115 +
1.116 + $messenger = new messenger(false);
1.117 +
1.118 + foreach ($inactive_users as $row)
1.119 + {
1.120 + $messenger->template('admin_welcome_activated', $row['user_lang']);
1.121 +
1.122 + $messenger->to($row['user_email'], $row['username']);
1.123 +
1.124 + $messenger->anti_abuse_headers($config, $user);
1.125 +
1.126 + $messenger->assign_vars(array(
1.127 + 'USERNAME' => htmlspecialchars_decode($row['username']))
1.128 + );
1.129 +
1.130 + $messenger->send(NOTIFY_EMAIL);
1.131 + }
1.132 +
1.133 + $messenger->save_queue();
1.134 + }
1.135 +
1.136 + if (!empty($inactive_users))
1.137 + {
1.138 + foreach ($inactive_users as $row)
1.139 + {
1.140 + add_log('admin', 'LOG_USER_ACTIVE', $row['username']);
1.141 + add_log('user', $row['user_id'], 'LOG_USER_ACTIVE_USER');
1.142 + }
1.143 + }
1.144 +
1.145 + // For activate we really need to redirect, else a refresh can result in users being deactivated again
1.146 + $u_action = $this->u_action . "&$u_sort_param&start=$start";
1.147 + $u_action .= ($per_page != $config['topics_per_page']) ? "&users_per_page=$per_page" : '';
1.148 +
1.149 + redirect($u_action);
1.150 + }
1.151 + else if ($action == 'delete')
1.152 + {
1.153 + if (confirm_box(true))
1.154 + {
1.155 + if (!$auth->acl_get('a_userdel'))
1.156 + {
1.157 + trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
1.158 + }
1.159 +
1.160 + foreach ($mark as $user_id)
1.161 + {
1.162 + user_delete('retain', $user_id, $user_affected[$user_id]);
1.163 + }
1.164 +
1.165 + add_log('admin', 'LOG_INACTIVE_' . strtoupper($action), implode(', ', $user_affected));
1.166 + }
1.167 + else
1.168 + {
1.169 + $s_hidden_fields = array(
1.170 + 'mode' => $mode,
1.171 + 'action' => $action,
1.172 + 'mark' => $mark,
1.173 + 'submit' => 1,
1.174 + 'start' => $start,
1.175 + );
1.176 + confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
1.177 + }
1.178 + }
1.179 +
1.180 + break;
1.181 +
1.182 + case 'remind':
1.183 + if (empty($config['email_enable']))
1.184 + {
1.185 + trigger_error($user->lang['EMAIL_DISABLED'] . adm_back_link($this->u_action), E_USER_WARNING);
1.186 + }
1.187 +
1.188 + $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type, user_regdate, user_actkey
1.189 + FROM ' . USERS_TABLE . '
1.190 + WHERE ' . $db->sql_in_set('user_id', $mark) . '
1.191 + AND user_inactive_reason';
1.192 +
1.193 + $sql .= ($config['require_activation'] == USER_ACTIVATION_ADMIN) ? ' = ' . INACTIVE_REMIND : ' <> ' . INACTIVE_MANUAL;
1.194 +
1.195 + $result = $db->sql_query($sql);
1.196 +
1.197 + if ($row = $db->sql_fetchrow($result))
1.198 + {
1.199 + // Send the messages
1.200 + include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
1.201 +
1.202 + $messenger = new messenger();
1.203 + $usernames = $user_ids = array();
1.204 +
1.205 + do
1.206 + {
1.207 + $messenger->template('user_remind_inactive', $row['user_lang']);
1.208 +
1.209 + $messenger->to($row['user_email'], $row['username']);
1.210 + $messenger->im($row['user_jabber'], $row['username']);
1.211 +
1.212 + $messenger->anti_abuse_headers($config, $user);
1.213 +
1.214 + $messenger->assign_vars(array(
1.215 + 'USERNAME' => htmlspecialchars_decode($row['username']),
1.216 + 'REGISTER_DATE' => $user->format_date($row['user_regdate'], false, true),
1.217 + 'U_ACTIVATE' => generate_board_url() . "/ucp.$phpEx?mode=activate&u=" . $row['user_id'] . '&k=' . $row['user_actkey'])
1.218 + );
1.219 +
1.220 + $messenger->send($row['user_notify_type']);
1.221 +
1.222 + $usernames[] = $row['username'];
1.223 + $user_ids[] = (int) $row['user_id'];
1.224 + }
1.225 + while ($row = $db->sql_fetchrow($result));
1.226 +
1.227 + $messenger->save_queue();
1.228 +
1.229 + // Add the remind state to the database
1.230 + $sql = 'UPDATE ' . USERS_TABLE . '
1.231 + SET user_reminded = user_reminded + 1,
1.232 + user_reminded_time = ' . time() . '
1.233 + WHERE ' . $db->sql_in_set('user_id', $user_ids);
1.234 + $db->sql_query($sql);
1.235 +
1.236 + add_log('admin', 'LOG_INACTIVE_REMIND', implode(', ', $usernames));
1.237 + unset($usernames);
1.238 + }
1.239 + $db->sql_freeresult($result);
1.240 +
1.241 + // For remind we really need to redirect, else a refresh can result in more than one reminder
1.242 + $u_action = $this->u_action . "&$u_sort_param&start=$start";
1.243 + $u_action .= ($per_page != $config['topics_per_page']) ? "&users_per_page=$per_page" : '';
1.244 +
1.245 + redirect($u_action);
1.246 +
1.247 + break;
1.248 + }
1.249 + }
1.250 +
1.251 + // Define where and sort sql for use in displaying logs
1.252 + $sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
1.253 + $sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
1.254 +
1.255 + $inactive = array();
1.256 + $inactive_count = 0;
1.257 +
1.258 + $start = view_inactive_users($inactive, $inactive_count, $per_page, $start, $sql_where, $sql_sort);
1.259 +
1.260 + foreach ($inactive as $row)
1.261 + {
1.262 + $template->assign_block_vars('inactive', array(
1.263 + 'INACTIVE_DATE' => $user->format_date($row['user_inactive_time']),
1.264 + 'REMINDED_DATE' => $user->format_date($row['user_reminded_time']),
1.265 + 'JOINED' => $user->format_date($row['user_regdate']),
1.266 + 'LAST_VISIT' => (!$row['user_lastvisit']) ? ' - ' : $user->format_date($row['user_lastvisit']),
1.267 +
1.268 + 'REASON' => $row['inactive_reason'],
1.269 + 'USER_ID' => $row['user_id'],
1.270 + 'POSTS' => ($row['user_posts']) ? $row['user_posts'] : 0,
1.271 + 'REMINDED' => $row['user_reminded'],
1.272 +
1.273 + 'REMINDED_EXPLAIN' => $user->lang('USER_LAST_REMINDED', (int) $row['user_reminded'], $user->format_date($row['user_reminded_time'])),
1.274 +
1.275 + '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')),
1.276 + 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
1.277 + 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
1.278 +
1.279 + 'U_USER_ADMIN' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&mode=overview&u={$row['user_id']}"),
1.280 + 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id={$row['user_id']}&sr=posts") : '',
1.281 + ));
1.282 + }
1.283 +
1.284 + $option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
1.285 + if ($config['email_enable'])
1.286 + {
1.287 + $option_ary += array('remind' => 'REMIND');
1.288 + }
1.289 +
1.290 + $template->assign_vars(array(
1.291 + 'S_INACTIVE_USERS' => true,
1.292 + 'S_INACTIVE_OPTIONS' => build_select($option_ary),
1.293 +
1.294 + 'S_LIMIT_DAYS' => $s_limit_days,
1.295 + 'S_SORT_KEY' => $s_sort_key,
1.296 + 'S_SORT_DIR' => $s_sort_dir,
1.297 + 'S_ON_PAGE' => on_page($inactive_count, $per_page, $start),
1.298 + 'PAGINATION' => generate_pagination($this->u_action . "&$u_sort_param&users_per_page=$per_page", $inactive_count, $per_page, $start, true),
1.299 + 'USERS_PER_PAGE' => $per_page,
1.300 +
1.301 + 'U_ACTION' => $this->u_action . "&$u_sort_param&users_per_page=$per_page&start=$start",
1.302 + ));
1.303 +
1.304 + $this->tpl_name = 'acp_inactive';
1.305 + $this->page_title = 'ACP_INACTIVE_USERS';
1.306 + }
1.307 +}
1.308 +
1.309 +?>
1.310 \ No newline at end of file