merge again, revisions 8516 to 8525
[phpbb.git] / phpBB / includes / mcp / mcp_main.php
blobf000bcc881f29c70950cd2fe49c053dbd09cc8b2
1 <?php
2 /**
4 * @package mcp
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * @ignore
14 if (!defined('IN_PHPBB'))
16 exit;
19 /**
20 * mcp_main
21 * Handling mcp actions
22 * @package mcp
24 class mcp_main
26 var $p_master;
27 var $u_action;
29 function __construct(&$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;
41 switch ($action)
43 case 'lock':
44 case 'unlock':
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);
53 break;
55 case 'lock_post':
56 case 'unlock_post':
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);
66 break;
68 case 'make_announce':
69 case 'make_sticky':
70 case 'make_global':
71 case 'make_normal':
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);
81 break;
83 case 'move':
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);
94 break;
96 case 'fork':
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);
107 break;
109 case 'delete_topic':
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);
120 break;
122 case 'delete_post':
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);
133 break;
136 switch ($mode)
138 case 'front':
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';
147 break;
149 case 'forum_view':
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');
161 return;
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';
170 break;
172 case 'topic_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';
179 break;
181 case 'post_details':
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';
188 break;
190 default:
191 trigger_error('NO_MODE', E_USER_ERROR);
192 break;
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';
209 $l_prefix = 'TOPIC';
211 else
213 $table = POSTS_TABLE;
214 $sql_id = 'post_id';
215 $set_id = 'post_edit_locked';
216 $l_prefix = 'POST';
219 $orig_ids = $ids;
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')
226 return;
229 $ids = $orig_ids;
231 if (!check_ids($ids, $table, $sql_id, array('f_user_lock')))
233 return;
236 unset($orig_ids);
238 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
240 $s_hidden_fields = build_hidden_fields(array(
241 $sql_id . '_list' => $ids,
242 'action' => $action,
243 'redirect' => $redirect)
245 $success_msg = '';
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';
263 else
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);
271 if (!$success_msg)
273 redirect($redirect);
275 else
277 meta_refresh(2, $redirect);
278 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
283 * Change Topic Type
285 function change_topic_type($action, $topic_ids)
287 global $auth, $user, $db, $phpEx, $phpbb_root_path;
289 // For changing topic types, we only allow operations in one forum.
290 $forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('f_announce', 'f_sticky', 'm_'), true);
292 if ($forum_id === false)
294 return;
297 switch ($action)
299 case 'make_announce':
300 $new_topic_type = POST_ANNOUNCE;
301 $check_acl = 'f_announce';
302 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_ANNOUNCEMENT' : 'MCP_MAKE_ANNOUNCEMENTS';
303 break;
305 case 'make_global':
306 $new_topic_type = POST_GLOBAL;
307 $check_acl = 'f_announce';
308 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_GLOBAL' : 'MCP_MAKE_GLOBALS';
309 break;
311 case 'make_sticky':
312 $new_topic_type = POST_STICKY;
313 $check_acl = 'f_sticky';
314 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_STICKY' : 'MCP_MAKE_STICKIES';
315 break;
317 default:
318 $new_topic_type = POST_NORMAL;
319 $check_acl = '';
320 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_NORMAL' : 'MCP_MAKE_NORMALS';
321 break;
324 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
326 $s_hidden_fields = array(
327 'topic_id_list' => $topic_ids,
328 'f' => $forum_id,
329 'action' => $action,
330 'redirect' => $redirect,
332 $success_msg = '';
334 if (confirm_box(true))
336 if ($new_topic_type != POST_GLOBAL)
338 $sql = 'UPDATE ' . TOPICS_TABLE . "
339 SET topic_type = $new_topic_type
340 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
341 AND forum_id <> 0';
342 $db->sql_query($sql);
344 // Reset forum id if a global topic is within the array
345 $to_forum_id = request_var('to_forum_id', 0);
347 if ($to_forum_id)
349 $sql = 'UPDATE ' . TOPICS_TABLE . "
350 SET topic_type = $new_topic_type, forum_id = $to_forum_id
351 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
352 AND forum_id = 0';
353 $db->sql_query($sql);
355 // Update forum_ids for all posts
356 $sql = 'UPDATE ' . POSTS_TABLE . "
357 SET forum_id = $to_forum_id
358 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
359 AND forum_id = 0';
360 $db->sql_query($sql);
362 // Do a little forum sync stuff
363 $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
364 FROM ' . TOPICS_TABLE . ' t
365 WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
366 $result = $db->sql_query($sql);
367 $row_data = $db->sql_fetchrow($result);
368 $db->sql_freeresult($result);
370 $sync_sql = array();
372 if ($row_data['topic_posts'])
374 $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . (int) $row_data['topic_posts'];
377 if ($row_data['topics_authed'])
379 $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $row_data['topics_authed'];
382 $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) sizeof($topic_ids);
384 foreach ($sync_sql as $forum_id_key => $array)
386 $sql = 'UPDATE ' . FORUMS_TABLE . '
387 SET ' . implode(', ', $array) . '
388 WHERE forum_id = ' . $forum_id_key;
389 $db->sql_query($sql);
392 sync('forum', 'forum_id', $to_forum_id);
395 else
397 // Get away with those topics already being a global announcement by re-calculating $topic_ids
398 $sql = 'SELECT topic_id
399 FROM ' . TOPICS_TABLE . '
400 WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
401 AND forum_id <> 0';
402 $result = $db->sql_query($sql);
404 $topic_ids = array();
405 while ($row = $db->sql_fetchrow($result))
407 $topic_ids[] = $row['topic_id'];
409 $db->sql_freeresult($result);
411 if (sizeof($topic_ids))
413 // Delete topic shadows for global announcements
414 $sql = 'DELETE FROM ' . TOPICS_TABLE . '
415 WHERE ' . $db->sql_in_set('topic_moved_id', $topic_ids);
416 $db->sql_query($sql);
418 $sql = 'UPDATE ' . TOPICS_TABLE . "
419 SET topic_type = $new_topic_type, forum_id = 0
420 WHERE " . $db->sql_in_set('topic_id', $topic_ids);
421 $db->sql_query($sql);
423 // Update forum_ids for all posts
424 $sql = 'UPDATE ' . POSTS_TABLE . '
425 SET forum_id = 0
426 WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
427 $db->sql_query($sql);
429 // Do a little forum sync stuff
430 $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
431 FROM ' . TOPICS_TABLE . ' t
432 WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
433 $result = $db->sql_query($sql);
434 $row_data = $db->sql_fetchrow($result);
435 $db->sql_freeresult($result);
437 $sync_sql = array();
439 if ($row_data['topic_posts'])
441 $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts'];
444 if ($row_data['topics_authed'])
446 $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $row_data['topics_authed'];
449 $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) sizeof($topic_ids);
451 foreach ($sync_sql as $forum_id_key => $array)
453 $sql = 'UPDATE ' . FORUMS_TABLE . '
454 SET ' . implode(', ', $array) . '
455 WHERE forum_id = ' . $forum_id_key;
456 $db->sql_query($sql);
459 sync('forum', 'forum_id', $forum_id);
463 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_TYPE_CHANGED' : 'TOPICS_TYPE_CHANGED';
465 if (sizeof($topic_ids))
467 $data = get_topic_data($topic_ids);
469 foreach ($data as $topic_id => $row)
471 add_log('mod', $forum_id, $topic_id, 'LOG_TOPIC_TYPE_CHANGED', $row['topic_title']);
475 else
477 // Global topic involved?
478 $global_involved = false;
480 if ($new_topic_type != POST_GLOBAL)
482 $sql = 'SELECT forum_id
483 FROM ' . TOPICS_TABLE . '
484 WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
485 AND forum_id = 0';
486 $result = $db->sql_query($sql);
487 $row = $db->sql_fetchrow($result);
488 $db->sql_freeresult($result);
490 if ($row)
492 $global_involved = true;
496 if ($global_involved)
498 global $template;
500 $template->assign_vars(array(
501 'S_FORUM_SELECT' => make_forum_select(request_var('f', $forum_id), false, false, true, true),
502 'S_CAN_LEAVE_SHADOW' => false,
503 'ADDITIONAL_MSG' => (sizeof($topic_ids) == 1) ? $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENT'] : $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENTS'])
506 confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields), 'mcp_move.html');
508 else
510 confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields));
514 $redirect = request_var('redirect', "index.$phpEx");
515 $redirect = reapply_sid($redirect);
517 if (!$success_msg)
519 redirect($redirect);
521 else
523 meta_refresh(2, $redirect);
524 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
529 * Move Topic
531 function mcp_move_topic($topic_ids)
533 global $auth, $user, $db, $template;
534 global $phpEx, $phpbb_root_path;
536 // Here we limit the operation to one forum only
537 $forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_move'), true);
539 if ($forum_id === false)
541 return;
544 $to_forum_id = request_var('to_forum_id', 0);
545 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
546 $additional_msg = $success_msg = '';
548 $s_hidden_fields = build_hidden_fields(array(
549 'topic_id_list' => $topic_ids,
550 'f' => $forum_id,
551 'action' => 'move',
552 'redirect' => $redirect)
555 if ($to_forum_id)
557 $forum_data = get_forum_data($to_forum_id);
559 if (!sizeof($forum_data))
561 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
563 else
565 $forum_data = $forum_data[$to_forum_id];
567 if ($forum_data['forum_type'] != FORUM_POST)
569 $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
571 else if (!$auth->acl_get('f_post', $to_forum_id))
573 $additional_msg = $user->lang['USER_CANNOT_POST'];
575 else if ($forum_id == $to_forum_id)
577 $additional_msg = $user->lang['CANNOT_MOVE_SAME_FORUM'];
581 else if (isset($_POST['confirm']))
583 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
586 if (!$to_forum_id || $additional_msg)
588 unset($_POST['confirm']);
589 unset($_REQUEST['confirm_key']);
592 if (confirm_box(true))
594 $topic_data = get_topic_data($topic_ids);
595 $leave_shadow = (isset($_POST['move_leave_shadow'])) ? true : false;
597 $topics_moved = sizeof($topic_ids);
598 $topics_authed_moved = 0;
599 $forum_sync_data = array();
601 $forum_sync_data[$forum_id] = current($topic_data);
602 $forum_sync_data[$to_forum_id] = $forum_data;
604 foreach ($topic_data as $topic_id => $topic_info)
606 if ($topic_info['topic_approved'] == '1')
608 $topics_authed_moved++;
612 $db->sql_transaction('begin');
614 $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts
615 FROM ' . TOPICS_TABLE . ' t
616 WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
617 $result = $db->sql_query($sql);
618 $row_data = $db->sql_fetchrow($result);
619 $db->sql_freeresult($result);
621 $sync_sql = array();
623 if ($row_data['topic_posts'])
625 $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts'];
626 $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . (int) $row_data['topic_posts'];
629 if ($topics_authed_moved)
631 $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_authed_moved;
634 $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved;
636 // Move topics, but do not resync yet
637 move_topics($topic_ids, $to_forum_id, false);
639 $forum_ids = array($to_forum_id);
640 foreach ($topic_data as $topic_id => $row)
642 // Get the list of forums to resync, add a log entry
643 $forum_ids[] = $row['forum_id'];
644 add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name']);
646 // If we have moved a global announcement, we need to correct the topic type
647 if ($row['topic_type'] == POST_GLOBAL)
649 $sql = 'UPDATE ' . TOPICS_TABLE . '
650 SET topic_type = ' . POST_ANNOUNCE . '
651 WHERE topic_id = ' . (int) $row['topic_id'];
652 $db->sql_query($sql);
655 // Leave a redirection if required and only if the topic is visible to users
656 if ($leave_shadow && $row['topic_approved'] && $row['topic_type'] != POST_GLOBAL)
658 $shadow = array(
659 'forum_id' => (int) $row['forum_id'],
660 'icon_id' => (int) $row['icon_id'],
661 'topic_attachment' => (int) $row['topic_attachment'],
662 'topic_approved' => 1,
663 'topic_reported' => (int) $row['topic_reported'],
664 'topic_title' => (string) $row['topic_title'],
665 'topic_poster' => (int) $row['topic_poster'],
666 'topic_time' => (int) $row['topic_time'],
667 'topic_time_limit' => (int) $row['topic_time_limit'],
668 'topic_views' => (int) $row['topic_views'],
669 'topic_replies' => (int) $row['topic_replies'],
670 'topic_replies_real' => (int) $row['topic_replies_real'],
671 'topic_status' => ITEM_MOVED,
672 'topic_type' => POST_NORMAL,
673 'topic_first_post_id' => (int) $row['topic_first_post_id'],
674 'topic_first_poster_colour'=>(string) $row['topic_first_poster_colour'],
675 'topic_first_poster_name'=> (string) $row['topic_first_poster_name'],
676 'topic_last_post_id' => (int) $row['topic_last_post_id'],
677 'topic_last_poster_id' => (int) $row['topic_last_poster_id'],
678 'topic_last_poster_colour'=>(string) $row['topic_last_poster_colour'],
679 'topic_last_poster_name'=> (string) $row['topic_last_poster_name'],
680 'topic_last_post_subject'=> (string) $row['topic_last_post_subject'],
681 'topic_last_post_time' => (int) $row['topic_last_post_time'],
682 'topic_last_view_time' => (int) $row['topic_last_view_time'],
683 'topic_moved_id' => (int) $row['topic_id'],
684 'topic_bumped' => (int) $row['topic_bumped'],
685 'topic_bumper' => (int) $row['topic_bumper'],
686 'poll_title' => (string) $row['poll_title'],
687 'poll_start' => (int) $row['poll_start'],
688 'poll_length' => (int) $row['poll_length'],
689 'poll_max_options' => (int) $row['poll_max_options'],
690 'poll_last_vote' => (int) $row['poll_last_vote']
693 $db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow));
695 $topics_authed_moved--;
696 $topics_moved--;
699 unset($topic_data);
701 $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) $topics_moved;
703 if ($topics_authed_moved)
705 $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $topics_authed_moved;
708 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS';
710 foreach ($sync_sql as $forum_id_key => $array)
712 $sql = 'UPDATE ' . FORUMS_TABLE . '
713 SET ' . implode(', ', $array) . '
714 WHERE forum_id = ' . $forum_id_key;
715 $db->sql_query($sql);
718 $db->sql_transaction('commit');
720 sync('forum', 'forum_id', array($forum_id, $to_forum_id));
722 else
724 $template->assign_vars(array(
725 'S_FORUM_SELECT' => make_forum_select($to_forum_id, $forum_id, false, true, true, true),
726 'S_CAN_LEAVE_SHADOW' => true,
727 'ADDITIONAL_MSG' => $additional_msg)
730 confirm_box(false, 'MOVE_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
733 $redirect = request_var('redirect', "index.$phpEx");
734 $redirect = reapply_sid($redirect);
736 if (!$success_msg)
738 redirect($redirect);
740 else
742 meta_refresh(3, $redirect);
744 $message = $user->lang[$success_msg];
745 $message .= '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
746 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id") . '">', '</a>');
747 $message .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$to_forum_id") . '">', '</a>');
749 trigger_error($message);
754 * Delete Topics
756 function mcp_delete_topic($topic_ids)
758 global $auth, $user, $db, $phpEx, $phpbb_root_path;
760 if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete')))
762 return;
765 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
766 $forum_id = request_var('f', 0);
768 $s_hidden_fields = build_hidden_fields(array(
769 'topic_id_list' => $topic_ids,
770 'f' => $forum_id,
771 'action' => 'delete_topic',
772 'redirect' => $redirect)
774 $success_msg = '';
776 if (confirm_box(true))
778 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS';
780 $data = get_topic_data($topic_ids);
782 foreach ($data as $topic_id => $row)
784 add_log('mod', $row['forum_id'], 0, 'LOG_TOPIC_DELETED', $row['topic_title']);
787 $return = delete_topics('topic_id', $topic_ids);
789 else
791 confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields);
794 $redirect = request_var('redirect', "index.$phpEx");
795 $redirect = reapply_sid($redirect);
797 if (!$success_msg)
799 redirect($redirect);
801 else
803 $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
804 meta_refresh(3, $redirect_url);
805 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
810 * Delete Posts
812 function mcp_delete_post($post_ids)
814 global $auth, $user, $db, $phpEx, $phpbb_root_path;
816 if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_delete')))
818 return;
821 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
822 $forum_id = request_var('f', 0);
824 $s_hidden_fields = build_hidden_fields(array(
825 'post_id_list' => $post_ids,
826 'f' => $forum_id,
827 'action' => 'delete_post',
828 'redirect' => $redirect)
830 $success_msg = '';
832 if (confirm_box(true))
834 if (!function_exists('delete_posts'))
836 include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
839 // Count the number of topics that are affected
840 // I did not use COUNT(DISTINCT ...) because I remember having problems
841 // with it on older versions of MySQL -- Ashe
843 $sql = 'SELECT DISTINCT topic_id
844 FROM ' . POSTS_TABLE . '
845 WHERE ' . $db->sql_in_set('post_id', $post_ids);
846 $result = $db->sql_query($sql);
848 $topic_id_list = array();
849 while ($row = $db->sql_fetchrow($result))
851 $topic_id_list[] = $row['topic_id'];
853 $affected_topics = sizeof($topic_id_list);
854 $db->sql_freeresult($result);
856 $post_data = get_post_data($post_ids);
858 foreach ($post_data as $id => $row)
860 add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_DELETE_POST', $row['post_subject']);
863 // Now delete the posts, topics and forums are automatically resync'ed
864 delete_posts('post_id', $post_ids);
866 $sql = 'SELECT COUNT(topic_id) AS topics_left
867 FROM ' . TOPICS_TABLE . '
868 WHERE ' . $db->sql_in_set('topic_id', $topic_id_list);
869 $result = $db->sql_query_limit($sql, 1);
871 $deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics;
872 $db->sql_freeresult($result);
874 $topic_id = request_var('t', 0);
876 // Return links
877 $return_link = array();
878 if ($affected_topics == 1 && !$deleted_topics && $topic_id)
880 $return_link[] = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id") . '">', '</a>');
882 $return_link[] = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
884 if (sizeof($post_ids) == 1)
886 if ($deleted_topics)
888 // We deleted the only post of a topic, which in turn has
889 // been removed from the database
890 $success_msg = $user->lang['TOPIC_DELETED_SUCCESS'];
892 else
894 $success_msg = $user->lang['POST_DELETED_SUCCESS'];
897 else
899 if ($deleted_topics)
901 // Some of topics disappeared
902 $success_msg = $user->lang['POSTS_DELETED_SUCCESS'] . '<br /><br />' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING'];
904 else
906 $success_msg = $user->lang['POSTS_DELETED_SUCCESS'];
910 else
912 confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields);
915 $redirect = request_var('redirect', "index.$phpEx");
916 $redirect = reapply_sid($redirect);
918 if (!$success_msg)
920 redirect($redirect);
922 else
924 meta_refresh(3, $redirect);
925 trigger_error($success_msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>') . '<br /><br />' . implode('<br /><br />', $return_link));
930 * Fork Topic
932 function mcp_fork_topic($topic_ids)
934 global $auth, $user, $db, $template, $config;
935 global $phpEx, $phpbb_root_path;
937 if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_')))
939 return;
942 $to_forum_id = request_var('to_forum_id', 0);
943 $forum_id = request_var('f', 0);
944 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
945 $additional_msg = $success_msg = '';
947 $s_hidden_fields = build_hidden_fields(array(
948 'topic_id_list' => $topic_ids,
949 'f' => $forum_id,
950 'action' => 'fork',
951 'redirect' => $redirect)
954 if ($to_forum_id)
956 $forum_data = get_forum_data($to_forum_id);
958 if (!sizeof($topic_ids))
960 $additional_msg = $user->lang['NO_TOPIC_SELECTED'];
962 else if (!sizeof($forum_data))
964 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
966 else
968 $forum_data = $forum_data[$to_forum_id];
970 if ($forum_data['forum_type'] != FORUM_POST)
972 $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
974 else if (!$auth->acl_get('f_post', $to_forum_id))
976 $additional_msg = $user->lang['USER_CANNOT_POST'];
980 else if (isset($_POST['confirm']))
982 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
985 if ($additional_msg)
987 unset($_POST['confirm']);
988 unset($_REQUEST['confirm_key']);
991 if (confirm_box(true))
993 $topic_data = get_topic_data($topic_ids);
995 $total_posts = 0;
996 $new_topic_id_list = array();
998 foreach ($topic_data as $topic_id => $topic_row)
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']
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;
1029 if ($topic_row['poll_start'])
1031 $poll_rows = array();
1033 $sql = 'SELECT *
1034 FROM ' . POLL_OPTIONS_TABLE . "
1035 WHERE topic_id = $topic_id";
1036 $result = $db->sql_query($sql);
1038 while ($row = $db->sql_fetchrow($result))
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
1047 $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
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);
1057 $post_rows = array();
1058 while ($row = $db->sql_fetchrow($result))
1060 $post_rows[] = $row;
1062 $db->sql_freeresult($result);
1064 if (!sizeof($post_rows))
1066 continue;
1069 $total_posts += sizeof($post_rows);
1070 foreach ($post_rows as $row)
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,
1100 $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1101 $new_post_id = $db->sql_nextid();
1103 // Copy whether the topic is dotted
1104 markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']);
1106 // Copy Attachments
1107 if ($row['post_attachment'])
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);
1115 $sql_ary = array();
1116 while ($attach_row = $db->sql_fetchrow($result))
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']
1135 $db->sql_freeresult($result);
1137 if (sizeof($sql_ary))
1139 $db->sql_multi_insert(ATTACHMENTS_TABLE, $sql_ary);
1144 $sql = 'SELECT user_id, notify_status
1145 FROM ' . TOPICS_WATCH_TABLE . '
1146 WHERE topic_id = ' . $topic_id;
1147 $result = $db->sql_query($sql);
1149 $sql_ary = array();
1150 while ($row = $db->sql_fetchrow($result))
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'],
1158 $db->sql_freeresult($result);
1160 if (sizeof($sql_ary))
1162 $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
1166 // Sync new topics, parent forums and board stats
1167 sync('topic', 'topic_id', $new_topic_id_list);
1169 $sync_sql = array();
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);
1175 foreach ($sync_sql as $forum_id_key => $array)
1177 $sql = 'UPDATE ' . FORUMS_TABLE . '
1178 SET ' . implode(', ', $array) . '
1179 WHERE forum_id = ' . $forum_id_key;
1180 $db->sql_query($sql);
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);
1187 foreach ($new_topic_id_list as $topic_id => $new_topic_id)
1189 add_log('mod', $to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']);
1192 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS';
1194 else
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)
1202 confirm_box(false, 'FORK_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
1205 $redirect = request_var('redirect', "index.$phpEx");
1206 $redirect = reapply_sid($redirect);
1208 if (!$success_msg)
1210 redirect($redirect);
1212 else
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>');
1218 if ($forum_id != $to_forum_id)
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>');
1223 trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);