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

d6e8d8
d6e8d8
/**
d6e8d8
*
d6e8d8
* @package mcp
d6e8d8
* @version $Id: mcp_main.php 8950 2008-09-27 10:59:25Z toonarmy $
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
* mcp_main
d6e8d8
* Handling mcp actions
d6e8d8
* @package mcp
d6e8d8
*/
d6e8d8
class mcp_main
d6e8d8
{
d6e8d8
	var $p_master;
d6e8d8
	var $u_action;
d6e8d8
d6e8d8
	function mcp_main(&$p_master)
d6e8d8
	{
d6e8d8
		$this->p_master = &$p_master;
d6e8d8
	}
d6e8d8
d6e8d8
	function main($id, $mode)
d6e8d8
	{
d6e8d8
		global $auth, $db, $user, $template, $action;
d6e8d8
		global $config, $phpbb_root_path, $phpEx;
d6e8d8
d6e8d8
		$quickmod = ($mode == 'quickmod') ? true : false;
d6e8d8
d6e8d8
		switch ($action)
d6e8d8
		{
d6e8d8
			case 'lock':
d6e8d8
			case 'unlock':
d6e8d8
				$topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
d6e8d8
d6e8d8
				if (!sizeof($topic_ids))
d6e8d8
				{
d6e8d8
					trigger_error('NO_TOPIC_SELECTED');
d6e8d8
				}
d6e8d8
d6e8d8
				lock_unlock($action, $topic_ids);
d6e8d8
			break;
d6e8d8
d6e8d8
			case 'lock_post':
d6e8d8
			case 'unlock_post':
d6e8d8
d6e8d8
				$post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
d6e8d8
d6e8d8
				if (!sizeof($post_ids))
d6e8d8
				{
d6e8d8
					trigger_error('NO_POST_SELECTED');
d6e8d8
				}
d6e8d8
d6e8d8
				lock_unlock($action, $post_ids);
d6e8d8
			break;
d6e8d8
d6e8d8
			case 'make_announce':
d6e8d8
			case 'make_sticky':
d6e8d8
			case 'make_global':
d6e8d8
			case 'make_normal':
d6e8d8
d6e8d8
				$topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
d6e8d8
d6e8d8
				if (!sizeof($topic_ids))
d6e8d8
				{
d6e8d8
					trigger_error('NO_TOPIC_SELECTED');
d6e8d8
				}
d6e8d8
d6e8d8
				change_topic_type($action, $topic_ids);
d6e8d8
			break;
d6e8d8
d6e8d8
			case 'move':
d6e8d8
				$user->add_lang('viewtopic');
d6e8d8
d6e8d8
				$topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
d6e8d8
d6e8d8
				if (!sizeof($topic_ids))
d6e8d8
				{
d6e8d8
					trigger_error('NO_TOPIC_SELECTED');
d6e8d8
				}
d6e8d8
d6e8d8
				mcp_move_topic($topic_ids);
d6e8d8
			break;
d6e8d8
d6e8d8
			case 'fork':
d6e8d8
				$user->add_lang('viewtopic');
d6e8d8
d6e8d8
				$topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
d6e8d8
d6e8d8
				if (!sizeof($topic_ids))
d6e8d8
				{
d6e8d8
					trigger_error('NO_TOPIC_SELECTED');
d6e8d8
				}
d6e8d8
d6e8d8
				mcp_fork_topic($topic_ids);
d6e8d8
			break;
d6e8d8
d6e8d8
			case 'delete_topic':
d6e8d8
				$user->add_lang('viewtopic');
d6e8d8
d6e8d8
				$topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
d6e8d8
d6e8d8
				if (!sizeof($topic_ids))
d6e8d8
				{
d6e8d8
					trigger_error('NO_TOPIC_SELECTED');
d6e8d8
				}
d6e8d8
d6e8d8
				mcp_delete_topic($topic_ids);
d6e8d8
			break;
d6e8d8
d6e8d8
			case 'delete_post':
d6e8d8
				$user->add_lang('posting');
d6e8d8
d6e8d8
				$post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
d6e8d8
d6e8d8
				if (!sizeof($post_ids))
d6e8d8
				{
d6e8d8
					trigger_error('NO_POST_SELECTED');
d6e8d8
				}
d6e8d8
d6e8d8
				mcp_delete_post($post_ids);
d6e8d8
			break;
d6e8d8
		}
d6e8d8
d6e8d8
		switch ($mode)
d6e8d8
		{
d6e8d8
			case 'front':
d6e8d8
				include($phpbb_root_path . 'includes/mcp/mcp_front.' . $phpEx);
d6e8d8
d6e8d8
				$user->add_lang('acp/common');
d6e8d8
d6e8d8
				mcp_front_view($id, $mode, $action);
d6e8d8
d6e8d8
				$this->tpl_name = 'mcp_front';
d6e8d8
				$this->page_title = 'MCP_MAIN';
d6e8d8
			break;
d6e8d8
d6e8d8
			case 'forum_view':
d6e8d8
				include($phpbb_root_path . 'includes/mcp/mcp_forum.' . $phpEx);
d6e8d8
d6e8d8
				$user->add_lang('viewforum');
d6e8d8
d6e8d8
				$forum_id = request_var('f', 0);
d6e8d8
d6e8d8
				$forum_info = get_forum_data($forum_id, 'm_', true);
d6e8d8
d6e8d8
				if (!sizeof($forum_info))
d6e8d8
				{
d6e8d8
					$this->main('main', 'front');
d6e8d8
					return;
d6e8d8
				}
d6e8d8
d6e8d8
				$forum_info = $forum_info[$forum_id];
d6e8d8
d6e8d8
				mcp_forum_view($id, $mode, $action, $forum_info);
d6e8d8
d6e8d8
				$this->tpl_name = 'mcp_forum';
d6e8d8
				$this->page_title = 'MCP_MAIN_FORUM_VIEW';
d6e8d8
			break;
d6e8d8
d6e8d8
			case 'topic_view':
d6e8d8
				include($phpbb_root_path . 'includes/mcp/mcp_topic.' . $phpEx);
d6e8d8
d6e8d8
				mcp_topic_view($id, $mode, $action);
d6e8d8
d6e8d8
				$this->tpl_name = 'mcp_topic';
d6e8d8
				$this->page_title = 'MCP_MAIN_TOPIC_VIEW';
d6e8d8
			break;
d6e8d8
d6e8d8
			case 'post_details':
d6e8d8
				include($phpbb_root_path . 'includes/mcp/mcp_post.' . $phpEx);
d6e8d8
d6e8d8
				mcp_post_details($id, $mode, $action);
d6e8d8
d6e8d8
				$this->tpl_name = ($action == 'whois') ? 'mcp_whois' : 'mcp_post';
d6e8d8
				$this->page_title = 'MCP_MAIN_POST_DETAILS';
d6e8d8
			break;
d6e8d8
d6e8d8
			default:
d6e8d8
				trigger_error('NO_MODE', E_USER_ERROR);
d6e8d8
			break;
d6e8d8
		}
d6e8d8
	}
d6e8d8
}
d6e8d8
d6e8d8
/**
d6e8d8
* Lock/Unlock Topic/Post
d6e8d8
*/
d6e8d8
function lock_unlock($action, $ids)
d6e8d8
{
d6e8d8
	global $auth, $user, $db, $phpEx, $phpbb_root_path;
d6e8d8
d6e8d8
	if ($action == 'lock' || $action == 'unlock')
d6e8d8
	{
d6e8d8
		$table = TOPICS_TABLE;
d6e8d8
		$sql_id = 'topic_id';
d6e8d8
		$set_id = 'topic_status';
d6e8d8
		$l_prefix = 'TOPIC';
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		$table = POSTS_TABLE;
d6e8d8
		$sql_id = 'post_id';
d6e8d8
		$set_id = 'post_edit_locked';
d6e8d8
		$l_prefix = 'POST';
d6e8d8
	}
d6e8d8
d6e8d8
	$orig_ids = $ids;
d6e8d8
d6e8d8
	if (!check_ids($ids, $table, $sql_id, array('m_lock')))
d6e8d8
	{
d6e8d8
		// Make sure that for f_user_lock only the lock action is triggered.
d6e8d8
		if ($action != 'lock')
d6e8d8
		{
d6e8d8
			return;
d6e8d8
		}
d6e8d8
d6e8d8
		$ids = $orig_ids;
d6e8d8
d6e8d8
		if (!check_ids($ids, $table, $sql_id, array('f_user_lock')))
d6e8d8
		{
d6e8d8
			return;
d6e8d8
		}
d6e8d8
	}
d6e8d8
	unset($orig_ids);
d6e8d8
d6e8d8
	$redirect = request_var('redirect', build_url(array('action', 'quickmod')));
d6e8d8
d6e8d8
	$s_hidden_fields = build_hidden_fields(array(
d6e8d8
		$sql_id . '_list'	=> $ids,
d6e8d8
		'action'			=> $action,
d6e8d8
		'redirect'			=> $redirect)
d6e8d8
	);
d6e8d8
	$success_msg = '';
d6e8d8
d6e8d8
	if (confirm_box(true))
d6e8d8
	{
d6e8d8
		$sql = "UPDATE $table
d6e8d8
			SET $set_id = " . (($action == 'lock' || $action == 'lock_post') ? ITEM_LOCKED : ITEM_UNLOCKED) . '
d6e8d8
			WHERE ' . $db->sql_in_set($sql_id, $ids);
d6e8d8
		$db->sql_query($sql);
d6e8d8
d6e8d8
		$data = ($action == 'lock' || $action == 'unlock') ? get_topic_data($ids) : get_post_data($ids);
d6e8d8
d6e8d8
		foreach ($data as $id => $row)
d6e8d8
		{
d6e8d8
			add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_' . strtoupper($action), $row['topic_title']);
d6e8d8
		}
d6e8d8
d6e8d8
		$success_msg = $l_prefix . ((sizeof($ids) == 1) ? '' : 'S') . '_' . (($action == 'lock' || $action == 'lock_post') ? 'LOCKED' : 'UNLOCKED') . '_SUCCESS';
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		confirm_box(false, strtoupper($action) . '_' . $l_prefix . ((sizeof($ids) == 1) ? '' : 'S'), $s_hidden_fields);
d6e8d8
	}
d6e8d8
d6e8d8
	$redirect = request_var('redirect', "index.$phpEx");
d6e8d8
	$redirect = reapply_sid($redirect);
d6e8d8
d6e8d8
	if (!$success_msg)
d6e8d8
	{
d6e8d8
		redirect($redirect);
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		meta_refresh(2, $redirect);
d6e8d8
		trigger_error($user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], '', ''));
d6e8d8
	}
d6e8d8
}
d6e8d8
d6e8d8
/**
d6e8d8
* Change Topic Type
d6e8d8
*/
d6e8d8
function change_topic_type($action, $topic_ids)
d6e8d8
{
d6e8d8
	global $auth, $user, $db, $phpEx, $phpbb_root_path;
d6e8d8
d6e8d8
	// For changing topic types, we only allow operations in one forum.
d6e8d8
	$forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('f_announce', 'f_sticky', 'm_'), true);
d6e8d8
d6e8d8
	if ($forum_id === false)
d6e8d8
	{
d6e8d8
		return;
d6e8d8
	}
d6e8d8
d6e8d8
	switch ($action)
d6e8d8
	{
d6e8d8
		case 'make_announce':
d6e8d8
			$new_topic_type = POST_ANNOUNCE;
d6e8d8
			$check_acl = 'f_announce';
d6e8d8
			$l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_ANNOUNCEMENT' : 'MCP_MAKE_ANNOUNCEMENTS';
d6e8d8
		break;
d6e8d8
d6e8d8
		case 'make_global':
d6e8d8
			$new_topic_type = POST_GLOBAL;
d6e8d8
			$check_acl = 'f_announce';
d6e8d8
			$l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_GLOBAL' : 'MCP_MAKE_GLOBALS';
d6e8d8
		break;
d6e8d8
d6e8d8
		case 'make_sticky':
d6e8d8
			$new_topic_type = POST_STICKY;
d6e8d8
			$check_acl = 'f_sticky';
d6e8d8
			$l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_STICKY' : 'MCP_MAKE_STICKIES';
d6e8d8
		break;
d6e8d8
d6e8d8
		default:
d6e8d8
			$new_topic_type = POST_NORMAL;
d6e8d8
			$check_acl = '';
d6e8d8
			$l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_NORMAL' : 'MCP_MAKE_NORMALS';
d6e8d8
		break;
d6e8d8
	}
d6e8d8
d6e8d8
	$redirect = request_var('redirect', build_url(array('action', 'quickmod')));
d6e8d8
d6e8d8
	$s_hidden_fields = array(
d6e8d8
		'topic_id_list'	=> $topic_ids,
d6e8d8
		'f'				=> $forum_id,
d6e8d8
		'action'		=> $action,
d6e8d8
		'redirect'		=> $redirect,
d6e8d8
	);
d6e8d8
	$success_msg = '';
d6e8d8
d6e8d8
	if (confirm_box(true))
d6e8d8
	{
d6e8d8
		if ($new_topic_type != POST_GLOBAL)
d6e8d8
		{
d6e8d8
			$sql = 'UPDATE ' . TOPICS_TABLE . "
d6e8d8
				SET topic_type = $new_topic_type
d6e8d8
				WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
d6e8d8
					AND forum_id <> 0';
d6e8d8
			$db->sql_query($sql);
d6e8d8
d6e8d8
			// Reset forum id if a global topic is within the array
d6e8d8
			$to_forum_id = request_var('to_forum_id', 0);
d6e8d8
d6e8d8
			if ($to_forum_id)
d6e8d8
			{
d6e8d8
				$sql = 'UPDATE ' . TOPICS_TABLE . "
d6e8d8
					SET topic_type = $new_topic_type, forum_id = $to_forum_id
d6e8d8
					WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
d6e8d8
						AND forum_id = 0';
d6e8d8
				$db->sql_query($sql);
d6e8d8
d6e8d8
				// Update forum_ids for all posts
d6e8d8
				$sql = 'UPDATE ' . POSTS_TABLE . "
d6e8d8
					SET forum_id = $to_forum_id
d6e8d8
					WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
d6e8d8
						AND forum_id = 0';
d6e8d8
				$db->sql_query($sql);
d6e8d8
d6e8d8
				// Do a little forum sync stuff
d6e8d8
				$sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
d6e8d8
					FROM ' . TOPICS_TABLE . ' t
d6e8d8
					WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
d6e8d8
				$result = $db->sql_query($sql);
d6e8d8
				$row_data = $db->sql_fetchrow($result);
d6e8d8
				$db->sql_freeresult($result);
d6e8d8
d6e8d8
				$sync_sql = array();
d6e8d8
d6e8d8
				if ($row_data['topic_posts'])
d6e8d8
				{
d6e8d8
					$sync_sql[$to_forum_id][]	= 'forum_posts = forum_posts + ' . (int) $row_data['topic_posts'];
d6e8d8
				}
d6e8d8
d6e8d8
				if ($row_data['topics_authed'])
d6e8d8
				{
d6e8d8
					$sync_sql[$to_forum_id][]	= 'forum_topics = forum_topics + ' . (int) $row_data['topics_authed'];
d6e8d8
				}
d6e8d8
d6e8d8
				$sync_sql[$to_forum_id][]	= 'forum_topics_real = forum_topics_real + ' . (int) sizeof($topic_ids);
d6e8d8
d6e8d8
				foreach ($sync_sql as $forum_id_key => $array)
d6e8d8
				{
d6e8d8
					$sql = 'UPDATE ' . FORUMS_TABLE . '
d6e8d8
						SET ' . implode(', ', $array) . '
d6e8d8
						WHERE forum_id = ' . $forum_id_key;
d6e8d8
					$db->sql_query($sql);
d6e8d8
				}
d6e8d8
d6e8d8
				sync('forum', 'forum_id', $to_forum_id);
d6e8d8
			}
d6e8d8
		}
d6e8d8
		else
d6e8d8
		{
d6e8d8
			// Get away with those topics already being a global announcement by re-calculating $topic_ids
d6e8d8
			$sql = 'SELECT topic_id
d6e8d8
				FROM ' . TOPICS_TABLE . '
d6e8d8
				WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
d6e8d8
					AND forum_id <> 0';
d6e8d8
			$result = $db->sql_query($sql);
d6e8d8
d6e8d8
			$topic_ids = array();
d6e8d8
			while ($row = $db->sql_fetchrow($result))
d6e8d8
			{
d6e8d8
				$topic_ids[] = $row['topic_id'];
d6e8d8
			}
d6e8d8
			$db->sql_freeresult($result);
d6e8d8
d6e8d8
			if (sizeof($topic_ids))
d6e8d8
			{
d6e8d8
				// Delete topic shadows for global announcements
d6e8d8
				$sql = 'DELETE FROM ' . TOPICS_TABLE . '
d6e8d8
					WHERE ' . $db->sql_in_set('topic_moved_id', $topic_ids);
d6e8d8
				$db->sql_query($sql);
d6e8d8
d6e8d8
				$sql = 'UPDATE ' . TOPICS_TABLE . "
d6e8d8
					SET topic_type = $new_topic_type, forum_id = 0
d6e8d8
						WHERE " . $db->sql_in_set('topic_id', $topic_ids);
d6e8d8
				$db->sql_query($sql);
d6e8d8
d6e8d8
				// Update forum_ids for all posts
d6e8d8
				$sql = 'UPDATE ' . POSTS_TABLE . '
d6e8d8
					SET forum_id = 0
d6e8d8
					WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
d6e8d8
				$db->sql_query($sql);
d6e8d8
d6e8d8
				// Do a little forum sync stuff
d6e8d8
				$sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
d6e8d8
					FROM ' . TOPICS_TABLE . ' t
d6e8d8
					WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
d6e8d8
				$result = $db->sql_query($sql);
d6e8d8
				$row_data = $db->sql_fetchrow($result);
d6e8d8
				$db->sql_freeresult($result);
d6e8d8
d6e8d8
				$sync_sql = array();
d6e8d8
d6e8d8
				if ($row_data['topic_posts'])
d6e8d8
				{
d6e8d8
					$sync_sql[$forum_id][]	= 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts'];
d6e8d8
				}
d6e8d8
d6e8d8
				if ($row_data['topics_authed'])
d6e8d8
				{
d6e8d8
					$sync_sql[$forum_id][]	= 'forum_topics = forum_topics - ' . (int) $row_data['topics_authed'];
d6e8d8
				}
d6e8d8
d6e8d8
				$sync_sql[$forum_id][]	= 'forum_topics_real = forum_topics_real - ' . (int) sizeof($topic_ids);
d6e8d8
d6e8d8
				foreach ($sync_sql as $forum_id_key => $array)
d6e8d8
				{
d6e8d8
					$sql = 'UPDATE ' . FORUMS_TABLE . '
d6e8d8
						SET ' . implode(', ', $array) . '
d6e8d8
						WHERE forum_id = ' . $forum_id_key;
d6e8d8
					$db->sql_query($sql);
d6e8d8
				}
d6e8d8
d6e8d8
				sync('forum', 'forum_id', $forum_id);
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		$success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_TYPE_CHANGED' : 'TOPICS_TYPE_CHANGED';
d6e8d8
d6e8d8
		if (sizeof($topic_ids))
d6e8d8
		{
d6e8d8
			$data = get_topic_data($topic_ids);
d6e8d8
d6e8d8
			foreach ($data as $topic_id => $row)
d6e8d8
			{
d6e8d8
				add_log('mod', $forum_id, $topic_id, 'LOG_TOPIC_TYPE_CHANGED', $row['topic_title']);
d6e8d8
			}
d6e8d8
		}
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		// Global topic involved?
d6e8d8
		$global_involved = false;
d6e8d8
d6e8d8
		if ($new_topic_type != POST_GLOBAL)
d6e8d8
		{
d6e8d8
			$sql = 'SELECT forum_id
d6e8d8
				FROM ' . TOPICS_TABLE . '
d6e8d8
				WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
d6e8d8
					AND forum_id = 0';
d6e8d8
			$result = $db->sql_query($sql);
d6e8d8
			$row = $db->sql_fetchrow($result);
d6e8d8
			$db->sql_freeresult($result);
d6e8d8
d6e8d8
			if ($row)
d6e8d8
			{
d6e8d8
				$global_involved = true;
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		if ($global_involved)
d6e8d8
		{
d6e8d8
			global $template;
d6e8d8
d6e8d8
			$template->assign_vars(array(
d6e8d8
				'S_FORUM_SELECT'		=> make_forum_select(request_var('f', $forum_id), false, false, true, true),
d6e8d8
				'S_CAN_LEAVE_SHADOW'	=> false,
d6e8d8
				'ADDITIONAL_MSG'		=> (sizeof($topic_ids) == 1) ? $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENT'] : $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENTS'])
d6e8d8
			);
d6e8d8
d6e8d8
			confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields), 'mcp_move.html');
d6e8d8
		}
d6e8d8
		else
d6e8d8
		{
d6e8d8
			confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields));
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	$redirect = request_var('redirect', "index.$phpEx");
d6e8d8
	$redirect = reapply_sid($redirect);
d6e8d8
d6e8d8
	if (!$success_msg)
d6e8d8
	{
d6e8d8
		redirect($redirect);
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		meta_refresh(2, $redirect);
d6e8d8
		trigger_error($user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], '', ''));
d6e8d8
	}
d6e8d8
}
d6e8d8
d6e8d8
/**
d6e8d8
* Move Topic
d6e8d8
*/
d6e8d8
function mcp_move_topic($topic_ids)
d6e8d8
{
d6e8d8
	global $auth, $user, $db, $template;
d6e8d8
	global $phpEx, $phpbb_root_path;
d6e8d8
d6e8d8
	// Here we limit the operation to one forum only
d6e8d8
	$forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_move'), true);
d6e8d8
d6e8d8
	if ($forum_id === false)
d6e8d8
	{
d6e8d8
		return;
d6e8d8
	}
d6e8d8
d6e8d8
	$to_forum_id = request_var('to_forum_id', 0);
d6e8d8
	$redirect = request_var('redirect', build_url(array('action', 'quickmod')));
d6e8d8
	$additional_msg = $success_msg = '';
d6e8d8
d6e8d8
	$s_hidden_fields = build_hidden_fields(array(
d6e8d8
		'topic_id_list'	=> $topic_ids,
d6e8d8
		'f'				=> $forum_id,
d6e8d8
		'action'		=> 'move',
d6e8d8
		'redirect'		=> $redirect)
d6e8d8
	);
d6e8d8
d6e8d8
	if ($to_forum_id)
d6e8d8
	{
d6e8d8
		$forum_data = get_forum_data($to_forum_id, 'f_post');
d6e8d8
d6e8d8
		if (!sizeof($forum_data))
d6e8d8
		{
d6e8d8
			$additional_msg = $user->lang['FORUM_NOT_EXIST'];
d6e8d8
		}
d6e8d8
		else
d6e8d8
		{
d6e8d8
			$forum_data = $forum_data[$to_forum_id];
d6e8d8
d6e8d8
			if ($forum_data['forum_type'] != FORUM_POST)
d6e8d8
			{
d6e8d8
				$additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
d6e8d8
			}
d6e8d8
			else if (!$auth->acl_get('f_post', $to_forum_id))
d6e8d8
			{
d6e8d8
				$additional_msg = $user->lang['USER_CANNOT_POST'];
d6e8d8
			}
d6e8d8
			else if ($forum_id == $to_forum_id)
d6e8d8
			{
d6e8d8
				$additional_msg = $user->lang['CANNOT_MOVE_SAME_FORUM'];
d6e8d8
			}
d6e8d8
		}
d6e8d8
	}
d6e8d8
	else if (isset($_POST['confirm']))
d6e8d8
	{
d6e8d8
		$additional_msg = $user->lang['FORUM_NOT_EXIST'];
d6e8d8
	}
d6e8d8
d6e8d8
	if (!$to_forum_id || $additional_msg)
d6e8d8
	{
d6e8d8
		unset($_POST['confirm']);
d6e8d8
		unset($_REQUEST['confirm_key']);
d6e8d8
	}
d6e8d8
d6e8d8
	if (confirm_box(true))
d6e8d8
	{
d6e8d8
		$topic_data = get_topic_data($topic_ids);
d6e8d8
		$leave_shadow = (isset($_POST['move_leave_shadow'])) ? true : false;
d6e8d8
d6e8d8
		$topics_moved = sizeof($topic_ids);
d6e8d8
		$topics_authed_moved = 0;
d6e8d8
		$forum_sync_data = array();
d6e8d8
d6e8d8
		$forum_sync_data[$forum_id] = current($topic_data);
d6e8d8
		$forum_sync_data[$to_forum_id] = $forum_data;
d6e8d8
d6e8d8
		foreach ($topic_data as $topic_id => $topic_info)
d6e8d8
		{
d6e8d8
			if ($topic_info['topic_approved'] == '1')
d6e8d8
			{
d6e8d8
				$topics_authed_moved++;
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		$db->sql_transaction('begin');
d6e8d8
d6e8d8
		$sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts
d6e8d8
			FROM ' . TOPICS_TABLE . ' t
d6e8d8
			WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
d6e8d8
		$result = $db->sql_query($sql);
d6e8d8
		$row_data = $db->sql_fetchrow($result);
d6e8d8
		$db->sql_freeresult($result);
d6e8d8
d6e8d8
		$sync_sql = array();
d6e8d8
d6e8d8
		if ($row_data['topic_posts'])
d6e8d8
		{
d6e8d8
			$sync_sql[$forum_id][]		= 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts'];
d6e8d8
			$sync_sql[$to_forum_id][]	= 'forum_posts = forum_posts + ' . (int) $row_data['topic_posts'];
d6e8d8
		}
d6e8d8
d6e8d8
		if ($topics_authed_moved)
d6e8d8
		{
d6e8d8
			$sync_sql[$to_forum_id][]	= 'forum_topics = forum_topics + ' . (int) $topics_authed_moved;
d6e8d8
		}
d6e8d8
d6e8d8
		$sync_sql[$to_forum_id][]	= 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved;
d6e8d8
d6e8d8
		// Move topics, but do not resync yet
d6e8d8
		move_topics($topic_ids, $to_forum_id, false);
d6e8d8
d6e8d8
		$forum_ids = array($to_forum_id);
d6e8d8
		foreach ($topic_data as $topic_id => $row)
d6e8d8
		{
d6e8d8
			// Get the list of forums to resync, add a log entry
d6e8d8
			$forum_ids[] = $row['forum_id'];
d6e8d8
			add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name'], $forum_data['forum_name']);
d6e8d8
d6e8d8
			// If we have moved a global announcement, we need to correct the topic type
d6e8d8
			if ($row['topic_type'] == POST_GLOBAL)
d6e8d8
			{
d6e8d8
				$sql = 'UPDATE ' . TOPICS_TABLE . '
d6e8d8
					SET topic_type = ' . POST_ANNOUNCE . '
d6e8d8
					WHERE topic_id = ' . (int) $row['topic_id'];
d6e8d8
				$db->sql_query($sql);
d6e8d8
			}
d6e8d8
d6e8d8
			// Leave a redirection if required and only if the topic is visible to users
d6e8d8
			if ($leave_shadow && $row['topic_approved'] && $row['topic_type'] != POST_GLOBAL)
d6e8d8
			{
d6e8d8
				$shadow = array(
d6e8d8
					'forum_id'				=>	(int) $row['forum_id'],
d6e8d8
					'icon_id'				=>	(int) $row['icon_id'],
d6e8d8
					'topic_attachment'		=>	(int) $row['topic_attachment'],
d6e8d8
					'topic_approved'		=>	1, // a shadow topic is always approved
d6e8d8
					'topic_reported'		=>	0, // a shadow topic is never reported
d6e8d8
					'topic_title'			=>	(string) $row['topic_title'],
d6e8d8
					'topic_poster'			=>	(int) $row['topic_poster'],
d6e8d8
					'topic_time'			=>	(int) $row['topic_time'],
d6e8d8
					'topic_time_limit'		=>	(int) $row['topic_time_limit'],
d6e8d8
					'topic_views'			=>	(int) $row['topic_views'],
d6e8d8
					'topic_replies'			=>	(int) $row['topic_replies'],
d6e8d8
					'topic_replies_real'	=>	(int) $row['topic_replies_real'],
d6e8d8
					'topic_status'			=>	ITEM_MOVED,
d6e8d8
					'topic_type'			=>	POST_NORMAL,
d6e8d8
					'topic_first_post_id'	=>	(int) $row['topic_first_post_id'],
d6e8d8
					'topic_first_poster_colour'=>(string) $row['topic_first_poster_colour'],
d6e8d8
					'topic_first_poster_name'=>	(string) $row['topic_first_poster_name'],
d6e8d8
					'topic_last_post_id'	=>	(int) $row['topic_last_post_id'],
d6e8d8
					'topic_last_poster_id'	=>	(int) $row['topic_last_poster_id'],
d6e8d8
					'topic_last_poster_colour'=>(string) $row['topic_last_poster_colour'],
d6e8d8
					'topic_last_poster_name'=>	(string) $row['topic_last_poster_name'],
d6e8d8
					'topic_last_post_subject'=>	(string)  $row['topic_last_post_subject'],
d6e8d8
					'topic_last_post_time'	=>	(int) $row['topic_last_post_time'],
d6e8d8
					'topic_last_view_time'	=>	(int) $row['topic_last_view_time'],
d6e8d8
					'topic_moved_id'		=>	(int) $row['topic_id'],
d6e8d8
					'topic_bumped'			=>	(int) $row['topic_bumped'],
d6e8d8
					'topic_bumper'			=>	(int) $row['topic_bumper'],
d6e8d8
					'poll_title'			=>	(string) $row['poll_title'],
d6e8d8
					'poll_start'			=>	(int) $row['poll_start'],
d6e8d8
					'poll_length'			=>	(int) $row['poll_length'],
d6e8d8
					'poll_max_options'		=>	(int) $row['poll_max_options'],
d6e8d8
					'poll_last_vote'		=>	(int) $row['poll_last_vote']
d6e8d8
				);
d6e8d8
d6e8d8
				$db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow));
d6e8d8
d6e8d8
				$topics_authed_moved--;
d6e8d8
				$topics_moved--;
d6e8d8
			}
d6e8d8
		}
d6e8d8
		unset($topic_data);
d6e8d8
d6e8d8
		$sync_sql[$forum_id][]	= 'forum_topics_real = forum_topics_real - ' . (int) $topics_moved;
d6e8d8
d6e8d8
		if ($topics_authed_moved)
d6e8d8
		{
d6e8d8
			$sync_sql[$forum_id][]	= 'forum_topics = forum_topics - ' . (int) $topics_authed_moved;
d6e8d8
		}
d6e8d8
d6e8d8
		$success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS';
d6e8d8
d6e8d8
		foreach ($sync_sql as $forum_id_key => $array)
d6e8d8
		{
d6e8d8
			$sql = 'UPDATE ' . FORUMS_TABLE . '
d6e8d8
				SET ' . implode(', ', $array) . '
d6e8d8
				WHERE forum_id = ' . $forum_id_key;
d6e8d8
			$db->sql_query($sql);
d6e8d8
		}
d6e8d8
d6e8d8
		$db->sql_transaction('commit');
d6e8d8
d6e8d8
		sync('forum', 'forum_id', array($forum_id, $to_forum_id));
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		$template->assign_vars(array(
d6e8d8
			'S_FORUM_SELECT'		=> make_forum_select($to_forum_id, $forum_id, false, true, true, true),
d6e8d8
			'S_CAN_LEAVE_SHADOW'	=> true,
d6e8d8
			'ADDITIONAL_MSG'		=> $additional_msg)
d6e8d8
		);
d6e8d8
d6e8d8
		confirm_box(false, 'MOVE_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
d6e8d8
	}
d6e8d8
d6e8d8
	$redirect = request_var('redirect', "index.$phpEx");
d6e8d8
	$redirect = reapply_sid($redirect);
d6e8d8
d6e8d8
	if (!$success_msg)
d6e8d8
	{
d6e8d8
		redirect($redirect);
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		meta_refresh(3, $redirect);
d6e8d8
d6e8d8
		$message = $user->lang[$success_msg];
d6e8d8
		$message .= '

' . sprintf($user->lang['RETURN_PAGE'], '', '');
d6e8d8
		$message .= '

' . sprintf($user->lang['RETURN_FORUM'], '', '');
d6e8d8
		$message .= '

' . sprintf($user->lang['RETURN_NEW_FORUM'], '', '');
d6e8d8
d6e8d8
		trigger_error($message);
d6e8d8
	}
d6e8d8
}
d6e8d8
d6e8d8
/**
d6e8d8
* Delete Topics
d6e8d8
*/
d6e8d8
function mcp_delete_topic($topic_ids)
d6e8d8
{
d6e8d8
	global $auth, $user, $db, $phpEx, $phpbb_root_path;
d6e8d8
d6e8d8
	if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete')))
d6e8d8
	{
d6e8d8
		return;
d6e8d8
	}
d6e8d8
d6e8d8
	$redirect = request_var('redirect', build_url(array('action', 'quickmod')));
d6e8d8
	$forum_id = request_var('f', 0);
d6e8d8
d6e8d8
	$s_hidden_fields = build_hidden_fields(array(
d6e8d8
		'topic_id_list'	=> $topic_ids,
d6e8d8
		'f'				=> $forum_id,
d6e8d8
		'action'		=> 'delete_topic',
d6e8d8
		'redirect'		=> $redirect)
d6e8d8
	);
d6e8d8
	$success_msg = '';
d6e8d8
d6e8d8
	if (confirm_box(true))
d6e8d8
	{
d6e8d8
		$success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS';
d6e8d8
d6e8d8
		$data = get_topic_data($topic_ids);
d6e8d8
d6e8d8
		foreach ($data as $topic_id => $row)
d6e8d8
		{
d6e8d8
			add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_' . ($row['topic_moved_id'] ? 'SHADOW_' : '') . 'TOPIC', $row['topic_title']);
d6e8d8
		}
d6e8d8
d6e8d8
		$return = delete_topics('topic_id', $topic_ids);
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields);
d6e8d8
	}
d6e8d8
d6e8d8
	if (!isset($_REQUEST['quickmod']))
d6e8d8
	{
d6e8d8
		$redirect = request_var('redirect', "index.$phpEx");
d6e8d8
		$redirect = reapply_sid($redirect);
d6e8d8
		$redirect_message = 'PAGE';
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		$redirect = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
d6e8d8
		$redirect_message = 'FORUM';
d6e8d8
	}
d6e8d8
d6e8d8
	if (!$success_msg)
d6e8d8
	{
d6e8d8
		redirect($redirect);
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		meta_refresh(3, $redirect);
d6e8d8
		trigger_error($user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_' . $redirect_message], '', ''));
d6e8d8
	}
d6e8d8
}
d6e8d8
d6e8d8
/**
d6e8d8
* Delete Posts
d6e8d8
*/
d6e8d8
function mcp_delete_post($post_ids)
d6e8d8
{
d6e8d8
	global $auth, $user, $db, $phpEx, $phpbb_root_path;
d6e8d8
d6e8d8
	if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_delete')))
d6e8d8
	{
d6e8d8
		return;
d6e8d8
	}
d6e8d8
d6e8d8
	$redirect = request_var('redirect', build_url(array('action', 'quickmod')));
d6e8d8
	$forum_id = request_var('f', 0);
d6e8d8
d6e8d8
	$s_hidden_fields = build_hidden_fields(array(
d6e8d8
		'post_id_list'	=> $post_ids,
d6e8d8
		'f'				=> $forum_id,
d6e8d8
		'action'		=> 'delete_post',
d6e8d8
		'redirect'		=> $redirect)
d6e8d8
	);
d6e8d8
	$success_msg = '';
d6e8d8
d6e8d8
	if (confirm_box(true))
d6e8d8
	{
d6e8d8
		if (!function_exists('delete_posts'))
d6e8d8
		{
d6e8d8
			include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
d6e8d8
		}
d6e8d8
d6e8d8
		// Count the number of topics that are affected
d6e8d8
		// I did not use COUNT(DISTINCT ...) because I remember having problems
d6e8d8
		// with it on older versions of MySQL -- Ashe
d6e8d8
d6e8d8
		$sql = 'SELECT DISTINCT topic_id
d6e8d8
			FROM ' . POSTS_TABLE . '
d6e8d8
			WHERE ' . $db->sql_in_set('post_id', $post_ids);
d6e8d8
		$result = $db->sql_query($sql);
d6e8d8
d6e8d8
		$topic_id_list = array();
d6e8d8
		while ($row = $db->sql_fetchrow($result))
d6e8d8
		{
d6e8d8
			$topic_id_list[] = $row['topic_id'];
d6e8d8
		}
d6e8d8
		$affected_topics = sizeof($topic_id_list);
d6e8d8
		$db->sql_freeresult($result);
d6e8d8
d6e8d8
		$post_data = get_post_data($post_ids);
d6e8d8
d6e8d8
		foreach ($post_data as $id => $row)
d6e8d8
		{
d6e8d8
			add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_DELETE_POST', $row['post_subject']);
d6e8d8
		}
d6e8d8
d6e8d8
		// Now delete the posts, topics and forums are automatically resync'ed
d6e8d8
		delete_posts('post_id', $post_ids);
d6e8d8
d6e8d8
		$sql = 'SELECT COUNT(topic_id) AS topics_left
d6e8d8
			FROM ' . TOPICS_TABLE . '
d6e8d8
			WHERE ' . $db->sql_in_set('topic_id', $topic_id_list);
d6e8d8
		$result = $db->sql_query_limit($sql, 1);
d6e8d8
d6e8d8
		$deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics;
d6e8d8
		$db->sql_freeresult($result);
d6e8d8
d6e8d8
		$topic_id = request_var('t', 0);
d6e8d8
d6e8d8
		// Return links
d6e8d8
		$return_link = array();
d6e8d8
		if ($affected_topics == 1 && !$deleted_topics && $topic_id)
d6e8d8
		{
d6e8d8
			$return_link[] = sprintf($user->lang['RETURN_TOPIC'], '', '');
d6e8d8
		}
d6e8d8
		$return_link[] = sprintf($user->lang['RETURN_FORUM'], '', '');
d6e8d8
d6e8d8
		if (sizeof($post_ids) == 1)
d6e8d8
		{
d6e8d8
			if ($deleted_topics)
d6e8d8
			{
d6e8d8
				// We deleted the only post of a topic, which in turn has
d6e8d8
				// been removed from the database
d6e8d8
				$success_msg = $user->lang['TOPIC_DELETED_SUCCESS'];
d6e8d8
			}
d6e8d8
			else
d6e8d8
			{
d6e8d8
				$success_msg = $user->lang['POST_DELETED_SUCCESS'];
d6e8d8
			}
d6e8d8
		}
d6e8d8
		else
d6e8d8
		{
d6e8d8
			if ($deleted_topics)
d6e8d8
			{
d6e8d8
				// Some of topics disappeared
d6e8d8
				$success_msg = $user->lang['POSTS_DELETED_SUCCESS'] . '

' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING'];
d6e8d8
			}
d6e8d8
			else
d6e8d8
			{
d6e8d8
				$success_msg = $user->lang['POSTS_DELETED_SUCCESS'];
d6e8d8
			}
d6e8d8
		}
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_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
		redirect($redirect);
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		meta_refresh(3, $redirect);
d6e8d8
		trigger_error($success_msg . '

' . sprintf($user->lang['RETURN_PAGE'], '', '') . '

' . implode('

', $return_link));
d6e8d8
	}
d6e8d8
}
d6e8d8
d6e8d8
/**
d6e8d8
* Fork Topic
d6e8d8
*/
d6e8d8
function mcp_fork_topic($topic_ids)
d6e8d8
{
d6e8d8
	global $auth, $user, $db, $template, $config;
d6e8d8
	global $phpEx, $phpbb_root_path;
d6e8d8
d6e8d8
	if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_')))
d6e8d8
	{
d6e8d8
		return;
d6e8d8
	}
d6e8d8
d6e8d8
	$to_forum_id = request_var('to_forum_id', 0);
d6e8d8
	$forum_id = request_var('f', 0);
d6e8d8
	$redirect = request_var('redirect', build_url(array('action', 'quickmod')));
d6e8d8
	$additional_msg = $success_msg = '';
d6e8d8
d6e8d8
	$s_hidden_fields = build_hidden_fields(array(
d6e8d8
		'topic_id_list'	=> $topic_ids,
d6e8d8
		'f'				=> $forum_id,
d6e8d8
		'action'		=> 'fork',
d6e8d8
		'redirect'		=> $redirect)
d6e8d8
	);
d6e8d8
d6e8d8
	if ($to_forum_id)
d6e8d8
	{
d6e8d8
		$forum_data = get_forum_data($to_forum_id, 'f_post');
d6e8d8
d6e8d8
		if (!sizeof($topic_ids))
d6e8d8
		{
d6e8d8
			$additional_msg = $user->lang['NO_TOPIC_SELECTED'];
d6e8d8
		}
d6e8d8
		else if (!sizeof($forum_data))
d6e8d8
		{
d6e8d8
			$additional_msg = $user->lang['FORUM_NOT_EXIST'];
d6e8d8
		}
d6e8d8
		else
d6e8d8
		{
d6e8d8
			$forum_data = $forum_data[$to_forum_id];
d6e8d8
d6e8d8
			if ($forum_data['forum_type'] != FORUM_POST)
d6e8d8
			{
d6e8d8
				$additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
d6e8d8
			}
d6e8d8
			else if (!$auth->acl_get('f_post', $to_forum_id))
d6e8d8
			{
d6e8d8
				$additional_msg = $user->lang['USER_CANNOT_POST'];
d6e8d8
			}
d6e8d8
		}
d6e8d8
	}
d6e8d8
	else if (isset($_POST['confirm']))
d6e8d8
	{
d6e8d8
		$additional_msg = $user->lang['FORUM_NOT_EXIST'];
d6e8d8
	}
d6e8d8
d6e8d8
	if ($additional_msg)
d6e8d8
	{
d6e8d8
		unset($_POST['confirm']);
d6e8d8
		unset($_REQUEST['confirm_key']);
d6e8d8
	}
d6e8d8
d6e8d8
	if (confirm_box(true))
d6e8d8
	{
d6e8d8
		$topic_data = get_topic_data($topic_ids, 'f_post');
d6e8d8
d6e8d8
		$total_posts = 0;
d6e8d8
		$new_topic_id_list = array();
d6e8d8
d6e8d8
		foreach ($topic_data as $topic_id => $topic_row)
d6e8d8
		{
d6e8d8
			$sql_ary = array(
d6e8d8
				'forum_id'					=> (int) $to_forum_id,
d6e8d8
				'icon_id'					=> (int) $topic_row['icon_id'],
d6e8d8
				'topic_attachment'			=> (int) $topic_row['topic_attachment'],
d6e8d8
				'topic_approved'			=> 1,
d6e8d8
				'topic_reported'			=> 0,
d6e8d8
				'topic_title'				=> (string) $topic_row['topic_title'],
d6e8d8
				'topic_poster'				=> (int) $topic_row['topic_poster'],
d6e8d8
				'topic_time'				=> (int) $topic_row['topic_time'],
d6e8d8
				'topic_replies'				=> (int) $topic_row['topic_replies_real'],
d6e8d8
				'topic_replies_real'		=> (int) $topic_row['topic_replies_real'],
d6e8d8
				'topic_status'				=> (int) $topic_row['topic_status'],
d6e8d8
				'topic_type'				=> (int) $topic_row['topic_type'],
d6e8d8
				'topic_first_poster_name'	=> (string) $topic_row['topic_first_poster_name'],
d6e8d8
				'topic_last_poster_id'		=> (int) $topic_row['topic_last_poster_id'],
d6e8d8
				'topic_last_poster_name'	=> (string) $topic_row['topic_last_poster_name'],
d6e8d8
				'topic_last_post_time'		=> (int) $topic_row['topic_last_post_time'],
d6e8d8
				'topic_last_view_time'		=> (int) $topic_row['topic_last_view_time'],
d6e8d8
				'topic_bumped'				=> (int) $topic_row['topic_bumped'],
d6e8d8
				'topic_bumper'				=> (int) $topic_row['topic_bumper'],
d6e8d8
				'poll_title'				=> (string) $topic_row['poll_title'],
d6e8d8
				'poll_start'				=> (int) $topic_row['poll_start'],
d6e8d8
				'poll_length'				=> (int) $topic_row['poll_length']
d6e8d8
			);
d6e8d8
d6e8d8
			$db->sql_query('INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
d6e8d8
			$new_topic_id = $db->sql_nextid();
d6e8d8
			$new_topic_id_list[$topic_id] = $new_topic_id;
d6e8d8
d6e8d8
			if ($topic_row['poll_start'])
d6e8d8
			{
d6e8d8
				$poll_rows = array();
d6e8d8
d6e8d8
				$sql = 'SELECT *
d6e8d8
					FROM ' . POLL_OPTIONS_TABLE . "
d6e8d8
					WHERE topic_id = $topic_id";
d6e8d8
				$result = $db->sql_query($sql);
d6e8d8
d6e8d8
				while ($row = $db->sql_fetchrow($result))
d6e8d8
				{
d6e8d8
					$sql_ary = array(
d6e8d8
						'poll_option_id'	=> (int) $row['poll_option_id'],
d6e8d8
						'topic_id'			=> (int) $new_topic_id,
d6e8d8
						'poll_option_text'	=> (string) $row['poll_option_text'],
d6e8d8
						'poll_option_total'	=> 0
d6e8d8
					);
d6e8d8
d6e8d8
					$db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			$sql = 'SELECT *
d6e8d8
				FROM ' . POSTS_TABLE . "
d6e8d8
				WHERE topic_id = $topic_id
d6e8d8
				ORDER BY post_time ASC";
d6e8d8
			$result = $db->sql_query($sql);
d6e8d8
d6e8d8
			$post_rows = array();
d6e8d8
			while ($row = $db->sql_fetchrow($result))
d6e8d8
			{
d6e8d8
				$post_rows[] = $row;
d6e8d8
			}
d6e8d8
			$db->sql_freeresult($result);
d6e8d8
d6e8d8
			if (!sizeof($post_rows))
d6e8d8
			{
d6e8d8
				continue;
d6e8d8
			}
d6e8d8
d6e8d8
			$total_posts += sizeof($post_rows);
d6e8d8
			foreach ($post_rows as $row)
d6e8d8
			{
d6e8d8
				$sql_ary = array(
d6e8d8
					'topic_id'			=> (int) $new_topic_id,
d6e8d8
					'forum_id'			=> (int) $to_forum_id,
d6e8d8
					'poster_id'			=> (int) $row['poster_id'],
d6e8d8
					'icon_id'			=> (int) $row['icon_id'],
d6e8d8
					'poster_ip'			=> (string) $row['poster_ip'],
d6e8d8
					'post_time'			=> (int) $row['post_time'],
d6e8d8
					'post_approved'		=> 1,
d6e8d8
					'post_reported'		=> 0,
d6e8d8
					'enable_bbcode'		=> (int) $row['enable_bbcode'],
d6e8d8
					'enable_smilies'	=> (int) $row['enable_smilies'],
d6e8d8
					'enable_magic_url'	=> (int) $row['enable_magic_url'],
d6e8d8
					'enable_sig'		=> (int) $row['enable_sig'],
d6e8d8
					'post_username'		=> (string) $row['post_username'],
d6e8d8
					'post_subject'		=> (string) $row['post_subject'],
d6e8d8
					'post_text'			=> (string) $row['post_text'],
d6e8d8
					'post_edit_reason'	=> (string) $row['post_edit_reason'],
d6e8d8
					'post_edit_user'	=> (int) $row['post_edit_user'],
d6e8d8
					'post_checksum'		=> (string) $row['post_checksum'],
d6e8d8
					'post_attachment'	=> (int) $row['post_attachment'],
d6e8d8
					'bbcode_bitfield'	=> $row['bbcode_bitfield'],
d6e8d8
					'bbcode_uid'		=> (string) $row['bbcode_uid'],
d6e8d8
					'post_edit_time'	=> (int) $row['post_edit_time'],
d6e8d8
					'post_edit_count'	=> (int) $row['post_edit_count'],
d6e8d8
					'post_edit_locked'	=> (int) $row['post_edit_locked'],
d6e8d8
					'post_postcount'	=> 0,
d6e8d8
				);
d6e8d8
d6e8d8
				$db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
d6e8d8
				$new_post_id = $db->sql_nextid();
d6e8d8
d6e8d8
				// Copy whether the topic is dotted
d6e8d8
				markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']);
d6e8d8
d6e8d8
				// Copy Attachments
d6e8d8
				if ($row['post_attachment'])
d6e8d8
				{
d6e8d8
					$sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . "
d6e8d8
						WHERE post_msg_id = {$row['post_id']}
d6e8d8
							AND topic_id = $topic_id
d6e8d8
							AND in_message = 0";
d6e8d8
					$result = $db->sql_query($sql);
d6e8d8
d6e8d8
					$sql_ary = array();
d6e8d8
					while ($attach_row = $db->sql_fetchrow($result))
d6e8d8
					{
d6e8d8
						$sql_ary[] = array(
d6e8d8
							'post_msg_id'		=> (int) $new_post_id,
d6e8d8
							'topic_id'			=> (int) $new_topic_id,
d6e8d8
							'in_message'		=> 0,
d6e8d8
							'is_orphan'			=> (int) $attach_row['is_orphan'],
d6e8d8
							'poster_id'			=> (int) $attach_row['poster_id'],
d6e8d8
							'physical_filename'	=> (string) basename($attach_row['physical_filename']),
d6e8d8
							'real_filename'		=> (string) basename($attach_row['real_filename']),
d6e8d8
							'download_count'	=> (int) $attach_row['download_count'],
d6e8d8
							'attach_comment'	=> (string) $attach_row['attach_comment'],
d6e8d8
							'extension'			=> (string) $attach_row['extension'],
d6e8d8
							'mimetype'			=> (string) $attach_row['mimetype'],
d6e8d8
							'filesize'			=> (int) $attach_row['filesize'],
d6e8d8
							'filetime'			=> (int) $attach_row['filetime'],
d6e8d8
							'thumbnail'			=> (int) $attach_row['thumbnail']
d6e8d8
						);
d6e8d8
					}
d6e8d8
					$db->sql_freeresult($result);
d6e8d8
d6e8d8
					if (sizeof($sql_ary))
d6e8d8
					{
d6e8d8
						$db->sql_multi_insert(ATTACHMENTS_TABLE, $sql_ary);
d6e8d8
					}
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			$sql = 'SELECT user_id, notify_status
d6e8d8
				FROM ' . TOPICS_WATCH_TABLE . '
d6e8d8
				WHERE topic_id = ' . $topic_id;
d6e8d8
			$result = $db->sql_query($sql);
d6e8d8
d6e8d8
			$sql_ary = array();
d6e8d8
			while ($row = $db->sql_fetchrow($result))
d6e8d8
			{
d6e8d8
				$sql_ary[] = array(
d6e8d8
					'topic_id'		=> (int) $new_topic_id,
d6e8d8
					'user_id'		=> (int) $row['user_id'],
d6e8d8
					'notify_status'	=> (int) $row['notify_status'],
d6e8d8
				);
d6e8d8
			}
d6e8d8
			$db->sql_freeresult($result);
d6e8d8
d6e8d8
			if (sizeof($sql_ary))
d6e8d8
			{
d6e8d8
				$db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		// Sync new topics, parent forums and board stats
d6e8d8
		sync('topic', 'topic_id', $new_topic_id_list);
d6e8d8
d6e8d8
		$sync_sql = array();
d6e8d8
d6e8d8
		$sync_sql[$to_forum_id][]	= 'forum_posts = forum_posts + ' . $total_posts;
d6e8d8
		$sync_sql[$to_forum_id][]	= 'forum_topics = forum_topics + ' . sizeof($new_topic_id_list);
d6e8d8
		$sync_sql[$to_forum_id][]	= 'forum_topics_real = forum_topics_real + ' . sizeof($new_topic_id_list);
d6e8d8
d6e8d8
		foreach ($sync_sql as $forum_id_key => $array)
d6e8d8
		{
d6e8d8
			$sql = 'UPDATE ' . FORUMS_TABLE . '
d6e8d8
				SET ' . implode(', ', $array) . '
d6e8d8
				WHERE forum_id = ' . $forum_id_key;
d6e8d8
			$db->sql_query($sql);
d6e8d8
		}
d6e8d8
d6e8d8
		sync('forum', 'forum_id', $to_forum_id);
d6e8d8
		set_config('num_topics', $config['num_topics'] + sizeof($new_topic_id_list), true);
d6e8d8
		set_config('num_posts', $config['num_posts'] + $total_posts, true);
d6e8d8
d6e8d8
		foreach ($new_topic_id_list as $topic_id => $new_topic_id)
d6e8d8
		{
d6e8d8
			add_log('mod', $to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']);
d6e8d8
		}
d6e8d8
d6e8d8
		$success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS';
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		$template->assign_vars(array(
d6e8d8
			'S_FORUM_SELECT'		=> make_forum_select($to_forum_id, false, false, true, true, true),
d6e8d8
			'S_CAN_LEAVE_SHADOW'	=> false,
d6e8d8
			'ADDITIONAL_MSG'		=> $additional_msg)
d6e8d8
		);
d6e8d8
d6e8d8
		confirm_box(false, 'FORK_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
d6e8d8
	}
d6e8d8
d6e8d8
	$redirect = request_var('redirect', "index.$phpEx");
d6e8d8
	$redirect = reapply_sid($redirect);
d6e8d8
d6e8d8
	if (!$success_msg)
d6e8d8
	{
d6e8d8
		redirect($redirect);
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		$redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
d6e8d8
		meta_refresh(3, $redirect_url);
d6e8d8
		$return_link = sprintf($user->lang['RETURN_FORUM'], '', '');
d6e8d8
d6e8d8
		if ($forum_id != $to_forum_id)
d6e8d8
		{
d6e8d8
			$return_link .= '

' . sprintf($user->lang['RETURN_NEW_FORUM'], '', '');
d6e8d8
		}
d6e8d8
d6e8d8
		trigger_error($user->lang[$success_msg] . '

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