includes/mcp/mcp_forum.php
changeset 0 ceef6d64c21d
equal deleted inserted replaced
-1:000000000000 0:ceef6d64c21d
       
     1 <?php
       
     2 /**
       
     3 *
       
     4 * @package mcp
       
     5 * @version $Id$
       
     6 * @copyright (c) 2005 phpBB Group
       
     7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
       
     8 *
       
     9 */
       
    10 
       
    11 /**
       
    12 * @ignore
       
    13 */
       
    14 if (!defined('IN_PHPBB'))
       
    15 {
       
    16 	exit;
       
    17 }
       
    18 
       
    19 /**
       
    20 * MCP Forum View
       
    21 */
       
    22 function mcp_forum_view($id, $mode, $action, $forum_info)
       
    23 {
       
    24 	global $template, $db, $user, $auth, $cache, $module;
       
    25 	global $phpEx, $phpbb_root_path, $config;
       
    26 
       
    27 	$user->add_lang(array('viewtopic', 'viewforum'));
       
    28 
       
    29 	include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
       
    30 
       
    31 	// merge_topic is the quickmod action, merge_topics is the mcp_forum action, and merge_select is the mcp_topic action
       
    32 	$merge_select = ($action == 'merge_select' || $action == 'merge_topic' || $action == 'merge_topics') ? true : false;
       
    33 
       
    34 	if ($merge_select)
       
    35 	{
       
    36 		// Fixes a "bug" that makes forum_view use the same ordering as topic_view
       
    37 		unset($_POST['sk'], $_POST['sd'], $_REQUEST['sk'], $_REQUEST['sd']);
       
    38 	}
       
    39 
       
    40 	$forum_id			= $forum_info['forum_id'];
       
    41 	$start				= request_var('start', 0);
       
    42 	$topic_id_list		= request_var('topic_id_list', array(0));
       
    43 	$post_id_list		= request_var('post_id_list', array(0));
       
    44 	$source_topic_ids	= array(request_var('t', 0));
       
    45 	$to_topic_id		= request_var('to_topic_id', 0);
       
    46 
       
    47 	$url_extra = '';
       
    48 	$url_extra .= ($forum_id) ? "&amp;f=$forum_id" : '';
       
    49 	$url_extra .= ($GLOBALS['topic_id']) ? '&amp;t=' . $GLOBALS['topic_id'] : '';
       
    50 	$url_extra .= ($GLOBALS['post_id']) ? '&amp;p=' . $GLOBALS['post_id'] : '';
       
    51 	$url_extra .= ($GLOBALS['user_id']) ? '&amp;u=' . $GLOBALS['user_id'] : '';
       
    52 
       
    53 	$url = append_sid("{$phpbb_root_path}mcp.$phpEx?$url_extra");
       
    54 
       
    55 	// Resync Topics
       
    56 	switch ($action)
       
    57 	{
       
    58 		case 'resync':
       
    59 			$topic_ids = request_var('topic_id_list', array(0));
       
    60 			mcp_resync_topics($topic_ids);
       
    61 		break;
       
    62 
       
    63 		case 'merge_topics':
       
    64 			$source_topic_ids = $topic_id_list;
       
    65 		case 'merge_topic':
       
    66 			if ($to_topic_id)
       
    67 			{
       
    68 				merge_topics($forum_id, $source_topic_ids, $to_topic_id);
       
    69 			}
       
    70 		break;
       
    71 	}
       
    72 
       
    73 	$selected_ids = '';
       
    74 	if (sizeof($post_id_list) && $action != 'merge_topics')
       
    75 	{
       
    76 		foreach ($post_id_list as $num => $post_id)
       
    77 		{
       
    78 			$selected_ids .= '&amp;post_id_list[' . $num . ']=' . $post_id;
       
    79 		}
       
    80 	}
       
    81 	else if (sizeof($topic_id_list) && $action == 'merge_topics')
       
    82 	{
       
    83 		foreach ($topic_id_list as $num => $topic_id)
       
    84 		{
       
    85 			$selected_ids .= '&amp;topic_id_list[' . $num . ']=' . $topic_id;
       
    86 		}
       
    87 	}
       
    88 
       
    89 	make_jumpbox($url . "&amp;i=$id&amp;action=$action&amp;mode=$mode" . (($merge_select) ? $selected_ids : ''), $forum_id, false, 'm_', true);
       
    90 
       
    91 	$topics_per_page = ($forum_info['forum_topics_per_page']) ? $forum_info['forum_topics_per_page'] : $config['topics_per_page'];
       
    92 
       
    93 	$sort_days = $total = 0;
       
    94 	$sort_key = $sort_dir = '';
       
    95 	$sort_by_sql = $sort_order_sql = array();
       
    96 	mcp_sorting('viewforum', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id);
       
    97 
       
    98 	$forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
       
    99 	$limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
       
   100 
       
   101 	$template->assign_vars(array(
       
   102 		'ACTION'				=> $action,
       
   103 		'FORUM_NAME'			=> $forum_info['forum_name'],
       
   104 		'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']),
       
   105 
       
   106 		'REPORTED_IMG'			=> $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
       
   107 		'UNAPPROVED_IMG'		=> $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
       
   108 		'LAST_POST_IMG'			=> $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
       
   109 		'NEWEST_POST_IMG'		=> $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
       
   110 
       
   111 		'S_CAN_REPORT'			=> $auth->acl_get('m_report', $forum_id),
       
   112 		'S_CAN_DELETE'			=> $auth->acl_get('m_delete', $forum_id),
       
   113 		'S_CAN_MERGE'			=> $auth->acl_get('m_merge', $forum_id),
       
   114 		'S_CAN_MOVE'			=> $auth->acl_get('m_move', $forum_id),
       
   115 		'S_CAN_FORK'			=> $auth->acl_get('m_', $forum_id),
       
   116 		'S_CAN_LOCK'			=> $auth->acl_get('m_lock', $forum_id),
       
   117 		'S_CAN_SYNC'			=> $auth->acl_get('m_', $forum_id),
       
   118 		'S_CAN_APPROVE'			=> $auth->acl_get('m_approve', $forum_id),
       
   119 		'S_MERGE_SELECT'		=> ($merge_select) ? true : false,
       
   120 		'S_CAN_MAKE_NORMAL'		=> $auth->acl_gets('f_sticky', 'f_announce', $forum_id),
       
   121 		'S_CAN_MAKE_STICKY'		=> $auth->acl_get('f_sticky', $forum_id),
       
   122 		'S_CAN_MAKE_ANNOUNCE'	=> $auth->acl_get('f_announce', $forum_id),
       
   123 
       
   124 		'U_VIEW_FORUM'			=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
       
   125 		'U_VIEW_FORUM_LOGS'		=> ($auth->acl_gets('a_', 'm_', $forum_id) && $module->loaded('logs')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=logs&amp;mode=forum_logs&amp;f=' . $forum_id) : '',
       
   126 
       
   127 		'S_MCP_ACTION'			=> $url . "&amp;i=$id&amp;forum_action=$action&amp;mode=$mode&amp;start=$start" . (($merge_select) ? $selected_ids : ''),
       
   128 
       
   129 		'PAGINATION'			=> generate_pagination($url . "&amp;i=$id&amp;action=$action&amp;mode=$mode&amp;sd=$sort_dir&amp;sk=$sort_key&amp;st=$sort_days" . (($merge_select) ? $selected_ids : ''), $forum_topics, $topics_per_page, $start),
       
   130 		'PAGE_NUMBER'			=> on_page($forum_topics, $topics_per_page, $start),
       
   131 		'TOTAL_TOPICS'			=> ($forum_topics == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $forum_topics),
       
   132 	));
       
   133 
       
   134 	// Grab icons
       
   135 	$icons = $cache->obtain_icons();
       
   136 
       
   137 	$topic_rows = array();
       
   138 
       
   139 	if ($config['load_db_lastread'])
       
   140 	{
       
   141 		$read_tracking_join = ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . ')';
       
   142 		$read_tracking_select = ', tt.mark_time';
       
   143 	}
       
   144 	else
       
   145 	{
       
   146 		$read_tracking_join = $read_tracking_select = '';
       
   147 	}
       
   148 
       
   149 	$sql = "SELECT t.topic_id
       
   150 		FROM " . TOPICS_TABLE . " t
       
   151 		WHERE t.forum_id IN($forum_id, 0)
       
   152 			" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1') . "
       
   153 			$limit_time_sql
       
   154 		ORDER BY t.topic_type DESC, $sort_order_sql";
       
   155 	$result = $db->sql_query_limit($sql, $topics_per_page, $start);
       
   156 
       
   157 	$topic_list = $topic_tracking_info = array();
       
   158 
       
   159 	while ($row = $db->sql_fetchrow($result))
       
   160 	{
       
   161 		$topic_list[] = $row['topic_id'];
       
   162 	}
       
   163 	$db->sql_freeresult($result);
       
   164 
       
   165 	$sql = "SELECT t.*$read_tracking_select
       
   166 		FROM " . TOPICS_TABLE . " t $read_tracking_join
       
   167 		WHERE " . $db->sql_in_set('t.topic_id', $topic_list, false, true);
       
   168 
       
   169 	$result = $db->sql_query($sql);
       
   170 	while ($row = $db->sql_fetchrow($result))
       
   171 	{
       
   172 		$topic_rows[$row['topic_id']] = $row;
       
   173 	}
       
   174 	$db->sql_freeresult($result);
       
   175 
       
   176 	// If there is more than one page, but we have no topic list, then the start parameter is... erm... out of sync
       
   177 	if (!sizeof($topic_list) && $forum_topics && $start > 0)
       
   178 	{
       
   179 		redirect($url . "&amp;i=$id&amp;action=$action&amp;mode=$mode");
       
   180 	}
       
   181 
       
   182 	// Get topic tracking info
       
   183 	if (sizeof($topic_list))
       
   184 	{
       
   185 		if ($config['load_db_lastread'])
       
   186 		{
       
   187 			$topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $topic_rows, array($forum_id => $forum_info['mark_time']), array());
       
   188 		}
       
   189 		else
       
   190 		{
       
   191 			$topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, array());
       
   192 		}
       
   193 	}
       
   194 
       
   195 	foreach ($topic_list as $topic_id)
       
   196 	{
       
   197 		$topic_title = '';
       
   198 
       
   199 		$row = &$topic_rows[$topic_id];
       
   200 
       
   201 		$replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
       
   202 
       
   203 		if ($row['topic_status'] == ITEM_MOVED)
       
   204 		{
       
   205 			$unread_topic = false;
       
   206 		}
       
   207 		else
       
   208 		{
       
   209 			$unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
       
   210 		}
       
   211 
       
   212 		// Get folder img, topic status/type related information
       
   213 		$folder_img = $folder_alt = $topic_type = '';
       
   214 		topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
       
   215 
       
   216 		$topic_title = censor_text($row['topic_title']);
       
   217 
       
   218 		$topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false;
       
   219 		$posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false;
       
   220 		$u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? $url . '&amp;i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . '&amp;t=' . $row['topic_id'] : '';
       
   221 
       
   222 		$topic_row = array(
       
   223 			'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']) : '',
       
   224 			'TOPIC_FOLDER_IMG'		=> $user->img($folder_img, $folder_alt),
       
   225 			'TOPIC_FOLDER_IMG_SRC'	=> $user->img($folder_img, $folder_alt, false, '', 'src'),
       
   226 			'TOPIC_ICON_IMG'		=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
       
   227 			'TOPIC_ICON_IMG_WIDTH'	=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
       
   228 			'TOPIC_ICON_IMG_HEIGHT'	=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
       
   229 			'UNAPPROVED_IMG'		=> ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
       
   230 
       
   231 			'TOPIC_AUTHOR'				=> get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
       
   232 			'TOPIC_AUTHOR_COLOUR'		=> get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
       
   233 			'TOPIC_AUTHOR_FULL'			=> get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
       
   234 			'U_TOPIC_AUTHOR'			=> get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
       
   235 
       
   236 			'LAST_POST_AUTHOR'			=> get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
       
   237 			'LAST_POST_AUTHOR_COLOUR'	=> get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
       
   238 			'LAST_POST_AUTHOR_FULL'		=> get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
       
   239 			'U_LAST_POST_AUTHOR'		=> get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
       
   240 
       
   241 			'TOPIC_TYPE'		=> $topic_type,
       
   242 			'TOPIC_TITLE'		=> $topic_title,
       
   243 			'REPLIES'			=> ($auth->acl_get('m_approve', $row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies'],
       
   244 			'LAST_POST_TIME'	=> $user->format_date($row['topic_last_post_time']),
       
   245 			'FIRST_POST_TIME'	=> $user->format_date($row['topic_time']),
       
   246 			'LAST_POST_SUBJECT'	=> $row['topic_last_post_subject'],
       
   247 			'LAST_VIEW_TIME'	=> $user->format_date($row['topic_last_view_time']),
       
   248 
       
   249 			'S_TOPIC_REPORTED'		=> (!empty($row['topic_reported']) && empty($row['topic_moved_id']) && $auth->acl_get('m_report', $row['forum_id'])) ? true : false,
       
   250 			'S_TOPIC_UNAPPROVED'	=> $topic_unapproved,
       
   251 			'S_POSTS_UNAPPROVED'	=> $posts_unapproved,
       
   252 			'S_UNREAD_TOPIC'		=> $unread_topic,
       
   253 		);
       
   254 
       
   255 		if ($row['topic_status'] == ITEM_MOVED)
       
   256 		{
       
   257 			$topic_row = array_merge($topic_row, array(
       
   258 				'U_VIEW_TOPIC'		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_moved_id']}"),
       
   259 				'U_DELETE_TOPIC'	=> ($auth->acl_get('m_delete', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;f=$forum_id&amp;topic_id_list[]={$row['topic_id']}&amp;mode=forum_view&amp;action=delete_topic") : '',
       
   260 				'S_MOVED_TOPIC'		=> true,
       
   261 				'TOPIC_ID'			=> $row['topic_moved_id'],
       
   262 			));
       
   263 		}
       
   264 		else
       
   265 		{
       
   266 			if ($action == 'merge_topic' || $action == 'merge_topics')
       
   267 			{
       
   268 				$u_select_topic = $url . "&amp;i=$id&amp;mode=forum_view&amp;action=$action&amp;to_topic_id=" . $row['topic_id'] . $selected_ids;
       
   269 			}
       
   270 			else
       
   271 			{
       
   272 				$u_select_topic = $url . "&amp;i=$id&amp;mode=topic_view&amp;action=merge&amp;to_topic_id=" . $row['topic_id'] . $selected_ids;
       
   273 			}
       
   274 			$topic_row = array_merge($topic_row, array(
       
   275 				'U_VIEW_TOPIC'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;f=$forum_id&amp;t={$row['topic_id']}&amp;mode=topic_view"),
       
   276 
       
   277 				'S_SELECT_TOPIC'	=> ($merge_select && !in_array($row['topic_id'], $source_topic_ids)) ? true : false,
       
   278 				'U_SELECT_TOPIC'	=> $u_select_topic,
       
   279 				'U_MCP_QUEUE'		=> $u_mcp_queue,
       
   280 				'U_MCP_REPORT'		=> ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=topic_view&amp;t=' . $row['topic_id'] . '&amp;action=reports') : '',
       
   281 				'TOPIC_ID'			=> $row['topic_id'],
       
   282 				'S_TOPIC_CHECKED'	=> ($topic_id_list && in_array($row['topic_id'], $topic_id_list)) ? true : false,
       
   283 			));
       
   284 		}
       
   285 
       
   286 		$template->assign_block_vars('topicrow', $topic_row);
       
   287 	}
       
   288 	unset($topic_rows);
       
   289 }
       
   290 
       
   291 /**
       
   292 * Resync topics
       
   293 */
       
   294 function mcp_resync_topics($topic_ids)
       
   295 {
       
   296 	global $auth, $db, $template, $phpEx, $user, $phpbb_root_path;
       
   297 
       
   298 	if (!sizeof($topic_ids))
       
   299 	{
       
   300 		trigger_error('NO_TOPIC_SELECTED');
       
   301 	}
       
   302 
       
   303 	if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_')))
       
   304 	{
       
   305 		return;
       
   306 	}
       
   307 
       
   308 	// Sync everything and perform extra checks separately
       
   309 	sync('topic_reported', 'topic_id', $topic_ids, false, true);
       
   310 	sync('topic_attachment', 'topic_id', $topic_ids, false, true);
       
   311 	sync('topic', 'topic_id', $topic_ids, true, false);
       
   312 
       
   313 	$sql = 'SELECT topic_id, forum_id, topic_title
       
   314 		FROM ' . TOPICS_TABLE . '
       
   315 		WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
       
   316 	$result = $db->sql_query($sql);
       
   317 
       
   318 	// Log this action
       
   319 	while ($row = $db->sql_fetchrow($result))
       
   320 	{
       
   321 		add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_TOPIC_RESYNC', $row['topic_title']);
       
   322 	}
       
   323 	$db->sql_freeresult($result);
       
   324 
       
   325 	$msg = (sizeof($topic_ids) == 1) ? $user->lang['TOPIC_RESYNC_SUCCESS'] : $user->lang['TOPICS_RESYNC_SUCCESS'];
       
   326 
       
   327 	$redirect = request_var('redirect', $user->data['session_page']);
       
   328 
       
   329 	meta_refresh(3, $redirect);
       
   330 	trigger_error($msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
       
   331 
       
   332 	return;
       
   333 }
       
   334 
       
   335 /**
       
   336 * Merge selected topics into selected topic
       
   337 */
       
   338 function merge_topics($forum_id, $topic_ids, $to_topic_id)
       
   339 {
       
   340 	global $db, $template, $user, $phpEx, $phpbb_root_path, $auth;
       
   341 
       
   342 	if (!sizeof($topic_ids))
       
   343 	{
       
   344 		$template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']);
       
   345 		return;
       
   346 	}
       
   347 	if (!$to_topic_id)
       
   348 	{
       
   349 		$template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
       
   350 		return;
       
   351 	}
       
   352 
       
   353 	$topic_data = get_topic_data(array($to_topic_id), 'm_merge');
       
   354 
       
   355 	if (!sizeof($topic_data))
       
   356 	{
       
   357 		$template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
       
   358 		return;
       
   359 	}
       
   360 
       
   361 	$topic_data = $topic_data[$to_topic_id];
       
   362 
       
   363 	$post_id_list	= request_var('post_id_list', array(0));
       
   364 	$start			= request_var('start', 0);
       
   365 
       
   366 	if (!sizeof($post_id_list) && sizeof($topic_ids))
       
   367 	{
       
   368 		$sql = 'SELECT post_id
       
   369 			FROM ' . POSTS_TABLE . '
       
   370 			WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
       
   371 		$result = $db->sql_query($sql);
       
   372 
       
   373 		$post_id_list = array();
       
   374 		while ($row = $db->sql_fetchrow($result))
       
   375 		{
       
   376 			$post_id_list[] = $row['post_id'];
       
   377 		}
       
   378 		$db->sql_freeresult($result);
       
   379 	}
       
   380 
       
   381 	if (!sizeof($post_id_list))
       
   382 	{
       
   383 		$template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
       
   384 		return;
       
   385 	}
       
   386 
       
   387 	if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_merge')))
       
   388 	{
       
   389 		return;
       
   390 	}
       
   391 
       
   392 	$redirect = request_var('redirect', build_url(array('quickmod')));
       
   393 
       
   394 	$s_hidden_fields = build_hidden_fields(array(
       
   395 		'i'				=> 'main',
       
   396 		'f'				=> $forum_id,
       
   397 		'post_id_list'	=> $post_id_list,
       
   398 		'to_topic_id'	=> $to_topic_id,
       
   399 		'mode'			=> 'forum_view',
       
   400 		'action'		=> 'merge_topics',
       
   401 		'start'			=> $start,
       
   402 		'redirect'		=> $redirect,
       
   403 		'topic_id_list'	=> $topic_ids)
       
   404 	);
       
   405 	$success_msg = $return_link = '';
       
   406 
       
   407 	if (confirm_box(true))
       
   408 	{
       
   409 		$to_forum_id = $topic_data['forum_id'];
       
   410 
       
   411 		move_posts($post_id_list, $to_topic_id);
       
   412 		add_log('mod', $to_forum_id, $to_topic_id, 'LOG_MERGE', $topic_data['topic_title']);
       
   413 
       
   414 		// Message and return links
       
   415 		$success_msg = 'POSTS_MERGED_SUCCESS';
       
   416 
       
   417 		// If the topic no longer exist, we will update the topic watch table.
       
   418 		// To not let it error out on users watching both topics, we just return on an error...
       
   419 		$db->sql_return_on_error(true);
       
   420 		$db->sql_query('UPDATE ' . TOPICS_WATCH_TABLE . ' SET topic_id = ' . (int) $to_topic_id . ' WHERE ' . $db->sql_in_set('topic_id', $topic_ids));
       
   421 		$db->sql_return_on_error(false);
       
   422 
       
   423 		$db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', $topic_ids));
       
   424 
       
   425 		// Link to the new topic
       
   426 		$return_link .= (($return_link) ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>');
       
   427 	}
       
   428 	else
       
   429 	{
       
   430 		confirm_box(false, 'MERGE_TOPICS', $s_hidden_fields);
       
   431 	}
       
   432 
       
   433 	$redirect = request_var('redirect', "index.$phpEx");
       
   434 	$redirect = reapply_sid($redirect);
       
   435 
       
   436 	if (!$success_msg)
       
   437 	{
       
   438 		return;
       
   439 	}
       
   440 	else
       
   441 	{
       
   442 		meta_refresh(3, append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&amp;t=$to_topic_id"));
       
   443 		trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
       
   444 	}
       
   445 }
       
   446 
       
   447 ?>