Blame Identity/Webenv/phpBB/3.0.4/includes/mcp/mcp_main.php

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

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

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

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

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

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

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

' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING'];
ef5584
			}
ef5584
			else
ef5584
			{
ef5584
				$success_msg = $user->lang['POSTS_DELETED_SUCCESS'];
ef5584
			}
ef5584
		}
ef5584
	}
ef5584
	else
ef5584
	{
ef5584
		confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields);
ef5584
	}
ef5584
ef5584
	$redirect = request_var('redirect', "index.$phpEx");
ef5584
	$redirect = reapply_sid($redirect);
ef5584
ef5584
	if (!$success_msg)
ef5584
	{
ef5584
		redirect($redirect);
ef5584
	}
ef5584
	else
ef5584
	{
ef5584
		meta_refresh(3, $redirect);
ef5584
		trigger_error($success_msg . '

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

' . implode('

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

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

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