Verzeichnisstruktur phpBB-3.0.0
- Veröffentlicht
- 12.12.2007
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
mcp_main.php
0001 <?php
0002 /**
0003 *
0004 * @package mcp
0005 * @version $Id$
0006 * @copyright (c) 2005 phpBB Group
0007 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
0008 *
0009 */
0010
0011 /**
0012 * @ignore
0013 */
0014 if (!defined('IN_PHPBB'))
0015 {
0016 exit;
0017 }
0018
0019 /**
0020 * mcp_main
0021 * Handling mcp actions
0022 * @package mcp
0023 */
0024 class mcp_main
0025 {
0026 var $p_master;
0027 var $u_action;
0028
0029 function mcp_main(&$p_master)
0030 {
0031 $this->p_master = &$p_master;
0032 }
0033
0034 function main($id, $mode)
0035 {
0036 global $auth, $db, $user, $template, $action;
0037 global $config, $phpbb_root_path, $phpEx;
0038
0039 $quickmod = ($mode == 'quickmod') ? true : false;
0040
0041 switch ($action)
0042 {
0043 case 'lock':
0044 case 'unlock':
0045 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
0046
0047 if (!sizeof($topic_ids))
0048 {
0049 trigger_error('NO_TOPIC_SELECTED');
0050 }
0051
0052 lock_unlock($action, $topic_ids);
0053 break;
0054
0055 case 'lock_post':
0056 case 'unlock_post':
0057
0058 $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
0059
0060 if (!sizeof($post_ids))
0061 {
0062 trigger_error('NO_POST_SELECTED');
0063 }
0064
0065 lock_unlock($action, $post_ids);
0066 break;
0067
0068 case 'make_announce':
0069 case 'make_sticky':
0070 case 'make_global':
0071 case 'make_normal':
0072
0073 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
0074
0075 if (!sizeof($topic_ids))
0076 {
0077 trigger_error('NO_TOPIC_SELECTED');
0078 }
0079
0080 change_topic_type($action, $topic_ids);
0081 break;
0082
0083 case 'move':
0084 $user->add_lang('viewtopic');
0085
0086 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
0087
0088 if (!sizeof($topic_ids))
0089 {
0090 trigger_error('NO_TOPIC_SELECTED');
0091 }
0092
0093 mcp_move_topic($topic_ids);
0094 break;
0095
0096 case 'fork':
0097 $user->add_lang('viewtopic');
0098
0099 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
0100
0101 if (!sizeof($topic_ids))
0102 {
0103 trigger_error('NO_TOPIC_SELECTED');
0104 }
0105
0106 mcp_fork_topic($topic_ids);
0107 break;
0108
0109 case 'delete_topic':
0110 $user->add_lang('viewtopic');
0111
0112 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
0113
0114 if (!sizeof($topic_ids))
0115 {
0116 trigger_error('NO_TOPIC_SELECTED');
0117 }
0118
0119 mcp_delete_topic($topic_ids);
0120 break;
0121
0122 case 'delete_post':
0123 $user->add_lang('posting');
0124
0125 $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
0126
0127 if (!sizeof($post_ids))
0128 {
0129 trigger_error('NO_POST_SELECTED');
0130 }
0131
0132 mcp_delete_post($post_ids);
0133 break;
0134 }
0135
0136 switch ($mode)
0137 {
0138 case 'front':
0139 include($phpbb_root_path . 'includes/mcp/mcp_front.' . $phpEx);
0140
0141 $user->add_lang('acp/common');
0142
0143 mcp_front_view($id, $mode, $action);
0144
0145 $this->tpl_name = 'mcp_front';
0146 $this->page_title = 'MCP_MAIN';
0147 break;
0148
0149 case 'forum_view':
0150 include($phpbb_root_path . 'includes/mcp/mcp_forum.' . $phpEx);
0151
0152 $user->add_lang('viewforum');
0153
0154 $forum_id = request_var('f', 0);
0155
0156 $forum_info = get_forum_data($forum_id, 'm_', true);
0157
0158 if (!sizeof($forum_info))
0159 {
0160 $this->main('main', 'front');
0161 return;
0162 }
0163
0164 $forum_info = $forum_info[$forum_id];
0165
0166 mcp_forum_view($id, $mode, $action, $forum_info);
0167
0168 $this->tpl_name = 'mcp_forum';
0169 $this->page_title = 'MCP_MAIN_FORUM_VIEW';
0170 break;
0171
0172 case 'topic_view':
0173 include($phpbb_root_path . 'includes/mcp/mcp_topic.' . $phpEx);
0174
0175 mcp_topic_view($id, $mode, $action);
0176
0177 $this->tpl_name = 'mcp_topic';
0178 $this->page_title = 'MCP_MAIN_TOPIC_VIEW';
0179 break;
0180
0181 case 'post_details':
0182 include($phpbb_root_path . 'includes/mcp/mcp_post.' . $phpEx);
0183
0184 mcp_post_details($id, $mode, $action);
0185
0186 $this->tpl_name = ($action == 'whois') ? 'mcp_whois' : 'mcp_post';
0187 $this->page_title = 'MCP_MAIN_POST_DETAILS';
0188 break;
0189
0190 default:
0191 trigger_error('NO_MODE', E_USER_ERROR);
0192 break;
0193 }
0194 }
0195 }
0196
0197 /**
0198 * Lock/Unlock Topic/Post
0199 */
0200 function lock_unlock($action, $ids)
0201 {
0202 global $auth, $user, $db, $phpEx, $phpbb_root_path;
0203
0204 if ($action == 'lock' || $action == 'unlock')
0205 {
0206 $table = TOPICS_TABLE;
0207 $sql_id = 'topic_id';
0208 $set_id = 'topic_status';
0209 $l_prefix = 'TOPIC';
0210 }
0211 else
0212 {
0213 $table = POSTS_TABLE;
0214 $sql_id = 'post_id';
0215 $set_id = 'post_edit_locked';
0216 $l_prefix = 'POST';
0217 }
0218
0219 $orig_ids = $ids;
0220
0221 if (!check_ids($ids, $table, $sql_id, array('m_lock')))
0222 {
0223 // Make sure that for f_user_lock only the lock action is triggered.
0224 if ($action != 'lock')
0225 {
0226 return;
0227 }
0228
0229 $ids = $orig_ids;
0230
0231 if (!check_ids($ids, $table, $sql_id, array('f_user_lock')))
0232 {
0233 return;
0234 }
0235 }
0236 unset($orig_ids);
0237
0238 $redirect = request_var('redirect', build_url(array('_f_', 'action', 'quickmod')));
0239
0240 $s_hidden_fields = build_hidden_fields(array(
0241 $sql_id . '_list' => $ids,
0242 'action' => $action,
0243 'redirect' => $redirect)
0244 );
0245 $success_msg = '';
0246
0247 if (confirm_box(true))
0248 {
0249 $sql = "UPDATE $table
0250 SET $set_id = " . (($action == 'lock' || $action == 'lock_post') ? ITEM_LOCKED : ITEM_UNLOCKED) . '
0251 WHERE ' . $db->sql_in_set($sql_id, $ids);
0252 $db->sql_query($sql);
0253
0254 $data = ($action == 'lock' || $action == 'unlock') ? get_topic_data($ids) : get_post_data($ids);
0255
0256 foreach ($data as $id => $row)
0257 {
0258 add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_' . strtoupper($action), $row['topic_title']);
0259 }
0260
0261 $success_msg = $l_prefix . ((sizeof($ids) == 1) ? '' : 'S') . '_' . (($action == 'lock' || $action == 'lock_post') ? 'LOCKED' : 'UNLOCKED') . '_SUCCESS';
0262 }
0263 else
0264 {
0265 confirm_box(false, strtoupper($action) . '_' . $l_prefix . ((sizeof($ids) == 1) ? '' : 'S'), $s_hidden_fields);
0266 }
0267
0268 $redirect = request_var('redirect', "index.$phpEx");
0269 $redirect = reapply_sid($redirect);
0270
0271 if (!$success_msg)
0272 {
0273 redirect($redirect);
0274 }
0275 else
0276 {
0277 meta_refresh(2, $redirect);
0278 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
0279 }
0280 }
0281
0282 /**
0283 * Change Topic Type
0284 */
0285 function change_topic_type($action, $topic_ids)
0286 {
0287 global $auth, $user, $db, $phpEx, $phpbb_root_path;
0288
0289 // For changing topic types, we only allow operations in one forum.
0290 $forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('f_announce', 'f_sticky', 'm_'), true);
0291
0292 if ($forum_id === false)
0293 {
0294 return;
0295 }
0296
0297 switch ($action)
0298 {
0299 case 'make_announce':
0300 $new_topic_type = POST_ANNOUNCE;
0301 $check_acl = 'f_announce';
0302 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_ANNOUNCEMENT' : 'MCP_MAKE_ANNOUNCEMENTS';
0303 break;
0304
0305 case 'make_global':
0306 $new_topic_type = POST_GLOBAL;
0307 $check_acl = 'f_announce';
0308 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_GLOBAL' : 'MCP_MAKE_GLOBALS';
0309 break;
0310
0311 case 'make_sticky':
0312 $new_topic_type = POST_STICKY;
0313 $check_acl = 'f_sticky';
0314 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_STICKY' : 'MCP_MAKE_STICKIES';
0315 break;
0316
0317 default:
0318 $new_topic_type = POST_NORMAL;
0319 $check_acl = '';
0320 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_NORMAL' : 'MCP_MAKE_NORMALS';
0321 break;
0322 }
0323
0324 $redirect = request_var('redirect', build_url(array('_f_', 'action', 'quickmod')));
0325
0326 $s_hidden_fields = array(
0327 'topic_id_list' => $topic_ids,
0328 'f' => $forum_id,
0329 'action' => $action,
0330 'redirect' => $redirect,
0331 );
0332 $success_msg = '';
0333
0334 if (confirm_box(true))
0335 {
0336 if ($new_topic_type != POST_GLOBAL)
0337 {
0338 $sql = 'UPDATE ' . TOPICS_TABLE . "
0339 SET topic_type = $new_topic_type
0340 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
0341 AND forum_id <> 0';
0342 $db->sql_query($sql);
0343
0344 // Reset forum id if a global topic is within the array
0345 $to_forum_id = request_var('to_forum_id', 0);
0346
0347 if ($to_forum_id)
0348 {
0349 $sql = 'UPDATE ' . TOPICS_TABLE . "
0350 SET topic_type = $new_topic_type, forum_id = $to_forum_id
0351 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
0352 AND forum_id = 0';
0353 $db->sql_query($sql);
0354
0355 // Update forum_ids for all posts
0356 $sql = 'UPDATE ' . POSTS_TABLE . "
0357 SET forum_id = $to_forum_id
0358 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
0359 AND forum_id = 0';
0360 $db->sql_query($sql);
0361
0362 // Do a little forum sync stuff
0363 $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
0364 FROM ' . TOPICS_TABLE . ' t
0365 WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
0366 $result = $db->sql_query($sql);
0367 $row_data = $db->sql_fetchrow($result);
0368 $db->sql_freeresult($result);
0369
0370 $sync_sql = array();
0371
0372 if ($row_data['topic_posts'])
0373 {
0374 $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . (int) $row_data['topic_posts'];
0375 }
0376
0377 if ($row_data['topics_authed'])
0378 {
0379 $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $row_data['topics_authed'];
0380 }
0381
0382 $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) sizeof($topic_ids);
0383
0384 foreach ($sync_sql as $forum_id_key => $array)
0385 {
0386 $sql = 'UPDATE ' . FORUMS_TABLE . '
0387 SET ' . implode(', ', $array) . '
0388 WHERE forum_id = ' . $forum_id_key;
0389 $db->sql_query($sql);
0390 }
0391
0392 sync('forum', 'forum_id', $to_forum_id);
0393 }
0394 }
0395 else
0396 {
0397 // Get away with those topics already being a global announcement by re-calculating $topic_ids
0398 $sql = 'SELECT topic_id
0399 FROM ' . TOPICS_TABLE . '
0400 WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
0401 AND forum_id <> 0';
0402 $result = $db->sql_query($sql);
0403
0404 $topic_ids = array();
0405 while ($row = $db->sql_fetchrow($result))
0406 {
0407 $topic_ids[] = $row['topic_id'];
0408 }
0409 $db->sql_freeresult($result);
0410
0411 if (sizeof($topic_ids))
0412 {
0413 // Delete topic shadows for global announcements
0414 $sql = 'DELETE FROM ' . TOPICS_TABLE . '
0415 WHERE ' . $db->sql_in_set('topic_moved_id', $topic_ids);
0416 $db->sql_query($sql);
0417
0418 $sql = 'UPDATE ' . TOPICS_TABLE . "
0419 SET topic_type = $new_topic_type, forum_id = 0
0420 WHERE " . $db->sql_in_set('topic_id', $topic_ids);
0421 $db->sql_query($sql);
0422
0423 // Update forum_ids for all posts
0424 $sql = 'UPDATE ' . POSTS_TABLE . '
0425 SET forum_id = 0
0426 WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
0427 $db->sql_query($sql);
0428
0429 // Do a little forum sync stuff
0430 $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
0431 FROM ' . TOPICS_TABLE . ' t
0432 WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
0433 $result = $db->sql_query($sql);
0434 $row_data = $db->sql_fetchrow($result);
0435 $db->sql_freeresult($result);
0436
0437 $sync_sql = array();
0438
0439 if ($row_data['topic_posts'])
0440 {
0441 $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts'];
0442 }
0443
0444 if ($row_data['topics_authed'])
0445 {
0446 $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $row_data['topics_authed'];
0447 }
0448
0449 $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) sizeof($topic_ids);
0450
0451 foreach ($sync_sql as $forum_id_key => $array)
0452 {
0453 $sql = 'UPDATE ' . FORUMS_TABLE . '
0454 SET ' . implode(', ', $array) . '
0455 WHERE forum_id = ' . $forum_id_key;
0456 $db->sql_query($sql);
0457 }
0458
0459 sync('forum', 'forum_id', $forum_id);
0460 }
0461 }
0462
0463 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_TYPE_CHANGED' : 'TOPICS_TYPE_CHANGED';
0464
0465 if (sizeof($topic_ids))
0466 {
0467 $data = get_topic_data($topic_ids);
0468
0469 foreach ($data as $topic_id => $row)
0470 {
0471 add_log('mod', $forum_id, $topic_id, 'LOG_TOPIC_TYPE_CHANGED', $row['topic_title']);
0472 }
0473 }
0474 }
0475 else
0476 {
0477 // Global topic involved?
0478 $global_involved = false;
0479
0480 if ($new_topic_type != POST_GLOBAL)
0481 {
0482 $sql = 'SELECT forum_id
0483 FROM ' . TOPICS_TABLE . '
0484 WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
0485 AND forum_id = 0';
0486 $result = $db->sql_query($sql);
0487 $row = $db->sql_fetchrow($result);
0488 $db->sql_freeresult($result);
0489
0490 if ($row)
0491 {
0492 $global_involved = true;
0493 }
0494 }
0495
0496 if ($global_involved)
0497 {
0498 global $template;
0499
0500 $template->assign_vars(array(
0501 'S_FORUM_SELECT' => make_forum_select(request_var('f', $forum_id), false, false, true, true),
0502 'S_CAN_LEAVE_SHADOW' => false,
0503 'ADDITIONAL_MSG' => (sizeof($topic_ids) == 1) ? $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENT'] : $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENTS'])
0504 );
0505
0506 confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields), 'mcp_move.html');
0507 }
0508 else
0509 {
0510 confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields));
0511 }
0512 }
0513
0514 $redirect = request_var('redirect', "index.$phpEx");
0515 $redirect = reapply_sid($redirect);
0516
0517 if (!$success_msg)
0518 {
0519 redirect($redirect);
0520 }
0521 else
0522 {
0523 meta_refresh(2, $redirect);
0524 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
0525 }
0526 }
0527
0528 /**
0529 * Move Topic
0530 */
0531 function mcp_move_topic($topic_ids)
0532 {
0533 global $auth, $user, $db, $template;
0534 global $phpEx, $phpbb_root_path;
0535
0536 // Here we limit the operation to one forum only
0537 $forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_move'), true);
0538
0539 if ($forum_id === false)
0540 {
0541 return;
0542 }
0543
0544 $to_forum_id = request_var('to_forum_id', 0);
0545 $redirect = request_var('redirect', build_url(array('_f_', 'action', 'quickmod')));
0546 $additional_msg = $success_msg = '';
0547
0548 $s_hidden_fields = build_hidden_fields(array(
0549 'topic_id_list' => $topic_ids,
0550 'f' => $forum_id,
0551 'action' => 'move',
0552 'redirect' => $redirect)
0553 );
0554
0555 if ($to_forum_id)
0556 {
0557 $forum_data = get_forum_data($to_forum_id);
0558
0559 if (!sizeof($forum_data))
0560 {
0561 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
0562 }
0563 else
0564 {
0565 $forum_data = $forum_data[$to_forum_id];
0566
0567 if ($forum_data['forum_type'] != FORUM_POST)
0568 {
0569 $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
0570 }
0571 else if (!$auth->acl_get('f_post', $to_forum_id))
0572 {
0573 $additional_msg = $user->lang['USER_CANNOT_POST'];
0574 }
0575 else if ($forum_id == $to_forum_id)
0576 {
0577 $additional_msg = $user->lang['CANNOT_MOVE_SAME_FORUM'];
0578 }
0579 }
0580 }
0581 else if (isset($_POST['confirm']))
0582 {
0583 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
0584 }
0585
0586 if (!$to_forum_id || $additional_msg)
0587 {
0588 unset($_POST['confirm']);
0589 unset($_REQUEST['confirm_key']);
0590 }
0591
0592 if (confirm_box(true))
0593 {
0594 $topic_data = get_topic_data($topic_ids);
0595 $leave_shadow = (isset($_POST['move_leave_shadow'])) ? true : false;
0596
0597 $topics_moved = sizeof($topic_ids);
0598 $topics_authed_moved = 0;
0599 $forum_sync_data = array();
0600
0601 $forum_sync_data[$forum_id] = current($topic_data);
0602 $forum_sync_data[$to_forum_id] = $forum_data;
0603
0604 foreach ($topic_data as $topic_id => $topic_info)
0605 {
0606 if ($topic_info['topic_approved'] == '1')
0607 {
0608 $topics_authed_moved++;
0609 }
0610 }
0611
0612 $db->sql_transaction('begin');
0613
0614 $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts
0615 FROM ' . TOPICS_TABLE . ' t
0616 WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
0617 $result = $db->sql_query($sql);
0618 $row_data = $db->sql_fetchrow($result);
0619 $db->sql_freeresult($result);
0620
0621 $sync_sql = array();
0622
0623 if ($row_data['topic_posts'])
0624 {
0625 $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts'];
0626 $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . (int) $row_data['topic_posts'];
0627 }
0628
0629 if ($topics_authed_moved)
0630 {
0631 $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_authed_moved;
0632 }
0633
0634 $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved;
0635
0636 // Move topics, but do not resync yet
0637 move_topics($topic_ids, $to_forum_id, false);
0638
0639 $forum_ids = array($to_forum_id);
0640 foreach ($topic_data as $topic_id => $row)
0641 {
0642 // Get the list of forums to resync, add a log entry
0643 $forum_ids[] = $row['forum_id'];
0644 add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name']);
0645
0646 // If we have moved a global announcement, we need to correct the topic type
0647 if ($row['topic_type'] == POST_GLOBAL)
0648 {
0649 $sql = 'UPDATE ' . TOPICS_TABLE . '
0650 SET topic_type = ' . POST_ANNOUNCE . '
0651 WHERE topic_id = ' . (int) $row['topic_id'];
0652 $db->sql_query($sql);
0653 }
0654
0655 // Leave a redirection if required and only if the topic is visible to users
0656 if ($leave_shadow && $row['topic_approved'] && $row['topic_type'] != POST_GLOBAL)
0657 {
0658 $shadow = array(
0659 'forum_id' => (int) $row['forum_id'],
0660 'icon_id' => (int) $row['icon_id'],
0661 'topic_attachment' => (int) $row['topic_attachment'],
0662 'topic_approved' => 1,
0663 'topic_reported' => (int) $row['topic_reported'],
0664 'topic_title' => (string) $row['topic_title'],
0665 'topic_poster' => (int) $row['topic_poster'],
0666 'topic_time' => (int) $row['topic_time'],
0667 'topic_time_limit' => (int) $row['topic_time_limit'],
0668 'topic_views' => (int) $row['topic_views'],
0669 'topic_replies' => (int) $row['topic_replies'],
0670 'topic_replies_real' => (int) $row['topic_replies_real'],
0671 'topic_status' => ITEM_MOVED,
0672 'topic_type' => POST_NORMAL,
0673 'topic_first_post_id' => (int) $row['topic_first_post_id'],
0674 'topic_first_poster_colour'=>(string) $row['topic_first_poster_colour'],
0675 'topic_first_poster_name'=> (string) $row['topic_first_poster_name'],
0676 'topic_last_post_id' => (int) $row['topic_last_post_id'],
0677 'topic_last_poster_id' => (int) $row['topic_last_poster_id'],
0678 'topic_last_poster_colour'=>(string) $row['topic_last_poster_colour'],
0679 'topic_last_poster_name'=> (string) $row['topic_last_poster_name'],
0680 'topic_last_post_subject'=> (string) $row['topic_last_post_subject'],
0681 'topic_last_post_time' => (int) $row['topic_last_post_time'],
0682 'topic_last_view_time' => (int) $row['topic_last_view_time'],
0683 'topic_moved_id' => (int) $row['topic_id'],
0684 'topic_bumped' => (int) $row['topic_bumped'],
0685 'topic_bumper' => (int) $row['topic_bumper'],
0686 'poll_title' => (string) $row['poll_title'],
0687 'poll_start' => (int) $row['poll_start'],
0688 'poll_length' => (int) $row['poll_length'],
0689 'poll_max_options' => (int) $row['poll_max_options'],
0690 'poll_last_vote' => (int) $row['poll_last_vote']
0691 );
0692
0693 $db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow));
0694
0695 $topics_authed_moved--;
0696 $topics_moved--;
0697 }
0698 }
0699 unset($topic_data);
0700
0701 $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) $topics_moved;
0702
0703 if ($topics_authed_moved)
0704 {
0705 $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $topics_authed_moved;
0706 }
0707
0708 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS';
0709
0710 foreach ($sync_sql as $forum_id_key => $array)
0711 {
0712 $sql = 'UPDATE ' . FORUMS_TABLE . '
0713 SET ' . implode(', ', $array) . '
0714 WHERE forum_id = ' . $forum_id_key;
0715 $db->sql_query($sql);
0716 }
0717
0718 $db->sql_transaction('commit');
0719
0720 sync('forum', 'forum_id', array($forum_id, $to_forum_id));
0721 }
0722 else
0723 {
0724 $template->assign_vars(array(
0725 'S_FORUM_SELECT' => make_forum_select($to_forum_id, $forum_id, false, true, true, true),
0726 'S_CAN_LEAVE_SHADOW' => true,
0727 'ADDITIONAL_MSG' => $additional_msg)
0728 );
0729
0730 confirm_box(false, 'MOVE_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
0731 }
0732
0733 $redirect = request_var('redirect', "index.$phpEx");
0734 $redirect = reapply_sid($redirect);
0735
0736 if (!$success_msg)
0737 {
0738 redirect($redirect);
0739 }
0740 else
0741 {
0742 meta_refresh(3, $redirect);
0743
0744 $message = $user->lang[$success_msg];
0745 $message .= '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
0746 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id") . '">', '</a>');
0747 $message .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$to_forum_id") . '">', '</a>');
0748
0749 trigger_error($message);
0750 }
0751 }
0752
0753 /**
0754 * Delete Topics
0755 */
0756 function mcp_delete_topic($topic_ids)
0757 {
0758 global $auth, $user, $db, $phpEx, $phpbb_root_path;
0759
0760 if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete')))
0761 {
0762 return;
0763 }
0764
0765 $redirect = request_var('redirect', build_url(array('_f_', 'action', 'quickmod')));
0766 $forum_id = request_var('f', 0);
0767
0768 $s_hidden_fields = build_hidden_fields(array(
0769 'topic_id_list' => $topic_ids,
0770 'f' => $forum_id,
0771 'action' => 'delete_topic',
0772 'redirect' => $redirect)
0773 );
0774 $success_msg = '';
0775
0776 if (confirm_box(true))
0777 {
0778 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS';
0779
0780 $data = get_topic_data($topic_ids);
0781
0782 foreach ($data as $topic_id => $row)
0783 {
0784 add_log('mod', $row['forum_id'], 0, 'LOG_TOPIC_DELETED', $row['topic_title']);
0785 }
0786
0787 $return = delete_topics('topic_id', $topic_ids);
0788 }
0789 else
0790 {
0791 confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields);
0792 }
0793
0794 $redirect = request_var('redirect', "index.$phpEx");
0795 $redirect = reapply_sid($redirect);
0796
0797 if (!$success_msg)
0798 {
0799 redirect($redirect);
0800 }
0801 else
0802 {
0803 $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
0804 meta_refresh(3, $redirect_url);
0805 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
0806 }
0807 }
0808
0809 /**
0810 * Delete Posts
0811 */
0812 function mcp_delete_post($post_ids)
0813 {
0814 global $auth, $user, $db, $phpEx, $phpbb_root_path;
0815
0816 if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_delete')))
0817 {
0818 return;
0819 }
0820
0821 $redirect = request_var('redirect', build_url(array('_f_', 'action', 'quickmod')));
0822 $forum_id = request_var('f', 0);
0823
0824 $s_hidden_fields = build_hidden_fields(array(
0825 'post_id_list' => $post_ids,
0826 'f' => $forum_id,
0827 'action' => 'delete_post',
0828 'redirect' => $redirect)
0829 );
0830 $success_msg = '';
0831
0832 if (confirm_box(true))
0833 {
0834 if (!function_exists('delete_posts'))
0835 {
0836 include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
0837 }
0838
0839 // Count the number of topics that are affected
0840 // I did not use COUNT(DISTINCT ...) because I remember having problems
0841 // with it on older versions of MySQL -- Ashe
0842
0843 $sql = 'SELECT DISTINCT topic_id
0844 FROM ' . POSTS_TABLE . '
0845 WHERE ' . $db->sql_in_set('post_id', $post_ids);
0846 $result = $db->sql_query($sql);
0847
0848 $topic_id_list = array();
0849 while ($row = $db->sql_fetchrow($result))
0850 {
0851 $topic_id_list[] = $row['topic_id'];
0852 }
0853 $affected_topics = sizeof($topic_id_list);
0854 $db->sql_freeresult($result);
0855
0856 $post_data = get_post_data($post_ids);
0857
0858 foreach ($post_data as $id => $row)
0859 {
0860 add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_DELETE_POST', $row['post_subject']);
0861 }
0862
0863 // Now delete the posts, topics and forums are automatically resync'ed
0864 delete_posts('post_id', $post_ids);
0865
0866 $sql = 'SELECT COUNT(topic_id) AS topics_left
0867 FROM ' . TOPICS_TABLE . '
0868 WHERE ' . $db->sql_in_set('topic_id', $topic_id_list);
0869 $result = $db->sql_query_limit($sql, 1);
0870
0871 $deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics;
0872 $db->sql_freeresult($result);
0873
0874 $topic_id = request_var('t', 0);
0875
0876 // Return links
0877 $return_link = array();
0878 if ($affected_topics == 1 && !$deleted_topics && $topic_id)
0879 {
0880 $return_link[] = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id") . '">', '</a>');
0881 }
0882 $return_link[] = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
0883
0884 if (sizeof($post_ids) == 1)
0885 {
0886 if ($deleted_topics)
0887 {
0888 // We deleted the only post of a topic, which in turn has
0889 // been removed from the database
0890 $success_msg = $user->lang['TOPIC_DELETED_SUCCESS'];
0891 }
0892 else
0893 {
0894 $success_msg = $user->lang['POST_DELETED_SUCCESS'];
0895 }
0896 }
0897 else
0898 {
0899 if ($deleted_topics)
0900 {
0901 // Some of topics disappeared
0902 $success_msg = $user->lang['POSTS_DELETED_SUCCESS'] . '<br /><br />' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING'];
0903 }
0904 else
0905 {
0906 $success_msg = $user->lang['POSTS_DELETED_SUCCESS'];
0907 }
0908 }
0909 }
0910 else
0911 {
0912 confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields);
0913 }
0914
0915 $redirect = request_var('redirect', "index.$phpEx");
0916 $redirect = reapply_sid($redirect);
0917
0918 if (!$success_msg)
0919 {
0920 redirect($redirect);
0921 }
0922 else
0923 {
0924 meta_refresh(3, $redirect);
0925 trigger_error($success_msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>') . '<br /><br />' . implode('<br /><br />', $return_link));
0926 }
0927 }
0928
0929 /**
0930 * Fork Topic
0931 */
0932 function mcp_fork_topic($topic_ids)
0933 {
0934 global $auth, $user, $db, $template, $config;
0935 global $phpEx, $phpbb_root_path;
0936
0937 if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_')))
0938 {
0939 return;
0940 }
0941
0942 $to_forum_id = request_var('to_forum_id', 0);
0943 $forum_id = request_var('f', 0);
0944 $redirect = request_var('redirect', build_url(array('_f_', 'action', 'quickmod')));
0945 $additional_msg = $success_msg = '';
0946
0947 $s_hidden_fields = build_hidden_fields(array(
0948 'topic_id_list' => $topic_ids,
0949 'f' => $forum_id,
0950 'action' => 'fork',
0951 'redirect' => $redirect)
0952 );
0953
0954 if ($to_forum_id)
0955 {
0956 $forum_data = get_forum_data($to_forum_id);
0957
0958 if (!sizeof($topic_ids))
0959 {
0960 $additional_msg = $user->lang['NO_TOPIC_SELECTED'];
0961 }
0962 else if (!sizeof($forum_data))
0963 {
0964 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
0965 }
0966 else
0967 {
0968 $forum_data = $forum_data[$to_forum_id];
0969
0970 if ($forum_data['forum_type'] != FORUM_POST)
0971 {
0972 $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
0973 }
0974 else if (!$auth->acl_get('f_post', $to_forum_id))
0975 {
0976 $additional_msg = $user->lang['USER_CANNOT_POST'];
0977 }
0978 }
0979 }
0980 else if (isset($_POST['confirm']))
0981 {
0982 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
0983 }
0984
0985 if ($additional_msg)
0986 {
0987 unset($_POST['confirm']);
0988 unset($_REQUEST['confirm_key']);
0989 }
0990
0991 if (confirm_box(true))
0992 {
0993 $topic_data = get_topic_data($topic_ids);
0994
0995 $total_posts = 0;
0996 $new_topic_id_list = array();
0997
0998 foreach ($topic_data as $topic_id => $topic_row)
0999 {
1000 $sql_ary = array(
1001 'forum_id' => (int) $to_forum_id,
1002 'icon_id' => (int) $topic_row['icon_id'],
1003 'topic_attachment' => (int) $topic_row['topic_attachment'],
1004 'topic_approved' => 1,
1005 'topic_reported' => 0,
1006 'topic_title' => (string) $topic_row['topic_title'],
1007 'topic_poster' => (int) $topic_row['topic_poster'],
1008 'topic_time' => (int) $topic_row['topic_time'],
1009 'topic_replies' => (int) $topic_row['topic_replies_real'],
1010 'topic_replies_real' => (int) $topic_row['topic_replies_real'],
1011 'topic_status' => (int) $topic_row['topic_status'],
1012 'topic_type' => (int) $topic_row['topic_type'],
1013 'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'],
1014 'topic_last_poster_id' => (int) $topic_row['topic_last_poster_id'],
1015 'topic_last_poster_name' => (string) $topic_row['topic_last_poster_name'],
1016 'topic_last_post_time' => (int) $topic_row['topic_last_post_time'],
1017 'topic_last_view_time' => (int) $topic_row['topic_last_view_time'],
1018 'topic_bumped' => (int) $topic_row['topic_bumped'],
1019 'topic_bumper' => (int) $topic_row['topic_bumper'],
1020 'poll_title' => (string) $topic_row['poll_title'],
1021 'poll_start' => (int) $topic_row['poll_start'],
1022 'poll_length' => (int) $topic_row['poll_length']
1023 );
1024
1025 $db->sql_query('INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1026 $new_topic_id = $db->sql_nextid();
1027 $new_topic_id_list[$topic_id] = $new_topic_id;
1028
1029 if ($topic_row['poll_start'])
1030 {
1031 $poll_rows = array();
1032
1033 $sql = 'SELECT *
1034 FROM ' . POLL_OPTIONS_TABLE . "
1035 WHERE topic_id = $topic_id";
1036 $result = $db->sql_query($sql);
1037
1038 while ($row = $db->sql_fetchrow($result))
1039 {
1040 $sql_ary = array(
1041 'poll_option_id' => (int) $row['poll_option_id'],
1042 'topic_id' => (int) $new_topic_id,
1043 'poll_option_text' => (string) $row['poll_option_text'],
1044 'poll_option_total' => 0
1045 );
1046
1047 $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1048 }
1049 }
1050
1051 $sql = 'SELECT *
1052 FROM ' . POSTS_TABLE . "
1053 WHERE topic_id = $topic_id
1054 ORDER BY post_time ASC";
1055 $result = $db->sql_query($sql);
1056
1057 $post_rows = array();
1058 while ($row = $db->sql_fetchrow($result))
1059 {
1060 $post_rows[] = $row;
1061 }
1062 $db->sql_freeresult($result);
1063
1064 if (!sizeof($post_rows))
1065 {
1066 continue;
1067 }
1068
1069 $total_posts += sizeof($post_rows);
1070 foreach ($post_rows as $row)
1071 {
1072 $sql_ary = array(
1073 'topic_id' => (int) $new_topic_id,
1074 'forum_id' => (int) $to_forum_id,
1075 'poster_id' => (int) $row['poster_id'],
1076 'icon_id' => (int) $row['icon_id'],
1077 'poster_ip' => (string) $row['poster_ip'],
1078 'post_time' => (int) $row['post_time'],
1079 'post_approved' => 1,
1080 'post_reported' => 0,
1081 'enable_bbcode' => (int) $row['enable_bbcode'],
1082 'enable_smilies' => (int) $row['enable_smilies'],
1083 'enable_magic_url' => (int) $row['enable_magic_url'],
1084 'enable_sig' => (int) $row['enable_sig'],
1085 'post_username' => (string) $row['post_username'],
1086 'post_subject' => (string) $row['post_subject'],
1087 'post_text' => (string) $row['post_text'],
1088 'post_edit_reason' => (string) $row['post_edit_reason'],
1089 'post_edit_user' => (int) $row['post_edit_user'],
1090 'post_checksum' => (string) $row['post_checksum'],
1091 'post_attachment' => (int) $row['post_attachment'],
1092 'bbcode_bitfield' => $row['bbcode_bitfield'],
1093 'bbcode_uid' => (string) $row['bbcode_uid'],
1094 'post_edit_time' => (int) $row['post_edit_time'],
1095 'post_edit_count' => (int) $row['post_edit_count'],
1096 'post_edit_locked' => (int) $row['post_edit_locked'],
1097 'post_postcount' => 0,
1098 );
1099
1100 $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1101 $new_post_id = $db->sql_nextid();
1102
1103 // Copy whether the topic is dotted
1104 markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']);
1105
1106 // Copy Attachments
1107 if ($row['post_attachment'])
1108 {
1109 $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . "
1110 WHERE post_msg_id = {$row['post_id']}
1111 AND topic_id = $topic_id
1112 AND in_message = 0";
1113 $result = $db->sql_query($sql);
1114
1115 $sql_ary = array();
1116 while ($attach_row = $db->sql_fetchrow($result))
1117 {
1118 $sql_ary[] = array(
1119 'post_msg_id' => (int) $new_post_id,
1120 'topic_id' => (int) $new_topic_id,
1121 'in_message' => 0,
1122 'is_orphan' => (int) $attach_row['is_orphan'],
1123 'poster_id' => (int) $attach_row['poster_id'],
1124 'physical_filename' => (string) basename($attach_row['physical_filename']),
1125 'real_filename' => (string) basename($attach_row['real_filename']),
1126 'download_count' => (int) $attach_row['download_count'],
1127 'attach_comment' => (string) $attach_row['attach_comment'],
1128 'extension' => (string) $attach_row['extension'],
1129 'mimetype' => (string) $attach_row['mimetype'],
1130 'filesize' => (int) $attach_row['filesize'],
1131 'filetime' => (int) $attach_row['filetime'],
1132 'thumbnail' => (int) $attach_row['thumbnail']
1133 );
1134 }
1135 $db->sql_freeresult($result);
1136
1137 if (sizeof($sql_ary))
1138 {
1139 $db->sql_multi_insert(ATTACHMENTS_TABLE, $sql_ary);
1140 }
1141 }
1142 }
1143
1144 $sql = 'SELECT user_id, notify_status
1145 FROM ' . TOPICS_WATCH_TABLE . '
1146 WHERE topic_id = ' . $topic_id;
1147 $result = $db->sql_query($sql);
1148
1149 $sql_ary = array();
1150 while ($row = $db->sql_fetchrow($result))
1151 {
1152 $sql_ary[] = array(
1153 'topic_id' => (int) $new_topic_id,
1154 'user_id' => (int) $row['user_id'],
1155 'notify_status' => (int) $row['notify_status'],
1156 );
1157 }
1158 $db->sql_freeresult($result);
1159
1160 if (sizeof($sql_ary))
1161 {
1162 $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
1163 }
1164 }
1165
1166 // Sync new topics, parent forums and board stats
1167 sync('topic', 'topic_id', $new_topic_id_list);
1168
1169 $sync_sql = array();
1170
1171 $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $total_posts;
1172 $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . sizeof($new_topic_id_list);
1173 $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . sizeof($new_topic_id_list);
1174
1175 foreach ($sync_sql as $forum_id_key => $array)
1176 {
1177 $sql = 'UPDATE ' . FORUMS_TABLE . '
1178 SET ' . implode(', ', $array) . '
1179 WHERE forum_id = ' . $forum_id_key;
1180 $db->sql_query($sql);
1181 }
1182
1183 sync('forum', 'forum_id', $to_forum_id);
1184 set_config('num_topics', $config['num_topics'] + sizeof($new_topic_id_list), true);
1185 set_config('num_posts', $config['num_posts'] + $total_posts, true);
1186
1187 foreach ($new_topic_id_list as $topic_id => $new_topic_id)
1188 {
1189 add_log('mod', $to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']);
1190 }
1191
1192 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS';
1193 }
1194 else
1195 {
1196 $template->assign_vars(array(
1197 'S_FORUM_SELECT' => make_forum_select($to_forum_id, false, false, true, true, true),
1198 'S_CAN_LEAVE_SHADOW' => false,
1199 'ADDITIONAL_MSG' => $additional_msg)
1200 );
1201
1202 confirm_box(false, 'FORK_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
1203 }
1204
1205 $redirect = request_var('redirect', "index.$phpEx");
1206 $redirect = reapply_sid($redirect);
1207
1208 if (!$success_msg)
1209 {
1210 redirect($redirect);
1211 }
1212 else
1213 {
1214 $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
1215 meta_refresh(3, $redirect_url);
1216 $return_link = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>');
1217
1218 if ($forum_id != $to_forum_id)
1219 {
1220 $return_link .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $to_forum_id) . '">', '</a>');
1221 }
1222
1223 trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
1224 }
1225 }
1226
1227 ?>