PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/mcp/mcp_topic.php

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