1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/mcp/mcp_notes.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,251 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package mcp
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 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 +* mcp_notes
1.24 +* Displays notes about a user
1.25 +* @package mcp
1.26 +*/
1.27 +class mcp_notes
1.28 +{
1.29 + var $p_master;
1.30 + var $u_action;
1.31 +
1.32 + function mcp_notes(&$p_master)
1.33 + {
1.34 + $this->p_master = &$p_master;
1.35 + }
1.36 +
1.37 + function main($id, $mode)
1.38 + {
1.39 + global $auth, $db, $user, $template;
1.40 + global $config, $phpbb_root_path, $phpEx;
1.41 +
1.42 + $action = request_var('action', array('' => ''));
1.43 +
1.44 + if (is_array($action))
1.45 + {
1.46 + list($action, ) = each($action);
1.47 + }
1.48 +
1.49 + $this->page_title = 'MCP_NOTES';
1.50 +
1.51 + switch ($mode)
1.52 + {
1.53 + case 'front':
1.54 + $template->assign_vars(array(
1.55 + 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=mcp&field=username&select_single=true'),
1.56 + 'U_POST_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes'),
1.57 +
1.58 + 'L_TITLE' => $user->lang['MCP_NOTES'],
1.59 + ));
1.60 +
1.61 + $this->tpl_name = 'mcp_notes_front';
1.62 + break;
1.63 +
1.64 + case 'user_notes':
1.65 + $user->add_lang('acp/common');
1.66 +
1.67 + $this->mcp_notes_user_view($action);
1.68 + $this->tpl_name = 'mcp_notes_user';
1.69 + break;
1.70 + }
1.71 + }
1.72 +
1.73 + /**
1.74 + * Display user notes
1.75 + */
1.76 + function mcp_notes_user_view($action)
1.77 + {
1.78 + global $phpEx, $phpbb_root_path, $config;
1.79 + global $template, $db, $user, $auth;
1.80 +
1.81 + $user_id = request_var('u', 0);
1.82 + $username = request_var('username', '', true);
1.83 + $start = request_var('start', 0);
1.84 + $st = request_var('st', 0);
1.85 + $sk = request_var('sk', 'b');
1.86 + $sd = request_var('sd', 'd');
1.87 +
1.88 + add_form_key('mcp_notes');
1.89 +
1.90 + $sql_where = ($user_id) ? "user_id = $user_id" : "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
1.91 +
1.92 + $sql = 'SELECT *
1.93 + FROM ' . USERS_TABLE . "
1.94 + WHERE $sql_where";
1.95 + $result = $db->sql_query($sql);
1.96 + $userrow = $db->sql_fetchrow($result);
1.97 + $db->sql_freeresult($result);
1.98 +
1.99 + if (!$userrow)
1.100 + {
1.101 + trigger_error('NO_USER');
1.102 + }
1.103 +
1.104 + $user_id = $userrow['user_id'];
1.105 +
1.106 + // Populate user id to the currently active module (this module)
1.107 + // The following method is another way of adjusting module urls. It is the easy variant if we want
1.108 + // to directly adjust the current module url based on data retrieved within the same module.
1.109 + if (strpos($this->u_action, "&u=$user_id") === false)
1.110 + {
1.111 + $this->p_master->adjust_url('&u=' . $user_id);
1.112 + $this->u_action .= "&u=$user_id";
1.113 + }
1.114 +
1.115 + $deletemark = ($action == 'del_marked') ? true : false;
1.116 + $deleteall = ($action == 'del_all') ? true : false;
1.117 + $marked = request_var('marknote', array(0));
1.118 + $usernote = utf8_normalize_nfc(request_var('usernote', '', true));
1.119 +
1.120 + // Handle any actions
1.121 + if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs'))
1.122 + {
1.123 + $where_sql = '';
1.124 + if ($deletemark && $marked)
1.125 + {
1.126 + $sql_in = array();
1.127 + foreach ($marked as $mark)
1.128 + {
1.129 + $sql_in[] = $mark;
1.130 + }
1.131 + $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
1.132 + unset($sql_in);
1.133 + }
1.134 +
1.135 + if ($where_sql || $deleteall)
1.136 + {
1.137 + if (check_form_key('mcp_notes'))
1.138 + {
1.139 + $sql = 'DELETE FROM ' . LOG_TABLE . '
1.140 + WHERE log_type = ' . LOG_USERS . "
1.141 + AND reportee_id = $user_id
1.142 + $where_sql";
1.143 + $db->sql_query($sql);
1.144 +
1.145 + add_log('admin', 'LOG_CLEAR_USER', $userrow['username']);
1.146 +
1.147 + $msg = ($deletemark) ? 'MARKED_NOTES_DELETED' : 'ALL_NOTES_DELETED';
1.148 + }
1.149 + else
1.150 + {
1.151 + $msg = 'FORM_INVALID';
1.152 + }
1.153 + $redirect = $this->u_action . '&u=' . $user_id;
1.154 + meta_refresh(3, $redirect);
1.155 + trigger_error($user->lang[$msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
1.156 + }
1.157 + }
1.158 +
1.159 + if ($usernote && $action == 'add_feedback')
1.160 + {
1.161 + if (check_form_key('mcp_notes'))
1.162 + {
1.163 + add_log('admin', 'LOG_USER_FEEDBACK', $userrow['username']);
1.164 + add_log('mod', 0, 0, 'LOG_USER_FEEDBACK', $userrow['username']);
1.165 +
1.166 + add_log('user', $user_id, 'LOG_USER_GENERAL', $usernote);
1.167 + $msg = $user->lang['USER_FEEDBACK_ADDED'];
1.168 + }
1.169 + else
1.170 + {
1.171 + $msg = $user->lang['FORM_INVALID'];
1.172 + }
1.173 + $redirect = $this->u_action;
1.174 + meta_refresh(3, $redirect);
1.175 +
1.176 + trigger_error($msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
1.177 + }
1.178 +
1.179 + // Generate the appropriate user information for the user we are looking at
1.180 + if (!function_exists('get_user_avatar'))
1.181 + {
1.182 + include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
1.183 + }
1.184 +
1.185 + $rank_title = $rank_img = '';
1.186 + $avatar_img = get_user_avatar($userrow['user_avatar'], $userrow['user_avatar_type'], $userrow['user_avatar_width'], $userrow['user_avatar_height']);
1.187 +
1.188 + $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.189 + $sort_by_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_DATE'], 'c' => $user->lang['SORT_IP'], 'd' => $user->lang['SORT_ACTION']);
1.190 + $sort_by_sql = array('a' => 'u.username_clean', 'b' => 'l.log_time', 'c' => 'l.log_ip', 'd' => 'l.log_operation');
1.191 +
1.192 + $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
1.193 + gen_sort_selects($limit_days, $sort_by_text, $st, $sk, $sd, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
1.194 +
1.195 + // Define where and sort sql for use in displaying logs
1.196 + $sql_where = ($st) ? (time() - ($st * 86400)) : 0;
1.197 + $sql_sort = $sort_by_sql[$sk] . ' ' . (($sd == 'd') ? 'DESC' : 'ASC');
1.198 +
1.199 + $keywords = utf8_normalize_nfc(request_var('keywords', '', true));
1.200 + $keywords_param = !empty($keywords) ? '&keywords=' . urlencode(htmlspecialchars_decode($keywords)) : '';
1.201 +
1.202 + $log_data = array();
1.203 + $log_count = 0;
1.204 + $start = view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort, $keywords);
1.205 +
1.206 + if ($log_count)
1.207 + {
1.208 + $template->assign_var('S_USER_NOTES', true);
1.209 +
1.210 + foreach ($log_data as $row)
1.211 + {
1.212 + $template->assign_block_vars('usernotes', array(
1.213 + 'REPORT_BY' => $row['username_full'],
1.214 + 'REPORT_AT' => $user->format_date($row['time']),
1.215 + 'ACTION' => $row['action'],
1.216 + 'IP' => $row['ip'],
1.217 + 'ID' => $row['id'])
1.218 + );
1.219 + }
1.220 + }
1.221 +
1.222 + $template->assign_vars(array(
1.223 + 'U_POST_ACTION' => $this->u_action,
1.224 + 'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false,
1.225 + 'S_SELECT_SORT_DIR' => $s_sort_dir,
1.226 + 'S_SELECT_SORT_KEY' => $s_sort_key,
1.227 + 'S_SELECT_SORT_DAYS' => $s_limit_days,
1.228 + 'S_KEYWORDS' => $keywords,
1.229 +
1.230 + 'L_TITLE' => $user->lang['MCP_NOTES_USER'],
1.231 +
1.232 + 'PAGE_NUMBER' => on_page($log_count, $config['topics_per_page'], $start),
1.233 + 'PAGINATION' => generate_pagination($this->u_action . "&$u_sort_param$keywords_param", $log_count, $config['topics_per_page'], $start),
1.234 + 'TOTAL_REPORTS' => ($log_count == 1) ? $user->lang['LIST_REPORT'] : sprintf($user->lang['LIST_REPORTS'], $log_count),
1.235 +
1.236 + 'RANK_TITLE' => $rank_title,
1.237 + 'JOINED' => $user->format_date($userrow['user_regdate']),
1.238 + 'POSTS' => ($userrow['user_posts']) ? $userrow['user_posts'] : 0,
1.239 + 'WARNINGS' => ($userrow['user_warnings']) ? $userrow['user_warnings'] : 0,
1.240 +
1.241 + 'USERNAME_FULL' => get_username_string('full', $userrow['user_id'], $userrow['username'], $userrow['user_colour']),
1.242 + 'USERNAME_COLOUR' => get_username_string('colour', $userrow['user_id'], $userrow['username'], $userrow['user_colour']),
1.243 + 'USERNAME' => get_username_string('username', $userrow['user_id'], $userrow['username'], $userrow['user_colour']),
1.244 + 'U_PROFILE' => get_username_string('profile', $userrow['user_id'], $userrow['username'], $userrow['user_colour']),
1.245 +
1.246 + 'AVATAR_IMG' => $avatar_img,
1.247 + 'RANK_IMG' => $rank_img,
1.248 + )
1.249 + );
1.250 + }
1.251 +
1.252 +}
1.253 +
1.254 +?>
1.255 \ No newline at end of file