Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 137 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| mcp_notes | |
0.00% |
0 / 135 |
|
0.00% |
0 / 3 |
1190 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| main | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
20 | |||
| mcp_notes_user_view | |
0.00% |
0 / 115 |
|
0.00% |
0 / 1 |
870 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | /** |
| 15 | * @ignore |
| 16 | */ |
| 17 | if (!defined('IN_PHPBB')) |
| 18 | { |
| 19 | exit; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * mcp_notes |
| 24 | * Displays notes about a user |
| 25 | */ |
| 26 | class mcp_notes |
| 27 | { |
| 28 | var $p_master; |
| 29 | var $u_action; |
| 30 | |
| 31 | function __construct($p_master) |
| 32 | { |
| 33 | $this->p_master = $p_master; |
| 34 | } |
| 35 | |
| 36 | function main($id, $mode) |
| 37 | { |
| 38 | global $user, $template, $request; |
| 39 | global $phpbb_root_path, $phpEx; |
| 40 | |
| 41 | $action = $request->variable('action', array('' => '')); |
| 42 | |
| 43 | if (is_array($action)) |
| 44 | { |
| 45 | $action = key($action); |
| 46 | } |
| 47 | |
| 48 | $this->page_title = 'MCP_NOTES'; |
| 49 | |
| 50 | switch ($mode) |
| 51 | { |
| 52 | case 'front': |
| 53 | $template->assign_vars(array( |
| 54 | 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=mcp&field=username&select_single=true'), |
| 55 | 'U_POST_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes'), |
| 56 | |
| 57 | 'L_TITLE' => $user->lang['MCP_NOTES'], |
| 58 | )); |
| 59 | |
| 60 | $this->tpl_name = 'mcp_notes_front'; |
| 61 | break; |
| 62 | |
| 63 | case 'user_notes': |
| 64 | $user->add_lang('acp/common'); |
| 65 | |
| 66 | $this->mcp_notes_user_view($action); |
| 67 | $this->tpl_name = 'mcp_notes_user'; |
| 68 | break; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Display user notes |
| 74 | */ |
| 75 | function mcp_notes_user_view($action) |
| 76 | { |
| 77 | global $config, $phpbb_log, $request, $phpbb_root_path, $phpEx; |
| 78 | global $template, $db, $user, $auth, $phpbb_container; |
| 79 | |
| 80 | $user_id = $request->variable('u', 0); |
| 81 | $username = $request->variable('username', '', true); |
| 82 | $start = $request->variable('start', 0); |
| 83 | $st = $request->variable('st', 0); |
| 84 | $sk = $request->variable('sk', 'b'); |
| 85 | $sd = $request->variable('sd', 'd'); |
| 86 | |
| 87 | /* @var $pagination \phpbb\pagination */ |
| 88 | $pagination = $phpbb_container->get('pagination'); |
| 89 | |
| 90 | add_form_key('mcp_notes'); |
| 91 | |
| 92 | $sql_where = ($user_id) ? "user_id = $user_id" : "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'"; |
| 93 | |
| 94 | $sql = 'SELECT * |
| 95 | FROM ' . USERS_TABLE . " |
| 96 | WHERE $sql_where"; |
| 97 | $result = $db->sql_query($sql); |
| 98 | $userrow = $db->sql_fetchrow($result); |
| 99 | $db->sql_freeresult($result); |
| 100 | |
| 101 | if (!$userrow || (int) $userrow['user_id'] === ANONYMOUS) |
| 102 | { |
| 103 | trigger_error('NO_USER'); |
| 104 | } |
| 105 | |
| 106 | $user_id = $userrow['user_id']; |
| 107 | |
| 108 | // Populate user id to the currently active module (this module) |
| 109 | // The following method is another way of adjusting module urls. It is the easy variant if we want |
| 110 | // to directly adjust the current module url based on data retrieved within the same module. |
| 111 | if (strpos($this->u_action, "&u=$user_id") === false) |
| 112 | { |
| 113 | $this->p_master->adjust_url('&u=' . $user_id); |
| 114 | $this->u_action .= "&u=$user_id"; |
| 115 | } |
| 116 | |
| 117 | $deletemark = ($action == 'del_marked') ? true : false; |
| 118 | $deleteall = ($action == 'del_all') ? true : false; |
| 119 | $marked = $request->variable('marknote', array(0)); |
| 120 | $usernote = $request->variable('usernote', '', true); |
| 121 | |
| 122 | // Handle any actions |
| 123 | if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) |
| 124 | { |
| 125 | $where_sql = ''; |
| 126 | if ($deletemark && $marked) |
| 127 | { |
| 128 | $sql_in = array(); |
| 129 | foreach ($marked as $mark) |
| 130 | { |
| 131 | $sql_in[] = $mark; |
| 132 | } |
| 133 | $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in); |
| 134 | unset($sql_in); |
| 135 | } |
| 136 | |
| 137 | if ($where_sql || $deleteall) |
| 138 | { |
| 139 | if (check_form_key('mcp_notes')) |
| 140 | { |
| 141 | $sql = 'DELETE FROM ' . LOG_TABLE . ' |
| 142 | WHERE log_type = ' . LOG_USERS . " |
| 143 | AND reportee_id = $user_id |
| 144 | $where_sql"; |
| 145 | $db->sql_query($sql); |
| 146 | |
| 147 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CLEAR_USER', false, array($userrow['username'])); |
| 148 | |
| 149 | $msg = ($deletemark) ? 'MARKED_NOTES_DELETED' : 'ALL_NOTES_DELETED'; |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | $msg = 'FORM_INVALID'; |
| 154 | } |
| 155 | $redirect = $this->u_action . '&u=' . $user_id; |
| 156 | meta_refresh(3, $redirect); |
| 157 | trigger_error($user->lang[$msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>')); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | if ($usernote && $action == 'add_feedback') |
| 162 | { |
| 163 | if (check_form_key('mcp_notes')) |
| 164 | { |
| 165 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_FEEDBACK', false, [$userrow['username']]); |
| 166 | $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_USER_FEEDBACK', false, [ |
| 167 | 'forum_id' => 0, |
| 168 | 'topic_id' => 0, |
| 169 | $userrow['username'] |
| 170 | ]); |
| 171 | $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_GENERAL', false, [ |
| 172 | 'reportee_id' => $user_id, |
| 173 | utf8_encode_ucr($usernote) |
| 174 | ]); |
| 175 | |
| 176 | $msg = $user->lang['USER_FEEDBACK_ADDED']; |
| 177 | } |
| 178 | else |
| 179 | { |
| 180 | $msg = $user->lang['FORM_INVALID']; |
| 181 | } |
| 182 | $redirect = $this->u_action; |
| 183 | meta_refresh(3, $redirect); |
| 184 | |
| 185 | trigger_error($msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>')); |
| 186 | } |
| 187 | |
| 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']); |
| 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']); |
| 190 | $sort_by_sql = array('a' => 'u.username_clean', 'b' => 'l.log_time', 'c' => 'l.log_ip', 'd' => 'l.log_operation'); |
| 191 | |
| 192 | $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = ''; |
| 193 | gen_sort_selects($limit_days, $sort_by_text, $st, $sk, $sd, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param); |
| 194 | |
| 195 | // Define where and sort sql for use in displaying logs |
| 196 | $sql_where = ($st) ? (time() - ($st * 86400)) : 0; |
| 197 | $sql_sort = $sort_by_sql[$sk] . ' ' . (($sd == 'd') ? 'DESC' : 'ASC'); |
| 198 | |
| 199 | $keywords = $request->variable('keywords', '', true); |
| 200 | $keywords_param = !empty($keywords) ? '&keywords=' . urlencode(html_entity_decode($keywords, ENT_COMPAT)) : ''; |
| 201 | |
| 202 | $log_data = array(); |
| 203 | $log_count = 0; |
| 204 | $start = view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort, $keywords); |
| 205 | |
| 206 | if ($log_count) |
| 207 | { |
| 208 | $template->assign_var('S_USER_NOTES', true); |
| 209 | |
| 210 | foreach ($log_data as $row) |
| 211 | { |
| 212 | $template->assign_block_vars('usernotes', array( |
| 213 | 'REPORT_BY' => $row['username_full'], |
| 214 | 'REPORT_AT' => $user->format_date($row['time']), |
| 215 | 'ACTION' => $row['action'], |
| 216 | 'IP' => $row['ip'], |
| 217 | 'ID' => $row['id']) |
| 218 | ); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | $base_url = $this->u_action . "&$u_sort_param$keywords_param"; |
| 223 | $pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start); |
| 224 | |
| 225 | if (!function_exists('phpbb_get_user_rank')) |
| 226 | { |
| 227 | include($phpbb_root_path . 'includes/functions_display.' . $phpEx); |
| 228 | } |
| 229 | |
| 230 | // Generate the appropriate user information for the user we are looking at |
| 231 | $rank_data = phpbb_get_user_rank($userrow, $userrow['user_posts']); |
| 232 | |
| 233 | /** @var \phpbb\avatar\helper $avatar_helper */ |
| 234 | $avatar_helper = $phpbb_container->get('avatar.helper'); |
| 235 | |
| 236 | $avatar = $avatar_helper->get_user_avatar($userrow); |
| 237 | $template->assign_vars($avatar_helper->get_template_vars($avatar, 'USER_')); |
| 238 | |
| 239 | $template->assign_vars(array( |
| 240 | 'U_POST_ACTION' => $this->u_action, |
| 241 | 'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false, |
| 242 | 'S_SELECT_SORT_DIR' => $s_sort_dir, |
| 243 | 'S_SELECT_SORT_KEY' => $s_sort_key, |
| 244 | 'S_SELECT_SORT_DAYS' => $s_limit_days, |
| 245 | 'S_KEYWORDS' => $keywords, |
| 246 | |
| 247 | 'L_TITLE' => $user->lang['MCP_NOTES_USER'], |
| 248 | |
| 249 | 'TOTAL_REPORTS' => $user->lang('LIST_REPORTS', (int) $log_count), |
| 250 | |
| 251 | 'JOINED' => $user->format_date($userrow['user_regdate']), |
| 252 | 'POSTS' => ($userrow['user_posts']) ? $userrow['user_posts'] : 0, |
| 253 | 'WARNINGS' => ($userrow['user_warnings']) ? $userrow['user_warnings'] : 0, |
| 254 | |
| 255 | 'USERNAME_FULL' => get_username_string('full', $userrow['user_id'], $userrow['username'], $userrow['user_colour']), |
| 256 | 'USERNAME_COLOUR' => get_username_string('colour', $userrow['user_id'], $userrow['username'], $userrow['user_colour']), |
| 257 | 'USERNAME' => get_username_string('username', $userrow['user_id'], $userrow['username'], $userrow['user_colour']), |
| 258 | 'USER_ID' => $userrow['user_id'], |
| 259 | 'U_PROFILE' => get_username_string('profile', $userrow['user_id'], $userrow['username'], $userrow['user_colour']), |
| 260 | |
| 261 | 'RANK_IMG' => $rank_data['img'], |
| 262 | 'RANK_TITLE' => $rank_data['title'], |
| 263 | )); |
| 264 | } |
| 265 | } |