6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
21 * Handling mcp actions
29 function mcp_main(&$p_master)
31 $this->p_master = &$p_master;
34 function main($id, $mode)
36 global $auth, $db, $user, $template, $action;
37 global $config, $phpbb_root_path, $phpEx;
39 $quickmod = ($mode == 'quickmod') ? true : false;
45 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
47 if (!sizeof($topic_ids))
49 trigger_error('NO_TOPIC_SELECTED');
52 lock_unlock($action, $topic_ids);
58 $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
60 if (!sizeof($post_ids))
62 trigger_error('NO_POST_SELECTED');
65 lock_unlock($action, $post_ids);
73 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
75 if (!sizeof($topic_ids))
77 trigger_error('NO_TOPIC_SELECTED');
80 change_topic_type($action, $topic_ids);
84 $user->add_lang('viewtopic');
86 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
88 if (!sizeof($topic_ids))
90 trigger_error('NO_TOPIC_SELECTED');
93 mcp_move_topic($topic_ids);
97 $user->add_lang('viewtopic');
99 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
101 if (!sizeof($topic_ids))
103 trigger_error('NO_TOPIC_SELECTED');
106 mcp_fork_topic($topic_ids);
110 $user->add_lang('viewtopic');
112 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
114 if (!sizeof($topic_ids))
116 trigger_error('NO_TOPIC_SELECTED');
119 mcp_delete_topic($topic_ids);
123 $user->add_lang('posting');
125 $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
127 if (!sizeof($post_ids))
129 trigger_error('NO_POST_SELECTED');
132 mcp_delete_post($post_ids);
139 include($phpbb_root_path . 'includes/mcp/mcp_front.' . $phpEx);
141 $user->add_lang('acp/common');
143 mcp_front_view($id, $mode, $action);
145 $this->tpl_name = 'mcp_front';
146 $this->page_title = 'MCP_MAIN';
150 include($phpbb_root_path . 'includes/mcp/mcp_forum.' . $phpEx);
152 $user->add_lang('viewforum');
154 $forum_id = request_var('f', 0);
156 $forum_info = get_forum_data($forum_id, 'm_', true);
158 if (!sizeof($forum_info))
160 $this->main('main', 'front');
164 $forum_info = $forum_info[$forum_id];
166 mcp_forum_view($id, $mode, $action, $forum_info);
168 $this->tpl_name = 'mcp_forum';
169 $this->page_title = 'MCP_MAIN_FORUM_VIEW';
173 include($phpbb_root_path . 'includes/mcp/mcp_topic.' . $phpEx);
175 mcp_topic_view($id, $mode, $action);
177 $this->tpl_name = 'mcp_topic';
178 $this->page_title = 'MCP_MAIN_TOPIC_VIEW';
182 include($phpbb_root_path . 'includes/mcp/mcp_post.' . $phpEx);
184 mcp_post_details($id, $mode, $action);
186 $this->tpl_name = ($action == 'whois') ? 'mcp_whois' : 'mcp_post';
187 $this->page_title = 'MCP_MAIN_POST_DETAILS';
191 trigger_error('NO_MODE', E_USER_ERROR);
198 * Lock/Unlock Topic/Post
200 function lock_unlock($action, $ids)
202 global $auth, $user, $db, $phpEx, $phpbb_root_path;
204 if ($action == 'lock' || $action == 'unlock')
206 $table = TOPICS_TABLE;
207 $sql_id = 'topic_id';
208 $set_id = 'topic_status';
213 $table = POSTS_TABLE;
215 $set_id = 'post_edit_locked';
221 if (!check_ids($ids, $table, $sql_id, array('m_lock')))
223 // Make sure that for f_user_lock only the lock action is triggered.
224 if ($action != 'lock')
231 if (!check_ids($ids, $table, $sql_id, array('f_user_lock')))
238 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
240 $s_hidden_fields = build_hidden_fields(array(
241 $sql_id . '_list' => $ids,
243 'redirect' => $redirect)
247 if (confirm_box(true))
249 $sql = "UPDATE $table
250 SET $set_id = " . (($action == 'lock' || $action == 'lock_post') ? ITEM_LOCKED : ITEM_UNLOCKED) . '
251 WHERE ' . $db->sql_in_set($sql_id, $ids);
252 $db->sql_query($sql);
254 $data = ($action == 'lock' || $action == 'unlock') ? get_topic_data($ids) : get_post_data($ids);
256 foreach ($data as $id => $row)
258 add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_' . strtoupper($action), $row['topic_title']);
261 $success_msg = $l_prefix . ((sizeof($ids) == 1) ? '' : 'S') . '_' . (($action == 'lock' || $action == 'lock_post') ? 'LOCKED' : 'UNLOCKED') . '_SUCCESS';
265 confirm_box(false, strtoupper($action) . '_' . $l_prefix . ((sizeof($ids) == 1) ? '' : 'S'), $s_hidden_fields);
268 $redirect = request_var('redirect', "index.$phpEx");
269 $redirect = reapply_sid($redirect);
277 meta_refresh(2, $redirect);
278 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
285 function change_topic_type($action, $topic_ids)
287 global $auth, $user, $db, $phpEx, $phpbb_root_path;
291 case 'make_announce':
292 $new_topic_type = POST_ANNOUNCE;
293 $check_acl = 'f_announce';
294 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_ANNOUNCEMENT' : 'MCP_MAKE_ANNOUNCEMENTS';
298 $new_topic_type = POST_GLOBAL;
299 $check_acl = 'f_announce';
300 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_GLOBAL' : 'MCP_MAKE_GLOBALS';
304 $new_topic_type = POST_STICKY;
305 $check_acl = 'f_sticky';
306 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_STICKY' : 'MCP_MAKE_STICKIES';
310 $new_topic_type = POST_NORMAL;
312 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_NORMAL' : 'MCP_MAKE_NORMALS';
316 $forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', $check_acl, true);
318 if ($forum_id === false)
323 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
325 $s_hidden_fields = array(
326 'topic_id_list' => $topic_ids,
329 'redirect' => $redirect,
333 if (confirm_box(true))
335 if ($new_topic_type != POST_GLOBAL)
337 $sql = 'UPDATE ' . TOPICS_TABLE . "
338 SET topic_type = $new_topic_type
339 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
341 $db->sql_query($sql);
343 // Reset forum id if a global topic is within the array
344 $to_forum_id = request_var('to_forum_id', 0);
348 $sql = 'UPDATE ' . TOPICS_TABLE . "
349 SET topic_type = $new_topic_type, forum_id = $to_forum_id
350 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
352 $db->sql_query($sql);
354 // Update forum_ids for all posts
355 $sql = 'UPDATE ' . POSTS_TABLE . "
356 SET forum_id = $to_forum_id
357 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
359 $db->sql_query($sql);
361 // Do a little forum sync stuff
362 $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
363 FROM ' . TOPICS_TABLE . ' t
364 WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
365 $result = $db->sql_query($sql);
366 $row_data = $db->sql_fetchrow($result);
367 $db->sql_freeresult($result);
371 if ($row_data['topic_posts'])
373 $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . (int) $row_data['topic_posts'];
376 if ($row_data['topics_authed'])
378 $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $row_data['topics_authed'];
381 $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) sizeof($topic_ids);
383 foreach ($sync_sql as $forum_id_key => $array)
385 $sql = 'UPDATE ' . FORUMS_TABLE . '
386 SET ' . implode(', ', $array) . '
387 WHERE forum_id = ' . $forum_id_key;
388 $db->sql_query($sql);
391 sync('forum', 'forum_id', $to_forum_id);
396 // Get away with those topics already being a global announcement by re-calculating $topic_ids
397 $sql = 'SELECT topic_id
398 FROM ' . TOPICS_TABLE . '
399 WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
401 $result = $db->sql_query($sql);
403 $topic_ids = array();
404 while ($row = $db->sql_fetchrow($result))
406 $topic_ids[] = $row['topic_id'];
408 $db->sql_freeresult($result);
410 if (sizeof($topic_ids))
412 // Delete topic shadows for global announcements
413 $sql = 'DELETE FROM ' . TOPICS_TABLE . '
414 WHERE ' . $db->sql_in_set('topic_moved_id', $topic_ids);
415 $db->sql_query($sql);
417 $sql = 'UPDATE ' . TOPICS_TABLE . "
418 SET topic_type = $new_topic_type, forum_id = 0
419 WHERE " . $db->sql_in_set('topic_id', $topic_ids);
420 $db->sql_query($sql);
422 // Update forum_ids for all posts
423 $sql = 'UPDATE ' . POSTS_TABLE . '
425 WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
426 $db->sql_query($sql);
428 // Do a little forum sync stuff
429 $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
430 FROM ' . TOPICS_TABLE . ' t
431 WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
432 $result = $db->sql_query($sql);
433 $row_data = $db->sql_fetchrow($result);
434 $db->sql_freeresult($result);
438 if ($row_data['topic_posts'])
440 $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts'];
443 if ($row_data['topics_authed'])
445 $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $row_data['topics_authed'];
448 $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) sizeof($topic_ids);
450 foreach ($sync_sql as $forum_id_key => $array)
452 $sql = 'UPDATE ' . FORUMS_TABLE . '
453 SET ' . implode(', ', $array) . '
454 WHERE forum_id = ' . $forum_id_key;
455 $db->sql_query($sql);
458 sync('forum', 'forum_id', $forum_id);
462 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_TYPE_CHANGED' : 'TOPICS_TYPE_CHANGED';
464 if (sizeof($topic_ids))
466 $data = get_topic_data($topic_ids);
468 foreach ($data as $topic_id => $row)
470 add_log('mod', $forum_id, $topic_id, 'LOG_TOPIC_TYPE_CHANGED', $row['topic_title']);
476 // Global topic involved?
477 $global_involved = false;
479 if ($new_topic_type != POST_GLOBAL)
481 $sql = 'SELECT forum_id
482 FROM ' . TOPICS_TABLE . '
483 WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
485 $result = $db->sql_query($sql);
486 $row = $db->sql_fetchrow($result);
487 $db->sql_freeresult($result);
491 $global_involved = true;
495 if ($global_involved)
499 $template->assign_vars(array(
500 'S_FORUM_SELECT' => make_forum_select(request_var('f', $forum_id), false, false, true, true),
501 'S_CAN_LEAVE_SHADOW' => false,
502 'ADDITIONAL_MSG' => (sizeof($topic_ids) == 1) ? $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENT'] : $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENTS'])
505 confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields), 'mcp_move.html');
509 confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields));
513 $redirect = request_var('redirect', "index.$phpEx");
514 $redirect = reapply_sid($redirect);
522 meta_refresh(2, $redirect);
523 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
530 function mcp_move_topic($topic_ids)
532 global $auth, $user, $db, $template;
533 global $phpEx, $phpbb_root_path;
535 // Here we limit the operation to one forum only
536 $forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_move'), true);
538 if ($forum_id === false)
543 $to_forum_id = request_var('to_forum_id', 0);
544 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
545 $additional_msg = $success_msg = '';
547 $s_hidden_fields = build_hidden_fields(array(
548 'topic_id_list' => $topic_ids,
551 'redirect' => $redirect)
556 $forum_data = get_forum_data($to_forum_id, 'f_post');
558 if (!sizeof($forum_data))
560 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
564 $forum_data = $forum_data[$to_forum_id];
566 if ($forum_data['forum_type'] != FORUM_POST)
568 $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
570 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)))
572 $additional_msg = $user->lang['USER_CANNOT_POST'];
574 else if ($forum_id == $to_forum_id)
576 $additional_msg = $user->lang['CANNOT_MOVE_SAME_FORUM'];
580 else if (isset($_POST['confirm']))
582 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
585 if (!$to_forum_id || $additional_msg)
587 unset($_POST['confirm']);
588 unset($_REQUEST['confirm_key']);
591 if (confirm_box(true))
593 $topic_data = get_topic_data($topic_ids);
594 $leave_shadow = (isset($_POST['move_leave_shadow'])) ? true : false;
596 $forum_sync_data = array();
598 $forum_sync_data[$forum_id] = current($topic_data);
599 $forum_sync_data[$to_forum_id] = $forum_data;
601 // Real topics added to target forum
602 $topics_moved = sizeof($topic_data);
604 // Approved topics added to target forum
605 $topics_authed_moved = 0;
607 // Posts (topic replies + topic post if approved) added to target forum
608 $topic_posts_added = 0;
610 // Posts (topic replies + topic post if approved and not global announcement) removed from source forum
611 $topic_posts_removed = 0;
613 // Real topics removed from source forum (all topics without global announcements)
616 // Approved topics removed from source forum (except global announcements)
617 $topics_authed_removed = 0;
619 foreach ($topic_data as $topic_id => $topic_info)
621 if ($topic_info['topic_approved'])
623 $topics_authed_moved++;
624 $topic_posts_added++;
627 $topic_posts_added += $topic_info['topic_replies'];
629 if ($topic_info['topic_type'] != POST_GLOBAL)
632 $topic_posts_removed += $topic_info['topic_replies'];
634 if ($topic_info['topic_approved'])
636 $topics_authed_removed++;
637 $topic_posts_removed++;
642 $db->sql_transaction('begin');
646 if ($topic_posts_added)
648 $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $topic_posts_added;
651 if ($topics_authed_moved)
653 $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_authed_moved;
656 $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved;
658 // Move topics, but do not resync yet
659 move_topics($topic_ids, $to_forum_id, false);
661 $forum_ids = array($to_forum_id);
662 foreach ($topic_data as $topic_id => $row)
664 // Get the list of forums to resync, add a log entry
665 $forum_ids[] = $row['forum_id'];
666 add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name'], $forum_data['forum_name']);
668 // If we have moved a global announcement, we need to correct the topic type
669 if ($row['topic_type'] == POST_GLOBAL)
671 $sql = 'UPDATE ' . TOPICS_TABLE . '
672 SET topic_type = ' . POST_ANNOUNCE . '
673 WHERE topic_id = ' . (int) $row['topic_id'];
674 $db->sql_query($sql);
677 // Leave a redirection if required and only if the topic is visible to users
678 if ($leave_shadow && $row['topic_approved'] && $row['topic_type'] != POST_GLOBAL)
681 'forum_id' => (int) $row['forum_id'],
682 'icon_id' => (int) $row['icon_id'],
683 'topic_attachment' => (int) $row['topic_attachment'],
684 'topic_approved' => 1, // a shadow topic is always approved
685 'topic_reported' => 0, // a shadow topic is never reported
686 'topic_title' => (string) $row['topic_title'],
687 'topic_poster' => (int) $row['topic_poster'],
688 'topic_time' => (int) $row['topic_time'],
689 'topic_time_limit' => (int) $row['topic_time_limit'],
690 'topic_views' => (int) $row['topic_views'],
691 'topic_replies' => (int) $row['topic_replies'],
692 'topic_replies_real' => (int) $row['topic_replies_real'],
693 'topic_status' => ITEM_MOVED,
694 'topic_type' => POST_NORMAL,
695 'topic_first_post_id' => (int) $row['topic_first_post_id'],
696 'topic_first_poster_colour'=>(string) $row['topic_first_poster_colour'],
697 'topic_first_poster_name'=> (string) $row['topic_first_poster_name'],
698 'topic_last_post_id' => (int) $row['topic_last_post_id'],
699 'topic_last_poster_id' => (int) $row['topic_last_poster_id'],
700 'topic_last_poster_colour'=>(string) $row['topic_last_poster_colour'],
701 'topic_last_poster_name'=> (string) $row['topic_last_poster_name'],
702 'topic_last_post_subject'=> (string) $row['topic_last_post_subject'],
703 'topic_last_post_time' => (int) $row['topic_last_post_time'],
704 'topic_last_view_time' => (int) $row['topic_last_view_time'],
705 'topic_moved_id' => (int) $row['topic_id'],
706 'topic_bumped' => (int) $row['topic_bumped'],
707 'topic_bumper' => (int) $row['topic_bumper'],
708 'poll_title' => (string) $row['poll_title'],
709 'poll_start' => (int) $row['poll_start'],
710 'poll_length' => (int) $row['poll_length'],
711 'poll_max_options' => (int) $row['poll_max_options'],
712 'poll_last_vote' => (int) $row['poll_last_vote']
715 $db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow));
717 // Shadow topics only count on new "topics" and not posts... a shadow topic alone has 0 posts
719 $topics_authed_removed--;
724 if ($topic_posts_removed)
726 $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . $topic_posts_removed;
731 $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) $topics_removed;
734 if ($topics_authed_removed)
736 $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $topics_authed_removed;
739 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS';
741 foreach ($sync_sql as $forum_id_key => $array)
743 $sql = 'UPDATE ' . FORUMS_TABLE . '
744 SET ' . implode(', ', $array) . '
745 WHERE forum_id = ' . $forum_id_key;
746 $db->sql_query($sql);
749 $db->sql_transaction('commit');
751 sync('forum', 'forum_id', array($forum_id, $to_forum_id));
755 $template->assign_vars(array(
756 'S_FORUM_SELECT' => make_forum_select($to_forum_id, $forum_id, false, true, true, true),
757 'S_CAN_LEAVE_SHADOW' => true,
758 'ADDITIONAL_MSG' => $additional_msg)
761 confirm_box(false, 'MOVE_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
764 $redirect = request_var('redirect', "index.$phpEx");
765 $redirect = reapply_sid($redirect);
773 meta_refresh(3, $redirect);
775 $message = $user->lang[$success_msg];
776 $message .= '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
777 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id") . '">', '</a>');
778 $message .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$to_forum_id") . '">', '</a>');
780 trigger_error($message);
787 function mcp_delete_topic($topic_ids)
789 global $auth, $user, $db, $phpEx, $phpbb_root_path;
791 if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete')))
796 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
797 $forum_id = request_var('f', 0);
799 $s_hidden_fields = build_hidden_fields(array(
800 'topic_id_list' => $topic_ids,
802 'action' => 'delete_topic',
803 'redirect' => $redirect)
807 if (confirm_box(true))
809 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS';
811 $data = get_topic_data($topic_ids);
813 foreach ($data as $topic_id => $row)
815 if ($row['topic_moved_id'])
817 add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_SHADOW_TOPIC', $row['topic_title']);
821 add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']);
825 $return = delete_topics('topic_id', $topic_ids);
829 confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields);
832 if (!isset($_REQUEST['quickmod']))
834 $redirect = request_var('redirect', "index.$phpEx");
835 $redirect = reapply_sid($redirect);
836 $redirect_message = 'PAGE';
840 $redirect = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
841 $redirect_message = 'FORUM';
850 meta_refresh(3, $redirect);
851 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_' . $redirect_message], '<a href="' . $redirect . '">', '</a>'));
858 function mcp_delete_post($post_ids)
860 global $auth, $user, $db, $phpEx, $phpbb_root_path;
862 if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_delete')))
867 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
868 $forum_id = request_var('f', 0);
870 $s_hidden_fields = build_hidden_fields(array(
871 'post_id_list' => $post_ids,
873 'action' => 'delete_post',
874 'redirect' => $redirect)
878 if (confirm_box(true))
880 if (!function_exists('delete_posts'))
882 include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
885 // Count the number of topics that are affected
886 // I did not use COUNT(DISTINCT ...) because I remember having problems
887 // with it on older versions of MySQL -- Ashe
889 $sql = 'SELECT DISTINCT topic_id
890 FROM ' . POSTS_TABLE . '
891 WHERE ' . $db->sql_in_set('post_id', $post_ids);
892 $result = $db->sql_query($sql);
894 $topic_id_list = array();
895 while ($row = $db->sql_fetchrow($result))
897 $topic_id_list[] = $row['topic_id'];
899 $affected_topics = sizeof($topic_id_list);
900 $db->sql_freeresult($result);
902 $post_data = get_post_data($post_ids);
904 foreach ($post_data as $id => $row)
906 $post_username = ($row['poster_id'] == ANONYMOUS && !empty($row['post_username'])) ? $row['post_username'] : $row['username'];
907 add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_DELETE_POST', $row['post_subject'], $post_username);
910 // Now delete the posts, topics and forums are automatically resync'ed
911 delete_posts('post_id', $post_ids);
913 $sql = 'SELECT COUNT(topic_id) AS topics_left
914 FROM ' . TOPICS_TABLE . '
915 WHERE ' . $db->sql_in_set('topic_id', $topic_id_list);
916 $result = $db->sql_query_limit($sql, 1);
918 $deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics;
919 $db->sql_freeresult($result);
921 $topic_id = request_var('t', 0);
924 $return_link = array();
925 if ($affected_topics == 1 && !$deleted_topics && $topic_id)
927 $return_link[] = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id") . '">', '</a>');
929 $return_link[] = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
931 if (sizeof($post_ids) == 1)
935 // We deleted the only post of a topic, which in turn has
936 // been removed from the database
937 $success_msg = $user->lang['TOPIC_DELETED_SUCCESS'];
941 $success_msg = $user->lang['POST_DELETED_SUCCESS'];
948 // Some of topics disappeared
949 $success_msg = $user->lang['POSTS_DELETED_SUCCESS'] . '<br /><br />' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING'];
953 $success_msg = $user->lang['POSTS_DELETED_SUCCESS'];
959 confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields);
962 $redirect = request_var('redirect', "index.$phpEx");
963 $redirect = reapply_sid($redirect);
971 if ($affected_topics != 1 || $deleted_topics || !$topic_id)
973 $redirect = append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&i=main&mode=forum_view", false);
976 meta_refresh(3, $redirect);
977 trigger_error($success_msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>') . '<br /><br />' . implode('<br /><br />', $return_link));
984 function mcp_fork_topic($topic_ids)
986 global $auth, $user, $db, $template, $config;
987 global $phpEx, $phpbb_root_path;
989 if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_')))
994 $to_forum_id = request_var('to_forum_id', 0);
995 $forum_id = request_var('f', 0);
996 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
997 $additional_msg = $success_msg = '';
999 $s_hidden_fields = build_hidden_fields(array(
1000 'topic_id_list' => $topic_ids,
1003 'redirect' => $redirect)
1008 $forum_data = get_forum_data($to_forum_id, 'f_post');
1010 if (!sizeof($topic_ids))
1012 $additional_msg = $user->lang['NO_TOPIC_SELECTED'];
1014 else if (!sizeof($forum_data))
1016 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
1020 $forum_data = $forum_data[$to_forum_id];
1022 if ($forum_data['forum_type'] != FORUM_POST)
1024 $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
1026 else if (!$auth->acl_get('f_post', $to_forum_id))
1028 $additional_msg = $user->lang['USER_CANNOT_POST'];
1032 else if (isset($_POST['confirm']))
1034 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
1037 if ($additional_msg)
1039 unset($_POST['confirm']);
1040 unset($_REQUEST['confirm_key']);
1043 if (confirm_box(true))
1045 $topic_data = get_topic_data($topic_ids, 'f_post');
1048 $new_topic_id_list = array();
1051 foreach ($topic_data as $topic_id => $topic_row)
1053 if (!isset($search_type) && $topic_row['enable_indexing'])
1055 // Select the search method and do some additional checks to ensure it can actually be utilised
1056 $search_type = basename($config['search_type']);
1058 if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
1060 trigger_error('NO_SUCH_SEARCH_MODULE');
1063 if (!class_exists($search_type))
1065 include("{$phpbb_root_path}includes/search/$search_type.$phpEx");
1069 $search = new $search_type($error);
1070 $search_mode = 'post';
1074 trigger_error($error);
1077 else if (!isset($search_type) && !$topic_row['enable_indexing'])
1079 $search_type = false;
1083 'forum_id' => (int) $to_forum_id,
1084 'icon_id' => (int) $topic_row['icon_id'],
1085 'topic_attachment' => (int) $topic_row['topic_attachment'],
1086 'topic_approved' => 1,
1087 'topic_reported' => 0,
1088 'topic_title' => (string) $topic_row['topic_title'],
1089 'topic_poster' => (int) $topic_row['topic_poster'],
1090 'topic_time' => (int) $topic_row['topic_time'],
1091 'topic_replies' => (int) $topic_row['topic_replies_real'],
1092 'topic_replies_real' => (int) $topic_row['topic_replies_real'],
1093 'topic_status' => (int) $topic_row['topic_status'],
1094 'topic_type' => (int) $topic_row['topic_type'],
1095 'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'],
1096 'topic_last_poster_id' => (int) $topic_row['topic_last_poster_id'],
1097 'topic_last_poster_name' => (string) $topic_row['topic_last_poster_name'],
1098 'topic_last_post_time' => (int) $topic_row['topic_last_post_time'],
1099 'topic_last_view_time' => (int) $topic_row['topic_last_view_time'],
1100 'topic_bumped' => (int) $topic_row['topic_bumped'],
1101 'topic_bumper' => (int) $topic_row['topic_bumper'],
1102 'poll_title' => (string) $topic_row['poll_title'],
1103 'poll_start' => (int) $topic_row['poll_start'],
1104 'poll_length' => (int) $topic_row['poll_length'],
1105 'poll_max_options' => (int) $topic_row['poll_max_options'],
1106 'poll_vote_change' => (int) $topic_row['poll_vote_change'],
1109 $db->sql_query('INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1110 $new_topic_id = $db->sql_nextid();
1111 $new_topic_id_list[$topic_id] = $new_topic_id;
1113 if ($topic_row['poll_start'])
1115 $poll_rows = array();
1118 FROM ' . POLL_OPTIONS_TABLE . "
1119 WHERE topic_id = $topic_id";
1120 $result = $db->sql_query($sql);
1122 while ($row = $db->sql_fetchrow($result))
1125 'poll_option_id' => (int) $row['poll_option_id'],
1126 'topic_id' => (int) $new_topic_id,
1127 'poll_option_text' => (string) $row['poll_option_text'],
1128 'poll_option_total' => 0
1131 $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1136 FROM ' . POSTS_TABLE . "
1137 WHERE topic_id = $topic_id
1138 ORDER BY post_time ASC";
1139 $result = $db->sql_query($sql);
1141 $post_rows = array();
1142 while ($row = $db->sql_fetchrow($result))
1144 $post_rows[] = $row;
1146 $db->sql_freeresult($result);
1148 if (!sizeof($post_rows))
1153 $total_posts += sizeof($post_rows);
1154 foreach ($post_rows as $row)
1157 'topic_id' => (int) $new_topic_id,
1158 'forum_id' => (int) $to_forum_id,
1159 'poster_id' => (int) $row['poster_id'],
1160 'icon_id' => (int) $row['icon_id'],
1161 'poster_ip' => (string) $row['poster_ip'],
1162 'post_time' => (int) $row['post_time'],
1163 'post_approved' => 1,
1164 'post_reported' => 0,
1165 'enable_bbcode' => (int) $row['enable_bbcode'],
1166 'enable_smilies' => (int) $row['enable_smilies'],
1167 'enable_magic_url' => (int) $row['enable_magic_url'],
1168 'enable_sig' => (int) $row['enable_sig'],
1169 'post_username' => (string) $row['post_username'],
1170 'post_subject' => (string) $row['post_subject'],
1171 'post_text' => (string) $row['post_text'],
1172 'post_edit_reason' => (string) $row['post_edit_reason'],
1173 'post_edit_user' => (int) $row['post_edit_user'],
1174 'post_checksum' => (string) $row['post_checksum'],
1175 'post_attachment' => (int) $row['post_attachment'],
1176 'bbcode_bitfield' => $row['bbcode_bitfield'],
1177 'bbcode_uid' => (string) $row['bbcode_uid'],
1178 'post_edit_time' => (int) $row['post_edit_time'],
1179 'post_edit_count' => (int) $row['post_edit_count'],
1180 'post_edit_locked' => (int) $row['post_edit_locked'],
1181 'post_postcount' => 0,
1184 $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1185 $new_post_id = $db->sql_nextid();
1187 // Copy whether the topic is dotted
1188 markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']);
1190 if (!empty($search_type))
1192 $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);
1193 $search_mode = 'reply'; // After one we index replies
1197 if ($row['post_attachment'])
1199 $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . "
1200 WHERE post_msg_id = {$row['post_id']}
1201 AND topic_id = $topic_id
1202 AND in_message = 0";
1203 $result = $db->sql_query($sql);
1206 while ($attach_row = $db->sql_fetchrow($result))
1209 'post_msg_id' => (int) $new_post_id,
1210 'topic_id' => (int) $new_topic_id,
1212 'is_orphan' => (int) $attach_row['is_orphan'],
1213 'poster_id' => (int) $attach_row['poster_id'],
1214 'physical_filename' => (string) utf8_basename($attach_row['physical_filename']),
1215 'real_filename' => (string) utf8_basename($attach_row['real_filename']),
1216 'download_count' => (int) $attach_row['download_count'],
1217 'attach_comment' => (string) $attach_row['attach_comment'],
1218 'extension' => (string) $attach_row['extension'],
1219 'mimetype' => (string) $attach_row['mimetype'],
1220 'filesize' => (int) $attach_row['filesize'],
1221 'filetime' => (int) $attach_row['filetime'],
1222 'thumbnail' => (int) $attach_row['thumbnail']
1225 $db->sql_freeresult($result);
1227 if (sizeof($sql_ary))
1229 $db->sql_multi_insert(ATTACHMENTS_TABLE, $sql_ary);
1234 $sql = 'SELECT user_id, notify_status
1235 FROM ' . TOPICS_WATCH_TABLE . '
1236 WHERE topic_id = ' . $topic_id;
1237 $result = $db->sql_query($sql);
1240 while ($row = $db->sql_fetchrow($result))
1243 'topic_id' => (int) $new_topic_id,
1244 'user_id' => (int) $row['user_id'],
1245 'notify_status' => (int) $row['notify_status'],
1248 $db->sql_freeresult($result);
1250 if (sizeof($sql_ary))
1252 $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
1256 // Sync new topics, parent forums and board stats
1257 sync('topic', 'topic_id', $new_topic_id_list);
1259 $sync_sql = array();
1261 $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $total_posts;
1262 $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . sizeof($new_topic_id_list);
1263 $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . sizeof($new_topic_id_list);
1265 foreach ($sync_sql as $forum_id_key => $array)
1267 $sql = 'UPDATE ' . FORUMS_TABLE . '
1268 SET ' . implode(', ', $array) . '
1269 WHERE forum_id = ' . $forum_id_key;
1270 $db->sql_query($sql);
1273 sync('forum', 'forum_id', $to_forum_id);
1274 set_config_count('num_topics', sizeof($new_topic_id_list), true);
1275 set_config_count('num_posts', $total_posts, true);
1277 foreach ($new_topic_id_list as $topic_id => $new_topic_id)
1279 add_log('mod', $to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']);
1282 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS';
1286 $template->assign_vars(array(
1287 'S_FORUM_SELECT' => make_forum_select($to_forum_id, false, false, true, true, true),
1288 'S_CAN_LEAVE_SHADOW' => false,
1289 'ADDITIONAL_MSG' => $additional_msg)
1292 confirm_box(false, 'FORK_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
1295 $redirect = request_var('redirect', "index.$phpEx");
1296 $redirect = reapply_sid($redirect);
1300 redirect($redirect);
1304 $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
1305 meta_refresh(3, $redirect_url);
1306 $return_link = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>');
1308 if ($forum_id != $to_forum_id)
1310 $return_link .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $to_forum_id) . '">', '</a>');
1313 trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);