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

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package mcp
4c79b5
* @version $Id: mcp_forum.php 9003 2008-10-11 18:23:12Z toonarmy $
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
* MCP Forum View
4c79b5
*/
4c79b5
function mcp_forum_view($id, $mode, $action, $forum_info)
4c79b5
{
4c79b5
	global $template, $db, $user, $auth, $cache, $module;
4c79b5
	global $phpEx, $phpbb_root_path, $config;
4c79b5
4c79b5
	$user->add_lang(array('viewtopic', 'viewforum'));
4c79b5
4c79b5
	include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
4c79b5
4c79b5
	// merge_topic is the quickmod action, merge_topics is the mcp_forum action, and merge_select is the mcp_topic action
4c79b5
	$merge_select = ($action == 'merge_select' || $action == 'merge_topic' || $action == 'merge_topics') ? true : false;
4c79b5
4c79b5
	if ($merge_select)
4c79b5
	{
4c79b5
		// Fixes a "bug" that makes forum_view use the same ordering as topic_view
4c79b5
		unset($_POST['sk'], $_POST['sd'], $_REQUEST['sk'], $_REQUEST['sd']);
4c79b5
	}
4c79b5
4c79b5
	$forum_id			= $forum_info['forum_id'];
4c79b5
	$start				= request_var('start', 0);
4c79b5
	$topic_id_list		= request_var('topic_id_list', array(0));
4c79b5
	$post_id_list		= request_var('post_id_list', array(0));
4c79b5
	$source_topic_ids	= array(request_var('t', 0));
4c79b5
	$to_topic_id		= request_var('to_topic_id', 0);
4c79b5
4c79b5
	$url_extra = '';
4c79b5
	$url_extra .= ($forum_id) ? "&f=$forum_id" : '';
4c79b5
	$url_extra .= ($GLOBALS['topic_id']) ? '&t=' . $GLOBALS['topic_id'] : '';
4c79b5
	$url_extra .= ($GLOBALS['post_id']) ? '&p=' . $GLOBALS['post_id'] : '';
4c79b5
	$url_extra .= ($GLOBALS['user_id']) ? '&u=' . $GLOBALS['user_id'] : '';
4c79b5
4c79b5
	$url = append_sid("{$phpbb_root_path}mcp.$phpEx?$url_extra");
4c79b5
4c79b5
	// Resync Topics
4c79b5
	switch ($action)
4c79b5
	{
4c79b5
		case 'resync':
4c79b5
			$topic_ids = request_var('topic_id_list', array(0));
4c79b5
			mcp_resync_topics($topic_ids);
4c79b5
		break;
4c79b5
4c79b5
		case 'merge_topics':
4c79b5
			$source_topic_ids = $topic_id_list;
4c79b5
		case 'merge_topic':
4c79b5
			if ($to_topic_id)
4c79b5
			{
4c79b5
				merge_topics($forum_id, $source_topic_ids, $to_topic_id);
4c79b5
			}
4c79b5
		break;
4c79b5
	}
4c79b5
4c79b5
	$selected_ids = '';
4c79b5
	if (sizeof($post_id_list) && $action != 'merge_topics')
4c79b5
	{
4c79b5
		foreach ($post_id_list as $num => $post_id)
4c79b5
		{
4c79b5
			$selected_ids .= '&post_id_list[' . $num . ']=' . $post_id;
4c79b5
		}
4c79b5
	}
4c79b5
	else if (sizeof($topic_id_list) && $action == 'merge_topics')
4c79b5
	{
4c79b5
		foreach ($topic_id_list as $num => $topic_id)
4c79b5
		{
4c79b5
			$selected_ids .= '&topic_id_list[' . $num . ']=' . $topic_id;
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	make_jumpbox($url . "&i=$id&action=$action&mode=$mode" . (($merge_select) ? $selected_ids : ''), $forum_id, false, 'm_', true);
4c79b5
4c79b5
	$topics_per_page = ($forum_info['forum_topics_per_page']) ? $forum_info['forum_topics_per_page'] : $config['topics_per_page'];
4c79b5
4c79b5
	$sort_days = $total = 0;
4c79b5
	$sort_key = $sort_dir = '';
4c79b5
	$sort_by_sql = $sort_order_sql = array();
4c79b5
	mcp_sorting('viewforum', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id);
4c79b5
4c79b5
	$forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
4c79b5
	$limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
4c79b5
4c79b5
	$template->assign_vars(array(
4c79b5
		'ACTION'				=> $action,
4c79b5
		'FORUM_NAME'			=> $forum_info['forum_name'],
4c79b5
		'FORUM_DESCRIPTION'		=> generate_text_for_display($forum_info['forum_desc'], $forum_info['forum_desc_uid'], $forum_info['forum_desc_bitfield'], $forum_info['forum_desc_options']),
4c79b5
4c79b5
		'REPORTED_IMG'			=> $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
4c79b5
		'UNAPPROVED_IMG'		=> $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
4c79b5
		'LAST_POST_IMG'			=> $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
4c79b5
		'NEWEST_POST_IMG'		=> $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
4c79b5
4c79b5
		'S_CAN_REPORT'			=> $auth->acl_get('m_report', $forum_id),
4c79b5
		'S_CAN_DELETE'			=> $auth->acl_get('m_delete', $forum_id),
4c79b5
		'S_CAN_MERGE'			=> $auth->acl_get('m_merge', $forum_id),
4c79b5
		'S_CAN_MOVE'			=> $auth->acl_get('m_move', $forum_id),
4c79b5
		'S_CAN_FORK'			=> $auth->acl_get('m_', $forum_id),
4c79b5
		'S_CAN_LOCK'			=> $auth->acl_get('m_lock', $forum_id),
4c79b5
		'S_CAN_SYNC'			=> $auth->acl_get('m_', $forum_id),
4c79b5
		'S_CAN_APPROVE'			=> $auth->acl_get('m_approve', $forum_id),
4c79b5
		'S_MERGE_SELECT'		=> ($merge_select) ? true : false,
4c79b5
		'S_CAN_MAKE_NORMAL'		=> $auth->acl_gets('f_sticky', 'f_announce', $forum_id),
4c79b5
		'S_CAN_MAKE_STICKY'		=> $auth->acl_get('f_sticky', $forum_id),
4c79b5
		'S_CAN_MAKE_ANNOUNCE'	=> $auth->acl_get('f_announce', $forum_id),
4c79b5
4c79b5
		'U_VIEW_FORUM'			=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
4c79b5
		'U_VIEW_FORUM_LOGS'		=> ($auth->acl_gets('a_', 'm_', $forum_id) && $module->loaded('logs')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=logs&mode=forum_logs&f=' . $forum_id) : '',
4c79b5
4c79b5
		'S_MCP_ACTION'			=> $url . "&i=$id&forum_action=$action&mode=$mode&start=$start" . (($merge_select) ? $selected_ids : ''),
4c79b5
4c79b5
		'PAGINATION'			=> generate_pagination($url . "&i=$id&action=$action&mode=$mode&sd=$sort_dir&sk=$sort_key&st=$sort_days" . (($merge_select) ? $selected_ids : ''), $forum_topics, $topics_per_page, $start),
4c79b5
		'PAGE_NUMBER'			=> on_page($forum_topics, $topics_per_page, $start),
4c79b5
		'TOTAL_TOPICS'			=> ($forum_topics == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $forum_topics),
4c79b5
	));
4c79b5
4c79b5
	// Grab icons
4c79b5
	$icons = $cache->obtain_icons();
4c79b5
4c79b5
	$topic_rows = array();
4c79b5
4c79b5
	if ($config['load_db_lastread'])
4c79b5
	{
4c79b5
		$read_tracking_join = ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . ')';
4c79b5
		$read_tracking_select = ', tt.mark_time';
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$read_tracking_join = $read_tracking_select = '';
4c79b5
	}
4c79b5
4c79b5
	$sql = "SELECT t.topic_id
4c79b5
		FROM " . TOPICS_TABLE . " t
4c79b5
		WHERE t.forum_id IN($forum_id, 0)
4c79b5
			" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1') . "
4c79b5
			$limit_time_sql
4c79b5
		ORDER BY t.topic_type DESC, $sort_order_sql";
4c79b5
	$result = $db->sql_query_limit($sql, $topics_per_page, $start);
4c79b5
4c79b5
	$topic_list = $topic_tracking_info = array();
4c79b5
4c79b5
	while ($row = $db->sql_fetchrow($result))
4c79b5
	{
4c79b5
		$topic_list[] = $row['topic_id'];
4c79b5
	}
4c79b5
	$db->sql_freeresult($result);
4c79b5
4c79b5
	$sql = "SELECT t.*$read_tracking_select
4c79b5
		FROM " . TOPICS_TABLE . " t $read_tracking_join
4c79b5
		WHERE " . $db->sql_in_set('t.topic_id', $topic_list, false, true);
4c79b5
4c79b5
	$result = $db->sql_query($sql);
4c79b5
	while ($row = $db->sql_fetchrow($result))
4c79b5
	{
4c79b5
		$topic_rows[$row['topic_id']] = $row;
4c79b5
	}
4c79b5
	$db->sql_freeresult($result);
4c79b5
4c79b5
	// If there is more than one page, but we have no topic list, then the start parameter is... erm... out of sync
4c79b5
	if (!sizeof($topic_list) && $forum_topics && $start > 0)
4c79b5
	{
4c79b5
		redirect($url . "&i=$id&action=$action&mode=$mode");
4c79b5
	}
4c79b5
4c79b5
	// Get topic tracking info
4c79b5
	if (sizeof($topic_list))
4c79b5
	{
4c79b5
		if ($config['load_db_lastread'])
4c79b5
		{
4c79b5
			$topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $topic_rows, array($forum_id => $forum_info['mark_time']), array());
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, array());
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	foreach ($topic_list as $topic_id)
4c79b5
	{
4c79b5
		$topic_title = '';
4c79b5
4c79b5
		$row = &$topic_rows[$topic_id];
4c79b5
4c79b5
		$replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
4c79b5
4c79b5
		if ($row['topic_status'] == ITEM_MOVED)
4c79b5
		{
4c79b5
			$unread_topic = false;
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
4c79b5
		}
4c79b5
4c79b5
		// Get folder img, topic status/type related information
4c79b5
		$folder_img = $folder_alt = $topic_type = '';
4c79b5
		topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
4c79b5
4c79b5
		$topic_title = censor_text($row['topic_title']);
4c79b5
4c79b5
		$topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false;
4c79b5
		$posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false;
4c79b5
		$u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? $url . '&i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . '&t=' . $row['topic_id'] : '';
4c79b5
4c79b5
		$topic_row = array(
4c79b5
			'ATTACH_ICON_IMG'		=> ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
4c79b5
			'TOPIC_FOLDER_IMG'		=> $user->img($folder_img, $folder_alt),
4c79b5
			'TOPIC_FOLDER_IMG_SRC'	=> $user->img($folder_img, $folder_alt, false, '', 'src'),
4c79b5
			'TOPIC_ICON_IMG'		=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
4c79b5
			'TOPIC_ICON_IMG_WIDTH'	=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
4c79b5
			'TOPIC_ICON_IMG_HEIGHT'	=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
4c79b5
			'UNAPPROVED_IMG'		=> ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
4c79b5
4c79b5
			'TOPIC_AUTHOR'				=> get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
4c79b5
			'TOPIC_AUTHOR_COLOUR'		=> get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
4c79b5
			'TOPIC_AUTHOR_FULL'			=> get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
4c79b5
			'U_TOPIC_AUTHOR'			=> get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
4c79b5
4c79b5
			'LAST_POST_AUTHOR'			=> get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
4c79b5
			'LAST_POST_AUTHOR_COLOUR'	=> get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
4c79b5
			'LAST_POST_AUTHOR_FULL'		=> get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
4c79b5
			'U_LAST_POST_AUTHOR'		=> get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
4c79b5
4c79b5
			'TOPIC_TYPE'		=> $topic_type,
4c79b5
			'TOPIC_TITLE'		=> $topic_title,
4c79b5
			'REPLIES'			=> ($auth->acl_get('m_approve', $row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies'],
4c79b5
			'LAST_POST_TIME'	=> $user->format_date($row['topic_last_post_time']),
4c79b5
			'FIRST_POST_TIME'	=> $user->format_date($row['topic_time']),
4c79b5
			'LAST_POST_SUBJECT'	=> $row['topic_last_post_subject'],
4c79b5
			'LAST_VIEW_TIME'	=> $user->format_date($row['topic_last_view_time']),
4c79b5
4c79b5
			'S_TOPIC_REPORTED'		=> (!empty($row['topic_reported']) && empty($row['topic_moved_id']) && $auth->acl_get('m_report', $row['forum_id'])) ? true : false,
4c79b5
			'S_TOPIC_UNAPPROVED'	=> $topic_unapproved,
4c79b5
			'S_POSTS_UNAPPROVED'	=> $posts_unapproved,
4c79b5
			'S_UNREAD_TOPIC'		=> $unread_topic,
4c79b5
		);
4c79b5
4c79b5
		if ($row['topic_status'] == ITEM_MOVED)
4c79b5
		{
4c79b5
			$topic_row = array_merge($topic_row, array(
4c79b5
				'U_VIEW_TOPIC'		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_moved_id']}"),
4c79b5
				'U_DELETE_TOPIC'	=> ($auth->acl_get('m_delete', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&f=$forum_id&topic_id_list[]={$row['topic_id']}&mode=forum_view&action=delete_topic") : '',
4c79b5
				'S_MOVED_TOPIC'		=> true,
4c79b5
				'TOPIC_ID'			=> $row['topic_moved_id'],
4c79b5
			));
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			if ($action == 'merge_topic' || $action == 'merge_topics')
4c79b5
			{
4c79b5
				$u_select_topic = $url . "&i=$id&mode=forum_view&action=$action&to_topic_id=" . $row['topic_id'] . $selected_ids;
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$u_select_topic = $url . "&i=$id&mode=topic_view&action=merge&to_topic_id=" . $row['topic_id'] . $selected_ids;
4c79b5
			}
4c79b5
			$topic_row = array_merge($topic_row, array(
4c79b5
				'U_VIEW_TOPIC'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&f=$forum_id&t={$row['topic_id']}&mode=topic_view"),
4c79b5
4c79b5
				'S_SELECT_TOPIC'	=> ($merge_select && !in_array($row['topic_id'], $source_topic_ids)) ? true : false,
4c79b5
				'U_SELECT_TOPIC'	=> $u_select_topic,
4c79b5
				'U_MCP_QUEUE'		=> $u_mcp_queue,
4c79b5
				'U_MCP_REPORT'		=> ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&mode=topic_view&t=' . $row['topic_id'] . '&action=reports') : '',
4c79b5
				'TOPIC_ID'			=> $row['topic_id'],
4c79b5
				'S_TOPIC_CHECKED'	=> ($topic_id_list && in_array($row['topic_id'], $topic_id_list)) ? true : false,
4c79b5
			));
4c79b5
		}
4c79b5
4c79b5
		$template->assign_block_vars('topicrow', $topic_row);
4c79b5
	}
4c79b5
	unset($topic_rows);
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* Resync topics
4c79b5
*/
4c79b5
function mcp_resync_topics($topic_ids)
4c79b5
{
4c79b5
	global $auth, $db, $template, $phpEx, $user, $phpbb_root_path;
4c79b5
4c79b5
	if (!sizeof($topic_ids))
4c79b5
	{
4c79b5
		trigger_error('NO_TOPIC_SELECTED');
4c79b5
	}
4c79b5
4c79b5
	if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_')))
4c79b5
	{
4c79b5
		return;
4c79b5
	}
4c79b5
4c79b5
	// Sync everything and perform extra checks separately
4c79b5
	sync('topic_reported', 'topic_id', $topic_ids, false, true);
4c79b5
	sync('topic_attachment', 'topic_id', $topic_ids, false, true);
4c79b5
	sync('topic', 'topic_id', $topic_ids, true, false);
4c79b5
4c79b5
	$sql = 'SELECT topic_id, forum_id, topic_title
4c79b5
		FROM ' . TOPICS_TABLE . '
4c79b5
		WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
4c79b5
	$result = $db->sql_query($sql);
4c79b5
4c79b5
	// Log this action
4c79b5
	while ($row = $db->sql_fetchrow($result))
4c79b5
	{
4c79b5
		add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_TOPIC_RESYNC', $row['topic_title']);
4c79b5
	}
4c79b5
	$db->sql_freeresult($result);
4c79b5
4c79b5
	$msg = (sizeof($topic_ids) == 1) ? $user->lang['TOPIC_RESYNC_SUCCESS'] : $user->lang['TOPICS_RESYNC_SUCCESS'];
4c79b5
4c79b5
	$redirect = request_var('redirect', $user->data['session_page']);
4c79b5
4c79b5
	meta_refresh(3, $redirect);
4c79b5
	trigger_error($msg . '

' . sprintf($user->lang['RETURN_PAGE'], '', ''));
4c79b5
4c79b5
	return;
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* Merge selected topics into selected topic
4c79b5
*/
4c79b5
function merge_topics($forum_id, $topic_ids, $to_topic_id)
4c79b5
{
4c79b5
	global $db, $template, $user, $phpEx, $phpbb_root_path, $auth;
4c79b5
4c79b5
	if (!sizeof($topic_ids))
4c79b5
	{
4c79b5
		$template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']);
4c79b5
		return;
4c79b5
	}
4c79b5
	if (!$to_topic_id)
4c79b5
	{
4c79b5
		$template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
4c79b5
		return;
4c79b5
	}
4c79b5
4c79b5
	$topic_data = get_topic_data(array($to_topic_id), 'm_merge');
4c79b5
4c79b5
	if (!sizeof($topic_data))
4c79b5
	{
4c79b5
		$template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
4c79b5
		return;
4c79b5
	}
4c79b5
4c79b5
	$topic_data = $topic_data[$to_topic_id];
4c79b5
4c79b5
	$post_id_list	= request_var('post_id_list', array(0));
4c79b5
	$start			= request_var('start', 0);
4c79b5
4c79b5
	if (!sizeof($post_id_list) && sizeof($topic_ids))
4c79b5
	{
4c79b5
		$sql = 'SELECT post_id
4c79b5
			FROM ' . POSTS_TABLE . '
4c79b5
			WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		$post_id_list = array();
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$post_id_list[] = $row['post_id'];
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
	}
4c79b5
4c79b5
	if (!sizeof($post_id_list))
4c79b5
	{
4c79b5
		$template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
4c79b5
		return;
4c79b5
	}
4c79b5
4c79b5
	if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_merge')))
4c79b5
	{
4c79b5
		return;
4c79b5
	}
4c79b5
4c79b5
	$redirect = request_var('redirect', build_url(array('quickmod')));
4c79b5
4c79b5
	$s_hidden_fields = build_hidden_fields(array(
4c79b5
		'i'				=> 'main',
4c79b5
		'f'				=> $forum_id,
4c79b5
		'post_id_list'	=> $post_id_list,
4c79b5
		'to_topic_id'	=> $to_topic_id,
4c79b5
		'mode'			=> 'forum_view',
4c79b5
		'action'		=> 'merge_topics',
4c79b5
		'start'			=> $start,
4c79b5
		'redirect'		=> $redirect,
4c79b5
		'topic_id_list'	=> $topic_ids)
4c79b5
	);
4c79b5
	$success_msg = $return_link = '';
4c79b5
4c79b5
	if (confirm_box(true))
4c79b5
	{
4c79b5
		$to_forum_id = $topic_data['forum_id'];
4c79b5
4c79b5
		move_posts($post_id_list, $to_topic_id);
4c79b5
		add_log('mod', $to_forum_id, $to_topic_id, 'LOG_MERGE', $topic_data['topic_title']);
4c79b5
4c79b5
		// Message and return links
4c79b5
		$success_msg = 'POSTS_MERGED_SUCCESS';
4c79b5
4c79b5
		// If the topic no longer exist, we will update the topic watch table.
4c79b5
		// To not let it error out on users watching both topics, we just return on an error...
4c79b5
		$db->sql_return_on_error(true);
4c79b5
		$db->sql_query('UPDATE ' . TOPICS_WATCH_TABLE . ' SET topic_id = ' . (int) $to_topic_id . ' WHERE ' . $db->sql_in_set('topic_id', $topic_ids));
4c79b5
		$db->sql_return_on_error(false);
4c79b5
4c79b5
		$db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', $topic_ids));
4c79b5
4c79b5
		// Link to the new topic
4c79b5
		$return_link .= (($return_link) ? '

' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '', '');
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		confirm_box(false, 'MERGE_TOPICS', $s_hidden_fields);
4c79b5
	}
4c79b5
4c79b5
	$redirect = request_var('redirect', "index.$phpEx");
4c79b5
	$redirect = reapply_sid($redirect);
4c79b5
4c79b5
	if (!$success_msg)
4c79b5
	{
4c79b5
		return;
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		meta_refresh(3, append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&t=$to_topic_id"));
4c79b5
		trigger_error($user->lang[$success_msg] . '

' . $return_link);
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
?>