Blame Identity/Webenv/phpBB/3.0.4/includes/mcp/mcp_post.php

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