includes/mcp/mcp_post.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/mcp/mcp_post.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,501 @@
     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 +* Handling actions in post details screen
    1.24 +*/
    1.25 +function mcp_post_details($id, $mode, $action)
    1.26 +{
    1.27 +	global $phpEx, $phpbb_root_path, $config;
    1.28 +	global $template, $db, $user, $auth, $cache;
    1.29 +
    1.30 +	$user->add_lang('posting');
    1.31 +
    1.32 +	$post_id = request_var('p', 0);
    1.33 +	$start	= request_var('start', 0);
    1.34 +
    1.35 +	// Get post data
    1.36 +	$post_info = get_post_data(array($post_id), false, true);
    1.37 +
    1.38 +	add_form_key('mcp_post_details');
    1.39 +
    1.40 +	if (!sizeof($post_info))
    1.41 +	{
    1.42 +		trigger_error('POST_NOT_EXIST');
    1.43 +	}
    1.44 +
    1.45 +	$post_info = $post_info[$post_id];
    1.46 +	$url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . extra_url());
    1.47 +
    1.48 +	switch ($action)
    1.49 +	{
    1.50 +		case 'whois':
    1.51 +
    1.52 +			if ($auth->acl_get('m_info', $post_info['forum_id']))
    1.53 +			{
    1.54 +				$ip = request_var('ip', '');
    1.55 +				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
    1.56 +
    1.57 +				$template->assign_vars(array(
    1.58 +					'RETURN_POST'	=> sprintf($user->lang['RETURN_POST'], '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;mode=$mode&amp;p=$post_id") . '">', '</a>'),
    1.59 +					'U_RETURN_POST'	=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;mode=$mode&amp;p=$post_id"),
    1.60 +					'L_RETURN_POST'	=> sprintf($user->lang['RETURN_POST'], '', ''),
    1.61 +					'WHOIS'			=> user_ipwhois($ip),
    1.62 +				));
    1.63 +			}
    1.64 +
    1.65 +			// We're done with the whois page so return
    1.66 +			return;
    1.67 +
    1.68 +		break;
    1.69 +
    1.70 +		case 'chgposter':
    1.71 +		case 'chgposter_ip':
    1.72 +
    1.73 +			if ($action == 'chgposter')
    1.74 +			{
    1.75 +				$username = request_var('username', '', true);
    1.76 +				$sql_where = "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
    1.77 +			}
    1.78 +			else
    1.79 +			{
    1.80 +				$new_user_id = request_var('u', 0);
    1.81 +				$sql_where = 'user_id = ' . $new_user_id;
    1.82 +			}
    1.83 +
    1.84 +			$sql = 'SELECT *
    1.85 +				FROM ' . USERS_TABLE . '
    1.86 +				WHERE ' . $sql_where;
    1.87 +			$result = $db->sql_query($sql);
    1.88 +			$row = $db->sql_fetchrow($result);
    1.89 +			$db->sql_freeresult($result);
    1.90 +
    1.91 +			if (!$row)
    1.92 +			{
    1.93 +				trigger_error('NO_USER');
    1.94 +			}
    1.95 +
    1.96 +			if ($auth->acl_get('m_chgposter', $post_info['forum_id']))
    1.97 +			{
    1.98 +				if (check_form_key('mcp_post_details'))
    1.99 +				{
   1.100 +					change_poster($post_info, $row);
   1.101 +				}
   1.102 +				else
   1.103 +				{
   1.104 +					trigger_error('FORM_INVALID');
   1.105 +				}
   1.106 +			}
   1.107 +
   1.108 +		break;
   1.109 +	}
   1.110 +
   1.111 +	// Set some vars
   1.112 +	$users_ary = $usernames_ary = array();
   1.113 +	$attachments = $extensions = array();
   1.114 +	$post_id = $post_info['post_id'];
   1.115 +	$topic_tracking_info = array();
   1.116 +
   1.117 +	// Get topic tracking info
   1.118 +	if ($config['load_db_lastread'])
   1.119 +	{
   1.120 +		$tmp_topic_data = array($post_info['topic_id'] => $post_info);
   1.121 +		$topic_tracking_info = get_topic_tracking($post_info['forum_id'], $post_info['topic_id'], $tmp_topic_data, array($post_info['forum_id'] => $post_info['forum_mark_time']));
   1.122 +		unset($tmp_topic_data);
   1.123 +	}
   1.124 +	else
   1.125 +	{
   1.126 +		$topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
   1.127 +	}
   1.128 +
   1.129 +	$post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
   1.130 +
   1.131 +	// Process message, leave it uncensored
   1.132 +	$message = $post_info['post_text'];
   1.133 +
   1.134 +	if ($post_info['bbcode_bitfield'])
   1.135 +	{
   1.136 +		include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
   1.137 +		$bbcode = new bbcode($post_info['bbcode_bitfield']);
   1.138 +		$bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
   1.139 +	}
   1.140 +
   1.141 +	$message = bbcode_nl2br($message);
   1.142 +	$message = smiley_text($message);
   1.143 +
   1.144 +	if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
   1.145 +	{
   1.146 +		$extensions = $cache->obtain_attach_extensions($post_info['forum_id']);
   1.147 +
   1.148 +		$sql = 'SELECT *
   1.149 +			FROM ' . ATTACHMENTS_TABLE . '
   1.150 +			WHERE post_msg_id = ' . $post_id . '
   1.151 +				AND in_message = 0
   1.152 +			ORDER BY filetime DESC, post_msg_id ASC';
   1.153 +		$result = $db->sql_query($sql);
   1.154 +
   1.155 +		while ($row = $db->sql_fetchrow($result))
   1.156 +		{
   1.157 +			$attachments[] = $row;
   1.158 +		}
   1.159 +		$db->sql_freeresult($result);
   1.160 +
   1.161 +		if (sizeof($attachments))
   1.162 +		{
   1.163 +			$update_count = array();
   1.164 +			parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
   1.165 +		}
   1.166 +
   1.167 +		// Display not already displayed Attachments for this post, we already parsed them. ;)
   1.168 +		if (!empty($attachments))
   1.169 +		{
   1.170 +			$template->assign_var('S_HAS_ATTACHMENTS', true);
   1.171 +
   1.172 +			foreach ($attachments as $attachment)
   1.173 +			{
   1.174 +				$template->assign_block_vars('attachment', array(
   1.175 +					'DISPLAY_ATTACHMENT'	=> $attachment)
   1.176 +				);
   1.177 +			}
   1.178 +		}
   1.179 +	}
   1.180 +
   1.181 +	$template->assign_vars(array(
   1.182 +		'U_MCP_ACTION'			=> "$url&amp;i=main&amp;quickmod=1&amp;mode=post_details", // Use this for mode paramaters
   1.183 +		'U_POST_ACTION'			=> "$url&amp;i=$id&amp;mode=post_details", // Use this for action parameters
   1.184 +		'U_APPROVE_ACTION'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&amp;p=$post_id&amp;f={$post_info['forum_id']}"),
   1.185 +
   1.186 +		'S_CAN_VIEWIP'			=> $auth->acl_get('m_info', $post_info['forum_id']),
   1.187 +		'S_CAN_CHGPOSTER'		=> $auth->acl_get('m_chgposter', $post_info['forum_id']),
   1.188 +		'S_CAN_LOCK_POST'		=> $auth->acl_get('m_lock', $post_info['forum_id']),
   1.189 +		'S_CAN_DELETE_POST'		=> $auth->acl_get('m_delete', $post_info['forum_id']),
   1.190 +
   1.191 +		'S_POST_REPORTED'		=> ($post_info['post_reported']) ? true : false,
   1.192 +		'S_POST_UNAPPROVED'		=> (!$post_info['post_approved']) ? true : false,
   1.193 +		'S_POST_LOCKED'			=> ($post_info['post_edit_locked']) ? true : false,
   1.194 +		'S_USER_NOTES'			=> true,
   1.195 +		'S_CLEAR_ALLOWED'		=> ($auth->acl_get('a_clearlogs')) ? true : false,
   1.196 +
   1.197 +		'U_EDIT'				=> ($auth->acl_get('m_edit', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&amp;f={$post_info['forum_id']}&amp;p={$post_info['post_id']}") : '',
   1.198 +		'U_FIND_USERNAME'		=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=mcp_chgposter&amp;field=username&amp;select_single=true'),
   1.199 +		'U_MCP_APPROVE'			=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id),
   1.200 +		'U_MCP_REPORT'			=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id),
   1.201 +		'U_MCP_USER_NOTES'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $post_info['user_id']),
   1.202 +		'U_MCP_WARN_USER'		=> ($auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_user&amp;u=' . $post_info['user_id']) : '',
   1.203 +		'U_VIEW_POST'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;p=' . $post_info['post_id'] . '#p' . $post_info['post_id']),
   1.204 +		'U_VIEW_TOPIC'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']),
   1.205 +
   1.206 +		'MINI_POST_IMG'			=> ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
   1.207 +
   1.208 +		'RETURN_TOPIC'			=> sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_info['forum_id']}&amp;p=$post_id") . "#p$post_id\">", '</a>'),
   1.209 +		'RETURN_FORUM'			=> sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f={$post_info['forum_id']}&amp;start={$start}") . '">', '</a>'),
   1.210 +		'REPORTED_IMG'			=> $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
   1.211 +		'UNAPPROVED_IMG'		=> $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
   1.212 +		'EDIT_IMG'				=> $user->img('icon_post_edit', $user->lang['EDIT_POST']),
   1.213 +		'SEARCH_IMG'			=> $user->img('icon_user_search', $user->lang['SEARCH']),
   1.214 +
   1.215 +		'POST_AUTHOR_FULL'		=> get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
   1.216 +		'POST_AUTHOR_COLOUR'	=> get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
   1.217 +		'POST_AUTHOR'			=> get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
   1.218 +		'U_POST_AUTHOR'			=> get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
   1.219 +
   1.220 +		'POST_PREVIEW'			=> $message,
   1.221 +		'POST_SUBJECT'			=> $post_info['post_subject'],
   1.222 +		'POST_DATE'				=> $user->format_date($post_info['post_time']),
   1.223 +		'POST_IP'				=> $post_info['poster_ip'],
   1.224 +		'POST_IPADDR'			=> ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
   1.225 +		'POST_ID'				=> $post_info['post_id'],
   1.226 +
   1.227 +		'U_LOOKUP_IP'			=> ($auth->acl_get('m_info', $post_info['forum_id'])) ? "$url&amp;i=$id&amp;mode=$mode&amp;lookup={$post_info['poster_ip']}#ip" : '',
   1.228 +		'U_WHOIS'				=> ($auth->acl_get('m_info', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;mode=$mode&amp;action=whois&amp;p=$post_id&amp;ip={$post_info['poster_ip']}") : '',
   1.229 +	));
   1.230 +
   1.231 +	// Get User Notes
   1.232 +	$log_data = array();
   1.233 +	$log_count = false;
   1.234 +	view_log('user', $log_data, $log_count, $config['posts_per_page'], 0, 0, 0, $post_info['user_id']);
   1.235 +
   1.236 +	if (!empty($log_data))
   1.237 +	{
   1.238 +		$template->assign_var('S_USER_NOTES', true);
   1.239 +
   1.240 +		foreach ($log_data as $row)
   1.241 +		{
   1.242 +			$template->assign_block_vars('usernotes', array(
   1.243 +				'REPORT_BY'		=> $row['username_full'],
   1.244 +				'REPORT_AT'		=> $user->format_date($row['time']),
   1.245 +				'ACTION'		=> $row['action'],
   1.246 +				'ID'			=> $row['id'])
   1.247 +			);
   1.248 +		}
   1.249 +	}
   1.250 +
   1.251 +	// Get Reports
   1.252 +	if ($auth->acl_get('m_report', $post_info['forum_id']))
   1.253 +	{
   1.254 +		$sql = 'SELECT r.*, re.*, u.user_id, u.username
   1.255 +			FROM ' . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u, ' . REPORTS_REASONS_TABLE . " re
   1.256 +			WHERE r.post_id = $post_id
   1.257 +				AND r.reason_id = re.reason_id
   1.258 +				AND u.user_id = r.user_id
   1.259 +			ORDER BY r.report_time DESC";
   1.260 +		$result = $db->sql_query($sql);
   1.261 +
   1.262 +		if ($row = $db->sql_fetchrow($result))
   1.263 +		{
   1.264 +			$template->assign_var('S_SHOW_REPORTS', true);
   1.265 +
   1.266 +			do
   1.267 +			{
   1.268 +				// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
   1.269 +				if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
   1.270 +				{
   1.271 +					$row['reson_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
   1.272 +					$row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
   1.273 +				}
   1.274 +
   1.275 +				$template->assign_block_vars('reports', array(
   1.276 +					'REPORT_ID'		=> $row['report_id'],
   1.277 +					'REASON_TITLE'	=> $row['reason_title'],
   1.278 +					'REASON_DESC'	=> $row['reason_description'],
   1.279 +					'REPORTER'		=> ($row['user_id'] != ANONYMOUS) ? $row['username'] : $user->lang['GUEST'],
   1.280 +					'U_REPORTER'	=> ($row['user_id'] != ANONYMOUS) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']) : '',
   1.281 +					'USER_NOTIFY'	=> ($row['user_notify']) ? true : false,
   1.282 +					'REPORT_TIME'	=> $user->format_date($row['report_time']),
   1.283 +					'REPORT_TEXT'	=> bbcode_nl2br(trim($row['report_text'])),
   1.284 +				));
   1.285 +			}
   1.286 +			while ($row = $db->sql_fetchrow($result));
   1.287 +		}
   1.288 +		$db->sql_freeresult($result);
   1.289 +	}
   1.290 +
   1.291 +	// Get IP
   1.292 +	if ($auth->acl_get('m_info', $post_info['forum_id']))
   1.293 +	{
   1.294 +		$rdns_ip_num = request_var('rdns', '');
   1.295 +
   1.296 +		if ($rdns_ip_num != 'all')
   1.297 +		{
   1.298 +			$template->assign_vars(array(
   1.299 +				'U_LOOKUP_ALL'	=> "$url&amp;i=main&amp;mode=post_details&amp;rdns=all")
   1.300 +			);
   1.301 +		}
   1.302 +
   1.303 +		// Get other users who've posted under this IP
   1.304 +		$sql = 'SELECT poster_id, COUNT(poster_id) as postings
   1.305 +			FROM ' . POSTS_TABLE . "
   1.306 +			WHERE poster_ip = '" . $db->sql_escape($post_info['poster_ip']) . "'
   1.307 +			GROUP BY poster_id
   1.308 +			ORDER BY postings DESC";
   1.309 +		$result = $db->sql_query($sql);
   1.310 +
   1.311 +		while ($row = $db->sql_fetchrow($result))
   1.312 +		{
   1.313 +			// Fill the user select list with users who have posted under this IP
   1.314 +			if ($row['poster_id'] != $post_info['poster_id'])
   1.315 +			{
   1.316 +				$users_ary[$row['poster_id']] = $row;
   1.317 +			}
   1.318 +		}
   1.319 +		$db->sql_freeresult($result);
   1.320 +
   1.321 +		if (sizeof($users_ary))
   1.322 +		{
   1.323 +			// Get the usernames
   1.324 +			$sql = 'SELECT user_id, username
   1.325 +				FROM ' . USERS_TABLE . '
   1.326 +				WHERE ' . $db->sql_in_set('user_id', array_keys($users_ary));
   1.327 +			$result = $db->sql_query($sql);
   1.328 +
   1.329 +			while ($row = $db->sql_fetchrow($result))
   1.330 +			{
   1.331 +				$users_ary[$row['user_id']]['username'] = $row['username'];
   1.332 +				$usernames_ary[utf8_clean_string($row['username'])] = $users_ary[$row['user_id']];
   1.333 +			}
   1.334 +			$db->sql_freeresult($result);
   1.335 +
   1.336 +			foreach ($users_ary as $user_id => $user_row)
   1.337 +			{
   1.338 +				$template->assign_block_vars('userrow', array(
   1.339 +					'USERNAME'		=> ($user_id == ANONYMOUS) ? $user->lang['GUEST'] : $user_row['username'],
   1.340 +					'NUM_POSTS'		=> $user_row['postings'],
   1.341 +					'L_POST_S'		=> ($user_row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS'],
   1.342 +
   1.343 +					'U_PROFILE'		=> ($user_id == ANONYMOUS) ? '' : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $user_id),
   1.344 +					'U_SEARCHPOSTS' => append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user_id . '&amp;sr=topics'))
   1.345 +				);
   1.346 +			}
   1.347 +		}
   1.348 +
   1.349 +		// Get other IP's this user has posted under
   1.350 +
   1.351 +		// A compound index on poster_id, poster_ip (posts table) would help speed up this query a lot,
   1.352 +		// but the extra size is only valuable if there are persons having more than a thousands posts.
   1.353 +		// This is better left to the really really big forums.
   1.354 +
   1.355 +		$sql = 'SELECT poster_ip, COUNT(poster_ip) AS postings
   1.356 +			FROM ' . POSTS_TABLE . '
   1.357 +			WHERE poster_id = ' . $post_info['poster_id'] . "
   1.358 +			GROUP BY poster_ip
   1.359 +			ORDER BY postings DESC";
   1.360 +		$result = $db->sql_query($sql);
   1.361 +
   1.362 +		while ($row = $db->sql_fetchrow($result))
   1.363 +		{
   1.364 +			$hostname = (($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') && $row['poster_ip']) ? @gethostbyaddr($row['poster_ip']) : '';
   1.365 +
   1.366 +			$template->assign_block_vars('iprow', array(
   1.367 +				'IP'			=> $row['poster_ip'],
   1.368 +				'HOSTNAME'		=> $hostname,
   1.369 +				'NUM_POSTS'		=> $row['postings'],
   1.370 +				'L_POST_S'		=> ($row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS'],
   1.371 +
   1.372 +				'U_LOOKUP_IP'	=> ($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? '' : "$url&amp;i=$id&amp;mode=post_details&amp;rdns={$row['poster_ip']}#ip",
   1.373 +				'U_WHOIS'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;mode=$mode&amp;action=whois&amp;p=$post_id&amp;ip={$row['poster_ip']}"))
   1.374 +			);
   1.375 +		}
   1.376 +		$db->sql_freeresult($result);
   1.377 +
   1.378 +		$user_select = '';
   1.379 +
   1.380 +		if (sizeof($usernames_ary))
   1.381 +		{
   1.382 +			ksort($usernames_ary);
   1.383 +
   1.384 +			foreach ($usernames_ary as $row)
   1.385 +			{
   1.386 +				$user_select .= '<option value="' . $row['poster_id'] . '">' . $row['username'] . "</option>\n";
   1.387 +			}
   1.388 +		}
   1.389 +
   1.390 +		$template->assign_var('S_USER_SELECT', $user_select);
   1.391 +	}
   1.392 +
   1.393 +}
   1.394 +
   1.395 +/**
   1.396 +* Change a post's poster
   1.397 +*/
   1.398 +function change_poster(&$post_info, $userdata)
   1.399 +{
   1.400 +	global $auth, $db, $config, $phpbb_root_path, $phpEx;
   1.401 +
   1.402 +	if (empty($userdata) || $userdata['user_id'] == $post_info['user_id'])
   1.403 +	{
   1.404 +		return;
   1.405 +	}
   1.406 +
   1.407 +	$post_id = $post_info['post_id'];
   1.408 +
   1.409 +	$sql = 'UPDATE ' . POSTS_TABLE . "
   1.410 +		SET poster_id = {$userdata['user_id']}
   1.411 +		WHERE post_id = $post_id";
   1.412 +	$db->sql_query($sql);
   1.413 +
   1.414 +	// Resync topic/forum if needed
   1.415 +	if ($post_info['topic_last_post_id'] == $post_id || $post_info['forum_last_post_id'] == $post_id || $post_info['topic_first_post_id'] == $post_id)
   1.416 +	{
   1.417 +		sync('topic', 'topic_id', $post_info['topic_id'], false, false);
   1.418 +		sync('forum', 'forum_id', $post_info['forum_id'], false, false);
   1.419 +	}
   1.420 +
   1.421 +	// Adjust post counts... only if the post is approved (else, it was not added the users post count anyway)
   1.422 +	if ($post_info['post_postcount'] && $post_info['post_approved'])
   1.423 +	{
   1.424 +		$sql = 'UPDATE ' . USERS_TABLE . '
   1.425 +			SET user_posts = user_posts - 1
   1.426 +			WHERE user_id = ' . $post_info['user_id'] .'
   1.427 +			AND user_posts > 0';
   1.428 +		$db->sql_query($sql);
   1.429 +
   1.430 +		$sql = 'UPDATE ' . USERS_TABLE . '
   1.431 +			SET user_posts = user_posts + 1
   1.432 +			WHERE user_id = ' . $userdata['user_id'];
   1.433 +		$db->sql_query($sql);
   1.434 +	}
   1.435 +
   1.436 +	// Add posted to information for this topic for the new user
   1.437 +	markread('post', $post_info['forum_id'], $post_info['topic_id'], time(), $userdata['user_id']);
   1.438 +
   1.439 +	// Remove the dotted topic option if the old user has no more posts within this topic
   1.440 +	if ($config['load_db_track'] && $post_info['user_id'] != ANONYMOUS)
   1.441 +	{
   1.442 +		$sql = 'SELECT topic_id
   1.443 +			FROM ' . POSTS_TABLE . '
   1.444 +			WHERE topic_id = ' . $post_info['topic_id'] . '
   1.445 +				AND poster_id = ' . $post_info['user_id'];
   1.446 +		$result = $db->sql_query_limit($sql, 1);
   1.447 +		$topic_id = (int) $db->sql_fetchfield('topic_id');
   1.448 +		$db->sql_freeresult($result);
   1.449 +
   1.450 +		if (!$topic_id)
   1.451 +		{
   1.452 +			$sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
   1.453 +				WHERE user_id = ' . $post_info['user_id'] . '
   1.454 +					AND topic_id = ' . $post_info['topic_id'];
   1.455 +			$db->sql_query($sql);
   1.456 +		}
   1.457 +	}
   1.458 +
   1.459 +	// change the poster_id within the attachments table, else the data becomes out of sync and errors displayed because of wrong ownership
   1.460 +	if ($post_info['post_attachment'])
   1.461 +	{
   1.462 +		$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
   1.463 +			SET poster_id = ' . $userdata['user_id'] . '
   1.464 +			WHERE poster_id = ' . $post_info['user_id'] . '
   1.465 +				AND post_msg_id = ' . $post_info['post_id'] . '
   1.466 +				AND topic_id = ' . $post_info['topic_id'];
   1.467 +		$db->sql_query($sql);
   1.468 +	}
   1.469 +
   1.470 +	// refresh search cache of this post
   1.471 +	$search_type = basename($config['search_type']);
   1.472 +
   1.473 +	if (file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
   1.474 +	{
   1.475 +		require("{$phpbb_root_path}includes/search/$search_type.$phpEx");
   1.476 +
   1.477 +		// We do some additional checks in the module to ensure it can actually be utilised
   1.478 +		$error = false;
   1.479 +		$search = new $search_type($error);
   1.480 +
   1.481 +		if (!$error && method_exists($search, 'destroy_cache'))
   1.482 +		{
   1.483 +			$search->destroy_cache(array(), array($post_info['user_id'], $userdata['user_id']));
   1.484 +		}
   1.485 +	}
   1.486 +
   1.487 +	$from_username = $post_info['username'];
   1.488 +	$to_username = $userdata['username'];
   1.489 +
   1.490 +	// Renew post info
   1.491 +	$post_info = get_post_data(array($post_id), false, true);
   1.492 +
   1.493 +	if (!sizeof($post_info))
   1.494 +	{
   1.495 +		trigger_error('POST_NOT_EXIST');
   1.496 +	}
   1.497 +
   1.498 +	$post_info = $post_info[$post_id];
   1.499 +
   1.500 +	// Now add log entry
   1.501 +	add_log('mod', $post_info['forum_id'], $post_info['topic_id'], 'LOG_MCP_CHANGE_POSTER', $post_info['topic_title'], $from_username, $to_username);
   1.502 +}
   1.503 +
   1.504 +?>
   1.505 \ No newline at end of file