(a little test for later merges)
[phpbb.git] / phpBB / includes / mcp / mcp_main.php
blob50b05e989faf1c170ebca0502a1ea5800b18e606
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 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;
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, 'f_post');
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 $forum_sync_data = array();
599 $forum_sync_data[$forum_id] = current($topic_data);
600 $forum_sync_data[$to_forum_id] = $forum_data;
602 // Real topics added to target forum
603 $topics_moved = sizeof($topic_data);
605 // Approved topics added to target forum
606 $topics_authed_moved = 0;
608 // Posts (topic replies + topic post if approved) added to target forum
609 $topic_posts_added = 0;
611 // Posts (topic replies + topic post if approved and not global announcement) removed from source forum
612 $topic_posts_removed = 0;
614 // Real topics removed from source forum (all topics without global announcements)
615 $topics_removed = 0;
617 // Approved topics removed from source forum (except global announcements)
618 $topics_authed_removed = 0;
620 foreach ($topic_data as $topic_id => $topic_info)
622 if ($topic_info['topic_approved'])
624 $topics_authed_moved++;
625 $topic_posts_added++;
628 $topic_posts_added += $topic_info['topic_replies'];
630 if ($topic_info['topic_type'] != POST_GLOBAL)
632 $topics_removed++;
633 $topic_posts_removed += $topic_info['topic_replies'];
635 if ($topic_info['topic_approved'])
637 $topics_authed_removed++;
638 $topic_posts_removed++;
643 $db->sql_transaction('begin');
645 $sync_sql = array();
647 if ($topic_posts_added)
649 $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $topic_posts_added;
652 if ($topics_authed_moved)
654 $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_authed_moved;
657 $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved;
659 // Move topics, but do not resync yet
660 move_topics($topic_ids, $to_forum_id, false);
662 $forum_ids = array($to_forum_id);
663 foreach ($topic_data as $topic_id => $row)
665 // Get the list of forums to resync, add a log entry
666 $forum_ids[] = $row['forum_id'];
667 add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name'], $forum_data['forum_name']);
669 // If we have moved a global announcement, we need to correct the topic type
670 if ($row['topic_type'] == POST_GLOBAL)
672 $sql = 'UPDATE ' . TOPICS_TABLE . '
673 SET topic_type = ' . POST_ANNOUNCE . '
674 WHERE topic_id = ' . (int) $row['topic_id'];
675 $db->sql_query($sql);
678 // Leave a redirection if required and only if the topic is visible to users
679 if ($leave_shadow && $row['topic_approved'] && $row['topic_type'] != POST_GLOBAL)
681 $shadow = array(
682 'forum_id' => (int) $row['forum_id'],
683 'icon_id' => (int) $row['icon_id'],
684 'topic_attachment' => (int) $row['topic_attachment'],
685 'topic_approved' => 1, // a shadow topic is always approved
686 'topic_reported' => 0, // a shadow topic is never reported
687 'topic_title' => (string) $row['topic_title'],
688 'topic_poster' => (int) $row['topic_poster'],
689 'topic_time' => (int) $row['topic_time'],
690 'topic_time_limit' => (int) $row['topic_time_limit'],
691 'topic_views' => (int) $row['topic_views'],
692 'topic_replies' => (int) $row['topic_replies'],
693 'topic_replies_real' => (int) $row['topic_replies_real'],
694 'topic_status' => ITEM_MOVED,
695 'topic_type' => POST_NORMAL,
696 'topic_first_post_id' => (int) $row['topic_first_post_id'],
697 'topic_first_poster_colour'=>(string) $row['topic_first_poster_colour'],
698 'topic_first_poster_name'=> (string) $row['topic_first_poster_name'],
699 'topic_last_post_id' => (int) $row['topic_last_post_id'],
700 'topic_last_poster_id' => (int) $row['topic_last_poster_id'],
701 'topic_last_poster_colour'=>(string) $row['topic_last_poster_colour'],
702 'topic_last_poster_name'=> (string) $row['topic_last_poster_name'],
703 'topic_last_post_subject'=> (string) $row['topic_last_post_subject'],
704 'topic_last_post_time' => (int) $row['topic_last_post_time'],
705 'topic_last_view_time' => (int) $row['topic_last_view_time'],
706 'topic_moved_id' => (int) $row['topic_id'],
707 'topic_bumped' => (int) $row['topic_bumped'],
708 'topic_bumper' => (int) $row['topic_bumper'],
709 'poll_title' => (string) $row['poll_title'],
710 'poll_start' => (int) $row['poll_start'],
711 'poll_length' => (int) $row['poll_length'],
712 'poll_max_options' => (int) $row['poll_max_options'],
713 'poll_last_vote' => (int) $row['poll_last_vote']
716 $db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow));
718 // Shadow topics only count on new "topics" and not posts... a shadow topic alone has 0 posts
719 $topics_removed--;
720 $topics_authed_removed--;
723 unset($topic_data);
725 if ($topic_posts_removed)
727 $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . $topic_posts_removed;
730 if ($topics_removed)
732 $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) $topics_removed;
735 if ($topics_authed_removed)
737 $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $topics_authed_removed;
740 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS';
742 foreach ($sync_sql as $forum_id_key => $array)
744 $sql = 'UPDATE ' . FORUMS_TABLE . '
745 SET ' . implode(', ', $array) . '
746 WHERE forum_id = ' . $forum_id_key;
747 $db->sql_query($sql);
750 $db->sql_transaction('commit');
752 sync('forum', 'forum_id', array($forum_id, $to_forum_id));
754 else
756 $template->assign_vars(array(
757 'S_FORUM_SELECT' => make_forum_select($to_forum_id, $forum_id, false, true, true, true),
758 'S_CAN_LEAVE_SHADOW' => true,
759 'ADDITIONAL_MSG' => $additional_msg)
762 confirm_box(false, 'MOVE_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
765 $redirect = request_var('redirect', "index.$phpEx");
766 $redirect = reapply_sid($redirect);
768 if (!$success_msg)
770 redirect($redirect);
772 else
774 meta_refresh(3, $redirect);
776 $message = $user->lang[$success_msg];
777 $message .= '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
778 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id") . '">', '</a>');
779 $message .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$to_forum_id") . '">', '</a>');
781 trigger_error($message);
786 * Delete Topics
788 function mcp_delete_topic($topic_ids)
790 global $auth, $user, $db, $phpEx, $phpbb_root_path;
792 if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete')))
794 return;
797 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
798 $forum_id = request_var('f', 0);
800 $s_hidden_fields = build_hidden_fields(array(
801 'topic_id_list' => $topic_ids,
802 'f' => $forum_id,
803 'action' => 'delete_topic',
804 'redirect' => $redirect)
806 $success_msg = '';
808 if (confirm_box(true))
810 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS';
812 $data = get_topic_data($topic_ids);
814 foreach ($data as $topic_id => $row)
816 if ($row['topic_moved_id'])
818 add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_SHADOW_TOPIC', $row['topic_title']);
820 else
822 add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']);
826 $return = delete_topics('topic_id', $topic_ids);
828 else
830 confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields);
833 if (!isset($_REQUEST['quickmod']))
835 $redirect = request_var('redirect', "index.$phpEx");
836 $redirect = reapply_sid($redirect);
837 $redirect_message = 'PAGE';
839 else
841 $redirect = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
842 $redirect_message = 'FORUM';
845 if (!$success_msg)
847 redirect($redirect);
849 else
851 meta_refresh(3, $redirect);
852 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_' . $redirect_message], '<a href="' . $redirect . '">', '</a>'));
857 * Delete Posts
859 function mcp_delete_post($post_ids)
861 global $auth, $user, $db, $phpEx, $phpbb_root_path;
863 if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_delete')))
865 return;
868 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
869 $forum_id = request_var('f', 0);
871 $s_hidden_fields = build_hidden_fields(array(
872 'post_id_list' => $post_ids,
873 'f' => $forum_id,
874 'action' => 'delete_post',
875 'redirect' => $redirect)
877 $success_msg = '';
879 if (confirm_box(true))
881 if (!function_exists('delete_posts'))
883 include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
886 // Count the number of topics that are affected
887 // I did not use COUNT(DISTINCT ...) because I remember having problems
888 // with it on older versions of MySQL -- Ashe
890 $sql = 'SELECT DISTINCT topic_id
891 FROM ' . POSTS_TABLE . '
892 WHERE ' . $db->sql_in_set('post_id', $post_ids);
893 $result = $db->sql_query($sql);
895 $topic_id_list = array();
896 while ($row = $db->sql_fetchrow($result))
898 $topic_id_list[] = $row['topic_id'];
900 $affected_topics = sizeof($topic_id_list);
901 $db->sql_freeresult($result);
903 $post_data = get_post_data($post_ids);
905 foreach ($post_data as $id => $row)
907 $post_username = ($row['poster_id'] == ANONYMOUS && !empty($row['post_username'])) ? $row['post_username'] : $row['username'];
908 add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_DELETE_POST', $row['post_subject'], $post_username);
911 // Now delete the posts, topics and forums are automatically resync'ed
912 delete_posts('post_id', $post_ids);
914 $sql = 'SELECT COUNT(topic_id) AS topics_left
915 FROM ' . TOPICS_TABLE . '
916 WHERE ' . $db->sql_in_set('topic_id', $topic_id_list);
917 $result = $db->sql_query_limit($sql, 1);
919 $deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics;
920 $db->sql_freeresult($result);
922 $topic_id = request_var('t', 0);
924 // Return links
925 $return_link = array();
926 if ($affected_topics == 1 && !$deleted_topics && $topic_id)
928 $return_link[] = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id") . '">', '</a>');
930 $return_link[] = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
932 if (sizeof($post_ids) == 1)
934 if ($deleted_topics)
936 // We deleted the only post of a topic, which in turn has
937 // been removed from the database
938 $success_msg = $user->lang['TOPIC_DELETED_SUCCESS'];
940 else
942 $success_msg = $user->lang['POST_DELETED_SUCCESS'];
945 else
947 if ($deleted_topics)
949 // Some of topics disappeared
950 $success_msg = $user->lang['POSTS_DELETED_SUCCESS'] . '<br /><br />' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING'];
952 else
954 $success_msg = $user->lang['POSTS_DELETED_SUCCESS'];
958 else
960 confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields);
963 $redirect = request_var('redirect', "index.$phpEx");
964 $redirect = reapply_sid($redirect);
966 if (!$success_msg)
968 redirect($redirect);
970 else
972 if ($affected_topics != 1 || $deleted_topics || !$topic_id)
974 $redirect = append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&i=main&mode=forum_view", false);
977 meta_refresh(3, $redirect);
978 trigger_error($success_msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>') . '<br /><br />' . implode('<br /><br />', $return_link));
983 * Fork Topic
985 function mcp_fork_topic($topic_ids)
987 global $auth, $user, $db, $template, $config;
988 global $phpEx, $phpbb_root_path;
990 if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_')))
992 return;
995 $to_forum_id = request_var('to_forum_id', 0);
996 $forum_id = request_var('f', 0);
997 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
998 $additional_msg = $success_msg = '';
1000 $s_hidden_fields = build_hidden_fields(array(
1001 'topic_id_list' => $topic_ids,
1002 'f' => $forum_id,
1003 'action' => 'fork',
1004 'redirect' => $redirect)
1007 if ($to_forum_id)
1009 $forum_data = get_forum_data($to_forum_id, 'f_post');
1011 if (!sizeof($topic_ids))
1013 $additional_msg = $user->lang['NO_TOPIC_SELECTED'];
1015 else if (!sizeof($forum_data))
1017 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
1019 else
1021 $forum_data = $forum_data[$to_forum_id];
1023 if ($forum_data['forum_type'] != FORUM_POST)
1025 $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
1027 else if (!$auth->acl_get('f_post', $to_forum_id))
1029 $additional_msg = $user->lang['USER_CANNOT_POST'];
1033 else if (isset($_POST['confirm']))
1035 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
1038 if ($additional_msg)
1040 unset($_POST['confirm']);
1041 unset($_REQUEST['confirm_key']);
1044 if (confirm_box(true))
1046 $topic_data = get_topic_data($topic_ids, 'f_post');
1048 $total_posts = 0;
1049 $new_topic_id_list = array();
1051 foreach ($topic_data as $topic_id => $topic_row)
1053 $sql_ary = array(
1054 'forum_id' => (int) $to_forum_id,
1055 'icon_id' => (int) $topic_row['icon_id'],
1056 'topic_attachment' => (int) $topic_row['topic_attachment'],
1057 'topic_approved' => 1,
1058 'topic_reported' => 0,
1059 'topic_title' => (string) $topic_row['topic_title'],
1060 'topic_poster' => (int) $topic_row['topic_poster'],
1061 'topic_time' => (int) $topic_row['topic_time'],
1062 'topic_replies' => (int) $topic_row['topic_replies_real'],
1063 'topic_replies_real' => (int) $topic_row['topic_replies_real'],
1064 'topic_status' => (int) $topic_row['topic_status'],
1065 'topic_type' => (int) $topic_row['topic_type'],
1066 'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'],
1067 'topic_last_poster_id' => (int) $topic_row['topic_last_poster_id'],
1068 'topic_last_poster_name' => (string) $topic_row['topic_last_poster_name'],
1069 'topic_last_post_time' => (int) $topic_row['topic_last_post_time'],
1070 'topic_last_view_time' => (int) $topic_row['topic_last_view_time'],
1071 'topic_bumped' => (int) $topic_row['topic_bumped'],
1072 'topic_bumper' => (int) $topic_row['topic_bumper'],
1073 'poll_title' => (string) $topic_row['poll_title'],
1074 'poll_start' => (int) $topic_row['poll_start'],
1075 'poll_length' => (int) $topic_row['poll_length'],
1076 'poll_max_options' => (int) $topic_row['poll_max_options'],
1077 'poll_vote_change' => (int) $topic_row['poll_vote_change'],
1080 $db->sql_query('INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1081 $new_topic_id = $db->sql_nextid();
1082 $new_topic_id_list[$topic_id] = $new_topic_id;
1084 if ($topic_row['poll_start'])
1086 $poll_rows = array();
1088 $sql = 'SELECT *
1089 FROM ' . POLL_OPTIONS_TABLE . "
1090 WHERE topic_id = $topic_id";
1091 $result = $db->sql_query($sql);
1093 while ($row = $db->sql_fetchrow($result))
1095 $sql_ary = array(
1096 'poll_option_id' => (int) $row['poll_option_id'],
1097 'topic_id' => (int) $new_topic_id,
1098 'poll_option_text' => (string) $row['poll_option_text'],
1099 'poll_option_total' => 0
1102 $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1106 $sql = 'SELECT *
1107 FROM ' . POSTS_TABLE . "
1108 WHERE topic_id = $topic_id
1109 ORDER BY post_time ASC";
1110 $result = $db->sql_query($sql);
1112 $post_rows = array();
1113 while ($row = $db->sql_fetchrow($result))
1115 $post_rows[] = $row;
1117 $db->sql_freeresult($result);
1119 if (!sizeof($post_rows))
1121 continue;
1124 $total_posts += sizeof($post_rows);
1125 foreach ($post_rows as $row)
1127 $sql_ary = array(
1128 'topic_id' => (int) $new_topic_id,
1129 'forum_id' => (int) $to_forum_id,
1130 'poster_id' => (int) $row['poster_id'],
1131 'icon_id' => (int) $row['icon_id'],
1132 'poster_ip' => (string) $row['poster_ip'],
1133 'post_time' => (int) $row['post_time'],
1134 'post_approved' => 1,
1135 'post_reported' => 0,
1136 'enable_bbcode' => (int) $row['enable_bbcode'],
1137 'enable_smilies' => (int) $row['enable_smilies'],
1138 'enable_magic_url' => (int) $row['enable_magic_url'],
1139 'enable_sig' => (int) $row['enable_sig'],
1140 'post_username' => (string) $row['post_username'],
1141 'post_subject' => (string) $row['post_subject'],
1142 'post_text' => (string) $row['post_text'],
1143 'post_edit_reason' => (string) $row['post_edit_reason'],
1144 'post_edit_user' => (int) $row['post_edit_user'],
1145 'post_checksum' => (string) $row['post_checksum'],
1146 'post_attachment' => (int) $row['post_attachment'],
1147 'bbcode_bitfield' => $row['bbcode_bitfield'],
1148 'bbcode_uid' => (string) $row['bbcode_uid'],
1149 'post_edit_time' => (int) $row['post_edit_time'],
1150 'post_edit_count' => (int) $row['post_edit_count'],
1151 'post_edit_locked' => (int) $row['post_edit_locked'],
1152 'post_postcount' => 0,
1155 $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1156 $new_post_id = $db->sql_nextid();
1158 // Copy whether the topic is dotted
1159 markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']);
1161 // Copy Attachments
1162 if ($row['post_attachment'])
1164 $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . "
1165 WHERE post_msg_id = {$row['post_id']}
1166 AND topic_id = $topic_id
1167 AND in_message = 0";
1168 $result = $db->sql_query($sql);
1170 $sql_ary = array();
1171 while ($attach_row = $db->sql_fetchrow($result))
1173 $sql_ary[] = array(
1174 'post_msg_id' => (int) $new_post_id,
1175 'topic_id' => (int) $new_topic_id,
1176 'in_message' => 0,
1177 'is_orphan' => (int) $attach_row['is_orphan'],
1178 'poster_id' => (int) $attach_row['poster_id'],
1179 'physical_filename' => (string) utf8_basename($attach_row['physical_filename']),
1180 'real_filename' => (string) utf8_basename($attach_row['real_filename']),
1181 'download_count' => (int) $attach_row['download_count'],
1182 'attach_comment' => (string) $attach_row['attach_comment'],
1183 'extension' => (string) $attach_row['extension'],
1184 'mimetype' => (string) $attach_row['mimetype'],
1185 'filesize' => (int) $attach_row['filesize'],
1186 'filetime' => (int) $attach_row['filetime'],
1187 'thumbnail' => (int) $attach_row['thumbnail']
1190 $db->sql_freeresult($result);
1192 if (sizeof($sql_ary))
1194 $db->sql_multi_insert(ATTACHMENTS_TABLE, $sql_ary);
1199 $sql = 'SELECT user_id, notify_status
1200 FROM ' . TOPICS_WATCH_TABLE . '
1201 WHERE topic_id = ' . $topic_id;
1202 $result = $db->sql_query($sql);
1204 $sql_ary = array();
1205 while ($row = $db->sql_fetchrow($result))
1207 $sql_ary[] = array(
1208 'topic_id' => (int) $new_topic_id,
1209 'user_id' => (int) $row['user_id'],
1210 'notify_status' => (int) $row['notify_status'],
1213 $db->sql_freeresult($result);
1215 if (sizeof($sql_ary))
1217 $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
1221 // Sync new topics, parent forums and board stats
1222 sync('topic', 'topic_id', $new_topic_id_list);
1224 $sync_sql = array();
1226 $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $total_posts;
1227 $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . sizeof($new_topic_id_list);
1228 $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . sizeof($new_topic_id_list);
1230 foreach ($sync_sql as $forum_id_key => $array)
1232 $sql = 'UPDATE ' . FORUMS_TABLE . '
1233 SET ' . implode(', ', $array) . '
1234 WHERE forum_id = ' . $forum_id_key;
1235 $db->sql_query($sql);
1238 sync('forum', 'forum_id', $to_forum_id);
1239 set_config_count('num_topics', sizeof($new_topic_id_list), true);
1240 set_config_count('num_posts', $total_posts, true);
1242 foreach ($new_topic_id_list as $topic_id => $new_topic_id)
1244 add_log('mod', $to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']);
1247 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS';
1249 else
1251 $template->assign_vars(array(
1252 'S_FORUM_SELECT' => make_forum_select($to_forum_id, false, false, true, true, true),
1253 'S_CAN_LEAVE_SHADOW' => false,
1254 'ADDITIONAL_MSG' => $additional_msg)
1257 confirm_box(false, 'FORK_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
1260 $redirect = request_var('redirect', "index.$phpEx");
1261 $redirect = reapply_sid($redirect);
1263 if (!$success_msg)
1265 redirect($redirect);
1267 else
1269 $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
1270 meta_refresh(3, $redirect_url);
1271 $return_link = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>');
1273 if ($forum_id != $to_forum_id)
1275 $return_link .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $to_forum_id) . '">', '</a>');
1278 trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);