Advertisement
Guest User

Untitled

a guest
May 30th, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 64.38 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @package acp
  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. */
  14. if (!defined('IN_PHPBB'))
  15. {
  16. exit;
  17. }
  18.  
  19. /**
  20. * @package acp
  21. */
  22. class acp_forums
  23. {
  24. var $u_action;
  25. var $parent_id = 0;
  26.  
  27. function main($id, $mode)
  28. {
  29. global $db, $user, $auth, $template, $cache;
  30. global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
  31.  
  32. $user->add_lang('acp/forums');
  33. $this->tpl_name = 'acp_forums';
  34. $this->page_title = 'ACP_MANAGE_FORUMS';
  35.  
  36. $form_key = 'acp_forums';
  37. add_form_key($form_key);
  38.  
  39. $action = request_var('action', '');
  40. $update = (isset($_POST['update'])) ? true : false;
  41. $forum_id = request_var('f', 0);
  42.  
  43. $this->parent_id = request_var('parent_id', 0);
  44. $forum_data = $errors = array();
  45. if ($update && !check_form_key($form_key))
  46. {
  47. $update = false;
  48. $errors[] = $user->lang['FORM_INVALID'];
  49. }
  50.  
  51. // Check additional permissions
  52. switch ($action)
  53. {
  54. case 'progress_bar':
  55. $start = request_var('start', 0);
  56. $total = request_var('total', 0);
  57.  
  58. $this->display_progress_bar($start, $total);
  59. exit;
  60. break;
  61.  
  62. case 'delete':
  63.  
  64. if (!$auth->acl_get('a_forumdel'))
  65. {
  66. trigger_error($user->lang['NO_PERMISSION_FORUM_DELETE'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  67. }
  68.  
  69. break;
  70.  
  71. case 'add':
  72.  
  73. if (!$auth->acl_get('a_forumadd'))
  74. {
  75. trigger_error($user->lang['NO_PERMISSION_FORUM_ADD'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  76. }
  77.  
  78. break;
  79. }
  80.  
  81. // Major routines
  82. if ($update)
  83. {
  84. switch ($action)
  85. {
  86. case 'delete':
  87. $action_subforums = request_var('action_subforums', '');
  88. $subforums_to_id = request_var('subforums_to_id', 0);
  89. $action_posts = request_var('action_posts', '');
  90. $posts_to_id = request_var('posts_to_id', 0);
  91.  
  92. $errors = $this->delete_forum($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id);
  93.  
  94. if (sizeof($errors))
  95. {
  96. break;
  97. }
  98.  
  99. $auth->acl_clear_prefetch();
  100. $cache->destroy('sql', FORUMS_TABLE);
  101.  
  102. trigger_error($user->lang['FORUM_DELETED'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
  103.  
  104. break;
  105.  
  106. case 'edit':
  107. $forum_data = array(
  108. 'forum_id' => $forum_id
  109. );
  110.  
  111. // No break here
  112.  
  113. case 'add':
  114.  
  115. $forum_data += array(
  116. 'parent_id' => request_var('forum_parent_id', $this->parent_id),
  117. 'forum_type' => request_var('forum_type', FORUM_POST),
  118. 'type_action' => request_var('type_action', ''),
  119. 'forum_status' => request_var('forum_status', ITEM_UNLOCKED),
  120. 'forum_parents' => '',
  121. 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
  122. 'forum_link' => request_var('forum_link', ''),
  123. 'forum_link_track' => request_var('forum_link_track', false),
  124. 'forum_desc' => utf8_normalize_nfc(request_var('forum_desc', '', true)),
  125. 'forum_desc_uid' => '',
  126. 'forum_desc_options' => 7,
  127. 'forum_desc_bitfield' => '',
  128. 'forum_rules' => utf8_normalize_nfc(request_var('forum_rules', '', true)),
  129. 'forum_rules_uid' => '',
  130. 'forum_rules_options' => 7,
  131. 'forum_rules_bitfield' => '',
  132. 'forum_rules_link' => request_var('forum_rules_link', ''),
  133. 'forum_image' => request_var('forum_image', ''),
  134. 'forum_style' => request_var('forum_style', 0),
  135. 'display_subforum_list' => request_var('display_subforum_list', false),
  136. 'display_on_index' => request_var('display_on_index', false),
  137. 'forum_topics_per_page' => request_var('topics_per_page', 0),
  138. 'enable_indexing' => request_var('enable_indexing', true),
  139. 'enable_icons' => request_var('enable_icons', false),
  140. 'enable_prune' => request_var('enable_prune', false),
  141. //Begin Thank Post MOD
  142. 'enable_thanks' => request_var('enable_thanks', false),
  143. //End Thank Post MOD
  144. 'enable_post_review' => request_var('enable_post_review', true),
  145. 'enable_quick_reply' => request_var('enable_quick_reply', false),
  146. 'prune_days' => request_var('prune_days', 7),
  147. 'prune_viewed' => request_var('prune_viewed', 7),
  148. 'prune_freq' => request_var('prune_freq', 1),
  149. 'prune_old_polls' => request_var('prune_old_polls', false),
  150. 'prune_announce' => request_var('prune_announce', false),
  151. 'prune_sticky' => request_var('prune_sticky', false),
  152. 'forum_password' => request_var('forum_password', '', true),
  153. 'forum_password_confirm'=> request_var('forum_password_confirm', '', true),
  154. 'forum_password_unset' => request_var('forum_password_unset', false),
  155. // Start Ultimate Points
  156. 'forum_pertopic' => request_var('forum_pertopic', 0.00),
  157. 'forum_perpost' => request_var('forum_perpost', 0.00),
  158. 'forum_peredit' => request_var('forum_peredit', 0.00),
  159. // End Ultimate Points
  160. );
  161.  
  162. // On add, add empty forum_options... else do not consider it (not updating it)
  163. if ($action == 'add')
  164. {
  165. $forum_data['forum_options'] = 0;
  166. }
  167.  
  168. // Use link_display_on_index setting if forum type is link
  169. if ($forum_data['forum_type'] == FORUM_LINK)
  170. {
  171. $forum_data['display_on_index'] = request_var('link_display_on_index', false);
  172. }
  173.  
  174. // Linked forums and categories are not able to be locked...
  175. if ($forum_data['forum_type'] == FORUM_LINK || $forum_data['forum_type'] == FORUM_CAT)
  176. {
  177. $forum_data['forum_status'] = ITEM_UNLOCKED;
  178. }
  179.  
  180. $forum_data['show_active'] = ($forum_data['forum_type'] == FORUM_POST) ? request_var('display_recent', true) : request_var('display_active', false);
  181.  
  182. // Get data for forum rules if specified...
  183. if ($forum_data['forum_rules'])
  184. {
  185. generate_text_for_storage($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options'], request_var('rules_parse_bbcode', false), request_var('rules_parse_urls', false), request_var('rules_parse_smilies', false));
  186. }
  187.  
  188. // Get data for forum description if specified
  189. if ($forum_data['forum_desc'])
  190. {
  191. generate_text_for_storage($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options'], request_var('desc_parse_bbcode', false), request_var('desc_parse_urls', false), request_var('desc_parse_smilies', false));
  192. }
  193.  
  194. $errors = $this->update_forum_data($forum_data);
  195.  
  196. if (!sizeof($errors))
  197. {
  198. $forum_perm_from = request_var('forum_perm_from', 0);
  199. $cache->destroy('sql', FORUMS_TABLE);
  200.  
  201. $copied_permissions = false;
  202. // Copy permissions?
  203. if ($forum_perm_from && $forum_perm_from != $forum_data['forum_id'] &&
  204. ($action != 'edit' || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))))
  205. {
  206. copy_forum_permissions($forum_perm_from, $forum_data['forum_id'], ($action == 'edit') ? true : false);
  207. cache_moderators();
  208. $copied_permissions = true;
  209. }
  210. /* Commented out because of questionable UI workflow - re-visit for 3.0.7
  211. else if (!$this->parent_id && $action != 'edit' && $auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))
  212. {
  213. $this->copy_permission_page($forum_data);
  214. return;
  215. }
  216. */
  217. $auth->acl_clear_prefetch();
  218.  
  219. $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_data['forum_id'];
  220.  
  221. $message = ($action == 'add') ? $user->lang['FORUM_CREATED'] : $user->lang['FORUM_UPDATED'];
  222.  
  223. // Redirect to permissions
  224. if ($auth->acl_get('a_fauth') && !$copied_permissions)
  225. {
  226. $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
  227. }
  228.  
  229. // redirect directly to permission settings screen if authed
  230. if ($action == 'add' && !$copied_permissions && $auth->acl_get('a_fauth'))
  231. {
  232. meta_refresh(4, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url));
  233. }
  234.  
  235. trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
  236. }
  237.  
  238. break;
  239. }
  240. }
  241.  
  242. switch ($action)
  243. {
  244. case 'move_up':
  245. case 'move_down':
  246.  
  247. if (!$forum_id)
  248. {
  249. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  250. }
  251.  
  252. $sql = 'SELECT *
  253. FROM ' . FORUMS_TABLE . "
  254. WHERE forum_id = $forum_id";
  255. $result = $db->sql_query($sql);
  256. $row = $db->sql_fetchrow($result);
  257. $db->sql_freeresult($result);
  258.  
  259. if (!$row)
  260. {
  261. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  262. }
  263.  
  264. $move_forum_name = $this->move_forum_by($row, $action, 1);
  265.  
  266. if ($move_forum_name !== false)
  267. {
  268. add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name);
  269. $cache->destroy('sql', FORUMS_TABLE);
  270. }
  271.  
  272. break;
  273.  
  274. case 'sync':
  275. if (!$forum_id)
  276. {
  277. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  278. }
  279.  
  280. @set_time_limit(0);
  281.  
  282. $sql = 'SELECT forum_name, forum_topics_real
  283. FROM ' . FORUMS_TABLE . "
  284. WHERE forum_id = $forum_id";
  285. $result = $db->sql_query($sql);
  286. $row = $db->sql_fetchrow($result);
  287. $db->sql_freeresult($result);
  288.  
  289. if (!$row)
  290. {
  291. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  292. }
  293.  
  294. if ($row['forum_topics_real'])
  295. {
  296. $sql = 'SELECT MIN(topic_id) as min_topic_id, MAX(topic_id) as max_topic_id
  297. FROM ' . TOPICS_TABLE . '
  298. WHERE forum_id = ' . $forum_id;
  299. $result = $db->sql_query($sql);
  300. $row2 = $db->sql_fetchrow($result);
  301. $db->sql_freeresult($result);
  302.  
  303. // Typecast to int if there is no data available
  304. $row2['min_topic_id'] = (int) $row2['min_topic_id'];
  305. $row2['max_topic_id'] = (int) $row2['max_topic_id'];
  306.  
  307. $start = request_var('start', $row2['min_topic_id']);
  308.  
  309. $batch_size = 2000;
  310. $end = $start + $batch_size;
  311.  
  312. // Sync all topics in batch mode...
  313. sync('topic_approved', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false);
  314. sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true);
  315.  
  316. if ($end < $row2['max_topic_id'])
  317. {
  318. // We really need to find a way of showing statistics... no progress here
  319. $sql = 'SELECT COUNT(topic_id) as num_topics
  320. FROM ' . TOPICS_TABLE . '
  321. WHERE forum_id = ' . $forum_id . '
  322. AND topic_id BETWEEN ' . $start . ' AND ' . $end;
  323. $result = $db->sql_query($sql);
  324. $topics_done = request_var('topics_done', 0) + (int) $db->sql_fetchfield('num_topics');
  325. $db->sql_freeresult($result);
  326.  
  327. $start += $batch_size;
  328.  
  329. $url = $this->u_action . "&amp;parent_id={$this->parent_id}&amp;f=$forum_id&amp;action=sync&amp;start=$start&amp;topics_done=$topics_done&amp;total={$row['forum_topics_real']}";
  330.  
  331. meta_refresh(0, $url);
  332.  
  333. $template->assign_vars(array(
  334. 'U_PROGRESS_BAR' => $this->u_action . "&amp;action=progress_bar&amp;start=$topics_done&amp;total={$row['forum_topics_real']}",
  335. 'UA_PROGRESS_BAR' => addslashes($this->u_action . "&amp;action=progress_bar&amp;start=$topics_done&amp;total={$row['forum_topics_real']}"),
  336. 'S_CONTINUE_SYNC' => true,
  337. 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['forum_topics_real']))
  338. );
  339.  
  340. return;
  341. }
  342. }
  343.  
  344. $url = $this->u_action . "&amp;parent_id={$this->parent_id}&amp;f=$forum_id&amp;action=sync_forum";
  345. meta_refresh(0, $url);
  346.  
  347. $template->assign_vars(array(
  348. 'U_PROGRESS_BAR' => $this->u_action . '&amp;action=progress_bar',
  349. 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&amp;action=progress_bar'),
  350. 'S_CONTINUE_SYNC' => true,
  351. 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['forum_topics_real']))
  352. );
  353.  
  354. return;
  355.  
  356. break;
  357.  
  358. case 'sync_forum':
  359.  
  360. $sql = 'SELECT forum_name, forum_type
  361. FROM ' . FORUMS_TABLE . "
  362. WHERE forum_id = $forum_id";
  363. $result = $db->sql_query($sql);
  364. $row = $db->sql_fetchrow($result);
  365. $db->sql_freeresult($result);
  366.  
  367. if (!$row)
  368. {
  369. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  370. }
  371.  
  372. sync('forum', 'forum_id', $forum_id, false, true);
  373.  
  374. add_log('admin', 'LOG_FORUM_SYNC', $row['forum_name']);
  375. $cache->destroy('sql', FORUMS_TABLE);
  376.  
  377. $template->assign_var('L_FORUM_RESYNCED', sprintf($user->lang['FORUM_RESYNCED'], $row['forum_name']));
  378.  
  379. break;
  380.  
  381. case 'add':
  382. case 'edit':
  383.  
  384. if ($update)
  385. {
  386. $forum_data['forum_flags'] = 0;
  387. $forum_data['forum_flags'] += (request_var('forum_link_track', false)) ? FORUM_FLAG_LINK_TRACK : 0;
  388. $forum_data['forum_flags'] += (request_var('prune_old_polls', false)) ? FORUM_FLAG_PRUNE_POLL : 0;
  389. $forum_data['forum_flags'] += (request_var('prune_announce', false)) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
  390. $forum_data['forum_flags'] += (request_var('prune_sticky', false)) ? FORUM_FLAG_PRUNE_STICKY : 0;
  391. $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
  392. $forum_data['forum_flags'] += (request_var('enable_post_review', true)) ? FORUM_FLAG_POST_REVIEW : 0;
  393. $forum_data['forum_flags'] += (request_var('enable_quick_reply', false)) ? FORUM_FLAG_QUICK_REPLY : 0;
  394. }
  395.  
  396. // Show form to create/modify a forum
  397. if ($action == 'edit')
  398. {
  399. $this->page_title = 'EDIT_FORUM';
  400. $row = $this->get_forum_info($forum_id);
  401. $old_forum_type = $row['forum_type'];
  402.  
  403. if (!$update)
  404. {
  405. $forum_data = $row;
  406. }
  407. else
  408. {
  409. $forum_data['left_id'] = $row['left_id'];
  410. $forum_data['right_id'] = $row['right_id'];
  411. }
  412.  
  413. // Make sure no direct child forums are able to be selected as parents.
  414. $exclude_forums = array();
  415. foreach (get_forum_branch($forum_id, 'children') as $row)
  416. {
  417. $exclude_forums[] = $row['forum_id'];
  418. }
  419.  
  420. $parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false);
  421.  
  422. $forum_data['forum_password_confirm'] = $forum_data['forum_password'];
  423. }
  424. else
  425. {
  426. $this->page_title = 'CREATE_FORUM';
  427.  
  428. $forum_id = $this->parent_id;
  429. $parents_list = make_forum_select($this->parent_id, false, false, false, false);
  430.  
  431. // Fill forum data with default values
  432. if (!$update)
  433. {
  434. $forum_data = array(
  435. 'parent_id' => $this->parent_id,
  436. 'forum_type' => FORUM_POST,
  437. 'forum_status' => ITEM_UNLOCKED,
  438. //Begin Thank Post MOD
  439. 'thanks_yes' => true,
  440. 'thanks_no' => false,
  441. //End Thank Post MOD
  442. 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
  443. 'forum_link' => '',
  444. 'forum_link_track' => false,
  445. 'forum_desc' => '',
  446. 'forum_rules' => '',
  447. 'forum_rules_link' => '',
  448. 'forum_image' => '',
  449. 'forum_style' => 0,
  450. 'display_subforum_list' => true,
  451. 'display_on_index' => false,
  452. 'forum_topics_per_page' => 0,
  453. 'enable_indexing' => true,
  454. 'enable_icons' => false,
  455. 'enable_prune' => false,
  456. //Begin Thank Post MOD
  457. 'enable_thanks' => false,
  458. //End Thank Post MOD
  459. 'prune_days' => 7,
  460. 'prune_viewed' => 7,
  461. 'prune_freq' => 1,
  462. 'forum_flags' => FORUM_FLAG_POST_REVIEW + FORUM_FLAG_ACTIVE_TOPICS,
  463. 'forum_options' => 0,
  464. 'forum_password' => '',
  465. 'forum_password_confirm'=> '',
  466. // Start Ultimate Points
  467. 'forum_pertopic' => 0.00,
  468. 'forum_perpost' => 0.00,
  469. 'forum_peredit' => 0.00,
  470. // End Ultimate Points
  471. );
  472. }
  473. }
  474.  
  475. $forum_rules_data = array(
  476. 'text' => $forum_data['forum_rules'],
  477. 'allow_bbcode' => true,
  478. 'allow_smilies' => true,
  479. 'allow_urls' => true
  480. );
  481.  
  482. $forum_desc_data = array(
  483. 'text' => $forum_data['forum_desc'],
  484. 'allow_bbcode' => true,
  485. 'allow_smilies' => true,
  486. 'allow_urls' => true
  487. );
  488.  
  489. $forum_rules_preview = '';
  490.  
  491. // Parse rules if specified
  492. if ($forum_data['forum_rules'])
  493. {
  494. if (!isset($forum_data['forum_rules_uid']))
  495. {
  496. // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
  497. $forum_data['forum_rules_uid'] = '';
  498. $forum_data['forum_rules_bitfield'] = '';
  499. $forum_data['forum_rules_options'] = 0;
  500.  
  501. generate_text_for_storage($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options'], request_var('rules_allow_bbcode', false), request_var('rules_allow_urls', false), request_var('rules_allow_smilies', false));
  502. }
  503.  
  504. // Generate preview content
  505. $forum_rules_preview = generate_text_for_display($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options']);
  506.  
  507. // decode...
  508. $forum_rules_data = generate_text_for_edit($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_options']);
  509. }
  510.  
  511. // Parse desciption if specified
  512. if ($forum_data['forum_desc'])
  513. {
  514. if (!isset($forum_data['forum_desc_uid']))
  515. {
  516. // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
  517. $forum_data['forum_desc_uid'] = '';
  518. $forum_data['forum_desc_bitfield'] = '';
  519. $forum_data['forum_desc_options'] = 0;
  520.  
  521. generate_text_for_storage($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options'], request_var('desc_allow_bbcode', false), request_var('desc_allow_urls', false), request_var('desc_allow_smilies', false));
  522. }
  523.  
  524. // decode...
  525. $forum_desc_data = generate_text_for_edit($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_options']);
  526. }
  527.  
  528. $forum_type_options = '';
  529. $forum_type_ary = array(FORUM_CAT => 'CAT', FORUM_POST => 'FORUM', FORUM_LINK => 'LINK');
  530.  
  531. foreach ($forum_type_ary as $value => $lang)
  532. {
  533. $forum_type_options .= '<option value="' . $value . '"' . (($value == $forum_data['forum_type']) ? ' selected="selected"' : '') . '>' . $user->lang['TYPE_' . $lang] . '</option>';
  534. }
  535.  
  536. $styles_list = style_select($forum_data['forum_style'], true);
  537.  
  538. $statuslist = '<option value="' . ITEM_UNLOCKED . '"' . (($forum_data['forum_status'] == ITEM_UNLOCKED) ? ' selected="selected"' : '') . '>' . $user->lang['UNLOCKED'] . '</option><option value="' . ITEM_LOCKED . '"' . (($forum_data['forum_status'] == ITEM_LOCKED) ? ' selected="selected"' : '') . '>' . $user->lang['LOCKED'] . '</option>';
  539.  
  540. $sql = 'SELECT forum_id
  541. FROM ' . FORUMS_TABLE . '
  542. WHERE forum_type = ' . FORUM_POST . "
  543. AND forum_id <> $forum_id";
  544. $result = $db->sql_query_limit($sql, 1);
  545.  
  546. $postable_forum_exists = false;
  547. if ($db->sql_fetchrow($result))
  548. {
  549. $postable_forum_exists = true;
  550. }
  551. $db->sql_freeresult($result);
  552.  
  553. // Subforum move options
  554. if ($action == 'edit' && $forum_data['forum_type'] == FORUM_CAT)
  555. {
  556. $subforums_id = array();
  557. $subforums = get_forum_branch($forum_id, 'children');
  558.  
  559. foreach ($subforums as $row)
  560. {
  561. $subforums_id[] = $row['forum_id'];
  562. }
  563.  
  564. $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
  565.  
  566. if ($postable_forum_exists)
  567. {
  568. $template->assign_vars(array(
  569. 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id)) // , false, true, false???
  570. );
  571. }
  572.  
  573. $template->assign_vars(array(
  574. 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
  575. 'S_FORUMS_LIST' => $forums_list)
  576. );
  577. }
  578. else if ($postable_forum_exists)
  579. {
  580. $template->assign_vars(array(
  581. 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_id, false, true, false))
  582. );
  583. }
  584.  
  585. $s_show_display_on_index = false;
  586.  
  587. if ($forum_data['parent_id'] > 0)
  588. {
  589. // if this forum is a subforum put the "display on index" checkbox
  590. if ($parent_info = $this->get_forum_info($forum_data['parent_id']))
  591. {
  592. if ($parent_info['parent_id'] > 0 || $parent_info['forum_type'] == FORUM_CAT)
  593. {
  594. $s_show_display_on_index = true;
  595. }
  596. }
  597. }
  598.  
  599. if (strlen($forum_data['forum_password']) == 32)
  600. {
  601. $errors[] = $user->lang['FORUM_PASSWORD_OLD'];
  602. }
  603.  
  604. $template->assign_vars(array(
  605. 'S_EDIT_FORUM' => true,
  606. 'S_ERROR' => (sizeof($errors)) ? true : false,
  607. 'S_PARENT_ID' => $this->parent_id,
  608. 'S_FORUM_PARENT_ID' => $forum_data['parent_id'],
  609. 'S_ADD_ACTION' => ($action == 'add') ? true : false,
  610.  
  611. 'U_BACK' => $this->u_action . '&amp;parent_id=' . $this->parent_id,
  612. 'U_EDIT_ACTION' => $this->u_action . "&amp;parent_id={$this->parent_id}&amp;action=$action&amp;f=$forum_id",
  613.  
  614. 'L_COPY_PERMISSIONS_EXPLAIN' => $user->lang['COPY_PERMISSIONS_' . strtoupper($action) . '_EXPLAIN'],
  615. 'L_TITLE' => $user->lang[$this->page_title],
  616. 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
  617.  
  618. 'FORUM_NAME' => $forum_data['forum_name'],
  619. 'FORUM_DATA_LINK' => $forum_data['forum_link'],
  620. 'FORUM_IMAGE' => $forum_data['forum_image'],
  621. 'FORUM_IMAGE_SRC' => ($forum_data['forum_image']) ? $phpbb_root_path . $forum_data['forum_image'] : '',
  622. 'FORUM_POST' => FORUM_POST,
  623. 'FORUM_LINK' => FORUM_LINK,
  624. 'FORUM_CAT' => FORUM_CAT,
  625. 'PRUNE_FREQ' => $forum_data['prune_freq'],
  626. 'PRUNE_DAYS' => $forum_data['prune_days'],
  627. 'PRUNE_VIEWED' => $forum_data['prune_viewed'],
  628. 'TOPICS_PER_PAGE' => $forum_data['forum_topics_per_page'],
  629. 'FORUM_RULES_LINK' => $forum_data['forum_rules_link'],
  630. 'FORUM_RULES' => $forum_data['forum_rules'],
  631. 'FORUM_RULES_PREVIEW' => $forum_rules_preview,
  632. // Start Ultimate Points
  633. 'FORUM_PERTOPIC' => $forum_data['forum_pertopic'],
  634. 'FORUM_PERPOST' => $forum_data['forum_perpost'],
  635. 'FORUM_PEREDIT' => $forum_data['forum_peredit'],
  636. // End Ultimate Points
  637. 'FORUM_RULES_PLAIN' => $forum_rules_data['text'],
  638. 'S_BBCODE_CHECKED' => ($forum_rules_data['allow_bbcode']) ? true : false,
  639. 'S_SMILIES_CHECKED' => ($forum_rules_data['allow_smilies']) ? true : false,
  640. 'S_URLS_CHECKED' => ($forum_rules_data['allow_urls']) ? true : false,
  641. 'S_FORUM_PASSWORD_SET' => (empty($forum_data['forum_password'])) ? false : true,
  642.  
  643. 'FORUM_DESC' => $forum_desc_data['text'],
  644. 'S_DESC_BBCODE_CHECKED' => ($forum_desc_data['allow_bbcode']) ? true : false,
  645. 'S_DESC_SMILIES_CHECKED' => ($forum_desc_data['allow_smilies']) ? true : false,
  646. 'S_DESC_URLS_CHECKED' => ($forum_desc_data['allow_urls']) ? true : false,
  647.  
  648. 'S_FORUM_TYPE_OPTIONS' => $forum_type_options,
  649. 'S_STATUS_OPTIONS' => $statuslist,
  650. 'S_PARENT_OPTIONS' => $parents_list,
  651. 'S_STYLES_OPTIONS' => $styles_list,
  652. 'S_FORUM_OPTIONS' => make_forum_select(($action == 'add') ? $forum_data['parent_id'] : false, ($action == 'edit') ? $forum_data['forum_id'] : false, false, false, false),
  653. 'S_SHOW_DISPLAY_ON_INDEX' => $s_show_display_on_index,
  654. 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
  655. 'S_FORUM_ORIG_POST' => (isset($old_forum_type) && $old_forum_type == FORUM_POST) ? true : false,
  656. 'S_FORUM_ORIG_CAT' => (isset($old_forum_type) && $old_forum_type == FORUM_CAT) ? true : false,
  657. 'S_FORUM_ORIG_LINK' => (isset($old_forum_type) && $old_forum_type == FORUM_LINK) ? true : false,
  658. 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
  659. 'S_FORUM_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
  660. 'S_ENABLE_INDEXING' => ($forum_data['enable_indexing']) ? true : false,
  661. 'S_TOPIC_ICONS' => ($forum_data['enable_icons']) ? true : false,
  662. 'S_DISPLAY_SUBFORUM_LIST' => ($forum_data['display_subforum_list']) ? true : false,
  663. 'S_DISPLAY_ON_INDEX' => ($forum_data['display_on_index']) ? true : false,
  664. 'S_PRUNE_ENABLE' => ($forum_data['enable_prune']) ? true : false,
  665. //Begin Thank Post MOD
  666. 'S_THANKS_ENABLE' => ($forum_data['enable_thanks']) ? true : false,
  667. //End Thank Post MOD
  668. 'S_FORUM_LINK_TRACK' => ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? true : false,
  669. 'S_PRUNE_OLD_POLLS' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL) ? true : false,
  670. 'S_PRUNE_ANNOUNCE' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE) ? true : false,
  671. 'S_PRUNE_STICKY' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_STICKY) ? true : false,
  672. 'S_DISPLAY_ACTIVE_TOPICS' => ($forum_data['forum_type'] == FORUM_POST) ? ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) : true,
  673. 'S_ENABLE_ACTIVE_TOPICS' => ($forum_data['forum_type'] == FORUM_CAT) ? ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) : false,
  674. 'S_ENABLE_POST_REVIEW' => ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false,
  675. 'S_ENABLE_QUICK_REPLY' => ($forum_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY) ? true : false,
  676. 'S_CAN_COPY_PERMISSIONS' => ($action != 'edit' || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))) ? true : false,
  677. ));
  678.  
  679. return;
  680.  
  681. break;
  682.  
  683. case 'delete':
  684.  
  685. if (!$forum_id)
  686. {
  687. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  688. }
  689.  
  690. $forum_data = $this->get_forum_info($forum_id);
  691.  
  692. $subforums_id = array();
  693. $subforums = get_forum_branch($forum_id, 'children');
  694.  
  695. foreach ($subforums as $row)
  696. {
  697. $subforums_id[] = $row['forum_id'];
  698. }
  699.  
  700. $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
  701.  
  702. $sql = 'SELECT forum_id
  703. FROM ' . FORUMS_TABLE . '
  704. WHERE forum_type = ' . FORUM_POST . "
  705. AND forum_id <> $forum_id";
  706. $result = $db->sql_query_limit($sql, 1);
  707.  
  708. if ($db->sql_fetchrow($result))
  709. {
  710. $template->assign_vars(array(
  711. 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id, false, true)) // , false, true, false???
  712. );
  713. }
  714. $db->sql_freeresult($result);
  715.  
  716. $parent_id = ($this->parent_id == $forum_id) ? 0 : $this->parent_id;
  717.  
  718. $template->assign_vars(array(
  719. 'S_DELETE_FORUM' => true,
  720. 'U_ACTION' => $this->u_action . "&amp;parent_id={$parent_id}&amp;action=delete&amp;f=$forum_id",
  721. 'U_BACK' => $this->u_action . '&amp;parent_id=' . $this->parent_id,
  722.  
  723. 'FORUM_NAME' => $forum_data['forum_name'],
  724. 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
  725. 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
  726. 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
  727. 'S_FORUMS_LIST' => $forums_list,
  728. 'S_ERROR' => (sizeof($errors)) ? true : false,
  729. 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '')
  730. );
  731.  
  732. return;
  733. break;
  734.  
  735. case 'copy_perm':
  736. $forum_perm_from = request_var('forum_perm_from', 0);
  737.  
  738. // Copy permissions?
  739. if (!empty($forum_perm_from) && $forum_perm_from != $forum_id)
  740. {
  741. copy_forum_permissions($forum_perm_from, $forum_id, true);
  742. cache_moderators();
  743. $auth->acl_clear_prefetch();
  744. $cache->destroy('sql', FORUMS_TABLE);
  745.  
  746. $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_id;
  747.  
  748. $message = $user->lang['FORUM_UPDATED'];
  749.  
  750. // Redirect to permissions
  751. if ($auth->acl_get('a_fauth'))
  752. {
  753. $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
  754. }
  755.  
  756. trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
  757. }
  758.  
  759. break;
  760. }
  761.  
  762. // Default management page
  763. if (!$this->parent_id)
  764. {
  765. $navigation = $user->lang['FORUM_INDEX'];
  766. }
  767. else
  768. {
  769. $navigation = '<a href="' . $this->u_action . '">' . $user->lang['FORUM_INDEX'] . '</a>';
  770.  
  771. $forums_nav = get_forum_branch($this->parent_id, 'parents', 'descending');
  772. foreach ($forums_nav as $row)
  773. {
  774. if ($row['forum_id'] == $this->parent_id)
  775. {
  776. $navigation .= ' -&gt; ' . $row['forum_name'];
  777. }
  778. else
  779. {
  780. $navigation .= ' -&gt; <a href="' . $this->u_action . '&amp;parent_id=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>';
  781. }
  782. }
  783. }
  784.  
  785. // Jumpbox
  786. $forum_box = make_forum_select($this->parent_id, false, false, false, false); //make_forum_select($this->parent_id);
  787.  
  788. if ($action == 'sync' || $action == 'sync_forum')
  789. {
  790. $template->assign_var('S_RESYNCED', true);
  791. }
  792.  
  793. $sql = 'SELECT *
  794. FROM ' . FORUMS_TABLE . "
  795. WHERE parent_id = $this->parent_id
  796. ORDER BY left_id";
  797. $result = $db->sql_query($sql);
  798.  
  799. if ($row = $db->sql_fetchrow($result))
  800. {
  801. do
  802. {
  803. $forum_type = $row['forum_type'];
  804.  
  805. if ($row['forum_status'] == ITEM_LOCKED)
  806. {
  807. $folder_image = '<img src="images/icon_folder_lock.gif" alt="' . $user->lang['LOCKED'] . '" />';
  808. }
  809. else
  810. {
  811. switch ($forum_type)
  812. {
  813. case FORUM_LINK:
  814. $folder_image = '<img src="images/icon_folder_link.gif" alt="' . $user->lang['LINK'] . '" />';
  815. break;
  816.  
  817. default:
  818. $folder_image = ($row['left_id'] + 1 != $row['right_id']) ? '<img src="images/icon_subfolder.gif" alt="' . $user->lang['SUBFORUM'] . '" />' : '<img src="images/icon_folder.gif" alt="' . $user->lang['FOLDER'] . '" />';
  819. break;
  820. }
  821. }
  822.  
  823. $url = $this->u_action . "&amp;parent_id=$this->parent_id&amp;f={$row['forum_id']}";
  824.  
  825. $template->assign_block_vars('forums', array(
  826. 'FOLDER_IMAGE' => $folder_image,
  827. 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="" />' : '',
  828. 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
  829. 'FORUM_NAME' => $row['forum_name'],
  830. 'FORUM_DESCRIPTION' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
  831. 'FORUM_TOPICS' => $row['forum_topics'],
  832. 'FORUM_POSTS' => $row['forum_posts'],
  833.  
  834. 'S_FORUM_LINK' => ($forum_type == FORUM_LINK) ? true : false,
  835. 'S_FORUM_POST' => ($forum_type == FORUM_POST) ? true : false,
  836.  
  837. 'U_FORUM' => $this->u_action . '&amp;parent_id=' . $row['forum_id'],
  838. 'U_MOVE_UP' => $url . '&amp;action=move_up',
  839. 'U_MOVE_DOWN' => $url . '&amp;action=move_down',
  840. 'U_EDIT' => $url . '&amp;action=edit',
  841. 'U_DELETE' => $url . '&amp;action=delete',
  842. 'U_SYNC' => $url . '&amp;action=sync')
  843. );
  844. }
  845. while ($row = $db->sql_fetchrow($result));
  846. }
  847. else if ($this->parent_id)
  848. {
  849. $row = $this->get_forum_info($this->parent_id);
  850.  
  851. $url = $this->u_action . '&amp;parent_id=' . $this->parent_id . '&amp;f=' . $row['forum_id'];
  852.  
  853. $template->assign_vars(array(
  854. 'S_NO_FORUMS' => true,
  855.  
  856. 'U_EDIT' => $url . '&amp;action=edit',
  857. 'U_DELETE' => $url . '&amp;action=delete',
  858. 'U_SYNC' => $url . '&amp;action=sync')
  859. );
  860. }
  861. $db->sql_freeresult($result);
  862.  
  863. $template->assign_vars(array(
  864. 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
  865. 'NAVIGATION' => $navigation,
  866. 'FORUM_BOX' => $forum_box,
  867. 'U_SEL_ACTION' => $this->u_action,
  868. 'U_ACTION' => $this->u_action . '&amp;parent_id=' . $this->parent_id,
  869.  
  870. 'U_PROGRESS_BAR' => $this->u_action . '&amp;action=progress_bar',
  871. 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&amp;action=progress_bar'),
  872. ));
  873. }
  874.  
  875. /**
  876. * Get forum details
  877. */
  878. function get_forum_info($forum_id)
  879. {
  880. global $db;
  881.  
  882. $sql = 'SELECT *
  883. FROM ' . FORUMS_TABLE . "
  884. WHERE forum_id = $forum_id";
  885. $result = $db->sql_query($sql);
  886. $row = $db->sql_fetchrow($result);
  887. $db->sql_freeresult($result);
  888.  
  889. if (!$row)
  890. {
  891. trigger_error("Forum #$forum_id does not exist", E_USER_ERROR);
  892. }
  893.  
  894. return $row;
  895. }
  896.  
  897. /**
  898. * Update forum data
  899. */
  900. function update_forum_data(&$forum_data)
  901. {
  902. global $db, $user, $cache, $phpbb_root_path;
  903.  
  904. $errors = array();
  905.  
  906. if (!$forum_data['forum_name'])
  907. {
  908. $errors[] = $user->lang['FORUM_NAME_EMPTY'];
  909. }
  910.  
  911. if (utf8_strlen($forum_data['forum_desc']) > 4000)
  912. {
  913. $errors[] = $user->lang['FORUM_DESC_TOO_LONG'];
  914. }
  915.  
  916. if (utf8_strlen($forum_data['forum_rules']) > 4000)
  917. {
  918. $errors[] = $user->lang['FORUM_RULES_TOO_LONG'];
  919. }
  920.  
  921. if ($forum_data['forum_password'] || $forum_data['forum_password_confirm'])
  922. {
  923. if ($forum_data['forum_password'] != $forum_data['forum_password_confirm'])
  924. {
  925. $forum_data['forum_password'] = $forum_data['forum_password_confirm'] = '';
  926. $errors[] = $user->lang['FORUM_PASSWORD_MISMATCH'];
  927. }
  928. }
  929.  
  930. if ($forum_data['prune_days'] < 0 || $forum_data['prune_viewed'] < 0 || $forum_data['prune_freq'] < 0)
  931. {
  932. $forum_data['prune_days'] = $forum_data['prune_viewed'] = $forum_data['prune_freq'] = 0;
  933. $errors[] = $user->lang['FORUM_DATA_NEGATIVE'];
  934. }
  935.  
  936. $range_test_ary = array(
  937. array('lang' => 'FORUM_TOPICS_PAGE', 'value' => $forum_data['forum_topics_per_page'], 'column_type' => 'TINT:0'),
  938. );
  939.  
  940. if (!empty($forum_data['forum_image']) && !file_exists($phpbb_root_path . $forum_data['forum_image']))
  941. {
  942. $errors[] = $user->lang['FORUM_IMAGE_NO_EXIST'];
  943. }
  944.  
  945. validate_range($range_test_ary, $errors);
  946.  
  947. // Set forum flags
  948. // 1 = link tracking
  949. // 2 = prune old polls
  950. // 4 = prune announcements
  951. // 8 = prune stickies
  952. // 16 = show active topics
  953. // 32 = enable post review
  954. $forum_data['forum_flags'] = 0;
  955. $forum_data['forum_flags'] += ($forum_data['forum_link_track']) ? FORUM_FLAG_LINK_TRACK : 0;
  956. $forum_data['forum_flags'] += ($forum_data['prune_old_polls']) ? FORUM_FLAG_PRUNE_POLL : 0;
  957. $forum_data['forum_flags'] += ($forum_data['prune_announce']) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
  958. $forum_data['forum_flags'] += ($forum_data['prune_sticky']) ? FORUM_FLAG_PRUNE_STICKY : 0;
  959. $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
  960. $forum_data['forum_flags'] += ($forum_data['enable_post_review']) ? FORUM_FLAG_POST_REVIEW : 0;
  961. $forum_data['forum_flags'] += ($forum_data['enable_quick_reply']) ? FORUM_FLAG_QUICK_REPLY : 0;
  962.  
  963. // Unset data that are not database fields
  964. $forum_data_sql = $forum_data;
  965.  
  966. unset($forum_data_sql['forum_link_track']);
  967. unset($forum_data_sql['prune_old_polls']);
  968. unset($forum_data_sql['prune_announce']);
  969. unset($forum_data_sql['prune_sticky']);
  970. unset($forum_data_sql['show_active']);
  971. unset($forum_data_sql['enable_post_review']);
  972. unset($forum_data_sql['enable_quick_reply']);
  973. unset($forum_data_sql['forum_password_confirm']);
  974.  
  975. // What are we going to do tonight Brain? The same thing we do everynight,
  976. // try to take over the world ... or decide whether to continue update
  977. // and if so, whether it's a new forum/cat/link or an existing one
  978. if (sizeof($errors))
  979. {
  980. return $errors;
  981. }
  982.  
  983. // As we don't know the old password, it's kinda tricky to detect changes
  984. if ($forum_data_sql['forum_password_unset'])
  985. {
  986. $forum_data_sql['forum_password'] = '';
  987. }
  988. else if (empty($forum_data_sql['forum_password']))
  989. {
  990. unset($forum_data_sql['forum_password']);
  991. }
  992. else
  993. {
  994. $forum_data_sql['forum_password'] = phpbb_hash($forum_data_sql['forum_password']);
  995. }
  996. unset($forum_data_sql['forum_password_unset']);
  997.  
  998. if (!isset($forum_data_sql['forum_id']))
  999. {
  1000. // no forum_id means we're creating a new forum
  1001. unset($forum_data_sql['type_action']);
  1002.  
  1003. if ($forum_data_sql['parent_id'])
  1004. {
  1005. $sql = 'SELECT left_id, right_id, forum_type
  1006. FROM ' . FORUMS_TABLE . '
  1007. WHERE forum_id = ' . $forum_data_sql['parent_id'];
  1008. $result = $db->sql_query($sql);
  1009. $row = $db->sql_fetchrow($result);
  1010. $db->sql_freeresult($result);
  1011.  
  1012. if (!$row)
  1013. {
  1014. trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  1015. }
  1016.  
  1017. if ($row['forum_type'] == FORUM_LINK)
  1018. {
  1019. $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
  1020. return $errors;
  1021. }
  1022.  
  1023. $sql = 'UPDATE ' . FORUMS_TABLE . '
  1024. SET left_id = left_id + 2, right_id = right_id + 2
  1025. WHERE left_id > ' . $row['right_id'];
  1026. $db->sql_query($sql);
  1027.  
  1028. $sql = 'UPDATE ' . FORUMS_TABLE . '
  1029. SET right_id = right_id + 2
  1030. WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
  1031. $db->sql_query($sql);
  1032.  
  1033. $forum_data_sql['left_id'] = $row['right_id'];
  1034. $forum_data_sql['right_id'] = $row['right_id'] + 1;
  1035. }
  1036. else
  1037. {
  1038. $sql = 'SELECT MAX(right_id) AS right_id
  1039. FROM ' . FORUMS_TABLE;
  1040. $result = $db->sql_query($sql);
  1041. $row = $db->sql_fetchrow($result);
  1042. $db->sql_freeresult($result);
  1043.  
  1044. $forum_data_sql['left_id'] = $row['right_id'] + 1;
  1045. $forum_data_sql['right_id'] = $row['right_id'] + 2;
  1046. }
  1047.  
  1048. $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data_sql);
  1049. $db->sql_query($sql);
  1050.  
  1051. $forum_data['forum_id'] = $db->sql_nextid();
  1052.  
  1053. add_log('admin', 'LOG_FORUM_ADD', $forum_data['forum_name']);
  1054. }
  1055. else
  1056. {
  1057. $row = $this->get_forum_info($forum_data_sql['forum_id']);
  1058.  
  1059. if ($row['forum_type'] == FORUM_POST && $row['forum_type'] != $forum_data_sql['forum_type'])
  1060. {
  1061. // Has subforums and want to change into a link?
  1062. if ($row['right_id'] - $row['left_id'] > 1 && $forum_data_sql['forum_type'] == FORUM_LINK)
  1063. {
  1064. $errors[] = $user->lang['FORUM_WITH_SUBFORUMS_NOT_TO_LINK'];
  1065. return $errors;
  1066. }
  1067.  
  1068. // we're turning a postable forum into a non-postable forum
  1069. if ($forum_data_sql['type_action'] == 'move')
  1070. {
  1071. $to_forum_id = request_var('to_forum_id', 0);
  1072.  
  1073. if ($to_forum_id)
  1074. {
  1075. $errors = $this->move_forum_content($forum_data_sql['forum_id'], $to_forum_id);
  1076. }
  1077. else
  1078. {
  1079. return array($user->lang['NO_DESTINATION_FORUM']);
  1080. }
  1081. }
  1082. else if ($forum_data_sql['type_action'] == 'delete')
  1083. {
  1084. $errors = $this->delete_forum_content($forum_data_sql['forum_id']);
  1085. }
  1086. else
  1087. {
  1088. return array($user->lang['NO_FORUM_ACTION']);
  1089. }
  1090.  
  1091. $forum_data_sql['forum_posts'] = $forum_data_sql['forum_topics'] = $forum_data_sql['forum_topics_real'] = $forum_data_sql['forum_last_post_id'] = $forum_data_sql['forum_last_poster_id'] = $forum_data_sql['forum_last_post_time'] = 0;
  1092. $forum_data_sql['forum_last_poster_name'] = $forum_data_sql['forum_last_poster_colour'] = '';
  1093. }
  1094. else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_LINK)
  1095. {
  1096. // Has subforums?
  1097. if ($row['right_id'] - $row['left_id'] > 1)
  1098. {
  1099. // We are turning a category into a link - but need to decide what to do with the subforums.
  1100. $action_subforums = request_var('action_subforums', '');
  1101. $subforums_to_id = request_var('subforums_to_id', 0);
  1102.  
  1103. if ($action_subforums == 'delete')
  1104. {
  1105. $rows = get_forum_branch($row['forum_id'], 'children', 'descending', false);
  1106.  
  1107. foreach ($rows as $_row)
  1108. {
  1109. // Do not remove the forum id we are about to change. ;)
  1110. if ($_row['forum_id'] == $row['forum_id'])
  1111. {
  1112. continue;
  1113. }
  1114.  
  1115. $forum_ids[] = $_row['forum_id'];
  1116. $errors = array_merge($errors, $this->delete_forum_content($_row['forum_id']));
  1117. }
  1118.  
  1119. if (sizeof($errors))
  1120. {
  1121. return $errors;
  1122. }
  1123.  
  1124. if (sizeof($forum_ids))
  1125. {
  1126. $sql = 'DELETE FROM ' . FORUMS_TABLE . '
  1127. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  1128. $db->sql_query($sql);
  1129.  
  1130. $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
  1131. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  1132. $db->sql_query($sql);
  1133.  
  1134. $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
  1135. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  1136. $db->sql_query($sql);
  1137.  
  1138. // Delete forum ids from extension groups table
  1139. $sql = 'SELECT group_id, allowed_forums
  1140. FROM ' . EXTENSION_GROUPS_TABLE;
  1141. $result = $db->sql_query($sql);
  1142.  
  1143. while ($_row = $db->sql_fetchrow($result))
  1144. {
  1145. if (!$_row['allowed_forums'])
  1146. {
  1147. continue;
  1148. }
  1149.  
  1150. $allowed_forums = unserialize(trim($_row['allowed_forums']));
  1151. $allowed_forums = array_diff($allowed_forums, $forum_ids);
  1152.  
  1153. $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
  1154. SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
  1155. WHERE group_id = {$_row['group_id']}";
  1156. $db->sql_query($sql);
  1157. }
  1158. $db->sql_freeresult($result);
  1159.  
  1160. $cache->destroy('_extensions');
  1161. }
  1162. }
  1163. else if ($action_subforums == 'move')
  1164. {
  1165. if (!$subforums_to_id)
  1166. {
  1167. return array($user->lang['NO_DESTINATION_FORUM']);
  1168. }
  1169.  
  1170. $sql = 'SELECT forum_name
  1171. FROM ' . FORUMS_TABLE . '
  1172. WHERE forum_id = ' . $subforums_to_id;
  1173. $result = $db->sql_query($sql);
  1174. $_row = $db->sql_fetchrow($result);
  1175. $db->sql_freeresult($result);
  1176.  
  1177. if (!$_row)
  1178. {
  1179. return array($user->lang['NO_FORUM']);
  1180. }
  1181.  
  1182. $subforums_to_name = $_row['forum_name'];
  1183.  
  1184. $sql = 'SELECT forum_id
  1185. FROM ' . FORUMS_TABLE . "
  1186. WHERE parent_id = {$row['forum_id']}";
  1187. $result = $db->sql_query($sql);
  1188.  
  1189. while ($_row = $db->sql_fetchrow($result))
  1190. {
  1191. $this->move_forum($_row['forum_id'], $subforums_to_id);
  1192. }
  1193. $db->sql_freeresult($result);
  1194.  
  1195. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1196. SET parent_id = $subforums_to_id
  1197. WHERE parent_id = {$row['forum_id']}";
  1198. $db->sql_query($sql);
  1199. }
  1200.  
  1201. // Adjust the left/right id
  1202. $sql = 'UPDATE ' . FORUMS_TABLE . '
  1203. SET right_id = left_id + 1
  1204. WHERE forum_id = ' . $row['forum_id'];
  1205. $db->sql_query($sql);
  1206. }
  1207. }
  1208. else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_POST)
  1209. {
  1210. // Changing a category to a forum? Reset the data (you can't post directly in a cat, you must use a forum)
  1211. $forum_data_sql['forum_posts'] = 0;
  1212. $forum_data_sql['forum_topics'] = 0;
  1213. $forum_data_sql['forum_topics_real'] = 0;
  1214. $forum_data_sql['forum_last_post_id'] = 0;
  1215. $forum_data_sql['forum_last_post_subject'] = '';
  1216. $forum_data_sql['forum_last_post_time'] = 0;
  1217. $forum_data_sql['forum_last_poster_id'] = 0;
  1218. $forum_data_sql['forum_last_poster_name'] = '';
  1219. $forum_data_sql['forum_last_poster_colour'] = '';
  1220. }
  1221.  
  1222. if (sizeof($errors))
  1223. {
  1224. return $errors;
  1225. }
  1226.  
  1227. if ($row['parent_id'] != $forum_data_sql['parent_id'])
  1228. {
  1229. if ($row['forum_id'] != $forum_data_sql['parent_id'])
  1230. {
  1231. $errors = $this->move_forum($forum_data_sql['forum_id'], $forum_data_sql['parent_id']);
  1232. }
  1233. else
  1234. {
  1235. $forum_data_sql['parent_id'] = $row['parent_id'];
  1236. }
  1237. }
  1238.  
  1239. if (sizeof($errors))
  1240. {
  1241. return $errors;
  1242. }
  1243.  
  1244. unset($forum_data_sql['type_action']);
  1245.  
  1246. if ($row['forum_name'] != $forum_data_sql['forum_name'])
  1247. {
  1248. // the forum name has changed, clear the parents list of all forums (for safety)
  1249. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1250. SET forum_parents = ''";
  1251. $db->sql_query($sql);
  1252. }
  1253.  
  1254. // Setting the forum id to the forum id is not really received well by some dbs. ;)
  1255. $forum_id = $forum_data_sql['forum_id'];
  1256. unset($forum_data_sql['forum_id']);
  1257.  
  1258. $sql = 'UPDATE ' . FORUMS_TABLE . '
  1259. SET ' . $db->sql_build_array('UPDATE', $forum_data_sql) . '
  1260. WHERE forum_id = ' . $forum_id;
  1261. $db->sql_query($sql);
  1262.  
  1263. // Add it back
  1264. $forum_data['forum_id'] = $forum_id;
  1265.  
  1266. add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']);
  1267. }
  1268.  
  1269. return $errors;
  1270. }
  1271.  
  1272. /**
  1273. * Move forum
  1274. */
  1275. function move_forum($from_id, $to_id)
  1276. {
  1277. global $db, $user;
  1278.  
  1279. $to_data = $moved_ids = $errors = array();
  1280.  
  1281. // Check if we want to move to a parent with link type
  1282. if ($to_id > 0)
  1283. {
  1284. $to_data = $this->get_forum_info($to_id);
  1285.  
  1286. if ($to_data['forum_type'] == FORUM_LINK)
  1287. {
  1288. $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
  1289. return $errors;
  1290. }
  1291. }
  1292.  
  1293. $moved_forums = get_forum_branch($from_id, 'children', 'descending');
  1294. $from_data = $moved_forums[0];
  1295. $diff = sizeof($moved_forums) * 2;
  1296.  
  1297. $moved_ids = array();
  1298. for ($i = 0; $i < sizeof($moved_forums); ++$i)
  1299. {
  1300. $moved_ids[] = $moved_forums[$i]['forum_id'];
  1301. }
  1302.  
  1303. // Resync parents
  1304. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1305. SET right_id = right_id - $diff, forum_parents = ''
  1306. WHERE left_id < " . $from_data['right_id'] . "
  1307. AND right_id > " . $from_data['right_id'];
  1308. $db->sql_query($sql);
  1309.  
  1310. // Resync righthand side of tree
  1311. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1312. SET left_id = left_id - $diff, right_id = right_id - $diff, forum_parents = ''
  1313. WHERE left_id > " . $from_data['right_id'];
  1314. $db->sql_query($sql);
  1315.  
  1316. if ($to_id > 0)
  1317. {
  1318. // Retrieve $to_data again, it may have been changed...
  1319. $to_data = $this->get_forum_info($to_id);
  1320.  
  1321. // Resync new parents
  1322. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1323. SET right_id = right_id + $diff, forum_parents = ''
  1324. WHERE " . $to_data['right_id'] . ' BETWEEN left_id AND right_id
  1325. AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
  1326. $db->sql_query($sql);
  1327.  
  1328. // Resync the righthand side of the tree
  1329. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1330. SET left_id = left_id + $diff, right_id = right_id + $diff, forum_parents = ''
  1331. WHERE left_id > " . $to_data['right_id'] . '
  1332. AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
  1333. $db->sql_query($sql);
  1334.  
  1335. // Resync moved branch
  1336. $to_data['right_id'] += $diff;
  1337.  
  1338. if ($to_data['right_id'] > $from_data['right_id'])
  1339. {
  1340. $diff = '+ ' . ($to_data['right_id'] - $from_data['right_id'] - 1);
  1341. }
  1342. else
  1343. {
  1344. $diff = '- ' . abs($to_data['right_id'] - $from_data['right_id'] - 1);
  1345. }
  1346. }
  1347. else
  1348. {
  1349. $sql = 'SELECT MAX(right_id) AS right_id
  1350. FROM ' . FORUMS_TABLE . '
  1351. WHERE ' . $db->sql_in_set('forum_id', $moved_ids, true);
  1352. $result = $db->sql_query($sql);
  1353. $row = $db->sql_fetchrow($result);
  1354. $db->sql_freeresult($result);
  1355.  
  1356. $diff = '+ ' . ($row['right_id'] - $from_data['left_id'] + 1);
  1357. }
  1358.  
  1359. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1360. SET left_id = left_id $diff, right_id = right_id $diff, forum_parents = ''
  1361. WHERE " . $db->sql_in_set('forum_id', $moved_ids);
  1362. $db->sql_query($sql);
  1363.  
  1364. return $errors;
  1365. }
  1366.  
  1367. /**
  1368. * Move forum content from one to another forum
  1369. */
  1370. function move_forum_content($from_id, $to_id, $sync = true)
  1371. {
  1372. global $db;
  1373.  
  1374. $table_ary = array(LOG_TABLE, POSTS_TABLE, TOPICS_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE);
  1375.  
  1376. foreach ($table_ary as $table)
  1377. {
  1378. $sql = "UPDATE $table
  1379. SET forum_id = $to_id
  1380. WHERE forum_id = $from_id";
  1381. $db->sql_query($sql);
  1382. }
  1383. unset($table_ary);
  1384.  
  1385. $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, MODERATOR_CACHE_TABLE);
  1386.  
  1387. foreach ($table_ary as $table)
  1388. {
  1389. $sql = "DELETE FROM $table
  1390. WHERE forum_id = $from_id";
  1391. $db->sql_query($sql);
  1392. }
  1393.  
  1394. if ($sync)
  1395. {
  1396. // Delete ghost topics that link back to the same forum then resync counters
  1397. sync('topic_moved');
  1398. sync('forum', 'forum_id', $to_id, false, true);
  1399. }
  1400.  
  1401. return array();
  1402. }
  1403.  
  1404. /**
  1405. * Remove complete forum
  1406. */
  1407. function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = 'delete', $posts_to_id = 0, $subforums_to_id = 0)
  1408. {
  1409. global $db, $user, $cache;
  1410.  
  1411. $forum_data = $this->get_forum_info($forum_id);
  1412.  
  1413. $errors = array();
  1414. $log_action_posts = $log_action_forums = $posts_to_name = $subforums_to_name = '';
  1415. $forum_ids = array($forum_id);
  1416.  
  1417. if ($action_posts == 'delete')
  1418. {
  1419. $log_action_posts = 'POSTS';
  1420. $errors = array_merge($errors, $this->delete_forum_content($forum_id));
  1421. }
  1422. else if ($action_posts == 'move')
  1423. {
  1424. if (!$posts_to_id)
  1425. {
  1426. $errors[] = $user->lang['NO_DESTINATION_FORUM'];
  1427. }
  1428. else
  1429. {
  1430. $log_action_posts = 'MOVE_POSTS';
  1431.  
  1432. $sql = 'SELECT forum_name
  1433. FROM ' . FORUMS_TABLE . '
  1434. WHERE forum_id = ' . $posts_to_id;
  1435. $result = $db->sql_query($sql);
  1436. $row = $db->sql_fetchrow($result);
  1437. $db->sql_freeresult($result);
  1438.  
  1439. if (!$row)
  1440. {
  1441. $errors[] = $user->lang['NO_FORUM'];
  1442. }
  1443. else
  1444. {
  1445. $posts_to_name = $row['forum_name'];
  1446. $errors = array_merge($errors, $this->move_forum_content($forum_id, $posts_to_id));
  1447. }
  1448. }
  1449. }
  1450.  
  1451. if (sizeof($errors))
  1452. {
  1453. return $errors;
  1454. }
  1455.  
  1456. if ($action_subforums == 'delete')
  1457. {
  1458. $log_action_forums = 'FORUMS';
  1459. $rows = get_forum_branch($forum_id, 'children', 'descending', false);
  1460.  
  1461. foreach ($rows as $row)
  1462. {
  1463. $forum_ids[] = $row['forum_id'];
  1464. $errors = array_merge($errors, $this->delete_forum_content($row['forum_id']));
  1465. }
  1466.  
  1467. if (sizeof($errors))
  1468. {
  1469. return $errors;
  1470. }
  1471.  
  1472. $diff = sizeof($forum_ids) * 2;
  1473.  
  1474. $sql = 'DELETE FROM ' . FORUMS_TABLE . '
  1475. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  1476. $db->sql_query($sql);
  1477.  
  1478. $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
  1479. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  1480. $db->sql_query($sql);
  1481.  
  1482. $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
  1483. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  1484. $db->sql_query($sql);
  1485. }
  1486. else if ($action_subforums == 'move')
  1487. {
  1488. if (!$subforums_to_id)
  1489. {
  1490. $errors[] = $user->lang['NO_DESTINATION_FORUM'];
  1491. }
  1492. else
  1493. {
  1494. $log_action_forums = 'MOVE_FORUMS';
  1495.  
  1496. $sql = 'SELECT forum_name
  1497. FROM ' . FORUMS_TABLE . '
  1498. WHERE forum_id = ' . $subforums_to_id;
  1499. $result = $db->sql_query($sql);
  1500. $row = $db->sql_fetchrow($result);
  1501. $db->sql_freeresult($result);
  1502.  
  1503. if (!$row)
  1504. {
  1505. $errors[] = $user->lang['NO_FORUM'];
  1506. }
  1507. else
  1508. {
  1509. $subforums_to_name = $row['forum_name'];
  1510.  
  1511. $sql = 'SELECT forum_id
  1512. FROM ' . FORUMS_TABLE . "
  1513. WHERE parent_id = $forum_id";
  1514. $result = $db->sql_query($sql);
  1515.  
  1516. while ($row = $db->sql_fetchrow($result))
  1517. {
  1518. $this->move_forum($row['forum_id'], $subforums_to_id);
  1519. }
  1520. $db->sql_freeresult($result);
  1521.  
  1522. // Grab new forum data for correct tree updating later
  1523. $forum_data = $this->get_forum_info($forum_id);
  1524.  
  1525. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1526. SET parent_id = $subforums_to_id
  1527. WHERE parent_id = $forum_id";
  1528. $db->sql_query($sql);
  1529.  
  1530. $diff = 2;
  1531. $sql = 'DELETE FROM ' . FORUMS_TABLE . "
  1532. WHERE forum_id = $forum_id";
  1533. $db->sql_query($sql);
  1534.  
  1535. $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
  1536. WHERE forum_id = $forum_id";
  1537. $db->sql_query($sql);
  1538.  
  1539. $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
  1540. WHERE forum_id = $forum_id";
  1541. $db->sql_query($sql);
  1542. }
  1543. }
  1544.  
  1545. if (sizeof($errors))
  1546. {
  1547. return $errors;
  1548. }
  1549. }
  1550. else
  1551. {
  1552. $diff = 2;
  1553. $sql = 'DELETE FROM ' . FORUMS_TABLE . "
  1554. WHERE forum_id = $forum_id";
  1555. $db->sql_query($sql);
  1556.  
  1557. $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
  1558. WHERE forum_id = $forum_id";
  1559. $db->sql_query($sql);
  1560.  
  1561. $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
  1562. WHERE forum_id = $forum_id";
  1563. $db->sql_query($sql);
  1564. }
  1565.  
  1566. // Resync tree
  1567. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1568. SET right_id = right_id - $diff
  1569. WHERE left_id < {$forum_data['right_id']} AND right_id > {$forum_data['right_id']}";
  1570. $db->sql_query($sql);
  1571.  
  1572. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1573. SET left_id = left_id - $diff, right_id = right_id - $diff
  1574. WHERE left_id > {$forum_data['right_id']}";
  1575. $db->sql_query($sql);
  1576.  
  1577. // Delete forum ids from extension groups table
  1578. $sql = 'SELECT group_id, allowed_forums
  1579. FROM ' . EXTENSION_GROUPS_TABLE;
  1580. $result = $db->sql_query($sql);
  1581.  
  1582. while ($row = $db->sql_fetchrow($result))
  1583. {
  1584. if (!$row['allowed_forums'])
  1585. {
  1586. continue;
  1587. }
  1588.  
  1589. $allowed_forums = unserialize(trim($row['allowed_forums']));
  1590. $allowed_forums = array_diff($allowed_forums, $forum_ids);
  1591.  
  1592. $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
  1593. SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
  1594. WHERE group_id = {$row['group_id']}";
  1595. $db->sql_query($sql);
  1596. }
  1597. $db->sql_freeresult($result);
  1598.  
  1599. $cache->destroy('_extensions');
  1600.  
  1601. $log_action = implode('_', array($log_action_posts, $log_action_forums));
  1602.  
  1603. switch ($log_action)
  1604. {
  1605. case 'MOVE_POSTS_MOVE_FORUMS':
  1606. add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_MOVE_FORUMS', $posts_to_name, $subforums_to_name, $forum_data['forum_name']);
  1607. break;
  1608.  
  1609. case 'MOVE_POSTS_FORUMS':
  1610. add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_FORUMS', $posts_to_name, $forum_data['forum_name']);
  1611. break;
  1612.  
  1613. case 'POSTS_MOVE_FORUMS':
  1614. add_log('admin', 'LOG_FORUM_DEL_POSTS_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']);
  1615. break;
  1616.  
  1617. case '_MOVE_FORUMS':
  1618. add_log('admin', 'LOG_FORUM_DEL_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']);
  1619. break;
  1620.  
  1621. case 'MOVE_POSTS_':
  1622. add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS', $posts_to_name, $forum_data['forum_name']);
  1623. break;
  1624.  
  1625. case 'POSTS_FORUMS':
  1626. add_log('admin', 'LOG_FORUM_DEL_POSTS_FORUMS', $forum_data['forum_name']);
  1627. break;
  1628.  
  1629. case '_FORUMS':
  1630. add_log('admin', 'LOG_FORUM_DEL_FORUMS', $forum_data['forum_name']);
  1631. break;
  1632.  
  1633. case 'POSTS_':
  1634. add_log('admin', 'LOG_FORUM_DEL_POSTS', $forum_data['forum_name']);
  1635. break;
  1636.  
  1637. default:
  1638. add_log('admin', 'LOG_FORUM_DEL_FORUM', $forum_data['forum_name']);
  1639. break;
  1640. }
  1641.  
  1642. return $errors;
  1643. }
  1644.  
  1645. /**
  1646. * Delete forum content
  1647. */
  1648. function delete_forum_content($forum_id)
  1649. {
  1650. global $db, $config, $phpbb_root_path, $phpEx;
  1651.  
  1652. include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  1653.  
  1654. $db->sql_transaction('begin');
  1655.  
  1656. // Select then delete all attachments
  1657. $sql = 'SELECT a.topic_id
  1658. FROM ' . POSTS_TABLE . ' p, ' . ATTACHMENTS_TABLE . " a
  1659. WHERE p.forum_id = $forum_id
  1660. AND a.in_message = 0
  1661. AND a.topic_id = p.topic_id";
  1662. $result = $db->sql_query($sql);
  1663.  
  1664. $topic_ids = array();
  1665. while ($row = $db->sql_fetchrow($result))
  1666. {
  1667. $topic_ids[] = $row['topic_id'];
  1668. }
  1669. $db->sql_freeresult($result);
  1670.  
  1671. delete_attachments('topic', $topic_ids, false);
  1672.  
  1673. // Delete shadow topics pointing to topics in this forum
  1674. delete_topic_shadows($forum_id);
  1675.  
  1676. // Before we remove anything we make sure we are able to adjust the post counts later. ;)
  1677. $sql = 'SELECT poster_id
  1678. FROM ' . POSTS_TABLE . '
  1679. WHERE forum_id = ' . $forum_id . '
  1680. AND post_postcount = 1
  1681. AND post_approved = 1';
  1682. $result = $db->sql_query($sql);
  1683.  
  1684. $post_counts = array();
  1685. while ($row = $db->sql_fetchrow($result))
  1686. {
  1687. $post_counts[$row['poster_id']] = (!empty($post_counts[$row['poster_id']])) ? $post_counts[$row['poster_id']] + 1 : 1;
  1688. }
  1689. $db->sql_freeresult($result);
  1690.  
  1691. switch ($db->sql_layer)
  1692. {
  1693. case 'mysql4':
  1694. case 'mysqli':
  1695.  
  1696. // Delete everything else and thank MySQL for offering multi-table deletion
  1697. $tables_ary = array(
  1698. SEARCH_WORDMATCH_TABLE => 'post_id',
  1699. REPORTS_TABLE => 'post_id',
  1700. WARNINGS_TABLE => 'post_id',
  1701. BOOKMARKS_TABLE => 'topic_id',
  1702. TOPICS_WATCH_TABLE => 'topic_id',
  1703. TOPICS_POSTED_TABLE => 'topic_id',
  1704. POLL_OPTIONS_TABLE => 'topic_id',
  1705. POLL_VOTES_TABLE => 'topic_id',
  1706. );
  1707.  
  1708. $sql = 'DELETE ' . POSTS_TABLE;
  1709. $sql_using = "\nFROM " . POSTS_TABLE;
  1710. $sql_where = "\nWHERE " . POSTS_TABLE . ".forum_id = $forum_id\n";
  1711.  
  1712. foreach ($tables_ary as $table => $field)
  1713. {
  1714. $sql .= ", $table ";
  1715. $sql_using .= ", $table ";
  1716. $sql_where .= "\nAND $table.$field = " . POSTS_TABLE . ".$field";
  1717. }
  1718.  
  1719. $db->sql_query($sql . $sql_using . $sql_where);
  1720.  
  1721. break;
  1722.  
  1723. default:
  1724.  
  1725. // Delete everything else and curse your DB for not offering multi-table deletion
  1726. $tables_ary = array(
  1727. 'post_id' => array(
  1728. SEARCH_WORDMATCH_TABLE,
  1729. REPORTS_TABLE,
  1730. WARNINGS_TABLE,
  1731. ),
  1732.  
  1733. 'topic_id' => array(
  1734. BOOKMARKS_TABLE,
  1735. TOPICS_WATCH_TABLE,
  1736. TOPICS_POSTED_TABLE,
  1737. POLL_OPTIONS_TABLE,
  1738. POLL_VOTES_TABLE,
  1739. )
  1740. );
  1741.  
  1742. // Amount of rows we select and delete in one iteration.
  1743. $batch_size = 500;
  1744.  
  1745. foreach ($tables_ary as $field => $tables)
  1746. {
  1747. $start = 0;
  1748.  
  1749. do
  1750. {
  1751. $sql = "SELECT $field
  1752. FROM " . POSTS_TABLE . '
  1753. WHERE forum_id = ' . $forum_id;
  1754. $result = $db->sql_query_limit($sql, $batch_size, $start);
  1755.  
  1756. $ids = array();
  1757. while ($row = $db->sql_fetchrow($result))
  1758. {
  1759. $ids[] = $row[$field];
  1760. }
  1761. $db->sql_freeresult($result);
  1762.  
  1763. if (sizeof($ids))
  1764. {
  1765. $start += sizeof($ids);
  1766.  
  1767. foreach ($tables as $table)
  1768. {
  1769. $db->sql_query("DELETE FROM $table WHERE " . $db->sql_in_set($field, $ids));
  1770. }
  1771. }
  1772. }
  1773. while (sizeof($ids) == $batch_size);
  1774. }
  1775. unset($ids);
  1776.  
  1777. break;
  1778. }
  1779.  
  1780. $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, LOG_TABLE, MODERATOR_CACHE_TABLE, POSTS_TABLE, TOPICS_TABLE, TOPICS_TRACK_TABLE);
  1781.  
  1782. foreach ($table_ary as $table)
  1783. {
  1784. $db->sql_query("DELETE FROM $table WHERE forum_id = $forum_id");
  1785. }
  1786.  
  1787. // Set forum ids to 0
  1788. $table_ary = array(DRAFTS_TABLE);
  1789.  
  1790. foreach ($table_ary as $table)
  1791. {
  1792. $db->sql_query("UPDATE $table SET forum_id = 0 WHERE forum_id = $forum_id");
  1793. }
  1794.  
  1795. // Adjust users post counts
  1796. if (sizeof($post_counts))
  1797. {
  1798. foreach ($post_counts as $poster_id => $substract)
  1799. {
  1800. $sql = 'UPDATE ' . USERS_TABLE . '
  1801. SET user_posts = 0
  1802. WHERE user_id = ' . $poster_id . '
  1803. AND user_posts < ' . $substract;
  1804. $db->sql_query($sql);
  1805.  
  1806. $sql = 'UPDATE ' . USERS_TABLE . '
  1807. SET user_posts = user_posts - ' . $substract . '
  1808. WHERE user_id = ' . $poster_id . '
  1809. AND user_posts >= ' . $substract;
  1810. $db->sql_query($sql);
  1811. }
  1812. }
  1813.  
  1814. $db->sql_transaction('commit');
  1815.  
  1816. // Make sure the overall post/topic count is correct...
  1817. $sql = 'SELECT COUNT(post_id) AS stat
  1818. FROM ' . POSTS_TABLE . '
  1819. WHERE post_approved = 1';
  1820. $result = $db->sql_query($sql);
  1821. $row = $db->sql_fetchrow($result);
  1822. $db->sql_freeresult($result);
  1823.  
  1824. set_config('num_posts', (int) $row['stat'], true);
  1825.  
  1826. $sql = 'SELECT COUNT(topic_id) AS stat
  1827. FROM ' . TOPICS_TABLE . '
  1828. WHERE topic_approved = 1';
  1829. $result = $db->sql_query($sql);
  1830. $row = $db->sql_fetchrow($result);
  1831. $db->sql_freeresult($result);
  1832.  
  1833. set_config('num_topics', (int) $row['stat'], true);
  1834.  
  1835. $sql = 'SELECT COUNT(attach_id) as stat
  1836. FROM ' . ATTACHMENTS_TABLE;
  1837. $result = $db->sql_query($sql);
  1838. $row = $db->sql_fetchrow($result);
  1839. $db->sql_freeresult($result);
  1840.  
  1841. set_config('num_files', (int) $row['stat'], true);
  1842.  
  1843. $sql = 'SELECT SUM(filesize) as stat
  1844. FROM ' . ATTACHMENTS_TABLE;
  1845. $result = $db->sql_query($sql);
  1846. $row = $db->sql_fetchrow($result);
  1847. $db->sql_freeresult($result);
  1848.  
  1849. set_config('upload_dir_size', (float) $row['stat'], true);
  1850.  
  1851. return array();
  1852. }
  1853.  
  1854. /**
  1855. * Move forum position by $steps up/down
  1856. */
  1857. function move_forum_by($forum_row, $action = 'move_up', $steps = 1)
  1858. {
  1859. global $db;
  1860.  
  1861. /**
  1862. * Fetch all the siblings between the module's current spot
  1863. * and where we want to move it to. If there are less than $steps
  1864. * siblings between the current spot and the target then the
  1865. * module will move as far as possible
  1866. */
  1867. $sql = 'SELECT forum_id, forum_name, left_id, right_id
  1868. FROM ' . FORUMS_TABLE . "
  1869. WHERE parent_id = {$forum_row['parent_id']}
  1870. AND " . (($action == 'move_up') ? "right_id < {$forum_row['right_id']} ORDER BY right_id DESC" : "left_id > {$forum_row['left_id']} ORDER BY left_id ASC");
  1871. $result = $db->sql_query_limit($sql, $steps);
  1872.  
  1873. $target = array();
  1874. while ($row = $db->sql_fetchrow($result))
  1875. {
  1876. $target = $row;
  1877. }
  1878. $db->sql_freeresult($result);
  1879.  
  1880. if (!sizeof($target))
  1881. {
  1882. // The forum is already on top or bottom
  1883. return false;
  1884. }
  1885.  
  1886. /**
  1887. * $left_id and $right_id define the scope of the nodes that are affected by the move.
  1888. * $diff_up and $diff_down are the values to substract or add to each node's left_id
  1889. * and right_id in order to move them up or down.
  1890. * $move_up_left and $move_up_right define the scope of the nodes that are moving
  1891. * up. Other nodes in the scope of ($left_id, $right_id) are considered to move down.
  1892. */
  1893. if ($action == 'move_up')
  1894. {
  1895. $left_id = $target['left_id'];
  1896. $right_id = $forum_row['right_id'];
  1897.  
  1898. $diff_up = $forum_row['left_id'] - $target['left_id'];
  1899. $diff_down = $forum_row['right_id'] + 1 - $forum_row['left_id'];
  1900.  
  1901. $move_up_left = $forum_row['left_id'];
  1902. $move_up_right = $forum_row['right_id'];
  1903. }
  1904. else
  1905. {
  1906. $left_id = $forum_row['left_id'];
  1907. $right_id = $target['right_id'];
  1908.  
  1909. $diff_up = $forum_row['right_id'] + 1 - $forum_row['left_id'];
  1910. $diff_down = $target['right_id'] - $forum_row['right_id'];
  1911.  
  1912. $move_up_left = $forum_row['right_id'] + 1;
  1913. $move_up_right = $target['right_id'];
  1914. }
  1915.  
  1916. // Now do the dirty job
  1917. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1918. SET left_id = left_id + CASE
  1919. WHEN left_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
  1920. ELSE {$diff_down}
  1921. END,
  1922. right_id = right_id + CASE
  1923. WHEN right_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
  1924. ELSE {$diff_down}
  1925. END,
  1926. forum_parents = ''
  1927. WHERE
  1928. left_id BETWEEN {$left_id} AND {$right_id}
  1929. AND right_id BETWEEN {$left_id} AND {$right_id}";
  1930. $db->sql_query($sql);
  1931.  
  1932. return $target['forum_name'];
  1933. }
  1934.  
  1935. /**
  1936. * Display progress bar for syncinc forums
  1937. */
  1938. function display_progress_bar($start, $total)
  1939. {
  1940. global $template, $user;
  1941.  
  1942. adm_page_header($user->lang['SYNC_IN_PROGRESS']);
  1943.  
  1944. $template->set_filenames(array(
  1945. 'body' => 'progress_bar.html')
  1946. );
  1947.  
  1948. $template->assign_vars(array(
  1949. 'L_PROGRESS' => $user->lang['SYNC_IN_PROGRESS'],
  1950. 'L_PROGRESS_EXPLAIN' => ($start && $total) ? sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $start, $total) : $user->lang['SYNC_IN_PROGRESS'])
  1951. );
  1952.  
  1953. adm_page_footer();
  1954. }
  1955.  
  1956. /**
  1957. * Display copy permission page
  1958. * Not used at the moment - we will have a look at it for 3.0.7
  1959. */
  1960. function copy_permission_page($forum_data)
  1961. {
  1962. global $phpEx, $phpbb_admin_path, $template, $user;
  1963.  
  1964. $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_data['forum_id'];
  1965. $action = append_sid($this->u_action . "&amp;parent_id={$this->parent_id}&amp;f={$forum_data['forum_id']}&amp;action=copy_perm");
  1966.  
  1967. $l_acl = sprintf($user->lang['COPY_TO_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
  1968.  
  1969. $this->tpl_name = 'acp_forums_copy_perm';
  1970.  
  1971. $template->assign_vars(array(
  1972. 'U_ACL' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url),
  1973. 'L_ACL_LINK' => $l_acl,
  1974. 'L_BACK_LINK' => adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id),
  1975. 'S_COPY_ACTION' => $action,
  1976. 'S_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_data['forum_id'], false, false, false),
  1977. ));
  1978. }
  1979.  
  1980. }
  1981.  
  1982. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement