2 /***************************************************************************
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: modcp.php,v 1.71.2.27 2005/09/14 18:14:30 acydburn Exp $
11 ***************************************************************************/
13 /***************************************************************************
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 ***************************************************************************/
23 * Moderator Control Panel
25 * From this 'Control Panel' the moderator of a forum will be able to do
26 * mass topic operations (locking/unlocking/moving/deleteing), and it will
27 * provide an interface to do quick locking/unlocking/moving/deleting of
28 * topics via the moderator operations buttons on all of the viewtopic pages.
31 define('IN_PHPBB', true);
32 $phpbb_root_path = './';
33 include($phpbb_root_path . 'extension.inc');
34 include($phpbb_root_path . 'common.'.$phpEx);
35 include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
36 include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
39 // Obtain initial var settings
41 if ( isset($HTTP_GET_VARS[POST_FORUM_URL]) || isset($HTTP_POST_VARS[POST_FORUM_URL]) )
43 $forum_id = (isset($HTTP_POST_VARS[POST_FORUM_URL])) ? intval($HTTP_POST_VARS[POST_FORUM_URL]) : intval($HTTP_GET_VARS[POST_FORUM_URL]);
50 if ( isset($HTTP_GET_VARS[POST_POST_URL]) || isset($HTTP_POST_VARS[POST_POST_URL]) )
52 $post_id = (isset($HTTP_POST_VARS[POST_POST_URL])) ? intval($HTTP_POST_VARS[POST_POST_URL]) : intval($HTTP_GET_VARS[POST_POST_URL]);
59 if ( isset($HTTP_GET_VARS[POST_TOPIC_URL]) || isset($HTTP_POST_VARS[POST_TOPIC_URL]) )
61 $topic_id = (isset($HTTP_POST_VARS[POST_TOPIC_URL])) ? intval($HTTP_POST_VARS[POST_TOPIC_URL]) : intval($HTTP_GET_VARS[POST_TOPIC_URL]);
68 $confirm = ( $HTTP_POST_VARS['confirm'] ) ? TRUE : 0;
71 // Continue var definitions
73 $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
75 $delete = ( isset($HTTP_POST_VARS['delete']) ) ? TRUE : FALSE;
76 $move = ( isset($HTTP_POST_VARS['move']) ) ? TRUE : FALSE;
77 $lock = ( isset($HTTP_POST_VARS['lock']) ) ? TRUE : FALSE;
78 $unlock = ( isset($HTTP_POST_VARS['unlock']) ) ? TRUE : FALSE;
80 if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
82 $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
83 $mode = htmlspecialchars($mode);
110 if (!empty($HTTP_POST_VARS['sid']) || !empty($HTTP_GET_VARS['sid']))
112 $sid = (!empty($HTTP_POST_VARS['sid'])) ? $HTTP_POST_VARS['sid'] : $HTTP_GET_VARS['sid'];
120 // Obtain relevant data
122 if ( !empty($topic_id) )
124 $sql = "SELECT f.forum_id, f.forum_name, f.forum_topics
125 FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
126 WHERE t.topic_id = " . $topic_id . "
127 AND f.forum_id = t.forum_id";
128 if ( !($result = $db->sql_query($sql)) )
130 message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
132 $topic_row = $db->sql_fetchrow($result);
136 message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
139 $forum_topics = ( $topic_row['forum_topics'] == 0 ) ? 1 : $topic_row['forum_topics'];
140 $forum_id = $topic_row['forum_id'];
141 $forum_name = $topic_row['forum_name'];
143 else if ( !empty($forum_id) )
145 $sql = "SELECT forum_name, forum_topics
146 FROM " . FORUMS_TABLE . "
147 WHERE forum_id = " . $forum_id;
148 if ( !($result = $db->sql_query($sql)) )
150 message_die(GENERAL_MESSAGE, 'Forum_not_exist');
152 $topic_row = $db->sql_fetchrow($result);
156 message_die(GENERAL_MESSAGE, 'Forum_not_exist');
159 $forum_topics = ( $topic_row['forum_topics'] == 0 ) ? 1 : $topic_row['forum_topics'];
160 $forum_name = $topic_row['forum_name'];
164 message_die(GENERAL_MESSAGE, 'Forum_not_exist');
168 // Start session management
170 $userdata = session_pagestart($user_ip, $forum_id);
171 init_userprefs($userdata);
173 // End session management
177 if ($sid == '' || $sid != $userdata['session_id'])
179 message_die(GENERAL_ERROR, 'Invalid_session');
183 // Check if user did or did not confirm
184 // If they did not, forward them to the last page they were on
186 if ( isset($HTTP_POST_VARS['cancel']) )
190 $redirect = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id";
192 else if ( $forum_id )
194 $redirect = "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id";
198 $redirect = "index.$phpEx";
201 redirect(append_sid($redirect, true));
207 $is_auth = auth(AUTH_ALL, $forum_id, $userdata);
209 if ( !$is_auth['auth_mod'] )
211 message_die(GENERAL_MESSAGE, $lang['Not_Moderator'], $lang['Not_Authorised']);
223 if (!$is_auth['auth_delete'])
225 message_die(GENERAL_MESSAGE, sprintf($lang['Sorry_auth_delete'], $is_auth['auth_delete_type']));
228 $page_title = $lang['Mod_CP'];
229 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
233 include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
235 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
238 for($i = 0; $i < count($topics); $i++)
240 $topic_id_sql .= ( ( $topic_id_sql != '' ) ? ', ' : '' ) . intval($topics[$i]);
243 $sql = "SELECT topic_id
244 FROM " . TOPICS_TABLE . "
245 WHERE topic_id IN ($topic_id_sql)
246 AND forum_id = $forum_id";
247 if ( !($result = $db->sql_query($sql)) )
249 message_die(GENERAL_ERROR, 'Could not get topic id information', '', __LINE__, __FILE__, $sql);
253 while ($row = $db->sql_fetchrow($result))
255 $topic_id_sql .= (($topic_id_sql != '') ? ', ' : '') . intval($row['topic_id']);
257 $db->sql_freeresult($result);
259 $sql = "SELECT poster_id, COUNT(post_id) AS posts
260 FROM " . POSTS_TABLE . "
261 WHERE topic_id IN ($topic_id_sql)
263 if ( !($result = $db->sql_query($sql)) )
265 message_die(GENERAL_ERROR, 'Could not get poster id information', '', __LINE__, __FILE__, $sql);
268 $count_sql = array();
269 while ( $row = $db->sql_fetchrow($result) )
271 $count_sql[] = "UPDATE " . USERS_TABLE . "
272 SET user_posts = user_posts - " . $row['posts'] . "
273 WHERE user_id = " . $row['poster_id'];
275 $db->sql_freeresult($result);
277 if ( sizeof($count_sql) )
279 for($i = 0; $i < sizeof($count_sql); $i++)
281 if ( !$db->sql_query($count_sql[$i]) )
283 message_die(GENERAL_ERROR, 'Could not update user post count information', '', __LINE__, __FILE__, $sql);
288 $sql = "SELECT post_id
289 FROM " . POSTS_TABLE . "
290 WHERE topic_id IN ($topic_id_sql)";
291 if ( !($result = $db->sql_query($sql)) )
293 message_die(GENERAL_ERROR, 'Could not get post id information', '', __LINE__, __FILE__, $sql);
297 while ( $row = $db->sql_fetchrow($result) )
299 $post_id_sql .= ( ( $post_id_sql != '' ) ? ', ' : '' ) . intval($row['post_id']);
301 $db->sql_freeresult($result);
303 $sql = "SELECT vote_id
304 FROM " . VOTE_DESC_TABLE . "
305 WHERE topic_id IN ($topic_id_sql)";
306 if ( !($result = $db->sql_query($sql)) )
308 message_die(GENERAL_ERROR, 'Could not get vote id information', '', __LINE__, __FILE__, $sql);
312 while ( $row = $db->sql_fetchrow($result) )
314 $vote_id_sql .= ( ( $vote_id_sql != '' ) ? ', ' : '' ) . $row['vote_id'];
316 $db->sql_freeresult($result);
319 // Got all required info so go ahead and start deleting everything
322 FROM " . TOPICS_TABLE . "
323 WHERE topic_id IN ($topic_id_sql)
324 OR topic_moved_id IN ($topic_id_sql)";
325 if ( !$db->sql_query($sql, BEGIN_TRANSACTION) )
327 message_die(GENERAL_ERROR, 'Could not delete topics', '', __LINE__, __FILE__, $sql);
330 if ( $post_id_sql != '' )
333 FROM " . POSTS_TABLE . "
334 WHERE post_id IN ($post_id_sql)";
335 if ( !$db->sql_query($sql) )
337 message_die(GENERAL_ERROR, 'Could not delete posts', '', __LINE__, __FILE__, $sql);
341 FROM " . POSTS_TEXT_TABLE . "
342 WHERE post_id IN ($post_id_sql)";
343 if ( !$db->sql_query($sql) )
345 message_die(GENERAL_ERROR, 'Could not delete posts text', '', __LINE__, __FILE__, $sql);
348 remove_search_post($post_id_sql);
351 if ( $vote_id_sql != '' )
354 FROM " . VOTE_DESC_TABLE . "
355 WHERE vote_id IN ($vote_id_sql)";
356 if ( !$db->sql_query($sql) )
358 message_die(GENERAL_ERROR, 'Could not delete vote descriptions', '', __LINE__, __FILE__, $sql);
362 FROM " . VOTE_RESULTS_TABLE . "
363 WHERE vote_id IN ($vote_id_sql)";
364 if ( !$db->sql_query($sql) )
366 message_die(GENERAL_ERROR, 'Could not delete vote results', '', __LINE__, __FILE__, $sql);
370 FROM " . VOTE_USERS_TABLE . "
371 WHERE vote_id IN ($vote_id_sql)";
372 if ( !$db->sql_query($sql) )
374 message_die(GENERAL_ERROR, 'Could not delete vote users', '', __LINE__, __FILE__, $sql);
379 FROM " . TOPICS_WATCH_TABLE . "
380 WHERE topic_id IN ($topic_id_sql)";
381 if ( !$db->sql_query($sql, END_TRANSACTION) )
383 message_die(GENERAL_ERROR, 'Could not delete watched post list', '', __LINE__, __FILE__, $sql);
386 sync('forum', $forum_id);
388 if ( !empty($topic_id) )
390 $redirect_page = "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
391 $l_redirect = sprintf($lang['Click_return_forum'], '<a href="' . $redirect_page . '">', '</a>');
395 $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
396 $l_redirect = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
399 $template->assign_vars(array(
400 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
403 message_die(GENERAL_MESSAGE, $lang['Topics_Removed'] . '<br /><br />' . $l_redirect);
407 // Not confirmed, show confirmation message
408 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
410 message_die(GENERAL_MESSAGE, $lang['None_selected']);
413 $hidden_fields = '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" /><input type="hidden" name="mode" value="' . $mode . '" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />';
415 if ( isset($HTTP_POST_VARS['topic_id_list']) )
417 $topics = $HTTP_POST_VARS['topic_id_list'];
418 for($i = 0; $i < count($topics); $i++)
420 $hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . intval($topics[$i]) . '" />';
425 $hidden_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';
429 // Set template files
431 $template->set_filenames(array(
432 'confirm' => 'confirm_body.tpl')
435 $template->assign_vars(array(
436 'MESSAGE_TITLE' => $lang['Confirm'],
437 'MESSAGE_TEXT' => $lang['Confirm_delete_topic'],
439 'L_YES' => $lang['Yes'],
440 'L_NO' => $lang['No'],
442 'S_CONFIRM_ACTION' => append_sid("modcp.$phpEx"),
443 'S_HIDDEN_FIELDS' => $hidden_fields)
446 $template->pparse('confirm');
448 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
453 $page_title = $lang['Mod_CP'];
454 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
458 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
460 message_die(GENERAL_MESSAGE, $lang['None_selected']);
463 $new_forum_id = intval($HTTP_POST_VARS['new_forum']);
464 $old_forum_id = $forum_id;
466 $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . '
467 WHERE forum_id = ' . $new_forum_id;
468 if ( !($result = $db->sql_query($sql)) )
470 message_die(GENERAL_ERROR, 'Could not select from forums table', '', __LINE__, __FILE__, $sql);
473 if (!$db->sql_fetchrow($result))
475 message_die(GENERAL_MESSAGE, 'New forum does not exist');
478 $db->sql_freeresult($result);
480 if ( $new_forum_id != $old_forum_id )
482 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
485 for($i = 0; $i < count($topics); $i++)
487 $topic_list .= ( ( $topic_list != '' ) ? ', ' : '' ) . intval($topics[$i]);
491 FROM " . TOPICS_TABLE . "
492 WHERE topic_id IN ($topic_list)
493 AND forum_id = $old_forum_id
494 AND topic_status <> " . TOPIC_MOVED;
495 if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
497 message_die(GENERAL_ERROR, 'Could not select from topic table', '', __LINE__, __FILE__, $sql);
500 $row = $db->sql_fetchrowset($result);
501 $db->sql_freeresult($result);
503 for($i = 0; $i < count($row); $i++)
505 $topic_id = $row[$i]['topic_id'];
507 if ( isset($HTTP_POST_VARS['move_leave_shadow']) )
509 // Insert topic in the old forum that indicates that the forum has moved.
510 $sql = "INSERT INTO " . TOPICS_TABLE . " (forum_id, topic_title, topic_poster, topic_time, topic_status, topic_type, topic_vote, topic_views, topic_replies, topic_first_post_id, topic_last_post_id, topic_moved_id)
511 VALUES ($old_forum_id, '" . addslashes(str_replace("\'", "''", $row[$i]['topic_title'])) . "', '" . str_replace("\'", "''", $row[$i]['topic_poster']) . "', " . $row[$i]['topic_time'] . ", " . TOPIC_MOVED . ", " . POST_NORMAL . ", " . $row[$i]['topic_vote'] . ", " . $row[$i]['topic_views'] . ", " . $row[$i]['topic_replies'] . ", " . $row[$i]['topic_first_post_id'] . ", " . $row[$i]['topic_last_post_id'] . ", $topic_id)";
512 if ( !$db->sql_query($sql) )
514 message_die(GENERAL_ERROR, 'Could not insert shadow topic', '', __LINE__, __FILE__, $sql);
518 $sql = "UPDATE " . TOPICS_TABLE . "
519 SET forum_id = $new_forum_id
520 WHERE topic_id = $topic_id";
521 if ( !$db->sql_query($sql) )
523 message_die(GENERAL_ERROR, 'Could not update old topic', '', __LINE__, __FILE__, $sql);
526 $sql = "UPDATE " . POSTS_TABLE . "
527 SET forum_id = $new_forum_id
528 WHERE topic_id = $topic_id";
529 if ( !$db->sql_query($sql) )
531 message_die(GENERAL_ERROR, 'Could not update post topic ids', '', __LINE__, __FILE__, $sql);
535 // Sync the forum indexes
536 sync('forum', $new_forum_id);
537 sync('forum', $old_forum_id);
539 $message = $lang['Topics_Moved'] . '<br /><br />';
544 $message = $lang['No_Topics_Moved'] . '<br /><br />';
547 if ( !empty($topic_id) )
549 $redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'];
550 $message .= sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
554 $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
555 $message .= sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
558 $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . "viewforum.$phpEx?" . POST_FORUM_URL . "=$old_forum_id&sid=" . $userdata['session_id'] . '">', '</a>');
560 $template->assign_vars(array(
561 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
564 message_die(GENERAL_MESSAGE, $message);
568 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
570 message_die(GENERAL_MESSAGE, $lang['None_selected']);
573 $hidden_fields = '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" /><input type="hidden" name="mode" value="' . $mode . '" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />';
575 if ( isset($HTTP_POST_VARS['topic_id_list']) )
577 $topics = $HTTP_POST_VARS['topic_id_list'];
579 for($i = 0; $i < count($topics); $i++)
581 $hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . intval($topics[$i]) . '" />';
586 $hidden_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';
590 // Set template files
592 $template->set_filenames(array(
593 'movetopic' => 'modcp_move.tpl')
596 $template->assign_vars(array(
597 'MESSAGE_TITLE' => $lang['Confirm'],
598 'MESSAGE_TEXT' => $lang['Confirm_move_topic'],
600 'L_MOVE_TO_FORUM' => $lang['Move_to_forum'],
601 'L_LEAVESHADOW' => $lang['Leave_shadow_topic'],
602 'L_YES' => $lang['Yes'],
603 'L_NO' => $lang['No'],
605 'S_FORUM_SELECT' => make_forum_select('new_forum', $forum_id),
606 'S_MODCP_ACTION' => append_sid("modcp.$phpEx"),
607 'S_HIDDEN_FIELDS' => $hidden_fields)
610 $template->pparse('movetopic');
612 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
617 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
619 message_die(GENERAL_MESSAGE, $lang['None_selected']);
622 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
625 for($i = 0; $i < count($topics); $i++)
627 $topic_id_sql .= ( ( $topic_id_sql != '' ) ? ', ' : '' ) . intval($topics[$i]);
630 $sql = "UPDATE " . TOPICS_TABLE . "
631 SET topic_status = " . TOPIC_LOCKED . "
632 WHERE topic_id IN ($topic_id_sql)
633 AND forum_id = $forum_id
634 AND topic_moved_id = 0";
635 if ( !($result = $db->sql_query($sql)) )
637 message_die(GENERAL_ERROR, 'Could not update topics table', '', __LINE__, __FILE__, $sql);
640 if ( !empty($topic_id) )
642 $redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'];
643 $message = sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
647 $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
648 $message = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
651 $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'] . '">', '</a>');
653 $template->assign_vars(array(
654 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
657 message_die(GENERAL_MESSAGE, $lang['Topics_Locked'] . '<br /><br />' . $message);
662 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
664 message_die(GENERAL_MESSAGE, $lang['None_selected']);
667 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
670 for($i = 0; $i < count($topics); $i++)
672 $topic_id_sql .= ( ( $topic_id_sql != "") ? ', ' : '' ) . intval($topics[$i]);
675 $sql = "UPDATE " . TOPICS_TABLE . "
676 SET topic_status = " . TOPIC_UNLOCKED . "
677 WHERE topic_id IN ($topic_id_sql)
678 AND forum_id = $forum_id
679 AND topic_moved_id = 0";
680 if ( !($result = $db->sql_query($sql)) )
682 message_die(GENERAL_ERROR, 'Could not update topics table', '', __LINE__, __FILE__, $sql);
685 if ( !empty($topic_id) )
687 $redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'];
688 $message = sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
692 $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
693 $message = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
696 $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'] . '">', '</a>');
698 $template->assign_vars(array(
699 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
702 message_die(GENERAL_MESSAGE, $lang['Topics_Unlocked'] . '<br /><br />' . $message);
707 $page_title = $lang['Mod_CP'];
708 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
712 if (isset($HTTP_POST_VARS['split_type_all']) || isset($HTTP_POST_VARS['split_type_beyond']))
714 $posts = $HTTP_POST_VARS['post_id_list'];
716 for ($i = 0; $i < count($posts); $i++)
718 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($posts[$i]);
722 if ($post_id_sql != '')
724 $sql = "SELECT post_id
725 FROM " . POSTS_TABLE . "
726 WHERE post_id IN ($post_id_sql)
727 AND forum_id = $forum_id";
728 if ( !($result = $db->sql_query($sql)) )
730 message_die(GENERAL_ERROR, 'Could not get post id information', '', __LINE__, __FILE__, $sql);
734 while ($row = $db->sql_fetchrow($result))
736 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);
738 $db->sql_freeresult($result);
740 $sql = "SELECT post_id, poster_id, topic_id, post_time
741 FROM " . POSTS_TABLE . "
742 WHERE post_id IN ($post_id_sql)
743 ORDER BY post_time ASC";
744 if (!($result = $db->sql_query($sql)))
746 message_die(GENERAL_ERROR, 'Could not get post information', '', __LINE__, __FILE__, $sql);
749 if ($row = $db->sql_fetchrow($result))
751 $first_poster = $row['poster_id'];
752 $topic_id = $row['topic_id'];
753 $post_time = $row['post_time'];
759 $user_id_sql .= (($user_id_sql != '') ? ', ' : '') . intval($row['poster_id']);
760 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);;
762 while ($row = $db->sql_fetchrow($result));
764 $post_subject = trim(htmlspecialchars($HTTP_POST_VARS['subject']));
765 if (empty($post_subject))
767 message_die(GENERAL_MESSAGE, $lang['Empty_subject']);
770 $new_forum_id = intval($HTTP_POST_VARS['new_forum_id']);
771 $topic_time = time();
773 $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . '
774 WHERE forum_id = ' . $new_forum_id;
775 if ( !($result = $db->sql_query($sql)) )
777 message_die(GENERAL_ERROR, 'Could not select from forums table', '', __LINE__, __FILE__, $sql);
780 if (!$db->sql_fetchrow($result))
782 message_die(GENERAL_MESSAGE, 'New forum does not exist');
785 $db->sql_freeresult($result);
787 $sql = "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type)
788 VALUES ('" . str_replace("\'", "''", $post_subject) . "', $first_poster, " . $topic_time . ", $new_forum_id, " . TOPIC_UNLOCKED . ", " . POST_NORMAL . ")";
789 if (!($db->sql_query($sql, BEGIN_TRANSACTION)))
791 message_die(GENERAL_ERROR, 'Could not insert new topic', '', __LINE__, __FILE__, $sql);
794 $new_topic_id = $db->sql_nextid();
796 // Update topic watch table, switch users whose posts
797 // have moved, over to watching the new topic
798 $sql = "UPDATE " . TOPICS_WATCH_TABLE . "
799 SET topic_id = $new_topic_id
800 WHERE topic_id = $topic_id
801 AND user_id IN ($user_id_sql)";
802 if (!$db->sql_query($sql))
804 message_die(GENERAL_ERROR, 'Could not update topics watch table', '', __LINE__, __FILE__, $sql);
807 $sql_where = (!empty($HTTP_POST_VARS['split_type_beyond'])) ? " post_time >= $post_time AND topic_id = $topic_id" : "post_id IN ($post_id_sql)";
809 $sql = "UPDATE " . POSTS_TABLE . "
810 SET topic_id = $new_topic_id, forum_id = $new_forum_id
812 if (!$db->sql_query($sql, END_TRANSACTION))
814 message_die(GENERAL_ERROR, 'Could not update posts table', '', __LINE__, __FILE__, $sql);
817 sync('topic', $new_topic_id);
818 sync('topic', $topic_id);
819 sync('forum', $new_forum_id);
820 sync('forum', $forum_id);
822 $template->assign_vars(array(
823 'META' => '<meta http-equiv="refresh" content="3;url=' . "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'] . '">')
826 $message = $lang['Topic_split'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'] . '">', '</a>');
827 message_die(GENERAL_MESSAGE, $message);
833 // Set template files
835 $template->set_filenames(array(
836 'split_body' => 'modcp_split.tpl')
839 $sql = "SELECT u.username, p.*, pt.post_text, pt.bbcode_uid, pt.post_subject, p.post_username
840 FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
841 WHERE p.topic_id = $topic_id
842 AND p.poster_id = u.user_id
843 AND p.post_id = pt.post_id
844 ORDER BY p.post_time ASC";
845 if ( !($result = $db->sql_query($sql)) )
847 message_die(GENERAL_ERROR, 'Could not get topic/post information', '', __LINE__, __FILE__, $sql);
850 $s_hidden_fields = '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" /><input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" /><input type="hidden" name="mode" value="split" />';
852 if( ( $total_posts = $db->sql_numrows($result) ) > 0 )
854 $postrow = $db->sql_fetchrowset($result);
856 $template->assign_vars(array(
857 'L_SPLIT_TOPIC' => $lang['Split_Topic'],
858 'L_SPLIT_TOPIC_EXPLAIN' => $lang['Split_Topic_explain'],
859 'L_AUTHOR' => $lang['Author'],
860 'L_MESSAGE' => $lang['Message'],
861 'L_SELECT' => $lang['Select'],
862 'L_SPLIT_SUBJECT' => $lang['Split_title'],
863 'L_SPLIT_FORUM' => $lang['Split_forum'],
864 'L_POSTED' => $lang['Posted'],
865 'L_SPLIT_POSTS' => $lang['Split_posts'],
866 'L_SUBMIT' => $lang['Submit'],
867 'L_SPLIT_AFTER' => $lang['Split_after'],
868 'L_POST_SUBJECT' => $lang['Post_subject'],
869 'L_MARK_ALL' => $lang['Mark_all'],
870 'L_UNMARK_ALL' => $lang['Unmark_all'],
871 'L_POST' => $lang['Post'],
873 'FORUM_NAME' => $forum_name,
875 'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"),
877 'S_SPLIT_ACTION' => append_sid("modcp.$phpEx"),
878 'S_HIDDEN_FIELDS' => $s_hidden_fields,
879 'S_FORUM_SELECT' => make_forum_select("new_forum_id", false, $forum_id))
883 // Define censored word matches
885 $orig_word = array();
886 $replacement_word = array();
887 obtain_word_list($orig_word, $replacement_word);
889 for($i = 0; $i < $total_posts; $i++)
891 $post_id = $postrow[$i]['post_id'];
892 $poster_id = $postrow[$i]['poster_id'];
893 $poster = $postrow[$i]['username'];
895 $post_date = create_date($board_config['default_dateformat'], $postrow[$i]['post_time'], $board_config['board_timezone']);
897 $bbcode_uid = $postrow[$i]['bbcode_uid'];
898 $message = $postrow[$i]['post_text'];
899 $post_subject = ( $postrow[$i]['post_subject'] != '' ) ? $postrow[$i]['post_subject'] : $topic_title;
902 // If the board has HTML off but the post has HTML
903 // on then we process it, else leave it alone
905 if ( !$board_config['allow_html'] )
907 if ( $postrow[$i]['enable_html'] )
909 $message = preg_replace('#(<)([\/]?.*?)(>)#is', '<\\2>', $message);
913 if ( $bbcode_uid != '' )
915 $message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
918 if ( count($orig_word) )
920 $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
921 $message = preg_replace($orig_word, $replacement_word, $message);
924 $message = make_clickable($message);
926 if ( $board_config['allow_smilies'] && $postrow[$i]['enable_smilies'] )
928 $message = smilies_pass($message);
931 $message = str_replace("\n", '<br />', $message);
933 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
934 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
936 $checkbox = ( $i > 0 ) ? '<input type="checkbox" name="post_id_list[]" value="' . $post_id . '" />' : ' ';
938 $template->assign_block_vars('postrow', array(
939 'ROW_COLOR' => '#' . $row_color,
940 'ROW_CLASS' => $row_class,
941 'POSTER_NAME' => $poster,
942 'POST_DATE' => $post_date,
943 'POST_SUBJECT' => $post_subject,
944 'MESSAGE' => $message,
945 'POST_ID' => $post_id,
947 'S_SPLIT_CHECKBOX' => $checkbox)
951 $template->pparse('split_body');
957 $page_title = $lang['Mod_CP'];
958 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
960 $rdns_ip_num = ( isset($HTTP_GET_VARS['rdns']) ) ? $HTTP_GET_VARS['rdns'] : "";
964 message_die(GENERAL_MESSAGE, $lang['No_such_post']);
968 // Set template files
970 $template->set_filenames(array(
971 'viewip' => 'modcp_viewip.tpl')
974 // Look up relevent data for this post
975 $sql = "SELECT poster_ip, poster_id
976 FROM " . POSTS_TABLE . "
977 WHERE post_id = $post_id
978 AND forum_id = $forum_id";
979 if ( !($result = $db->sql_query($sql)) )
981 message_die(GENERAL_ERROR, 'Could not get poster IP information', '', __LINE__, __FILE__, $sql);
984 if ( !($post_row = $db->sql_fetchrow($result)) )
986 message_die(GENERAL_MESSAGE, $lang['No_such_post']);
989 $ip_this_post = decode_ip($post_row['poster_ip']);
990 $ip_this_post = ( $rdns_ip_num == $ip_this_post ) ? gethostbyaddr($ip_this_post) : $ip_this_post;
992 $poster_id = $post_row['poster_id'];
994 $template->assign_vars(array(
995 'L_IP_INFO' => $lang['IP_info'],
996 'L_THIS_POST_IP' => $lang['This_posts_IP'],
997 'L_OTHER_IPS' => $lang['Other_IP_this_user'],
998 'L_OTHER_USERS' => $lang['Users_this_IP'],
999 'L_LOOKUP_IP' => $lang['Lookup_IP'],
1000 'L_SEARCH' => $lang['Search'],
1002 'SEARCH_IMG' => $images['icon_search'],
1004 'IP' => $ip_this_post,
1006 'U_LOOKUP_IP' => "modcp.$phpEx?mode=ip&" . POST_POST_URL . "=$post_id&" . POST_TOPIC_URL . "=$topic_id&rdns=$ip_this_post&sid=" . $userdata['session_id'])
1010 // Get other IP's this user has posted under
1012 $sql = "SELECT poster_ip, COUNT(*) AS postings
1013 FROM " . POSTS_TABLE . "
1014 WHERE poster_id = $poster_id
1016 ORDER BY " . (( SQL_LAYER == 'msaccess' ) ? 'COUNT(*)' : 'postings' ) . " DESC";
1017 if ( !($result = $db->sql_query($sql)) )
1019 message_die(GENERAL_ERROR, 'Could not get IP information for this user', '', __LINE__, __FILE__, $sql);
1022 if ( $row = $db->sql_fetchrow($result) )
1027 if ( $row['poster_ip'] == $post_row['poster_ip'] )
1029 $template->assign_vars(array(
1030 'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ))
1035 $ip = decode_ip($row['poster_ip']);
1036 $ip = ( $rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? gethostbyaddr($ip) : $ip;
1038 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1039 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1041 $template->assign_block_vars('iprow', array(
1042 'ROW_COLOR' => '#' . $row_color,
1043 'ROW_CLASS' => $row_class,
1045 'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ),
1047 'U_LOOKUP_IP' => "modcp.$phpEx?mode=ip&" . POST_POST_URL . "=$post_id&" . POST_TOPIC_URL . "=$topic_id&rdns=" . $row['poster_ip'] . "&sid=" . $userdata['session_id'])
1052 while ( $row = $db->sql_fetchrow($result) );
1056 // Get other users who've posted under this IP
1058 $sql = "SELECT u.user_id, u.username, COUNT(*) as postings
1059 FROM " . USERS_TABLE ." u, " . POSTS_TABLE . " p
1060 WHERE p.poster_id = u.user_id
1061 AND p.poster_ip = '" . $post_row['poster_ip'] . "'
1062 GROUP BY u.user_id, u.username
1063 ORDER BY " . (( SQL_LAYER == 'msaccess' ) ? 'COUNT(*)' : 'postings' ) . " DESC";
1064 if ( !($result = $db->sql_query($sql)) )
1066 message_die(GENERAL_ERROR, 'Could not get posters information based on IP', '', __LINE__, __FILE__, $sql);
1069 if ( $row = $db->sql_fetchrow($result) )
1074 $id = $row['user_id'];
1075 $username = ( $id == ANONYMOUS ) ? $lang['Guest'] : $row['username'];
1077 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1078 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1080 $template->assign_block_vars('userrow', array(
1081 'ROW_COLOR' => '#' . $row_color,
1082 'ROW_CLASS' => $row_class,
1083 'USERNAME' => $username,
1084 'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ),
1085 'L_SEARCH_POSTS' => sprintf($lang['Search_user_posts'], $username),
1087 'U_PROFILE' => ($id == ANONYMOUS) ? "modcp.$phpEx?mode=ip&" . POST_POST_URL . "=" . $post_id . "&" . POST_TOPIC_URL . "=" . $topic_id . "&sid=" . $userdata['session_id'] : append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$id"),
1088 'U_SEARCHPOSTS' => append_sid("search.$phpEx?search_author=" . (($id == ANONYMOUS) ? 'Anonymous' : urlencode($username)) . "&showresults=topics"))
1093 while ( $row = $db->sql_fetchrow($result) );
1096 $template->pparse('viewip');
1101 $page_title = $lang['Mod_CP'];
1102 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
1104 $template->assign_vars(array(
1105 'FORUM_NAME' => $forum_name,
1107 'L_MOD_CP' => $lang['Mod_CP'],
1108 'L_MOD_CP_EXPLAIN' => $lang['Mod_CP_explain'],
1109 'L_SELECT' => $lang['Select'],
1110 'L_DELETE' => $lang['Delete'],
1111 'L_MOVE' => $lang['Move'],
1112 'L_LOCK' => $lang['Lock'],
1113 'L_UNLOCK' => $lang['Unlock'],
1114 'L_TOPICS' => $lang['Topics'],
1115 'L_REPLIES' => $lang['Replies'],
1116 'L_LASTPOST' => $lang['Last_Post'],
1117 'L_SELECT' => $lang['Select'],
1119 'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"),
1120 'S_HIDDEN_FIELDS' => '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />',
1121 'S_MODCP_ACTION' => append_sid("modcp.$phpEx"))
1124 $template->set_filenames(array(
1125 'body' => 'modcp_body.tpl')
1127 make_jumpbox('modcp.'.$phpEx);
1130 // Define censored word matches
1132 $orig_word = array();
1133 $replacement_word = array();
1134 obtain_word_list($orig_word, $replacement_word);
1136 $sql = "SELECT t.*, u.username, u.user_id, p.post_time
1137 FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p
1138 WHERE t.forum_id = $forum_id
1139 AND t.topic_poster = u.user_id
1140 AND p.post_id = t.topic_last_post_id
1141 ORDER BY t.topic_type DESC, p.post_time DESC
1142 LIMIT $start, " . $board_config['topics_per_page'];
1143 if ( !($result = $db->sql_query($sql)) )
1145 message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
1148 while ( $row = $db->sql_fetchrow($result) )
1152 if ( $row['topic_status'] == TOPIC_LOCKED )
1154 $folder_img = $images['folder_locked'];
1155 $folder_alt = $lang['Topic_locked'];
1159 if ( $row['topic_type'] == POST_ANNOUNCE )
1161 $folder_img = $images['folder_announce'];
1162 $folder_alt = $lang['Topic_Announcement'];
1164 else if ( $row['topic_type'] == POST_STICKY )
1166 $folder_img = $images['folder_sticky'];
1167 $folder_alt = $lang['Topic_Sticky'];
1171 $folder_img = $images['folder'];
1172 $folder_alt = $lang['No_new_posts'];
1176 $topic_id = $row['topic_id'];
1177 $topic_type = $row['topic_type'];
1178 $topic_status = $row['topic_status'];
1180 if ( $topic_type == POST_ANNOUNCE )
1182 $topic_type = $lang['Topic_Announcement'] . ' ';
1184 else if ( $topic_type == POST_STICKY )
1186 $topic_type = $lang['Topic_Sticky'] . ' ';
1188 else if ( $topic_status == TOPIC_MOVED )
1190 $topic_type = $lang['Topic_Moved'] . ' ';
1197 if ( $row['topic_vote'] )
1199 $topic_type .= $lang['Topic_Poll'] . ' ';
1202 $topic_title = $row['topic_title'];
1203 if ( count($orig_word) )
1205 $topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
1208 $u_view_topic = "modcp.$phpEx?mode=split&" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'];
1209 $topic_replies = $row['topic_replies'];
1211 $last_post_time = create_date($board_config['default_dateformat'], $row['post_time'], $board_config['board_timezone']);
1213 $template->assign_block_vars('topicrow', array(
1214 'U_VIEW_TOPIC' => $u_view_topic,
1216 'TOPIC_FOLDER_IMG' => $folder_img,
1217 'TOPIC_TYPE' => $topic_type,
1218 'TOPIC_TITLE' => $topic_title,
1219 'REPLIES' => $topic_replies,
1220 'LAST_POST_TIME' => $last_post_time,
1221 'TOPIC_ID' => $topic_id,
1223 'L_TOPIC_FOLDER_ALT' => $folder_alt)
1227 $template->assign_vars(array(
1228 'PAGINATION' => generate_pagination("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'], $forum_topics, $board_config['topics_per_page'], $start),
1229 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $forum_topics / $board_config['topics_per_page'] )),
1230 'L_GOTO_PAGE' => $lang['Goto_page'])
1233 $template->pparse('body');
1238 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);