2 /***************************************************************************
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: modcp.php,v 1.71.2.24 2004/07/11 16:46:15 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);
134 $forum_topics = ( $topic_row['forum_topics'] == 0 ) ? 1 : $topic_row['forum_topics'];
135 $forum_id = $topic_row['forum_id'];
136 $forum_name = $topic_row['forum_name'];
138 else if ( !empty($forum_id) )
140 $sql = "SELECT forum_name, forum_topics
141 FROM " . FORUMS_TABLE . "
142 WHERE forum_id = " . $forum_id;
143 if ( !($result = $db->sql_query($sql)) )
145 message_die(GENERAL_MESSAGE, 'Forum_not_exist');
147 $topic_row = $db->sql_fetchrow($result);
149 $forum_topics = ( $topic_row['forum_topics'] == 0 ) ? 1 : $topic_row['forum_topics'];
150 $forum_name = $topic_row['forum_name'];
154 message_die(GENERAL_MESSAGE, 'Forum_not_exist');
158 // Start session management
160 $userdata = session_pagestart($user_ip, $forum_id);
161 init_userprefs($userdata);
163 // End session management
167 if ($sid == '' || $sid != $userdata['session_id'])
169 message_die(GENERAL_ERROR, 'Invalid_session');
173 // Check if user did or did not confirm
174 // If they did not, forward them to the last page they were on
176 if ( isset($HTTP_POST_VARS['cancel']) )
180 $redirect = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id";
182 else if ( $forum_id )
184 $redirect = "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id";
188 $redirect = "index.$phpEx";
191 redirect(append_sid($redirect, true));
197 $is_auth = auth(AUTH_ALL, $forum_id, $userdata);
199 if ( !$is_auth['auth_mod'] )
201 message_die(GENERAL_MESSAGE, $lang['Not_Moderator'], $lang['Not_Authorised']);
213 if (!$is_auth['auth_delete'])
215 message_die(MESSAGE, sprintf($lang['Sorry_auth_delete'], $is_auth['auth_delete_type']));
218 $page_title = $lang['Mod_CP'];
219 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
223 include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
225 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
228 for($i = 0; $i < count($topics); $i++)
230 $topic_id_sql .= ( ( $topic_id_sql != '' ) ? ', ' : '' ) . intval($topics[$i]);
233 $sql = "SELECT topic_id
234 FROM " . TOPICS_TABLE . "
235 WHERE topic_id IN ($topic_id_sql)
236 AND forum_id = $forum_id";
237 if ( !($result = $db->sql_query($sql)) )
239 message_die(GENERAL_ERROR, 'Could not get topic id information', '', __LINE__, __FILE__, $sql);
243 while ($row = $db->sql_fetchrow($result))
245 $topic_id_sql .= (($topic_id_sql != '') ? ', ' : '') . intval($row['topic_id']);
247 $db->sql_freeresult($result);
249 $sql = "SELECT poster_id, COUNT(post_id) AS posts
250 FROM " . POSTS_TABLE . "
251 WHERE topic_id IN ($topic_id_sql)
253 if ( !($result = $db->sql_query($sql)) )
255 message_die(GENERAL_ERROR, 'Could not get poster id information', '', __LINE__, __FILE__, $sql);
258 $count_sql = array();
259 while ( $row = $db->sql_fetchrow($result) )
261 $count_sql[] = "UPDATE " . USERS_TABLE . "
262 SET user_posts = user_posts - " . $row['posts'] . "
263 WHERE user_id = " . $row['poster_id'];
265 $db->sql_freeresult($result);
267 if ( sizeof($count_sql) )
269 for($i = 0; $i < sizeof($count_sql); $i++)
271 if ( !$db->sql_query($count_sql[$i]) )
273 message_die(GENERAL_ERROR, 'Could not update user post count information', '', __LINE__, __FILE__, $sql);
278 $sql = "SELECT post_id
279 FROM " . POSTS_TABLE . "
280 WHERE topic_id IN ($topic_id_sql)";
281 if ( !($result = $db->sql_query($sql)) )
283 message_die(GENERAL_ERROR, 'Could not get post id information', '', __LINE__, __FILE__, $sql);
287 while ( $row = $db->sql_fetchrow($result) )
289 $post_id_sql .= ( ( $post_id_sql != '' ) ? ', ' : '' ) . intval($row['post_id']);
291 $db->sql_freeresult($result);
293 $sql = "SELECT vote_id
294 FROM " . VOTE_DESC_TABLE . "
295 WHERE topic_id IN ($topic_id_sql)";
296 if ( !($result = $db->sql_query($sql)) )
298 message_die(GENERAL_ERROR, 'Could not get vote id information', '', __LINE__, __FILE__, $sql);
302 while ( $row = $db->sql_fetchrow($result) )
304 $vote_id_sql .= ( ( $vote_id_sql != '' ) ? ', ' : '' ) . $row['vote_id'];
306 $db->sql_freeresult($result);
309 // Got all required info so go ahead and start deleting everything
312 FROM " . TOPICS_TABLE . "
313 WHERE topic_id IN ($topic_id_sql)
314 OR topic_moved_id IN ($topic_id_sql)";
315 if ( !$db->sql_query($sql, BEGIN_TRANSACTION) )
317 message_die(GENERAL_ERROR, 'Could not delete topics', '', __LINE__, __FILE__, $sql);
320 if ( $post_id_sql != '' )
323 FROM " . POSTS_TABLE . "
324 WHERE post_id IN ($post_id_sql)";
325 if ( !$db->sql_query($sql) )
327 message_die(GENERAL_ERROR, 'Could not delete posts', '', __LINE__, __FILE__, $sql);
331 FROM " . POSTS_TEXT_TABLE . "
332 WHERE post_id IN ($post_id_sql)";
333 if ( !$db->sql_query($sql) )
335 message_die(GENERAL_ERROR, 'Could not delete posts text', '', __LINE__, __FILE__, $sql);
338 remove_search_post($post_id_sql);
341 if ( $vote_id_sql != '' )
344 FROM " . VOTE_DESC_TABLE . "
345 WHERE vote_id IN ($vote_id_sql)";
346 if ( !$db->sql_query($sql) )
348 message_die(GENERAL_ERROR, 'Could not delete vote descriptions', '', __LINE__, __FILE__, $sql);
352 FROM " . VOTE_RESULTS_TABLE . "
353 WHERE vote_id IN ($vote_id_sql)";
354 if ( !$db->sql_query($sql) )
356 message_die(GENERAL_ERROR, 'Could not delete vote results', '', __LINE__, __FILE__, $sql);
360 FROM " . VOTE_USERS_TABLE . "
361 WHERE vote_id IN ($vote_id_sql)";
362 if ( !$db->sql_query($sql) )
364 message_die(GENERAL_ERROR, 'Could not delete vote users', '', __LINE__, __FILE__, $sql);
369 FROM " . TOPICS_WATCH_TABLE . "
370 WHERE topic_id IN ($topic_id_sql)";
371 if ( !$db->sql_query($sql, END_TRANSACTION) )
373 message_die(GENERAL_ERROR, 'Could not delete watched post list', '', __LINE__, __FILE__, $sql);
376 sync('forum', $forum_id);
378 if ( !empty($topic_id) )
380 $redirect_page = "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
381 $l_redirect = sprintf($lang['Click_return_forum'], '<a href="' . $redirect_page . '">', '</a>');
385 $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
386 $l_redirect = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
389 $template->assign_vars(array(
390 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
393 message_die(GENERAL_MESSAGE, $lang['Topics_Removed'] . '<br /><br />' . $l_redirect);
397 // Not confirmed, show confirmation message
398 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
400 message_die(GENERAL_MESSAGE, $lang['None_selected']);
403 $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 . '" />';
405 if ( isset($HTTP_POST_VARS['topic_id_list']) )
407 $topics = $HTTP_POST_VARS['topic_id_list'];
408 for($i = 0; $i < count($topics); $i++)
410 $hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . intval($topics[$i]) . '" />';
415 $hidden_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';
419 // Set template files
421 $template->set_filenames(array(
422 'confirm' => 'confirm_body.tpl')
425 $template->assign_vars(array(
426 'MESSAGE_TITLE' => $lang['Confirm'],
427 'MESSAGE_TEXT' => $lang['Confirm_delete_topic'],
429 'L_YES' => $lang['Yes'],
430 'L_NO' => $lang['No'],
432 'S_CONFIRM_ACTION' => append_sid("modcp.$phpEx"),
433 'S_HIDDEN_FIELDS' => $hidden_fields)
436 $template->pparse('confirm');
438 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
443 $page_title = $lang['Mod_CP'];
444 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
448 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
450 message_die(GENERAL_MESSAGE, $lang['None_selected']);
453 $new_forum_id = intval($HTTP_POST_VARS['new_forum']);
454 $old_forum_id = $forum_id;
456 if ( $new_forum_id != $old_forum_id )
458 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
461 for($i = 0; $i < count($topics); $i++)
463 $topic_list .= ( ( $topic_list != '' ) ? ', ' : '' ) . intval($topics[$i]);
467 FROM " . TOPICS_TABLE . "
468 WHERE topic_id IN ($topic_list)
469 AND forum_id = $old_forum_id
470 AND topic_status <> " . TOPIC_MOVED;
471 if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
473 message_die(GENERAL_ERROR, 'Could not select from topic table', '', __LINE__, __FILE__, $sql);
476 $row = $db->sql_fetchrowset($result);
477 $db->sql_freeresult($result);
479 for($i = 0; $i < count($row); $i++)
481 $topic_id = $row[$i]['topic_id'];
483 if ( isset($HTTP_POST_VARS['move_leave_shadow']) )
485 // Insert topic in the old forum that indicates that the forum has moved.
486 $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)
487 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)";
488 if ( !$db->sql_query($sql) )
490 message_die(GENERAL_ERROR, 'Could not insert shadow topic', '', __LINE__, __FILE__, $sql);
494 $sql = "UPDATE " . TOPICS_TABLE . "
495 SET forum_id = $new_forum_id
496 WHERE topic_id = $topic_id";
497 if ( !$db->sql_query($sql) )
499 message_die(GENERAL_ERROR, 'Could not update old topic', '', __LINE__, __FILE__, $sql);
502 $sql = "UPDATE " . POSTS_TABLE . "
503 SET forum_id = $new_forum_id
504 WHERE topic_id = $topic_id";
505 if ( !$db->sql_query($sql) )
507 message_die(GENERAL_ERROR, 'Could not update post topic ids', '', __LINE__, __FILE__, $sql);
511 // Sync the forum indexes
512 sync('forum', $new_forum_id);
513 sync('forum', $old_forum_id);
515 $message = $lang['Topics_Moved'] . '<br /><br />';
520 $message = $lang['No_Topics_Moved'] . '<br /><br />';
523 if ( !empty($topic_id) )
525 $redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'];
526 $message .= sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
530 $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
531 $message .= sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
534 $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . "viewforum.$phpEx?" . POST_FORUM_URL . "=$old_forum_id&sid=" . $userdata['session_id'] . '">', '</a>');
536 $template->assign_vars(array(
537 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
540 message_die(GENERAL_MESSAGE, $message);
544 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
546 message_die(GENERAL_MESSAGE, $lang['None_selected']);
549 $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 . '" />';
551 if ( isset($HTTP_POST_VARS['topic_id_list']) )
553 $topics = $HTTP_POST_VARS['topic_id_list'];
555 for($i = 0; $i < count($topics); $i++)
557 $hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . intval($topics[$i]) . '" />';
562 $hidden_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';
566 // Set template files
568 $template->set_filenames(array(
569 'movetopic' => 'modcp_move.tpl')
572 $template->assign_vars(array(
573 'MESSAGE_TITLE' => $lang['Confirm'],
574 'MESSAGE_TEXT' => $lang['Confirm_move_topic'],
576 'L_MOVE_TO_FORUM' => $lang['Move_to_forum'],
577 'L_LEAVESHADOW' => $lang['Leave_shadow_topic'],
578 'L_YES' => $lang['Yes'],
579 'L_NO' => $lang['No'],
581 'S_FORUM_SELECT' => make_forum_select('new_forum', $forum_id),
582 'S_MODCP_ACTION' => append_sid("modcp.$phpEx"),
583 'S_HIDDEN_FIELDS' => $hidden_fields)
586 $template->pparse('movetopic');
588 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
593 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
595 message_die(GENERAL_MESSAGE, $lang['None_selected']);
598 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
601 for($i = 0; $i < count($topics); $i++)
603 $topic_id_sql .= ( ( $topic_id_sql != '' ) ? ', ' : '' ) . intval($topics[$i]);
606 $sql = "UPDATE " . TOPICS_TABLE . "
607 SET topic_status = " . TOPIC_LOCKED . "
608 WHERE topic_id IN ($topic_id_sql)
609 AND forum_id = $forum_id
610 AND topic_moved_id = 0";
611 if ( !($result = $db->sql_query($sql)) )
613 message_die(GENERAL_ERROR, 'Could not update topics table', '', __LINE__, __FILE__, $sql);
616 if ( !empty($topic_id) )
618 $redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'];
619 $message = sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
623 $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
624 $message = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
627 $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'] . '">', '</a>');
629 $template->assign_vars(array(
630 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
633 message_die(GENERAL_MESSAGE, $lang['Topics_Locked'] . '<br /><br />' . $message);
638 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
640 message_die(GENERAL_MESSAGE, $lang['None_selected']);
643 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
646 for($i = 0; $i < count($topics); $i++)
648 $topic_id_sql .= ( ( $topic_id_sql != "") ? ', ' : '' ) . intval($topics[$i]);
651 $sql = "UPDATE " . TOPICS_TABLE . "
652 SET topic_status = " . TOPIC_UNLOCKED . "
653 WHERE topic_id IN ($topic_id_sql)
654 AND forum_id = $forum_id
655 AND topic_moved_id = 0";
656 if ( !($result = $db->sql_query($sql)) )
658 message_die(GENERAL_ERROR, 'Could not update topics table', '', __LINE__, __FILE__, $sql);
661 if ( !empty($topic_id) )
663 $redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'];
664 $message = sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
668 $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
669 $message = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
672 $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'] . '">', '</a>');
674 $template->assign_vars(array(
675 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
678 message_die(GENERAL_MESSAGE, $lang['Topics_Unlocked'] . '<br /><br />' . $message);
683 $page_title = $lang['Mod_CP'];
684 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
688 if (isset($HTTP_POST_VARS['split_type_all']) || isset($HTTP_POST_VARS['split_type_beyond']))
690 $posts = $HTTP_POST_VARS['post_id_list'];
692 for ($i = 0; $i < count($posts); $i++)
694 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($posts[$i]);
698 if ($post_id_sql != '')
700 $sql = "SELECT post_id
701 FROM " . POSTS_TABLE . "
702 WHERE post_id IN ($post_id_sql)
703 AND forum_id = $forum_id";
704 if ( !($result = $db->sql_query($sql)) )
706 message_die(GENERAL_ERROR, 'Could not get post id information', '', __LINE__, __FILE__, $sql);
710 while ($row = $db->sql_fetchrow($result))
712 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);
714 $db->sql_freeresult($result);
716 $sql = "SELECT post_id, poster_id, topic_id, post_time
717 FROM " . POSTS_TABLE . "
718 WHERE post_id IN ($post_id_sql)
719 ORDER BY post_time ASC";
720 if (!($result = $db->sql_query($sql)))
722 message_die(GENERAL_ERROR, 'Could not get post information', '', __LINE__, __FILE__, $sql);
725 if ($row = $db->sql_fetchrow($result))
727 $first_poster = $row['poster_id'];
728 $topic_id = $row['topic_id'];
729 $post_time = $row['post_time'];
735 $user_id_sql .= (($user_id_sql != '') ? ', ' : '') . intval($row['poster_id']);
736 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);;
738 while ($row = $db->sql_fetchrow($result));
740 $post_subject = trim(htmlspecialchars($HTTP_POST_VARS['subject']));
741 if (empty($post_subject))
743 message_die(GENERAL_MESSAGE, $lang['Empty_subject']);
746 $new_forum_id = intval($HTTP_POST_VARS['new_forum_id']);
747 $topic_time = time();
749 $sql = "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type)
750 VALUES ('" . str_replace("\'", "''", $post_subject) . "', $first_poster, " . $topic_time . ", $new_forum_id, " . TOPIC_UNLOCKED . ", " . POST_NORMAL . ")";
751 if (!($db->sql_query($sql, BEGIN_TRANSACTION)))
753 message_die(GENERAL_ERROR, 'Could not insert new topic', '', __LINE__, __FILE__, $sql);
756 $new_topic_id = $db->sql_nextid();
758 // Update topic watch table, switch users whose posts
759 // have moved, over to watching the new topic
760 $sql = "UPDATE " . TOPICS_WATCH_TABLE . "
761 SET topic_id = $new_topic_id
762 WHERE topic_id = $topic_id
763 AND user_id IN ($user_id_sql)";
764 if (!$db->sql_query($sql))
766 message_die(GENERAL_ERROR, 'Could not update topics watch table', '', __LINE__, __FILE__, $sql);
769 $sql_where = (!empty($HTTP_POST_VARS['split_type_beyond'])) ? " post_time >= $post_time AND topic_id = $topic_id" : "post_id IN ($post_id_sql)";
771 $sql = "UPDATE " . POSTS_TABLE . "
772 SET topic_id = $new_topic_id, forum_id = $new_forum_id
774 if (!$db->sql_query($sql, END_TRANSACTION))
776 message_die(GENERAL_ERROR, 'Could not update posts table', '', __LINE__, __FILE__, $sql);
779 sync('topic', $new_topic_id);
780 sync('topic', $topic_id);
781 sync('forum', $new_forum_id);
782 sync('forum', $forum_id);
784 $template->assign_vars(array(
785 'META' => '<meta http-equiv="refresh" content="3;url=' . "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'] . '">')
788 $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>');
789 message_die(GENERAL_MESSAGE, $message);
795 // Set template files
797 $template->set_filenames(array(
798 'split_body' => 'modcp_split.tpl')
801 $sql = "SELECT u.username, p.*, pt.post_text, pt.bbcode_uid, pt.post_subject, p.post_username
802 FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
803 WHERE p.topic_id = $topic_id
804 AND p.poster_id = u.user_id
805 AND p.post_id = pt.post_id
806 ORDER BY p.post_time ASC";
807 if ( !($result = $db->sql_query($sql)) )
809 message_die(GENERAL_ERROR, 'Could not get topic/post information', '', __LINE__, __FILE__, $sql);
812 $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" />';
814 if( ( $total_posts = $db->sql_numrows($result) ) > 0 )
816 $postrow = $db->sql_fetchrowset($result);
818 $template->assign_vars(array(
819 'L_SPLIT_TOPIC' => $lang['Split_Topic'],
820 'L_SPLIT_TOPIC_EXPLAIN' => $lang['Split_Topic_explain'],
821 'L_AUTHOR' => $lang['Author'],
822 'L_MESSAGE' => $lang['Message'],
823 'L_SELECT' => $lang['Select'],
824 'L_SPLIT_SUBJECT' => $lang['Split_title'],
825 'L_SPLIT_FORUM' => $lang['Split_forum'],
826 'L_POSTED' => $lang['Posted'],
827 'L_SPLIT_POSTS' => $lang['Split_posts'],
828 'L_SUBMIT' => $lang['Submit'],
829 'L_SPLIT_AFTER' => $lang['Split_after'],
830 'L_POST_SUBJECT' => $lang['Post_subject'],
831 'L_MARK_ALL' => $lang['Mark_all'],
832 'L_UNMARK_ALL' => $lang['Unmark_all'],
833 'L_POST' => $lang['Post'],
835 'FORUM_NAME' => $forum_name,
837 'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"),
839 'S_SPLIT_ACTION' => append_sid("modcp.$phpEx"),
840 'S_HIDDEN_FIELDS' => $s_hidden_fields,
841 'S_FORUM_SELECT' => make_forum_select("new_forum_id", false, $forum_id))
845 // Define censored word matches
847 $orig_word = array();
848 $replacement_word = array();
849 obtain_word_list($orig_word, $replacement_word);
851 for($i = 0; $i < $total_posts; $i++)
853 $post_id = $postrow[$i]['post_id'];
854 $poster_id = $postrow[$i]['poster_id'];
855 $poster = $postrow[$i]['username'];
857 $post_date = create_date($board_config['default_dateformat'], $postrow[$i]['post_time'], $board_config['board_timezone']);
859 $bbcode_uid = $postrow[$i]['bbcode_uid'];
860 $message = $postrow[$i]['post_text'];
861 $post_subject = ( $postrow[$i]['post_subject'] != '' ) ? $postrow[$i]['post_subject'] : $topic_title;
864 // If the board has HTML off but the post has HTML
865 // on then we process it, else leave it alone
867 if ( !$board_config['allow_html'] )
869 if ( $postrow[$i]['enable_html'] )
871 $message = preg_replace('#(<)([\/]?.*?)(>)#is', '<\\2>', $message);
875 if ( $bbcode_uid != '' )
877 $message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
880 if ( count($orig_word) )
882 $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
883 $message = preg_replace($orig_word, $replacement_word, $message);
886 $message = make_clickable($message);
888 if ( $board_config['allow_smilies'] && $postrow[$i]['enable_smilies'] )
890 $message = smilies_pass($message);
893 $message = str_replace("\n", '<br />', $message);
895 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
896 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
898 $checkbox = ( $i > 0 ) ? '<input type="checkbox" name="post_id_list[]" value="' . $post_id . '" />' : ' ';
900 $template->assign_block_vars('postrow', array(
901 'ROW_COLOR' => '#' . $row_color,
902 'ROW_CLASS' => $row_class,
903 'POSTER_NAME' => $poster,
904 'POST_DATE' => $post_date,
905 'POST_SUBJECT' => $post_subject,
906 'MESSAGE' => $message,
907 'POST_ID' => $post_id,
909 'S_SPLIT_CHECKBOX' => $checkbox)
913 $template->pparse('split_body');
919 $page_title = $lang['Mod_CP'];
920 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
922 $rdns_ip_num = ( isset($HTTP_GET_VARS['rdns']) ) ? $HTTP_GET_VARS['rdns'] : "";
926 message_die(GENERAL_MESSAGE, $lang['No_such_post']);
930 // Set template files
932 $template->set_filenames(array(
933 'viewip' => 'modcp_viewip.tpl')
936 // Look up relevent data for this post
937 $sql = "SELECT poster_ip, poster_id
938 FROM " . POSTS_TABLE . "
939 WHERE post_id = $post_id
940 AND forum_id = $forum_id";
941 if ( !($result = $db->sql_query($sql)) )
943 message_die(GENERAL_ERROR, 'Could not get poster IP information', '', __LINE__, __FILE__, $sql);
946 if ( !($post_row = $db->sql_fetchrow($result)) )
948 message_die(GENERAL_MESSAGE, $lang['No_such_post']);
951 $ip_this_post = decode_ip($post_row['poster_ip']);
952 $ip_this_post = ( $rdns_ip_num == $ip_this_post ) ? gethostbyaddr($ip_this_post) : $ip_this_post;
954 $poster_id = $post_row['poster_id'];
956 $template->assign_vars(array(
957 'L_IP_INFO' => $lang['IP_info'],
958 'L_THIS_POST_IP' => $lang['This_posts_IP'],
959 'L_OTHER_IPS' => $lang['Other_IP_this_user'],
960 'L_OTHER_USERS' => $lang['Users_this_IP'],
961 'L_LOOKUP_IP' => $lang['Lookup_IP'],
962 'L_SEARCH' => $lang['Search'],
964 'SEARCH_IMG' => $images['icon_search'],
966 'IP' => $ip_this_post,
968 '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'])
972 // Get other IP's this user has posted under
974 $sql = "SELECT poster_ip, COUNT(*) AS postings
975 FROM " . POSTS_TABLE . "
976 WHERE poster_id = $poster_id
978 ORDER BY " . (( SQL_LAYER == 'msaccess' ) ? 'COUNT(*)' : 'postings' ) . " DESC";
979 if ( !($result = $db->sql_query($sql)) )
981 message_die(GENERAL_ERROR, 'Could not get IP information for this user', '', __LINE__, __FILE__, $sql);
984 if ( $row = $db->sql_fetchrow($result) )
989 if ( $row['poster_ip'] == $post_row['poster_ip'] )
991 $template->assign_vars(array(
992 'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ))
997 $ip = decode_ip($row['poster_ip']);
998 $ip = ( $rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? gethostbyaddr($ip) : $ip;
1000 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1001 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1003 $template->assign_block_vars('iprow', array(
1004 'ROW_COLOR' => '#' . $row_color,
1005 'ROW_CLASS' => $row_class,
1007 'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ),
1009 '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'])
1014 while ( $row = $db->sql_fetchrow($result) );
1018 // Get other users who've posted under this IP
1020 $sql = "SELECT u.user_id, u.username, COUNT(*) as postings
1021 FROM " . USERS_TABLE ." u, " . POSTS_TABLE . " p
1022 WHERE p.poster_id = u.user_id
1023 AND p.poster_ip = '" . $post_row['poster_ip'] . "'
1024 GROUP BY u.user_id, u.username
1025 ORDER BY " . (( SQL_LAYER == 'msaccess' ) ? 'COUNT(*)' : 'postings' ) . " DESC";
1026 if ( !($result = $db->sql_query($sql)) )
1028 message_die(GENERAL_ERROR, 'Could not get posters information based on IP', '', __LINE__, __FILE__, $sql);
1031 if ( $row = $db->sql_fetchrow($result) )
1036 $id = $row['user_id'];
1037 $username = ( $id == ANONYMOUS ) ? $lang['Guest'] : $row['username'];
1039 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1040 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1042 $template->assign_block_vars('userrow', array(
1043 'ROW_COLOR' => '#' . $row_color,
1044 'ROW_CLASS' => $row_class,
1045 'USERNAME' => $username,
1046 'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ),
1047 'L_SEARCH_POSTS' => sprintf($lang['Search_user_posts'], $username),
1049 '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"),
1050 'U_SEARCHPOSTS' => append_sid("search.$phpEx?search_author=" . urlencode($username) . "&showresults=topics"))
1055 while ( $row = $db->sql_fetchrow($result) );
1058 $template->pparse('viewip');
1063 $page_title = $lang['Mod_CP'];
1064 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
1066 $template->assign_vars(array(
1067 'FORUM_NAME' => $forum_name,
1069 'L_MOD_CP' => $lang['Mod_CP'],
1070 'L_MOD_CP_EXPLAIN' => $lang['Mod_CP_explain'],
1071 'L_SELECT' => $lang['Select'],
1072 'L_DELETE' => $lang['Delete'],
1073 'L_MOVE' => $lang['Move'],
1074 'L_LOCK' => $lang['Lock'],
1075 'L_UNLOCK' => $lang['Unlock'],
1076 'L_TOPICS' => $lang['Topics'],
1077 'L_REPLIES' => $lang['Replies'],
1078 'L_LASTPOST' => $lang['Last_Post'],
1079 'L_SELECT' => $lang['Select'],
1081 'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"),
1082 'S_HIDDEN_FIELDS' => '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />',
1083 'S_MODCP_ACTION' => append_sid("modcp.$phpEx"))
1086 $template->set_filenames(array(
1087 'body' => 'modcp_body.tpl')
1089 make_jumpbox('modcp.'.$phpEx);
1092 // Define censored word matches
1094 $orig_word = array();
1095 $replacement_word = array();
1096 obtain_word_list($orig_word, $replacement_word);
1098 $sql = "SELECT t.*, u.username, u.user_id, p.post_time
1099 FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p
1100 WHERE t.forum_id = $forum_id
1101 AND t.topic_poster = u.user_id
1102 AND p.post_id = t.topic_last_post_id
1103 ORDER BY t.topic_type DESC, p.post_time DESC
1104 LIMIT $start, " . $board_config['topics_per_page'];
1105 if ( !($result = $db->sql_query($sql)) )
1107 message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
1110 while ( $row = $db->sql_fetchrow($result) )
1114 if ( $row['topic_status'] == TOPIC_LOCKED )
1116 $folder_img = $images['folder_locked'];
1117 $folder_alt = $lang['Topic_locked'];
1121 if ( $row['topic_type'] == POST_ANNOUNCE )
1123 $folder_img = $images['folder_announce'];
1124 $folder_alt = $lang['Topic_Announcement'];
1126 else if ( $row['topic_type'] == POST_STICKY )
1128 $folder_img = $images['folder_sticky'];
1129 $folder_alt = $lang['Topic_Sticky'];
1133 $folder_img = $images['folder'];
1134 $folder_alt = $lang['No_new_posts'];
1138 $topic_id = $row['topic_id'];
1139 $topic_type = $row['topic_type'];
1140 $topic_status = $row['topic_status'];
1142 if ( $topic_type == POST_ANNOUNCE )
1144 $topic_type = $lang['Topic_Announcement'] . ' ';
1146 else if ( $topic_type == POST_STICKY )
1148 $topic_type = $lang['Topic_Sticky'] . ' ';
1150 else if ( $topic_status == TOPIC_MOVED )
1152 $topic_type = $lang['Topic_Moved'] . ' ';
1159 if ( $row['topic_vote'] )
1161 $topic_type .= $lang['Topic_Poll'] . ' ';
1164 $topic_title = $row['topic_title'];
1165 if ( count($orig_word) )
1167 $topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
1170 $u_view_topic = "modcp.$phpEx?mode=split&" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'];
1171 $topic_replies = $row['topic_replies'];
1173 $last_post_time = create_date($board_config['default_dateformat'], $row['post_time'], $board_config['board_timezone']);
1175 $template->assign_block_vars('topicrow', array(
1176 'U_VIEW_TOPIC' => $u_view_topic,
1178 'TOPIC_FOLDER_IMG' => $folder_img,
1179 'TOPIC_TYPE' => $topic_type,
1180 'TOPIC_TITLE' => $topic_title,
1181 'REPLIES' => $topic_replies,
1182 'LAST_POST_TIME' => $last_post_time,
1183 'TOPIC_ID' => $topic_id,
1185 'L_TOPIC_FOLDER_ALT' => $folder_alt)
1189 $template->assign_vars(array(
1190 'PAGINATION' => generate_pagination("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'], $forum_topics, $board_config['topics_per_page'], $start),
1191 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $forum_topics / $board_config['topics_per_page'] )),
1192 'L_GOTO_PAGE' => $lang['Goto_page'])
1195 $template->pparse('body');
1200 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);