diff options
author | Ludovic Arnaud <ludovic_arnaud@users.sourceforge.net> | 2003-11-27 23:20:31 +0000 |
---|---|---|
committer | Ludovic Arnaud <ludovic_arnaud@users.sourceforge.net> | 2003-11-27 23:20:31 +0000 |
commit | a08d9e647300dfa70052245d7fd1cddacdbd0453 (patch) | |
tree | cca603e762b6e177d9d8fd9712f8f85c47a65fba /phpBB/includes/mcp/mcp_main.php | |
parent | da4f6d99de01f773e579b0463dd4d2f0a10fc871 (diff) | |
download | forums-a08d9e647300dfa70052245d7fd1cddacdbd0453.tar forums-a08d9e647300dfa70052245d7fd1cddacdbd0453.tar.gz forums-a08d9e647300dfa70052245d7fd1cddacdbd0453.tar.bz2 forums-a08d9e647300dfa70052245d7fd1cddacdbd0453.tar.xz forums-a08d9e647300dfa70052245d7fd1cddacdbd0453.zip |
mcp_main module, responsible for forum/topic/post view and common operations
git-svn-id: file:///svn/phpbb/trunk@4692 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/mcp/mcp_main.php')
-rw-r--r-- | phpBB/includes/mcp/mcp_main.php | 1336 |
1 files changed, 1152 insertions, 184 deletions
diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 12169c0fda..f4c0910a50 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -13,60 +13,316 @@ class mcp_main extends mcp { - var $module_name = 'main'; - - function mcp_main($module_id) + function init() { - $this->module_id = $module_id; - $this->url = $module_url; - + // Validate input $this->mcp_init(); - $this->submodules = array( - 'MCP_FRONT' => '&i=' . $module_id . '&mode=front', - 'MCP_FORUM' => '&i=' . $module_id . '&mode=forum_view' - ); - - if ($this->topic_id) + if (!$this->post_id) { - $this->submodules['MCP_TOPIC'] = '&i=' . $module_id . '&mode=topic_view'; + unset($this->modules[$this->id]['subs']['post_details']); } - if ($this->post_id) + if (!$this->topic_id) { - $this->submodules['MCP_POST'] = '&i=' . $module_id . '&mode=post_details'; + unset($this->modules[$this->id]['subs']['topic_view']); } } function main($mode) { global $auth, $db, $user, $template; - global $config, $phpbb_root_path, $phpEx, $SID, $start; + global $config, $phpbb_root_path, $phpEx, $SID; + + $this->mode = $mode; switch ($mode) { - case 'merge_posts': - if (!$this->to_topic_id) + case 'resync': + if (!$topic_id_list = $this->get_topic_ids('m_')) { - redirect(str_replace('&', '&', $this->url . $this->selected_ids) . '&i=' . $this->module_id . '&mode=merge_select'); + $template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']); + $this->main('forum_view'); } + + // Sync everything and perform extra checks separately + sync('topic_reported', 'topic_id', $topic_id_list, FALSE, TRUE); + sync('topic_attachment', 'topic_id', $topic_id_list, FALSE, TRUE); + sync('topic', 'topic_id', $topic_id_list, TRUE, FALSE); + + + $sql = 'SELECT topic_id, forum_id, topic_title + FROM ' . TOPICS_TABLE . ' + WHERE topic_id IN (' . implode(', ', $topic_id_list) . ')'; + $result = $db->sql_query($sql); + + // Log this action + while ($row = $db->sql_fetchrow($result)) + { + add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_TOPIC_RESYNC', $row['topic_title']); + } + + $msg = (count($topic_id_list) == 1) ? $user->lang['TOPIC_RESYNC_SUCCESS'] : $user->lang['TOPICS_RESYNC_SUCCESS']; + $template->assign_var('MESSAGE', $msg); + + // Back to the topics list + $this->main('forum_view'); break; - case 'merge_select': - case 'forum_view': - $this->menu('MCP_FORUM'); - $this->mcp_jumpbox($this->url . '&mode=forum_view', 'm_', $this->forum_id); - - if (!$this->forum_id) + case 'lock': + case 'unlock': + if (!$topic_id_list = $this->get_topic_ids('m_lock')) { - $this->message_die('PLEASE_SELECT_FORUM'); + $template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']); + $this->main('forum_view'); } - if (!$auth->acl_get('m_', $this->forum_id)) + if (count($topic_id_list) == 1) { - trigger_error('NOT_MODERATOR'); + $message = ($mode == 'lock') ? $user->lang['TOPIC_LOCKED_SUCCESS'] : $user->lang['TOPIC_UNLOCKED_SUCCESS']; + } + else + { + $message = ($mode == 'lock') ? $user->lang['TOPICS_LOCKED_SUCCESS'] : $user->lang['TOPICS_UNLOCKED_SUCCESS']; + } + + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_status = ' . (($mode == 'lock') ? ITEM_LOCKED : ITEM_UNLOCKED) . ' + WHERE topic_id IN (' . implode(', ', $topic_id_list) . ')'; + $db->sql_query($sql); + + $topic_data = $this->get_topic_data($topic_id_list); + foreach ($topic_data as $topic_id => $row) + { + add_log('mod', $this->forum_id, $topic_id, 'LOG_' . strtoupper($mode), $row['topic_title']); + } + + // Where are we going to be redirected? + $return_topic = "viewtopic.$phpEx$SID&f={$this->forum_id}&t={$this->topic_id}&start={$this->start}"; + $return_forum = "viewforum.$phpEx$SID&f={$this->forum_id}"; + + if ($this->quickmod) + { + meta_refresh(3, $return_topic); + + $message .= '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $return_topic . '">', '</a>'); + $message .= '<br \><br \>' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum . '">', '</a>'); + + trigger_error($message); + } + else + { + return_link('RETURN_TOPIC', $return_topic); + return_link('RETURN_FORUM', $return_forum); + + $template->assign_var('MESSAGE', $message); + $this->main('forum_view'); + } + break; + + case 'front': + // ------------- + // Latest 5 unapproved + $forum_list = get_forum_list('m_approve'); + $post_list = array(); + + $template->assign_var('S_SHOW_UNAPPROVED', (!empty($forum_list)) ? TRUE : FALSE); + if (!empty($forum_list)) + { + $sql = 'SELECT COUNT(post_id) AS total + FROM ' . POSTS_TABLE . ' + WHERE forum_id IN (' . implode(', ', $forum_list) . ') + AND post_approved = 0'; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $total = $row['total']; + + if ($total) + { + // KNOWN BUG: does not work with global announcements + $sql = 'SELECT post_id + FROM ' . POSTS_TABLE . ' + WHERE forum_id IN (' . implode(', ', $forum_list) . ') + AND post_approved = 0 + ORDER BY post_id DESC'; + $result = $db->sql_query_limit($sql, 5); + while ($row = $db->sql_fetchrow($result)) + { + $post_list[] = $row['post_id']; + } + + $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.username, t.topic_id, t.topic_title, t.topic_first_post_id, f.forum_id, f.forum_name + FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . ' u + WHERE p.post_id IN (' . implode(', ', $post_list) . ') + AND t.topic_id = p.topic_id + AND f.forum_id = p.forum_id + AND p.poster_id = u.user_id + ORDER BY p.post_id DESC'; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + if ($row['poster_id'] == ANONYMOUS) + { + $author = ($row['post_username']) ? $row['post_username'] : $user->lang['GUEST']; + } + else + { + $author = '<a href="memberlist.' . $phpEx . $SID . '&mode=viewprofile&u=' . $row['poster_id'] . '">' . $row['username'] . '</a>'; + } + + $template->assign_block_vars('unapproved', array( + 'U_POST_DETAILS'=> $this->url . '&mode=post_details', + 'FORUM' => (!empty($row['forum_id'])) ? '<a href="viewforum.' . $phpEx . $SID . '&f=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>' : $user->lang['POST_GLOBAL'], + 'TOPIC' => '<a href="viewtopic.' . $phpEx . $SID . '&f=' . $row['forum_id'] . '&t=' . $row['topic_id'] . '">' . $row['topic_title'] . '</a>', + 'AUTHOR' => $author, + 'SUBJECT' => '<a href="mcp.' . $phpEx . $SID . '&p=' . $row['post_id'] . '&mode=post_details">' . (($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT']) . '</a>', + 'POST_TIME' => $user->format_date($row['post_time']) + )); + } + } + + if ($total == 0) + { + $template->assign_vars(array( + 'L_UNAPPROVED_TOTAL' => $user->lang['UNAPPROVED_POSTS_ZERO_TOTAL'], + 'S_HAS_UNAPPROVED_POSTS' => FALSE + )); + } + elseif ($total == 1) + { + $template->assign_vars(array( + 'L_UNAPPROVED_TOTAL' => $user->lang['UNAPPROVED_POST_TOTAL'], + 'S_HAS_UNAPPROVED_POSTS' => TRUE + )); + } + else + { + $template->assign_vars(array( + 'L_UNAPPROVED_TOTAL' => sprintf($user->lang['UNAPPROVED_POSTS_TOTAL'], $total), + 'S_HAS_UNAPPROVED_POSTS' => TRUE + )); + } + } + // ------------- + + // ------------- + // Latest 5 reported + $forum_list = get_forum_list('m_'); + + $template->assign_var('S_SHOW_REPORTS', (!empty($forum_list)) ? TRUE : FALSE); + if (!empty($forum_list)) + { + $sql = 'SELECT COUNT(r.report_id) AS total + FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p + WHERE r.post_id = p.post_id + AND p.forum_id IN (0, ' . implode(', ', $forum_list) . ')'; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $total = $row['total']; + + if ($total) + { + $sql = 'SELECT r.*, p.post_id, p.post_subject, u.username, t.topic_id, t.topic_title, f.forum_id, f.forum_name + FROM ' . REPORTS_TABLE . ' r, ' . REASONS_TABLE . ' rr,' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u + LEFT JOIN ' . FORUMS_TABLE . ' f ON f.forum_id = p.forum_id + WHERE r.post_id = p.post_id + AND r.reason_id = rr.reason_id + AND p.topic_id = t.topic_id + AND r.user_id = u.user_id + AND p.forum_id IN (0, ' . implode(', ', $forum_list) . ') + ORDER BY p.post_id DESC'; + $result = $db->sql_query_limit($sql, 5); + + while ($row = $db->sql_fetchrow($result)) + { + $template->assign_block_vars('report', array( + 'U_POST_DETAILS' => $this->url . '&mode=post_details', + 'FORUM' => (!empty($row['forum_id'])) ? '<a href="viewforum.' . $phpEx . $SID . '&f=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>' : $user->lang['POST_GLOBAL'], + 'TOPIC' => '<a href="viewtopic.' . $phpEx . $SID . '&f=' . $row['forum_id'] . '&t=' . $row['topic_id'] . '">' . $row['topic_title'] . '</a>', + 'REPORTER' => ($row['user_id'] == ANONYMOUS) ? $user->lang['GUEST'] : '<a href="memberlist.' . $phpEx . $SID . '&mode=viewprofile&u=' . $row['user_id'] . '">' . $row['username'] . '</a>', + 'SUBJECT' => '<a href="mcp.' . $phpEx . $SID . '&p=' . $row['post_id'] . '&mode=post_details">' . (($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT']) . '</a>', + 'REPORT_TIME' => $user->format_date($row['report_time']) + )); + } + } + + if ($total == 0) + { + $template->assign_vars(array( + 'L_REPORTS_TOTAL' => $user->lang['REPORTS_ZERO_TOTAL'], + 'S_HAS_REPORTS' => FALSE + )); + } + elseif ($total == 1) + { + $template->assign_vars(array( + 'L_REPORTS_TOTAL' => $user->lang['REPORT_TOTAL'], + 'S_HAS_REPORTS' => TRUE + )); + } + else + { + $template->assign_vars(array( + 'L_REPORTS_TOTAL' => sprintf($user->lang['REPORTS_TOTAL'], total), + 'S_HAS_REPORTS' => TRUE + )); + } + } + // ------------- + + // ------------- + // Latest 5 logs + $forum_list = get_forum_list(array('m_', 'a_general')); + + if (!empty($forum_list)) + { + // Add forum_id 0 for global announcements + $forum_list[] = 0; + + $log_count = 0; + $log = array(); + view_log('mod', $log, $log_count, 5, 0, $forum_list); + + foreach ($log as $row) + { + $template->assign_block_vars('log', array( + 'USERNAME' => $row['username'], + 'IP' => $row['ip'], + 'TIME' => $user->format_date($row['time']), + 'ACTION' => $row['action'], + 'U_VIEWTOPIC' => $row['viewtopic'], + 'U_VIEWLOGS' => $row['viewlogs'] + )); + } + } + $template->assign_vars(array( + 'S_SHOW_LOGS' => (!empty($forum_list)) ? TRUE : FALSE, + 'S_HAS_LOGS' => (!empty($log)) ? TRUE : FALSE + )); + // ------------- + + $template->assign_var('S_MCP_ACTION', $this->url); + $this->mcp_jumpbox($this->url . '&mode=forum_view', 'm_', $this->forum_id); + $this->display($user->lang['MCP'], 'mcp_front.html'); + break; + + case 'merge_select': + // Change current mode for the menu + $this->mode = 'forum_view'; + + // Fixes a "bug" that makes forum_view use the same ordering as topic_view + unset($_POST['sk'], $_POST['sd'], $_REQUEST['sk'], $_REQUEST['sd']); + + // No break; here + + case 'forum_view': + if (!$forum_info = $this->get_forum_data($this->forum_id, 'm_', TRUE)) + { + $this->main($id, 'front'); } - $forum_info = $this->get_forum_data($this->forum_id, 'm_'); + $this->mcp_jumpbox($this->url . '&mode=' . $mode . (($mode == 'merge_select') ? $this->selected_ids : ''), 'm_', $this->forum_id); + $topics_per_page = ($forum_info['forum_topics_per_page']) ? $forum_info['forum_topics_per_page'] : $config['topics_per_page']; $this->mcp_sorting('viewforum', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $this->forum_id); @@ -76,6 +332,9 @@ class mcp_main extends mcp $template->assign_vars(array( 'FORUM_NAME' => $forum_info['forum_name'], + 'REPORTED_IMG' => $user->img('icon_reported', 'TOPIC_REPORTED'), + 'UNAPPROVED_IMG' => $user->img('icon_unapproved', 'TOPIC_UNAPPROVED'), + 'S_CAN_DELETE' => $auth->acl_get('m_delete', $this->forum_id), 'S_CAN_MOVE' => $auth->acl_get('m_move', $this->forum_id), 'S_CAN_FORK' => $auth->acl_get('m_', $this->forum_id), @@ -83,10 +342,10 @@ class mcp_main extends mcp 'S_CAN_SYNC' => $auth->acl_get('m_', $this->forum_id), 'U_VIEW_FORUM' => "viewforum.$phpEx$SID&f=" . $this->forum_id, - 'S_MCP_ACTION' => "mcp.$phpEx$SID&mode=$mode&f=$this->forum_id&start=$start" . (($mode == 'merge_select') ? $this->selected_ids : ''), + 'S_MCP_ACTION' => $this->url . "&mode={$mode}&start={$this->start}" . (($mode == 'merge_select') ? $this->selected_ids : ''), - 'PAGINATION' => generate_pagination($this->url . "&mode={$mode}&f=" . $this->forum_id . (($mode == 'merge_select') ? $this->selected_ids : ''), $forum_topics, $topics_per_page, $start), - 'PAGE_NUMBER' => on_page($forum_topics, $config['topics_per_page'], $start) + 'PAGINATION' => generate_pagination($this->url . "&mode={$mode}&f=" . $this->forum_id . (($mode == 'merge_select') ? $this->selected_ids : ''), $forum_topics, $topics_per_page, $this->start), + 'PAGE_NUMBER' => on_page($forum_topics, $config['topics_per_page'], $this->start) )); @@ -96,10 +355,11 @@ class mcp_main extends mcp $topic_rows = array(); +// TODO: no global announcements here $sql = 'SELECT t.* FROM ' . TOPICS_TABLE . " t WHERE t.forum_id = {$this->forum_id} - " . (($auth->acl_gets('m_approve', $this->forum_id)) ? '' : 'AND t.topic_approved = 1') . " + " . (($auth->acl_get('m_approve', $this->forum_id)) ? '' : 'AND t.topic_approved = 1') . " AND t.topic_type = " . POST_ANNOUNCE . " $limit_time_sql ORDER BY $sort_order_sql"; @@ -115,11 +375,11 @@ class mcp_main extends mcp $sql = "SELECT t.* FROM " . TOPICS_TABLE . " t WHERE t.forum_id = {$this->forum_id} - " . (($auth->acl_gets('m_approve', $this->forum_id)) ? '' : 'AND t.topic_approved = 1') . " - AND t.topic_type <> " . POST_ANNOUNCE . " + " . (($auth->acl_get('m_approve', $this->forum_id)) ? '' : 'AND t.topic_approved = 1') . ' + AND t.topic_type IN (' . POST_NORMAL . ', ' . POST_STICKY . ") $limit_time_sql ORDER BY t.topic_type DESC, $sort_order_sql"; - $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); + $result = $db->sql_query_limit($sql, $config['topics_per_page'], $this->start); while ($row = $db->sql_fetchrow($result)) { @@ -156,7 +416,7 @@ class mcp_main extends mcp } } - if ($row['topic_type'] == POST_ANNOUNCE) + if ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) { $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'] . ' '; } @@ -189,6 +449,8 @@ class mcp_main extends mcp 'S_SELECT_TOPIC' => ($mode == 'merge_select' && $row['topic_id'] != $this->topic_id) ? TRUE : FALSE, 'U_SELECT_TOPIC' => $this->url . '&mode=merge&to_topic_id=' . $row['topic_id'] . $this->selected_ids, + 'U_MCP_QUEUE' => $this->url . '&mode=approve&t=' . $row['topic_id'], + 'U_MCP_REPORT' => $this->url . '&mode=reports&t=' . $row['topic_id'], 'TOPIC_FOLDER_IMG' => $folder_img, 'TOPIC_TYPE' => $topic_type, @@ -196,36 +458,336 @@ class mcp_main extends mcp 'REPLIES' => $row['topic_replies'], 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'TOPIC_ID' => $row['topic_id'], + 'S_TOPIC_CHECKED' => (in_array($row['topic_id'], $this->topic_id_list)) ? 'checked="checked" ' : '', 'S_TOPIC_REPORTED' => ($row['topic_reported']) ? TRUE : FALSE, 'S_TOPIC_UNAPPROVED'=> ($row['topic_approved']) ? FALSE : TRUE )); } - unset($topoic_rows); + unset($topic_rows); $this->display($user->lang['MCP'], 'mcp_forum.html'); break; - case 'merge': - case 'split': - case 'delete': - case 'topic_view': - $this->menu('MCP_TOPIC'); - $this->mcp_jumpbox($this->url . '&mode=forum_view', 'm_', $this->forum_id); + case 'move': + if ($this->cancel) + { + $this->main('forum_view'); + } + // + // KNOWN BUG: won't work with global announcements + // + if (!$topic_id_list = $this->get_topic_ids('m_move')) + { + $template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']); + } - $topic_info = $this->get_topic_data($this->topic_id, 'm_'); + if (1 > $this->to_forum_id) + { + $this->confirm = FALSE; + } + elseif (!$forum_data = $this->get_forum_data($this->to_forum_id)) + { + $template->assign_var('MESSAGE', $user->lang['FORUM_NOT_EXIST']); + $this->confirm = FALSE; + } + elseif ($forum_data['forum_type'] != FORUM_POST) + { + $template->assign_var('MESSAGE', $user->lang['FORUM_NOT_POSTABLE']); + $this->confirm = FALSE; + } + elseif (!$auth->acl_get('f_post', $this->to_forum_id)) + { + $template->assign_var('MESSAGE', $user->lang['USER_CANNOT_POST']); + $this->confirm = FALSE; + } - if (!$this->topic_id) + if (!$this->confirm) { - $this->message_die('TOPIC_NOT_EXIST'); + $s_hidden_fields = ''; + foreach ($topic_id_list as $topic_id) + { + $s_hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . $topic_id . '">'; + } + + $template->assign_vars(array( + 'S_MCP_ACTION' => "mcp.$phpEx$SID&mode=move", + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_FORUM_SELECT' => make_forum_select(), + 'S_CAN_LEAVE_SHADOW' => TRUE, + + 'L_MODE_TITLE' => $user->lang['MOVE'], + 'L_MODE_EXPLAIN' => '' + )); + + $this->display($user->lang['MCP'], 'mcp_move.html'); } - if (!$auth->acl_get('m_', $topic_info['forum_id'])) + else { - trigger_error('NOT_MODERATOR'); + // Get topic data + $topic_data = $this->get_topic_data($topic_id_list); + + // Check if any of topics is moved to the same forum + foreach ($topic_data as $topic_id => $row) + { + if ($row['forum_id'] == $this->to_forum_id) + { + $template->assign_var('MESSAGE', $user->lang['CANNOT_MOVE_SAME_FORUM']); + + // Another convienient way to eliminate redundancy, go back to the move form + $this->confirm = FALSE; + $this->main('move'); + } + } + + // Move topics, but do not resync yet + move_topics($topic_id_list, $this->to_forum_id, FALSE); + + $forum_ids = array($this->to_forum_id); + foreach ($topic_data as $topic_id => $row) + { + // Get the list of forums to resync, add a log entry + $forum_ids[] = $row['forum_id']; + add_log('mod', $this->to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name']); + + // Leave a redirection if required and only if the topic is visible to users + if (!empty($_POST['move_leave_shadow']) && $row['topic_approved']) + { + $shadow = array( + 'forum_id' => (int) $row['forum_id'], + 'icon_id' => (int) $row['icon_id'], + 'topic_attachment' => (int) $row['topic_attachment'], + 'topic_approved' => 1, + 'topic_reported' => (int) $row['topic_reported'], + 'topic_title' => (string) $row['topic_title'], + 'topic_poster' => (int) $row['topic_poster'], + 'topic_time' => (int) $row['topic_time'], + 'topic_time_limit' => (int) $row['topic_time_limit'], + 'topic_views' => (int) $row['topic_views'], + 'topic_replies' => (int) $row['topic_replies'], + 'topic_replies_real' => (int) $row['topic_replies_real'], + 'topic_status' => ITEM_MOVED, + 'topic_type' => (int) $row['topic_type'], + 'topic_first_post_id' => (int) $row['topic_first_post_id'], + 'topic_first_poster_name'=> (string) $row['topic_first_poster_name'], + 'topic_last_post_id' => (int) $row['topic_last_post_id'], + 'topic_last_poster_id' => (int) $row['topic_last_poster_id'], + 'topic_last_poster_name'=> (string) $row['topic_last_poster_name'], + 'topic_last_post_time' => (int) $row['topic_last_post_time'], + 'topic_last_view_time' => (int) $row['topic_last_view_time'], + 'topic_moved_id' => (int) $row['topic_id'], + 'poll_title' => (string) $row['poll_title'], + 'poll_start' => (int) $row['poll_start'], + 'poll_length' => (int) $row['poll_length'], + 'poll_max_options' => (int) $row['poll_max_options'], + 'poll_last_vote' => (int) $row['poll_last_vote'] + ); + + $db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow)); + } + } + unset($topic_data); + + // Now sync forums + sync('forum', 'forum_id', $forum_ids); + + $msg = (count($topic_id_list) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS'; + $template->assign_var('MESSAGE', $user->lang[$msg]); + + // Return to the destination forum + return_link('RETURN_FORUM', "viewforum.$phpEx$SID&f={$this->forum_id}"); + return_link('RETURN_NEW_FORUM', "viewforum.$phpEx$SID&f={$this->to_forum_id}"); + + $this->forum_id = $this->to_forum_id; + $this->main('forum_view'); + } + break; + + case 'fork': + if (!$topic_id_list = $this->get_topic_ids('m_')) + { + $template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']); + } + + if (1 > $this->to_forum_id) + { + $this->confirm = FALSE; + } + elseif (!$forum_data = $this->get_forum_data($this->to_forum_id)) + { + $template->assign_var('MESSAGE', $user->lang['FORUM_NOT_EXIST']); + $this->confirm = FALSE; + } + elseif ($forum_data['forum_type'] != FORUM_POST) + { + $template->assign_var('MESSAGE', $user->lang['FORUM_NOT_POSTABLE']); + $this->confirm = FALSE; + } + elseif (!$auth->acl_get('f_post', $this->to_forum_id)) + { + $template->assign_var('MESSAGE', $user->lang['USER_CANNOT_POST']); + $this->confirm = FALSE; + } + + if (!$this->confirm) + { + $s_hidden_fields = ''; + foreach ($topic_id_list as $topic_id) + { + $s_hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . $topic_id . '">'; + } + + $template->assign_vars(array( + 'S_MCP_ACTION' => "mcp.$phpEx$SID&mode=fork", + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_FORUM_SELECT' => make_forum_select(), + + 'L_MODE_TITLE' => $user->lang['FORK'], + 'L_MODE_EXPLAIN' => $user->lang['FORK_EXPLAIN'] + )); + + $this->display($user->lang['MCP'], 'mcp_move.html'); + } + else + { + $topic_data = $this->get_topic_data($topic_id_list); + + $total_posts = 0; + $new_topic_id_list = $post_rows = array(); + foreach ($topic_data as $topic_id => $topic_row) + { + $sql_ary = array( + 'forum_id' => (int) $this->to_forum_id, + 'icon_id' => (int) $topic_row['icon_id'], + 'topic_approved' => 1, + 'topic_title' => (string) $topic_row['topic_title'], + 'topic_poster' => (int) $topic_row['topic_poster'], + 'topic_time' => (int) $topic_row['topic_time'], + 'topic_replies' => (int) $topic_row['topic_replies_real'], + 'topic_replies_real' => (int) $topic_row['topic_replies_real'], + 'topic_status' => (int) $topic_row['topic_status'], + 'topic_type' => (int) $topic_row['topic_type'], + 'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'], + 'topic_last_poster_id' => (int) $topic_row['topic_last_poster_id'], + 'topic_last_poster_name' => (string) $topic_row['topic_last_poster_name'], + 'topic_last_post_time' => (int) $topic_row['topic_last_post_time'], + 'poll_title' => (string) $topic_row['poll_title'], + 'poll_start' => (int) $topic_row['poll_start'], + 'poll_length' => (int) $topic_row['poll_length'] + ); + + $db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $sql_ary)); + $new_topic_id = $db->sql_nextid(); + $new_topic_id_list[$topic_id] = $new_topic_id; + + if ($topic_row['poll_start']) + { + $poll_rows = array(); + + $result = $db->sql_query('SELECT * FROM ' . POLL_OPTIONS_TABLE . ' WHERE topic_id = ' . $topic_id); + while ($row = $db->sql_fetchrow($result)) + { + $sql = 'INSERT INTO ' . POLL_OPTIONS_TABLE . ' (poll_option_id, topic_id, poll_option_text, poll_option_total) + VALUES (' . $row['poll_option_id'] . ', ' . $new_topic_id . ", '" . $db->sql_escape($row['poll_option_text']) . "', 0)"; + + $db->sql_query($sql); + } + } + + $sql = 'SELECT * + FROM ' . POSTS_TABLE . " + WHERE topic_id = $topic_id + ORDER BY post_id ASC"; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $post_rows[] = $row; + } + $db->sql_freeresult(); + + if (!count($post_rows)) + { + continue; + } + + $total_posts += count($post_rows); + foreach ($post_rows as $row) + { + $sql_ary = array( + 'topic_id' => (int) $new_topic_id, + 'forum_id' => (int) $this->to_forum_id, + 'poster_id' => (int) $row['poster_id'], + 'icon_id' => (int) $row['icon_id'], + 'poster_ip' => (string) $row['poster_ip'], + 'post_time' => (int) $row['post_time'], + 'post_approved' => 1, + 'enable_bbcode' => (int) $row['enable_bbcode'], + 'enable_html' => (int) $row['enable_html'], + 'enable_smilies' => (int) $row['enable_smilies'], + 'enable_magic_url' => (int) $row['enable_magic_url'], + 'enable_sig' => (int) $row['enable_sig'], + 'post_username' => (string) $row['post_username'], + 'post_subject' => (string) $row['post_subject'], + 'post_text' => (string) $row['post_text'], + 'post_checksum' => (string) $row['post_checksum'], + 'post_encoding' => (string) $row['post_encoding'], + 'bbcode_bitfield' => (int) $row['bbcode_bitfield'], + 'bbcode_uid' => (string) $row['bbcode_uid'] + ); + + $db->sql_query('INSERT INTO ' . POSTS_TABLE . $db->sql_build_array('INSERT', $sql_ary)); + } + } + + // Sync new topics, parent forums and board stats + sync('topic', 'topic_id', $new_topic_id_list, TRUE); + sync('forum', 'forum_id', $this->to_forum_id, TRUE); + set_config('num_topics', $config['num_topics'] + count($topic_id_list)); + set_config('num_posts', $config['num_posts'] + $total_posts); + + foreach ($new_topic_id_list as $topic_id => $new_topic_id) + { + add_log('mod', $this->to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']); + } + + $msg = (count($topic_id_list) == 1) ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS'; + $template->assign_var('MESSAGE', $user->lang[$msg]); + + // Return to the destination forum + return_link('RETURN_FORUM', "viewforum.$phpEx$SID&f={$this->forum_id}"); + + if ($this->forum_id != $this->to_forum_id) + { + return_link('RETURN_NEW_FORUM', "viewforum.$phpEx$SID&f={$this->to_forum_id}"); + } + + $this->forum_id = $this->to_forum_id; + $this->main('forum_view'); } + break; + case 'merge': + case 'split': + case 'delete': + case 'topic_view': + if (!$topic_info = $this->get_topic_data($this->topic_id, 'm_', TRUE)) + { + $template->assign_var('MESSAGE', $user->lang['TOPIC_NOT_EXIST']); + + $mode = ($this->forum_id) ? 'forum_view' : 'front'; + $this->main($mode); + } + + // Whatever mode was selected, the submode is "topic_view" + $this->mode = 'topic_view'; + + // Set up some vars + $icon_id = request_var('icon', 0); + $subject = request_var('subject', ''); $topics_per_page = ($forum_info['forum_topics_per_page']) ? $forum_info['forum_topics_per_page'] : $config['topics_per_page']; + // Jumpbox, sort selects and that kind of things + $this->mcp_jumpbox($this->url . '&mode=forum_view', 'm_', $this->forum_id); $this->mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $topic_info['forum_id'], $this->topic_id); $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total; @@ -235,14 +797,14 @@ class mcp_main extends mcp { $total = $topic_info['topic_replies'] + 1; } - $posts_per_page = (isset($_REQUEST['posts_per_page'])) ? max(0, intval($_REQUEST['posts_per_page'])) : $config['posts_per_page']; + $posts_per_page = max(0, request_var('posts_per_page', intval($config['posts_per_page']))); $sql = 'SELECT u.username, u.user_colour, p.* FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u WHERE p.topic_id = {$this->topic_id} AND p.poster_id = u.user_id ORDER BY $sort_order_sql"; - $result = $db->sql_query_limit($sql, $posts_per_page, $start); + $result = $db->sql_query_limit($sql, $posts_per_page, $this->start); $rowset = array(); while ($row = $db->sql_fetchrow($result)) @@ -253,14 +815,14 @@ class mcp_main extends mcp if ($bbcode_bitfield) { - include($phpbb_root_path . 'includes/bbcode.' . $phpEx); + include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx); $bbcode = new bbcode($bbcode_bitfield); } foreach ($rowset as $i => $row) { $has_unapproved_posts = FALSE; - $poster = (!empty($row['username'])) ? $row['username'] : ((!$row['post_username']) ? $user->lang['GUEST'] : $row['post_username']); + $poster = ($row['poster_id'] != ANONYMOUS) ? $row['username'] : ((!$row['post_username']) ? $user->lang['GUEST'] : $row['post_username']); $poster = ($row['user_colour']) ? '<span style="color:#' . $row['user_colour'] . '">' . $poster . '</span>' : $poster; $message = $row['post_text']; @@ -300,7 +862,6 @@ class mcp_main extends mcp 'POST_ICON_IMG' => ($row['post_time'] > $user->data['user_lastvisit'] && $user->data['user_id'] != ANONYMOUS) ? $user->img('icon_post_new', $user->lang['NEW_POST']) : $user->img('icon_post', $user->lang['POST']), 'S_CHECKBOX' => $s_checkbox, - 'S_DISPLAY_MODES' => ($i % 10 == 0) ? TRUE : FALSE, 'S_ROW_COUNT' => $i, 'S_POST_REPORTED' => ($row['post_reported']) ? TRUE : FALSE, 'S_POST_UNAPPROVED' => ($row['post_approved']) ? FALSE : TRUE, @@ -330,7 +891,9 @@ class mcp_main extends mcp 'ICON_ID' => $id, 'ICON_IMG' => $config['icons_path'] . '/' . $data['img'], 'ICON_WIDTH' => $data['width'], - 'ICON_HEIGHT' => $data['height'] + 'ICON_HEIGHT' => $data['height'], + + 'S_CHECKED' => ($id == $icon_id) ? TRUE : FALSE )); } } @@ -351,7 +914,7 @@ class mcp_main extends mcp 'U_VIEW_TOPIC' => "viewtopic.$phpEx$SID&f=" . $topic_info['forum_id'] . '&t=' . $topic_info['topic_id'], 'TO_TOPIC_ID' => ($this->to_topic_id) ? $this->to_topic_id : '', - 'TO_TOPIC_INFO' => ($this->to_topic_id) ? sprintf($user->lang['YOU_SELECTED_TOPIC'], $this->to_topic_id, '<a href="viewtopic.' . $phpEx . $SID . '&f=' . $to_topic_info['forum_id'] . '&t=' . $this->to_topic_id . '" target="_new">' . $to_topic_info['topic_title'] . '</a>') : '', + 'TO_TOPIC_INFO' => ($this->to_topic_id) ? sprintf($user->lang['YOU_SELECTED_TOPIC'], $this->to_topic_id, '<a href="viewtopic.' . $phpEx . $SID . '&f=' . $to_topic_info['forum_id'] . '&t=' . $this->to_topic_id . '" target="_new">' . $to_topic_info['topic_title'] . '</a>') : '', 'SPLIT_SUBJECT' => $subject, 'POSTS_PER_PAGE' => $posts_per_page, @@ -360,188 +923,593 @@ class mcp_main extends mcp 'REPORTED_IMG' => $user->img('icon_reported', 'POST_REPORTED', FALSE, TRUE), 'UNAPPROVED_IMG' => $user->img('icon_unapproved', 'POST_UNAPPROVED', FALSE, TRUE), - 'S_FORM_ACTION' => "mcp.$phpEx$SID&mode=$mode&t=" . $topic_info['topic_id'] . '&start=' . $start, - 'S_FORUM_SELECT' => '<select name="to_forum_id">' . make_forum_select($this->to_forum_id) . '</select>', + 'S_MCP_ACTION' => "mcp.$phpEx$SID&mode=$mode&t=" . $topic_info['topic_id'] . '&start=' . $this->start, + 'S_FORUM_SELECT' => '<select name="to_forum_id">' . (($this->to_forum_id) ? make_forum_select($this->to_forum_id) : make_forum_select($this->forum_id)) . '</select>', 'S_CAN_SPLIT' => ($auth->acl_get('m_split', $topic_info['forum_id'])) ? TRUE : FALSE, 'S_CAN_MERGE' => ($auth->acl_get('m_merge', $topic_info['forum_id'])) ? TRUE : FALSE, 'S_CAN_DELETE' => ($auth->acl_get('m_delete', $topic_info['forum_id'])) ? TRUE : FALSE, 'S_CAN_APPROVE' => ($has_unapproved_posts && $auth->acl_get('m_approve', $topic_info['forum_id'])) ? TRUE : FALSE, + 'S_SHOW_TOPIC_ICONS'=> (!empty($s_topic_icons)) ? TRUE : FALSE, + 'S_TOPIC_ICON' => $icon_id, - 'PAGE_NUMBER' => on_page($total, $posts_per_page, $start), - 'PAGINATION' => (!$posts_per_page) ? '' : generate_pagination("mcp.$phpEx$SID&t=" . $topic_info['topic_id'] . "&mode=$mode&posts_per_page=$posts_per_page&st=$sort_days&sk=$sort_key&sd=$sort_dir", $total, $posts_per_page, $start) + 'PAGE_NUMBER' => on_page($total, $posts_per_page, $this->start), + 'PAGINATION' => (!$posts_per_page) ? '' : generate_pagination("mcp.$phpEx$SID&t=" . $topic_info['topic_id'] . "&mode=$mode&posts_per_page=$posts_per_page&st=$sort_days&sk=$sort_key&sd=$sort_dir", $total, $posts_per_page, $this->start) )); - $this->display('MCP', 'mcp_topic.html'); + $this->display($user->lang['MCP'], 'mcp_topic.html'); break; - default: - $this->menu('MCP_FRONT'); - // ------------- - // Latest 5 unapproved - $forum_list = get_forum_list('m_approve'); + case 'merge_posts': + if (!$this->to_topic_id || !$topic_data = $this->get_topic_data($this->to_topic_id, 'm_merge')) + { + // No destination topic? Make the user select one + $this->main('merge_select'); +// redirect(str_replace('&', '&', $this->url . $this->selected_ids) . '&i=' . $this->id . '&mode=merge_select'); + } - $template->assign_var('S_SHOW_UNAPPROVED', (!empty($forum_list)) ? TRUE : FALSE); - if (!empty($forum_list)) + if (!$post_id_list = $this->get_post_ids('m_merge')) + { + $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']); + $this->main('merge'); + } + + move_posts($post_id_list, $this->to_topic_id); + add_log('mod', $this->to_forum_id, $this->to_topic_id, 'LOG_MERGE', $topic_data['topic_title']); + + // Message and return links + $template->assign_var('MESSAGE', $user->lang['POSTS_MERGED_SUCCESS']); + + // Does the original topic still exist? If yes, link back to it + if ($topic_data = $this->get_topic_data($this->topic_id)) + { + return_link('RETURN_TOPIC', "viewtopic.$phpEx$SID&f={$this->forum_id}&t={$this->topic_id}"); + } + + // Link to the new topic + return_link('RETURN_NEW_TOPIC', "viewtopic.$phpEx$SID&f={$this->to_forum_id}&t={$this->to_topic_id}"); + + // Back to the topics list + $this->main('forum_view'); + break; + + case 'delete_topic': + if ($this->cancel) + { + if (!$this->topic_id && $this->topic_id_list) + { + $this->topic_id = $this->topic_id_list[0]; + } + if ($this->quickmod) + { + redirect("viewtopic.$phpEx$SID?f={$this->forum_id}&t={$this->topic_id}"); + } + else + { + $this->main('forum_view'); + } + } + if (!$topic_id_list = $this->get_topic_ids('m_delete')) + { + $template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']); + $this->main('forum_view'); + } + + if ($this->confirm) { - $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.username, t.topic_id, t.topic_title, t.topic_first_post_id, f.forum_id, f.forum_name - FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u - LEFT JOIN ' . FORUMS_TABLE . ' f ON f.forum_id = p.forum_id - WHERE p.topic_id = t.topic_id - AND p.poster_id = u.user_id - AND p.post_approved = 0 - AND p.forum_id IN (0,' . implode(', ', $forum_list) . ') - ORDER BY p.post_time DESC'; - $result = $db->sql_query_limit($sql, 5); + return_link('RETURN_FORUM', "viewforum.$phpEx$SID&f={$this->forum_id}"); + $template->assign_var('MESSAGE', (count($topic_id_list) == 1) ? $user->lang['TOPIC_DELETED_SUCCESS'] : $user->lang['TOPICS_DELETED_SUCCESS']); + $this->main('forum_view'); + } + else + { + $s_hidden_fields = ''; + foreach ($topic_id_list as $topic_id) + { + $s_hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . $topic_id . '">'; + } + + $template->assign_vars(array( + 'S_CONFIRM_ACTION' => $this->url . '&mode=' . $mode . '&quickmod=' . intval($this->quickmod), + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + + 'CONFIRM_MODE' => $mode, + 'CONFIRM_MESSAGE' => (count($topic_id_list) == 1) ? $user->lang['DELETE_TOPIC_CONFIRM'] : $user->lang['DELETE_TOPICS_CONFIRM'] + )); + + $this->main('forum_view'); + } + break; + + case 'delete_post': + if ($this->cancel) + { + $this->main('forum_view'); + } + if (!$post_id_list = $this->get_post_ids('m_delete')) + { + $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']); + $this->main('topic_view'); + } + + if ($this->confirm) + { + // Count the number of topics that are affected + // I did not use COUNT(DISTINCT ...) because I remember having problems + // with it on older versions of MySQL -- Ashe + + $sql = 'SELECT DISTINCT topic_id + FROM ' . POSTS_TABLE . ' + WHERE post_id IN (' . implode(', ', $post_id_list) . ')'; + + $result = $db->sql_query_limit($sql); + + $topic_id_list = array(); while ($row = $db->sql_fetchrow($result)) { - if ($row['poster_id'] == ANONYMOUS) + $topic_id_list[] = $row['topic_id']; + } + $affected_topics = count($topic_id_list); + $db->sql_freeresult($result); + + // Now delete the posts, topics and forums are automatically resync'ed + delete_posts('post_id', $post_id_list); + + $sql = 'SELECT COUNT(topic_id) AS topics_left + FROM ' . TOPICS_TABLE . ' + WHERE topic_id IN (' . implode(', ', $topic_id_list) . ')'; + $result = $db->sql_query_limit($sql); + + $deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics; + $db->sql_freeresult($result); + + // Return links + if ($affected_topics == 1 && !$deleted_topics) + { + return_link('RETURN_TOPIC', "viewtopic.$phpEx$SID&f={$this->forum_id}&t={$this->topic_id}"); + } + return_link('RETURN_FORUM', "viewforum.$phpEx$SID&f={$this->forum_id}"); + + if (count($post_id_list) == 1) + { + if ($deleted_topics) + { + // We deleted the only post of a topic, which in turn has + // been removed from the database + $template->assign_var('MESSAGE', $user->lang['TOPIC_DELETED_SUCCESS']); + } + else + { + $template->assign_var('MESSAGE', $user->lang['POST_DELETED_SUCCESS']); + } + } + else + { + if ($deleted_topics) { - $author = ($row['post_username']) ? $row['post_username'] : $user->lang['GUEST']; + // Some of topics disappeared + $template->assign_var('MESSAGE', $user->lang['POSTS_DELETED_SUCCESS'] . '<br /><br />' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING']); } else { - $author = '<a href="memberlist.' . $phpEx . $SID . '&mode=viewprofile&u=' . $row['poster_id'] . '">' . $row['username'] . '</a>'; + $template->assign_var('MESSAGE', $user->lang['POSTS_DELETED_SUCCESS']); } + } - $template->assign_block_vars('unapproved', array( - 'U_POST_DETAILS'=> $this->url . '&mode=post_details', - 'FORUM' => (!empty($row['forum_id'])) ? '<a href="viewforum.' . $phpEx . $SID . '&f=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>' : $user->lang['POST_GLOBAL'], - 'TOPIC' => '<a href="viewtopic.' . $phpEx . $SID . '&f=' . $row['forum_id'] . '&t=' . $row['topic_id'] . '">' . $row['topic_title'] . '</a>', - 'AUTHOR' => $author, - 'SUBJECT' => '<a href="mcp.' . $phpEx . $SID . '&p=' . $row['post_id'] . '&mode=post_details">' . (($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT']) . '</a>', - 'POST_TIME' => $user->format_date($row['post_time']) - )); + // Back to the appropriate mode + $mode = ($affected_topics == 1 && !$deleted_topics) ? 'topic_view' : 'forum_view'; + $this->main($mode); + } + else + { + $s_hidden_fields = ''; + foreach ($post_id_list as $post_id) + { + $s_hidden_fields .= '<input type="hidden" name="post_id_list[]" value="' . $post_id . '">'; } - $sql = 'SELECT COUNT(post_id) AS total - FROM ' . POSTS_TABLE . ' - WHERE post_approved = 0 - AND forum_id IN (0, ' . implode(', ', $forum_list) . ')'; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); + $template->assign_vars(array( + 'S_CONFIRM_ACTION' => $this->url . '&mode=' . $mode, + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + + 'CONFIRM_MODE' => $mode, + 'CONFIRM_MESSAGE' => (count($post_id_list) == 1) ? $user->lang['DELETE_POST_CONFIRM'] : $user->lang['DELETE_POSTS_CONFIRM'] + )); + + $this->main('topic_view'); + } + break; + + case 'split_all': + case 'split_beyond': + if (!$post_id_list = $this->get_post_ids('m_split')) + { + // No posts? back to the topic + $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']); + $this->main('split'); + } + + $post_id = $post_id_list[0]; + if (!$post_info = $this->get_post_data($post_id)) + { + // No posts? back to the topic + $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']); + $this->main('split'); + } - if ($row['total'] == 0) + if (!$subject = request_var('subject', '')) + { + $template->assign_var('MESSAGE', $user->lang['EMPTY_SUBJECT']); + $this->main('split'); + } + if ($this->to_forum_id <= 0) + { + $template->assign_var('MESSAGE', $user->lang['NO_DESTINATION_FORUM']); + $this->main('split'); + } + if (!$forum_info = $this->get_forum_data($this->to_forum_id, 'm_split', TRUE)) + { + $template->assign_var('MESSAGE', $user->lang['NOT_MODERATOR']); + $this->main('split'); + } + if ($forum_info['forum_type'] != FORUM_POST) + { + $template->assign_var('MESSAGE', $user->lang['FORUM_NOT_POSTABLE']); + $this->main('split'); + } + + if ($mode == 'split_beyond') + { + $this->mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $this->forum_id, $this->topic_id); + $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : ''; + + if ($sort_order_sql{0} == 'u') { - $template->assign_vars(array( - 'L_UNAPPROVED_TOTAL' => $user->lang['UNAPPROVED_POSTS_ZERO_TOTAL'], - 'S_HAS_UNAPPROVED_POSTS' => FALSE - )); + $sql = 'SELECT p.post_id + FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u + WHERE p.topic_id = {$this->topic_id} + AND p.poster_id = u.user_id + $limit_time_sql + ORDER BY $sort_order_sql"; } - elseif ($row['total'] == 1) + else { - $template->assign_vars(array( - 'L_UNAPPROVED_TOTAL' => $user->lang['UNAPPROVED_POST_TOTAL'], - 'S_HAS_UNAPPROVED_POSTS' => TRUE - )); + $sql = 'SELECT p.post_id + FROM ' . POSTS_TABLE . " p + WHERE p.topic_id = {$this->topic_id} + $limit_time_sql + ORDER BY $sort_order_sql"; } - else + $result = $db->sql_query_limit($sql, 0, $this->start); + + $store = FALSE; + $post_id_list = array(); + while ($row = $db->sql_fetchrow($result)) { - $template->assign_vars(array( - 'L_UNAPPROVED_TOTAL' => sprintf($user->lang['UNAPPROVED_POSTS_TOTAL'], $row['total']), - 'S_HAS_UNAPPROVED_POSTS' => TRUE - )); + // TODO: see unapproved items? perform any action? + if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id'])) + { +// continue; + } + + // Start to store post_ids as soon as we see the first post that was selected + if ($row['post_id'] == $post_id) + { + $store = TRUE; + } + if ($store) + { + $post_id_list[] = $row['post_id']; + } } } - // ------------- - // ------------- - // Latest 5 reported - $forum_list = get_forum_list('m_'); - - $template->assign_var('S_SHOW_REPORTS', (!empty($forum_list)) ? TRUE : FALSE); - if (!empty($forum_list)) + if (!count($post_id_list)) { - $sql = 'SELECT r.*, p.post_id, p.post_subject, u.username, t.topic_id, t.topic_title, f.forum_id, f.forum_name - FROM ' . REPORTS_TABLE . ' r, ' . REASONS_TABLE . ' rr,' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u - LEFT JOIN ' . FORUMS_TABLE . ' f ON f.forum_id = p.forum_id - WHERE r.post_id = p.post_id - AND r.reason_id = rr.reason_id - AND p.topic_id = t.topic_id - AND r.user_id = u.user_id - AND p.forum_id IN (0, ' . implode(', ', $forum_list) . ') - ORDER BY p.post_time DESC'; - $result = $db->sql_query_limit($sql, 5); + $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']); + $this->main('split'); + } - while ($row = $db->sql_fetchrow($result)) - { - $template->assign_block_vars('report', array( - 'U_POST_DETAILS' => $this->url . '&mode=post_details', - 'FORUM' => (!empty($row['forum_id'])) ? '<a href="viewforum.' . $phpEx . $SID . '&f=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>' : $user->lang['POST_GLOBAL'], - 'TOPIC' => '<a href="viewtopic.' . $phpEx . $SID . '&f=' . $row['forum_id'] . '&t=' . $row['topic_id'] . '">' . $row['topic_title'] . '</a>', - 'REPORTER' => ($row['user_id'] == ANONYMOUS) ? $user->lang['GUEST'] : '<a href="memberlist.' . $phpEx . $SID . '&mode=viewprofile&u=' . $row['user_id'] . '">' . $row['username'] . '</a>', - 'SUBJECT' => '<a href="mcp.' . $phpEx . $SID . '&p=' . $row['post_id'] . '&mode=post_details">' . (($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT']) . '</a>', - 'REPORT_TIME' => $user->format_date($row['report_time']) - )); - } + $icon_id = request_var('icon', 0); + $sql = 'INSERT INTO ' . TOPICS_TABLE . " (forum_id, topic_title, icon_id, topic_approved) + VALUES ({$this->to_forum_id}, '" . $db->sql_escape($subject) . "', $icon_id, 1)"; + $db->sql_query($sql); - $sql = 'SELECT COUNT(r.report_id) AS total - FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p - WHERE r.post_id = p.post_id - AND p.forum_id IN (0, ' . implode(', ', $forum_list) . ')'; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); + $to_topic_id = $db->sql_nextid(); + move_posts($post_id_list, $to_topic_id); + + // Link back to both topics + return_link('RETURN_TOPIC', "viewtopic.$phpEx$SID&f=" . $post_info['forum_id'] . '&t=' . $post_info['topic_id']); + return_link('RETURN_NEW_TOPIC', "viewtopic.$phpEx$SID&f={$this->to_forum_id}&t=$to_topic_id"); + + $template->assign_var('MESSAGE', $user->lang['TOPIC_SPLIT_SUCCESS']); + $this->main('forum_view'); + break; + + case 'modoptions': + if ($this->forum_id && !$auth->acl_get('m_', $this->forum_id)) + { + trigger_error('NOT_MODERATOR'); + } + + switch ($this->action) + { + case 'unlock_post': + case 'lock_post': + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET post_edit_locked = ' . (($this->action == 'lock_post') ? '1' : '0') . ' + WHERE post_id = ' . $this->post_id; + $db->sql_query($sql); + + $msg = ($this->action == 'lock_post') ? $user->lang['POST_LOCKED_SUCCESS'] : $user->lang['POST_UNLOCKED_SUCCESS']; + $template->assign_var('MESSAGE', $msg); + + add_log('mod', $post_info['forum_id'], $post_info['topic_id'], 'LOG_' . strtoupper($this->action), $post_info['post_subject']); + $this->main('post_details'); + break; + + case 'chgposter': + $post_info = $this->get_post_data($this->post_id); + $user_id = request_var('u', 0); + + if (!empty($post_info) && $user_id) + { + $sql = 'UPDATE ' . POSTS_TABLE . " + SET poster_id = $user_id + WHERE post_id = {$this->post_id}"; + $db->sql_query($sql); + + if ($post_info['topic_last_post_id'] == $post_info['post_id'] || $post_info['forum_last_post_id'] == $post_info['post_id']) + { + sync('topic', 'topic_id', $post_info['topic_id'], FALSE, FALSE); + sync('forum', 'forum_id', $post_info['forum_id'], FALSE, FALSE); + } + } + + $this->main('post_details'); + break; + + case 'chgposter_search': + $post_info = $this->get_post_data($this->post_id); + $username = request_var('username', ''); + + if (!empty($post_info) && $username) + { + $users_ary = array(); + + if (strpos($username, '*') === FALSE) + { + $username = "*$username*"; + } + $username = str_replace('*', '%', str_replace('%', '\%', $username)); + + $sql = 'SELECT user_id, username + FROM ' . USERS_TABLE . " + WHERE username LIKE '" . $db->sql_escape($username) . "' + AND user_type = " . USER_NORMAL . ' + AND user_id <> ' . $post_info['user_id']; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $users_ary[strtolower($row['username'])] = $row; + } + + $user_select = ''; + ksort($users_ary); + foreach ($users_ary as $row) + { + $user_select .= '<option value="' . $row['user_id'] . '">' . $row['username'] . "</option>\n"; + } + } + + if (!$user_select) + { + $template->assign_var('MESSAGE', $user->lang['NO_MATCHES_FOUND']); + } - if ($row['total'] == 0) - { $template->assign_vars(array( - 'L_REPORTS_TOTAL' => $user->lang['REPORTS_ZERO_TOTAL'], - 'S_HAS_REPORTS' => FALSE + 'S_USER_SELECT' => $user_select, + 'SEARCH_USERNAME' => request_var('username', '') )); - } - elseif ($row['total'] == 1) + + $this->main('post_details'); + break; + + case 'unrate': + $post_info = $this->get_post_data($this->post_id, 'm_unrate'); + + if (!empty($post_info)) + { + $sql = 'DELETE FROM ' . RATINGS_TABLE . ' + WHERE post_id = ' . $this->post_id; + $db->sql_query($sql); + + add_log('mod', $post_info['forum_id'], $post_info['topic_id'], 'LOG_UNRATE', $post_info['post_subject']); + + $template->assign_var('MESSAGE', $user->lang['POST_UNRATED_SUCCESS']); + + // TODO: recompute user's rating or something? + } + else + { + $template->assign_var('MESSAGE', $user->lang['NOT_MODERATOR']); + } + + $this->main('post_details'); + } + + trigger_error("What the hell is happening here? (action: '$this->action')"); + break; + + case 'post_details': + + // Get post data + if (!$post_info = $this->get_post_data($this->post_id)) + { + trigger_error($user->lang['POST_NOT_EXIST']); + } + + // Set some vars + $users_ary = array(); + $poster = ($post_info['user_colour']) ? '<span style="color:#' . $post_info['user_colour'] . '">' . $post_info['username'] . '</span>' : $post_info['username']; + + // Process message, leave it uncensored + $message = $post_info['post_text']; + if ($post_info['bbcode_bitfield']) + { + include($phpbb_root_path . 'includes/bbcode.'.$phpEx); + $bbcode = new bbcode($post_info['bbcode_bitfield']); + $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']); + } + $message = (empty($config['allow_smilies']) || !$user->optionget('viewsmilies')) ? preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILE_PATH\}\/.*? \/><!\-\- s\1 \-\->#', '\1', $message) : str_replace('<img src="{SMILE_PATH}', '<img src="' . $config['smilies_path'], $message); + + $template->assign_vars(array( + 'S_MCP_ACTION' => $this->url . '&mode=modoptions', + 'S_CHGPOSTER_ACTION' => $this->url . '&mode=modoptions', + 'S_APPROVE_ACTION' => $this->url . '&i=queue&mode=approve&quickmod=' . intval($this->quickmod), + + 'S_CAN_VIEWIP' => $auth->acl_get('m_ip', $post_info['forum_id']), + 'S_CAN_CHGPOSTER' => $auth->acl_get('m_', $post_info['forum_id']), + 'S_CAN_LOCK_POST' => $auth->acl_get('m_', $post_info['forum_id']), + 'S_CAN_UNRATE' => $auth->acl_get('m_unrate', $post_info['forum_id']), + + 'S_POST_REPORTED' => $post_info['post_reported'], + 'S_POST_UNAPPROVED' => !$post_info['post_approved'], + 'S_POST_LOCKED' => $post_info['post_edit_locked'], + 'S_USER_NOTES' => ($post_info['user_notes']) ? TRUE : FALSE, + 'S_USER_WARNINGS' => ($post_info['user_warnings']) ? TRUE : FALSE, + 'S_QUICKMOD' => $this->quickmod, + + 'U_PROFILE' => "memberlist.$phpEx$SID&mode=viewprofile&u=" . $row['user_id'], + 'U_MCP_USERNOTES' => $this->url . '&i=notes&mode=user_notes', + 'U_MCP_WARNINGS' => $this->url . '&i=warnings&mode=view_user&u=' . $post_info['user_id'], + + 'RETURN_TOPIC' => sprintf($user->lang['RETURN_TOPIC'], "<a href=\"viewtopic.$phpEx$SID&p={$this->post_id}#{$this->post_id}\">", '</a>'), + 'RETURN_FORUM' => sprintf($user->lang['RETURN_FORUM'], "<a href=\"viewforum.$phpEx$SID&f={$this->forum_id}&start={$this->start}\">", '</a>'), + 'REPORTED_IMG' => $user->img('icon_reported', $user->lang['POST_REPORTED']), + 'UNAPPROVED_IMG' => $user->img('icon_unapproved', $user->lang['POST_UNAPPROVED']), + + 'POSTER_NAME' => $poster, + 'POST_PREVIEW' => $message, + 'POST_SUBJECT' => $post_info['post_subject'], + 'POST_DATE' => $user->format_date($post_info['post_time']), + 'POST_IP' => $post_info['poster_ip'] . ' (' . @gethostbyaddr($post_info['poster_ip']) . ')' + )); + + // -------- + // IP tools + if ($auth->acl_get('m_ip', $post_info['forum_id'])) + { + $rdns_ip_num = request_var('rdns', ''); + + if ($rdns_ip_num != 'all') { $template->assign_vars(array( - 'L_REPORTS_TOTAL' => $user->lang['REPORT_TOTAL'], - 'S_HAS_REPORTS' => TRUE + 'U_LOOKUP_ALL' => $this->url . '&i=main&mode=post_details&rdns=all' )); } - else + + // Get other users who've posted under this IP + $sql = "SELECT u.user_id, u.username, COUNT(*) as postings + FROM " . USERS_TABLE ." u, " . POSTS_TABLE . " p + WHERE p.poster_id = u.user_id + AND p.poster_ip = '" . $post_info['poster_ip'] . "' + AND p.poster_id <> " . $post_info['user_id'] . ' + GROUP BY u.user_id + ORDER BY postings DESC'; + $result = $db->sql_query($sql); + + $i = 0; + while ($row = $db->sql_fetchrow($result)) { - $template->assign_vars(array( - 'L_REPORTS_TOTAL' => sprintf($user->lang['REPORTS_TOTAL'], $row['total']), - 'S_HAS_REPORTS' => TRUE + // Fill the user select list with users who have posted + // under this IP + if ($row['user_id'] != $post_info['poster_id']) + { + $users_ary[strtolower($row['username'])] = $row; + } + + $template->assign_block_vars('userrow', array( + 'S_ROW_COUNT' => $i++, + + 'USERNAME' => ($row['user_id'] == ANONYMOUS) ? $user->lang['GUEST'] : $row['username'], + 'POSTS' => $row['postings'] . ' ' . (($row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS']), + + 'U_PROFILE' => ($row['user_id'] == ANONYMOUS) ? '' : "memberlist.$phpEx$SID&mode=viewprofile&u=" . $row['user_id'], + 'U_SEARCHPOSTS' => "search.$phpEx$SID&search_author=" . urlencode($row['username']) . "&showresults=topics" )); } - } - // ------------- + $db->sql_freeresult($result); - // ------------- - // Latest 5 logs - $forum_list = get_forum_list(array('m_', 'a_general')); + // Get other IP's this user has posted under + $sql = 'SELECT poster_ip, COUNT(*) AS postings + FROM ' . POSTS_TABLE . ' + WHERE poster_id = ' . $post_info['poster_id'] . ' + GROUP BY poster_ip + ORDER BY postings DESC'; + $result = $db->sql_query($sql); - if (!empty($forum_list)) - { - // Add forum_id 0 for global announcements - $forum_list[] = 0; + $i = 0; + while ($row = $db->sql_fetchrow($result)) + { + $hostname = ($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? @gethostbyaddr($row['poster_ip']) : ''; - $log_count = 0; - $log = array(); - view_log('mod', $log, $log_count, 5, 0, $forum_list); + $template->assign_block_vars('iprow', array( + 'S_ROW_COUNT' => $i++, + 'IP' => $row['poster_ip'], + 'HOSTNAME' => $hostname, + 'POSTS' => $row['postings'] . ' ' . (($row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS']), - foreach ($log as $row) - { - $template->assign_block_vars('log', array( - 'USERNAME' => $row['username'], - 'IP' => $row['ip'], - 'TIME' => $user->format_date($row['time']), - 'ACTION' => $row['action'], - 'U_VIEWTOPIC' => $row['viewtopic'], - 'U_VIEWLOGS' => $row['viewlogs'] + 'U_LOOKUP_IP' => ($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? '' : $this->url . '&mode=post_details&rdns=' . $row['poster_ip'] . '#ip', + 'U_WHOIS' => $this->url . '&i=iptool&mode=whois&ip=' . $row['poster_ip'] )); } + $db->sql_freeresult($result); + + // If we were not searching for a specific username fill + // the user_select box with users who have posted under + // the same IP + if ($this->action != 'chgposter_search') + { + $user_select = ''; + ksort($users_ary); + foreach ($users_ary as $row) + { + $user_select .= '<option value="' . $row['user_id'] . '">' . $row['username'] . "</option>\n"; + } + $template->assign_var('S_USER_SELECT', $user_select); + } } - $template->assign_vars(array( - 'S_SHOW_LOGS' => (!empty($forum_list)) ? TRUE : FALSE, - 'S_HAS_LOGS' => (!empty($log)) ? TRUE : FALSE - )); - // ------------- + // -------- - $template->assign_var('S_MCP_ACTION', $this->url); - $this->mcp_jumpbox($this->url . '&mode=forum_view', 'm_', $this->forum_id); - $this->display('MCP', 'mcp_front.html'); + $this->display($user->lang['MCP'], 'mcp_post.html'); + break; + + default: + trigger_error("Unkwnown mode: $mode"); } } + + function install() + { + } + + function uninstall() + { + } + + function module() + { + $details = array( + 'name' => 'MCP - Main', + 'description' => 'Front end for Moderator Control Panel', + 'filename' => 'main', + 'version' => '0.1.0', + 'phpbbversion' => '2.2.0' + ); + return $details; + } } ?>
\ No newline at end of file |