2 /***************************************************************************
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: modcp.php,v 1.71.2.29 2006/12/16 13:11:24 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;
74 $start = ($start < 0) ? 0 : $start;
76 $delete = ( isset($HTTP_POST_VARS['delete']) ) ? TRUE : FALSE;
77 $move = ( isset($HTTP_POST_VARS['move']) ) ? TRUE : FALSE;
78 $lock = ( isset($HTTP_POST_VARS['lock']) ) ? TRUE : FALSE;
79 $unlock = ( isset($HTTP_POST_VARS['unlock']) ) ? TRUE : FALSE;
81 if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
83 $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
84 $mode = htmlspecialchars($mode);
111 if (!empty($HTTP_POST_VARS['sid']) || !empty($HTTP_GET_VARS['sid']))
113 $sid = (!empty($HTTP_POST_VARS['sid'])) ? $HTTP_POST_VARS['sid'] : $HTTP_GET_VARS['sid'];
121 // Obtain relevant data
123 if ( !empty($topic_id) )
125 $sql = "SELECT f.forum_id, f.forum_name, f.forum_topics
126 FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
127 WHERE t.topic_id = " . $topic_id . "
128 AND f.forum_id = t.forum_id";
129 if ( !($result = $db->sql_query($sql)) )
131 message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
133 $topic_row = $db->sql_fetchrow($result);
137 message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
140 $forum_topics = ( $topic_row['forum_topics'] == 0 ) ? 1 : $topic_row['forum_topics'];
141 $forum_id = $topic_row['forum_id'];
142 $forum_name = $topic_row['forum_name'];
144 else if ( !empty($forum_id) )
146 $sql = "SELECT forum_name, forum_topics
147 FROM " . FORUMS_TABLE . "
148 WHERE forum_id = " . $forum_id;
149 if ( !($result = $db->sql_query($sql)) )
151 message_die(GENERAL_MESSAGE, 'Forum_not_exist');
153 $topic_row = $db->sql_fetchrow($result);
157 message_die(GENERAL_MESSAGE, 'Forum_not_exist');
160 $forum_topics = ( $topic_row['forum_topics'] == 0 ) ? 1 : $topic_row['forum_topics'];
161 $forum_name = $topic_row['forum_name'];
165 message_die(GENERAL_MESSAGE, 'Forum_not_exist');
169 // Start session management
171 $userdata = session_pagestart($user_ip, $forum_id);
172 init_userprefs($userdata);
174 // End session management
178 if ($sid == '' || $sid != $userdata['session_id'])
180 message_die(GENERAL_ERROR, 'Invalid_session');
184 // Check if user did or did not confirm
185 // If they did not, forward them to the last page they were on
187 if ( isset($HTTP_POST_VARS['cancel']) )
191 $redirect = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id";
193 else if ( $forum_id )
195 $redirect = "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id";
199 $redirect = "index.$phpEx";
202 redirect(append_sid($redirect, true));
208 $is_auth = auth(AUTH_ALL, $forum_id, $userdata);
210 if ( !$is_auth['auth_mod'] )
212 message_die(GENERAL_MESSAGE, $lang['Not_Moderator'], $lang['Not_Authorised']);
224 if (!$is_auth['auth_delete'])
226 message_die(GENERAL_MESSAGE, sprintf($lang['Sorry_auth_delete'], $is_auth['auth_delete_type']));
229 $page_title = $lang['Mod_CP'];
230 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
234 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
236 message_die(GENERAL_MESSAGE, $lang['None_selected']);
239 include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
241 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
244 for($i = 0; $i < count($topics); $i++)
246 $topic_id_sql .= ( ( $topic_id_sql != '' ) ? ', ' : '' ) . intval($topics[$i]);
249 $sql = "SELECT topic_id
250 FROM " . TOPICS_TABLE . "
251 WHERE topic_id IN ($topic_id_sql)
252 AND forum_id = $forum_id";
253 if ( !($result = $db->sql_query($sql)) )
255 message_die(GENERAL_ERROR, 'Could not get topic id information', '', __LINE__, __FILE__, $sql);
259 while ($row = $db->sql_fetchrow($result))
261 $topic_id_sql .= (($topic_id_sql != '') ? ', ' : '') . intval($row['topic_id']);
263 $db->sql_freeresult($result);
265 if ( $topic_id_sql == '')
267 message_die(GENERAL_MESSAGE, $lang['None_selected']);
270 $sql = "SELECT poster_id, COUNT(post_id) AS posts
271 FROM " . POSTS_TABLE . "
272 WHERE topic_id IN ($topic_id_sql)
274 if ( !($result = $db->sql_query($sql)) )
276 message_die(GENERAL_ERROR, 'Could not get poster id information', '', __LINE__, __FILE__, $sql);
279 $count_sql = array();
280 while ( $row = $db->sql_fetchrow($result) )
282 $count_sql[] = "UPDATE " . USERS_TABLE . "
283 SET user_posts = user_posts - " . $row['posts'] . "
284 WHERE user_id = " . $row['poster_id'];
286 $db->sql_freeresult($result);
288 if ( sizeof($count_sql) )
290 for($i = 0; $i < sizeof($count_sql); $i++)
292 if ( !$db->sql_query($count_sql[$i]) )
294 message_die(GENERAL_ERROR, 'Could not update user post count information', '', __LINE__, __FILE__, $sql);
299 $sql = "SELECT post_id
300 FROM " . POSTS_TABLE . "
301 WHERE topic_id IN ($topic_id_sql)";
302 if ( !($result = $db->sql_query($sql)) )
304 message_die(GENERAL_ERROR, 'Could not get post id information', '', __LINE__, __FILE__, $sql);
308 while ( $row = $db->sql_fetchrow($result) )
310 $post_id_sql .= ( ( $post_id_sql != '' ) ? ', ' : '' ) . intval($row['post_id']);
312 $db->sql_freeresult($result);
314 $sql = "SELECT vote_id
315 FROM " . VOTE_DESC_TABLE . "
316 WHERE topic_id IN ($topic_id_sql)";
317 if ( !($result = $db->sql_query($sql)) )
319 message_die(GENERAL_ERROR, 'Could not get vote id information', '', __LINE__, __FILE__, $sql);
323 while ( $row = $db->sql_fetchrow($result) )
325 $vote_id_sql .= ( ( $vote_id_sql != '' ) ? ', ' : '' ) . $row['vote_id'];
327 $db->sql_freeresult($result);
330 // Got all required info so go ahead and start deleting everything
333 FROM " . TOPICS_TABLE . "
334 WHERE topic_id IN ($topic_id_sql)
335 OR topic_moved_id IN ($topic_id_sql)";
336 if ( !$db->sql_query($sql, BEGIN_TRANSACTION) )
338 message_die(GENERAL_ERROR, 'Could not delete topics', '', __LINE__, __FILE__, $sql);
341 if ( $post_id_sql != '' )
344 FROM " . POSTS_TABLE . "
345 WHERE post_id IN ($post_id_sql)";
346 if ( !$db->sql_query($sql) )
348 message_die(GENERAL_ERROR, 'Could not delete posts', '', __LINE__, __FILE__, $sql);
352 FROM " . POSTS_TEXT_TABLE . "
353 WHERE post_id IN ($post_id_sql)";
354 if ( !$db->sql_query($sql) )
356 message_die(GENERAL_ERROR, 'Could not delete posts text', '', __LINE__, __FILE__, $sql);
359 remove_search_post($post_id_sql);
362 if ( $vote_id_sql != '' )
365 FROM " . VOTE_DESC_TABLE . "
366 WHERE vote_id IN ($vote_id_sql)";
367 if ( !$db->sql_query($sql) )
369 message_die(GENERAL_ERROR, 'Could not delete vote descriptions', '', __LINE__, __FILE__, $sql);
373 FROM " . VOTE_RESULTS_TABLE . "
374 WHERE vote_id IN ($vote_id_sql)";
375 if ( !$db->sql_query($sql) )
377 message_die(GENERAL_ERROR, 'Could not delete vote results', '', __LINE__, __FILE__, $sql);
381 FROM " . VOTE_USERS_TABLE . "
382 WHERE vote_id IN ($vote_id_sql)";
383 if ( !$db->sql_query($sql) )
385 message_die(GENERAL_ERROR, 'Could not delete vote users', '', __LINE__, __FILE__, $sql);
390 FROM " . TOPICS_WATCH_TABLE . "
391 WHERE topic_id IN ($topic_id_sql)";
392 if ( !$db->sql_query($sql, END_TRANSACTION) )
394 message_die(GENERAL_ERROR, 'Could not delete watched post list', '', __LINE__, __FILE__, $sql);
397 sync('forum', $forum_id);
399 if ( !empty($topic_id) )
401 $redirect_page = "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
402 $l_redirect = sprintf($lang['Click_return_forum'], '<a href="' . $redirect_page . '">', '</a>');
406 $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
407 $l_redirect = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
410 $template->assign_vars(array(
411 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
414 message_die(GENERAL_MESSAGE, $lang['Topics_Removed'] . '<br /><br />' . $l_redirect);
418 // Not confirmed, show confirmation message
419 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
421 message_die(GENERAL_MESSAGE, $lang['None_selected']);
424 $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 . '" />';
426 if ( isset($HTTP_POST_VARS['topic_id_list']) )
428 $topics = $HTTP_POST_VARS['topic_id_list'];
429 for($i = 0; $i < count($topics); $i++)
431 $hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . intval($topics[$i]) . '" />';
436 $hidden_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';
440 // Set template files
442 $template->set_filenames(array(
443 'confirm' => 'confirm_body.tpl')
446 $template->assign_vars(array(
447 'MESSAGE_TITLE' => $lang['Confirm'],
448 'MESSAGE_TEXT' => $lang['Confirm_delete_topic'],
450 'L_YES' => $lang['Yes'],
451 'L_NO' => $lang['No'],
453 'S_CONFIRM_ACTION' => append_sid("modcp.$phpEx"),
454 'S_HIDDEN_FIELDS' => $hidden_fields)
457 $template->pparse('confirm');
459 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
464 $page_title = $lang['Mod_CP'];
465 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
469 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
471 message_die(GENERAL_MESSAGE, $lang['None_selected']);
474 $new_forum_id = intval($HTTP_POST_VARS['new_forum']);
475 $old_forum_id = $forum_id;
477 $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . '
478 WHERE forum_id = ' . $new_forum_id;
479 if ( !($result = $db->sql_query($sql)) )
481 message_die(GENERAL_ERROR, 'Could not select from forums table', '', __LINE__, __FILE__, $sql);
484 if (!$db->sql_fetchrow($result))
486 message_die(GENERAL_MESSAGE, 'New forum does not exist');
489 $db->sql_freeresult($result);
491 if ( $new_forum_id != $old_forum_id )
493 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
496 for($i = 0; $i < count($topics); $i++)
498 $topic_list .= ( ( $topic_list != '' ) ? ', ' : '' ) . intval($topics[$i]);
502 FROM " . TOPICS_TABLE . "
503 WHERE topic_id IN ($topic_list)
504 AND forum_id = $old_forum_id
505 AND topic_status <> " . TOPIC_MOVED;
506 if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
508 message_die(GENERAL_ERROR, 'Could not select from topic table', '', __LINE__, __FILE__, $sql);
511 $row = $db->sql_fetchrowset($result);
512 $db->sql_freeresult($result);
514 for($i = 0; $i < count($row); $i++)
516 $topic_id = $row[$i]['topic_id'];
518 if ( isset($HTTP_POST_VARS['move_leave_shadow']) )
520 // Insert topic in the old forum that indicates that the forum has moved.
521 $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)
522 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)";
523 if ( !$db->sql_query($sql) )
525 message_die(GENERAL_ERROR, 'Could not insert shadow topic', '', __LINE__, __FILE__, $sql);
529 $sql = "UPDATE " . TOPICS_TABLE . "
530 SET forum_id = $new_forum_id
531 WHERE topic_id = $topic_id";
532 if ( !$db->sql_query($sql) )
534 message_die(GENERAL_ERROR, 'Could not update old topic', '', __LINE__, __FILE__, $sql);
537 $sql = "UPDATE " . POSTS_TABLE . "
538 SET forum_id = $new_forum_id
539 WHERE topic_id = $topic_id";
540 if ( !$db->sql_query($sql) )
542 message_die(GENERAL_ERROR, 'Could not update post topic ids', '', __LINE__, __FILE__, $sql);
546 // Sync the forum indexes
547 sync('forum', $new_forum_id);
548 sync('forum', $old_forum_id);
550 $message = $lang['Topics_Moved'] . '<br /><br />';
555 $message = $lang['No_Topics_Moved'] . '<br /><br />';
558 if ( !empty($topic_id) )
560 $redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'];
561 $message .= sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
565 $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
566 $message .= sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
569 $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . "viewforum.$phpEx?" . POST_FORUM_URL . "=$old_forum_id&sid=" . $userdata['session_id'] . '">', '</a>');
571 $template->assign_vars(array(
572 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
575 message_die(GENERAL_MESSAGE, $message);
579 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
581 message_die(GENERAL_MESSAGE, $lang['None_selected']);
584 $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 . '" />';
586 if ( isset($HTTP_POST_VARS['topic_id_list']) )
588 $topics = $HTTP_POST_VARS['topic_id_list'];
590 for($i = 0; $i < count($topics); $i++)
592 $hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . intval($topics[$i]) . '" />';
597 $hidden_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';
601 // Set template files
603 $template->set_filenames(array(
604 'movetopic' => 'modcp_move.tpl')
607 $template->assign_vars(array(
608 'MESSAGE_TITLE' => $lang['Confirm'],
609 'MESSAGE_TEXT' => $lang['Confirm_move_topic'],
611 'L_MOVE_TO_FORUM' => $lang['Move_to_forum'],
612 'L_LEAVESHADOW' => $lang['Leave_shadow_topic'],
613 'L_YES' => $lang['Yes'],
614 'L_NO' => $lang['No'],
616 'S_FORUM_SELECT' => make_forum_select('new_forum', $forum_id),
617 'S_MODCP_ACTION' => append_sid("modcp.$phpEx"),
618 'S_HIDDEN_FIELDS' => $hidden_fields)
621 $template->pparse('movetopic');
623 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
628 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
630 message_die(GENERAL_MESSAGE, $lang['None_selected']);
633 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
636 for($i = 0; $i < count($topics); $i++)
638 $topic_id_sql .= ( ( $topic_id_sql != '' ) ? ', ' : '' ) . intval($topics[$i]);
641 $sql = "UPDATE " . TOPICS_TABLE . "
642 SET topic_status = " . TOPIC_LOCKED . "
643 WHERE topic_id IN ($topic_id_sql)
644 AND forum_id = $forum_id
645 AND topic_moved_id = 0";
646 if ( !($result = $db->sql_query($sql)) )
648 message_die(GENERAL_ERROR, 'Could not update topics table', '', __LINE__, __FILE__, $sql);
651 if ( !empty($topic_id) )
653 $redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'];
654 $message = sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
658 $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
659 $message = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
662 $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'] . '">', '</a>');
664 $template->assign_vars(array(
665 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
668 message_die(GENERAL_MESSAGE, $lang['Topics_Locked'] . '<br /><br />' . $message);
673 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
675 message_die(GENERAL_MESSAGE, $lang['None_selected']);
678 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
681 for($i = 0; $i < count($topics); $i++)
683 $topic_id_sql .= ( ( $topic_id_sql != "") ? ', ' : '' ) . intval($topics[$i]);
686 $sql = "UPDATE " . TOPICS_TABLE . "
687 SET topic_status = " . TOPIC_UNLOCKED . "
688 WHERE topic_id IN ($topic_id_sql)
689 AND forum_id = $forum_id
690 AND topic_moved_id = 0";
691 if ( !($result = $db->sql_query($sql)) )
693 message_die(GENERAL_ERROR, 'Could not update topics table', '', __LINE__, __FILE__, $sql);
696 if ( !empty($topic_id) )
698 $redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'];
699 $message = sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
703 $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'];
704 $message = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
707 $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'] . '">', '</a>');
709 $template->assign_vars(array(
710 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
713 message_die(GENERAL_MESSAGE, $lang['Topics_Unlocked'] . '<br /><br />' . $message);
718 $page_title = $lang['Mod_CP'];
719 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
723 if (isset($HTTP_POST_VARS['split_type_all']) || isset($HTTP_POST_VARS['split_type_beyond']))
725 $posts = $HTTP_POST_VARS['post_id_list'];
727 for ($i = 0; $i < count($posts); $i++)
729 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($posts[$i]);
733 if ($post_id_sql != '')
735 $sql = "SELECT post_id
736 FROM " . POSTS_TABLE . "
737 WHERE post_id IN ($post_id_sql)
738 AND forum_id = $forum_id";
739 if ( !($result = $db->sql_query($sql)) )
741 message_die(GENERAL_ERROR, 'Could not get post id information', '', __LINE__, __FILE__, $sql);
745 while ($row = $db->sql_fetchrow($result))
747 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);
749 $db->sql_freeresult($result);
751 if ($post_id_sql == '')
753 message_die(GENERAL_MESSAGE, $lang['None_selected']);
756 $sql = "SELECT post_id, poster_id, topic_id, post_time
757 FROM " . POSTS_TABLE . "
758 WHERE post_id IN ($post_id_sql)
759 ORDER BY post_time ASC";
760 if (!($result = $db->sql_query($sql)))
762 message_die(GENERAL_ERROR, 'Could not get post information', '', __LINE__, __FILE__, $sql);
765 if ($row = $db->sql_fetchrow($result))
767 $first_poster = $row['poster_id'];
768 $topic_id = $row['topic_id'];
769 $post_time = $row['post_time'];
775 $user_id_sql .= (($user_id_sql != '') ? ', ' : '') . intval($row['poster_id']);
776 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);;
778 while ($row = $db->sql_fetchrow($result));
780 $post_subject = trim(htmlspecialchars($HTTP_POST_VARS['subject']));
781 if (empty($post_subject))
783 message_die(GENERAL_MESSAGE, $lang['Empty_subject']);
786 $new_forum_id = intval($HTTP_POST_VARS['new_forum_id']);
787 $topic_time = time();
789 $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . '
790 WHERE forum_id = ' . $new_forum_id;
791 if ( !($result = $db->sql_query($sql)) )
793 message_die(GENERAL_ERROR, 'Could not select from forums table', '', __LINE__, __FILE__, $sql);
796 if (!$db->sql_fetchrow($result))
798 message_die(GENERAL_MESSAGE, 'New forum does not exist');
801 $db->sql_freeresult($result);
803 $sql = "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type)
804 VALUES ('" . str_replace("\'", "''", $post_subject) . "', $first_poster, " . $topic_time . ", $new_forum_id, " . TOPIC_UNLOCKED . ", " . POST_NORMAL . ")";
805 if (!($db->sql_query($sql, BEGIN_TRANSACTION)))
807 message_die(GENERAL_ERROR, 'Could not insert new topic', '', __LINE__, __FILE__, $sql);
810 $new_topic_id = $db->sql_nextid();
812 // Update topic watch table, switch users whose posts
813 // have moved, over to watching the new topic
814 $sql = "UPDATE " . TOPICS_WATCH_TABLE . "
815 SET topic_id = $new_topic_id
816 WHERE topic_id = $topic_id
817 AND user_id IN ($user_id_sql)";
818 if (!$db->sql_query($sql))
820 message_die(GENERAL_ERROR, 'Could not update topics watch table', '', __LINE__, __FILE__, $sql);
823 $sql_where = (!empty($HTTP_POST_VARS['split_type_beyond'])) ? " post_time >= $post_time AND topic_id = $topic_id" : "post_id IN ($post_id_sql)";
825 $sql = "UPDATE " . POSTS_TABLE . "
826 SET topic_id = $new_topic_id, forum_id = $new_forum_id
828 if (!$db->sql_query($sql, END_TRANSACTION))
830 message_die(GENERAL_ERROR, 'Could not update posts table', '', __LINE__, __FILE__, $sql);
833 sync('topic', $new_topic_id);
834 sync('topic', $topic_id);
835 sync('forum', $new_forum_id);
836 sync('forum', $forum_id);
838 $template->assign_vars(array(
839 'META' => '<meta http-equiv="refresh" content="3;url=' . "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'] . '">')
842 $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>');
843 message_die(GENERAL_MESSAGE, $message);
849 // Set template files
851 $template->set_filenames(array(
852 'split_body' => 'modcp_split.tpl')
855 $sql = "SELECT u.username, p.*, pt.post_text, pt.bbcode_uid, pt.post_subject, p.post_username
856 FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
857 WHERE p.topic_id = $topic_id
858 AND p.poster_id = u.user_id
859 AND p.post_id = pt.post_id
860 ORDER BY p.post_time ASC";
861 if ( !($result = $db->sql_query($sql)) )
863 message_die(GENERAL_ERROR, 'Could not get topic/post information', '', __LINE__, __FILE__, $sql);
866 $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" />';
868 if( ( $total_posts = $db->sql_numrows($result) ) > 0 )
870 $postrow = $db->sql_fetchrowset($result);
872 $template->assign_vars(array(
873 'L_SPLIT_TOPIC' => $lang['Split_Topic'],
874 'L_SPLIT_TOPIC_EXPLAIN' => $lang['Split_Topic_explain'],
875 'L_AUTHOR' => $lang['Author'],
876 'L_MESSAGE' => $lang['Message'],
877 'L_SELECT' => $lang['Select'],
878 'L_SPLIT_SUBJECT' => $lang['Split_title'],
879 'L_SPLIT_FORUM' => $lang['Split_forum'],
880 'L_POSTED' => $lang['Posted'],
881 'L_SPLIT_POSTS' => $lang['Split_posts'],
882 'L_SUBMIT' => $lang['Submit'],
883 'L_SPLIT_AFTER' => $lang['Split_after'],
884 'L_POST_SUBJECT' => $lang['Post_subject'],
885 'L_MARK_ALL' => $lang['Mark_all'],
886 'L_UNMARK_ALL' => $lang['Unmark_all'],
887 'L_POST' => $lang['Post'],
889 'FORUM_NAME' => $forum_name,
891 'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"),
893 'S_SPLIT_ACTION' => append_sid("modcp.$phpEx"),
894 'S_HIDDEN_FIELDS' => $s_hidden_fields,
895 'S_FORUM_SELECT' => make_forum_select("new_forum_id", false, $forum_id))
899 // Define censored word matches
901 $orig_word = array();
902 $replacement_word = array();
903 obtain_word_list($orig_word, $replacement_word);
905 for($i = 0; $i < $total_posts; $i++)
907 $post_id = $postrow[$i]['post_id'];
908 $poster_id = $postrow[$i]['poster_id'];
909 $poster = $postrow[$i]['username'];
911 $post_date = create_date($board_config['default_dateformat'], $postrow[$i]['post_time'], $board_config['board_timezone']);
913 $bbcode_uid = $postrow[$i]['bbcode_uid'];
914 $message = $postrow[$i]['post_text'];
915 $post_subject = ( $postrow[$i]['post_subject'] != '' ) ? $postrow[$i]['post_subject'] : $topic_title;
918 // If the board has HTML off but the post has HTML
919 // on then we process it, else leave it alone
921 if ( !$board_config['allow_html'] )
923 if ( $postrow[$i]['enable_html'] )
925 $message = preg_replace('#(<)([\/]?.*?)(>)#is', '<\\2>', $message);
929 if ( $bbcode_uid != '' )
931 $message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
934 if ( count($orig_word) )
936 $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
937 $message = preg_replace($orig_word, $replacement_word, $message);
940 $message = make_clickable($message);
942 if ( $board_config['allow_smilies'] && $postrow[$i]['enable_smilies'] )
944 $message = smilies_pass($message);
947 $message = str_replace("\n", '<br />', $message);
949 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
950 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
952 $checkbox = ( $i > 0 ) ? '<input type="checkbox" name="post_id_list[]" value="' . $post_id . '" />' : ' ';
954 $template->assign_block_vars('postrow', array(
955 'ROW_COLOR' => '#' . $row_color,
956 'ROW_CLASS' => $row_class,
957 'POSTER_NAME' => $poster,
958 'POST_DATE' => $post_date,
959 'POST_SUBJECT' => $post_subject,
960 'MESSAGE' => $message,
961 'POST_ID' => $post_id,
963 'S_SPLIT_CHECKBOX' => $checkbox)
967 $template->pparse('split_body');
973 $page_title = $lang['Mod_CP'];
974 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
976 $rdns_ip_num = ( isset($HTTP_GET_VARS['rdns']) ) ? $HTTP_GET_VARS['rdns'] : "";
980 message_die(GENERAL_MESSAGE, $lang['No_such_post']);
984 // Set template files
986 $template->set_filenames(array(
987 'viewip' => 'modcp_viewip.tpl')
990 // Look up relevent data for this post
991 $sql = "SELECT poster_ip, poster_id
992 FROM " . POSTS_TABLE . "
993 WHERE post_id = $post_id
994 AND forum_id = $forum_id";
995 if ( !($result = $db->sql_query($sql)) )
997 message_die(GENERAL_ERROR, 'Could not get poster IP information', '', __LINE__, __FILE__, $sql);
1000 if ( !($post_row = $db->sql_fetchrow($result)) )
1002 message_die(GENERAL_MESSAGE, $lang['No_such_post']);
1005 $ip_this_post = decode_ip($post_row['poster_ip']);
1006 $ip_this_post = ( $rdns_ip_num == $ip_this_post ) ? htmlspecialchars(gethostbyaddr($ip_this_post)) : $ip_this_post;
1008 $poster_id = $post_row['poster_id'];
1010 $template->assign_vars(array(
1011 'L_IP_INFO' => $lang['IP_info'],
1012 'L_THIS_POST_IP' => $lang['This_posts_IP'],
1013 'L_OTHER_IPS' => $lang['Other_IP_this_user'],
1014 'L_OTHER_USERS' => $lang['Users_this_IP'],
1015 'L_LOOKUP_IP' => $lang['Lookup_IP'],
1016 'L_SEARCH' => $lang['Search'],
1018 'SEARCH_IMG' => $images['icon_search'],
1020 'IP' => $ip_this_post,
1022 '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'])
1026 // Get other IP's this user has posted under
1028 $sql = "SELECT poster_ip, COUNT(*) AS postings
1029 FROM " . POSTS_TABLE . "
1030 WHERE poster_id = $poster_id
1032 ORDER BY " . (( SQL_LAYER == 'msaccess' ) ? 'COUNT(*)' : 'postings' ) . " DESC";
1033 if ( !($result = $db->sql_query($sql)) )
1035 message_die(GENERAL_ERROR, 'Could not get IP information for this user', '', __LINE__, __FILE__, $sql);
1038 if ( $row = $db->sql_fetchrow($result) )
1043 if ( $row['poster_ip'] == $post_row['poster_ip'] )
1045 $template->assign_vars(array(
1046 'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ))
1051 $ip = decode_ip($row['poster_ip']);
1052 $ip = ( $rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? htmlspecialchars(gethostbyaddr($ip)) : $ip;
1054 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1055 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1057 $template->assign_block_vars('iprow', array(
1058 'ROW_COLOR' => '#' . $row_color,
1059 'ROW_CLASS' => $row_class,
1061 'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ),
1063 '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'])
1068 while ( $row = $db->sql_fetchrow($result) );
1072 // Get other users who've posted under this IP
1074 $sql = "SELECT u.user_id, u.username, COUNT(*) as postings
1075 FROM " . USERS_TABLE ." u, " . POSTS_TABLE . " p
1076 WHERE p.poster_id = u.user_id
1077 AND p.poster_ip = '" . $post_row['poster_ip'] . "'
1078 GROUP BY u.user_id, u.username
1079 ORDER BY " . (( SQL_LAYER == 'msaccess' ) ? 'COUNT(*)' : 'postings' ) . " DESC";
1080 if ( !($result = $db->sql_query($sql)) )
1082 message_die(GENERAL_ERROR, 'Could not get posters information based on IP', '', __LINE__, __FILE__, $sql);
1085 if ( $row = $db->sql_fetchrow($result) )
1090 $id = $row['user_id'];
1091 $username = ( $id == ANONYMOUS ) ? $lang['Guest'] : $row['username'];
1093 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1094 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1096 $template->assign_block_vars('userrow', array(
1097 'ROW_COLOR' => '#' . $row_color,
1098 'ROW_CLASS' => $row_class,
1099 'USERNAME' => $username,
1100 'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ),
1101 'L_SEARCH_POSTS' => sprintf($lang['Search_user_posts'], $username),
1103 '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"),
1104 'U_SEARCHPOSTS' => append_sid("search.$phpEx?search_author=" . (($id == ANONYMOUS) ? 'Anonymous' : urlencode($username)) . "&showresults=topics"))
1109 while ( $row = $db->sql_fetchrow($result) );
1112 $template->pparse('viewip');
1117 $page_title = $lang['Mod_CP'];
1118 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
1120 $template->assign_vars(array(
1121 'FORUM_NAME' => $forum_name,
1123 'L_MOD_CP' => $lang['Mod_CP'],
1124 'L_MOD_CP_EXPLAIN' => $lang['Mod_CP_explain'],
1125 'L_SELECT' => $lang['Select'],
1126 'L_DELETE' => $lang['Delete'],
1127 'L_MOVE' => $lang['Move'],
1128 'L_LOCK' => $lang['Lock'],
1129 'L_UNLOCK' => $lang['Unlock'],
1130 'L_TOPICS' => $lang['Topics'],
1131 'L_REPLIES' => $lang['Replies'],
1132 'L_LASTPOST' => $lang['Last_Post'],
1133 'L_SELECT' => $lang['Select'],
1135 'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"),
1136 'S_HIDDEN_FIELDS' => '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />',
1137 'S_MODCP_ACTION' => append_sid("modcp.$phpEx"))
1140 $template->set_filenames(array(
1141 'body' => 'modcp_body.tpl')
1143 make_jumpbox('modcp.'.$phpEx);
1146 // Define censored word matches
1148 $orig_word = array();
1149 $replacement_word = array();
1150 obtain_word_list($orig_word, $replacement_word);
1152 $sql = "SELECT t.*, u.username, u.user_id, p.post_time
1153 FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p
1154 WHERE t.forum_id = $forum_id
1155 AND t.topic_poster = u.user_id
1156 AND p.post_id = t.topic_last_post_id
1157 ORDER BY t.topic_type DESC, p.post_time DESC
1158 LIMIT $start, " . $board_config['topics_per_page'];
1159 if ( !($result = $db->sql_query($sql)) )
1161 message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
1164 while ( $row = $db->sql_fetchrow($result) )
1168 if ( $row['topic_status'] == TOPIC_LOCKED )
1170 $folder_img = $images['folder_locked'];
1171 $folder_alt = $lang['Topic_locked'];
1175 if ( $row['topic_type'] == POST_ANNOUNCE )
1177 $folder_img = $images['folder_announce'];
1178 $folder_alt = $lang['Topic_Announcement'];
1180 else if ( $row['topic_type'] == POST_STICKY )
1182 $folder_img = $images['folder_sticky'];
1183 $folder_alt = $lang['Topic_Sticky'];
1187 $folder_img = $images['folder'];
1188 $folder_alt = $lang['No_new_posts'];
1192 $topic_id = $row['topic_id'];
1193 $topic_type = $row['topic_type'];
1194 $topic_status = $row['topic_status'];
1196 if ( $topic_type == POST_ANNOUNCE )
1198 $topic_type = $lang['Topic_Announcement'] . ' ';
1200 else if ( $topic_type == POST_STICKY )
1202 $topic_type = $lang['Topic_Sticky'] . ' ';
1204 else if ( $topic_status == TOPIC_MOVED )
1206 $topic_type = $lang['Topic_Moved'] . ' ';
1213 if ( $row['topic_vote'] )
1215 $topic_type .= $lang['Topic_Poll'] . ' ';
1218 $topic_title = $row['topic_title'];
1219 if ( count($orig_word) )
1221 $topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
1224 $u_view_topic = "modcp.$phpEx?mode=split&" . POST_TOPIC_URL . "=$topic_id&sid=" . $userdata['session_id'];
1225 $topic_replies = $row['topic_replies'];
1227 $last_post_time = create_date($board_config['default_dateformat'], $row['post_time'], $board_config['board_timezone']);
1229 $template->assign_block_vars('topicrow', array(
1230 'U_VIEW_TOPIC' => $u_view_topic,
1232 'TOPIC_FOLDER_IMG' => $folder_img,
1233 'TOPIC_TYPE' => $topic_type,
1234 'TOPIC_TITLE' => $topic_title,
1235 'REPLIES' => $topic_replies,
1236 'LAST_POST_TIME' => $last_post_time,
1237 'TOPIC_ID' => $topic_id,
1239 'L_TOPIC_FOLDER_ALT' => $folder_alt)
1243 $template->assign_vars(array(
1244 'PAGINATION' => generate_pagination("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&sid=" . $userdata['session_id'], $forum_topics, $board_config['topics_per_page'], $start),
1245 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $forum_topics / $board_config['topics_per_page'] )),
1246 'L_GOTO_PAGE' => $lang['Goto_page'])
1249 $template->pparse('body');
1254 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);