PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/forum/includes/mcp/mcp_main.php

https://github.com/GreyTeardrop/socionicasys-forum
PHP | 1357 lines | 1047 code | 230 blank | 80 comment | 159 complexity | b808ad6755526b3c4d790981d5cc04c0 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-3.0, MPL-2.0-no-copyleft-exception
  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. * mcp_main
  19. * Handling mcp actions
  20. * @package mcp
  21. */
  22. class mcp_main
  23. {
  24. var $p_master;
  25. var $u_action;
  26. function mcp_main(&$p_master)
  27. {
  28. $this->p_master = &$p_master;
  29. }
  30. function main($id, $mode)
  31. {
  32. global $auth, $db, $user, $template, $action;
  33. global $config, $phpbb_root_path, $phpEx;
  34. //-- mod: Prime Trash Bin ---------------------------------------------------//
  35. // Include our language file for the logs.
  36. $user->add_lang('mods/prime_trash_bin_b');
  37. //-- end: Prime Trash Bin ---------------------------------------------------//
  38. $quickmod = ($mode == 'quickmod') ? true : false;
  39. switch ($action)
  40. {
  41. case 'lock':
  42. case 'unlock':
  43. $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
  44. if (!sizeof($topic_ids))
  45. {
  46. trigger_error('NO_TOPIC_SELECTED');
  47. }
  48. lock_unlock($action, $topic_ids);
  49. break;
  50. case 'lock_post':
  51. case 'unlock_post':
  52. $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
  53. if (!sizeof($post_ids))
  54. {
  55. trigger_error('NO_POST_SELECTED');
  56. }
  57. lock_unlock($action, $post_ids);
  58. break;
  59. case 'make_announce':
  60. case 'make_sticky':
  61. case 'make_global':
  62. case 'make_normal':
  63. $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
  64. if (!sizeof($topic_ids))
  65. {
  66. trigger_error('NO_TOPIC_SELECTED');
  67. }
  68. change_topic_type($action, $topic_ids);
  69. break;
  70. case 'move':
  71. $user->add_lang('viewtopic');
  72. $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
  73. if (!sizeof($topic_ids))
  74. {
  75. trigger_error('NO_TOPIC_SELECTED');
  76. }
  77. mcp_move_topic($topic_ids);
  78. break;
  79. case 'fork':
  80. $user->add_lang('viewtopic');
  81. $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
  82. if (!sizeof($topic_ids))
  83. {
  84. trigger_error('NO_TOPIC_SELECTED');
  85. }
  86. mcp_fork_topic($topic_ids);
  87. break;
  88. case 'delete_topic':
  89. $user->add_lang('viewtopic');
  90. $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
  91. if (!sizeof($topic_ids))
  92. {
  93. trigger_error('NO_TOPIC_SELECTED');
  94. }
  95. //-- mod: Prime Trash Bin (Topics) ------------------------------------------//
  96. // Intercept the topic deletion (for the moderator control panel).
  97. include($phpbb_root_path . 'includes/prime_trash_bin_b.' . $phpEx);
  98. mcp_stifle_topic($topic_ids);
  99. //-- end: Prime Trash Bin (Topics) ------------------------------------------//
  100. mcp_delete_topic($topic_ids);
  101. break;
  102. case 'delete_post':
  103. $user->add_lang('posting');
  104. $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
  105. if (!sizeof($post_ids))
  106. {
  107. trigger_error('NO_POST_SELECTED');
  108. }
  109. //-- mod: Prime Trash Bin (Posts) -------------------------------------------//
  110. // Intercept the post deletion (for the moderator control panel).
  111. include($phpbb_root_path . 'includes/prime_trash_bin_b.' . $phpEx);
  112. mcp_stifle_post($post_ids);
  113. //-- end: Prime Trash Bin (Posts) -------------------------------------------//
  114. mcp_delete_post($post_ids);
  115. break;
  116. //-- mod: Prime Trash Bin ---------------------------------------------------//
  117. // Reverse a deletion.
  118. case 'undelete_topic':
  119. $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
  120. if (!sizeof($topic_ids))
  121. {
  122. $user->add_lang('mcp');
  123. trigger_error('NO_TOPIC_SELECTED');
  124. }
  125. include($phpbb_root_path . 'includes/prime_trash_bin_b.' . $phpEx);
  126. mcp_unstifle_topic($topic_ids);
  127. break;
  128. case 'undelete_post':
  129. $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
  130. if (!sizeof($post_ids))
  131. {
  132. $user->add_lang('mcp');
  133. trigger_error('NO_POST_SELECTED');
  134. }
  135. include($phpbb_root_path . 'includes/prime_trash_bin_b.' . $phpEx);
  136. mcp_unstifle_post($post_ids);
  137. break;
  138. //-- end: Prime Trash Bin (Topics) ------------------------------------------//
  139. }
  140. switch ($mode)
  141. {
  142. case 'front':
  143. include($phpbb_root_path . 'includes/mcp/mcp_front.' . $phpEx);
  144. $user->add_lang('acp/common');
  145. mcp_front_view($id, $mode, $action);
  146. $this->tpl_name = 'mcp_front';
  147. $this->page_title = 'MCP_MAIN';
  148. break;
  149. case 'forum_view':
  150. include($phpbb_root_path . 'includes/mcp/mcp_forum.' . $phpEx);
  151. $user->add_lang('viewforum');
  152. $forum_id = request_var('f', 0);
  153. $forum_info = get_forum_data($forum_id, 'm_', true);
  154. if (!sizeof($forum_info))
  155. {
  156. $this->main('main', 'front');
  157. return;
  158. }
  159. $forum_info = $forum_info[$forum_id];
  160. mcp_forum_view($id, $mode, $action, $forum_info);
  161. $this->tpl_name = 'mcp_forum';
  162. $this->page_title = 'MCP_MAIN_FORUM_VIEW';
  163. break;
  164. case 'topic_view':
  165. include($phpbb_root_path . 'includes/mcp/mcp_topic.' . $phpEx);
  166. mcp_topic_view($id, $mode, $action);
  167. $this->tpl_name = 'mcp_topic';
  168. $this->page_title = 'MCP_MAIN_TOPIC_VIEW';
  169. break;
  170. case 'post_details':
  171. include($phpbb_root_path . 'includes/mcp/mcp_post.' . $phpEx);
  172. mcp_post_details($id, $mode, $action);
  173. $this->tpl_name = ($action == 'whois') ? 'mcp_whois' : 'mcp_post';
  174. $this->page_title = 'MCP_MAIN_POST_DETAILS';
  175. break;
  176. default:
  177. trigger_error('NO_MODE', E_USER_ERROR);
  178. break;
  179. }
  180. }
  181. }
  182. /**
  183. * Lock/Unlock Topic/Post
  184. */
  185. function lock_unlock($action, $ids)
  186. {
  187. global $auth, $user, $db, $phpEx, $phpbb_root_path;
  188. if ($action == 'lock' || $action == 'unlock')
  189. {
  190. $table = TOPICS_TABLE;
  191. $sql_id = 'topic_id';
  192. $set_id = 'topic_status';
  193. $l_prefix = 'TOPIC';
  194. }
  195. else
  196. {
  197. $table = POSTS_TABLE;
  198. $sql_id = 'post_id';
  199. $set_id = 'post_edit_locked';
  200. $l_prefix = 'POST';
  201. }
  202. $orig_ids = $ids;
  203. if (!check_ids($ids, $table, $sql_id, array('m_lock')))
  204. {
  205. // Make sure that for f_user_lock only the lock action is triggered.
  206. if ($action != 'lock')
  207. {
  208. return;
  209. }
  210. $ids = $orig_ids;
  211. if (!check_ids($ids, $table, $sql_id, array('f_user_lock')))
  212. {
  213. return;
  214. }
  215. }
  216. unset($orig_ids);
  217. $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
  218. $s_hidden_fields = build_hidden_fields(array(
  219. $sql_id . '_list' => $ids,
  220. 'action' => $action,
  221. 'redirect' => $redirect)
  222. );
  223. $success_msg = '';
  224. if (confirm_box(true))
  225. {
  226. $sql = "UPDATE $table
  227. SET $set_id = " . (($action == 'lock' || $action == 'lock_post') ? ITEM_LOCKED : ITEM_UNLOCKED) . '
  228. WHERE ' . $db->sql_in_set($sql_id, $ids);
  229. $db->sql_query($sql);
  230. $data = ($action == 'lock' || $action == 'unlock') ? get_topic_data($ids) : get_post_data($ids);
  231. foreach ($data as $id => $row)
  232. {
  233. add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_' . strtoupper($action), $row['topic_title']);
  234. }
  235. $success_msg = $l_prefix . ((sizeof($ids) == 1) ? '' : 'S') . '_' . (($action == 'lock' || $action == 'lock_post') ? 'LOCKED' : 'UNLOCKED') . '_SUCCESS';
  236. }
  237. else
  238. {
  239. confirm_box(false, strtoupper($action) . '_' . $l_prefix . ((sizeof($ids) == 1) ? '' : 'S'), $s_hidden_fields);
  240. }
  241. $redirect = request_var('redirect', "index.$phpEx");
  242. $redirect = reapply_sid($redirect);
  243. if (!$success_msg)
  244. {
  245. redirect($redirect);
  246. }
  247. else
  248. {
  249. meta_refresh(2, $redirect);
  250. trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
  251. }
  252. }
  253. /**
  254. * Change Topic Type
  255. */
  256. function change_topic_type($action, $topic_ids)
  257. {
  258. global $auth, $user, $db, $phpEx, $phpbb_root_path;
  259. // For changing topic types, we only allow operations in one forum.
  260. $forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('f_announce', 'f_sticky', 'm_'), true);
  261. if ($forum_id === false)
  262. {
  263. return;
  264. }
  265. switch ($action)
  266. {
  267. case 'make_announce':
  268. $new_topic_type = POST_ANNOUNCE;
  269. $check_acl = 'f_announce';
  270. $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_ANNOUNCEMENT' : 'MCP_MAKE_ANNOUNCEMENTS';
  271. break;
  272. case 'make_global':
  273. $new_topic_type = POST_GLOBAL;
  274. $check_acl = 'f_announce';
  275. $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_GLOBAL' : 'MCP_MAKE_GLOBALS';
  276. break;
  277. case 'make_sticky':
  278. $new_topic_type = POST_STICKY;
  279. $check_acl = 'f_sticky';
  280. $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_STICKY' : 'MCP_MAKE_STICKIES';
  281. break;
  282. default:
  283. $new_topic_type = POST_NORMAL;
  284. $check_acl = '';
  285. $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_NORMAL' : 'MCP_MAKE_NORMALS';
  286. break;
  287. }
  288. $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
  289. $s_hidden_fields = array(
  290. 'topic_id_list' => $topic_ids,
  291. 'f' => $forum_id,
  292. 'action' => $action,
  293. 'redirect' => $redirect,
  294. );
  295. $success_msg = '';
  296. if (confirm_box(true))
  297. {
  298. if ($new_topic_type != POST_GLOBAL)
  299. {
  300. $sql = 'UPDATE ' . TOPICS_TABLE . "
  301. SET topic_type = $new_topic_type
  302. WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
  303. AND forum_id <> 0';
  304. $db->sql_query($sql);
  305. // Reset forum id if a global topic is within the array
  306. $to_forum_id = request_var('to_forum_id', 0);
  307. if ($to_forum_id)
  308. {
  309. $sql = 'UPDATE ' . TOPICS_TABLE . "
  310. SET topic_type = $new_topic_type, forum_id = $to_forum_id
  311. WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
  312. AND forum_id = 0';
  313. $db->sql_query($sql);
  314. // Update forum_ids for all posts
  315. $sql = 'UPDATE ' . POSTS_TABLE . "
  316. SET forum_id = $to_forum_id
  317. WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
  318. AND forum_id = 0';
  319. $db->sql_query($sql);
  320. // Do a little forum sync stuff
  321. $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
  322. FROM ' . TOPICS_TABLE . ' t
  323. WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
  324. $result = $db->sql_query($sql);
  325. $row_data = $db->sql_fetchrow($result);
  326. $db->sql_freeresult($result);
  327. $sync_sql = array();
  328. if ($row_data['topic_posts'])
  329. {
  330. $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . (int) $row_data['topic_posts'];
  331. }
  332. if ($row_data['topics_authed'])
  333. {
  334. $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $row_data['topics_authed'];
  335. }
  336. $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) sizeof($topic_ids);
  337. foreach ($sync_sql as $forum_id_key => $array)
  338. {
  339. $sql = 'UPDATE ' . FORUMS_TABLE . '
  340. SET ' . implode(', ', $array) . '
  341. WHERE forum_id = ' . $forum_id_key;
  342. $db->sql_query($sql);
  343. }
  344. sync('forum', 'forum_id', $to_forum_id);
  345. }
  346. }
  347. else
  348. {
  349. // Get away with those topics already being a global announcement by re-calculating $topic_ids
  350. $sql = 'SELECT topic_id
  351. FROM ' . TOPICS_TABLE . '
  352. WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
  353. AND forum_id <> 0';
  354. $result = $db->sql_query($sql);
  355. $topic_ids = array();
  356. while ($row = $db->sql_fetchrow($result))
  357. {
  358. $topic_ids[] = $row['topic_id'];
  359. }
  360. $db->sql_freeresult($result);
  361. if (sizeof($topic_ids))
  362. {
  363. // Delete topic shadows for global announcements
  364. $sql = 'DELETE FROM ' . TOPICS_TABLE . '
  365. WHERE ' . $db->sql_in_set('topic_moved_id', $topic_ids);
  366. $db->sql_query($sql);
  367. $sql = 'UPDATE ' . TOPICS_TABLE . "
  368. SET topic_type = $new_topic_type, forum_id = 0
  369. WHERE " . $db->sql_in_set('topic_id', $topic_ids);
  370. $db->sql_query($sql);
  371. // Update forum_ids for all posts
  372. $sql = 'UPDATE ' . POSTS_TABLE . '
  373. SET forum_id = 0
  374. WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
  375. $db->sql_query($sql);
  376. // Do a little forum sync stuff
  377. $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
  378. FROM ' . TOPICS_TABLE . ' t
  379. WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
  380. $result = $db->sql_query($sql);
  381. $row_data = $db->sql_fetchrow($result);
  382. $db->sql_freeresult($result);
  383. $sync_sql = array();
  384. if ($row_data['topic_posts'])
  385. {
  386. $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts'];
  387. }
  388. if ($row_data['topics_authed'])
  389. {
  390. $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $row_data['topics_authed'];
  391. }
  392. $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) sizeof($topic_ids);
  393. foreach ($sync_sql as $forum_id_key => $array)
  394. {
  395. $sql = 'UPDATE ' . FORUMS_TABLE . '
  396. SET ' . implode(', ', $array) . '
  397. WHERE forum_id = ' . $forum_id_key;
  398. $db->sql_query($sql);
  399. }
  400. sync('forum', 'forum_id', $forum_id);
  401. }
  402. }
  403. $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_TYPE_CHANGED' : 'TOPICS_TYPE_CHANGED';
  404. if (sizeof($topic_ids))
  405. {
  406. $data = get_topic_data($topic_ids);
  407. foreach ($data as $topic_id => $row)
  408. {
  409. add_log('mod', $forum_id, $topic_id, 'LOG_TOPIC_TYPE_CHANGED', $row['topic_title']);
  410. }
  411. }
  412. }
  413. else
  414. {
  415. // Global topic involved?
  416. $global_involved = false;
  417. if ($new_topic_type != POST_GLOBAL)
  418. {
  419. $sql = 'SELECT forum_id
  420. FROM ' . TOPICS_TABLE . '
  421. WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
  422. AND forum_id = 0';
  423. $result = $db->sql_query($sql);
  424. $row = $db->sql_fetchrow($result);
  425. $db->sql_freeresult($result);
  426. if ($row)
  427. {
  428. $global_involved = true;
  429. }
  430. }
  431. if ($global_involved)
  432. {
  433. global $template;
  434. $template->assign_vars(array(
  435. 'S_FORUM_SELECT' => make_forum_select(request_var('f', $forum_id), false, false, true, true),
  436. 'S_CAN_LEAVE_SHADOW' => false,
  437. 'ADDITIONAL_MSG' => (sizeof($topic_ids) == 1) ? $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENT'] : $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENTS'])
  438. );
  439. confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields), 'mcp_move.html');
  440. }
  441. else
  442. {
  443. confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields));
  444. }
  445. }
  446. $redirect = request_var('redirect', "index.$phpEx");
  447. $redirect = reapply_sid($redirect);
  448. if (!$success_msg)
  449. {
  450. redirect($redirect);
  451. }
  452. else
  453. {
  454. meta_refresh(2, $redirect);
  455. trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
  456. }
  457. }
  458. /**
  459. * Move Topic
  460. */
  461. function mcp_move_topic($topic_ids)
  462. {
  463. global $auth, $user, $db, $template;
  464. global $phpEx, $phpbb_root_path;
  465. // Here we limit the operation to one forum only
  466. $forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_move'), true);
  467. if ($forum_id === false)
  468. {
  469. return;
  470. }
  471. $to_forum_id = request_var('to_forum_id', 0);
  472. $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
  473. $additional_msg = $success_msg = '';
  474. $s_hidden_fields = build_hidden_fields(array(
  475. 'topic_id_list' => $topic_ids,
  476. 'f' => $forum_id,
  477. 'action' => 'move',
  478. 'redirect' => $redirect)
  479. );
  480. if ($to_forum_id)
  481. {
  482. $forum_data = get_forum_data($to_forum_id, 'f_post');
  483. if (!sizeof($forum_data))
  484. {
  485. $additional_msg = $user->lang['FORUM_NOT_EXIST'];
  486. }
  487. else
  488. {
  489. $forum_data = $forum_data[$to_forum_id];
  490. if ($forum_data['forum_type'] != FORUM_POST)
  491. {
  492. $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
  493. }
  494. else if (!$auth->acl_get('f_post', $to_forum_id) || (!$auth->acl_get('m_approve', $to_forum_id) && !$auth->acl_get('f_noapprove', $to_forum_id)))
  495. {
  496. $additional_msg = $user->lang['USER_CANNOT_POST'];
  497. }
  498. else if ($forum_id == $to_forum_id)
  499. {
  500. $additional_msg = $user->lang['CANNOT_MOVE_SAME_FORUM'];
  501. }
  502. }
  503. }
  504. else if (isset($_POST['confirm']))
  505. {
  506. $additional_msg = $user->lang['FORUM_NOT_EXIST'];
  507. }
  508. if (!$to_forum_id || $additional_msg)
  509. {
  510. unset($_POST['confirm']);
  511. unset($_REQUEST['confirm_key']);
  512. }
  513. if (confirm_box(true))
  514. {
  515. $topic_data = get_topic_data($topic_ids);
  516. $leave_shadow = (isset($_POST['move_leave_shadow'])) ? true : false;
  517. $forum_sync_data = array();
  518. $forum_sync_data[$forum_id] = current($topic_data);
  519. $forum_sync_data[$to_forum_id] = $forum_data;
  520. // Real topics added to target forum
  521. $topics_moved = sizeof($topic_data);
  522. // Approved topics added to target forum
  523. $topics_authed_moved = 0;
  524. // Posts (topic replies + topic post if approved) added to target forum
  525. $topic_posts_added = 0;
  526. // Posts (topic replies + topic post if approved and not global announcement) removed from source forum
  527. $topic_posts_removed = 0;
  528. // Real topics removed from source forum (all topics without global announcements)
  529. $topics_removed = 0;
  530. // Approved topics removed from source forum (except global announcements)
  531. $topics_authed_removed = 0;
  532. foreach ($topic_data as $topic_id => $topic_info)
  533. {
  534. if ($topic_info['topic_approved'])
  535. {
  536. $topics_authed_moved++;
  537. $topic_posts_added++;
  538. }
  539. $topic_posts_added += $topic_info['topic_replies'];
  540. if ($topic_info['topic_type'] != POST_GLOBAL)
  541. {
  542. $topics_removed++;
  543. $topic_posts_removed += $topic_info['topic_replies'];
  544. if ($topic_info['topic_approved'])
  545. {
  546. $topics_authed_removed++;
  547. $topic_posts_removed++;
  548. }
  549. }
  550. }
  551. $db->sql_transaction('begin');
  552. $sync_sql = array();
  553. if ($topic_posts_added)
  554. {
  555. $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $topic_posts_added;
  556. }
  557. if ($topics_authed_moved)
  558. {
  559. $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_authed_moved;
  560. }
  561. $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved;
  562. // Move topics, but do not resync yet
  563. move_topics($topic_ids, $to_forum_id, false);
  564. $forum_ids = array($to_forum_id);
  565. foreach ($topic_data as $topic_id => $row)
  566. {
  567. // Get the list of forums to resync, add a log entry
  568. $forum_ids[] = $row['forum_id'];
  569. add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name'], $forum_data['forum_name']);
  570. // If we have moved a global announcement, we need to correct the topic type
  571. if ($row['topic_type'] == POST_GLOBAL)
  572. {
  573. $sql = 'UPDATE ' . TOPICS_TABLE . '
  574. SET topic_type = ' . POST_ANNOUNCE . '
  575. WHERE topic_id = ' . (int) $row['topic_id'];
  576. $db->sql_query($sql);
  577. }
  578. // Leave a redirection if required and only if the topic is visible to users
  579. if ($leave_shadow && $row['topic_approved'] && $row['topic_type'] != POST_GLOBAL)
  580. {
  581. $shadow = array(
  582. 'forum_id' => (int) $row['forum_id'],
  583. 'icon_id' => (int) $row['icon_id'],
  584. 'topic_attachment' => (int) $row['topic_attachment'],
  585. 'topic_approved' => 1, // a shadow topic is always approved
  586. 'topic_reported' => 0, // a shadow topic is never reported
  587. 'topic_title' => (string) $row['topic_title'],
  588. 'topic_poster' => (int) $row['topic_poster'],
  589. 'topic_time' => (int) $row['topic_time'],
  590. 'topic_time_limit' => (int) $row['topic_time_limit'],
  591. 'topic_views' => (int) $row['topic_views'],
  592. 'topic_replies' => (int) $row['topic_replies'],
  593. 'topic_replies_real' => (int) $row['topic_replies_real'],
  594. 'topic_status' => ITEM_MOVED,
  595. 'topic_type' => POST_NORMAL,
  596. 'topic_first_post_id' => (int) $row['topic_first_post_id'],
  597. 'topic_first_poster_colour'=>(string) $row['topic_first_poster_colour'],
  598. 'topic_first_poster_name'=> (string) $row['topic_first_poster_name'],
  599. 'topic_last_post_id' => (int) $row['topic_last_post_id'],
  600. 'topic_last_poster_id' => (int) $row['topic_last_poster_id'],
  601. 'topic_last_poster_colour'=>(string) $row['topic_last_poster_colour'],
  602. 'topic_last_poster_name'=> (string) $row['topic_last_poster_name'],
  603. 'topic_last_post_subject'=> (string) $row['topic_last_post_subject'],
  604. 'topic_last_post_time' => (int) $row['topic_last_post_time'],
  605. 'topic_last_view_time' => (int) $row['topic_last_view_time'],
  606. 'topic_moved_id' => (int) $row['topic_id'],
  607. 'topic_bumped' => (int) $row['topic_bumped'],
  608. 'topic_bumper' => (int) $row['topic_bumper'],
  609. 'poll_title' => (string) $row['poll_title'],
  610. 'poll_start' => (int) $row['poll_start'],
  611. 'poll_length' => (int) $row['poll_length'],
  612. 'poll_max_options' => (int) $row['poll_max_options'],
  613. 'poll_last_vote' => (int) $row['poll_last_vote']
  614. );
  615. $db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow));
  616. // Shadow topics only count on new "topics" and not posts... a shadow topic alone has 0 posts
  617. $topics_removed--;
  618. $topics_authed_removed--;
  619. }
  620. }
  621. unset($topic_data);
  622. if ($topic_posts_removed)
  623. {
  624. $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . $topic_posts_removed;
  625. }
  626. if ($topics_removed)
  627. {
  628. $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) $topics_removed;
  629. }
  630. if ($topics_authed_removed)
  631. {
  632. $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $topics_authed_removed;
  633. }
  634. $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS';
  635. foreach ($sync_sql as $forum_id_key => $array)
  636. {
  637. $sql = 'UPDATE ' . FORUMS_TABLE . '
  638. SET ' . implode(', ', $array) . '
  639. WHERE forum_id = ' . $forum_id_key;
  640. $db->sql_query($sql);
  641. }
  642. $db->sql_transaction('commit');
  643. sync('forum', 'forum_id', array($forum_id, $to_forum_id));
  644. }
  645. else
  646. {
  647. $template->assign_vars(array(
  648. 'S_FORUM_SELECT' => make_forum_select($to_forum_id, $forum_id, false, true, true, true),
  649. 'S_CAN_LEAVE_SHADOW' => true,
  650. 'ADDITIONAL_MSG' => $additional_msg)
  651. );
  652. confirm_box(false, 'MOVE_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
  653. }
  654. $redirect = request_var('redirect', "index.$phpEx");
  655. $redirect = reapply_sid($redirect);
  656. if (!$success_msg)
  657. {
  658. redirect($redirect);
  659. }
  660. else
  661. {
  662. meta_refresh(3, $redirect);
  663. $message = $user->lang[$success_msg];
  664. $message .= '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
  665. $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id") . '">', '</a>');
  666. $message .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$to_forum_id") . '">', '</a>');
  667. trigger_error($message);
  668. }
  669. }
  670. /**
  671. * Delete Topics
  672. */
  673. function mcp_delete_topic($topic_ids)
  674. {
  675. global $auth, $user, $db, $phpEx, $phpbb_root_path;
  676. if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete')))
  677. {
  678. return;
  679. }
  680. $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
  681. $forum_id = request_var('f', 0);
  682. $s_hidden_fields = build_hidden_fields(array(
  683. 'topic_id_list' => $topic_ids,
  684. 'f' => $forum_id,
  685. 'action' => 'delete_topic',
  686. 'redirect' => $redirect)
  687. );
  688. $success_msg = '';
  689. if (confirm_box(true))
  690. {
  691. $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS';
  692. $data = get_topic_data($topic_ids);
  693. foreach ($data as $topic_id => $row)
  694. {
  695. if ($row['topic_moved_id'])
  696. {
  697. add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_SHADOW_TOPIC', $row['topic_title']);
  698. }
  699. else
  700. {
  701. add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']);
  702. }
  703. }
  704. $return = delete_topics('topic_id', $topic_ids);
  705. }
  706. else
  707. {
  708. confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields);
  709. }
  710. if (!isset($_REQUEST['quickmod']))
  711. {
  712. $redirect = request_var('redirect', "index.$phpEx");
  713. $redirect = reapply_sid($redirect);
  714. $redirect_message = 'PAGE';
  715. }
  716. else
  717. {
  718. $redirect = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
  719. $redirect_message = 'FORUM';
  720. }
  721. if (!$success_msg)
  722. {
  723. redirect($redirect);
  724. }
  725. else
  726. {
  727. meta_refresh(3, $redirect);
  728. trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_' . $redirect_message], '<a href="' . $redirect . '">', '</a>'));
  729. }
  730. }
  731. /**
  732. * Delete Posts
  733. */
  734. function mcp_delete_post($post_ids)
  735. {
  736. global $auth, $user, $db, $phpEx, $phpbb_root_path;
  737. if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_delete')))
  738. {
  739. return;
  740. }
  741. $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
  742. $forum_id = request_var('f', 0);
  743. $s_hidden_fields = build_hidden_fields(array(
  744. 'post_id_list' => $post_ids,
  745. 'f' => $forum_id,
  746. 'action' => 'delete_post',
  747. 'redirect' => $redirect)
  748. );
  749. $success_msg = '';
  750. if (confirm_box(true))
  751. {
  752. if (!function_exists('delete_posts'))
  753. {
  754. include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
  755. }
  756. // Count the number of topics that are affected
  757. // I did not use COUNT(DISTINCT ...) because I remember having problems
  758. // with it on older versions of MySQL -- Ashe
  759. $sql = 'SELECT DISTINCT topic_id
  760. FROM ' . POSTS_TABLE . '
  761. WHERE ' . $db->sql_in_set('post_id', $post_ids);
  762. $result = $db->sql_query($sql);
  763. $topic_id_list = array();
  764. while ($row = $db->sql_fetchrow($result))
  765. {
  766. $topic_id_list[] = $row['topic_id'];
  767. }
  768. $affected_topics = sizeof($topic_id_list);
  769. $db->sql_freeresult($result);
  770. $post_data = get_post_data($post_ids);
  771. foreach ($post_data as $id => $row)
  772. {
  773. $post_username = ($row['poster_id'] == ANONYMOUS && !empty($row['post_username'])) ? $row['post_username'] : $row['username'];
  774. add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_DELETE_POST', $row['post_subject'], $post_username);
  775. }
  776. // Now delete the posts, topics and forums are automatically resync'ed
  777. delete_posts('post_id', $post_ids);
  778. $sql = 'SELECT COUNT(topic_id) AS topics_left
  779. FROM ' . TOPICS_TABLE . '
  780. WHERE ' . $db->sql_in_set('topic_id', $topic_id_list);
  781. $result = $db->sql_query_limit($sql, 1);
  782. $deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics;
  783. $db->sql_freeresult($result);
  784. $topic_id = request_var('t', 0);
  785. // Return links
  786. $return_link = array();
  787. if ($affected_topics == 1 && !$deleted_topics && $topic_id)
  788. {
  789. $return_link[] = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id") . '">', '</a>');
  790. }
  791. $return_link[] = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
  792. if (sizeof($post_ids) == 1)
  793. {
  794. if ($deleted_topics)
  795. {
  796. // We deleted the only post of a topic, which in turn has
  797. // been removed from the database
  798. $success_msg = $user->lang['TOPIC_DELETED_SUCCESS'];
  799. }
  800. else
  801. {
  802. $success_msg = $user->lang['POST_DELETED_SUCCESS'];
  803. }
  804. }
  805. else
  806. {
  807. if ($deleted_topics)
  808. {
  809. // Some of topics disappeared
  810. $success_msg = $user->lang['POSTS_DELETED_SUCCESS'] . '<br /><br />' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING'];
  811. }
  812. else
  813. {
  814. $success_msg = $user->lang['POSTS_DELETED_SUCCESS'];
  815. }
  816. }
  817. }
  818. else
  819. {
  820. confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields);
  821. }
  822. $redirect = request_var('redirect', "index.$phpEx");
  823. $redirect = reapply_sid($redirect);
  824. if (!$success_msg)
  825. {
  826. redirect($redirect);
  827. }
  828. else
  829. {
  830. if ($affected_topics != 1 || $deleted_topics || !$topic_id)
  831. {
  832. $redirect = append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&i=main&mode=forum_view", false);
  833. }
  834. meta_refresh(3, $redirect);
  835. trigger_error($success_msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>') . '<br /><br />' . implode('<br /><br />', $return_link));
  836. }
  837. }
  838. /**
  839. * Fork Topic
  840. */
  841. function mcp_fork_topic($topic_ids)
  842. {
  843. global $auth, $user, $db, $template, $config;
  844. global $phpEx, $phpbb_root_path;
  845. if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_')))
  846. {
  847. return;
  848. }
  849. $to_forum_id = request_var('to_forum_id', 0);
  850. $forum_id = request_var('f', 0);
  851. $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
  852. $additional_msg = $success_msg = '';
  853. $s_hidden_fields = build_hidden_fields(array(
  854. 'topic_id_list' => $topic_ids,
  855. 'f' => $forum_id,
  856. 'action' => 'fork',
  857. 'redirect' => $redirect)
  858. );
  859. if ($to_forum_id)
  860. {
  861. $forum_data = get_forum_data($to_forum_id, 'f_post');
  862. if (!sizeof($topic_ids))
  863. {
  864. $additional_msg = $user->lang['NO_TOPIC_SELECTED'];
  865. }
  866. else if (!sizeof($forum_data))
  867. {
  868. $additional_msg = $user->lang['FORUM_NOT_EXIST'];
  869. }
  870. else
  871. {
  872. $forum_data = $forum_data[$to_forum_id];
  873. if ($forum_data['forum_type'] != FORUM_POST)
  874. {
  875. $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
  876. }
  877. else if (!$auth->acl_get('f_post', $to_forum_id))
  878. {
  879. $additional_msg = $user->lang['USER_CANNOT_POST'];
  880. }
  881. }
  882. }
  883. else if (isset($_POST['confirm']))
  884. {
  885. $additional_msg = $user->lang['FORUM_NOT_EXIST'];
  886. }
  887. if ($additional_msg)
  888. {
  889. unset($_POST['confirm']);
  890. unset($_REQUEST['confirm_key']);
  891. }
  892. if (confirm_box(true))
  893. {
  894. $topic_data = get_topic_data($topic_ids, 'f_post');
  895. $total_posts = 0;
  896. $new_topic_id_list = array();
  897. foreach ($topic_data as $topic_id => $topic_row)
  898. {
  899. if (!isset($search_type) && $topic_row['enable_indexing'])
  900. {
  901. // Select the search method and do some additional checks to ensure it can actually be utilised
  902. $search_type = basename($config['search_type']);
  903. if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
  904. {
  905. trigger_error('NO_SUCH_SEARCH_MODULE');
  906. }
  907. if (!class_exists($search_type))
  908. {
  909. include("{$phpbb_root_path}includes/search/$search_type.$phpEx");
  910. }
  911. $error = false;
  912. $search = new $search_type($error);
  913. $search_mode = 'post';
  914. if ($error)
  915. {
  916. trigger_error($error);
  917. }
  918. }
  919. else if (!isset($search_type) && !$topic_row['enable_indexing'])
  920. {
  921. $search_type = false;
  922. }
  923. $sql_ary = array(
  924. 'forum_id' => (int) $to_forum_id,
  925. 'icon_id' => (int) $topic_row['icon_id'],
  926. 'topic_attachment' => (int) $topic_row['topic_attachment'],
  927. 'topic_approved' => 1,
  928. 'topic_reported' => 0,
  929. 'topic_title' => (string) $topic_row['topic_title'],
  930. 'topic_poster' => (int) $topic_row['topic_poster'],
  931. 'topic_time' => (int) $topic_row['topic_time'],
  932. 'topic_replies' => (int) $topic_row['topic_replies_real'],
  933. 'topic_replies_real' => (int) $topic_row['topic_replies_real'],
  934. 'topic_status' => (int) $topic_row['topic_status'],
  935. 'topic_type' => (int) $topic_row['topic_type'],
  936. 'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'],
  937. 'topic_last_poster_id' => (int) $topic_row['topic_last_poster_id'],
  938. 'topic_last_poster_name' => (string) $topic_row['topic_last_poster_name'],
  939. 'topic_last_post_time' => (int) $topic_row['topic_last_post_time'],
  940. 'topic_last_view_time' => (int) $topic_row['topic_last_view_time'],
  941. 'topic_bumped' => (int) $topic_row['topic_bumped'],
  942. 'topic_bumper' => (int) $topic_row['topic_bumper'],
  943. 'poll_title' => (string) $topic_row['poll_title'],
  944. 'poll_start' => (int) $topic_row['poll_start'],
  945. 'poll_length' => (int) $topic_row['poll_length'],
  946. 'poll_max_options' => (int) $topic_row['poll_max_options'],
  947. 'poll_vote_change' => (int) $topic_row['poll_vote_change'],
  948. );
  949. $db->sql_query('INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
  950. $new_topic_id = $db->sql_nextid();
  951. $new_topic_id_list[$topic_id] = $new_topic_id;
  952. if ($topic_row['poll_start'])
  953. {
  954. $poll_rows = array();
  955. $sql = 'SELECT *
  956. FROM ' . POLL_OPTIONS_TABLE . "
  957. WHERE topic_id = $topic_id";
  958. $result = $db->sql_query($sql);
  959. while ($row = $db->sql_fetchrow($result))
  960. {
  961. $sql_ary = array(
  962. 'poll_option_id' => (int) $row['poll_option_id'],
  963. 'topic_id' => (int) $new_topic_id,
  964. 'poll_option_text' => (string) $row['poll_option_text'],
  965. 'poll_option_total' => 0
  966. );
  967. $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
  968. }
  969. }
  970. $sql = 'SELECT *
  971. FROM ' . POSTS_TABLE . "
  972. WHERE topic_id = $topic_id
  973. ORDER BY post_time ASC";
  974. $result = $db->sql_query($sql);
  975. $post_rows = array();
  976. while ($row = $db->sql_fetchrow($result))
  977. {
  978. $post_rows[] = $row;
  979. }
  980. $db->sql_freeresult($result);
  981. if (!sizeof($post_rows))
  982. {
  983. continue;
  984. }
  985. $total_posts += sizeof($post_rows);
  986. foreach ($post_rows as $row)
  987. {
  988. $sql_ary = array(
  989. 'topic_id' => (int) $new_topic_id,
  990. 'forum_id' => (int) $to_forum_id,
  991. 'poster_id' => (int) $row['poster_id'],
  992. 'icon_id' => (int) $row['icon_id'],
  993. 'poster_ip' => (string) $row['poster_ip'],
  994. 'post_time' => (int) $row['post_time'],
  995. 'post_approved' => 1,
  996. 'post_reported' => 0,
  997. 'enable_bbcode' => (int) $row['enable_bbcode'],
  998. 'enable_smilies' => (int) $row['enable_smilies'],
  999. 'enable_magic_url' => (int) $row['enable_magic_url'],
  1000. 'enable_sig' => (int) $row['enable_sig'],
  1001. 'post_username' => (string) $row['post_username'],
  1002. 'post_subject' => (string) $row['post_subject'],
  1003. 'post_text' => (string) $row['post_text'],
  1004. 'post_edit_reason' => (string) $row['post_edit_reason'],
  1005. 'post_edit_user' => (int) $row['post_edit_user'],
  1006. 'post_checksum' => (string) $row['post_checksum'],
  1007. 'post_attachment' => (int) $row['post_attachment'],
  1008. 'bbcode_bitfield' => $row['bbcode_bitfield'],
  1009. 'bbcode_uid' => (string) $row['bbcode_uid'],
  1010. 'post_edit_time' => (int) $row['post_edit_time'],
  1011. 'post_edit_count' => (int) $row['post_edit_count'],
  1012. 'post_edit_locked' => (int) $row['post_edit_locked'],
  1013. 'post_postcount' => 0,
  1014. );
  1015. $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
  1016. $new_post_id = $db->sql_nextid();
  1017. // Copy whether the topic is dotted
  1018. markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']);
  1019. if (!empty($search_type))
  1020. {
  1021. $search->index($search_mode, $new_post_id, $sql_ary['post_text'], $sql_ary['post_subject'], $sql_ary['poster_id'], ($topic_row['topic_type'] == POST_GLOBAL) ? 0 : $to_forum_id);
  1022. $search_mode = 'reply'; // After one we index replies
  1023. }
  1024. // Copy Attachments
  1025. if ($row['post_attachment'])
  1026. {
  1027. $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . "
  1028. WHERE post_msg_id = {$row['post_id']}
  1029. AND topic_id = $topic_id
  1030. AND in_message = 0";
  1031. $result = $db->sql_query($sql);
  1032. $sql_ary = array();
  1033. while ($attach_row = $db->sql_fetchrow($result))
  1034. {
  1035. $sql_ary[] = array(
  1036. 'post_msg_id' => (int) $new_post_id,
  1037. 'topic_id' => (int) $new_topic_id,
  1038. 'in_message' => 0,
  1039. 'is_orphan' => (int) $attach_row['is_orphan'],
  1040. 'poster_id' => (int) $attach_row['poster_id'],
  1041. 'physical_filename' => (string) utf8_basename($attach_row['physical_filename']),
  1042. 'real_filename' => (string) utf8_basename($attach_row['real_filename']),
  1043. 'download_count' => (int) $attach_row['download_count'],
  1044. 'attach_comment' => (string) $attach_row['attach_comment'],
  1045. 'extension' => (string) $attach_row['extension'],
  1046. 'mimetype' => (string) $attach_row['mimetype'],
  1047. 'filesize' => (int) $attach_row['filesize'],
  1048. 'filetime' => (int) $attach_row['filetime'],
  1049. 'thumbnail' => (int) $attach_row['thumbnail']
  1050. );
  1051. }
  1052. $db->sql_freeresult($result);
  1053. if (sizeof($sql_ary))
  1054. {
  1055. $db->sql_multi_insert(ATTACHMENTS_TABLE, $sql_ary);
  1056. }
  1057. }
  1058. }
  1059. $sql = 'SELECT user_id, notify_status
  1060. FROM ' . TOPICS_WATCH_TABLE . '
  1061. WHERE topic_id = ' . $topic_id;
  1062. $result = $db->sql_query($sql);
  1063. $sql_ary = array();
  1064. while ($row = $db->sql_fetchrow($result))
  1065. {
  1066. $sql_ary[] = array(
  1067. 'topic_id' => (int) $new_topic_id,
  1068. 'user_id' => (int) $row['user_id'],
  1069. 'notify_status' => (int) $row['notify_status'],
  1070. );
  1071. }
  1072. $db->sql_freeresult($result);
  1073. if (sizeof($sql_ary))
  1074. {
  1075. $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
  1076. }
  1077. }
  1078. // Sync new topics, parent forums and board stats
  1079. sync('topic', 'topic_id', $new_topic_id_list);
  1080. $sync_sql = array();
  1081. $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $total_posts;
  1082. $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . sizeof($new_topic_id_list);
  1083. $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . sizeof($new_topic_id_list);
  1084. foreach ($sync_sql as $forum_id_key => $array)
  1085. {
  1086. $sql = 'UPDATE ' . FORUMS_TABLE . '
  1087. SET ' . implode(', ', $array) . '
  1088. WHERE forum_id = ' . $forum_id_key;
  1089. $db->sql_query($sql);
  1090. }
  1091. sync('forum', 'forum_id', $to_forum_id);
  1092. set_config_count('num_topics', sizeof($new_topic_id_list), true);
  1093. set_config_count('num_posts', $total_posts, true);
  1094. foreach ($new_topic_id_list as $topic_id => $new_topic_id)
  1095. {
  1096. add_log('mod', $to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']);
  1097. }
  1098. $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS';
  1099. }
  1100. else
  1101. {
  1102. $template->assign_vars(array(
  1103. 'S_FORUM_SELECT' => make_forum_select($to_forum_id, false, false, true, true, true),
  1104. 'S_CAN_LEAVE_SHADOW' => false,
  1105. 'ADDITIONAL_MSG' => $additional_msg)
  1106. );
  1107. confirm_box(false, 'FORK_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
  1108. }
  1109. $redirect = request_var('redirect', "index.$phpEx");
  1110. $redirect = reapply_sid($redirect);
  1111. if (!$success_msg)
  1112. {
  1113. redirect($redirect);
  1114. }
  1115. else
  1116. {
  1117. $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
  1118. meta_refresh(3, $redirect_url);
  1119. $return_link = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>');
  1120. if ($forum_id != $to_forum_id)
  1121. {
  1122. $return_link .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $to_forum_id) . '">', '</a>');
  1123. }
  1124. trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
  1125. }
  1126. }
  1127. ?>