source: trunk/forum/includes/mcp/mcp_topic.php

Last change on this file was 702, checked in by george, 15 years ago
  • Upraveno: Aktualizace fóra.
File size: 20.1 KB
Line 
1<?php
2/**
3*
4* @package mcp
5* @version $Id$
6* @copyright (c) 2005 phpBB Group
7* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8*
9*/
10
11/**
12* @ignore
13*/
14if (!defined('IN_PHPBB'))
15{
16 exit;
17}
18
19/**
20* View topic in MCP
21*/
22function mcp_topic_view($id, $mode, $action)
23{
24 global $phpEx, $phpbb_root_path, $config;
25 global $template, $db, $user, $auth, $cache;
26
27 $url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . extra_url());
28
29 $user->add_lang('viewtopic');
30
31 $topic_id = request_var('t', 0);
32 $topic_info = get_topic_data(array($topic_id), false, true);
33
34 if (!sizeof($topic_info))
35 {
36 trigger_error('TOPIC_NOT_EXIST');
37 }
38
39 $topic_info = $topic_info[$topic_id];
40
41 // Set up some vars
42 $icon_id = request_var('icon', 0);
43 $subject = utf8_normalize_nfc(request_var('subject', '', true));
44 $start = request_var('start', 0);
45 $sort_days_old = request_var('st_old', 0);
46 $forum_id = request_var('f', 0);
47 $to_topic_id = request_var('to_topic_id', 0);
48 $to_forum_id = request_var('to_forum_id', 0);
49 $sort = isset($_POST['sort']) ? true : false;
50 $submitted_id_list = request_var('post_ids', array(0));
51 $checked_ids = $post_id_list = request_var('post_id_list', array(0));
52
53 // Split Topic?
54 if ($action == 'split_all' || $action == 'split_beyond')
55 {
56 if (!$sort)
57 {
58 split_topic($action, $topic_id, $to_forum_id, $subject);
59 }
60 $action = 'split';
61 }
62
63 // Merge Posts?
64 if ($action == 'merge_posts')
65 {
66 if (!$sort)
67 {
68 merge_posts($topic_id, $to_topic_id);
69 }
70 $action = 'merge';
71 }
72
73 if ($action == 'split' && !$subject)
74 {
75 $subject = $topic_info['topic_title'];
76 }
77
78 // Approve posts?
79 if ($action == 'approve' && $auth->acl_get('m_approve', $topic_info['forum_id']))
80 {
81 include($phpbb_root_path . 'includes/mcp/mcp_queue.' . $phpEx);
82 include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
83 include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
84
85 if (!sizeof($post_id_list))
86 {
87 trigger_error('NO_POST_SELECTED');
88 }
89
90 if (!$sort)
91 {
92 approve_post($post_id_list, $id, $mode);
93 }
94 }
95
96 // Jumpbox, sort selects and that kind of things
97 make_jumpbox($url . "&amp;i=$id&amp;mode=forum_view", $topic_info['forum_id'], false, 'm_', true);
98 $where_sql = ($action == 'reports') ? 'WHERE post_reported = 1 AND ' : 'WHERE';
99
100 $sort_days = $total = 0;
101 $sort_key = $sort_dir = '';
102 $sort_by_sql = $sort_order_sql = array();
103 mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $topic_info['forum_id'], $topic_id, $where_sql);
104
105 $limit_time_sql = ($sort_days) ? 'AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
106
107 if ($total == -1)
108 {
109 if ($auth->acl_get('m_approve', $topic_info['forum_id']))
110 {
111 $total = $topic_info['topic_replies_real'] + 1;
112 }
113 else
114 {
115 $total = $topic_info['topic_replies'] + 1;
116 }
117 }
118
119 $posts_per_page = max(0, request_var('posts_per_page', intval($config['posts_per_page'])));
120 if ($posts_per_page == 0)
121 {
122 $posts_per_page = $total;
123 }
124
125 if ((!empty($sort_days_old) && $sort_days_old != $sort_days) || $total <= $posts_per_page)
126 {
127 $start = 0;
128 }
129
130 // Make sure $start is set to the last page if it exceeds the amount
131 if ($start < 0 || $start >= $total)
132 {
133 $start = ($start < 0) ? 0 : floor(($total - 1) / $posts_per_page) * $posts_per_page;
134 }
135
136 $sql = 'SELECT u.username, u.username_clean, u.user_colour, p.*
137 FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
138 WHERE ' . (($action == 'reports') ? 'p.post_reported = 1 AND ' : '') . '
139 p.topic_id = ' . $topic_id . ' ' .
140 ((!$auth->acl_get('m_approve', $topic_info['forum_id'])) ? ' AND p.post_approved = 1 ' : '') . '
141 AND p.poster_id = u.user_id ' .
142 $limit_time_sql . '
143 ORDER BY ' . $sort_order_sql;
144 $result = $db->sql_query_limit($sql, $posts_per_page, $start);
145
146 $rowset = $post_id_list = array();
147 $bbcode_bitfield = '';
148 while ($row = $db->sql_fetchrow($result))
149 {
150 $rowset[] = $row;
151 $post_id_list[] = $row['post_id'];
152 $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
153 }
154 $db->sql_freeresult($result);
155
156 if ($bbcode_bitfield !== '')
157 {
158 include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
159 $bbcode = new bbcode(base64_encode($bbcode_bitfield));
160 }
161
162 $topic_tracking_info = array();
163
164 // Get topic tracking info
165 if ($config['load_db_lastread'])
166 {
167 $tmp_topic_data = array($topic_id => $topic_info);
168 $topic_tracking_info = get_topic_tracking($topic_info['forum_id'], $topic_id, $tmp_topic_data, array($topic_info['forum_id'] => $topic_info['forum_mark_time']));
169 unset($tmp_topic_data);
170 }
171 else
172 {
173 $topic_tracking_info = get_complete_topic_tracking($topic_info['forum_id'], $topic_id);
174 }
175
176 $has_unapproved_posts = false;
177
178 // Grab extensions
179 $extensions = $attachments = array();
180 if ($topic_info['topic_attachment'] && sizeof($post_id_list))
181 {
182 $extensions = $cache->obtain_attach_extensions($topic_info['forum_id']);
183
184 // Get attachments...
185 if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $topic_info['forum_id']))
186 {
187 $sql = 'SELECT *
188 FROM ' . ATTACHMENTS_TABLE . '
189 WHERE ' . $db->sql_in_set('post_msg_id', $post_id_list) . '
190 AND in_message = 0
191 ORDER BY filetime DESC, post_msg_id ASC';
192 $result = $db->sql_query($sql);
193
194 while ($row = $db->sql_fetchrow($result))
195 {
196 $attachments[$row['post_msg_id']][] = $row;
197 }
198 $db->sql_freeresult($result);
199 }
200 }
201
202 foreach ($rowset as $i => $row)
203 {
204 $message = $row['post_text'];
205 $post_subject = ($row['post_subject'] != '') ? $row['post_subject'] : $topic_info['topic_title'];
206
207 if ($row['bbcode_bitfield'])
208 {
209 $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
210 }
211
212 $message = bbcode_nl2br($message);
213 $message = smiley_text($message);
214
215 if (!empty($attachments[$row['post_id']]))
216 {
217 $update_count = array();
218 parse_attachments($topic_info['forum_id'], $message, $attachments[$row['post_id']], $update_count);
219 }
220
221 if (!$row['post_approved'])
222 {
223 $has_unapproved_posts = true;
224 }
225
226 $post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
227
228 $template->assign_block_vars('postrow', array(
229 'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
230 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
231 'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
232 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
233
234 'POST_DATE' => $user->format_date($row['post_time']),
235 'POST_SUBJECT' => $post_subject,
236 'MESSAGE' => $message,
237 'POST_ID' => $row['post_id'],
238 'RETURN_TOPIC' => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id) . '">', '</a>'),
239
240 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
241
242 'S_POST_REPORTED' => ($row['post_reported']) ? true : false,
243 'S_POST_UNAPPROVED' => ($row['post_approved']) ? false : true,
244 'S_CHECKED' => (($submitted_id_list && !in_array(intval($row['post_id']), $submitted_id_list)) || in_array(intval($row['post_id']), $checked_ids)) ? true : false,
245 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false,
246
247 'U_POST_DETAILS' => "$url&amp;i=$id&amp;p={$row['post_id']}&amp;mode=post_details" . (($forum_id) ? "&amp;f=$forum_id" : ''),
248 'U_MCP_APPROVE' => ($auth->acl_get('m_approve', $topic_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $topic_info['forum_id'] . '&amp;p=' . $row['post_id']) : '',
249 'U_MCP_REPORT' => ($auth->acl_get('m_report', $topic_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $topic_info['forum_id'] . '&amp;p=' . $row['post_id']) : '')
250 );
251
252 // Display not already displayed Attachments for this post, we already parsed them. ;)
253 if (!empty($attachments[$row['post_id']]))
254 {
255 foreach ($attachments[$row['post_id']] as $attachment)
256 {
257 $template->assign_block_vars('postrow.attachment', array(
258 'DISPLAY_ATTACHMENT' => $attachment)
259 );
260 }
261 }
262
263 unset($rowset[$i]);
264 }
265
266 // Display topic icons for split topic
267 $s_topic_icons = false;
268
269 if ($auth->acl_gets('m_split', 'm_merge', (int) $topic_info['forum_id']))
270 {
271 include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
272 $s_topic_icons = posting_gen_topic_icons('', $icon_id);
273
274 // Has the user selected a topic for merge?
275 if ($to_topic_id)
276 {
277 $to_topic_info = get_topic_data(array($to_topic_id), 'm_merge');
278
279 if (!sizeof($to_topic_info))
280 {
281 $to_topic_id = 0;
282 }
283 else
284 {
285 $to_topic_info = $to_topic_info[$to_topic_id];
286
287 if (!$to_topic_info['enable_icons'] || $auth->acl_get('!f_icons', $topic_info['forum_id']))
288 {
289 $s_topic_icons = false;
290 }
291 }
292 }
293 }
294
295 $s_hidden_fields = build_hidden_fields(array(
296 'st_old' => $sort_days,
297 'post_ids' => $post_id_list,
298 ));
299
300 $template->assign_vars(array(
301 'TOPIC_TITLE' => $topic_info['topic_title'],
302 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_info['forum_id'] . '&amp;t=' . $topic_info['topic_id']),
303
304 'TO_TOPIC_ID' => $to_topic_id,
305 'TO_TOPIC_INFO' => ($to_topic_id) ? sprintf($user->lang['YOU_SELECTED_TOPIC'], $to_topic_id, '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_topic_info['forum_id'] . '&amp;t=' . $to_topic_id) . '">' . $to_topic_info['topic_title'] . '</a>') : '',
306
307 'SPLIT_SUBJECT' => $subject,
308 'POSTS_PER_PAGE' => $posts_per_page,
309 'ACTION' => $action,
310
311 'REPORTED_IMG' => $user->img('icon_topic_reported', 'POST_REPORTED'),
312 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'),
313 'INFO_IMG' => $user->img('icon_post_info', 'VIEW_INFO'),
314
315 'S_MCP_ACTION' => "$url&amp;i=$id&amp;mode=$mode&amp;action=$action&amp;start=$start",
316 'S_FORUM_SELECT' => ($to_forum_id) ? make_forum_select($to_forum_id, false, false, true, true, true) : make_forum_select($topic_info['forum_id'], false, false, true, true, true),
317 'S_CAN_SPLIT' => ($auth->acl_get('m_split', $topic_info['forum_id'])) ? true : false,
318 'S_CAN_MERGE' => ($auth->acl_get('m_merge', $topic_info['forum_id'])) ? true : false,
319 'S_CAN_DELETE' => ($auth->acl_get('m_delete', $topic_info['forum_id'])) ? true : false,
320 'S_CAN_APPROVE' => ($has_unapproved_posts && $auth->acl_get('m_approve', $topic_info['forum_id'])) ? true : false,
321 'S_CAN_LOCK' => ($auth->acl_get('m_lock', $topic_info['forum_id'])) ? true : false,
322 'S_CAN_REPORT' => ($auth->acl_get('m_report', $topic_info['forum_id'])) ? true : false,
323 'S_REPORT_VIEW' => ($action == 'reports') ? true : false,
324 'S_MERGE_VIEW' => ($action == 'merge') ? true : false,
325 'S_SPLIT_VIEW' => ($action == 'split') ? true : false,
326
327 'S_HIDDEN_FIELDS' => $s_hidden_fields,
328
329 'S_SHOW_TOPIC_ICONS' => $s_topic_icons,
330 'S_TOPIC_ICON' => $icon_id,
331
332 'U_SELECT_TOPIC' => "$url&amp;i=$id&amp;mode=forum_view&amp;action=merge_select" . (($forum_id) ? "&amp;f=$forum_id" : ''),
333
334 'RETURN_TOPIC' => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_info['forum_id']}&amp;t={$topic_info['topic_id']}&amp;start=$start") . '">', '</a>'),
335 'RETURN_FORUM' => sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f={$topic_info['forum_id']}&amp;start=$start") . '">', '</a>'),
336
337 'PAGE_NUMBER' => on_page($total, $posts_per_page, $start),
338 'PAGINATION' => (!$posts_per_page) ? '' : generate_pagination(append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;t={$topic_info['topic_id']}&amp;mode=$mode&amp;action=$action&amp;to_topic_id=$to_topic_id&amp;posts_per_page=$posts_per_page&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir"), $total, $posts_per_page, $start),
339 'TOTAL_POSTS' => ($total == 1) ? $user->lang['VIEW_TOPIC_POST'] : sprintf($user->lang['VIEW_TOPIC_POSTS'], $total),
340 ));
341}
342
343/**
344* Split topic
345*/
346function split_topic($action, $topic_id, $to_forum_id, $subject)
347{
348 global $db, $template, $user, $phpEx, $phpbb_root_path, $auth, $config;
349
350 $post_id_list = request_var('post_id_list', array(0));
351 $forum_id = request_var('forum_id', 0);
352 $start = request_var('start', 0);
353
354 if (!sizeof($post_id_list))
355 {
356 $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
357 return;
358 }
359
360 if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_split')))
361 {
362 return;
363 }
364
365 $post_id = $post_id_list[0];
366 $post_info = get_post_data(array($post_id));
367
368 if (!sizeof($post_info))
369 {
370 $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
371 return;
372 }
373
374 $post_info = $post_info[$post_id];
375 $subject = trim($subject);
376
377 // Make some tests
378 if (!$subject)
379 {
380 $template->assign_var('MESSAGE', $user->lang['EMPTY_SUBJECT']);
381 return;
382 }
383
384 if ($to_forum_id <= 0)
385 {
386 $template->assign_var('MESSAGE', $user->lang['NO_DESTINATION_FORUM']);
387 return;
388 }
389
390 $forum_info = get_forum_data(array($to_forum_id), 'f_post');
391
392 if (!sizeof($forum_info))
393 {
394 $template->assign_var('MESSAGE', $user->lang['USER_CANNOT_POST']);
395 return;
396 }
397
398 $forum_info = $forum_info[$to_forum_id];
399
400 if ($forum_info['forum_type'] != FORUM_POST)
401 {
402 $template->assign_var('MESSAGE', $user->lang['FORUM_NOT_POSTABLE']);
403 return;
404 }
405
406 $redirect = request_var('redirect', build_url(array('quickmod')));
407
408 $s_hidden_fields = build_hidden_fields(array(
409 'i' => 'main',
410 'post_id_list' => $post_id_list,
411 'f' => $forum_id,
412 'mode' => 'topic_view',
413 'start' => $start,
414 'action' => $action,
415 't' => $topic_id,
416 'redirect' => $redirect,
417 'subject' => $subject,
418 'to_forum_id' => $to_forum_id,
419 'icon' => request_var('icon', 0))
420 );
421 $success_msg = $return_link = '';
422
423 if (confirm_box(true))
424 {
425 if ($action == 'split_beyond')
426 {
427 $sort_days = $total = 0;
428 $sort_key = $sort_dir = '';
429 $sort_by_sql = $sort_order_sql = array();
430 mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
431
432 $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
433
434 if ($sort_order_sql[0] == 'u')
435 {
436 $sql = 'SELECT p.post_id, p.forum_id, p.post_approved
437 FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
438 WHERE p.topic_id = $topic_id
439 AND p.poster_id = u.user_id
440 $limit_time_sql
441 ORDER BY $sort_order_sql";
442 }
443 else
444 {
445 $sql = 'SELECT p.post_id, p.forum_id, p.post_approved
446 FROM ' . POSTS_TABLE . " p
447 WHERE p.topic_id = $topic_id
448 $limit_time_sql
449 ORDER BY $sort_order_sql";
450 }
451 $result = $db->sql_query_limit($sql, 0, $start);
452
453 $store = false;
454 $post_id_list = array();
455 while ($row = $db->sql_fetchrow($result))
456 {
457 // If split from selected post (split_beyond), we split the unapproved items too.
458 if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id']))
459 {
460// continue;
461 }
462
463 // Start to store post_ids as soon as we see the first post that was selected
464 if ($row['post_id'] == $post_id)
465 {
466 $store = true;
467 }
468
469 if ($store)
470 {
471 $post_id_list[] = $row['post_id'];
472 }
473 }
474 $db->sql_freeresult($result);
475 }
476
477 if (!sizeof($post_id_list))
478 {
479 trigger_error('NO_POST_SELECTED');
480 }
481
482 $icon_id = request_var('icon', 0);
483
484 $sql_ary = array(
485 'forum_id' => $to_forum_id,
486 'topic_title' => $subject,
487 'icon_id' => $icon_id,
488 'topic_approved'=> 1
489 );
490
491 $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
492 $db->sql_query($sql);
493
494 $to_topic_id = $db->sql_nextid();
495 move_posts($post_id_list, $to_topic_id);
496
497 $topic_info = get_topic_data(array($topic_id));
498 $topic_info = $topic_info[$topic_id];
499
500 add_log('mod', $to_forum_id, $to_topic_id, 'LOG_SPLIT_DESTINATION', $subject);
501 add_log('mod', $forum_id, $topic_id, 'LOG_SPLIT_SOURCE', $topic_info['topic_title']);
502
503 // Change topic title of first post
504 $sql = 'UPDATE ' . POSTS_TABLE . "
505 SET post_subject = '" . $db->sql_escape($subject) . "'
506 WHERE post_id = {$post_id_list[0]}";
507 $db->sql_query($sql);
508
509 $success_msg = 'TOPIC_SPLIT_SUCCESS';
510
511 // Update forum statistics
512 set_config_count('num_topics', 1, true);
513
514 // Link back to both topics
515 $return_link = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']) . '">', '</a>') . '<br /><br />' . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>');
516 }
517 else
518 {
519 confirm_box(false, ($action == 'split_all') ? 'SPLIT_TOPIC_ALL' : 'SPLIT_TOPIC_BEYOND', $s_hidden_fields);
520 }
521
522 $redirect = request_var('redirect', "index.$phpEx");
523 $redirect = reapply_sid($redirect);
524
525 if (!$success_msg)
526 {
527 return;
528 }
529 else
530 {
531 meta_refresh(3, append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&amp;t=$to_topic_id"));
532 trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
533 }
534}
535
536/**
537* Merge selected posts into selected topic
538*/
539function merge_posts($topic_id, $to_topic_id)
540{
541 global $db, $template, $user, $phpEx, $phpbb_root_path, $auth;
542
543 if (!$to_topic_id)
544 {
545 $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
546 return;
547 }
548
549 $topic_data = get_topic_data(array($to_topic_id), 'm_merge');
550
551 if (!sizeof($topic_data))
552 {
553 $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
554 return;
555 }
556
557 $topic_data = $topic_data[$to_topic_id];
558
559 $post_id_list = request_var('post_id_list', array(0));
560 $start = request_var('start', 0);
561
562 if (!sizeof($post_id_list))
563 {
564 $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
565 return;
566 }
567
568 if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_merge')))
569 {
570 return;
571 }
572
573 $redirect = request_var('redirect', build_url(array('quickmod')));
574
575 $s_hidden_fields = build_hidden_fields(array(
576 'i' => 'main',
577 'post_id_list' => $post_id_list,
578 'to_topic_id' => $to_topic_id,
579 'mode' => 'topic_view',
580 'action' => 'merge_posts',
581 'start' => $start,
582 'redirect' => $redirect,
583 't' => $topic_id)
584 );
585 $success_msg = $return_link = '';
586
587 if (confirm_box(true))
588 {
589 $to_forum_id = $topic_data['forum_id'];
590
591 move_posts($post_id_list, $to_topic_id);
592 add_log('mod', $to_forum_id, $to_topic_id, 'LOG_MERGE', $topic_data['topic_title']);
593
594 // Message and return links
595 $success_msg = 'POSTS_MERGED_SUCCESS';
596
597 // Does the original topic still exist? If yes, link back to it
598 $sql = 'SELECT forum_id
599 FROM ' . TOPICS_TABLE . '
600 WHERE topic_id = ' . $topic_id;
601 $result = $db->sql_query_limit($sql, 1);
602 $row = $db->sql_fetchrow($result);
603 $db->sql_freeresult($result);
604
605 if ($row)
606 {
607 $return_link .= sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;t=' . $topic_id) . '">', '</a>');
608 }
609 else
610 {
611 // If the topic no longer exist, we will update the topic watch table.
612 // To not let it error out on users watching both topics, we just return on an error...
613 $db->sql_return_on_error(true);
614 $db->sql_query('UPDATE ' . TOPICS_WATCH_TABLE . ' SET topic_id = ' . (int) $to_topic_id . ' WHERE topic_id = ' . (int) $topic_id);
615 $db->sql_return_on_error(false);
616
617 $db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . (int) $topic_id);
618 }
619
620 // Link to the new topic
621 $return_link .= (($return_link) ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>');
622 }
623 else
624 {
625 confirm_box(false, 'MERGE_POSTS', $s_hidden_fields);
626 }
627
628 $redirect = request_var('redirect', "index.$phpEx");
629 $redirect = reapply_sid($redirect);
630
631 if (!$success_msg)
632 {
633 return;
634 }
635 else
636 {
637 meta_refresh(3, append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&amp;t=$to_topic_id"));
638 trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
639 }
640}
641
642?>
Note: See TracBrowser for help on using the repository browser.