- a bunch of fixes
[phpbb.git] / phpBB / includes / mcp / mcp_forum.php
blob4fdae3159d2aeb9790c400d1346392c7cb35dbf8
1 <?php
2 /**
4 * @package mcp
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * MCP Forum View
14 function mcp_forum_view($id, $mode, $action, $forum_info)
16 global $template, $db, $user, $auth, $cache;
17 global $phpEx, $phpbb_root_path, $config;
19 include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
21 $url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . extra_url());
23 if ($action == 'merge_select')
25 // Fixes a "bug" that makes forum_view use the same ordering as topic_view
26 unset($_POST['sk'], $_POST['sd'], $_REQUEST['sk'], $_REQUEST['sd']);
29 $forum_id = $forum_info['forum_id'];
30 $start = request_var('start', 0);
31 $topic_id_list = request_var('topic_id_list', array(0));
32 $post_id_list = request_var('post_id_list', array(0));
33 $topic_id = request_var('t', 0);
35 // Resync Topics
36 if ($action == 'resync')
38 $topic_ids = request_var('topic_id_list', array(0));
40 mcp_resync_topics($topic_ids);
43 $selected_ids = '';
44 if (sizeof($post_id_list))
46 foreach ($post_id_list as $num => $post_id)
48 $selected_ids .= '&amp;post_id_list[' . $num . ']=' . $post_id;
52 make_jumpbox($url . "&amp;i=$id&amp;action=$action&amp;mode=$mode", $forum_id . (($action == 'merge_select') ? $selected_ids : ''), false, 'm_');
54 $topics_per_page = ($forum_info['forum_topics_per_page']) ? $forum_info['forum_topics_per_page'] : $config['topics_per_page'];
56 $sort_days = $total = 0;
57 $sort_key = $sort_dir = '';
58 $sort_by_sql = $sort_order_sql = array();
59 mcp_sorting('viewforum', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id);
61 $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
62 $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
64 $template->assign_vars(array(
65 'FORUM_NAME' => $forum_info['forum_name'],
66 'FORUM_DESCRIPTION' => generate_text_for_display($forum_info['forum_desc'], $forum_info['forum_desc_uid'], $forum_info['forum_desc_bitfield'], $forum_info['forum_desc_options']),
68 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
69 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
70 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
71 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
73 'S_CAN_REPORT' => $auth->acl_get('m_report', $forum_id),
74 'S_CAN_DELETE' => $auth->acl_get('m_delete', $forum_id),
75 'S_CAN_MOVE' => $auth->acl_get('m_move', $forum_id),
76 'S_CAN_FORK' => $auth->acl_get('m_', $forum_id),
77 'S_CAN_LOCK' => $auth->acl_get('m_lock', $forum_id),
78 'S_CAN_SYNC' => $auth->acl_get('m_', $forum_id),
79 'S_CAN_APPROVE' => $auth->acl_get('m_approve', $forum_id),
80 'S_MERGE_SELECT' => ($action == 'merge_select') ? true : false,
82 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
83 'U_VIEW_FORUM_LOGS' => ($auth->acl_gets('a_', 'm_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=logs&amp;mode=forum_logs&amp;f=' . $forum_id) : '',
85 'S_MCP_ACTION' => $url . "&amp;i=$id&amp;mode=$mode&amp;start=$start" . (($action == 'merge_select') ? $selected_ids : ''),
87 'PAGINATION' => generate_pagination($url . "&amp;i=$id&amp;action=$action&amp;mode=$mode" . (($action == 'merge_select') ? $selected_ids : ''), $forum_topics, $topics_per_page, $start),
88 'PAGE_NUMBER' => on_page($forum_topics, $topics_per_page, $start),
89 'TOTAL' => $forum_topics)
92 // Grab icons
93 $icons = $cache->obtain_icons();
95 $topic_rows = array();
97 $sql = 'SELECT t.*
98 FROM ' . TOPICS_TABLE . " t
99 WHERE (t.forum_id = $forum_id OR t.forum_id = 0)
100 " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1') . "
101 $limit_time_sql
102 ORDER BY t.topic_type DESC, $sort_order_sql";
103 $result = $db->sql_query_limit($sql, $topics_per_page, $start);
105 while ($row = $db->sql_fetchrow($result))
107 $topic_rows[] = $row;
109 $db->sql_freeresult($result);
111 foreach ($topic_rows as $row)
113 $topic_title = '';
115 $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
117 // Get folder img, topic status/type related information
118 $folder_img = $folder_alt = $topic_type = '';
119 topic_status($row, $replies, false, $folder_img, $folder_alt, $topic_type);
121 $topic_title = censor_text($row['topic_title']);
123 $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false;
124 $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id'])) ? true : false;
125 $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? $url . '&amp;i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . '&amp;t=' . $row['topic_id'] : '';
127 $template->assign_block_vars('topicrow', array(
128 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;f=$forum_id&amp;t={$row['topic_id']}&amp;mode=topic_view"),
130 'S_SELECT_TOPIC' => ($action == 'merge_select' && $row['topic_id'] != $topic_id) ? true : false,
131 'U_SELECT_TOPIC' => $url . "&amp;i=$id&amp;mode=topic_view&amp;action=merge&amp;to_topic_id=" . $row['topic_id'] . $selected_ids,
132 'U_MCP_QUEUE' => $u_mcp_queue,
133 'U_MCP_REPORT' => ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=topic_view&amp;t=' . $row['topic_id'] . '&amp;action=reports') : '',
135 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
136 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
137 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
138 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
139 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
140 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
141 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
143 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
144 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
145 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
146 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
148 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
149 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
150 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
151 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
153 'TOPIC_TYPE' => $topic_type,
154 'TOPIC_TITLE' => $topic_title,
155 'REPLIES' => ($auth->acl_get('m_approve', $row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies'],
156 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
157 'TOPIC_ID' => $row['topic_id'],
158 'S_TOPIC_CHECKED' => ($topic_id_list && in_array($row['topic_id'], $topic_id_list)) ? 'checked="checked" ' : '',
159 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
160 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'],
161 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
163 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $row['forum_id'])) ? true : false,
164 'S_TOPIC_UNAPPROVED' => $topic_unapproved,
165 'S_POSTS_UNAPPROVED' => $posts_unapproved)
168 unset($topic_rows);
172 * Resync topics
174 function mcp_resync_topics($topic_ids)
176 global $auth, $db, $template, $phpEx, $user, $phpbb_root_path;
178 if (!sizeof($topic_ids))
180 trigger_error($user->lang['NO_TOPIC_SELECTED']);
183 if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_')))
185 return;
188 // Sync everything and perform extra checks separately
189 sync('topic_reported', 'topic_id', $topic_ids, false, true);
190 sync('topic_attachment', 'topic_id', $topic_ids, false, true);
191 sync('topic', 'topic_id', $topic_ids, true, false);
193 $sql = 'SELECT topic_id, forum_id, topic_title
194 FROM ' . TOPICS_TABLE . '
195 WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
196 $result = $db->sql_query($sql);
198 // Log this action
199 while ($row = $db->sql_fetchrow($result))
201 add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_TOPIC_RESYNC', $row['topic_title']);
203 $db->sql_freeresult($result);
205 $msg = (sizeof($topic_ids) == 1) ? $user->lang['TOPIC_RESYNC_SUCCESS'] : $user->lang['TOPICS_RESYNC_SUCCESS'];
207 $redirect = request_var('redirect', $user->data['session_page']);
209 meta_refresh(3, $redirect);
210 trigger_error($msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
212 return;