includes/mcp/mcp_post.php
author indvdum (gotoindvdum[at]gmail[dot]com)
Wed, 07 Mar 2012 23:21:18 +0400
changeset 9 e5e5221fa5e1
parent 0 ceef6d64c21d
permissions -rw-r--r--
HG ignore
indvdum@0
     1
<?php
indvdum@0
     2
/**
indvdum@0
     3
*
indvdum@0
     4
* @package mcp
indvdum@0
     5
* @version $Id$
indvdum@0
     6
* @copyright (c) 2005 phpBB Group
indvdum@0
     7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
indvdum@0
     8
*
indvdum@0
     9
*/
indvdum@0
    10
indvdum@0
    11
/**
indvdum@0
    12
* @ignore
indvdum@0
    13
*/
indvdum@0
    14
if (!defined('IN_PHPBB'))
indvdum@0
    15
{
indvdum@0
    16
	exit;
indvdum@0
    17
}
indvdum@0
    18
indvdum@0
    19
/**
indvdum@0
    20
* Handling actions in post details screen
indvdum@0
    21
*/
indvdum@0
    22
function mcp_post_details($id, $mode, $action)
indvdum@0
    23
{
indvdum@0
    24
	global $phpEx, $phpbb_root_path, $config;
indvdum@0
    25
	global $template, $db, $user, $auth, $cache;
indvdum@0
    26
indvdum@0
    27
	$user->add_lang('posting');
indvdum@0
    28
indvdum@0
    29
	$post_id = request_var('p', 0);
indvdum@0
    30
	$start	= request_var('start', 0);
indvdum@0
    31
indvdum@0
    32
	// Get post data
indvdum@0
    33
	$post_info = get_post_data(array($post_id), false, true);
indvdum@0
    34
indvdum@0
    35
	add_form_key('mcp_post_details');
indvdum@0
    36
indvdum@0
    37
	if (!sizeof($post_info))
indvdum@0
    38
	{
indvdum@0
    39
		trigger_error('POST_NOT_EXIST');
indvdum@0
    40
	}
indvdum@0
    41
indvdum@0
    42
	$post_info = $post_info[$post_id];
indvdum@0
    43
	$url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . extra_url());
indvdum@0
    44
indvdum@0
    45
	switch ($action)
indvdum@0
    46
	{
indvdum@0
    47
		case 'whois':
indvdum@0
    48
indvdum@0
    49
			if ($auth->acl_get('m_info', $post_info['forum_id']))
indvdum@0
    50
			{
indvdum@0
    51
				$ip = request_var('ip', '');
indvdum@0
    52
				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
indvdum@0
    53
indvdum@0
    54
				$template->assign_vars(array(
indvdum@0
    55
					'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>'),
indvdum@0
    56
					'U_RETURN_POST'	=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;mode=$mode&amp;p=$post_id"),
indvdum@0
    57
					'L_RETURN_POST'	=> sprintf($user->lang['RETURN_POST'], '', ''),
indvdum@0
    58
					'WHOIS'			=> user_ipwhois($ip),
indvdum@0
    59
				));
indvdum@0
    60
			}
indvdum@0
    61
indvdum@0
    62
			// We're done with the whois page so return
indvdum@0
    63
			return;
indvdum@0
    64
indvdum@0
    65
		break;
indvdum@0
    66
indvdum@0
    67
		case 'chgposter':
indvdum@0
    68
		case 'chgposter_ip':
indvdum@0
    69
indvdum@0
    70
			if ($action == 'chgposter')
indvdum@0
    71
			{
indvdum@0
    72
				$username = request_var('username', '', true);
indvdum@0
    73
				$sql_where = "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
indvdum@0
    74
			}
indvdum@0
    75
			else
indvdum@0
    76
			{
indvdum@0
    77
				$new_user_id = request_var('u', 0);
indvdum@0
    78
				$sql_where = 'user_id = ' . $new_user_id;
indvdum@0
    79
			}
indvdum@0
    80
indvdum@0
    81
			$sql = 'SELECT *
indvdum@0
    82
				FROM ' . USERS_TABLE . '
indvdum@0
    83
				WHERE ' . $sql_where;
indvdum@0
    84
			$result = $db->sql_query($sql);
indvdum@0
    85
			$row = $db->sql_fetchrow($result);
indvdum@0
    86
			$db->sql_freeresult($result);
indvdum@0
    87
indvdum@0
    88
			if (!$row)
indvdum@0
    89
			{
indvdum@0
    90
				trigger_error('NO_USER');
indvdum@0
    91
			}
indvdum@0
    92
indvdum@0
    93
			if ($auth->acl_get('m_chgposter', $post_info['forum_id']))
indvdum@0
    94
			{
indvdum@0
    95
				if (check_form_key('mcp_post_details'))
indvdum@0
    96
				{
indvdum@0
    97
					change_poster($post_info, $row);
indvdum@0
    98
				}
indvdum@0
    99
				else
indvdum@0
   100
				{
indvdum@0
   101
					trigger_error('FORM_INVALID');
indvdum@0
   102
				}
indvdum@0
   103
			}
indvdum@0
   104
indvdum@0
   105
		break;
indvdum@0
   106
	}
indvdum@0
   107
indvdum@0
   108
	// Set some vars
indvdum@0
   109
	$users_ary = $usernames_ary = array();
indvdum@0
   110
	$attachments = $extensions = array();
indvdum@0
   111
	$post_id = $post_info['post_id'];
indvdum@0
   112
	$topic_tracking_info = array();
indvdum@0
   113
indvdum@0
   114
	// Get topic tracking info
indvdum@0
   115
	if ($config['load_db_lastread'])
indvdum@0
   116
	{
indvdum@0
   117
		$tmp_topic_data = array($post_info['topic_id'] => $post_info);
indvdum@0
   118
		$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']));
indvdum@0
   119
		unset($tmp_topic_data);
indvdum@0
   120
	}
indvdum@0
   121
	else
indvdum@0
   122
	{
indvdum@0
   123
		$topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
indvdum@0
   124
	}
indvdum@0
   125
indvdum@0
   126
	$post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
indvdum@0
   127
indvdum@0
   128
	// Process message, leave it uncensored
indvdum@0
   129
	$message = $post_info['post_text'];
indvdum@0
   130
indvdum@0
   131
	if ($post_info['bbcode_bitfield'])
indvdum@0
   132
	{
indvdum@0
   133
		include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
indvdum@0
   134
		$bbcode = new bbcode($post_info['bbcode_bitfield']);
indvdum@0
   135
		$bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
indvdum@0
   136
	}
indvdum@0
   137
indvdum@0
   138
	$message = bbcode_nl2br($message);
indvdum@0
   139
	$message = smiley_text($message);
indvdum@0
   140
indvdum@0
   141
	if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
indvdum@0
   142
	{
indvdum@0
   143
		$extensions = $cache->obtain_attach_extensions($post_info['forum_id']);
indvdum@0
   144
indvdum@0
   145
		$sql = 'SELECT *
indvdum@0
   146
			FROM ' . ATTACHMENTS_TABLE . '
indvdum@0
   147
			WHERE post_msg_id = ' . $post_id . '
indvdum@0
   148
				AND in_message = 0
indvdum@0
   149
			ORDER BY filetime DESC, post_msg_id ASC';
indvdum@0
   150
		$result = $db->sql_query($sql);
indvdum@0
   151
indvdum@0
   152
		while ($row = $db->sql_fetchrow($result))
indvdum@0
   153
		{
indvdum@0
   154
			$attachments[] = $row;
indvdum@0
   155
		}
indvdum@0
   156
		$db->sql_freeresult($result);
indvdum@0
   157
indvdum@0
   158
		if (sizeof($attachments))
indvdum@0
   159
		{
indvdum@0
   160
			$update_count = array();
indvdum@0
   161
			parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
indvdum@0
   162
		}
indvdum@0
   163
indvdum@0
   164
		// Display not already displayed Attachments for this post, we already parsed them. ;)
indvdum@0
   165
		if (!empty($attachments))
indvdum@0
   166
		{
indvdum@0
   167
			$template->assign_var('S_HAS_ATTACHMENTS', true);
indvdum@0
   168
indvdum@0
   169
			foreach ($attachments as $attachment)
indvdum@0
   170
			{
indvdum@0
   171
				$template->assign_block_vars('attachment', array(
indvdum@0
   172
					'DISPLAY_ATTACHMENT'	=> $attachment)
indvdum@0
   173
				);
indvdum@0
   174
			}
indvdum@0
   175
		}
indvdum@0
   176
	}
indvdum@0
   177
indvdum@0
   178
	$template->assign_vars(array(
indvdum@0
   179
		'U_MCP_ACTION'			=> "$url&amp;i=main&amp;quickmod=1&amp;mode=post_details", // Use this for mode paramaters
indvdum@0
   180
		'U_POST_ACTION'			=> "$url&amp;i=$id&amp;mode=post_details", // Use this for action parameters
indvdum@0
   181
		'U_APPROVE_ACTION'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&amp;p=$post_id&amp;f={$post_info['forum_id']}"),
indvdum@0
   182
indvdum@0
   183
		'S_CAN_VIEWIP'			=> $auth->acl_get('m_info', $post_info['forum_id']),
indvdum@0
   184
		'S_CAN_CHGPOSTER'		=> $auth->acl_get('m_chgposter', $post_info['forum_id']),
indvdum@0
   185
		'S_CAN_LOCK_POST'		=> $auth->acl_get('m_lock', $post_info['forum_id']),
indvdum@0
   186
		'S_CAN_DELETE_POST'		=> $auth->acl_get('m_delete', $post_info['forum_id']),
indvdum@0
   187
indvdum@0
   188
		'S_POST_REPORTED'		=> ($post_info['post_reported']) ? true : false,
indvdum@0
   189
		'S_POST_UNAPPROVED'		=> (!$post_info['post_approved']) ? true : false,
indvdum@0
   190
		'S_POST_LOCKED'			=> ($post_info['post_edit_locked']) ? true : false,
indvdum@0
   191
		'S_USER_NOTES'			=> true,
indvdum@0
   192
		'S_CLEAR_ALLOWED'		=> ($auth->acl_get('a_clearlogs')) ? true : false,
indvdum@0
   193
indvdum@0
   194
		'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']}") : '',
indvdum@0
   195
		'U_FIND_USERNAME'		=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=mcp_chgposter&amp;field=username&amp;select_single=true'),
indvdum@0
   196
		'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),
indvdum@0
   197
		'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),
indvdum@0
   198
		'U_MCP_USER_NOTES'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $post_info['user_id']),
indvdum@0
   199
		'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']) : '',
indvdum@0
   200
		'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']),
indvdum@0
   201
		'U_VIEW_TOPIC'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']),
indvdum@0
   202
indvdum@0
   203
		'MINI_POST_IMG'			=> ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
indvdum@0
   204
indvdum@0
   205
		'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>'),
indvdum@0
   206
		'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>'),
indvdum@0
   207
		'REPORTED_IMG'			=> $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
indvdum@0
   208
		'UNAPPROVED_IMG'		=> $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
indvdum@0
   209
		'EDIT_IMG'				=> $user->img('icon_post_edit', $user->lang['EDIT_POST']),
indvdum@0
   210
		'SEARCH_IMG'			=> $user->img('icon_user_search', $user->lang['SEARCH']),
indvdum@0
   211
indvdum@0
   212
		'POST_AUTHOR_FULL'		=> get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
indvdum@0
   213
		'POST_AUTHOR_COLOUR'	=> get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
indvdum@0
   214
		'POST_AUTHOR'			=> get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
indvdum@0
   215
		'U_POST_AUTHOR'			=> get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
indvdum@0
   216
indvdum@0
   217
		'POST_PREVIEW'			=> $message,
indvdum@0
   218
		'POST_SUBJECT'			=> $post_info['post_subject'],
indvdum@0
   219
		'POST_DATE'				=> $user->format_date($post_info['post_time']),
indvdum@0
   220
		'POST_IP'				=> $post_info['poster_ip'],
indvdum@0
   221
		'POST_IPADDR'			=> ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
indvdum@0
   222
		'POST_ID'				=> $post_info['post_id'],
indvdum@0
   223
indvdum@0
   224
		'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" : '',
indvdum@0
   225
		'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']}") : '',
indvdum@0
   226
	));
indvdum@0
   227
indvdum@0
   228
	// Get User Notes
indvdum@0
   229
	$log_data = array();
indvdum@0
   230
	$log_count = false;
indvdum@0
   231
	view_log('user', $log_data, $log_count, $config['posts_per_page'], 0, 0, 0, $post_info['user_id']);
indvdum@0
   232
indvdum@0
   233
	if (!empty($log_data))
indvdum@0
   234
	{
indvdum@0
   235
		$template->assign_var('S_USER_NOTES', true);
indvdum@0
   236
indvdum@0
   237
		foreach ($log_data as $row)
indvdum@0
   238
		{
indvdum@0
   239
			$template->assign_block_vars('usernotes', array(
indvdum@0
   240
				'REPORT_BY'		=> $row['username_full'],
indvdum@0
   241
				'REPORT_AT'		=> $user->format_date($row['time']),
indvdum@0
   242
				'ACTION'		=> $row['action'],
indvdum@0
   243
				'ID'			=> $row['id'])
indvdum@0
   244
			);
indvdum@0
   245
		}
indvdum@0
   246
	}
indvdum@0
   247
indvdum@0
   248
	// Get Reports
indvdum@0
   249
	if ($auth->acl_get('m_report', $post_info['forum_id']))
indvdum@0
   250
	{
indvdum@0
   251
		$sql = 'SELECT r.*, re.*, u.user_id, u.username
indvdum@0
   252
			FROM ' . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u, ' . REPORTS_REASONS_TABLE . " re
indvdum@0
   253
			WHERE r.post_id = $post_id
indvdum@0
   254
				AND r.reason_id = re.reason_id
indvdum@0
   255
				AND u.user_id = r.user_id
indvdum@0
   256
			ORDER BY r.report_time DESC";
indvdum@0
   257
		$result = $db->sql_query($sql);
indvdum@0
   258
indvdum@0
   259
		if ($row = $db->sql_fetchrow($result))
indvdum@0
   260
		{
indvdum@0
   261
			$template->assign_var('S_SHOW_REPORTS', true);
indvdum@0
   262
indvdum@0
   263
			do
indvdum@0
   264
			{
indvdum@0
   265
				// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
indvdum@0
   266
				if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
indvdum@0
   267
				{
indvdum@0
   268
					$row['reson_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
indvdum@0
   269
					$row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
indvdum@0
   270
				}
indvdum@0
   271
indvdum@0
   272
				$template->assign_block_vars('reports', array(
indvdum@0
   273
					'REPORT_ID'		=> $row['report_id'],
indvdum@0
   274
					'REASON_TITLE'	=> $row['reason_title'],
indvdum@0
   275
					'REASON_DESC'	=> $row['reason_description'],
indvdum@0
   276
					'REPORTER'		=> ($row['user_id'] != ANONYMOUS) ? $row['username'] : $user->lang['GUEST'],
indvdum@0
   277
					'U_REPORTER'	=> ($row['user_id'] != ANONYMOUS) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']) : '',
indvdum@0
   278
					'USER_NOTIFY'	=> ($row['user_notify']) ? true : false,
indvdum@0
   279
					'REPORT_TIME'	=> $user->format_date($row['report_time']),
indvdum@0
   280
					'REPORT_TEXT'	=> bbcode_nl2br(trim($row['report_text'])),
indvdum@0
   281
				));
indvdum@0
   282
			}
indvdum@0
   283
			while ($row = $db->sql_fetchrow($result));
indvdum@0
   284
		}
indvdum@0
   285
		$db->sql_freeresult($result);
indvdum@0
   286
	}
indvdum@0
   287
indvdum@0
   288
	// Get IP
indvdum@0
   289
	if ($auth->acl_get('m_info', $post_info['forum_id']))
indvdum@0
   290
	{
indvdum@0
   291
		$rdns_ip_num = request_var('rdns', '');
indvdum@0
   292
indvdum@0
   293
		if ($rdns_ip_num != 'all')
indvdum@0
   294
		{
indvdum@0
   295
			$template->assign_vars(array(
indvdum@0
   296
				'U_LOOKUP_ALL'	=> "$url&amp;i=main&amp;mode=post_details&amp;rdns=all")
indvdum@0
   297
			);
indvdum@0
   298
		}
indvdum@0
   299
indvdum@0
   300
		// Get other users who've posted under this IP
indvdum@0
   301
		$sql = 'SELECT poster_id, COUNT(poster_id) as postings
indvdum@0
   302
			FROM ' . POSTS_TABLE . "
indvdum@0
   303
			WHERE poster_ip = '" . $db->sql_escape($post_info['poster_ip']) . "'
indvdum@0
   304
			GROUP BY poster_id
indvdum@0
   305
			ORDER BY postings DESC";
indvdum@0
   306
		$result = $db->sql_query($sql);
indvdum@0
   307
indvdum@0
   308
		while ($row = $db->sql_fetchrow($result))
indvdum@0
   309
		{
indvdum@0
   310
			// Fill the user select list with users who have posted under this IP
indvdum@0
   311
			if ($row['poster_id'] != $post_info['poster_id'])
indvdum@0
   312
			{
indvdum@0
   313
				$users_ary[$row['poster_id']] = $row;
indvdum@0
   314
			}
indvdum@0
   315
		}
indvdum@0
   316
		$db->sql_freeresult($result);
indvdum@0
   317
indvdum@0
   318
		if (sizeof($users_ary))
indvdum@0
   319
		{
indvdum@0
   320
			// Get the usernames
indvdum@0
   321
			$sql = 'SELECT user_id, username
indvdum@0
   322
				FROM ' . USERS_TABLE . '
indvdum@0
   323
				WHERE ' . $db->sql_in_set('user_id', array_keys($users_ary));
indvdum@0
   324
			$result = $db->sql_query($sql);
indvdum@0
   325
indvdum@0
   326
			while ($row = $db->sql_fetchrow($result))
indvdum@0
   327
			{
indvdum@0
   328
				$users_ary[$row['user_id']]['username'] = $row['username'];
indvdum@0
   329
				$usernames_ary[utf8_clean_string($row['username'])] = $users_ary[$row['user_id']];
indvdum@0
   330
			}
indvdum@0
   331
			$db->sql_freeresult($result);
indvdum@0
   332
indvdum@0
   333
			foreach ($users_ary as $user_id => $user_row)
indvdum@0
   334
			{
indvdum@0
   335
				$template->assign_block_vars('userrow', array(
indvdum@0
   336
					'USERNAME'		=> ($user_id == ANONYMOUS) ? $user->lang['GUEST'] : $user_row['username'],
indvdum@0
   337
					'NUM_POSTS'		=> $user_row['postings'],
indvdum@0
   338
					'L_POST_S'		=> ($user_row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS'],
indvdum@0
   339
indvdum@0
   340
					'U_PROFILE'		=> ($user_id == ANONYMOUS) ? '' : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $user_id),
indvdum@0
   341
					'U_SEARCHPOSTS' => append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user_id . '&amp;sr=topics'))
indvdum@0
   342
				);
indvdum@0
   343
			}
indvdum@0
   344
		}
indvdum@0
   345
indvdum@0
   346
		// Get other IP's this user has posted under
indvdum@0
   347
indvdum@0
   348
		// A compound index on poster_id, poster_ip (posts table) would help speed up this query a lot,
indvdum@0
   349
		// but the extra size is only valuable if there are persons having more than a thousands posts.
indvdum@0
   350
		// This is better left to the really really big forums.
indvdum@0
   351
indvdum@0
   352
		$sql = 'SELECT poster_ip, COUNT(poster_ip) AS postings
indvdum@0
   353
			FROM ' . POSTS_TABLE . '
indvdum@0
   354
			WHERE poster_id = ' . $post_info['poster_id'] . "
indvdum@0
   355
			GROUP BY poster_ip
indvdum@0
   356
			ORDER BY postings DESC";
indvdum@0
   357
		$result = $db->sql_query($sql);
indvdum@0
   358
indvdum@0
   359
		while ($row = $db->sql_fetchrow($result))
indvdum@0
   360
		{
indvdum@0
   361
			$hostname = (($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') && $row['poster_ip']) ? @gethostbyaddr($row['poster_ip']) : '';
indvdum@0
   362
indvdum@0
   363
			$template->assign_block_vars('iprow', array(
indvdum@0
   364
				'IP'			=> $row['poster_ip'],
indvdum@0
   365
				'HOSTNAME'		=> $hostname,
indvdum@0
   366
				'NUM_POSTS'		=> $row['postings'],
indvdum@0
   367
				'L_POST_S'		=> ($row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS'],
indvdum@0
   368
indvdum@0
   369
				'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",
indvdum@0
   370
				'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']}"))
indvdum@0
   371
			);
indvdum@0
   372
		}
indvdum@0
   373
		$db->sql_freeresult($result);
indvdum@0
   374
indvdum@0
   375
		$user_select = '';
indvdum@0
   376
indvdum@0
   377
		if (sizeof($usernames_ary))
indvdum@0
   378
		{
indvdum@0
   379
			ksort($usernames_ary);
indvdum@0
   380
indvdum@0
   381
			foreach ($usernames_ary as $row)
indvdum@0
   382
			{
indvdum@0
   383
				$user_select .= '<option value="' . $row['poster_id'] . '">' . $row['username'] . "</option>\n";
indvdum@0
   384
			}
indvdum@0
   385
		}
indvdum@0
   386
indvdum@0
   387
		$template->assign_var('S_USER_SELECT', $user_select);
indvdum@0
   388
	}
indvdum@0
   389
indvdum@0
   390
}
indvdum@0
   391
indvdum@0
   392
/**
indvdum@0
   393
* Change a post's poster
indvdum@0
   394
*/
indvdum@0
   395
function change_poster(&$post_info, $userdata)
indvdum@0
   396
{
indvdum@0
   397
	global $auth, $db, $config, $phpbb_root_path, $phpEx;
indvdum@0
   398
indvdum@0
   399
	if (empty($userdata) || $userdata['user_id'] == $post_info['user_id'])
indvdum@0
   400
	{
indvdum@0
   401
		return;
indvdum@0
   402
	}
indvdum@0
   403
indvdum@0
   404
	$post_id = $post_info['post_id'];
indvdum@0
   405
indvdum@0
   406
	$sql = 'UPDATE ' . POSTS_TABLE . "
indvdum@0
   407
		SET poster_id = {$userdata['user_id']}
indvdum@0
   408
		WHERE post_id = $post_id";
indvdum@0
   409
	$db->sql_query($sql);
indvdum@0
   410
indvdum@0
   411
	// Resync topic/forum if needed
indvdum@0
   412
	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)
indvdum@0
   413
	{
indvdum@0
   414
		sync('topic', 'topic_id', $post_info['topic_id'], false, false);
indvdum@0
   415
		sync('forum', 'forum_id', $post_info['forum_id'], false, false);
indvdum@0
   416
	}
indvdum@0
   417
indvdum@0
   418
	// Adjust post counts... only if the post is approved (else, it was not added the users post count anyway)
indvdum@0
   419
	if ($post_info['post_postcount'] && $post_info['post_approved'])
indvdum@0
   420
	{
indvdum@0
   421
		$sql = 'UPDATE ' . USERS_TABLE . '
indvdum@0
   422
			SET user_posts = user_posts - 1
indvdum@0
   423
			WHERE user_id = ' . $post_info['user_id'] .'
indvdum@0
   424
			AND user_posts > 0';
indvdum@0
   425
		$db->sql_query($sql);
indvdum@0
   426
indvdum@0
   427
		$sql = 'UPDATE ' . USERS_TABLE . '
indvdum@0
   428
			SET user_posts = user_posts + 1
indvdum@0
   429
			WHERE user_id = ' . $userdata['user_id'];
indvdum@0
   430
		$db->sql_query($sql);
indvdum@0
   431
	}
indvdum@0
   432
indvdum@0
   433
	// Add posted to information for this topic for the new user
indvdum@0
   434
	markread('post', $post_info['forum_id'], $post_info['topic_id'], time(), $userdata['user_id']);
indvdum@0
   435
indvdum@0
   436
	// Remove the dotted topic option if the old user has no more posts within this topic
indvdum@0
   437
	if ($config['load_db_track'] && $post_info['user_id'] != ANONYMOUS)
indvdum@0
   438
	{
indvdum@0
   439
		$sql = 'SELECT topic_id
indvdum@0
   440
			FROM ' . POSTS_TABLE . '
indvdum@0
   441
			WHERE topic_id = ' . $post_info['topic_id'] . '
indvdum@0
   442
				AND poster_id = ' . $post_info['user_id'];
indvdum@0
   443
		$result = $db->sql_query_limit($sql, 1);
indvdum@0
   444
		$topic_id = (int) $db->sql_fetchfield('topic_id');
indvdum@0
   445
		$db->sql_freeresult($result);
indvdum@0
   446
indvdum@0
   447
		if (!$topic_id)
indvdum@0
   448
		{
indvdum@0
   449
			$sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
indvdum@0
   450
				WHERE user_id = ' . $post_info['user_id'] . '
indvdum@0
   451
					AND topic_id = ' . $post_info['topic_id'];
indvdum@0
   452
			$db->sql_query($sql);
indvdum@0
   453
		}
indvdum@0
   454
	}
indvdum@0
   455
indvdum@0
   456
	// change the poster_id within the attachments table, else the data becomes out of sync and errors displayed because of wrong ownership
indvdum@0
   457
	if ($post_info['post_attachment'])
indvdum@0
   458
	{
indvdum@0
   459
		$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
indvdum@0
   460
			SET poster_id = ' . $userdata['user_id'] . '
indvdum@0
   461
			WHERE poster_id = ' . $post_info['user_id'] . '
indvdum@0
   462
				AND post_msg_id = ' . $post_info['post_id'] . '
indvdum@0
   463
				AND topic_id = ' . $post_info['topic_id'];
indvdum@0
   464
		$db->sql_query($sql);
indvdum@0
   465
	}
indvdum@0
   466
indvdum@0
   467
	// refresh search cache of this post
indvdum@0
   468
	$search_type = basename($config['search_type']);
indvdum@0
   469
indvdum@0
   470
	if (file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
indvdum@0
   471
	{
indvdum@0
   472
		require("{$phpbb_root_path}includes/search/$search_type.$phpEx");
indvdum@0
   473
indvdum@0
   474
		// We do some additional checks in the module to ensure it can actually be utilised
indvdum@0
   475
		$error = false;
indvdum@0
   476
		$search = new $search_type($error);
indvdum@0
   477
indvdum@0
   478
		if (!$error && method_exists($search, 'destroy_cache'))
indvdum@0
   479
		{
indvdum@0
   480
			$search->destroy_cache(array(), array($post_info['user_id'], $userdata['user_id']));
indvdum@0
   481
		}
indvdum@0
   482
	}
indvdum@0
   483
indvdum@0
   484
	$from_username = $post_info['username'];
indvdum@0
   485
	$to_username = $userdata['username'];
indvdum@0
   486
indvdum@0
   487
	// Renew post info
indvdum@0
   488
	$post_info = get_post_data(array($post_id), false, true);
indvdum@0
   489
indvdum@0
   490
	if (!sizeof($post_info))
indvdum@0
   491
	{
indvdum@0
   492
		trigger_error('POST_NOT_EXIST');
indvdum@0
   493
	}
indvdum@0
   494
indvdum@0
   495
	$post_info = $post_info[$post_id];
indvdum@0
   496
indvdum@0
   497
	// Now add log entry
indvdum@0
   498
	add_log('mod', $post_info['forum_id'], $post_info['topic_id'], 'LOG_MCP_CHANGE_POSTER', $post_info['topic_title'], $from_username, $to_username);
indvdum@0
   499
}
indvdum@0
   500
indvdum@0
   501
?>