Blame Extras/phpBB/3.0.4/includes/mcp/mcp_post.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package mcp
4c79b5
* @version $Id: mcp_post.php 8805 2008-09-02 06:36:24Z acydburn $
4c79b5
* @copyright (c) 2005 phpBB Group
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
* @ignore
4c79b5
*/
4c79b5
if (!defined('IN_PHPBB'))
4c79b5
{
4c79b5
	exit;
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* Handling actions in post details screen
4c79b5
*/
4c79b5
function mcp_post_details($id, $mode, $action)
4c79b5
{
4c79b5
	global $phpEx, $phpbb_root_path, $config;
4c79b5
	global $template, $db, $user, $auth, $cache;
4c79b5
4c79b5
	$user->add_lang('posting');
4c79b5
4c79b5
	$post_id = request_var('p', 0);
4c79b5
	$start	= request_var('start', 0);
4c79b5
4c79b5
	// Get post data
4c79b5
	$post_info = get_post_data(array($post_id), false, true);
4c79b5
4c79b5
	add_form_key('mcp_post_details');
4c79b5
4c79b5
	if (!sizeof($post_info))
4c79b5
	{
4c79b5
		trigger_error('POST_NOT_EXIST');
4c79b5
	}
4c79b5
4c79b5
	$post_info = $post_info[$post_id];
4c79b5
	$url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . extra_url());
4c79b5
4c79b5
	switch ($action)
4c79b5
	{
4c79b5
		case 'whois':
4c79b5
4c79b5
			if ($auth->acl_get('m_info', $post_info['forum_id']))
4c79b5
			{
4c79b5
				$ip = request_var('ip', '');
4c79b5
				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'RETURN_POST'	=> sprintf($user->lang['RETURN_POST'], '', ''),
4c79b5
					'U_RETURN_POST'	=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&mode=$mode&p=$post_id"),
4c79b5
					'L_RETURN_POST'	=> sprintf($user->lang['RETURN_POST'], '', ''),
4c79b5
					'WHOIS'			=> user_ipwhois($ip),
4c79b5
				));
4c79b5
			}
4c79b5
4c79b5
			// We're done with the whois page so return
4c79b5
			return;
4c79b5
4c79b5
		break;
4c79b5
4c79b5
		case 'chgposter':
4c79b5
		case 'chgposter_ip':
4c79b5
4c79b5
			if ($action == 'chgposter')
4c79b5
			{
4c79b5
				$username = request_var('username', '', true);
4c79b5
				$sql_where = "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$new_user_id = request_var('u', 0);
4c79b5
				$sql_where = 'user_id = ' . $new_user_id;
4c79b5
			}
4c79b5
4c79b5
			$sql = 'SELECT *
4c79b5
				FROM ' . USERS_TABLE . '
4c79b5
				WHERE ' . $sql_where;
4c79b5
			$result = $db->sql_query($sql);
4c79b5
			$row = $db->sql_fetchrow($result);
4c79b5
			$db->sql_freeresult($result);
4c79b5
4c79b5
			if (!$row)
4c79b5
			{
4c79b5
				trigger_error('NO_USER');
4c79b5
			}
4c79b5
4c79b5
			if ($auth->acl_get('m_chgposter', $post_info['forum_id']))
4c79b5
			{
4c79b5
				if (check_form_key('mcp_post_details'))
4c79b5
				{
4c79b5
					change_poster($post_info, $row);
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					trigger_error('FORM_INVALID');
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
		break;
4c79b5
	}
4c79b5
4c79b5
	// Set some vars
4c79b5
	$users_ary = $usernames_ary = array();
4c79b5
	$attachments = $extensions = array();
4c79b5
	$post_id = $post_info['post_id'];
4c79b5
	$topic_tracking_info = array();
4c79b5
4c79b5
	// Get topic tracking info
4c79b5
	if ($config['load_db_lastread'])
4c79b5
	{
4c79b5
		$tmp_topic_data = array($post_info['topic_id'] => $post_info);
4c79b5
		$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']));
4c79b5
		unset($tmp_topic_data);
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
4c79b5
	}
4c79b5
4c79b5
	$post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
4c79b5
4c79b5
	// Process message, leave it uncensored
4c79b5
	$message = $post_info['post_text'];
4c79b5
4c79b5
	if ($post_info['bbcode_bitfield'])
4c79b5
	{
4c79b5
		include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
4c79b5
		$bbcode = new bbcode($post_info['bbcode_bitfield']);
4c79b5
		$bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
4c79b5
	}
4c79b5
4c79b5
	$message = bbcode_nl2br($message);
4c79b5
	$message = smiley_text($message);
4c79b5
4c79b5
	if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
4c79b5
	{
4c79b5
		$extensions = $cache->obtain_attach_extensions($post_info['forum_id']);
4c79b5
4c79b5
		$sql = 'SELECT *
4c79b5
			FROM ' . ATTACHMENTS_TABLE . '
4c79b5
			WHERE post_msg_id = ' . $post_id . '
4c79b5
				AND in_message = 0
4c79b5
			ORDER BY filetime DESC, post_msg_id ASC';
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$attachments[] = $row;
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		if (sizeof($attachments))
4c79b5
		{
4c79b5
			$update_count = array();
4c79b5
			parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
4c79b5
		}
4c79b5
4c79b5
		// Display not already displayed Attachments for this post, we already parsed them. ;)
4c79b5
		if (!empty($attachments))
4c79b5
		{
4c79b5
			$template->assign_var('S_HAS_ATTACHMENTS', true);
4c79b5
4c79b5
			foreach ($attachments as $attachment)
4c79b5
			{
4c79b5
				$template->assign_block_vars('attachment', array(
4c79b5
					'DISPLAY_ATTACHMENT'	=> $attachment)
4c79b5
				);
4c79b5
			}
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	$template->assign_vars(array(
4c79b5
		'U_MCP_ACTION'			=> "$url&i=main&quickmod=1", // Use this for mode paramaters
4c79b5
		'U_POST_ACTION'			=> "$url&i=$id&mode=post_details", // Use this for action parameters
4c79b5
		'U_APPROVE_ACTION'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p=$post_id&f={$post_info['forum_id']}"),
4c79b5
4c79b5
		'S_CAN_VIEWIP'			=> $auth->acl_get('m_info', $post_info['forum_id']),
4c79b5
		'S_CAN_CHGPOSTER'		=> $auth->acl_get('m_chgposter', $post_info['forum_id']),
4c79b5
		'S_CAN_LOCK_POST'		=> $auth->acl_get('m_lock', $post_info['forum_id']),
4c79b5
		'S_CAN_DELETE_POST'		=> $auth->acl_get('m_delete', $post_info['forum_id']),
4c79b5
4c79b5
		'S_POST_REPORTED'		=> ($post_info['post_reported']) ? true : false,
4c79b5
		'S_POST_UNAPPROVED'		=> (!$post_info['post_approved']) ? true : false,
4c79b5
		'S_POST_LOCKED'			=> ($post_info['post_edit_locked']) ? true : false,
4c79b5
		'S_USER_NOTES'			=> true,
4c79b5
		'S_CLEAR_ALLOWED'		=> ($auth->acl_get('a_clearlogs')) ? true : false,
4c79b5
4c79b5
		'U_EDIT'				=> ($auth->acl_get('m_edit', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&f={$post_info['forum_id']}&p={$post_info['post_id']}") : '',
4c79b5
		'U_FIND_USERNAME'		=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=mcp_chgposter&field=username&select_single=true'),
4c79b5
		'U_MCP_APPROVE'			=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
4c79b5
		'U_MCP_REPORT'			=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
4c79b5
		'U_MCP_USER_NOTES'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $post_info['user_id']),
4c79b5
		'U_MCP_WARN_USER'		=> ($auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user&u=' . $post_info['user_id']) : '',
4c79b5
		'U_VIEW_POST'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&p=' . $post_info['post_id'] . '#p' . $post_info['post_id']),
4c79b5
		'U_VIEW_TOPIC'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&t=' . $post_info['topic_id']),
4c79b5
4c79b5
		'MINI_POST_IMG'			=> ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
4c79b5
4c79b5
		'RETURN_TOPIC'			=> sprintf($user->lang['RETURN_TOPIC'], '", ''),
4c79b5
		'RETURN_FORUM'			=> sprintf($user->lang['RETURN_FORUM'], '', ''),
4c79b5
		'REPORTED_IMG'			=> $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
4c79b5
		'UNAPPROVED_IMG'		=> $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
4c79b5
		'EDIT_IMG'				=> $user->img('icon_post_edit', $user->lang['EDIT_POST']),
4c79b5
		'SEARCH_IMG'			=> $user->img('icon_user_search', $user->lang['SEARCH']),
4c79b5
4c79b5
		'POST_AUTHOR_FULL'		=> get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
4c79b5
		'POST_AUTHOR_COLOUR'	=> get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
4c79b5
		'POST_AUTHOR'			=> get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
4c79b5
		'U_POST_AUTHOR'			=> get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
4c79b5
4c79b5
		'POST_PREVIEW'			=> $message,
4c79b5
		'POST_SUBJECT'			=> $post_info['post_subject'],
4c79b5
		'POST_DATE'				=> $user->format_date($post_info['post_time']),
4c79b5
		'POST_IP'				=> $post_info['poster_ip'],
4c79b5
		'POST_IPADDR'			=> ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
4c79b5
		'POST_ID'				=> $post_info['post_id'],
4c79b5
4c79b5
		'U_LOOKUP_IP'			=> ($auth->acl_get('m_info', $post_info['forum_id'])) ? "$url&i=$id&mode=$mode&lookup={$post_info['poster_ip']}#ip" : '',
4c79b5
		'U_WHOIS'				=> ($auth->acl_get('m_info', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&mode=$mode&action=whois&p=$post_id&ip={$post_info['poster_ip']}") : '',
4c79b5
	));
4c79b5
4c79b5
	// Get User Notes
4c79b5
	$log_data = array();
4c79b5
	$log_count = 0;
4c79b5
	view_log('user', $log_data, $log_count, $config['posts_per_page'], 0, 0, 0, $post_info['user_id']);
4c79b5
4c79b5
	if ($log_count)
4c79b5
	{
4c79b5
		$template->assign_var('S_USER_NOTES', true);
4c79b5
4c79b5
		foreach ($log_data as $row)
4c79b5
		{
4c79b5
			$template->assign_block_vars('usernotes', array(
4c79b5
				'REPORT_BY'		=> $row['username_full'],
4c79b5
				'REPORT_AT'		=> $user->format_date($row['time']),
4c79b5
				'ACTION'		=> $row['action'],
4c79b5
				'ID'			=> $row['id'])
4c79b5
			);
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	// Get Reports
4c79b5
	if ($auth->acl_get('m_', $post_info['forum_id']))
4c79b5
	{
4c79b5
		$sql = 'SELECT r.*, re.*, u.user_id, u.username
4c79b5
			FROM ' . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u, ' . REPORTS_REASONS_TABLE . " re
4c79b5
			WHERE r.post_id = $post_id
4c79b5
				AND r.reason_id = re.reason_id
4c79b5
				AND u.user_id = r.user_id
4c79b5
			ORDER BY r.report_time DESC";
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		if ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$template->assign_var('S_SHOW_REPORTS', true);
4c79b5
4c79b5
			do
4c79b5
			{
4c79b5
				// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
4c79b5
				if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
4c79b5
				{
4c79b5
					$row['reson_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
4c79b5
					$row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
4c79b5
				}
4c79b5
4c79b5
				$template->assign_block_vars('reports', array(
4c79b5
					'REPORT_ID'		=> $row['report_id'],
4c79b5
					'REASON_TITLE'	=> $row['reason_title'],
4c79b5
					'REASON_DESC'	=> $row['reason_description'],
4c79b5
					'REPORTER'		=> ($row['user_id'] != ANONYMOUS) ? $row['username'] : $user->lang['GUEST'],
4c79b5
					'U_REPORTER'	=> ($row['user_id'] != ANONYMOUS) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . $row['user_id']) : '',
4c79b5
					'USER_NOTIFY'	=> ($row['user_notify']) ? true : false,
4c79b5
					'REPORT_TIME'	=> $user->format_date($row['report_time']),
4c79b5
					'REPORT_TEXT'	=> bbcode_nl2br(trim($row['report_text'])),
4c79b5
				));
4c79b5
			}
4c79b5
			while ($row = $db->sql_fetchrow($result));
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
	}
4c79b5
4c79b5
	// Get IP
4c79b5
	if ($auth->acl_get('m_info', $post_info['forum_id']))
4c79b5
	{
4c79b5
		$rdns_ip_num = request_var('rdns', '');
4c79b5
4c79b5
		if ($rdns_ip_num != 'all')
4c79b5
		{
4c79b5
			$template->assign_vars(array(
4c79b5
				'U_LOOKUP_ALL'	=> "$url&i=main&mode=post_details&rdns=all")
4c79b5
			);
4c79b5
		}
4c79b5
4c79b5
		// Get other users who've posted under this IP
4c79b5
		$sql = 'SELECT poster_id, COUNT(poster_id) as postings
4c79b5
			FROM ' . POSTS_TABLE . "
4c79b5
			WHERE poster_ip = '" . $db->sql_escape($post_info['poster_ip']) . "'
4c79b5
			GROUP BY poster_id
4c79b5
			ORDER BY postings DESC";
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			// Fill the user select list with users who have posted under this IP
4c79b5
			if ($row['poster_id'] != $post_info['poster_id'])
4c79b5
			{
4c79b5
				$users_ary[$row['poster_id']] = $row;
4c79b5
			}
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		if (sizeof($users_ary))
4c79b5
		{
4c79b5
			// Get the usernames
4c79b5
			$sql = 'SELECT user_id, username
4c79b5
				FROM ' . USERS_TABLE . '
4c79b5
				WHERE ' . $db->sql_in_set('user_id', array_keys($users_ary));
4c79b5
			$result = $db->sql_query($sql);
4c79b5
4c79b5
			while ($row = $db->sql_fetchrow($result))
4c79b5
			{
4c79b5
				$users_ary[$row['user_id']]['username'] = $row['username'];
4c79b5
				$usernames_ary[utf8_clean_string($row['username'])] = $users_ary[$row['user_id']];
4c79b5
			}
4c79b5
			$db->sql_freeresult($result);
4c79b5
4c79b5
			foreach ($users_ary as $user_id => $user_row)
4c79b5
			{
4c79b5
				$template->assign_block_vars('userrow', array(
4c79b5
					'USERNAME'		=> ($user_id == ANONYMOUS) ? $user->lang['GUEST'] : $user_row['username'],
4c79b5
					'NUM_POSTS'		=> $user_row['postings'],
4c79b5
					'L_POST_S'		=> ($user_row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS'],
4c79b5
4c79b5
					'U_PROFILE'		=> ($user_id == ANONYMOUS) ? '' : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . $user_id),
4c79b5
					'U_SEARCHPOSTS' => append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user_id . '&sr=topics'))
4c79b5
				);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		// Get other IP's this user has posted under
4c79b5
4c79b5
		// A compound index on poster_id, poster_ip (posts table) would help speed up this query a lot,
4c79b5
		// but the extra size is only valuable if there are persons having more than a thousands posts.
4c79b5
		// This is better left to the really really big forums.
4c79b5
4c79b5
		$sql = 'SELECT poster_ip, COUNT(poster_ip) AS postings
4c79b5
			FROM ' . POSTS_TABLE . '
4c79b5
			WHERE poster_id = ' . $post_info['poster_id'] . "
4c79b5
			GROUP BY poster_ip
4c79b5
			ORDER BY postings DESC";
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$hostname = (($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') && $row['poster_ip']) ? @gethostbyaddr($row['poster_ip']) : '';
4c79b5
4c79b5
			$template->assign_block_vars('iprow', array(
4c79b5
				'IP'			=> $row['poster_ip'],
4c79b5
				'HOSTNAME'		=> $hostname,
4c79b5
				'NUM_POSTS'		=> $row['postings'],
4c79b5
				'L_POST_S'		=> ($row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS'],
4c79b5
4c79b5
				'U_LOOKUP_IP'	=> ($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? '' : "$url&i=$id&mode=post_details&rdns={$row['poster_ip']}#ip",
4c79b5
				'U_WHOIS'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&mode=$mode&action=whois&p=$post_id&ip={$row['poster_ip']}"))
4c79b5
			);
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		$user_select = '';
4c79b5
4c79b5
		if (sizeof($usernames_ary))
4c79b5
		{
4c79b5
			ksort($usernames_ary);
4c79b5
4c79b5
			foreach ($usernames_ary as $row)
4c79b5
			{
4c79b5
				$user_select .= '<option value="' . $row['poster_id'] . '">' . $row['username'] . "</option>\n";
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		$template->assign_var('S_USER_SELECT', $user_select);
4c79b5
	}
4c79b5
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* Change a post's poster
4c79b5
*/
4c79b5
function change_poster(&$post_info, $userdata)
4c79b5
{
4c79b5
	global $auth, $db, $config, $phpbb_root_path, $phpEx;
4c79b5
4c79b5
	if (empty($userdata) || $userdata['user_id'] == $post_info['user_id'])
4c79b5
	{
4c79b5
		return;
4c79b5
	}
4c79b5
4c79b5
	$post_id = $post_info['post_id'];
4c79b5
4c79b5
	$sql = 'UPDATE ' . POSTS_TABLE . "
4c79b5
		SET poster_id = {$userdata['user_id']}
4c79b5
		WHERE post_id = $post_id";
4c79b5
	$db->sql_query($sql);
4c79b5
4c79b5
	// Resync topic/forum if needed
4c79b5
	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)
4c79b5
	{
4c79b5
		sync('topic', 'topic_id', $post_info['topic_id'], false, false);
4c79b5
		sync('forum', 'forum_id', $post_info['forum_id'], false, false);
4c79b5
	}
4c79b5
4c79b5
	// Adjust post counts... only if the post is approved (else, it was not added the users post count anyway)
4c79b5
	if ($post_info['post_postcount'] && $post_info['post_approved'])
4c79b5
	{
4c79b5
		$sql = 'UPDATE ' . USERS_TABLE . '
4c79b5
			SET user_posts = user_posts - 1
4c79b5
			WHERE user_id = ' . $post_info['user_id'] .'
4c79b5
			AND user_posts > 0';
4c79b5
		$db->sql_query($sql);
4c79b5
4c79b5
		$sql = 'UPDATE ' . USERS_TABLE . '
4c79b5
			SET user_posts = user_posts + 1
4c79b5
			WHERE user_id = ' . $userdata['user_id'];
4c79b5
		$db->sql_query($sql);
4c79b5
	}
4c79b5
4c79b5
	// Add posted to information for this topic for the new user
4c79b5
	markread('post', $post_info['forum_id'], $post_info['topic_id'], time(), $userdata['user_id']);
4c79b5
4c79b5
	// Remove the dotted topic option if the old user has no more posts within this topic
4c79b5
	if ($config['load_db_track'] && $post_info['user_id'] != ANONYMOUS)
4c79b5
	{
4c79b5
		$sql = 'SELECT topic_id
4c79b5
			FROM ' . POSTS_TABLE . '
4c79b5
			WHERE topic_id = ' . $post_info['topic_id'] . '
4c79b5
				AND poster_id = ' . $post_info['user_id'];
4c79b5
		$result = $db->sql_query_limit($sql, 1);
4c79b5
		$topic_id = (int) $db->sql_fetchfield('topic_id');
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		if (!$topic_id)
4c79b5
		{
4c79b5
			$sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
4c79b5
				WHERE user_id = ' . $post_info['user_id'] . '
4c79b5
					AND topic_id = ' . $post_info['topic_id'];
4c79b5
			$db->sql_query($sql);
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	// change the poster_id within the attachments table, else the data becomes out of sync and errors displayed because of wrong ownership
4c79b5
	if ($post_info['post_attachment'])
4c79b5
	{
4c79b5
		$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
4c79b5
			SET poster_id = ' . $userdata['user_id'] . '
4c79b5
			WHERE poster_id = ' . $post_info['user_id'] . '
4c79b5
				AND post_msg_id = ' . $post_info['post_id'] . '
4c79b5
				AND topic_id = ' . $post_info['topic_id'];
4c79b5
		$db->sql_query($sql);
4c79b5
	}
4c79b5
4c79b5
	// refresh search cache of this post
4c79b5
	$search_type = basename($config['search_type']);
4c79b5
4c79b5
	if (file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
4c79b5
	{
4c79b5
		require("{$phpbb_root_path}includes/search/$search_type.$phpEx");
4c79b5
4c79b5
		// We do some additional checks in the module to ensure it can actually be utilised
4c79b5
		$error = false;
4c79b5
		$search = new $search_type($error);
4c79b5
4c79b5
		if (!$error && method_exists($search, 'destroy_cache'))
4c79b5
		{
4c79b5
			$search->destroy_cache(array(), array($post_info['user_id'], $userdata['user_id']));
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	$from_username = $post_info['username'];
4c79b5
	$to_username = $userdata['username'];
4c79b5
4c79b5
	// Renew post info
4c79b5
	$post_info = get_post_data(array($post_id), false, true);
4c79b5
4c79b5
	if (!sizeof($post_info))
4c79b5
	{
4c79b5
		trigger_error('POST_NOT_EXIST');
4c79b5
	}
4c79b5
4c79b5
	$post_info = $post_info[$post_id];
4c79b5
4c79b5
	// Now add log entry
4c79b5
	add_log('mod', $post_info['forum_id'], $post_info['topic_id'], 'LOG_MCP_CHANGE_POSTER', $post_info['topic_title'], $from_username, $to_username);
4c79b5
}
4c79b5
4c79b5
?>