1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/mcp/mcp_main.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,1317 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package mcp
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* mcp_main
1.24 +* Handling mcp actions
1.25 +* @package mcp
1.26 +*/
1.27 +class mcp_main
1.28 +{
1.29 + var $p_master;
1.30 + var $u_action;
1.31 +
1.32 + function mcp_main(&$p_master)
1.33 + {
1.34 + $this->p_master = &$p_master;
1.35 + }
1.36 +
1.37 + function main($id, $mode)
1.38 + {
1.39 + global $auth, $db, $user, $template, $action;
1.40 + global $config, $phpbb_root_path, $phpEx;
1.41 +
1.42 + $quickmod = ($mode == 'quickmod') ? true : false;
1.43 +
1.44 + switch ($action)
1.45 + {
1.46 + case 'lock':
1.47 + case 'unlock':
1.48 + $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
1.49 +
1.50 + if (!sizeof($topic_ids))
1.51 + {
1.52 + trigger_error('NO_TOPIC_SELECTED');
1.53 + }
1.54 +
1.55 + lock_unlock($action, $topic_ids);
1.56 + break;
1.57 +
1.58 + case 'lock_post':
1.59 + case 'unlock_post':
1.60 +
1.61 + $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
1.62 +
1.63 + if (!sizeof($post_ids))
1.64 + {
1.65 + trigger_error('NO_POST_SELECTED');
1.66 + }
1.67 +
1.68 + lock_unlock($action, $post_ids);
1.69 + break;
1.70 +
1.71 + case 'make_announce':
1.72 + case 'make_sticky':
1.73 + case 'make_global':
1.74 + case 'make_normal':
1.75 +
1.76 + $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
1.77 +
1.78 + if (!sizeof($topic_ids))
1.79 + {
1.80 + trigger_error('NO_TOPIC_SELECTED');
1.81 + }
1.82 +
1.83 + change_topic_type($action, $topic_ids);
1.84 + break;
1.85 +
1.86 + case 'move':
1.87 + $user->add_lang('viewtopic');
1.88 +
1.89 + $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
1.90 +
1.91 + if (!sizeof($topic_ids))
1.92 + {
1.93 + trigger_error('NO_TOPIC_SELECTED');
1.94 + }
1.95 +
1.96 + mcp_move_topic($topic_ids);
1.97 + break;
1.98 +
1.99 + case 'fork':
1.100 + $user->add_lang('viewtopic');
1.101 +
1.102 + $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
1.103 +
1.104 + if (!sizeof($topic_ids))
1.105 + {
1.106 + trigger_error('NO_TOPIC_SELECTED');
1.107 + }
1.108 +
1.109 + mcp_fork_topic($topic_ids);
1.110 + break;
1.111 +
1.112 + case 'delete_topic':
1.113 + $user->add_lang('viewtopic');
1.114 +
1.115 + $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
1.116 +
1.117 + if (!sizeof($topic_ids))
1.118 + {
1.119 + trigger_error('NO_TOPIC_SELECTED');
1.120 + }
1.121 +
1.122 + mcp_delete_topic($topic_ids);
1.123 + break;
1.124 +
1.125 + case 'delete_post':
1.126 + $user->add_lang('posting');
1.127 +
1.128 + $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
1.129 +
1.130 + if (!sizeof($post_ids))
1.131 + {
1.132 + trigger_error('NO_POST_SELECTED');
1.133 + }
1.134 +
1.135 + mcp_delete_post($post_ids);
1.136 + break;
1.137 + }
1.138 +
1.139 + switch ($mode)
1.140 + {
1.141 + case 'front':
1.142 + include($phpbb_root_path . 'includes/mcp/mcp_front.' . $phpEx);
1.143 +
1.144 + $user->add_lang('acp/common');
1.145 +
1.146 + mcp_front_view($id, $mode, $action);
1.147 +
1.148 + $this->tpl_name = 'mcp_front';
1.149 + $this->page_title = 'MCP_MAIN';
1.150 + break;
1.151 +
1.152 + case 'forum_view':
1.153 + include($phpbb_root_path . 'includes/mcp/mcp_forum.' . $phpEx);
1.154 +
1.155 + $user->add_lang('viewforum');
1.156 +
1.157 + $forum_id = request_var('f', 0);
1.158 +
1.159 + $forum_info = get_forum_data($forum_id, 'm_', true);
1.160 +
1.161 + if (!sizeof($forum_info))
1.162 + {
1.163 + $this->main('main', 'front');
1.164 + return;
1.165 + }
1.166 +
1.167 + $forum_info = $forum_info[$forum_id];
1.168 +
1.169 + mcp_forum_view($id, $mode, $action, $forum_info);
1.170 +
1.171 + $this->tpl_name = 'mcp_forum';
1.172 + $this->page_title = 'MCP_MAIN_FORUM_VIEW';
1.173 + break;
1.174 +
1.175 + case 'topic_view':
1.176 + include($phpbb_root_path . 'includes/mcp/mcp_topic.' . $phpEx);
1.177 +
1.178 + mcp_topic_view($id, $mode, $action);
1.179 +
1.180 + $this->tpl_name = 'mcp_topic';
1.181 + $this->page_title = 'MCP_MAIN_TOPIC_VIEW';
1.182 + break;
1.183 +
1.184 + case 'post_details':
1.185 + include($phpbb_root_path . 'includes/mcp/mcp_post.' . $phpEx);
1.186 +
1.187 + mcp_post_details($id, $mode, $action);
1.188 +
1.189 + $this->tpl_name = ($action == 'whois') ? 'mcp_whois' : 'mcp_post';
1.190 + $this->page_title = 'MCP_MAIN_POST_DETAILS';
1.191 + break;
1.192 +
1.193 + default:
1.194 + trigger_error('NO_MODE', E_USER_ERROR);
1.195 + break;
1.196 + }
1.197 + }
1.198 +}
1.199 +
1.200 +/**
1.201 +* Lock/Unlock Topic/Post
1.202 +*/
1.203 +function lock_unlock($action, $ids)
1.204 +{
1.205 + global $auth, $user, $db, $phpEx, $phpbb_root_path;
1.206 +
1.207 + if ($action == 'lock' || $action == 'unlock')
1.208 + {
1.209 + $table = TOPICS_TABLE;
1.210 + $sql_id = 'topic_id';
1.211 + $set_id = 'topic_status';
1.212 + $l_prefix = 'TOPIC';
1.213 + }
1.214 + else
1.215 + {
1.216 + $table = POSTS_TABLE;
1.217 + $sql_id = 'post_id';
1.218 + $set_id = 'post_edit_locked';
1.219 + $l_prefix = 'POST';
1.220 + }
1.221 +
1.222 + $orig_ids = $ids;
1.223 +
1.224 + if (!check_ids($ids, $table, $sql_id, array('m_lock')))
1.225 + {
1.226 + // Make sure that for f_user_lock only the lock action is triggered.
1.227 + if ($action != 'lock')
1.228 + {
1.229 + return;
1.230 + }
1.231 +
1.232 + $ids = $orig_ids;
1.233 +
1.234 + if (!check_ids($ids, $table, $sql_id, array('f_user_lock')))
1.235 + {
1.236 + return;
1.237 + }
1.238 + }
1.239 + unset($orig_ids);
1.240 +
1.241 + $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
1.242 +
1.243 + $s_hidden_fields = build_hidden_fields(array(
1.244 + $sql_id . '_list' => $ids,
1.245 + 'action' => $action,
1.246 + 'redirect' => $redirect)
1.247 + );
1.248 + $success_msg = '';
1.249 +
1.250 + if (confirm_box(true))
1.251 + {
1.252 + $sql = "UPDATE $table
1.253 + SET $set_id = " . (($action == 'lock' || $action == 'lock_post') ? ITEM_LOCKED : ITEM_UNLOCKED) . '
1.254 + WHERE ' . $db->sql_in_set($sql_id, $ids);
1.255 + $db->sql_query($sql);
1.256 +
1.257 + $data = ($action == 'lock' || $action == 'unlock') ? get_topic_data($ids) : get_post_data($ids);
1.258 +
1.259 + foreach ($data as $id => $row)
1.260 + {
1.261 + add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_' . strtoupper($action), $row['topic_title']);
1.262 + }
1.263 +
1.264 + $success_msg = $l_prefix . ((sizeof($ids) == 1) ? '' : 'S') . '_' . (($action == 'lock' || $action == 'lock_post') ? 'LOCKED' : 'UNLOCKED') . '_SUCCESS';
1.265 + }
1.266 + else
1.267 + {
1.268 + confirm_box(false, strtoupper($action) . '_' . $l_prefix . ((sizeof($ids) == 1) ? '' : 'S'), $s_hidden_fields);
1.269 + }
1.270 +
1.271 + $redirect = request_var('redirect', "index.$phpEx");
1.272 + $redirect = reapply_sid($redirect);
1.273 +
1.274 + if (!$success_msg)
1.275 + {
1.276 + redirect($redirect);
1.277 + }
1.278 + else
1.279 + {
1.280 + meta_refresh(2, $redirect);
1.281 + trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
1.282 + }
1.283 +}
1.284 +
1.285 +/**
1.286 +* Change Topic Type
1.287 +*/
1.288 +function change_topic_type($action, $topic_ids)
1.289 +{
1.290 + global $auth, $user, $db, $phpEx, $phpbb_root_path;
1.291 +
1.292 + switch ($action)
1.293 + {
1.294 + case 'make_announce':
1.295 + $new_topic_type = POST_ANNOUNCE;
1.296 + $check_acl = 'f_announce';
1.297 + $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_ANNOUNCEMENT' : 'MCP_MAKE_ANNOUNCEMENTS';
1.298 + break;
1.299 +
1.300 + case 'make_global':
1.301 + $new_topic_type = POST_GLOBAL;
1.302 + $check_acl = 'f_announce';
1.303 + $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_GLOBAL' : 'MCP_MAKE_GLOBALS';
1.304 + break;
1.305 +
1.306 + case 'make_sticky':
1.307 + $new_topic_type = POST_STICKY;
1.308 + $check_acl = 'f_sticky';
1.309 + $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_STICKY' : 'MCP_MAKE_STICKIES';
1.310 + break;
1.311 +
1.312 + default:
1.313 + $new_topic_type = POST_NORMAL;
1.314 + $check_acl = false;
1.315 + $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_NORMAL' : 'MCP_MAKE_NORMALS';
1.316 + break;
1.317 + }
1.318 +
1.319 + $forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', $check_acl, true);
1.320 +
1.321 + if ($forum_id === false)
1.322 + {
1.323 + return;
1.324 + }
1.325 +
1.326 + $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
1.327 +
1.328 + $s_hidden_fields = array(
1.329 + 'topic_id_list' => $topic_ids,
1.330 + 'f' => $forum_id,
1.331 + 'action' => $action,
1.332 + 'redirect' => $redirect,
1.333 + );
1.334 + $success_msg = '';
1.335 +
1.336 + if (confirm_box(true))
1.337 + {
1.338 + if ($new_topic_type != POST_GLOBAL)
1.339 + {
1.340 + $sql = 'UPDATE ' . TOPICS_TABLE . "
1.341 + SET topic_type = $new_topic_type
1.342 + WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
1.343 + AND forum_id <> 0';
1.344 + $db->sql_query($sql);
1.345 +
1.346 + // Reset forum id if a global topic is within the array
1.347 + $to_forum_id = request_var('to_forum_id', 0);
1.348 +
1.349 + if ($to_forum_id)
1.350 + {
1.351 + $sql = 'UPDATE ' . TOPICS_TABLE . "
1.352 + SET topic_type = $new_topic_type, forum_id = $to_forum_id
1.353 + WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
1.354 + AND forum_id = 0';
1.355 + $db->sql_query($sql);
1.356 +
1.357 + // Update forum_ids for all posts
1.358 + $sql = 'UPDATE ' . POSTS_TABLE . "
1.359 + SET forum_id = $to_forum_id
1.360 + WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
1.361 + AND forum_id = 0';
1.362 + $db->sql_query($sql);
1.363 +
1.364 + // Do a little forum sync stuff
1.365 + $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
1.366 + FROM ' . TOPICS_TABLE . ' t
1.367 + WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
1.368 + $result = $db->sql_query($sql);
1.369 + $row_data = $db->sql_fetchrow($result);
1.370 + $db->sql_freeresult($result);
1.371 +
1.372 + $sync_sql = array();
1.373 +
1.374 + if ($row_data['topic_posts'])
1.375 + {
1.376 + $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . (int) $row_data['topic_posts'];
1.377 + }
1.378 +
1.379 + if ($row_data['topics_authed'])
1.380 + {
1.381 + $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $row_data['topics_authed'];
1.382 + }
1.383 +
1.384 + $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) sizeof($topic_ids);
1.385 +
1.386 + foreach ($sync_sql as $forum_id_key => $array)
1.387 + {
1.388 + $sql = 'UPDATE ' . FORUMS_TABLE . '
1.389 + SET ' . implode(', ', $array) . '
1.390 + WHERE forum_id = ' . $forum_id_key;
1.391 + $db->sql_query($sql);
1.392 + }
1.393 +
1.394 + sync('forum', 'forum_id', $to_forum_id);
1.395 + }
1.396 + }
1.397 + else
1.398 + {
1.399 + // Get away with those topics already being a global announcement by re-calculating $topic_ids
1.400 + $sql = 'SELECT topic_id
1.401 + FROM ' . TOPICS_TABLE . '
1.402 + WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
1.403 + AND forum_id <> 0';
1.404 + $result = $db->sql_query($sql);
1.405 +
1.406 + $topic_ids = array();
1.407 + while ($row = $db->sql_fetchrow($result))
1.408 + {
1.409 + $topic_ids[] = $row['topic_id'];
1.410 + }
1.411 + $db->sql_freeresult($result);
1.412 +
1.413 + if (sizeof($topic_ids))
1.414 + {
1.415 + // Delete topic shadows for global announcements
1.416 + $sql = 'DELETE FROM ' . TOPICS_TABLE . '
1.417 + WHERE ' . $db->sql_in_set('topic_moved_id', $topic_ids);
1.418 + $db->sql_query($sql);
1.419 +
1.420 + $sql = 'UPDATE ' . TOPICS_TABLE . "
1.421 + SET topic_type = $new_topic_type, forum_id = 0
1.422 + WHERE " . $db->sql_in_set('topic_id', $topic_ids);
1.423 + $db->sql_query($sql);
1.424 +
1.425 + // Update forum_ids for all posts
1.426 + $sql = 'UPDATE ' . POSTS_TABLE . '
1.427 + SET forum_id = 0
1.428 + WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
1.429 + $db->sql_query($sql);
1.430 +
1.431 + // Do a little forum sync stuff
1.432 + $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
1.433 + FROM ' . TOPICS_TABLE . ' t
1.434 + WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
1.435 + $result = $db->sql_query($sql);
1.436 + $row_data = $db->sql_fetchrow($result);
1.437 + $db->sql_freeresult($result);
1.438 +
1.439 + $sync_sql = array();
1.440 +
1.441 + if ($row_data['topic_posts'])
1.442 + {
1.443 + $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts'];
1.444 + }
1.445 +
1.446 + if ($row_data['topics_authed'])
1.447 + {
1.448 + $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $row_data['topics_authed'];
1.449 + }
1.450 +
1.451 + $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) sizeof($topic_ids);
1.452 +
1.453 + foreach ($sync_sql as $forum_id_key => $array)
1.454 + {
1.455 + $sql = 'UPDATE ' . FORUMS_TABLE . '
1.456 + SET ' . implode(', ', $array) . '
1.457 + WHERE forum_id = ' . $forum_id_key;
1.458 + $db->sql_query($sql);
1.459 + }
1.460 +
1.461 + sync('forum', 'forum_id', $forum_id);
1.462 + }
1.463 + }
1.464 +
1.465 + $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_TYPE_CHANGED' : 'TOPICS_TYPE_CHANGED';
1.466 +
1.467 + if (sizeof($topic_ids))
1.468 + {
1.469 + $data = get_topic_data($topic_ids);
1.470 +
1.471 + foreach ($data as $topic_id => $row)
1.472 + {
1.473 + add_log('mod', $forum_id, $topic_id, 'LOG_TOPIC_TYPE_CHANGED', $row['topic_title']);
1.474 + }
1.475 + }
1.476 + }
1.477 + else
1.478 + {
1.479 + // Global topic involved?
1.480 + $global_involved = false;
1.481 +
1.482 + if ($new_topic_type != POST_GLOBAL)
1.483 + {
1.484 + $sql = 'SELECT forum_id
1.485 + FROM ' . TOPICS_TABLE . '
1.486 + WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
1.487 + AND forum_id = 0';
1.488 + $result = $db->sql_query($sql);
1.489 + $row = $db->sql_fetchrow($result);
1.490 + $db->sql_freeresult($result);
1.491 +
1.492 + if ($row)
1.493 + {
1.494 + $global_involved = true;
1.495 + }
1.496 + }
1.497 +
1.498 + if ($global_involved)
1.499 + {
1.500 + global $template;
1.501 +
1.502 + $template->assign_vars(array(
1.503 + 'S_FORUM_SELECT' => make_forum_select(request_var('f', $forum_id), false, false, true, true),
1.504 + 'S_CAN_LEAVE_SHADOW' => false,
1.505 + 'ADDITIONAL_MSG' => (sizeof($topic_ids) == 1) ? $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENT'] : $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENTS'])
1.506 + );
1.507 +
1.508 + confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields), 'mcp_move.html');
1.509 + }
1.510 + else
1.511 + {
1.512 + confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields));
1.513 + }
1.514 + }
1.515 +
1.516 + $redirect = request_var('redirect', "index.$phpEx");
1.517 + $redirect = reapply_sid($redirect);
1.518 +
1.519 + if (!$success_msg)
1.520 + {
1.521 + redirect($redirect);
1.522 + }
1.523 + else
1.524 + {
1.525 + meta_refresh(2, $redirect);
1.526 + trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
1.527 + }
1.528 +}
1.529 +
1.530 +/**
1.531 +* Move Topic
1.532 +*/
1.533 +function mcp_move_topic($topic_ids)
1.534 +{
1.535 + global $auth, $user, $db, $template;
1.536 + global $phpEx, $phpbb_root_path;
1.537 +
1.538 + // Here we limit the operation to one forum only
1.539 + $forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_move'), true);
1.540 +
1.541 + if ($forum_id === false)
1.542 + {
1.543 + return;
1.544 + }
1.545 +
1.546 + $to_forum_id = request_var('to_forum_id', 0);
1.547 + $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
1.548 + $additional_msg = $success_msg = '';
1.549 +
1.550 + $s_hidden_fields = build_hidden_fields(array(
1.551 + 'topic_id_list' => $topic_ids,
1.552 + 'f' => $forum_id,
1.553 + 'action' => 'move',
1.554 + 'redirect' => $redirect)
1.555 + );
1.556 +
1.557 + if ($to_forum_id)
1.558 + {
1.559 + $forum_data = get_forum_data($to_forum_id, 'f_post');
1.560 +
1.561 + if (!sizeof($forum_data))
1.562 + {
1.563 + $additional_msg = $user->lang['FORUM_NOT_EXIST'];
1.564 + }
1.565 + else
1.566 + {
1.567 + $forum_data = $forum_data[$to_forum_id];
1.568 +
1.569 + if ($forum_data['forum_type'] != FORUM_POST)
1.570 + {
1.571 + $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
1.572 + }
1.573 + else if (!$auth->acl_get('f_post', $to_forum_id) || (!$auth->acl_get('m_approve', $to_forum_id) && !$auth->acl_get('f_noapprove', $to_forum_id)))
1.574 + {
1.575 + $additional_msg = $user->lang['USER_CANNOT_POST'];
1.576 + }
1.577 + else if ($forum_id == $to_forum_id)
1.578 + {
1.579 + $additional_msg = $user->lang['CANNOT_MOVE_SAME_FORUM'];
1.580 + }
1.581 + }
1.582 + }
1.583 + else if (isset($_POST['confirm']))
1.584 + {
1.585 + $additional_msg = $user->lang['FORUM_NOT_EXIST'];
1.586 + }
1.587 +
1.588 + if (!$to_forum_id || $additional_msg)
1.589 + {
1.590 + unset($_POST['confirm']);
1.591 + unset($_REQUEST['confirm_key']);
1.592 + }
1.593 +
1.594 + if (confirm_box(true))
1.595 + {
1.596 + $topic_data = get_topic_data($topic_ids);
1.597 + $leave_shadow = (isset($_POST['move_leave_shadow'])) ? true : false;
1.598 +
1.599 + $forum_sync_data = array();
1.600 +
1.601 + $forum_sync_data[$forum_id] = current($topic_data);
1.602 + $forum_sync_data[$to_forum_id] = $forum_data;
1.603 +
1.604 + // Real topics added to target forum
1.605 + $topics_moved = sizeof($topic_data);
1.606 +
1.607 + // Approved topics added to target forum
1.608 + $topics_authed_moved = 0;
1.609 +
1.610 + // Posts (topic replies + topic post if approved) added to target forum
1.611 + $topic_posts_added = 0;
1.612 +
1.613 + // Posts (topic replies + topic post if approved and not global announcement) removed from source forum
1.614 + $topic_posts_removed = 0;
1.615 +
1.616 + // Real topics removed from source forum (all topics without global announcements)
1.617 + $topics_removed = 0;
1.618 +
1.619 + // Approved topics removed from source forum (except global announcements)
1.620 + $topics_authed_removed = 0;
1.621 +
1.622 + foreach ($topic_data as $topic_id => $topic_info)
1.623 + {
1.624 + if ($topic_info['topic_approved'])
1.625 + {
1.626 + $topics_authed_moved++;
1.627 + $topic_posts_added++;
1.628 + }
1.629 +
1.630 + $topic_posts_added += $topic_info['topic_replies'];
1.631 +
1.632 + if ($topic_info['topic_type'] != POST_GLOBAL)
1.633 + {
1.634 + $topics_removed++;
1.635 + $topic_posts_removed += $topic_info['topic_replies'];
1.636 +
1.637 + if ($topic_info['topic_approved'])
1.638 + {
1.639 + $topics_authed_removed++;
1.640 + $topic_posts_removed++;
1.641 + }
1.642 + }
1.643 + }
1.644 +
1.645 + $db->sql_transaction('begin');
1.646 +
1.647 + $sync_sql = array();
1.648 +
1.649 + if ($topic_posts_added)
1.650 + {
1.651 + $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $topic_posts_added;
1.652 + }
1.653 +
1.654 + if ($topics_authed_moved)
1.655 + {
1.656 + $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_authed_moved;
1.657 + }
1.658 +
1.659 + $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved;
1.660 +
1.661 + // Move topics, but do not resync yet
1.662 + move_topics($topic_ids, $to_forum_id, false);
1.663 +
1.664 + $forum_ids = array($to_forum_id);
1.665 + foreach ($topic_data as $topic_id => $row)
1.666 + {
1.667 + // Get the list of forums to resync, add a log entry
1.668 + $forum_ids[] = $row['forum_id'];
1.669 + add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name'], $forum_data['forum_name']);
1.670 +
1.671 + // If we have moved a global announcement, we need to correct the topic type
1.672 + if ($row['topic_type'] == POST_GLOBAL)
1.673 + {
1.674 + $sql = 'UPDATE ' . TOPICS_TABLE . '
1.675 + SET topic_type = ' . POST_ANNOUNCE . '
1.676 + WHERE topic_id = ' . (int) $row['topic_id'];
1.677 + $db->sql_query($sql);
1.678 + }
1.679 +
1.680 + // Leave a redirection if required and only if the topic is visible to users
1.681 + if ($leave_shadow && $row['topic_approved'] && $row['topic_type'] != POST_GLOBAL)
1.682 + {
1.683 + $shadow = array(
1.684 + 'forum_id' => (int) $row['forum_id'],
1.685 + 'icon_id' => (int) $row['icon_id'],
1.686 + 'topic_attachment' => (int) $row['topic_attachment'],
1.687 + 'topic_approved' => 1, // a shadow topic is always approved
1.688 + 'topic_reported' => 0, // a shadow topic is never reported
1.689 + 'topic_title' => (string) $row['topic_title'],
1.690 + 'topic_poster' => (int) $row['topic_poster'],
1.691 + 'topic_time' => (int) $row['topic_time'],
1.692 + 'topic_time_limit' => (int) $row['topic_time_limit'],
1.693 + 'topic_views' => (int) $row['topic_views'],
1.694 + 'topic_replies' => (int) $row['topic_replies'],
1.695 + 'topic_replies_real' => (int) $row['topic_replies_real'],
1.696 + 'topic_status' => ITEM_MOVED,
1.697 + 'topic_type' => POST_NORMAL,
1.698 + 'topic_first_post_id' => (int) $row['topic_first_post_id'],
1.699 + 'topic_first_poster_colour'=>(string) $row['topic_first_poster_colour'],
1.700 + 'topic_first_poster_name'=> (string) $row['topic_first_poster_name'],
1.701 + 'topic_last_post_id' => (int) $row['topic_last_post_id'],
1.702 + 'topic_last_poster_id' => (int) $row['topic_last_poster_id'],
1.703 + 'topic_last_poster_colour'=>(string) $row['topic_last_poster_colour'],
1.704 + 'topic_last_poster_name'=> (string) $row['topic_last_poster_name'],
1.705 + 'topic_last_post_subject'=> (string) $row['topic_last_post_subject'],
1.706 + 'topic_last_post_time' => (int) $row['topic_last_post_time'],
1.707 + 'topic_last_view_time' => (int) $row['topic_last_view_time'],
1.708 + 'topic_moved_id' => (int) $row['topic_id'],
1.709 + 'topic_bumped' => (int) $row['topic_bumped'],
1.710 + 'topic_bumper' => (int) $row['topic_bumper'],
1.711 + 'poll_title' => (string) $row['poll_title'],
1.712 + 'poll_start' => (int) $row['poll_start'],
1.713 + 'poll_length' => (int) $row['poll_length'],
1.714 + 'poll_max_options' => (int) $row['poll_max_options'],
1.715 + 'poll_last_vote' => (int) $row['poll_last_vote']
1.716 + );
1.717 +
1.718 + $db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow));
1.719 +
1.720 + // Shadow topics only count on new "topics" and not posts... a shadow topic alone has 0 posts
1.721 + $topics_removed--;
1.722 + $topics_authed_removed--;
1.723 + }
1.724 + }
1.725 + unset($topic_data);
1.726 +
1.727 + if ($topic_posts_removed)
1.728 + {
1.729 + $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . $topic_posts_removed;
1.730 + }
1.731 +
1.732 + if ($topics_removed)
1.733 + {
1.734 + $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) $topics_removed;
1.735 + }
1.736 +
1.737 + if ($topics_authed_removed)
1.738 + {
1.739 + $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $topics_authed_removed;
1.740 + }
1.741 +
1.742 + $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS';
1.743 +
1.744 + foreach ($sync_sql as $forum_id_key => $array)
1.745 + {
1.746 + $sql = 'UPDATE ' . FORUMS_TABLE . '
1.747 + SET ' . implode(', ', $array) . '
1.748 + WHERE forum_id = ' . $forum_id_key;
1.749 + $db->sql_query($sql);
1.750 + }
1.751 +
1.752 + $db->sql_transaction('commit');
1.753 +
1.754 + sync('forum', 'forum_id', array($forum_id, $to_forum_id));
1.755 + }
1.756 + else
1.757 + {
1.758 + $template->assign_vars(array(
1.759 + 'S_FORUM_SELECT' => make_forum_select($to_forum_id, $forum_id, false, true, true, true),
1.760 + 'S_CAN_LEAVE_SHADOW' => true,
1.761 + 'ADDITIONAL_MSG' => $additional_msg)
1.762 + );
1.763 +
1.764 + confirm_box(false, 'MOVE_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
1.765 + }
1.766 +
1.767 + $redirect = request_var('redirect', "index.$phpEx");
1.768 + $redirect = reapply_sid($redirect);
1.769 +
1.770 + if (!$success_msg)
1.771 + {
1.772 + redirect($redirect);
1.773 + }
1.774 + else
1.775 + {
1.776 + meta_refresh(3, $redirect);
1.777 +
1.778 + $message = $user->lang[$success_msg];
1.779 + $message .= '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
1.780 + $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id") . '">', '</a>');
1.781 + $message .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$to_forum_id") . '">', '</a>');
1.782 +
1.783 + trigger_error($message);
1.784 + }
1.785 +}
1.786 +
1.787 +/**
1.788 +* Delete Topics
1.789 +*/
1.790 +function mcp_delete_topic($topic_ids)
1.791 +{
1.792 + global $auth, $user, $db, $phpEx, $phpbb_root_path;
1.793 +
1.794 + if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete')))
1.795 + {
1.796 + return;
1.797 + }
1.798 +
1.799 + $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
1.800 + $forum_id = request_var('f', 0);
1.801 +
1.802 + $s_hidden_fields = build_hidden_fields(array(
1.803 + 'topic_id_list' => $topic_ids,
1.804 + 'f' => $forum_id,
1.805 + 'action' => 'delete_topic',
1.806 + 'redirect' => $redirect)
1.807 + );
1.808 + $success_msg = '';
1.809 +
1.810 + if (confirm_box(true))
1.811 + {
1.812 + $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS';
1.813 +
1.814 + $data = get_topic_data($topic_ids);
1.815 +
1.816 + foreach ($data as $topic_id => $row)
1.817 + {
1.818 + if ($row['topic_moved_id'])
1.819 + {
1.820 + add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_SHADOW_TOPIC', $row['topic_title']);
1.821 + }
1.822 + else
1.823 + {
1.824 + add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']);
1.825 + }
1.826 + }
1.827 +
1.828 + $return = delete_topics('topic_id', $topic_ids);
1.829 + }
1.830 + else
1.831 + {
1.832 + confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields);
1.833 + }
1.834 +
1.835 + if (!isset($_REQUEST['quickmod']))
1.836 + {
1.837 + $redirect = request_var('redirect', "index.$phpEx");
1.838 + $redirect = reapply_sid($redirect);
1.839 + $redirect_message = 'PAGE';
1.840 + }
1.841 + else
1.842 + {
1.843 + $redirect = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
1.844 + $redirect_message = 'FORUM';
1.845 + }
1.846 +
1.847 + if (!$success_msg)
1.848 + {
1.849 + redirect($redirect);
1.850 + }
1.851 + else
1.852 + {
1.853 + meta_refresh(3, $redirect);
1.854 + trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_' . $redirect_message], '<a href="' . $redirect . '">', '</a>'));
1.855 + }
1.856 +}
1.857 +
1.858 +/**
1.859 +* Delete Posts
1.860 +*/
1.861 +function mcp_delete_post($post_ids)
1.862 +{
1.863 + global $auth, $user, $db, $phpEx, $phpbb_root_path;
1.864 +
1.865 + if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_delete')))
1.866 + {
1.867 + return;
1.868 + }
1.869 +
1.870 + $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
1.871 + $forum_id = request_var('f', 0);
1.872 +
1.873 + $s_hidden_fields = build_hidden_fields(array(
1.874 + 'post_id_list' => $post_ids,
1.875 + 'f' => $forum_id,
1.876 + 'action' => 'delete_post',
1.877 + 'redirect' => $redirect)
1.878 + );
1.879 + $success_msg = '';
1.880 +
1.881 + if (confirm_box(true))
1.882 + {
1.883 + if (!function_exists('delete_posts'))
1.884 + {
1.885 + include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
1.886 + }
1.887 +
1.888 + // Count the number of topics that are affected
1.889 + // I did not use COUNT(DISTINCT ...) because I remember having problems
1.890 + // with it on older versions of MySQL -- Ashe
1.891 +
1.892 + $sql = 'SELECT DISTINCT topic_id
1.893 + FROM ' . POSTS_TABLE . '
1.894 + WHERE ' . $db->sql_in_set('post_id', $post_ids);
1.895 + $result = $db->sql_query($sql);
1.896 +
1.897 + $topic_id_list = array();
1.898 + while ($row = $db->sql_fetchrow($result))
1.899 + {
1.900 + $topic_id_list[] = $row['topic_id'];
1.901 + }
1.902 + $affected_topics = sizeof($topic_id_list);
1.903 + $db->sql_freeresult($result);
1.904 +
1.905 + $post_data = get_post_data($post_ids);
1.906 +
1.907 + foreach ($post_data as $id => $row)
1.908 + {
1.909 + $post_username = ($row['poster_id'] == ANONYMOUS && !empty($row['post_username'])) ? $row['post_username'] : $row['username'];
1.910 + add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_DELETE_POST', $row['post_subject'], $post_username);
1.911 + }
1.912 +
1.913 + // Now delete the posts, topics and forums are automatically resync'ed
1.914 + delete_posts('post_id', $post_ids);
1.915 +
1.916 + $sql = 'SELECT COUNT(topic_id) AS topics_left
1.917 + FROM ' . TOPICS_TABLE . '
1.918 + WHERE ' . $db->sql_in_set('topic_id', $topic_id_list);
1.919 + $result = $db->sql_query_limit($sql, 1);
1.920 +
1.921 + $deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics;
1.922 + $db->sql_freeresult($result);
1.923 +
1.924 + $topic_id = request_var('t', 0);
1.925 +
1.926 + // Return links
1.927 + $return_link = array();
1.928 + if ($affected_topics == 1 && !$deleted_topics && $topic_id)
1.929 + {
1.930 + $return_link[] = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id") . '">', '</a>');
1.931 + }
1.932 + $return_link[] = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
1.933 +
1.934 + if (sizeof($post_ids) == 1)
1.935 + {
1.936 + if ($deleted_topics)
1.937 + {
1.938 + // We deleted the only post of a topic, which in turn has
1.939 + // been removed from the database
1.940 + $success_msg = $user->lang['TOPIC_DELETED_SUCCESS'];
1.941 + }
1.942 + else
1.943 + {
1.944 + $success_msg = $user->lang['POST_DELETED_SUCCESS'];
1.945 + }
1.946 + }
1.947 + else
1.948 + {
1.949 + if ($deleted_topics)
1.950 + {
1.951 + // Some of topics disappeared
1.952 + $success_msg = $user->lang['POSTS_DELETED_SUCCESS'] . '<br /><br />' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING'];
1.953 + }
1.954 + else
1.955 + {
1.956 + $success_msg = $user->lang['POSTS_DELETED_SUCCESS'];
1.957 + }
1.958 + }
1.959 + }
1.960 + else
1.961 + {
1.962 + confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields);
1.963 + }
1.964 +
1.965 + $redirect = request_var('redirect', "index.$phpEx");
1.966 + $redirect = reapply_sid($redirect);
1.967 +
1.968 + if (!$success_msg)
1.969 + {
1.970 + redirect($redirect);
1.971 + }
1.972 + else
1.973 + {
1.974 + if ($affected_topics != 1 || $deleted_topics || !$topic_id)
1.975 + {
1.976 + $redirect = append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&i=main&mode=forum_view", false);
1.977 + }
1.978 +
1.979 + meta_refresh(3, $redirect);
1.980 + trigger_error($success_msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>') . '<br /><br />' . implode('<br /><br />', $return_link));
1.981 + }
1.982 +}
1.983 +
1.984 +/**
1.985 +* Fork Topic
1.986 +*/
1.987 +function mcp_fork_topic($topic_ids)
1.988 +{
1.989 + global $auth, $user, $db, $template, $config;
1.990 + global $phpEx, $phpbb_root_path;
1.991 +
1.992 + if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_')))
1.993 + {
1.994 + return;
1.995 + }
1.996 +
1.997 + $to_forum_id = request_var('to_forum_id', 0);
1.998 + $forum_id = request_var('f', 0);
1.999 + $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
1.1000 + $additional_msg = $success_msg = '';
1.1001 +
1.1002 + $s_hidden_fields = build_hidden_fields(array(
1.1003 + 'topic_id_list' => $topic_ids,
1.1004 + 'f' => $forum_id,
1.1005 + 'action' => 'fork',
1.1006 + 'redirect' => $redirect)
1.1007 + );
1.1008 +
1.1009 + if ($to_forum_id)
1.1010 + {
1.1011 + $forum_data = get_forum_data($to_forum_id, 'f_post');
1.1012 +
1.1013 + if (!sizeof($topic_ids))
1.1014 + {
1.1015 + $additional_msg = $user->lang['NO_TOPIC_SELECTED'];
1.1016 + }
1.1017 + else if (!sizeof($forum_data))
1.1018 + {
1.1019 + $additional_msg = $user->lang['FORUM_NOT_EXIST'];
1.1020 + }
1.1021 + else
1.1022 + {
1.1023 + $forum_data = $forum_data[$to_forum_id];
1.1024 +
1.1025 + if ($forum_data['forum_type'] != FORUM_POST)
1.1026 + {
1.1027 + $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
1.1028 + }
1.1029 + else if (!$auth->acl_get('f_post', $to_forum_id))
1.1030 + {
1.1031 + $additional_msg = $user->lang['USER_CANNOT_POST'];
1.1032 + }
1.1033 + }
1.1034 + }
1.1035 + else if (isset($_POST['confirm']))
1.1036 + {
1.1037 + $additional_msg = $user->lang['FORUM_NOT_EXIST'];
1.1038 + }
1.1039 +
1.1040 + if ($additional_msg)
1.1041 + {
1.1042 + unset($_POST['confirm']);
1.1043 + unset($_REQUEST['confirm_key']);
1.1044 + }
1.1045 +
1.1046 + if (confirm_box(true))
1.1047 + {
1.1048 + $topic_data = get_topic_data($topic_ids, 'f_post');
1.1049 +
1.1050 + $total_posts = 0;
1.1051 + $new_topic_id_list = array();
1.1052 +
1.1053 +
1.1054 + foreach ($topic_data as $topic_id => $topic_row)
1.1055 + {
1.1056 + if (!isset($search_type) && $topic_row['enable_indexing'])
1.1057 + {
1.1058 + // Select the search method and do some additional checks to ensure it can actually be utilised
1.1059 + $search_type = basename($config['search_type']);
1.1060 +
1.1061 + if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
1.1062 + {
1.1063 + trigger_error('NO_SUCH_SEARCH_MODULE');
1.1064 + }
1.1065 +
1.1066 + if (!class_exists($search_type))
1.1067 + {
1.1068 + include("{$phpbb_root_path}includes/search/$search_type.$phpEx");
1.1069 + }
1.1070 +
1.1071 + $error = false;
1.1072 + $search = new $search_type($error);
1.1073 + $search_mode = 'post';
1.1074 +
1.1075 + if ($error)
1.1076 + {
1.1077 + trigger_error($error);
1.1078 + }
1.1079 + }
1.1080 + else if (!isset($search_type) && !$topic_row['enable_indexing'])
1.1081 + {
1.1082 + $search_type = false;
1.1083 + }
1.1084 +
1.1085 + $sql_ary = array(
1.1086 + 'forum_id' => (int) $to_forum_id,
1.1087 + 'icon_id' => (int) $topic_row['icon_id'],
1.1088 + 'topic_attachment' => (int) $topic_row['topic_attachment'],
1.1089 + 'topic_approved' => 1,
1.1090 + 'topic_reported' => 0,
1.1091 + 'topic_title' => (string) $topic_row['topic_title'],
1.1092 + 'topic_poster' => (int) $topic_row['topic_poster'],
1.1093 + 'topic_time' => (int) $topic_row['topic_time'],
1.1094 + 'topic_replies' => (int) $topic_row['topic_replies_real'],
1.1095 + 'topic_replies_real' => (int) $topic_row['topic_replies_real'],
1.1096 + 'topic_status' => (int) $topic_row['topic_status'],
1.1097 + 'topic_type' => (int) $topic_row['topic_type'],
1.1098 + 'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'],
1.1099 + 'topic_last_poster_id' => (int) $topic_row['topic_last_poster_id'],
1.1100 + 'topic_last_poster_name' => (string) $topic_row['topic_last_poster_name'],
1.1101 + 'topic_last_post_time' => (int) $topic_row['topic_last_post_time'],
1.1102 + 'topic_last_view_time' => (int) $topic_row['topic_last_view_time'],
1.1103 + 'topic_bumped' => (int) $topic_row['topic_bumped'],
1.1104 + 'topic_bumper' => (int) $topic_row['topic_bumper'],
1.1105 + 'poll_title' => (string) $topic_row['poll_title'],
1.1106 + 'poll_start' => (int) $topic_row['poll_start'],
1.1107 + 'poll_length' => (int) $topic_row['poll_length'],
1.1108 + 'poll_max_options' => (int) $topic_row['poll_max_options'],
1.1109 + 'poll_vote_change' => (int) $topic_row['poll_vote_change'],
1.1110 + );
1.1111 +
1.1112 + $db->sql_query('INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1.1113 + $new_topic_id = $db->sql_nextid();
1.1114 + $new_topic_id_list[$topic_id] = $new_topic_id;
1.1115 +
1.1116 + if ($topic_row['poll_start'])
1.1117 + {
1.1118 + $poll_rows = array();
1.1119 +
1.1120 + $sql = 'SELECT *
1.1121 + FROM ' . POLL_OPTIONS_TABLE . "
1.1122 + WHERE topic_id = $topic_id";
1.1123 + $result = $db->sql_query($sql);
1.1124 +
1.1125 + while ($row = $db->sql_fetchrow($result))
1.1126 + {
1.1127 + $sql_ary = array(
1.1128 + 'poll_option_id' => (int) $row['poll_option_id'],
1.1129 + 'topic_id' => (int) $new_topic_id,
1.1130 + 'poll_option_text' => (string) $row['poll_option_text'],
1.1131 + 'poll_option_total' => 0
1.1132 + );
1.1133 +
1.1134 + $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1.1135 + }
1.1136 + }
1.1137 +
1.1138 + $sql = 'SELECT *
1.1139 + FROM ' . POSTS_TABLE . "
1.1140 + WHERE topic_id = $topic_id
1.1141 + ORDER BY post_time ASC";
1.1142 + $result = $db->sql_query($sql);
1.1143 +
1.1144 + $post_rows = array();
1.1145 + while ($row = $db->sql_fetchrow($result))
1.1146 + {
1.1147 + $post_rows[] = $row;
1.1148 + }
1.1149 + $db->sql_freeresult($result);
1.1150 +
1.1151 + if (!sizeof($post_rows))
1.1152 + {
1.1153 + continue;
1.1154 + }
1.1155 +
1.1156 + $total_posts += sizeof($post_rows);
1.1157 + foreach ($post_rows as $row)
1.1158 + {
1.1159 + $sql_ary = array(
1.1160 + 'topic_id' => (int) $new_topic_id,
1.1161 + 'forum_id' => (int) $to_forum_id,
1.1162 + 'poster_id' => (int) $row['poster_id'],
1.1163 + 'icon_id' => (int) $row['icon_id'],
1.1164 + 'poster_ip' => (string) $row['poster_ip'],
1.1165 + 'post_time' => (int) $row['post_time'],
1.1166 + 'post_approved' => 1,
1.1167 + 'post_reported' => 0,
1.1168 + 'enable_bbcode' => (int) $row['enable_bbcode'],
1.1169 + 'enable_smilies' => (int) $row['enable_smilies'],
1.1170 + 'enable_magic_url' => (int) $row['enable_magic_url'],
1.1171 + 'enable_sig' => (int) $row['enable_sig'],
1.1172 + 'post_username' => (string) $row['post_username'],
1.1173 + 'post_subject' => (string) $row['post_subject'],
1.1174 + 'post_text' => (string) $row['post_text'],
1.1175 + 'post_edit_reason' => (string) $row['post_edit_reason'],
1.1176 + 'post_edit_user' => (int) $row['post_edit_user'],
1.1177 + 'post_checksum' => (string) $row['post_checksum'],
1.1178 + 'post_attachment' => (int) $row['post_attachment'],
1.1179 + 'bbcode_bitfield' => $row['bbcode_bitfield'],
1.1180 + 'bbcode_uid' => (string) $row['bbcode_uid'],
1.1181 + 'post_edit_time' => (int) $row['post_edit_time'],
1.1182 + 'post_edit_count' => (int) $row['post_edit_count'],
1.1183 + 'post_edit_locked' => (int) $row['post_edit_locked'],
1.1184 + 'post_postcount' => 0,
1.1185 + );
1.1186 +
1.1187 + $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1.1188 + $new_post_id = $db->sql_nextid();
1.1189 +
1.1190 + // Copy whether the topic is dotted
1.1191 + markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']);
1.1192 +
1.1193 + if (!empty($search_type))
1.1194 + {
1.1195 + $search->index($search_mode, $new_post_id, $sql_ary['post_text'], $sql_ary['post_subject'], $sql_ary['poster_id'], ($topic_row['topic_type'] == POST_GLOBAL) ? 0 : $to_forum_id);
1.1196 + $search_mode = 'reply'; // After one we index replies
1.1197 + }
1.1198 +
1.1199 + // Copy Attachments
1.1200 + if ($row['post_attachment'])
1.1201 + {
1.1202 + $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . "
1.1203 + WHERE post_msg_id = {$row['post_id']}
1.1204 + AND topic_id = $topic_id
1.1205 + AND in_message = 0";
1.1206 + $result = $db->sql_query($sql);
1.1207 +
1.1208 + $sql_ary = array();
1.1209 + while ($attach_row = $db->sql_fetchrow($result))
1.1210 + {
1.1211 + $sql_ary[] = array(
1.1212 + 'post_msg_id' => (int) $new_post_id,
1.1213 + 'topic_id' => (int) $new_topic_id,
1.1214 + 'in_message' => 0,
1.1215 + 'is_orphan' => (int) $attach_row['is_orphan'],
1.1216 + 'poster_id' => (int) $attach_row['poster_id'],
1.1217 + 'physical_filename' => (string) utf8_basename($attach_row['physical_filename']),
1.1218 + 'real_filename' => (string) utf8_basename($attach_row['real_filename']),
1.1219 + 'download_count' => (int) $attach_row['download_count'],
1.1220 + 'attach_comment' => (string) $attach_row['attach_comment'],
1.1221 + 'extension' => (string) $attach_row['extension'],
1.1222 + 'mimetype' => (string) $attach_row['mimetype'],
1.1223 + 'filesize' => (int) $attach_row['filesize'],
1.1224 + 'filetime' => (int) $attach_row['filetime'],
1.1225 + 'thumbnail' => (int) $attach_row['thumbnail']
1.1226 + );
1.1227 + }
1.1228 + $db->sql_freeresult($result);
1.1229 +
1.1230 + if (sizeof($sql_ary))
1.1231 + {
1.1232 + $db->sql_multi_insert(ATTACHMENTS_TABLE, $sql_ary);
1.1233 + }
1.1234 + }
1.1235 + }
1.1236 +
1.1237 + $sql = 'SELECT user_id, notify_status
1.1238 + FROM ' . TOPICS_WATCH_TABLE . '
1.1239 + WHERE topic_id = ' . $topic_id;
1.1240 + $result = $db->sql_query($sql);
1.1241 +
1.1242 + $sql_ary = array();
1.1243 + while ($row = $db->sql_fetchrow($result))
1.1244 + {
1.1245 + $sql_ary[] = array(
1.1246 + 'topic_id' => (int) $new_topic_id,
1.1247 + 'user_id' => (int) $row['user_id'],
1.1248 + 'notify_status' => (int) $row['notify_status'],
1.1249 + );
1.1250 + }
1.1251 + $db->sql_freeresult($result);
1.1252 +
1.1253 + if (sizeof($sql_ary))
1.1254 + {
1.1255 + $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
1.1256 + }
1.1257 + }
1.1258 +
1.1259 + // Sync new topics, parent forums and board stats
1.1260 + sync('topic', 'topic_id', $new_topic_id_list);
1.1261 +
1.1262 + $sync_sql = array();
1.1263 +
1.1264 + $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $total_posts;
1.1265 + $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . sizeof($new_topic_id_list);
1.1266 + $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . sizeof($new_topic_id_list);
1.1267 +
1.1268 + foreach ($sync_sql as $forum_id_key => $array)
1.1269 + {
1.1270 + $sql = 'UPDATE ' . FORUMS_TABLE . '
1.1271 + SET ' . implode(', ', $array) . '
1.1272 + WHERE forum_id = ' . $forum_id_key;
1.1273 + $db->sql_query($sql);
1.1274 + }
1.1275 +
1.1276 + sync('forum', 'forum_id', $to_forum_id);
1.1277 + set_config_count('num_topics', sizeof($new_topic_id_list), true);
1.1278 + set_config_count('num_posts', $total_posts, true);
1.1279 +
1.1280 + foreach ($new_topic_id_list as $topic_id => $new_topic_id)
1.1281 + {
1.1282 + add_log('mod', $to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']);
1.1283 + }
1.1284 +
1.1285 + $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS';
1.1286 + }
1.1287 + else
1.1288 + {
1.1289 + $template->assign_vars(array(
1.1290 + 'S_FORUM_SELECT' => make_forum_select($to_forum_id, false, false, true, true, true),
1.1291 + 'S_CAN_LEAVE_SHADOW' => false,
1.1292 + 'ADDITIONAL_MSG' => $additional_msg)
1.1293 + );
1.1294 +
1.1295 + confirm_box(false, 'FORK_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
1.1296 + }
1.1297 +
1.1298 + $redirect = request_var('redirect', "index.$phpEx");
1.1299 + $redirect = reapply_sid($redirect);
1.1300 +
1.1301 + if (!$success_msg)
1.1302 + {
1.1303 + redirect($redirect);
1.1304 + }
1.1305 + else
1.1306 + {
1.1307 + $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
1.1308 + meta_refresh(3, $redirect_url);
1.1309 + $return_link = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>');
1.1310 +
1.1311 + if ($forum_id != $to_forum_id)
1.1312 + {
1.1313 + $return_link .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $to_forum_id) . '">', '</a>');
1.1314 + }
1.1315 +
1.1316 + trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
1.1317 + }
1.1318 +}
1.1319 +
1.1320 +?>
1.1321 \ No newline at end of file