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

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package mcp
4c79b5
* @version $Id: mcp_topic.php 9030 2008-10-19 18:32:11Z 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
* View topic in MCP
4c79b5
*/
4c79b5
function mcp_topic_view($id, $mode, $action)
4c79b5
{
4c79b5
	global $phpEx, $phpbb_root_path, $config;
4c79b5
	global $template, $db, $user, $auth, $cache;
4c79b5
4c79b5
	$url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . extra_url());
4c79b5
4c79b5
	$user->add_lang('viewtopic');
4c79b5
4c79b5
	$topic_id = request_var('t', 0);
4c79b5
	$topic_info = get_topic_data(array($topic_id), false, true);
4c79b5
4c79b5
	if (!sizeof($topic_info))
4c79b5
	{
4c79b5
		trigger_error('TOPIC_NOT_EXIST');
4c79b5
	}
4c79b5
4c79b5
	$topic_info = $topic_info[$topic_id];
4c79b5
4c79b5
	// Set up some vars
4c79b5
	$icon_id		= request_var('icon', 0);
4c79b5
	$subject		= utf8_normalize_nfc(request_var('subject', '', true));
4c79b5
	$start			= request_var('start', 0);
4c79b5
	$sort_days_old	= request_var('st_old', 0);
4c79b5
	$forum_id		= request_var('f', 0);
4c79b5
	$to_topic_id	= request_var('to_topic_id', 0);
4c79b5
	$to_forum_id	= request_var('to_forum_id', 0);
4c79b5
	$sort			= isset($_POST['sort']) ? true : false;
4c79b5
	$submitted_id_list	= request_var('post_ids', array(0));
4c79b5
	$checked_ids = $post_id_list = request_var('post_id_list', array(0));
4c79b5
4c79b5
	// Split Topic?
4c79b5
	if ($action == 'split_all' || $action == 'split_beyond')
4c79b5
	{
4c79b5
		if (!$sort)
4c79b5
		{
4c79b5
			split_topic($action, $topic_id, $to_forum_id, $subject);
4c79b5
		}
4c79b5
		$action = 'split';
4c79b5
	}
4c79b5
4c79b5
	// Merge Posts?
4c79b5
	if ($action == 'merge_posts')
4c79b5
	{
4c79b5
		if (!$sort)
4c79b5
		{
4c79b5
			merge_posts($topic_id, $to_topic_id);
4c79b5
		}
4c79b5
		$action = 'merge';
4c79b5
	}
4c79b5
4c79b5
	if ($action == 'split' && !$subject)
4c79b5
	{
4c79b5
		$subject = $topic_info['topic_title'];
4c79b5
	}
4c79b5
4c79b5
	// Approve posts?
4c79b5
	if ($action == 'approve' && $auth->acl_get('m_approve', $topic_info['forum_id']))
4c79b5
	{
4c79b5
		include($phpbb_root_path . 'includes/mcp/mcp_queue.' . $phpEx);
4c79b5
		include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
4c79b5
		include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
4c79b5
4c79b5
		if (!sizeof($post_id_list))
4c79b5
		{
4c79b5
			trigger_error('NO_POST_SELECTED');
4c79b5
		}
4c79b5
4c79b5
		if (!$sort)
4c79b5
		{
4c79b5
			approve_post($post_id_list, $id, $mode);
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	// Jumpbox, sort selects and that kind of things
4c79b5
	make_jumpbox($url . "&i=$id&mode=forum_view", $topic_info['forum_id'], false, 'm_', true);
4c79b5
	$where_sql = ($action == 'reports') ? 'WHERE post_reported = 1 AND ' : 'WHERE';
4c79b5
4c79b5
	$sort_days = $total = 0;
4c79b5
	$sort_key = $sort_dir = '';
4c79b5
	$sort_by_sql = $sort_order_sql = array();
4c79b5
	mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $topic_info['forum_id'], $topic_id, $where_sql);
4c79b5
4c79b5
	$limit_time_sql = ($sort_days) ? 'AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
4c79b5
4c79b5
	if ($total == -1)
4c79b5
	{
4c79b5
		$total = $topic_info['topic_replies'] + 1;
4c79b5
	}
4c79b5
4c79b5
	$posts_per_page = max(0, request_var('posts_per_page', intval($config['posts_per_page'])));
4c79b5
	if ($posts_per_page == 0)
4c79b5
	{
4c79b5
		$posts_per_page = $total;
4c79b5
	}
4c79b5
4c79b5
	if ((!empty($sort_days_old) && $sort_days_old != $sort_days) || $total <= $posts_per_page)
4c79b5
	{
4c79b5
		$start = 0;
4c79b5
	}
4c79b5
4c79b5
	// Make sure $start is set to the last page if it exceeds the amount
4c79b5
	if ($start < 0 || $start >= $total)
4c79b5
	{
4c79b5
		$start = ($start < 0) ? 0 : floor(($total - 1) / $posts_per_page) * $posts_per_page;
4c79b5
	}
4c79b5
4c79b5
	$sql = 'SELECT u.username, u.username_clean, u.user_colour, p.*
4c79b5
		FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
4c79b5
		WHERE ' . (($action == 'reports') ? 'p.post_reported = 1 AND ' : '') . '
4c79b5
			p.topic_id = ' . $topic_id . ' ' .
4c79b5
			((!$auth->acl_get('m_approve', $topic_info['forum_id'])) ? ' AND p.post_approved = 1 ' : '') . '
4c79b5
			AND p.poster_id = u.user_id ' .
4c79b5
			$limit_time_sql . '
4c79b5
		ORDER BY ' . $sort_order_sql;
4c79b5
	$result = $db->sql_query_limit($sql, $posts_per_page, $start);
4c79b5
4c79b5
	$rowset = $post_id_list = array();
4c79b5
	$bbcode_bitfield = '';
4c79b5
	while ($row = $db->sql_fetchrow($result))
4c79b5
	{
4c79b5
		$rowset[] = $row;
4c79b5
		$post_id_list[] = $row['post_id'];
4c79b5
		$bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
4c79b5
	}
4c79b5
	$db->sql_freeresult($result);
4c79b5
4c79b5
	if ($bbcode_bitfield !== '')
4c79b5
	{
4c79b5
		include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
4c79b5
		$bbcode = new bbcode(base64_encode($bbcode_bitfield));
4c79b5
	}
4c79b5
4c79b5
	$topic_tracking_info = array();
4c79b5
4c79b5
	// Get topic tracking info
4c79b5
	if ($config['load_db_lastread'])
4c79b5
	{
4c79b5
		$tmp_topic_data = array($topic_id => $topic_info);
4c79b5
		$topic_tracking_info = get_topic_tracking($topic_info['forum_id'], $topic_id, $tmp_topic_data, array($topic_info['forum_id'] => $topic_info['forum_mark_time']));
4c79b5
		unset($tmp_topic_data);
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$topic_tracking_info = get_complete_topic_tracking($topic_info['forum_id'], $topic_id);
4c79b5
	}
4c79b5
4c79b5
	$has_unapproved_posts = false;
4c79b5
4c79b5
	// Grab extensions
4c79b5
	$extensions = $attachments = array();
4c79b5
	if ($topic_info['topic_attachment'] && sizeof($post_id_list))
4c79b5
	{
4c79b5
		$extensions = $cache->obtain_attach_extensions($topic_info['forum_id']);
4c79b5
4c79b5
		// Get attachments...
4c79b5
		if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $topic_info['forum_id']))
4c79b5
		{
4c79b5
			$sql = 'SELECT *
4c79b5
				FROM ' . ATTACHMENTS_TABLE . '
4c79b5
				WHERE ' . $db->sql_in_set('post_msg_id', $post_id_list) . '
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['post_msg_id']][] = $row;
4c79b5
			}
4c79b5
			$db->sql_freeresult($result);
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	foreach ($rowset as $i => $row)
4c79b5
	{
4c79b5
		$message = $row['post_text'];
4c79b5
		$post_subject = ($row['post_subject'] != '') ? $row['post_subject'] : $topic_info['topic_title'];
4c79b5
4c79b5
		if ($row['bbcode_bitfield'])
4c79b5
		{
4c79b5
			$bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
4c79b5
		}
4c79b5
4c79b5
		$message = bbcode_nl2br($message);
4c79b5
		$message = smiley_text($message);
4c79b5
4c79b5
		if (!empty($attachments[$row['post_id']]))
4c79b5
		{
4c79b5
			$update_count = array();
4c79b5
			parse_attachments($topic_info['forum_id'], $message, $attachments[$row['post_id']], $update_count);
4c79b5
		}
4c79b5
4c79b5
		if (!$row['post_approved'])
4c79b5
		{
4c79b5
			$has_unapproved_posts = true;
4c79b5
		}
4c79b5
4c79b5
		$post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
4c79b5
4c79b5
		$template->assign_block_vars('postrow', array(
4c79b5
			'POST_AUTHOR_FULL'		=> get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
4c79b5
			'POST_AUTHOR_COLOUR'	=> get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
4c79b5
			'POST_AUTHOR'			=> get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
4c79b5
			'U_POST_AUTHOR'			=> get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
4c79b5
4c79b5
			'POST_DATE'		=> $user->format_date($row['post_time']),
4c79b5
			'POST_SUBJECT'	=> $post_subject,
4c79b5
			'MESSAGE'		=> $message,
4c79b5
			'POST_ID'		=> $row['post_id'],
4c79b5
			'RETURN_TOPIC'	=> sprintf($user->lang['RETURN_TOPIC'], '', ''),
4c79b5
4c79b5
			'MINI_POST_IMG'			=> ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
4c79b5
4c79b5
			'S_POST_REPORTED'	=> ($row['post_reported']) ? true : false,
4c79b5
			'S_POST_UNAPPROVED'	=> ($row['post_approved']) ? false : true,
4c79b5
			'S_CHECKED'			=> (($submitted_id_list && !in_array(intval($row['post_id']), $submitted_id_list)) || in_array(intval($row['post_id']), $checked_ids)) ? true : false,
4c79b5
			'S_HAS_ATTACHMENTS'	=> (!empty($attachments[$row['post_id']])) ? true : false,
4c79b5
4c79b5
			'U_POST_DETAILS'	=> "$url&i=$id&p={$row['post_id']}&mode=post_details" . (($forum_id) ? "&f=$forum_id" : ''),
4c79b5
			'U_MCP_APPROVE'		=> ($auth->acl_get('m_approve', $topic_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $topic_info['forum_id'] . '&p=' . $row['post_id']) : '',
4c79b5
			'U_MCP_REPORT'		=> ($auth->acl_get('m_report', $topic_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $topic_info['forum_id'] . '&p=' . $row['post_id']) : '')
4c79b5
		);
4c79b5
4c79b5
		// Display not already displayed Attachments for this post, we already parsed them. ;)
4c79b5
		if (!empty($attachments[$row['post_id']]))
4c79b5
		{
4c79b5
			foreach ($attachments[$row['post_id']] as $attachment)
4c79b5
			{
4c79b5
				$template->assign_block_vars('postrow.attachment', array(
4c79b5
					'DISPLAY_ATTACHMENT'	=> $attachment)
4c79b5
				);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		unset($rowset[$i]);
4c79b5
	}
4c79b5
4c79b5
	// Display topic icons for split topic
4c79b5
	$s_topic_icons = false;
4c79b5
4c79b5
	if ($auth->acl_get('m_split', $topic_info['forum_id']))
4c79b5
	{
4c79b5
		include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
4c79b5
		$s_topic_icons = posting_gen_topic_icons('', $icon_id);
4c79b5
4c79b5
		// Has the user selected a topic for merge?
4c79b5
		if ($to_topic_id)
4c79b5
		{
4c79b5
			$to_topic_info = get_topic_data(array($to_topic_id), 'm_merge');
4c79b5
4c79b5
			if (!sizeof($to_topic_info))
4c79b5
			{
4c79b5
				$to_topic_id = 0;
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$to_topic_info = $to_topic_info[$to_topic_id];
4c79b5
4c79b5
				if (!$to_topic_info['enable_icons'] || $auth->acl_get('!f_icons', $topic_info['forum_id']))
4c79b5
				{
4c79b5
					$s_topic_icons = false;
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	$s_hidden_fields = build_hidden_fields(array(
4c79b5
		'st_old'	=> $sort_days,
4c79b5
		'post_ids'	=> $post_id_list,
4c79b5
	));
4c79b5
4c79b5
	$template->assign_vars(array(
4c79b5
		'TOPIC_TITLE'		=> $topic_info['topic_title'],
4c79b5
		'U_VIEW_TOPIC'		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_info['forum_id'] . '&t=' . $topic_info['topic_id']),
4c79b5
4c79b5
		'TO_TOPIC_ID'		=> $to_topic_id,
4c79b5
		'TO_TOPIC_INFO'		=> ($to_topic_id) ? sprintf($user->lang['YOU_SELECTED_TOPIC'], $to_topic_id, '' . $to_topic_info['topic_title'] . '') : '',
4c79b5
4c79b5
		'SPLIT_SUBJECT'		=> $subject,
4c79b5
		'POSTS_PER_PAGE'	=> $posts_per_page,
4c79b5
		'ACTION'			=> $action,
4c79b5
4c79b5
		'REPORTED_IMG'		=> $user->img('icon_topic_reported', 'POST_REPORTED', false, true),
4c79b5
		'UNAPPROVED_IMG'	=> $user->img('icon_topic_unapproved', 'POST_UNAPPROVED', false, true),
4c79b5
4c79b5
		'S_MCP_ACTION'		=> "$url&i=$id&mode=$mode&action=$action&start=$start",
4c79b5
		'S_FORUM_SELECT'	=> ($to_forum_id) ? make_forum_select($to_forum_id, false, false, true, true, true) : make_forum_select($topic_info['forum_id'], false, false, true, true, true),
4c79b5
		'S_CAN_SPLIT'		=> ($auth->acl_get('m_split', $topic_info['forum_id'])) ? true : false,
4c79b5
		'S_CAN_MERGE'		=> ($auth->acl_get('m_merge', $topic_info['forum_id'])) ? true : false,
4c79b5
		'S_CAN_DELETE'		=> ($auth->acl_get('m_delete', $topic_info['forum_id'])) ? true : false,
4c79b5
		'S_CAN_APPROVE'		=> ($has_unapproved_posts && $auth->acl_get('m_approve', $topic_info['forum_id'])) ? true : false,
4c79b5
		'S_CAN_LOCK'		=> ($auth->acl_get('m_lock', $topic_info['forum_id'])) ? true : false,
4c79b5
		'S_CAN_REPORT'		=> ($auth->acl_get('m_report', $topic_info['forum_id'])) ? true : false,
4c79b5
		'S_REPORT_VIEW'		=> ($action == 'reports') ? true : false,
4c79b5
		'S_MERGE_VIEW'		=> ($action == 'merge') ? true : false,
4c79b5
		'S_SPLIT_VIEW'		=> ($action == 'split') ? true : false,
4c79b5
4c79b5
		'S_HIDDEN_FIELDS'	=> $s_hidden_fields,
4c79b5
4c79b5
		'S_SHOW_TOPIC_ICONS'	=> $s_topic_icons,
4c79b5
		'S_TOPIC_ICON'			=> $icon_id,
4c79b5
4c79b5
		'U_SELECT_TOPIC'	=> "$url&i=$id&mode=forum_view&action=merge_select" . (($forum_id) ? "&f=$forum_id" : ''),
4c79b5
4c79b5
		'RETURN_TOPIC'		=> sprintf($user->lang['RETURN_TOPIC'], '', ''),
4c79b5
		'RETURN_FORUM'		=> sprintf($user->lang['RETURN_FORUM'], '', ''),
4c79b5
4c79b5
		'PAGE_NUMBER'		=> on_page($total, $posts_per_page, $start),
4c79b5
		'PAGINATION'		=> (!$posts_per_page) ? '' : generate_pagination(append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&t={$topic_info['topic_id']}&mode=$mode&action=$action&to_topic_id=$to_topic_id&posts_per_page=$posts_per_page&st=$sort_days&sk=$sort_key&sd=$sort_dir"), $total, $posts_per_page, $start),
4c79b5
		'TOTAL_POSTS'		=> ($total == 1) ? $user->lang['VIEW_TOPIC_POST'] : sprintf($user->lang['VIEW_TOPIC_POSTS'], $total),
4c79b5
	));
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* Split topic
4c79b5
*/
4c79b5
function split_topic($action, $topic_id, $to_forum_id, $subject)
4c79b5
{
4c79b5
	global $db, $template, $user, $phpEx, $phpbb_root_path, $auth, $config;
4c79b5
4c79b5
	$post_id_list	= request_var('post_id_list', array(0));
4c79b5
	$forum_id		= request_var('forum_id', 0);
4c79b5
	$start			= request_var('start', 0);
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_split')))
4c79b5
	{
4c79b5
		return;
4c79b5
	}
4c79b5
4c79b5
	$post_id = $post_id_list[0];
4c79b5
	$post_info = get_post_data(array($post_id));
4c79b5
4c79b5
	if (!sizeof($post_info))
4c79b5
	{
4c79b5
		$template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
4c79b5
		return;
4c79b5
	}
4c79b5
4c79b5
	$post_info = $post_info[$post_id];
4c79b5
	$subject = trim($subject);
4c79b5
4c79b5
	// Make some tests
4c79b5
	if (!$subject)
4c79b5
	{
4c79b5
		$template->assign_var('MESSAGE', $user->lang['EMPTY_SUBJECT']);
4c79b5
		return;
4c79b5
	}
4c79b5
4c79b5
	if ($to_forum_id <= 0)
4c79b5
	{
4c79b5
		$template->assign_var('MESSAGE', $user->lang['NO_DESTINATION_FORUM']);
4c79b5
		return;
4c79b5
	}
4c79b5
4c79b5
	$forum_info = get_forum_data(array($to_forum_id), 'f_post');
4c79b5
4c79b5
	if (!sizeof($forum_info))
4c79b5
	{
4c79b5
		$template->assign_var('MESSAGE', $user->lang['USER_CANNOT_POST']);
4c79b5
		return;
4c79b5
	}
4c79b5
4c79b5
	$forum_info = $forum_info[$to_forum_id];
4c79b5
4c79b5
	if ($forum_info['forum_type'] != FORUM_POST)
4c79b5
	{
4c79b5
		$template->assign_var('MESSAGE', $user->lang['FORUM_NOT_POSTABLE']);
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
		'post_id_list'	=> $post_id_list,
4c79b5
		'f'				=> $forum_id,
4c79b5
		'mode'			=> 'topic_view',
4c79b5
		'start'			=> $start,
4c79b5
		'action'		=> $action,
4c79b5
		't'				=> $topic_id,
4c79b5
		'redirect'		=> $redirect,
4c79b5
		'subject'		=> $subject,
4c79b5
		'to_forum_id'	=> $to_forum_id,
4c79b5
		'icon'			=> request_var('icon', 0))
4c79b5
	);
4c79b5
	$success_msg = $return_link = '';
4c79b5
4c79b5
	if (confirm_box(true))
4c79b5
	{
4c79b5
		if ($action == 'split_beyond')
4c79b5
		{
4c79b5
			$sort_days = $total = 0;
4c79b5
			$sort_key = $sort_dir = '';
4c79b5
			$sort_by_sql = $sort_order_sql = array();
4c79b5
			mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
4c79b5
4c79b5
			$limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
4c79b5
4c79b5
			if ($sort_order_sql[0] == 'u')
4c79b5
			{
4c79b5
				$sql = 'SELECT p.post_id, p.forum_id, p.post_approved
4c79b5
					FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
4c79b5
					WHERE p.topic_id = $topic_id
4c79b5
						AND p.poster_id = u.user_id
4c79b5
						$limit_time_sql
4c79b5
					ORDER BY $sort_order_sql";
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$sql = 'SELECT p.post_id, p.forum_id, p.post_approved
4c79b5
					FROM ' . POSTS_TABLE . " p
4c79b5
					WHERE p.topic_id = $topic_id
4c79b5
						$limit_time_sql
4c79b5
					ORDER BY $sort_order_sql";
4c79b5
			}
4c79b5
			$result = $db->sql_query_limit($sql, 0, $start);
4c79b5
4c79b5
			$store = false;
4c79b5
			$post_id_list = array();
4c79b5
			while ($row = $db->sql_fetchrow($result))
4c79b5
			{
4c79b5
				// If split from selected post (split_beyond), we split the unapproved items too.
4c79b5
				if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id']))
4c79b5
				{
4c79b5
//					continue;
4c79b5
				}
4c79b5
4c79b5
				// Start to store post_ids as soon as we see the first post that was selected
4c79b5
				if ($row['post_id'] == $post_id)
4c79b5
				{
4c79b5
					$store = true;
4c79b5
				}
4c79b5
4c79b5
				if ($store)
4c79b5
				{
4c79b5
					$post_id_list[] = $row['post_id'];
4c79b5
				}
4c79b5
			}
4c79b5
			$db->sql_freeresult($result);
4c79b5
		}
4c79b5
4c79b5
		if (!sizeof($post_id_list))
4c79b5
		{
4c79b5
			trigger_error('NO_POST_SELECTED');
4c79b5
		}
4c79b5
4c79b5
		$icon_id = request_var('icon', 0);
4c79b5
4c79b5
		$sql_ary = array(
4c79b5
			'forum_id'		=> $to_forum_id,
4c79b5
			'topic_title'	=> $subject,
4c79b5
			'icon_id'		=> $icon_id,
4c79b5
			'topic_approved'=> 1
4c79b5
		);
4c79b5
4c79b5
		$sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
4c79b5
		$db->sql_query($sql);
4c79b5
4c79b5
		$to_topic_id = $db->sql_nextid();
4c79b5
		move_posts($post_id_list, $to_topic_id);
4c79b5
4c79b5
		$topic_info = get_topic_data(array($topic_id));
4c79b5
		$topic_info = $topic_info[$topic_id];
4c79b5
4c79b5
		add_log('mod', $to_forum_id, $to_topic_id, 'LOG_SPLIT_DESTINATION', $subject);
4c79b5
		add_log('mod', $forum_id, $topic_id, 'LOG_SPLIT_SOURCE', $topic_info['topic_title']);
4c79b5
4c79b5
		// Change topic title of first post
4c79b5
		$sql = 'UPDATE ' . POSTS_TABLE . "
4c79b5
			SET post_subject = '" . $db->sql_escape($subject) . "'
4c79b5
			WHERE post_id = {$post_id_list[0]}";
4c79b5
		$db->sql_query($sql);
4c79b5
4c79b5
		$success_msg = 'TOPIC_SPLIT_SUCCESS';
4c79b5
4c79b5
		// Update forum statistics
4c79b5
		set_config('num_topics', $config['num_topics'] + 1, true);
4c79b5
4c79b5
		// Link back to both topics
4c79b5
		$return_link = sprintf($user->lang['RETURN_TOPIC'], '', '') . '

' . sprintf($user->lang['RETURN_NEW_TOPIC'], '', '');
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		confirm_box(false, ($action == 'split_all') ? 'SPLIT_TOPIC_ALL' : 'SPLIT_TOPIC_BEYOND', $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
/**
4c79b5
* Merge selected posts into selected topic
4c79b5
*/
4c79b5
function merge_posts($topic_id, $to_topic_id)
4c79b5
{
4c79b5
	global $db, $template, $user, $phpEx, $phpbb_root_path, $auth;
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))
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
		'post_id_list'	=> $post_id_list,
4c79b5
		'to_topic_id'	=> $to_topic_id,
4c79b5
		'mode'			=> 'topic_view',
4c79b5
		'action'		=> 'merge_posts',
4c79b5
		'start'			=> $start,
4c79b5
		'redirect'		=> $redirect,
4c79b5
		't'				=> $topic_id)
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
		// Does the original topic still exist? If yes, link back to it
4c79b5
		$sql = 'SELECT forum_id
4c79b5
			FROM ' . TOPICS_TABLE . '
4c79b5
			WHERE topic_id = ' . $topic_id;
4c79b5
		$result = $db->sql_query_limit($sql, 1);
4c79b5
		$row = $db->sql_fetchrow($result);
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		if ($row)
4c79b5
		{
4c79b5
			$return_link .= sprintf($user->lang['RETURN_TOPIC'], '', '');
4c79b5
		}
4c79b5
		else
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 topic_id = ' . (int) $topic_id);
4c79b5
			$db->sql_return_on_error(false);
4c79b5
4c79b5
			$db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . (int) $topic_id);
4c79b5
		}
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_POSTS', $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
?>