PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/forum/includes/mcp/mcp_topic.php

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