aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2004-07-08 22:57:05 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2004-07-08 22:57:05 +0000
commit754b1c91f4e844ddb76d8f256970eaa7007344cc (patch)
treefa2263c23754fe7c570f310658dcd2369751da5c /phpBB/includes
parent05f1315ebb96b46ea384df73d387aeb05602d2b5 (diff)
downloadforums-754b1c91f4e844ddb76d8f256970eaa7007344cc.tar
forums-754b1c91f4e844ddb76d8f256970eaa7007344cc.tar.gz
forums-754b1c91f4e844ddb76d8f256970eaa7007344cc.tar.bz2
forums-754b1c91f4e844ddb76d8f256970eaa7007344cc.tar.xz
forums-754b1c91f4e844ddb76d8f256970eaa7007344cc.zip
nooooo.... the mcp is gone. Yes, we now rely on the good will of our users, no moderation anymore.
buhahaha buhahaharrrr harrr git-svn-id: file:///svn/phpbb/trunk@4921 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/mcp/mcp_main.php2208
-rw-r--r--phpBB/includes/mcp/mcp_queue.php300
2 files changed, 854 insertions, 1654 deletions
diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php
index f1f20a9006..f5ec4d703b 100644
--- a/phpBB/includes/mcp/mcp_main.php
+++ b/phpBB/includes/mcp/mcp_main.php
@@ -11,1499 +11,999 @@
//
// -------------------------------------------------------------
-class mcp_main extends mcp
+class mcp_main extends module
{
- function init()
- {
- // Validate input
- $this->mcp_init();
-
- if (!$this->post_id)
- {
- unset($this->modules[$this->id]['subs']['post_details']);
- }
- if (!$this->topic_id)
- {
- unset($this->modules[$this->id]['subs']['topic_view']);
- }
- }
- function main($mode)
+ function mcp_main($id, $mode, $url)
{
global $auth, $db, $user, $template;
global $config, $phpbb_root_path, $phpEx, $SID;
+
+ $action = request_var('action', '');
+ $quickmod = request_var('quickmod', '');
- $this->mode = $mode;
+ if (is_array($action))
+ {
+ list($action, ) = each($action);
+ }
switch ($mode)
{
- case 'resync':
- if (!$topic_id_list = $this->get_topic_ids('m_'))
+ case 'lock':
+ case 'unlock':
+ $topic_ids = get_array((!$quickmod) ? 'topic_id_list' : 't', 0);
+
+ if (!$topic_ids)
{
- $template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']);
- $this->main('forum_view');
+ trigger_error('NO_TOPIC_SELECTED');
}
- // 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);
-
+ lock_unlock($mode, $topic_ids);
+ break;
- $sql = 'SELECT topic_id, forum_id, topic_title
- FROM ' . TOPICS_TABLE . '
- WHERE topic_id IN (' . implode(', ', $topic_id_list) . ')';
- $result = $db->sql_query($sql);
+ case 'lock_post':
+ case 'unlock_post':
- // Log this action
- while ($row = $db->sql_fetchrow($result))
+ $post_ids = get_array((!$quickmod) ? 'post_id_list' : 'p', 0);
+
+ if (!$post_ids)
{
- add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_TOPIC_RESYNC', $row['topic_title']);
+ trigger_error('NO_POST_SELECTED');
}
- $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;
+ lock_unlock($mode, $post_ids);
+ break;
- case 'lock':
- case 'unlock':
- if (!$topic_id_list = $this->get_topic_ids('m_lock'))
+ case 'make_announce':
+ case 'make_sticky':
+ case 'make_global':
+ case 'make_normal':
+
+ $topic_ids = get_array((!$quickmod) ? 'topic_id_list' : 't', 0);
+
+ if (!$topic_ids)
{
- $template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']);
- $this->main('forum_view');
+ trigger_error('NO_TOPIC_SELECTED');
}
- if (count($topic_id_list) == 1)
+ change_topic_type($mode, $topic_ids);
+
+ break;
+
+ case 'move':
+ $user->add_lang('viewtopic');
+
+ $topic_ids = get_array((!$quickmod) ? 'topic_id_list' : 't', 0);
+
+ if (!$topic_ids)
{
- $message = ($mode == 'lock') ? $user->lang['TOPIC_LOCKED_SUCCESS'] : $user->lang['TOPIC_UNLOCKED_SUCCESS'];
+ trigger_error('NO_TOPIC_SELECTED');
}
- else
+
+ mcp_move_topic($topic_ids);
+
+ break;
+
+ case 'delete_topic':
+ $user->add_lang('viewtopic');
+
+ $topic_ids = get_array((!$quickmod) ? 'topic_id_list' : 't', 0);
+
+ if (!$topic_ids)
{
- $message = ($mode == 'lock') ? $user->lang['TOPICS_LOCKED_SUCCESS'] : $user->lang['TOPICS_UNLOCKED_SUCCESS'];
+ trigger_error('NO_TOPIC_SELECTED');
}
- $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);
+ mcp_delete_topic($topic_ids);
+ break;
+
+ case 'delete_post':
+ $user->add_lang('posting');
- $topic_data = $this->get_topic_data($topic_id_list);
- foreach ($topic_data as $topic_id => $row)
+ $post_ids = get_array((!$quickmod) ? 'post_id_list' : 'p', 0);
+
+ if (!$post_ids)
{
- add_log('mod', $this->forum_id, $topic_id, 'LOG_' . strtoupper($mode), $row['topic_title']);
+ trigger_error('NO_TOPIC_SELECTED');
}
- // Where are we going to be redirected?
- $return_topic = "viewtopic.$phpEx$SID&amp;f={$this->forum_id}&amp;t={$this->topic_id}&amp;start={$this->start}";
- $return_forum = "viewforum.$phpEx$SID&amp;f={$this->forum_id}";
+ mcp_delete_post($post_ids);
+ break;
- if ($this->quickmod)
- {
- meta_refresh(3, $return_topic);
+ case 'front':
+ include($phpbb_root_path . 'includes/mcp/mcp_front.' . $phpEx);
- $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>');
+ mcp_front_view($id, $mode, $action, $url);
- trigger_error($message);
- }
- else
- {
- return_link('RETURN_TOPIC', $return_topic);
- return_link('RETURN_FORUM', $return_forum);
+ $this->display($user->lang['MCP'], 'mcp_front.html');
+ break;
- $template->assign_var('MESSAGE', $message);
- $this->main('forum_view');
- }
- break;
+ case 'forum_view':
+ include($phpbb_root_path . 'includes/mcp/mcp_forum.' . $phpEx);
+
+ $user->add_lang('viewforum');
- case 'front':
- // -------------
- // Latest 5 unapproved
- $forum_list = get_forum_list('m_approve');
- $post_list = array();
+ $forum_id = request_var('f', 0);
- $template->assign_var('S_SHOW_UNAPPROVED', (!empty($forum_list)) ? TRUE : FALSE);
- if (!empty($forum_list))
+ $forum_info = get_forum_data($forum_id, 'm_');
+
+ if (!sizeof($forum_info))
{
- $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 . '&amp;mode=viewprofile&amp;u=' . $row['poster_id'] . '">' . $row['username'] . '</a>';
- }
-
- $template->assign_block_vars('unapproved', array(
- 'U_POST_DETAILS'=> $this->url . '&amp;mode=post_details',
- 'FORUM' => (!empty($row['forum_id'])) ? '<a href="viewforum.' . $phpEx . $SID . '&amp;f=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>' : $user->lang['POST_GLOBAL'],
- 'TOPIC' => '<a href="viewtopic.' . $phpEx . $SID . '&amp;f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id'] . '">' . $row['topic_title'] . '</a>',
- 'AUTHOR' => $author,
- 'SUBJECT' => '<a href="mcp.' . $phpEx . $SID . '&amp;p=' . $row['post_id'] . '&amp;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
- ));
- }
+ $this->mcp_main('mcp', 'front', $url);
+ exit;
}
- // -------------
- // -------------
- // Latest 5 reported
- $forum_list = get_forum_list('m_');
+ $forum_info = $forum_info[$forum_id];
+
+ mcp_forum_view($id, $mode, $action, $url, $forum_info);
- $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 . '&amp;mode=post_details',
- 'FORUM' => (!empty($row['forum_id'])) ? '<a href="viewforum.' . $phpEx . $SID . '&amp;f=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>' : $user->lang['POST_GLOBAL'],
- 'TOPIC' => '<a href="viewtopic.' . $phpEx . $SID . '&amp;f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id'] . '">' . $row['topic_title'] . '</a>',
- 'REPORTER' => ($row['user_id'] == ANONYMOUS) ? $user->lang['GUEST'] : '<a href="memberlist.' . $phpEx . $SID . '&amp;mode=viewprofile&amp;u=' . $row['user_id'] . '">' . $row['username'] . '</a>',
- 'SUBJECT' => '<a href="mcp.' . $phpEx . $SID . '&amp;p=' . $row['post_id'] . '&amp;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
- ));
- }
- }
- // -------------
+ $this->display($user->lang['MCP'], 'mcp_forum.html');
+ break;
- // -------------
- // Latest 5 logs
- $forum_list = get_forum_list(array('m_', 'a_general'));
+ case 'topic_view':
+ include($phpbb_root_path . 'includes/mcp/mcp_topic.' . $phpEx);
+
+ mcp_topic_view($id, $mode, $action, $url);
+
+ $this->display($user->lang['MCP'], 'mcp_topic.html');
+ break;
+
+ case 'post_details':
+ include($phpbb_root_path . 'includes/mcp/mcp_post.' . $phpEx);
+
+ mcp_post_details($id, $mode, $action, $url);
+
+ $this->display($user->lang['MCP'], 'mcp_post.html');
+ break;
- 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 . '&amp;mode=forum_view', 'm_', $this->forum_id);
- $this->display($user->lang['MCP'], 'mcp_front.html');
- break;
+ default:
+ trigger_error("Unknown mode: $mode");
+ }
+ }
- case 'merge_select':
- // Change current mode for the menu
- $this->mode = 'forum_view';
+ function install()
+ {
+ }
- // Fixes a "bug" that makes forum_view use the same ordering as topic_view
- unset($_POST['sk'], $_POST['sd'], $_REQUEST['sk'], $_REQUEST['sd']);
+ function uninstall()
+ {
+ }
- // No break; here
+ 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;
+ }
+}
- case 'forum_view':
- if (!$forum_info = $this->get_forum_data($this->forum_id, 'm_', TRUE))
- {
- $this->main($id, 'front');
- }
+// request_var, the array way
+function get_array($var, $default_value)
+{
+ $ids = request_var($var, $default_value);
+
+ if (!is_array($ids))
+ {
+ if (!$ids)
+ {
+ return $default_value;
+ }
- $this->mcp_jumpbox($this->url . '&amp;mode=' . $mode . (($mode == 'merge_select') ? $this->selected_ids : ''), 'm_', $this->forum_id);
+ $ids = array($ids);
+ }
- $topics_per_page = ($forum_info['forum_topics_per_page']) ? $forum_info['forum_topics_per_page'] : $config['topics_per_page'];
+ $ids = array_unique($ids);
- $this->mcp_sorting('viewforum', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $this->forum_id);
- $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
- $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
+ if (sizeof($ids) == 1 && !$ids[0])
+ {
+ return $default_value;
+ }
- $template->assign_vars(array(
- 'FORUM_NAME' => $forum_info['forum_name'],
+ return $ids;
+}
- 'REPORTED_IMG' => $user->img('icon_reported', 'TOPIC_REPORTED'),
- 'UNAPPROVED_IMG' => $user->img('icon_unapproved', 'TOPIC_UNAPPROVED'),
+//
+// LITTLE HELPER
- '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),
- 'S_CAN_LOCK' => $auth->acl_get('m_lock', $this->forum_id),
- 'S_CAN_SYNC' => $auth->acl_get('m_', $this->forum_id),
+// Build simple hidden fields from array
+function build_hidden_fields($name, $vars)
+{
+ $s_hidden_fields = '';
- 'U_VIEW_FORUM' => "viewforum.$phpEx$SID&amp;f=" . $this->forum_id,
- 'S_MCP_ACTION' => $this->url . "&amp;mode={$mode}&amp;start={$this->start}" . (($mode == 'merge_select') ? $this->selected_ids : ''),
+ foreach ($vars as $key => $value)
+ {
+ $s_hidden_fields .= '<input type="hidden" name="' . $name . '[' . $key . ']" value="' . ((is_string($value)) ? htmlspecialchars($value) : (int) $value) . '" />';
+ }
- 'PAGINATION' => generate_pagination($this->url . "&amp;mode={$mode}&amp;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)
- ));
+ return $s_hidden_fields;
+}
+// Get simple topic data
+function get_topic_data($topic_ids, $acl_list = false)
+{
+ global $auth, $db;
+ $rowset = array();
- $topic_rows = array();
+ if (implode(', ', $topic_ids) == '')
+ {
+ return array();
+ }
-// TODO: no global announcements here
- $sql = 'SELECT t.*
- FROM ' . TOPICS_TABLE . " t
- WHERE t.forum_id = {$this->forum_id}
- " . (($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";
- $result = $db->sql_query($sql);
+ $sql = 'SELECT f.*, t.*
+ FROM ' . TOPICS_TABLE . ' t
+ LEFT JOIN ' . FORUMS_TABLE . ' f ON t.forum_id = f.forum_id
+ WHERE t.topic_id IN (' . implode(', ', $topic_ids) . ')';
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if ($acl_list && !$auth->acl_get($acl_list, $row['forum_id']))
+ {
+ continue;
+ }
- while ($row = $db->sql_fetchrow($result))
- {
- $topic_rows[] = $row;
- }
+ $rowset[$row['topic_id']] = $row;
+ }
- $db->sql_freeresult($result);
+ return $rowset;
+}
- $sql = "SELECT t.*
- FROM " . TOPICS_TABLE . " t
- WHERE t.forum_id = {$this->forum_id}
- " . (($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'], $this->start);
+// Get simple post data
+function get_post_data($post_ids, $acl_list = false)
+{
+ global $db, $auth;
+ $rowset = array();
+
+ $sql = 'SELECT p.*, u.*, t.*, f.*
+ FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u, ' . TOPICS_TABLE . ' t
+ LEFT JOIN ' . FORUMS_TABLE . ' f ON f.forum_id = p.forum_id
+ WHERE p.post_id IN (' . implode(', ', $post_ids) . ')
+ AND u.user_id = p.poster_id
+ AND t.topic_id = p.topic_id';
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if ($acl_list && !$auth->acl_get($acl_list, $row['forum_id']))
+ {
+ continue;
+ }
- while ($row = $db->sql_fetchrow($result))
- {
- $topic_rows[] = $row;
- }
- $db->sql_freeresult($result);
+ if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id']))
+ {
+ // Moderators without the permission to approve post should at least not see them. ;)
+ continue;
+ }
- foreach ($topic_rows as $row)
- {
- $topic_title = '';
-
- if ($auth->acl_get('m_approve', $row['forum_id']))
- {
- $row['topic_replies'] = $row['topic_replies_real'];
- }
-
- if ($row['topic_status'] == ITEM_LOCKED)
- {
- $folder_img = $user->img('folder_locked', 'VIEW_TOPIC_LOCKED');
- }
- else
- {
- if ($row['topic_type'] == POST_ANNOUNCE)
- {
- $folder_img = $user->img('folder_announce', 'VIEW_TOPIC_ANNOUNCEMENT');
- }
- else if ($row['topic_type'] == POST_STICKY)
- {
- $folder_img = $user->img('folder_sticky', 'VIEW_TOPIC_STICKY');
- }
- else
- {
- $folder_img = $user->img('folder', 'NO_NEW_POSTS');
- }
- }
-
- if ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL)
- {
- $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'] . ' ';
- }
- else if ($row['topic_type'] == POST_STICKY)
- {
- $topic_type = $user->lang['VIEW_TOPIC_STICKY'] . ' ';
- }
- else if ($row['topic_status'] == ITEM_MOVED)
- {
- $topic_type = $user->lang['VIEW_TOPIC_MOVED'] . ' ';
- }
- else
- {
- $topic_type = '';
- }
-
- if (intval($row['poll_start']))
- {
- $topic_type .= $user->lang['VIEW_TOPIC_POLL'] . ' ';
- }
-
- $topic_title = censor_text($row['topic_title']);
-
- $template->assign_block_vars('topicrow', array(
- 'U_VIEW_TOPIC' => "mcp.$phpEx$SID&amp;t=" . $row['topic_id'] . '&amp;mode=topic_view',
-
- 'S_SELECT_TOPIC' => ($mode == 'merge_select' && $row['topic_id'] != $this->topic_id) ? TRUE : FALSE,
- 'U_SELECT_TOPIC' => $this->url . '&amp;mode=merge&amp;to_topic_id=' . $row['topic_id'] . $this->selected_ids,
- 'U_MCP_QUEUE' => $this->url . '&amp;i=queue&amp;mode=approve&amp;t=' . $row['topic_id'],
- 'U_MCP_REPORT' => $this->url . '&amp;mode=reports&amp;t=' . $row['topic_id'],
-
- 'ATTACH_ICON_IMG' => ($auth->acl_gets('f_download', 'u_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_attach', sprintf($user->lang['TOTAL_ATTACHMENTS'], $row['topic_attachment'])) : '',
- 'TOPIC_FOLDER_IMG' => $folder_img,
- 'TOPIC_TYPE' => $topic_type,
- 'TOPIC_TITLE' => $topic_title,
- '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($topic_rows);
+ $rowset[$row['post_id']] = $row;
+ }
- $this->display($user->lang['MCP'], 'mcp_forum.html');
+ return $rowset;
+}
+
+function get_forum_data($forum_id, $acl_list = 'f_list')
+{
+ global $auth, $db;
+ $rowset = array();
+
+ $sql = 'SELECT *
+ FROM ' . FORUMS_TABLE . '
+ WHERE forum_id ' . ((is_array($forum_id)) ? 'IN (' . implode(', ', $forum_id) . ')' : "= $forum_id");
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if ($acl_list && !$auth->acl_get($acl_list, $row['forum_id']))
+ {
+ continue;
+ }
+ if ($auth->acl_get('m_approve', $row['forum_id']))
+ {
+ $row['forum_topics'] = $row['forum_topics_real'];
+ }
+
+ $rowset[$row['forum_id']] = $row;
+ }
+
+ return $rowset;
+}
+
+function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql, &$sort_order_sql, &$total, $forum_id = 0, $topic_id = 0, $where_sql = 'WHERE')
+{
+ global $db, $user, $auth, $template;
+
+ $sort_days = request_var('sort_days', 0);
+ $min_time = ($sort_days) ? time() - ($sort_days * 86400) : 0;
+
+ switch ($mode)
+ {
+ case 'viewforum':
+ $type = 'topics';
+ $default_key = 't';
+ $default_dir = 'd';
+ $sql = 'SELECT COUNT(topic_id) AS total
+ FROM ' . TOPICS_TABLE . "
+ $where_sql forum_id = $forum_id
+ AND topic_type NOT IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ")
+ AND topic_last_post_time >= $min_time";
+
+ if (!$auth->acl_get('m_approve', $forum_id))
+ {
+ $sql .= 'AND topic_approved = 1';
+ }
break;
- 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']);
- }
+ case 'viewtopic':
+ $type = 'posts';
+ $default_key = 't';
+ $default_dir = 'a';
+ $sql = 'SELECT COUNT(post_id) AS total
+ FROM ' . POSTS_TABLE . "
+ $where_sql topic_id = $topic_id
+ AND post_time >= $min_time";
+
+ if (!$auth->acl_get('m_approve', $forum_id))
+ {
+ $sql .= 'AND post_approved = 1';
+ }
+ break;
- 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;
- }
+ case 'unapproved_posts':
+ $type = 'posts';
+ $default_key = 't';
+ $default_dir = 'd';
+ $sql = 'SELECT COUNT(post_id) AS total
+ FROM ' . POSTS_TABLE . "
+ $where_sql forum_id IN (" . (($forum_id) ? $forum_id : implode(', ', get_forum_list('m_approve'))) . ')
+ AND post_approved = 0
+ AND post_time >= ' . $min_time;
+ break;
- 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&amp;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');
- }
- else
- {
- // 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&amp;f={$this->forum_id}");
- return_link('RETURN_NEW_FORUM', "viewforum.$phpEx$SID&amp;f={$this->to_forum_id}");
-
- $this->forum_id = $this->to_forum_id;
- $this->main('forum_view');
- }
+ case 'unapproved_topics':
+ $type = 'topics';
+ $default_key = 't';
+ $default_dir = 'd';
+ $sql = 'SELECT COUNT(topic_id) AS total
+ FROM ' . TOPICS_TABLE . "
+ $where_sql forum_id IN (" . (($forum_id) ? $forum_id : implode(', ', get_forum_list('m_approve'))) . ')
+ AND topic_approved = 0
+ AND topic_time >= ' . $min_time;
break;
- case 'fork':
- if (!$topic_id_list = $this->get_topic_ids('m_'))
- {
- $template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']);
- }
+ case 'reports':
+ $type = 'reports';
+ $default_key = 'p';
+ $default_dir = 'd';
+ $limit_time_sql = ($min_time) ? "AND r.report_time >= $min_time" : '';
+
+ if ($topic_id)
+ {
+ $where_sql .= ' p.topic_id = ' . $topic_id;
+ }
+ else if ($forum_id)
+ {
+ $where_sql .= ' p.forum_id = ' . $forum_id;
+ }
+ else
+ {
+ $where_sql .= ' p.forum_id IN (' . implode(', ', get_forum_list('m_')) . ')';
+ }
+ $sql = 'SELECT COUNT(r.report_id) AS total
+ FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . " p
+ $where_sql
+ AND p.post_id = r.post_id
+ $limit_time_sql";
+ break;
- 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;
- }
+ case 'viewlogs':
+ $type = 'logs';
+ $default_key = 't';
+ $default_dir = 'd';
+ $sql = 'SELECT COUNT(log_id) AS total
+ FROM ' . LOG_TABLE . "
+ $where_sql forum_id IN (" . (($forum_id) ? $forum_id : implode(', ', get_forum_list('m_'))) . ')
+ AND log_time >= ' . $min_time . '
+ AND log_type = ' . LOG_MOD;
+ break;
+ }
- 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&amp;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&amp;f={$this->forum_id}");
-
- if ($this->forum_id != $this->to_forum_id)
- {
- return_link('RETURN_NEW_FORUM', "viewforum.$phpEx$SID&amp;f={$this->to_forum_id}");
- }
-
- $this->forum_id = $this->to_forum_id;
- $this->main('forum_view');
- }
+ $sort_key = request_var('sk', $default_key);
+ $sort_dir = request_var('sd', $default_dir);
+ $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
+
+ switch ($type)
+ {
+ case 'topics':
+ $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']);
+ $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'tt' => $user->lang['TOPIC_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
+
+ $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'tt' => 't.topic_time', 'r' => (($auth->acl_get('m_approve', $forum_id)) ? 't.topic_replies_real' : 't.topic_replies'), 's' => 't.topic_title', 'v' => 't.topic_views');
+ $limit_time_sql = ($min_time) ? "AND t.topic_last_post_time >= $min_time" : '';
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']);
+ case 'posts':
+ $limit_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']);
+ $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
+ $sort_by_sql = array('a' => 'u.username', 't' => 'p.post_id', 's' => 'p.post_subject');
+ $limit_time_sql = ($min_time) ? "AND p.post_time >= $min_time" : '';
+ break;
- $mode = ($this->forum_id) ? 'forum_view' : 'front';
- $this->main($mode);
- }
+ case 'reports':
+ $limit_days = array(0 => $user->lang['ALL_REPORTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']);
+ $sort_by_text = array('p' => $user->lang['REPORT_PRIORITY'], 'r' => $user->lang['REPORTER'], 't' => $user->lang['REPORT_TIME']);
+ $sort_by_sql = array('p' => 'rr.reason_priority', 'r' => 'u.username', 't' => 'r.report_time');
+ break;
- // Whatever mode was selected, the submode is "topic_view"
- $this->mode = 'topic_view';
+ case 'logs':
+ $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']);
+ $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
- // 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'];
+ $sort_by_sql = array('u' => 'l.user_id', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
+ $limit_time_sql = ($min_time) ? "AND l.log_time >= $min_time" : '';
+ break;
+ }
- // Jumpbox, sort selects and that kind of things
- $this->mcp_jumpbox($this->url . '&amp;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);
+ $sort_order_sql = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
- $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
- $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
+ $s_limit_days = $s_sort_key = $s_sort_dir = $sort_url = '';
+ gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $sort_url);
- if ($total == -1)
- {
- $total = $topic_info['topic_replies'] + 1;
- }
- $posts_per_page = max(0, request_var('posts_per_page', intval($config['posts_per_page'])));
+ $template->assign_vars(array(
+ 'S_SELECT_SORT_DIR' => $s_sort_dir,
+ 'S_SELECT_SORT_KEY' => $s_sort_key,
+ 'S_SELECT_SORT_DAYS'=> $s_limit_days)
+ );
- $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, $this->start);
+ if (($sort_days && $mode != 'viewlogs') || $mode == 'reports')
+ {
+ $result = $db->sql_query($sql);
+ $total = ($row = $db->sql_fetchrow($result)) ? $row['total'] : 0;
+ }
+ else
+ {
+ $total = -1;
+ }
+}
- $rowset = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $rowset[] = $row;
- $bbcode_bitfield |= $row['bbcode_bitfield'];
- }
+//
+function check_ids(&$ids, $table, $sql_id, $acl_list = false)
+{
+ global $db, $auth;
- if ($bbcode_bitfield)
- {
- include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
- $bbcode = new bbcode($bbcode_bitfield);
- }
+ if (!is_array($ids) || !$ids)
+ {
+ return 0;
+ }
- foreach ($rowset as $i => $row)
- {
- $has_unapproved_posts = FALSE;
- $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'];
- $post_subject = ($row['post_subject'] != '') ? $row['post_subject'] : $topic_info['topic_title'];
-
- // If the board has HTML off but the post has HTML
- // on then we process it, else leave it alone
- if (!$config['allow_html'] && $row['enable_html'])
- {
- $message = preg_replace('#(<)([\/]?.*?)(>)#is', '&lt;\\2&gt;', $message);
- }
-
- if ($row['bbcode_bitfield'])
- {
- $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
- }
-
- $message = smilie_text($message);
-
- $message = nl2br($message);
-
- $checked = (in_array(intval($row['post_id']), $this->post_id_list)) ? 'checked="checked" ' : '';
- $s_checkbox = ($row['post_id'] == $topic_info['topic_first_post_id'] && $mode == 'split') ? '&nbsp;' : '<input type="checkbox" name="post_id_list[]" value="' . $row['post_id'] . '" ' . $checked . '/>';
-
- if (!$row['post_approved'])
- {
- $has_unapproved_posts = TRUE;
- }
-
- $template->assign_block_vars('postrow', array(
- 'POSTER_NAME' => $poster,
- 'POST_DATE' => $user->format_date($row['post_time']),
- 'POST_SUBJECT' => $post_subject,
- 'MESSAGE' => $message,
- 'POST_ID' => $row['post_id'],
-
- '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_ROW_COUNT' => $i,
- 'S_POST_REPORTED' => ($row['post_reported']) ? TRUE : FALSE,
- 'S_POST_UNAPPROVED' => ($row['post_approved']) ? FALSE : TRUE,
-
- 'U_POST_DETAILS' => "mcp.$phpEx$SID&amp;f=" . $row['forum_id'] . '&amp;t=' . $row['topic_id'] . '&amp;p=' . $row['post_id'] . '&amp;mode=post_details',
- 'U_APPROVE' => "mcp.$phpEx$SID&amp;i=queue&amp;mode=approve&amp;p=" . $row['post_id']
- ));
-
- unset($rowset[$i]);
- }
+ // a small logical error, since global announcement are assigned to forum_id == 0
+ // If the first topic id is a global announcement, we can force the forum. Though only global announcements can be
+ // tricked... i really do not know how to prevent this atm.
- // Display topic icons for split topic
- if ($auth->acl_get('m_split', $topic_info['forum_id']))
- {
- $icons = array();
- obtain_icons($icons);
-
- if (count($icons))
- {
- $s_topic_icons = true;
-
- foreach ($icons as $id => $data)
- {
- if ($data['display'])
- {
- $template->assign_block_vars('topic_icon', array(
- 'ICON_ID' => $id,
- 'ICON_IMG' => $config['icons_path'] . '/' . $data['img'],
- 'ICON_WIDTH' => $data['width'],
- 'ICON_HEIGHT' => $data['height'],
-
- 'S_CHECKED' => ($id == $icon_id) ? TRUE : FALSE
- ));
- }
- }
- }
- }
+ // With those two queries we make sure all ids are within one forum...
+ $sql = "SELECT forum_id FROM $table
+ WHERE $sql_id = {$ids[0]}";
+ $result = $db->sql_query($sql);
+ $forum_id = (int) $db->sql_fetchfield('forum_id', 0, $result);
+ $db->sql_freeresult($result);
- // Has the user selected a topic for merge?
- if ($this->to_topic_id)
- {
- if (!$to_topic_info = $this->get_topic_data($this->to_topic_id, 'm_merge', TRUE))
- {
- $this->to_topic_id = 0;
- }
- }
+ if (!$forum_id)
+ {
+ // Global Announcement?
+ $forum_id = request_var('f', 0);
+ }
+
+ if ($acl_list && !$auth->acl_get($acl_list, $forum_id))
+ {
+ trigger_error('NOT_AUTHORIZED');
+ }
- $template->assign_vars(array(
- 'TOPIC_TITLE' => $topic_info['topic_title'],
- 'U_VIEW_TOPIC' => "viewtopic.$phpEx$SID&amp;f=" . $topic_info['forum_id'] . '&amp;t=' . $topic_info['topic_id'],
+ if (!$forum_id)
+ {
+ trigger_error('Missing forum_id, has to be in url if global announcement...');
+ }
- '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 . '&amp;f=' . $to_topic_info['forum_id'] . '&amp;t=' . $this->to_topic_id . '" target="_new">' . $to_topic_info['topic_title'] . '</a>') : '',
+ $sql = "SELECT $sql_id FROM $table
+ WHERE $sql_id IN (" . implode(', ', $ids) . ")
+ AND (forum_id = $forum_id OR forum_id = 0)";
+ $result = $db->sql_query($sql);
- 'SPLIT_SUBJECT' => $subject,
- 'POSTS_PER_PAGE' => $posts_per_page,
- 'MODE' => $mode,
+ $ids = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $ids[] = $row[$sql_id];
+ }
+ $db->sql_freeresult($result);
- 'REPORTED_IMG' => $user->img('icon_reported', 'POST_REPORTED', FALSE, TRUE),
- 'UNAPPROVED_IMG' => $user->img('icon_unapproved', 'POST_UNAPPROVED', FALSE, TRUE),
+ return $forum_id;
+}
- 'S_MCP_ACTION' => "mcp.$phpEx$SID&amp;mode=$mode&amp;t=" . $topic_info['topic_id'] . '&amp;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,
+// LITTLE HELPER
+//
- 'S_SHOW_TOPIC_ICONS'=> (!empty($s_topic_icons)) ? TRUE : FALSE,
- 'S_TOPIC_ICON' => $icon_id,
+// Lock/Unlock Topic/Post
+function lock_unlock($mode, $ids)
+{
+ global $auth, $user, $db, $SID, $phpEx, $phpbb_root_path;
- 'PAGE_NUMBER' => on_page($total, $posts_per_page, $this->start),
- 'PAGINATION' => (!$posts_per_page) ? '' : generate_pagination("mcp.$phpEx$SID&amp;t=" . $topic_info['topic_id'] . "&amp;mode=$mode&amp;posts_per_page=$posts_per_page&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir", $total, $posts_per_page, $this->start)
- ));
+ if ($mode == 'lock' || $mode == 'unlock')
+ {
+ $table = TOPICS_TABLE;
+ $sql_id = 'topic_id';
+ $set_id = 'topic_status';
+ $l_prefix = 'TOPIC';
+ }
+ else
+ {
+ $table = POSTS_TABLE;
+ $sql_id = 'post_id';
+ $set_id = 'post_edit_locked';
+ $l_prefix = 'POST';
+ }
+
+ if (!($forum_id = check_ids($ids, $table, $sql_id, 'm_lock')))
+ {
+ return;
+ }
+
+ $redirect = request_var('redirect', $user->data['session_page']);
- $this->display($user->lang['MCP'], 'mcp_topic.html');
- break;
+ $s_hidden_fields = build_hidden_fields($sql_id . '_list', $ids);
+ $s_hidden_fields .= '<input type="hidden" name="mode" value="' . $mode . '" />';
+ $s_hidden_fields .= '<input type="hidden" name="redirect" value="' . $redirect . '" />';
+ $success_msg = '';
- 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('&amp;', '&', $this->url . $this->selected_ids) . '&i=' . $this->id . '&mode=merge_select');
- }
+ if (confirm_box(true))
+ {
+ $sql = "UPDATE $table
+ SET $set_id = " . (($mode == 'lock' || $mode == 'lock_post') ? ITEM_LOCKED : ITEM_UNLOCKED) . "
+ WHERE $sql_id IN (" . implode(', ', $ids) . ")";
+ $db->sql_query($sql);
- if (!$post_id_list = $this->get_post_ids('m_merge'))
- {
- $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
- $this->main('merge');
- }
+ $data = ($mode == 'lock' || $mode == 'unlock') ? get_topic_data($ids) : get_post_data($ids);
- 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']);
+ foreach ($data as $id => $row)
+ {
+ add_log('mod', $forum_id, $row['topic_id'], 'LOG_' . strtoupper($mode), $row['topic_title']);
+ }
+
+ $success_msg = $l_prefix . ((sizeof($ids) == 1) ? '' : 'S') . '_' . (($mode == 'lock' || $mode == 'lock_post') ? 'LOCKED' : 'UNLOCKED') . '_SUCCESS';
+ }
+ else
+ {
+ confirm_box(false, strtoupper($mode) . '_' . $l_prefix . ((sizeof($ids) == 1) ? '' : 'S'), $s_hidden_fields);
+ }
- // 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&amp;f={$this->forum_id}&amp;t={$this->topic_id}");
- }
+ $redirect = request_var('redirect', "index.$phpEx$SID");
+
+ if (strpos($redirect, '?') === false)
+ {
+ $redirect = substr_replace($redirect, ".$phpEx$SID&", strpos($redirect, '&'), 1);
+ }
+
+ if (!$success_msg)
+ {
+ redirect($redirect);
+ }
+ else
+ {
+ meta_refresh(2, $redirect);
+ trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
+ }
+}
+
+// Change Topic Type
+function change_topic_type($mode, $topic_ids)
+{
+ global $auth, $user, $db, $SID, $phpEx, $phpbb_root_path;
- // Link to the new topic
- return_link('RETURN_NEW_TOPIC', "viewtopic.$phpEx$SID&amp;f={$this->to_forum_id}&amp;t={$this->to_topic_id}");
+ if (!($forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', 'm_')))
+ {
+ return;
+ }
- // Back to the topics list
- $this->main('forum_view');
+ switch ($mode)
+ {
+ case 'make_announce':
+ $new_topic_type = POST_ANNOUNCE;
+ $check_acl = 'f_announce';
+ $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_ANNOUNCEMENT' : 'MCP_MAKE_ANNOUNCEMENTS';
+ break;
+ case 'make_global':
+ $new_topic_type = POST_GLOBAL;
+ $check_acl = 'f_announce';
+ $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_GLOBAL' : 'MCP_MAKE_GLOBALS';
+ break;
+ case 'make_sticky':
+ $new_topic_type = POST_STICKY;
+ $check_acl = 'f_sticky';
+ $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_STICKY' : 'MCP_MAKE_STICKIES';
+ break;
+ default:
+ $new_topic_type = POST_NORMAL;
+ $check_acl = '';
+ $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_NORMAL' : 'MCP_MAKE_NORMALS';
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');
- }
+ $redirect = request_var('redirect', $user->data['session_page']);
- if ($this->confirm)
- {
-// delete_topics('topic_id', $topic_id_list, true);
- return_link('RETURN_FORUM', "viewforum.$phpEx$SID&amp;f={$this->forum_id}");
+ $s_hidden_fields = build_hidden_fields('topic_id_list', $topic_ids);
+ $s_hidden_fields .= '<input type="hidden" name="f" value="' . $forum_id . '" />';
+ $s_hidden_fields .= '<input type="hidden" name="mode" value="' . $mode . '" />';
+ $s_hidden_fields .= '<input type="hidden" name="redirect" value="' . $redirect . '" />';
+ $success_msg = '';
- $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 . '">';
- }
+ if (confirm_box(true))
+ {
+ if ($new_topic_type != POST_GLOBAL)
+ {
+ $sql = 'UPDATE ' . TOPICS_TABLE . "
+ SET topic_type = $new_topic_type
+ WHERE topic_id IN (" . implode(', ', $topic_ids) . ')
+ AND forum_id <> 0';
+ $db->sql_query($sql);
+
+ // Reset forum id if a global topic is within the array
+ if ($forum_id)
+ {
+ $sql = 'UPDATE ' . TOPICS_TABLE . "
+ SET topic_type = $new_topic_type, forum_id = $forum_id
+ WHERE topic_id IN (" . implode(', ', $topic_ids) . ')
+ AND forum_id = 0';
+ $db->sql_query($sql);
+ }
+ }
+ else
+ {
+ $sql = 'UPDATE ' . TOPICS_TABLE . "
+ SET topic_type = $new_topic_type, forum_id = 0
+ WHERE topic_id IN (" . implode(', ', $topic_ids) . ")";
+ $db->sql_query($sql);
+ }
- $template->assign_vars(array(
- 'S_CONFIRM_ACTION' => $this->url . '&amp;mode=' . $mode . '&amp;quickmod=' . intval($this->quickmod),
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_TYPE_CHANGED' : 'TOPICS_TYPE_CHANGED';
- 'CONFIRM_MODE' => $mode,
- 'CONFIRM_MESSAGE' => (count($topic_id_list) == 1) ? $user->lang['DELETE_TOPIC_CONFIRM'] : $user->lang['DELETE_TOPICS_CONFIRM']
- ));
+ $data = get_topic_data($topic_ids);
- $this->main('forum_view');
- }
- break;
+ foreach ($data as $topic_id => $row)
+ {
+ add_log('mod', $forum_id, $topic_id, 'LOG_TOPIC_TYPE_CHANGED', $row['topic_title']);
+ }
+ }
+ else
+ {
+ confirm_box(false, $l_new_type, $s_hidden_fields);
+ }
- 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');
- }
+ $redirect = request_var('redirect', "index.$phpEx$SID");
- 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))
- {
- $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&amp;f={$this->forum_id}&amp;t={$this->topic_id}");
- }
- return_link('RETURN_FORUM', "viewforum.$phpEx$SID&amp;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)
- {
- // Some of topics disappeared
- $template->assign_var('MESSAGE', $user->lang['POSTS_DELETED_SUCCESS'] . '<br /><br />' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING']);
- }
- else
- {
- $template->assign_var('MESSAGE', $user->lang['POSTS_DELETED_SUCCESS']);
- }
- }
-
- // 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 . '">';
- }
+ if (strpos($redirect, '?') === false)
+ {
+ $redirect = substr_replace($redirect, ".$phpEx$SID&", strpos($redirect, '&'), 1);
+ }
- $template->assign_vars(array(
- 'S_CONFIRM_ACTION' => $this->url . '&amp;mode=' . $mode,
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ if (!$success_msg)
+ {
+ redirect($redirect);
+ }
+ else
+ {
+ meta_refresh(2, $redirect);
+ trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
+ }
+}
- 'CONFIRM_MODE' => $mode,
- 'CONFIRM_MESSAGE' => (count($post_id_list) == 1) ? $user->lang['DELETE_POST_CONFIRM'] : $user->lang['DELETE_POSTS_CONFIRM']
- ));
+// Move Topic
+function mcp_move_topic($topic_ids)
+{
+ global $auth, $user, $db, $SID, $phpEx, $phpbb_root_path, $template;
+ global $_POST, $_REQUEST;
- $this->main('topic_view');
- }
- break;
+ if (!($forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', 'm_move')))
+ {
+ return;
+ }
+
+ $to_forum_id = request_var('to_forum_id', 0);
+ $redirect = request_var('redirect', $user->data['session_page']);
+ $additional_msg = $success_msg = '';
- 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');
- }
+ $s_hidden_fields = build_hidden_fields('topic_id_list', $topic_ids);
+ $s_hidden_fields .= '<input type="hidden" name="f" value="' . $forum_id . '" />';
+ $s_hidden_fields .= '<input type="hidden" name="mode" value="move" />';
+ $s_hidden_fields .= '<input type="hidden" name="redirect" value="' . $redirect . '" />';
- $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 ($to_forum_id)
+ {
+ $forum_data = get_forum_data($to_forum_id);
- 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 (!sizeof($forum_data))
+ {
+ $additional_msg = $user->lang['FORUM_NOT_EXIST'];
+ }
+ else
+ {
+ $forum_data = $forum_data[$to_forum_id];
+
+ if ($forum_data['forum_type'] != FORUM_POST)
+ {
+ $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
+ }
+ else if (!$auth->acl_get('f_post', $to_forum_id))
+ {
+ $additional_msg = $user->lang['USER_CANNOT_POST'];
+ }
+ else if ($forum_id == $to_forum_id)
+ {
+ $additional_msg = $user->lang['CANNOT_MOVE_SAME_FORUM'];
+ }
+ }
+ }
- 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')
- {
- $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";
- }
- else
- {
- $sql = 'SELECT p.post_id
- FROM ' . POSTS_TABLE . " p
- WHERE p.topic_id = {$this->topic_id}
- $limit_time_sql
- ORDER BY $sort_order_sql";
- }
- $result = $db->sql_query_limit($sql, 0, $this->start);
-
- $store = FALSE;
- $post_id_list = array();
- while ($row = $db->sql_fetchrow($result))
- {
- // 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'];
- }
- }
- }
+ if (!$to_forum_id || $additional_msg)
+ {
+ unset($_POST['confirm']);
+ }
+
+ if (confirm_box(true))
+ {
+ $topic_data = get_topic_data($topic_ids);
+ $leave_shadow = (isset($_POST['move_leave_shadow'])) ? true : false;
- if (!count($post_id_list))
- {
- $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
- $this->main('split');
- }
+ // Move topics, but do not resync yet
+ move_topics($topic_ids, $to_forum_id, false);
- $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);
+ $forum_ids = array($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', $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 ($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'],
+ 'topic_bumped' => (int) $row['topic_bumped'],
+ 'topic_bumper' => (int) $row['topic_bumper'],
+ '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));
+ $next_id = $db->sql_nextid();
+
+ // Mark Shadow topic read
+ markread('topic', $row['forum_id'], $next_id);
+ }
+ }
+ unset($topic_data);
- $to_topic_id = $db->sql_nextid();
- move_posts($post_id_list, $to_topic_id);
+ // Now sync forums
+ sync('forum', 'forum_id', $forum_ids);
- // Link back to both topics
- return_link('RETURN_TOPIC', "viewtopic.$phpEx$SID&amp;f=" . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']);
- return_link('RETURN_NEW_TOPIC', "viewtopic.$phpEx$SID&amp;f={$this->to_forum_id}&amp;t=$to_topic_id");
+ $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS';
+ }
+ else
+ {
+ $template->assign_vars(array(
+ 'S_FORUM_SELECT' => make_forum_select($to_forum_id, $forum_id, false, true, true),
+ 'S_CAN_LEAVE_SHADOW' => true,
+ 'ADDITIONAL_MSG' => $additional_msg)
+ );
- $template->assign_var('MESSAGE', $user->lang['TOPIC_SPLIT_SUCCESS']);
- $this->main('forum_view');
- break;
+ confirm_box(false, 'MOVE_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
+ }
- case 'modoptions':
- if ($this->forum_id && !$auth->acl_get('m_', $this->forum_id))
- {
- trigger_error('NOT_MODERATOR');
- }
+ $redirect = request_var('redirect', "index.$phpEx$SID");
- 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']);
- }
-
- $template->assign_vars(array(
- 'S_USER_SELECT' => $user_select,
- 'SEARCH_USERNAME' => request_var('username', '')
- ));
-
- $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');
- }
+ if (strpos($redirect, '?') === false)
+ {
+ $redirect = substr_replace($redirect, ".$phpEx$SID&", strpos($redirect, '&'), 1);
+ }
- trigger_error("What the hell is happening here? (action: '$this->action')");
- break;
+ if (!$success_msg)
+ {
+ redirect($redirect);
+ }
+ else
+ {
+ meta_refresh(3, $redirect);
+ trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>') . '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="viewforum.' . $phpEx . $SID . '&amp;f=' . $to_forum_id . '">', '</a>'));
+ }
+}
- case 'post_details':
+// Delete Topics
+function mcp_delete_topic($topic_ids)
+{
+ global $auth, $user, $db, $SID, $phpEx, $phpbb_root_path;
- // Get post data
- if (!$post_info = $this->get_post_data($this->post_id))
- {
- trigger_error($user->lang['POST_NOT_EXIST']);
- }
+ if (!($forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', 'm_delete')))
+ {
+ return;
+ }
- // 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'];
+ $redirect = request_var('redirect', $user->data['session_page']);
- // 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 = smilie_text($message);
-
- $template->assign_vars(array(
- 'S_MCP_ACTION' => $this->url . '&amp;mode=modoptions',
- 'S_CHGPOSTER_ACTION' => $this->url . '&amp;mode=modoptions',
- 'S_APPROVE_ACTION' => $this->url . '&amp;i=queue&amp;mode=approve&amp;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&amp;mode=viewprofile&amp;u=" . $row['user_id'],
- 'U_MCP_USERNOTES' => $this->url . '&amp;i=notes&amp;mode=user_notes',
- 'U_MCP_WARNINGS' => $this->url . '&amp;i=warnings&amp;mode=view_user&u=' . $post_info['user_id'],
-
- 'RETURN_TOPIC' => sprintf($user->lang['RETURN_TOPIC'], "<a href=\"viewtopic.$phpEx$SID&amp;p={$this->post_id}#{$this->post_id}\">", '</a>'),
- 'RETURN_FORUM' => sprintf($user->lang['RETURN_FORUM'], "<a href=\"viewforum.$phpEx$SID&amp;f={$this->forum_id}&amp;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(
- 'U_LOOKUP_ALL' => $this->url . '&i=main&mode=post_details&rdns=all'
- ));
- }
-
- // 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))
- {
- // 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&amp;mode=viewprofile&amp;u=" . $row['user_id'],
- 'U_SEARCHPOSTS' => "search.$phpEx$SID&amp;search_author=" . urlencode($row['username']) . "&amp;showresults=topics"
- ));
- }
- $db->sql_freeresult($result);
-
- // 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);
-
- $i = 0;
- while ($row = $db->sql_fetchrow($result))
- {
- $hostname = ($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? @gethostbyaddr($row['poster_ip']) : '';
-
- $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']),
-
- 'U_LOOKUP_IP' => ($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? '' : $this->url . '&amp;mode=post_details&amp;rdns=' . $row['poster_ip'] . '#ip',
- 'U_WHOIS' => $this->url . '&amp;i=iptool&amp;mode=whois&amp;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);
- }
- }
- // --------
+ $s_hidden_fields = build_hidden_fields('topic_id_list', $topic_ids);
+ $s_hidden_fields .= '<input type="hidden" name="f" value="' . $forum_id . '" />';
+ $s_hidden_fields .= '<input type="hidden" name="mode" value="delete_topic" />';
+ $s_hidden_fields .= '<input type="hidden" name="redirect" value="' . $redirect . '" />';
+ $success_msg = '';
- $this->display($user->lang['MCP'], 'mcp_post.html');
- break;
+ if (confirm_box(true))
+ {
+ $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS';
- default:
- trigger_error("Unkwnown mode: $mode");
+ $data = get_topic_data($topic_ids);
+
+ foreach ($data as $topic_id => $row)
+ {
+ add_log('mod', $forum_id, 0, 'LOG_TOPIC_DELETED', $row['topic_title']);
}
+
+ $return = delete_topics('topic_id', $topic_ids, true);
+
+ // TODO: Adjust total post count...
+ }
+ else
+ {
+ confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields);
}
- function install()
+ $redirect = request_var('redirect', "index.$phpEx$SID");
+
+ if (strpos($redirect, '?') === false)
{
+ $redirect = substr_replace($redirect, ".$phpEx$SID&", strpos($redirect, '&'), 1);
}
- function uninstall()
+ if (!$success_msg)
{
+ redirect($redirect);
}
+ else
+ {
+ meta_refresh(3, "viewforum.$phpEx$SID&amp;f=$forum_id");
+ trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="viewforum.' . $phpEx . $SID . '&amp;f=' . $forum_id . '">', '</a>'));
+ }
+}
- function module()
+// Delete Topics
+function mcp_delete_post($post_ids)
+{
+ global $auth, $user, $db, $SID, $phpEx, $phpbb_root_path;
+
+ if (!($forum_id = check_ids($post_ids, POSTS_TABLE, 'post_id', 'm_delete')))
{
- $details = array(
- 'name' => 'MCP - Main',
- 'description' => 'Front end for Moderator Control Panel',
- 'filename' => 'main',
- 'version' => '0.1.0',
- 'phpbbversion' => '2.2.0'
- );
- return $details;
+ return;
+ }
+
+ $redirect = request_var('redirect', $user->data['session_page']);
+
+ $s_hidden_fields = build_hidden_fields('post_id_list', $post_ids);
+ $s_hidden_fields .= '<input type="hidden" name="f" value="' . $forum_id . '" />';
+ $s_hidden_fields .= '<input type="hidden" name="mode" value="delete_post" />';
+ $s_hidden_fields .= '<input type="hidden" name="redirect" value="' . $redirect . '" />';
+ $success_msg = '';
+
+ if (confirm_box(true))
+ {
+ // 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_ids) . ')';
+ $result = $db->sql_query($sql);
+
+ $topic_id_list = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $topic_id_list[] = $row['topic_id'];
+ }
+ $affected_topics = sizeof($topic_id_list);
+ $db->sql_freeresult($result);
+
+ // Now delete the posts, topics and forums are automatically resync'ed
+ delete_posts('post_id', $post_ids);
+
+ $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, 1);
+
+ $deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics;
+ $db->sql_freeresult($result);
+
+ $topic_id = request_var('t', 0);
+
+ // Return links
+ $return_link = array();
+ if ($affected_topics == 1 && !$deleted_topics && $topic_id)
+ {
+ $return_link[] = sprintf($user->lang['RETURN_TOPIC'], "<a href=\"viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id\">", '</a>');
+ }
+ $return_link[] = sprintf($user->lang['RETURN_FORUM'], "<a href=\"viewforum.$phpEx$SID&amp;f=$forum_id\">", '</a>');
+
+ if (sizeof($post_ids) == 1)
+ {
+ if ($deleted_topics)
+ {
+ // We deleted the only post of a topic, which in turn has
+ // been removed from the database
+ $success_msg = $user->lang['TOPIC_DELETED_SUCCESS'];
+ }
+ else
+ {
+ $success_msg = $user->lang['POST_DELETED_SUCCESS'];
+ }
+ }
+ else
+ {
+ if ($deleted_topics)
+ {
+ // Some of topics disappeared
+ $success_msg = $user->lang['POSTS_DELETED_SUCCESS'] . '<br /><br />' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING'];
+ }
+ else
+ {
+ $success_msg = $user->lang['POSTS_DELETED_SUCCESS'];
+ }
+ }
+ }
+ else
+ {
+ confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields);
+ }
+
+ $redirect = request_var('redirect', "index.$phpEx$SID");
+
+ if (strpos($redirect, '?') === false)
+ {
+ $redirect = substr_replace($redirect, ".$phpEx$SID&", strpos($redirect, '&'), 1);
+ }
+
+ if (!$success_msg)
+ {
+ redirect($redirect);
+ }
+ else
+ {
+ meta_refresh(3, $redirect);
+ trigger_error($success_msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>') . '<br /><br />' . implode('<br /><br />', $return_link));
}
}
+
?> \ No newline at end of file
diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php
index a8a4579ae1..15081be62c 100644
--- a/phpBB/includes/mcp/mcp_queue.php
+++ b/phpBB/includes/mcp/mcp_queue.php
@@ -11,304 +11,4 @@
//
// -------------------------------------------------------------
-/*
-
- TODO
-
-- order items by forum?
-- ability to restrict listing to a certain forum?
-- pagination missing
-
-*/
-
-class mcp_queue extends mcp
-{
- function init()
- {
- global $db;
-
- // Validate input
- $this->mcp_init();
- }
-
- function main($mode)
- {
- global $auth, $db, $user, $template;
- global $config, $phpbb_root_path, $phpEx, $SID;
-
- $this->mode = $mode;
-
- switch ($mode)
- {
- case 'approve':
- //
- // TODO: increment post counts
- // warn users watching forums/topics
- //
-
- // Get topic data
- if ($post_id_list = $this->get_post_ids('m_approve'))
- {
- $post_mode = 'unapproved_posts';
-
- $sql = 'SELECT topic_id
- FROM ' . POSTS_TABLE . '
- WHERE post_id IN (' . implode(', ', $post_id_list) . ')';
- $result = $db->sql_query($sql);
-
- $topic_id_list = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $topic_id_list[] = $row['topic_id'];
-
- // TODO: log posts being approved? that would be a hell lot of logging
- //add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_APPROVE_POST', $row['post_id']);
- }
-
- $msg = (count($post_id_list) == 1) ? $user->lang['POST_APPROVED_SUCCESS'] : $user->lang['POSTS_APPROVED_SUCCESS'];
-
- // Return to topic
- $redirect_url = "viewtopic.$phpEx$SID&amp;f={$this->forum_id}&amp;p={$this->post_id}#{$this->post_id}";
-
- if ($this->quickmod)
- {
- meta_refresh(3, $redirect_url);
- $return_topic = '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
- }
- else
- {
- if (count($post_id_list) == 1)
- {
- return_link('RETURN_POST', $this->url . '&amp;mode=post_details');
- }
- return_link('RETURN_TOPIC', $redirect_url);
- }
- }
- elseif ($topic_id_list = $this->get_topic_ids('m_approve'))
- {
- $post_mode = 'unapproved_topics';
-
- $sql = 'SELECT forum_id, topic_title, topic_first_post_id
- FROM ' . TOPICS_TABLE . '
- WHERE topic_id IN (' . implode(', ', $topic_id_list) . ')';
- $result = $db->sql_query($sql);
-
- $post_id_list = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $post_id_list[] = $row['topic_first_post_id'];
- add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_APPROVE_TOPIC', $row['topic_title']);
- }
-
- $sql = 'UPDATE ' . TOPICS_TABLE . '
- SET topic_approved = 1
- WHERE topic_id IN (' . implode(', ', $topic_id_list) . ')';
- $db->sql_query($sql);
-
- $msg = (count($topic_id_list) == 1) ? $user->lang['TOPIC_APPROVED_SUCCESS'] : $user->lang['TOPICS_APPROVED_SUCCESS'];
-
- // Return to forum
- $redirect_url = "viewforum.$phpEx$SID&amp;f=" . $this->forum_id;
-
- if ($this->quickmod)
- {
- meta_refresh(3, $redirect_url);
- $return_topic = '';
- }
- else
- {
- return_link('RETURN_FORUM', $redirect_url);
- }
- }
- else
- {
- trigger_error('NOT_MODERATOR');
- }
-
- // Update approved flag
- $sql = 'UPDATE ' . POSTS_TABLE . '
- SET post_approved = 1
- WHERE post_id IN (' . implode(', ', $post_id_list) . ')';
- $db->sql_query($sql);
-
- // Now resync everything
- sync('topic', 'topic_id', $topic_id_list, true, true);
- sync('forum', 'forum_id', $this->forum_id, true, true);
-
- // Back to... whatever
- if ($this->quickmod)
- {
- trigger_error($msg . $return_topic . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], "<a href=\"viewforum.$phpEx$SID&amp;f=" . $this->forum_id . '">', '</a>'));
- }
- else
- {
- $template->assign_var('MESSAGE', $msg);
- $this->main($post_mode);
- }
- break;
-
- case 'unapproved_topics':
- case 'unapproved_posts':
- if (!$forum_list = implode(', ', get_forum_list('m_approve')))
- {
- trigger_error('NOT_MODERATOR');
- }
-
- $this->mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $this->forum_id);
- $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
- $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
-
-
- if ($mode == 'unapproved_posts')
- {
- $sql = 'SELECT p.post_id
- FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql{0} == 'u') ? ', ' . USERS_TABLE . ' u' : '') . "
- WHERE p.forum_id IN ($forum_list)
- AND p.post_approved = 0
- " . (($sort_order_sql{0} == 'u') ? 'AND u.user_id = p.poster_id' : '') . "
- AND t.topic_id = p.topic_id
- AND t.topic_first_post_id <> p.post_id
- ORDER BY $sort_order_sql";
- $result = $db->sql_query_limit($sql, $config['topics_per_page'], $this->start);
-
- $i = 0;
- $post_ids = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $post_ids[] = $row['post_id'];
- $row_num[$row['post_id']] = $i++;
- }
-
- if (sizeof($post_ids))
- {
- $sql = 'SELECT f.forum_id, f.forum_name, t.topic_id, t.topic_title, p.post_id, p.post_username, p.poster_id, p.post_time, u.username
- FROM ' . POSTS_TABLE . ' p, ' . FORUMS_TABLE . ' f, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . " u
- WHERE p.post_id IN (" . implode(', ', $post_ids) . ")
- AND t.topic_id = p.topic_id
- AND f.forum_id = p.forum_id
- AND u.user_id = p.poster_id";
-
- $result = $db->sql_query($sql);
- $post_data = $rowset = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $post_data[$row['post_id']] = $row;
- }
- $db->sql_freeresult($result);
-
- foreach ($post_ids as $post_id)
- {
- $rowset[] = $post_data[$post_id];
- }
- unset($post_data, $post_ids);
- }
- else
- {
- $rowset = array();
- }
- }
- else
- {
- $sql = 'SELECT f.forum_id, f.forum_name, t.topic_id, t.topic_title, t.topic_time AS post_time, t.topic_poster AS poster_id, t.topic_first_post_id AS post_id, t.topic_first_poster_name AS username
- FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
- WHERE t.topic_approved = 0
- AND t.forum_id IN ($forum_list)
- AND f.forum_id = t.forum_id
- ORDER BY $sort_order_sql";
- $result = $db->sql_query_limit($sql, $config['topics_per_page'], $this->start);
-
- $rowset = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $rowset[] = $row;
- }
- $db->sql_freeresult($result);
- }
-
- foreach ($rowset as $row)
- {
- if ($row['poster_id'] == ANONYMOUS)
- {
- $poster = (!empty($row['post_username'])) ? $row['post_username'] : $user->lang['GUEST'];
- }
- else
- {
- $poster = '<a href="memberlist.' . $phpEx . $SID . '&amp;mode=viewprofile&amp;u=' . $row['poster_id'] . '">' . $row['username'] . '</a>';
- }
-
- $s_checkbox = ($mode == 'unapproved_posts') ? '<input type="checkbox" name="post_id_list[]" value="' . $row['post_id'] . '" />' : '<input type="checkbox" name="topic_id_list[]" value="' . $row['topic_id'] . '" />';
-
- $template->assign_block_vars('postrow', array(
- 'U_VIEWFORUM' => "viewforum.$phpEx$SID&amp;f=" . $row['forum_id'],
- // Q: Why accessing the topic by a post_id instead of its topic_id?
- // A: To prevent the post from being hidden because of low karma or wrong encoding
- 'U_VIEWTOPIC' => "viewtopic.$phpEx$SID&amp;f=" . $row['forum_id'] . '&amp;p=' . $row['post_id'] . (($mode == 'unapproved_posts') ? '#' . $row['post_id'] : ''),
-
- 'FORUM_NAME' => $row['forum_name'],
- 'TOPIC_TITLE' => $row['topic_title'],
- 'POSTER' => $poster,
- 'POST_TIME' => $user->format_date($row['post_time']),
- 'S_CHECKBOX' => $s_checkbox
- ));
- }
- unset($rowset);
-
- // Now display the page
- $template->assign_vars(array(
- 'L_DISPLAY_ITEMS' => ($mode == 'unapproved_posts') ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_POSTS']
- ));
-
- $this->display($user->lang['MCP_QUEUE'], 'mcp_queue.html');
- break;
-
- default:
- trigger_error('UNKNOWN_MODE');
- }
- }
-
- // This function simply puts the number of unapproved items in menu titles
- function alter_menu()
- {
- global $db, $user;
-
- $forum_list = get_forum_list('m_approve');
-
- $sql = 'SELECT COUNT(*) AS total
- FROM ' . TOPICS_TABLE . '
- WHERE forum_id IN (' . implode(', ', $forum_list) . ')
- AND topic_approved = 0';
- $result = $db->sql_query($sql);
- $total_topics = $db->sql_fetchfield('total', 0, $result);
-
- $sql = 'SELECT COUNT(*) AS total
- FROM ' . POSTS_TABLE . '
- WHERE forum_id IN (' . implode(', ', $forum_list) . ')
- AND post_approved = 0';
- $result = $db->sql_query($sql);
- $total_posts = $db->sql_fetchfield('total', 0, $result) - $total_topics;
-
- $this->subs['unapproved_topics']['title'] = sprintf($this->subs['unapproved_topics']['title'], ($total_topics) ? $total_topics : $user->lang['NONE']);
- $this->subs['unapproved_posts']['title'] = sprintf($this->subs['unapproved_posts']['title'], ($total_posts) ? $total_posts : $user->lang['NONE']);
- }
-
- function install()
- {
- }
-
- function uninstall()
- {
- }
-
- function module()
- {
- $details = array(
- 'name' => 'MCP - Queue',
- 'description' => 'Module for management of items waiting for approval',
- 'filename' => 'queue',
- 'version' => '0.1.0',
- 'phpbbversion' => '2.2.0'
- );
- return $details;
- }
-}
?> \ No newline at end of file