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

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

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

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

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

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

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

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

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

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

' . implode('

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

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

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