6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
22 function mcp_forum_view($id, $mode, $action, $forum_info)
24 global $template, $db, $user, $auth, $module;
26 $user->add_lang(array('viewtopic', 'viewforum'));
28 include_once(PHPBB_ROOT_PATH
. 'includes/functions_display.' . PHP_EXT
);
30 // merge_topic is the quickmod action, merge_topics is the mcp_forum action, and merge_select is the mcp_topic action
31 $merge_select = ($action == 'merge_select' ||
$action == 'merge_topic' ||
$action == 'merge_topics') ?
true : false;
35 // Fixes a "bug" that makes forum_view use the same ordering as topic_view
36 phpbb_request
::overwrite('sk', null, phpbb_request
::POST
);
37 phpbb_request
::overwrite('sd', null, phpbb_request
::POST
);
38 phpbb_request
::overwrite('sk', null, phpbb_request
::REQUEST
);
39 phpbb_request
::overwrite('sd', null, phpbb_request
::REQUEST
);
42 $forum_id = $forum_info['forum_id'];
43 $start = request_var('start', 0);
44 $topic_id_list = request_var('topic_id_list', array(0));
45 $post_id_list = request_var('post_id_list', array(0));
46 $source_topic_ids = array(request_var('t', 0));
47 $to_topic_id = request_var('to_topic_id', 0);
50 $url_extra .= ($forum_id) ?
"&f=$forum_id" : '';
51 $url_extra .= ($GLOBALS['topic_id']) ?
'&t=' . $GLOBALS['topic_id'] : '';
52 $url_extra .= ($GLOBALS['post_id']) ?
'&p=' . $GLOBALS['post_id'] : '';
53 $url_extra .= ($GLOBALS['user_id']) ?
'&u=' . $GLOBALS['user_id'] : '';
55 $url = ($url_extra) ?
append_sid('mcp', $url_extra) : append_sid('mcp');
61 $topic_ids = request_var('topic_id_list', array(0));
62 mcp_resync_topics($topic_ids);
66 $source_topic_ids = $topic_id_list;
70 merge_topics($forum_id, $source_topic_ids, $to_topic_id);
76 if (sizeof($post_id_list) && $action != 'merge_topics')
78 foreach ($post_id_list as $num => $post_id)
80 $selected_ids .= '&post_id_list[' . $num . ']=' . $post_id;
83 else if (sizeof($topic_id_list) && $action == 'merge_topics')
85 foreach ($topic_id_list as $num => $topic_id)
87 $selected_ids .= '&topic_id_list[' . $num . ']=' . $topic_id;
91 make_jumpbox($url . "&i=$id&action=$action&mode=$mode" . (($merge_select) ?
$selected_ids : ''), $forum_id, false, 'm_', true);
93 $topics_per_page = ($forum_info['forum_topics_per_page']) ?
$forum_info['forum_topics_per_page'] : phpbb
::$config['topics_per_page'];
95 $sort_days = $total = 0;
96 $sort_key = $sort_dir = '';
97 $sort_by_sql = $sort_order_sql = array();
98 mcp_sorting('viewforum', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id);
100 $forum_topics = ($total == -1) ?
$forum_info['forum_topics'] : $total;
101 $limit_time_sql = ($sort_days) ?
'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
103 $template->assign_vars(array(
105 'FORUM_NAME' => $forum_info['forum_name'],
106 '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']),
108 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
109 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
110 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
111 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
113 'S_CAN_REPORT' => $auth->acl_get('m_report', $forum_id),
114 'S_CAN_DELETE' => $auth->acl_get('m_delete', $forum_id),
115 'S_CAN_MERGE' => $auth->acl_get('m_merge', $forum_id),
116 'S_CAN_MOVE' => $auth->acl_get('m_move', $forum_id),
117 'S_CAN_FORK' => $auth->acl_get('m_', $forum_id),
118 'S_CAN_LOCK' => $auth->acl_get('m_lock', $forum_id),
119 'S_CAN_SYNC' => $auth->acl_get('m_', $forum_id),
120 'S_CAN_APPROVE' => $auth->acl_get('m_approve', $forum_id),
121 'S_MERGE_SELECT' => ($merge_select) ?
true : false,
122 'S_CAN_MAKE_NORMAL' => $auth->acl_gets('f_sticky', 'f_announce', $forum_id),
123 'S_CAN_MAKE_STICKY' => $auth->acl_get('f_sticky', $forum_id),
124 'S_CAN_MAKE_ANNOUNCE' => $auth->acl_get('f_announce', $forum_id),
126 'U_VIEW_FORUM' => append_sid('viewforum', 'f=' . $forum_id),
127 'U_VIEW_FORUM_LOGS' => ($auth->acl_gets('a_', 'm_', $forum_id) && $module->loaded('logs')) ?
append_sid('mcp', 'i=logs&mode=forum_logs&f=' . $forum_id) : '',
129 'S_MCP_ACTION' => $url . "&i=$id&forum_action=$action&mode=$mode&start=$start" . (($merge_select) ?
$selected_ids : ''),
131 'PAGINATION' => generate_pagination($url . "&i=$id&action=$action&mode=$mode&sd=$sort_dir&sk=$sort_key&st=$sort_days" . (($merge_select) ?
$selected_ids : ''), $forum_topics, $topics_per_page, $start),
132 'PAGE_NUMBER' => on_page($forum_topics, $topics_per_page, $start),
133 'TOTAL_TOPICS' => ($forum_topics == 1) ?
$user->lang
['VIEW_FORUM_TOPIC'] : sprintf($user->lang
['VIEW_FORUM_TOPICS'], $forum_topics),
137 $icons = phpbb_cache
::obtain_icons();
139 $topic_rows = array();
141 if (phpbb
::$config['load_db_lastread'])
143 $read_tracking_join = ' LEFT JOIN ' . TOPICS_TRACK_TABLE
. ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data
['user_id'] . ')';
144 $read_tracking_select = ', tt.mark_time';
148 $read_tracking_join = $read_tracking_select = '';
151 $sql = "SELECT t.topic_id
152 FROM " . TOPICS_TABLE
. " t
153 WHERE t.forum_id IN($forum_id, 0)
154 " . (($auth->acl_get('m_approve', $forum_id)) ?
'' : 'AND t.topic_approved = 1') . "
156 ORDER BY t.topic_type DESC, $sort_order_sql";
157 $result = $db->sql_query_limit($sql, $topics_per_page, $start);
159 $topic_list = $topic_tracking_info = array();
161 while ($row = $db->sql_fetchrow($result))
163 $topic_list[] = $row['topic_id'];
165 $db->sql_freeresult($result);
167 $sql = "SELECT t.*$read_tracking_select
168 FROM " . TOPICS_TABLE
. " t $read_tracking_join
169 WHERE " . $db->sql_in_set('t.topic_id', $topic_list, false, true);
171 $result = $db->sql_query($sql);
172 while ($row = $db->sql_fetchrow($result))
174 $topic_rows[$row['topic_id']] = $row;
176 $db->sql_freeresult($result);
178 // If there is more than one page, but we have no topic list, then the start parameter is... erm... out of sync
179 if (!sizeof($topic_list) && $forum_topics && $start > 0)
181 redirect($url . "&i=$id&action=$action&mode=$mode");
184 // Get topic tracking info
185 if (sizeof($topic_list))
187 if (phpbb
::$config['load_db_lastread'])
189 $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $topic_rows, array($forum_id => $forum_info['mark_time']), array());
193 $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, array());
197 foreach ($topic_list as $topic_id)
201 $row = &$topic_rows[$topic_id];
203 $replies = ($auth->acl_get('m_approve', $forum_id)) ?
$row['topic_replies_real'] : $row['topic_replies'];
205 if ($row['topic_status'] == ITEM_MOVED
)
207 $unread_topic = false;
211 $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ?
true : false;
214 // Get folder img, topic status/type related information
215 $folder_img = $folder_alt = $topic_type = '';
216 topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
218 $topic_title = censor_text($row['topic_title']);
220 $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $row['forum_id'])) ?
true : false;
221 $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id'])) ?
true : false;
222 $u_mcp_queue = ($topic_unapproved ||
$posts_unapproved) ?
$url . '&i=queue&mode=' . (($topic_unapproved) ?
'approve_details' : 'unapproved_posts') . '&t=' . $row['topic_id'] : '';
225 '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']) : '',
226 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
227 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, 'src'),
228 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ?
$icons[$row['icon_id']]['img'] : '',
229 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ?
$icons[$row['icon_id']]['width'] : '',
230 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ?
$icons[$row['icon_id']]['height'] : '',
231 'UNAPPROVED_IMG' => ($topic_unapproved ||
$posts_unapproved) ?
$user->img('icon_topic_unapproved', ($topic_unapproved) ?
'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
233 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
234 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
235 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
236 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
238 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
239 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
240 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
241 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
243 'TOPIC_TYPE' => $topic_type,
244 'TOPIC_TITLE' => $topic_title,
245 'REPLIES' => ($auth->acl_get('m_approve', $row['forum_id'])) ?
$row['topic_replies_real'] : $row['topic_replies'],
246 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
247 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
248 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'],
249 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
251 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && empty($row['topic_moved_id']) && $auth->acl_get('m_report', $row['forum_id'])) ?
true : false,
252 'S_TOPIC_UNAPPROVED' => $topic_unapproved,
253 'S_POSTS_UNAPPROVED' => $posts_unapproved,
254 'S_UNREAD_TOPIC' => $unread_topic,
257 if ($row['topic_status'] == ITEM_MOVED
)
259 $topic_row = array_merge($topic_row, array(
260 'U_VIEW_TOPIC' => append_sid('viewtopic', "t={$row['topic_moved_id']}"),
261 'U_DELETE_TOPIC' => ($auth->acl_get('m_delete', $forum_id)) ?
append_sid('mcp', "i=$id&f=$forum_id&topic_id_list[]={$row['topic_id']}&mode=forum_view&action=delete_topic") : '',
262 'S_MOVED_TOPIC' => true,
263 'TOPIC_ID' => $row['topic_moved_id'],
268 if ($action == 'merge_topic' ||
$action == 'merge_topics')
270 $u_select_topic = $url . "&i=$id&mode=forum_view&action=$action&to_topic_id=" . $row['topic_id'] . $selected_ids;
274 $u_select_topic = $url . "&i=$id&mode=topic_view&action=merge&to_topic_id=" . $row['topic_id'] . $selected_ids;
276 $topic_row = array_merge($topic_row, array(
277 'U_VIEW_TOPIC' => append_sid('mcp', "i=$id&f=$forum_id&t={$row['topic_id']}&mode=topic_view"),
279 'S_SELECT_TOPIC' => ($merge_select && !in_array($row['topic_id'], $source_topic_ids)) ?
true : false,
280 'U_SELECT_TOPIC' => $u_select_topic,
281 'U_MCP_QUEUE' => $u_mcp_queue,
282 'U_MCP_REPORT' => ($auth->acl_get('m_report', $forum_id)) ?
append_sid('mcp', 'i=main&mode=topic_view&t=' . $row['topic_id'] . '&action=reports') : '',
283 'TOPIC_ID' => $row['topic_id'],
284 'S_TOPIC_CHECKED' => ($topic_id_list && in_array($row['topic_id'], $topic_id_list)) ?
true : false,
288 $template->assign_block_vars('topicrow', $topic_row);
296 function mcp_resync_topics($topic_ids)
298 global $auth, $db, $template, $user;
300 if (!sizeof($topic_ids))
302 trigger_error('NO_TOPIC_SELECTED');
305 if (!check_ids($topic_ids, TOPICS_TABLE
, 'topic_id', array('m_')))
310 // Sync everything and perform extra checks separately
311 sync('topic_reported', 'topic_id', $topic_ids, false, true);
312 sync('topic_attachment', 'topic_id', $topic_ids, false, true);
313 sync('topic', 'topic_id', $topic_ids, true, false);
315 $sql = 'SELECT topic_id, forum_id, topic_title
316 FROM ' . TOPICS_TABLE
. '
317 WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
318 $result = $db->sql_query($sql);
321 while ($row = $db->sql_fetchrow($result))
323 add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_TOPIC_RESYNC', $row['topic_title']);
325 $db->sql_freeresult($result);
327 $msg = (sizeof($topic_ids) == 1) ?
$user->lang
['TOPIC_RESYNC_SUCCESS'] : $user->lang
['TOPICS_RESYNC_SUCCESS'];
329 $redirect = request_var('redirect', $user->data
['session_page']);
331 meta_refresh(3, $redirect);
332 trigger_error($msg . '<br /><br />' . sprintf($user->lang
['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
338 * Merge selected topics into selected topic
340 function merge_topics($forum_id, $topic_ids, $to_topic_id)
342 global $db, $template, $user, $auth;
344 if (!sizeof($topic_ids))
346 $template->assign_var('MESSAGE', $user->lang
['NO_TOPIC_SELECTED']);
351 $template->assign_var('MESSAGE', $user->lang
['NO_FINAL_TOPIC_SELECTED']);
355 $topic_data = get_topic_data(array($to_topic_id), 'm_merge');
357 if (!sizeof($topic_data))
359 $template->assign_var('MESSAGE', $user->lang
['NO_FINAL_TOPIC_SELECTED']);
363 $topic_data = $topic_data[$to_topic_id];
365 $post_id_list = request_var('post_id_list', array(0));
366 $start = request_var('start', 0);
368 if (!sizeof($post_id_list) && sizeof($topic_ids))
370 $sql = 'SELECT post_id
371 FROM ' . POSTS_TABLE
. '
372 WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
373 $result = $db->sql_query($sql);
375 $post_id_list = array();
376 while ($row = $db->sql_fetchrow($result))
378 $post_id_list[] = $row['post_id'];
380 $db->sql_freeresult($result);
383 if (!sizeof($post_id_list))
385 $template->assign_var('MESSAGE', $user->lang
['NO_POST_SELECTED']);
389 if (!check_ids($post_id_list, POSTS_TABLE
, 'post_id', array('m_merge')))
394 $redirect = request_var('redirect', build_url(array('quickmod')));
396 $s_hidden_fields = build_hidden_fields(array(
399 'post_id_list' => $post_id_list,
400 'to_topic_id' => $to_topic_id,
401 'mode' => 'forum_view',
402 'action' => 'merge_topics',
404 'redirect' => $redirect,
405 'topic_id_list' => $topic_ids)
407 $success_msg = $return_link = '';
409 if (confirm_box(true))
411 $to_forum_id = $topic_data['forum_id'];
413 move_posts($post_id_list, $to_topic_id);
414 add_log('mod', $to_forum_id, $to_topic_id, 'LOG_MERGE', $topic_data['topic_title']);
416 // Message and return links
417 $success_msg = 'POSTS_MERGED_SUCCESS';
419 // If the topic no longer exist, we will update the topic watch table.
420 // To not let it error out on users watching both topics, we just return on an error...
421 $db->sql_return_on_error(true);
422 $db->sql_query('UPDATE ' . TOPICS_WATCH_TABLE
. ' SET topic_id = ' . (int) $to_topic_id . ' WHERE ' . $db->sql_in_set('topic_id', $topic_ids));
423 $db->sql_return_on_error(false);
425 $db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE
. ' WHERE ' . $db->sql_in_set('topic_id', $topic_ids));
427 // Link to the new topic
428 $return_link .= (($return_link) ?
'<br /><br />' : '') . sprintf($user->lang
['RETURN_NEW_TOPIC'], '<a href="' . append_sid('viewtopic', 'f=' . $to_forum_id . '&t=' . $to_topic_id) . '">', '</a>');
432 confirm_box(false, 'MERGE_TOPICS', $s_hidden_fields);
435 $redirect = request_var('redirect', 'index.' . PHP_EXT
);
436 $redirect = reapply_sid($redirect);
444 meta_refresh(3, append_sid('viewtopic', "f=$to_forum_id&t=$to_topic_id"));
445 trigger_error($user->lang
[$success_msg] . '<br /><br />' . $return_link);