Blame Identity/Models/Html/phpBB/3.0.4/includes/mcp/mcp_topic.php

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

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

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

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

' . $return_link);
d6e8d8
	}
d6e8d8
}
d6e8d8
d6e8d8
?>