PageRenderTime 64ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/forum/includes/acp/acp_forums.php

https://github.com/GreyTeardrop/socionicasys-forum
PHP | 1964 lines | 1476 code | 345 blank | 143 comment | 230 complexity | acaa3c6dbc35a3c6e1f9e3e268d09619 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-3.0, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  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. * @ignore
  12. */
  13. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. /**
  18. * @package acp
  19. */
  20. class acp_forums
  21. {
  22. var $u_action;
  23. var $parent_id = 0;
  24. function main($id, $mode)
  25. {
  26. global $db, $user, $auth, $template, $cache;
  27. global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
  28. $user->add_lang('acp/forums');
  29. $this->tpl_name = 'acp_forums';
  30. $this->page_title = 'ACP_MANAGE_FORUMS';
  31. $form_key = 'acp_forums';
  32. add_form_key($form_key);
  33. $action = request_var('action', '');
  34. $update = (isset($_POST['update'])) ? true : false;
  35. $forum_id = request_var('f', 0);
  36. $this->parent_id = request_var('parent_id', 0);
  37. $forum_data = $errors = array();
  38. if ($update && !check_form_key($form_key))
  39. {
  40. $update = false;
  41. $errors[] = $user->lang['FORM_INVALID'];
  42. }
  43. // Check additional permissions
  44. switch ($action)
  45. {
  46. case 'progress_bar':
  47. $start = request_var('start', 0);
  48. $total = request_var('total', 0);
  49. $this->display_progress_bar($start, $total);
  50. exit;
  51. break;
  52. case 'delete':
  53. if (!$auth->acl_get('a_forumdel'))
  54. {
  55. trigger_error($user->lang['NO_PERMISSION_FORUM_DELETE'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  56. }
  57. break;
  58. case 'add':
  59. if (!$auth->acl_get('a_forumadd'))
  60. {
  61. trigger_error($user->lang['NO_PERMISSION_FORUM_ADD'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  62. }
  63. break;
  64. }
  65. // Major routines
  66. if ($update)
  67. {
  68. switch ($action)
  69. {
  70. case 'delete':
  71. $action_subforums = request_var('action_subforums', '');
  72. $subforums_to_id = request_var('subforums_to_id', 0);
  73. $action_posts = request_var('action_posts', '');
  74. $posts_to_id = request_var('posts_to_id', 0);
  75. $errors = $this->delete_forum($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id);
  76. if (sizeof($errors))
  77. {
  78. break;
  79. }
  80. $auth->acl_clear_prefetch();
  81. $cache->destroy('sql', FORUMS_TABLE);
  82. trigger_error($user->lang['FORUM_DELETED'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
  83. break;
  84. case 'edit':
  85. $forum_data = array(
  86. 'forum_id' => $forum_id
  87. );
  88. // No break here
  89. case 'add':
  90. $forum_data += array(
  91. 'parent_id' => request_var('forum_parent_id', $this->parent_id),
  92. 'forum_type' => request_var('forum_type', FORUM_POST),
  93. 'type_action' => request_var('type_action', ''),
  94. 'forum_status' => request_var('forum_status', ITEM_UNLOCKED),
  95. 'forum_parents' => '',
  96. 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
  97. 'forum_link' => request_var('forum_link', ''),
  98. 'forum_link_track' => request_var('forum_link_track', false),
  99. 'forum_desc' => utf8_normalize_nfc(request_var('forum_desc', '', true)),
  100. 'forum_desc_uid' => '',
  101. 'forum_desc_options' => 7,
  102. 'forum_desc_bitfield' => '',
  103. 'forum_rules' => utf8_normalize_nfc(request_var('forum_rules', '', true)),
  104. 'forum_rules_uid' => '',
  105. 'forum_rules_options' => 7,
  106. 'forum_rules_bitfield' => '',
  107. 'forum_rules_link' => request_var('forum_rules_link', ''),
  108. 'forum_image' => request_var('forum_image', ''),
  109. 'forum_style' => request_var('forum_style', 0),
  110. 'display_subforum_list' => request_var('display_subforum_list', false),
  111. 'display_on_index' => request_var('display_on_index', false),
  112. 'forum_topics_per_page' => request_var('topics_per_page', 0),
  113. 'enable_indexing' => request_var('enable_indexing', true),
  114. 'enable_icons' => request_var('enable_icons', false),
  115. 'enable_prune' => request_var('enable_prune', false),
  116. 'enable_post_review' => request_var('enable_post_review', true),
  117. 'enable_quick_reply' => request_var('enable_quick_reply', false),
  118. 'prune_days' => request_var('prune_days', 7),
  119. 'prune_viewed' => request_var('prune_viewed', 7),
  120. 'prune_freq' => request_var('prune_freq', 1),
  121. 'prune_old_polls' => request_var('prune_old_polls', false),
  122. 'prune_announce' => request_var('prune_announce', false),
  123. 'prune_sticky' => request_var('prune_sticky', false),
  124. 'forum_password' => request_var('forum_password', '', true),
  125. 'forum_password_confirm'=> request_var('forum_password_confirm', '', true),
  126. 'forum_password_unset' => request_var('forum_password_unset', false),
  127. );
  128. // On add, add empty forum_options... else do not consider it (not updating it)
  129. if ($action == 'add')
  130. {
  131. $forum_data['forum_options'] = 0;
  132. }
  133. // Use link_display_on_index setting if forum type is link
  134. if ($forum_data['forum_type'] == FORUM_LINK)
  135. {
  136. $forum_data['display_on_index'] = request_var('link_display_on_index', false);
  137. }
  138. // Linked forums and categories are not able to be locked...
  139. if ($forum_data['forum_type'] == FORUM_LINK || $forum_data['forum_type'] == FORUM_CAT)
  140. {
  141. $forum_data['forum_status'] = ITEM_UNLOCKED;
  142. }
  143. $forum_data['show_active'] = ($forum_data['forum_type'] == FORUM_POST) ? request_var('display_recent', true) : request_var('display_active', false);
  144. // Get data for forum rules if specified...
  145. if ($forum_data['forum_rules'])
  146. {
  147. 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));
  148. }
  149. // Get data for forum description if specified
  150. if ($forum_data['forum_desc'])
  151. {
  152. 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));
  153. }
  154. $errors = $this->update_forum_data($forum_data);
  155. if (!sizeof($errors))
  156. {
  157. $forum_perm_from = request_var('forum_perm_from', 0);
  158. $cache->destroy('sql', FORUMS_TABLE);
  159. $copied_permissions = false;
  160. // Copy permissions?
  161. if ($forum_perm_from && $forum_perm_from != $forum_data['forum_id'] &&
  162. ($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'))))
  163. {
  164. copy_forum_permissions($forum_perm_from, $forum_data['forum_id'], ($action == 'edit') ? true : false);
  165. cache_moderators();
  166. $copied_permissions = true;
  167. }
  168. /* Commented out because of questionable UI workflow - re-visit for 3.0.7
  169. 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'))
  170. {
  171. $this->copy_permission_page($forum_data);
  172. return;
  173. }
  174. */
  175. $auth->acl_clear_prefetch();
  176. $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_data['forum_id'];
  177. $message = ($action == 'add') ? $user->lang['FORUM_CREATED'] : $user->lang['FORUM_UPDATED'];
  178. // Redirect to permissions
  179. if ($auth->acl_get('a_fauth') && !$copied_permissions)
  180. {
  181. $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
  182. }
  183. // redirect directly to permission settings screen if authed
  184. if ($action == 'add' && !$copied_permissions && $auth->acl_get('a_fauth'))
  185. {
  186. meta_refresh(4, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url));
  187. }
  188. trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
  189. }
  190. break;
  191. }
  192. }
  193. switch ($action)
  194. {
  195. case 'move_up':
  196. case 'move_down':
  197. if (!$forum_id)
  198. {
  199. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  200. }
  201. $sql = 'SELECT *
  202. FROM ' . FORUMS_TABLE . "
  203. WHERE forum_id = $forum_id";
  204. $result = $db->sql_query($sql);
  205. $row = $db->sql_fetchrow($result);
  206. $db->sql_freeresult($result);
  207. if (!$row)
  208. {
  209. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  210. }
  211. $move_forum_name = $this->move_forum_by($row, $action, 1);
  212. if ($move_forum_name !== false)
  213. {
  214. add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name);
  215. $cache->destroy('sql', FORUMS_TABLE);
  216. }
  217. break;
  218. case 'sync':
  219. if (!$forum_id)
  220. {
  221. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  222. }
  223. @set_time_limit(0);
  224. $sql = 'SELECT forum_name, forum_topics_real
  225. FROM ' . FORUMS_TABLE . "
  226. WHERE forum_id = $forum_id";
  227. $result = $db->sql_query($sql);
  228. $row = $db->sql_fetchrow($result);
  229. $db->sql_freeresult($result);
  230. if (!$row)
  231. {
  232. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  233. }
  234. if ($row['forum_topics_real'])
  235. {
  236. $sql = 'SELECT MIN(topic_id) as min_topic_id, MAX(topic_id) as max_topic_id
  237. FROM ' . TOPICS_TABLE . '
  238. WHERE forum_id = ' . $forum_id;
  239. $result = $db->sql_query($sql);
  240. $row2 = $db->sql_fetchrow($result);
  241. $db->sql_freeresult($result);
  242. // Typecast to int if there is no data available
  243. $row2['min_topic_id'] = (int) $row2['min_topic_id'];
  244. $row2['max_topic_id'] = (int) $row2['max_topic_id'];
  245. $start = request_var('start', $row2['min_topic_id']);
  246. $batch_size = 2000;
  247. $end = $start + $batch_size;
  248. // Sync all topics in batch mode...
  249. sync('topic_approved', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false);
  250. sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true);
  251. if ($end < $row2['max_topic_id'])
  252. {
  253. // We really need to find a way of showing statistics... no progress here
  254. $sql = 'SELECT COUNT(topic_id) as num_topics
  255. FROM ' . TOPICS_TABLE . '
  256. WHERE forum_id = ' . $forum_id . '
  257. AND topic_id BETWEEN ' . $start . ' AND ' . $end;
  258. $result = $db->sql_query($sql);
  259. $topics_done = request_var('topics_done', 0) + (int) $db->sql_fetchfield('num_topics');
  260. $db->sql_freeresult($result);
  261. $start += $batch_size;
  262. $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']}";
  263. meta_refresh(0, $url);
  264. $template->assign_vars(array(
  265. 'U_PROGRESS_BAR' => $this->u_action . "&amp;action=progress_bar&amp;start=$topics_done&amp;total={$row['forum_topics_real']}",
  266. 'UA_PROGRESS_BAR' => addslashes($this->u_action . "&amp;action=progress_bar&amp;start=$topics_done&amp;total={$row['forum_topics_real']}"),
  267. 'S_CONTINUE_SYNC' => true,
  268. 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['forum_topics_real']))
  269. );
  270. return;
  271. }
  272. }
  273. $url = $this->u_action . "&amp;parent_id={$this->parent_id}&amp;f=$forum_id&amp;action=sync_forum";
  274. meta_refresh(0, $url);
  275. $template->assign_vars(array(
  276. 'U_PROGRESS_BAR' => $this->u_action . '&amp;action=progress_bar',
  277. 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&amp;action=progress_bar'),
  278. 'S_CONTINUE_SYNC' => true,
  279. 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['forum_topics_real']))
  280. );
  281. return;
  282. break;
  283. case 'sync_forum':
  284. $sql = 'SELECT forum_name, forum_type
  285. FROM ' . FORUMS_TABLE . "
  286. WHERE forum_id = $forum_id";
  287. $result = $db->sql_query($sql);
  288. $row = $db->sql_fetchrow($result);
  289. $db->sql_freeresult($result);
  290. if (!$row)
  291. {
  292. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  293. }
  294. sync('forum', 'forum_id', $forum_id, false, true);
  295. add_log('admin', 'LOG_FORUM_SYNC', $row['forum_name']);
  296. $cache->destroy('sql', FORUMS_TABLE);
  297. $template->assign_var('L_FORUM_RESYNCED', sprintf($user->lang['FORUM_RESYNCED'], $row['forum_name']));
  298. break;
  299. case 'add':
  300. case 'edit':
  301. if ($update)
  302. {
  303. $forum_data['forum_flags'] = 0;
  304. $forum_data['forum_flags'] += (request_var('forum_link_track', false)) ? FORUM_FLAG_LINK_TRACK : 0;
  305. $forum_data['forum_flags'] += (request_var('prune_old_polls', false)) ? FORUM_FLAG_PRUNE_POLL : 0;
  306. $forum_data['forum_flags'] += (request_var('prune_announce', false)) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
  307. $forum_data['forum_flags'] += (request_var('prune_sticky', false)) ? FORUM_FLAG_PRUNE_STICKY : 0;
  308. $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
  309. $forum_data['forum_flags'] += (request_var('enable_post_review', true)) ? FORUM_FLAG_POST_REVIEW : 0;
  310. $forum_data['forum_flags'] += (request_var('enable_quick_reply', false)) ? FORUM_FLAG_QUICK_REPLY : 0;
  311. }
  312. // Show form to create/modify a forum
  313. if ($action == 'edit')
  314. {
  315. $this->page_title = 'EDIT_FORUM';
  316. $row = $this->get_forum_info($forum_id);
  317. $old_forum_type = $row['forum_type'];
  318. if (!$update)
  319. {
  320. $forum_data = $row;
  321. }
  322. else
  323. {
  324. $forum_data['left_id'] = $row['left_id'];
  325. $forum_data['right_id'] = $row['right_id'];
  326. }
  327. // Make sure no direct child forums are able to be selected as parents.
  328. $exclude_forums = array();
  329. foreach (get_forum_branch($forum_id, 'children') as $row)
  330. {
  331. $exclude_forums[] = $row['forum_id'];
  332. }
  333. $parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false);
  334. $forum_data['forum_password_confirm'] = $forum_data['forum_password'];
  335. }
  336. else
  337. {
  338. $this->page_title = 'CREATE_FORUM';
  339. $forum_id = $this->parent_id;
  340. $parents_list = make_forum_select($this->parent_id, false, false, false, false);
  341. // Fill forum data with default values
  342. if (!$update)
  343. {
  344. $forum_data = array(
  345. 'parent_id' => $this->parent_id,
  346. 'forum_type' => FORUM_POST,
  347. 'forum_status' => ITEM_UNLOCKED,
  348. 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
  349. 'forum_link' => '',
  350. 'forum_link_track' => false,
  351. 'forum_desc' => '',
  352. 'forum_rules' => '',
  353. 'forum_rules_link' => '',
  354. 'forum_image' => '',
  355. 'forum_style' => 0,
  356. 'display_subforum_list' => true,
  357. 'display_on_index' => false,
  358. 'forum_topics_per_page' => 0,
  359. 'enable_indexing' => true,
  360. 'enable_icons' => false,
  361. 'enable_prune' => false,
  362. 'prune_days' => 7,
  363. 'prune_viewed' => 7,
  364. 'prune_freq' => 1,
  365. 'forum_flags' => FORUM_FLAG_POST_REVIEW + FORUM_FLAG_ACTIVE_TOPICS,
  366. 'forum_options' => 0,
  367. 'forum_password' => '',
  368. 'forum_password_confirm'=> '',
  369. );
  370. }
  371. }
  372. $forum_rules_data = array(
  373. 'text' => $forum_data['forum_rules'],
  374. 'allow_bbcode' => true,
  375. 'allow_smilies' => true,
  376. 'allow_urls' => true
  377. );
  378. $forum_desc_data = array(
  379. 'text' => $forum_data['forum_desc'],
  380. 'allow_bbcode' => true,
  381. 'allow_smilies' => true,
  382. 'allow_urls' => true
  383. );
  384. $forum_rules_preview = '';
  385. // Parse rules if specified
  386. if ($forum_data['forum_rules'])
  387. {
  388. if (!isset($forum_data['forum_rules_uid']))
  389. {
  390. // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
  391. $forum_data['forum_rules_uid'] = '';
  392. $forum_data['forum_rules_bitfield'] = '';
  393. $forum_data['forum_rules_options'] = 0;
  394. 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));
  395. }
  396. // Generate preview content
  397. $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']);
  398. // decode...
  399. $forum_rules_data = generate_text_for_edit($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_options']);
  400. }
  401. // Parse desciption if specified
  402. if ($forum_data['forum_desc'])
  403. {
  404. if (!isset($forum_data['forum_desc_uid']))
  405. {
  406. // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
  407. $forum_data['forum_desc_uid'] = '';
  408. $forum_data['forum_desc_bitfield'] = '';
  409. $forum_data['forum_desc_options'] = 0;
  410. 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));
  411. }
  412. // decode...
  413. $forum_desc_data = generate_text_for_edit($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_options']);
  414. }
  415. $forum_type_options = '';
  416. $forum_type_ary = array(FORUM_CAT => 'CAT', FORUM_POST => 'FORUM', FORUM_LINK => 'LINK');
  417. foreach ($forum_type_ary as $value => $lang)
  418. {
  419. $forum_type_options .= '<option value="' . $value . '"' . (($value == $forum_data['forum_type']) ? ' selected="selected"' : '') . '>' . $user->lang['TYPE_' . $lang] . '</option>';
  420. }
  421. $styles_list = style_select($forum_data['forum_style'], true);
  422. $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>';
  423. $sql = 'SELECT forum_id
  424. FROM ' . FORUMS_TABLE . '
  425. WHERE forum_type = ' . FORUM_POST . "
  426. AND forum_id <> $forum_id";
  427. $result = $db->sql_query_limit($sql, 1);
  428. $postable_forum_exists = false;
  429. if ($db->sql_fetchrow($result))
  430. {
  431. $postable_forum_exists = true;
  432. }
  433. $db->sql_freeresult($result);
  434. // Subforum move options
  435. if ($action == 'edit' && $forum_data['forum_type'] == FORUM_CAT)
  436. {
  437. $subforums_id = array();
  438. $subforums = get_forum_branch($forum_id, 'children');
  439. foreach ($subforums as $row)
  440. {
  441. $subforums_id[] = $row['forum_id'];
  442. }
  443. $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
  444. if ($postable_forum_exists)
  445. {
  446. $template->assign_vars(array(
  447. 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id)) // , false, true, false???
  448. );
  449. }
  450. $template->assign_vars(array(
  451. 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
  452. 'S_FORUMS_LIST' => $forums_list)
  453. );
  454. }
  455. else if ($postable_forum_exists)
  456. {
  457. $template->assign_vars(array(
  458. 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_id, false, true, false))
  459. );
  460. }
  461. $s_show_display_on_index = false;
  462. if ($forum_data['parent_id'] > 0)
  463. {
  464. // if this forum is a subforum put the "display on index" checkbox
  465. if ($parent_info = $this->get_forum_info($forum_data['parent_id']))
  466. {
  467. if ($parent_info['parent_id'] > 0 || $parent_info['forum_type'] == FORUM_CAT)
  468. {
  469. $s_show_display_on_index = true;
  470. }
  471. }
  472. }
  473. if (strlen($forum_data['forum_password']) == 32)
  474. {
  475. $errors[] = $user->lang['FORUM_PASSWORD_OLD'];
  476. }
  477. $template->assign_vars(array(
  478. 'S_EDIT_FORUM' => true,
  479. 'S_ERROR' => (sizeof($errors)) ? true : false,
  480. 'S_PARENT_ID' => $this->parent_id,
  481. 'S_FORUM_PARENT_ID' => $forum_data['parent_id'],
  482. 'S_ADD_ACTION' => ($action == 'add') ? true : false,
  483. 'U_BACK' => $this->u_action . '&amp;parent_id=' . $this->parent_id,
  484. 'U_EDIT_ACTION' => $this->u_action . "&amp;parent_id={$this->parent_id}&amp;action=$action&amp;f=$forum_id",
  485. 'L_COPY_PERMISSIONS_EXPLAIN' => $user->lang['COPY_PERMISSIONS_' . strtoupper($action) . '_EXPLAIN'],
  486. 'L_TITLE' => $user->lang[$this->page_title],
  487. 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
  488. 'FORUM_NAME' => $forum_data['forum_name'],
  489. 'FORUM_DATA_LINK' => $forum_data['forum_link'],
  490. 'FORUM_IMAGE' => $forum_data['forum_image'],
  491. 'FORUM_IMAGE_SRC' => ($forum_data['forum_image']) ? $phpbb_root_path . $forum_data['forum_image'] : '',
  492. 'FORUM_POST' => FORUM_POST,
  493. 'FORUM_LINK' => FORUM_LINK,
  494. 'FORUM_CAT' => FORUM_CAT,
  495. 'PRUNE_FREQ' => $forum_data['prune_freq'],
  496. 'PRUNE_DAYS' => $forum_data['prune_days'],
  497. 'PRUNE_VIEWED' => $forum_data['prune_viewed'],
  498. 'TOPICS_PER_PAGE' => $forum_data['forum_topics_per_page'],
  499. 'FORUM_RULES_LINK' => $forum_data['forum_rules_link'],
  500. 'FORUM_RULES' => $forum_data['forum_rules'],
  501. 'FORUM_RULES_PREVIEW' => $forum_rules_preview,
  502. 'FORUM_RULES_PLAIN' => $forum_rules_data['text'],
  503. 'S_BBCODE_CHECKED' => ($forum_rules_data['allow_bbcode']) ? true : false,
  504. 'S_SMILIES_CHECKED' => ($forum_rules_data['allow_smilies']) ? true : false,
  505. 'S_URLS_CHECKED' => ($forum_rules_data['allow_urls']) ? true : false,
  506. 'S_FORUM_PASSWORD_SET' => (empty($forum_data['forum_password'])) ? false : true,
  507. 'FORUM_DESC' => $forum_desc_data['text'],
  508. 'S_DESC_BBCODE_CHECKED' => ($forum_desc_data['allow_bbcode']) ? true : false,
  509. 'S_DESC_SMILIES_CHECKED' => ($forum_desc_data['allow_smilies']) ? true : false,
  510. 'S_DESC_URLS_CHECKED' => ($forum_desc_data['allow_urls']) ? true : false,
  511. 'S_FORUM_TYPE_OPTIONS' => $forum_type_options,
  512. 'S_STATUS_OPTIONS' => $statuslist,
  513. 'S_PARENT_OPTIONS' => $parents_list,
  514. 'S_STYLES_OPTIONS' => $styles_list,
  515. 'S_FORUM_OPTIONS' => make_forum_select(($action == 'add') ? $forum_data['parent_id'] : false, ($action == 'edit') ? $forum_data['forum_id'] : false, false, false, false),
  516. 'S_SHOW_DISPLAY_ON_INDEX' => $s_show_display_on_index,
  517. 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
  518. 'S_FORUM_ORIG_POST' => (isset($old_forum_type) && $old_forum_type == FORUM_POST) ? true : false,
  519. 'S_FORUM_ORIG_CAT' => (isset($old_forum_type) && $old_forum_type == FORUM_CAT) ? true : false,
  520. 'S_FORUM_ORIG_LINK' => (isset($old_forum_type) && $old_forum_type == FORUM_LINK) ? true : false,
  521. 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
  522. 'S_FORUM_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
  523. 'S_ENABLE_INDEXING' => ($forum_data['enable_indexing']) ? true : false,
  524. 'S_TOPIC_ICONS' => ($forum_data['enable_icons']) ? true : false,
  525. 'S_DISPLAY_SUBFORUM_LIST' => ($forum_data['display_subforum_list']) ? true : false,
  526. 'S_DISPLAY_ON_INDEX' => ($forum_data['display_on_index']) ? true : false,
  527. 'S_PRUNE_ENABLE' => ($forum_data['enable_prune']) ? true : false,
  528. 'S_FORUM_LINK_TRACK' => ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? true : false,
  529. 'S_PRUNE_OLD_POLLS' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL) ? true : false,
  530. 'S_PRUNE_ANNOUNCE' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE) ? true : false,
  531. 'S_PRUNE_STICKY' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_STICKY) ? true : false,
  532. 'S_DISPLAY_ACTIVE_TOPICS' => ($forum_data['forum_type'] == FORUM_POST) ? ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) : true,
  533. 'S_ENABLE_ACTIVE_TOPICS' => ($forum_data['forum_type'] == FORUM_CAT) ? ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) : false,
  534. 'S_ENABLE_POST_REVIEW' => ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false,
  535. 'S_ENABLE_QUICK_REPLY' => ($forum_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY) ? true : false,
  536. '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,
  537. ));
  538. return;
  539. break;
  540. case 'delete':
  541. if (!$forum_id)
  542. {
  543. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  544. }
  545. $forum_data = $this->get_forum_info($forum_id);
  546. $subforums_id = array();
  547. $subforums = get_forum_branch($forum_id, 'children');
  548. foreach ($subforums as $row)
  549. {
  550. $subforums_id[] = $row['forum_id'];
  551. }
  552. $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
  553. $sql = 'SELECT forum_id
  554. FROM ' . FORUMS_TABLE . '
  555. WHERE forum_type = ' . FORUM_POST . "
  556. AND forum_id <> $forum_id";
  557. $result = $db->sql_query_limit($sql, 1);
  558. if ($db->sql_fetchrow($result))
  559. {
  560. $template->assign_vars(array(
  561. 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id, false, true)) // , false, true, false???
  562. );
  563. }
  564. $db->sql_freeresult($result);
  565. $parent_id = ($this->parent_id == $forum_id) ? 0 : $this->parent_id;
  566. $template->assign_vars(array(
  567. 'S_DELETE_FORUM' => true,
  568. 'U_ACTION' => $this->u_action . "&amp;parent_id={$parent_id}&amp;action=delete&amp;f=$forum_id",
  569. 'U_BACK' => $this->u_action . '&amp;parent_id=' . $this->parent_id,
  570. 'FORUM_NAME' => $forum_data['forum_name'],
  571. 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
  572. 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
  573. 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
  574. 'S_FORUMS_LIST' => $forums_list,
  575. 'S_ERROR' => (sizeof($errors)) ? true : false,
  576. 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '')
  577. );
  578. return;
  579. break;
  580. case 'copy_perm':
  581. $forum_perm_from = request_var('forum_perm_from', 0);
  582. // Copy permissions?
  583. if (!empty($forum_perm_from) && $forum_perm_from != $forum_id)
  584. {
  585. copy_forum_permissions($forum_perm_from, $forum_id, true);
  586. cache_moderators();
  587. $auth->acl_clear_prefetch();
  588. $cache->destroy('sql', FORUMS_TABLE);
  589. $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_id;
  590. $message = $user->lang['FORUM_UPDATED'];
  591. // Redirect to permissions
  592. if ($auth->acl_get('a_fauth'))
  593. {
  594. $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
  595. }
  596. trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
  597. }
  598. break;
  599. }
  600. // Default management page
  601. if (!$this->parent_id)
  602. {
  603. $navigation = $user->lang['FORUM_INDEX'];
  604. }
  605. else
  606. {
  607. $navigation = '<a href="' . $this->u_action . '">' . $user->lang['FORUM_INDEX'] . '</a>';
  608. $forums_nav = get_forum_branch($this->parent_id, 'parents', 'descending');
  609. foreach ($forums_nav as $row)
  610. {
  611. if ($row['forum_id'] == $this->parent_id)
  612. {
  613. $navigation .= ' -&gt; ' . $row['forum_name'];
  614. }
  615. else
  616. {
  617. $navigation .= ' -&gt; <a href="' . $this->u_action . '&amp;parent_id=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>';
  618. }
  619. }
  620. }
  621. // Jumpbox
  622. $forum_box = make_forum_select($this->parent_id, false, false, false, false); //make_forum_select($this->parent_id);
  623. if ($action == 'sync' || $action == 'sync_forum')
  624. {
  625. $template->assign_var('S_RESYNCED', true);
  626. }
  627. $sql = 'SELECT *
  628. FROM ' . FORUMS_TABLE . "
  629. WHERE parent_id = $this->parent_id
  630. ORDER BY left_id";
  631. $result = $db->sql_query($sql);
  632. if ($row = $db->sql_fetchrow($result))
  633. {
  634. do
  635. {
  636. $forum_type = $row['forum_type'];
  637. if ($row['forum_status'] == ITEM_LOCKED)
  638. {
  639. $folder_image = '<img src="images/icon_folder_lock.gif" alt="' . $user->lang['LOCKED'] . '" />';
  640. }
  641. else
  642. {
  643. switch ($forum_type)
  644. {
  645. case FORUM_LINK:
  646. $folder_image = '<img src="images/icon_folder_link.gif" alt="' . $user->lang['LINK'] . '" />';
  647. break;
  648. default:
  649. $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'] . '" />';
  650. break;
  651. }
  652. }
  653. $url = $this->u_action . "&amp;parent_id=$this->parent_id&amp;f={$row['forum_id']}";
  654. $template->assign_block_vars('forums', array(
  655. 'FOLDER_IMAGE' => $folder_image,
  656. 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="" />' : '',
  657. 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
  658. 'FORUM_NAME' => $row['forum_name'],
  659. 'FORUM_DESCRIPTION' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
  660. 'FORUM_TOPICS' => $row['forum_topics'],
  661. 'FORUM_POSTS' => $row['forum_posts'],
  662. 'S_FORUM_LINK' => ($forum_type == FORUM_LINK) ? true : false,
  663. 'S_FORUM_POST' => ($forum_type == FORUM_POST) ? true : false,
  664. 'U_FORUM' => $this->u_action . '&amp;parent_id=' . $row['forum_id'],
  665. 'U_MOVE_UP' => $url . '&amp;action=move_up',
  666. 'U_MOVE_DOWN' => $url . '&amp;action=move_down',
  667. 'U_EDIT' => $url . '&amp;action=edit',
  668. 'U_DELETE' => $url . '&amp;action=delete',
  669. 'U_SYNC' => $url . '&amp;action=sync')
  670. );
  671. }
  672. while ($row = $db->sql_fetchrow($result));
  673. }
  674. else if ($this->parent_id)
  675. {
  676. $row = $this->get_forum_info($this->parent_id);
  677. $url = $this->u_action . '&amp;parent_id=' . $this->parent_id . '&amp;f=' . $row['forum_id'];
  678. $template->assign_vars(array(
  679. 'S_NO_FORUMS' => true,
  680. 'U_EDIT' => $url . '&amp;action=edit',
  681. 'U_DELETE' => $url . '&amp;action=delete',
  682. 'U_SYNC' => $url . '&amp;action=sync')
  683. );
  684. }
  685. $db->sql_freeresult($result);
  686. $template->assign_vars(array(
  687. 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
  688. 'NAVIGATION' => $navigation,
  689. 'FORUM_BOX' => $forum_box,
  690. 'U_SEL_ACTION' => $this->u_action,
  691. 'U_ACTION' => $this->u_action . '&amp;parent_id=' . $this->parent_id,
  692. 'U_PROGRESS_BAR' => $this->u_action . '&amp;action=progress_bar',
  693. 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&amp;action=progress_bar'),
  694. ));
  695. }
  696. /**
  697. * Get forum details
  698. */
  699. function get_forum_info($forum_id)
  700. {
  701. global $db;
  702. $sql = 'SELECT *
  703. FROM ' . FORUMS_TABLE . "
  704. WHERE forum_id = $forum_id";
  705. $result = $db->sql_query($sql);
  706. $row = $db->sql_fetchrow($result);
  707. $db->sql_freeresult($result);
  708. if (!$row)
  709. {
  710. trigger_error("Forum #$forum_id does not exist", E_USER_ERROR);
  711. }
  712. return $row;
  713. }
  714. /**
  715. * Update forum data
  716. */
  717. function update_forum_data(&$forum_data)
  718. {
  719. global $db, $user, $cache, $phpbb_root_path;
  720. $errors = array();
  721. if (!$forum_data['forum_name'])
  722. {
  723. $errors[] = $user->lang['FORUM_NAME_EMPTY'];
  724. }
  725. if (utf8_strlen($forum_data['forum_desc']) > 4000)
  726. {
  727. $errors[] = $user->lang['FORUM_DESC_TOO_LONG'];
  728. }
  729. if (utf8_strlen($forum_data['forum_rules']) > 4000)
  730. {
  731. $errors[] = $user->lang['FORUM_RULES_TOO_LONG'];
  732. }
  733. if ($forum_data['forum_password'] || $forum_data['forum_password_confirm'])
  734. {
  735. if ($forum_data['forum_password'] != $forum_data['forum_password_confirm'])
  736. {
  737. $forum_data['forum_password'] = $forum_data['forum_password_confirm'] = '';
  738. $errors[] = $user->lang['FORUM_PASSWORD_MISMATCH'];
  739. }
  740. }
  741. if ($forum_data['prune_days'] < 0 || $forum_data['prune_viewed'] < 0 || $forum_data['prune_freq'] < 0)
  742. {
  743. $forum_data['prune_days'] = $forum_data['prune_viewed'] = $forum_data['prune_freq'] = 0;
  744. $errors[] = $user->lang['FORUM_DATA_NEGATIVE'];
  745. }
  746. $range_test_ary = array(
  747. array('lang' => 'FORUM_TOPICS_PAGE', 'value' => $forum_data['forum_topics_per_page'], 'column_type' => 'TINT:0'),
  748. );
  749. if (!empty($forum_data['forum_image']) && !file_exists($phpbb_root_path . $forum_data['forum_image']))
  750. {
  751. $errors[] = $user->lang['FORUM_IMAGE_NO_EXIST'];
  752. }
  753. validate_range($range_test_ary, $errors);
  754. // Set forum flags
  755. // 1 = link tracking
  756. // 2 = prune old polls
  757. // 4 = prune announcements
  758. // 8 = prune stickies
  759. // 16 = show active topics
  760. // 32 = enable post review
  761. $forum_data['forum_flags'] = 0;
  762. $forum_data['forum_flags'] += ($forum_data['forum_link_track']) ? FORUM_FLAG_LINK_TRACK : 0;
  763. $forum_data['forum_flags'] += ($forum_data['prune_old_polls']) ? FORUM_FLAG_PRUNE_POLL : 0;
  764. $forum_data['forum_flags'] += ($forum_data['prune_announce']) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
  765. $forum_data['forum_flags'] += ($forum_data['prune_sticky']) ? FORUM_FLAG_PRUNE_STICKY : 0;
  766. $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
  767. $forum_data['forum_flags'] += ($forum_data['enable_post_review']) ? FORUM_FLAG_POST_REVIEW : 0;
  768. $forum_data['forum_flags'] += ($forum_data['enable_quick_reply']) ? FORUM_FLAG_QUICK_REPLY : 0;
  769. // Unset data that are not database fields
  770. $forum_data_sql = $forum_data;
  771. unset($forum_data_sql['forum_link_track']);
  772. unset($forum_data_sql['prune_old_polls']);
  773. unset($forum_data_sql['prune_announce']);
  774. unset($forum_data_sql['prune_sticky']);
  775. unset($forum_data_sql['show_active']);
  776. unset($forum_data_sql['enable_post_review']);
  777. unset($forum_data_sql['enable_quick_reply']);
  778. unset($forum_data_sql['forum_password_confirm']);
  779. // What are we going to do tonight Brain? The same thing we do everynight,
  780. // try to take over the world ... or decide whether to continue update
  781. // and if so, whether it's a new forum/cat/link or an existing one
  782. if (sizeof($errors))
  783. {
  784. return $errors;
  785. }
  786. // As we don't know the old password, it's kinda tricky to detect changes
  787. if ($forum_data_sql['forum_password_unset'])
  788. {
  789. $forum_data_sql['forum_password'] = '';
  790. }
  791. else if (empty($forum_data_sql['forum_password']))
  792. {
  793. unset($forum_data_sql['forum_password']);
  794. }
  795. else
  796. {
  797. $forum_data_sql['forum_password'] = phpbb_hash($forum_data_sql['forum_password']);
  798. }
  799. unset($forum_data_sql['forum_password_unset']);
  800. if (!isset($forum_data_sql['forum_id']))
  801. {
  802. // no forum_id means we're creating a new forum
  803. unset($forum_data_sql['type_action']);
  804. if ($forum_data_sql['parent_id'])
  805. {
  806. $sql = 'SELECT left_id, right_id, forum_type
  807. FROM ' . FORUMS_TABLE . '
  808. WHERE forum_id = ' . $forum_data_sql['parent_id'];
  809. $result = $db->sql_query($sql);
  810. $row = $db->sql_fetchrow($result);
  811. $db->sql_freeresult($result);
  812. if (!$row)
  813. {
  814. trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
  815. }
  816. if ($row['forum_type'] == FORUM_LINK)
  817. {
  818. $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
  819. return $errors;
  820. }
  821. $sql = 'UPDATE ' . FORUMS_TABLE . '
  822. SET left_id = left_id + 2, right_id = right_id + 2
  823. WHERE left_id > ' . $row['right_id'];
  824. $db->sql_query($sql);
  825. $sql = 'UPDATE ' . FORUMS_TABLE . '
  826. SET right_id = right_id + 2
  827. WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
  828. $db->sql_query($sql);
  829. $forum_data_sql['left_id'] = $row['right_id'];
  830. $forum_data_sql['right_id'] = $row['right_id'] + 1;
  831. }
  832. else
  833. {
  834. $sql = 'SELECT MAX(right_id) AS right_id
  835. FROM ' . FORUMS_TABLE;
  836. $result = $db->sql_query($sql);
  837. $row = $db->sql_fetchrow($result);
  838. $db->sql_freeresult($result);
  839. $forum_data_sql['left_id'] = $row['right_id'] + 1;
  840. $forum_data_sql['right_id'] = $row['right_id'] + 2;
  841. }
  842. $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data_sql);
  843. $db->sql_query($sql);
  844. $forum_data['forum_id'] = $db->sql_nextid();
  845. add_log('admin', 'LOG_FORUM_ADD', $forum_data['forum_name']);
  846. }
  847. else
  848. {
  849. $row = $this->get_forum_info($forum_data_sql['forum_id']);
  850. if ($row['forum_type'] == FORUM_POST && $row['forum_type'] != $forum_data_sql['forum_type'])
  851. {
  852. // Has subforums and want to change into a link?
  853. if ($row['right_id'] - $row['left_id'] > 1 && $forum_data_sql['forum_type'] == FORUM_LINK)
  854. {
  855. $errors[] = $user->lang['FORUM_WITH_SUBFORUMS_NOT_TO_LINK'];
  856. return $errors;
  857. }
  858. // we're turning a postable forum into a non-postable forum
  859. if ($forum_data_sql['type_action'] == 'move')
  860. {
  861. $to_forum_id = request_var('to_forum_id', 0);
  862. if ($to_forum_id)
  863. {
  864. $errors = $this->move_forum_content($forum_data_sql['forum_id'], $to_forum_id);
  865. }
  866. else
  867. {
  868. return array($user->lang['NO_DESTINATION_FORUM']);
  869. }
  870. }
  871. else if ($forum_data_sql['type_action'] == 'delete')
  872. {
  873. $errors = $this->delete_forum_content($forum_data_sql['forum_id']);
  874. }
  875. else
  876. {
  877. return array($user->lang['NO_FORUM_ACTION']);
  878. }
  879. $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;
  880. $forum_data_sql['forum_last_poster_name'] = $forum_data_sql['forum_last_poster_colour'] = '';
  881. }
  882. else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_LINK)
  883. {
  884. // Has subforums?
  885. if ($row['right_id'] - $row['left_id'] > 1)
  886. {
  887. // We are turning a category into a link - but need to decide what to do with the subforums.
  888. $action_subforums = request_var('action_subforums', '');
  889. $subforums_to_id = request_var('subforums_to_id', 0);
  890. if ($action_subforums == 'delete')
  891. {
  892. $rows = get_forum_branch($row['forum_id'], 'children', 'descending', false);
  893. foreach ($rows as $_row)
  894. {
  895. // Do not remove the forum id we are about to change. ;)
  896. if ($_row['forum_id'] == $row['forum_id'])
  897. {
  898. continue;
  899. }
  900. $forum_ids[] = $_row['forum_id'];
  901. $errors = array_merge($errors, $this->delete_forum_content($_row['forum_id']));
  902. }
  903. if (sizeof($errors))
  904. {
  905. return $errors;
  906. }
  907. if (sizeof($forum_ids))
  908. {
  909. $sql = 'DELETE FROM ' . FORUMS_TABLE . '
  910. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  911. $db->sql_query($sql);
  912. $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
  913. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  914. $db->sql_query($sql);
  915. $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
  916. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  917. $db->sql_query($sql);
  918. // Delete forum ids from extension groups table
  919. $sql = 'SELECT group_id, allowed_forums
  920. FROM ' . EXTENSION_GROUPS_TABLE;
  921. $result = $db->sql_query($sql);
  922. while ($_row = $db->sql_fetchrow($result))
  923. {
  924. if (!$_row['allowed_forums'])
  925. {
  926. continue;
  927. }
  928. $allowed_forums = unserialize(trim($_row['allowed_forums']));
  929. $allowed_forums = array_diff($allowed_forums, $forum_ids);
  930. $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
  931. SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
  932. WHERE group_id = {$_row['group_id']}";
  933. $db->sql_query($sql);
  934. }
  935. $db->sql_freeresult($result);
  936. $cache->destroy('_extensions');
  937. }
  938. }
  939. else if ($action_subforums == 'move')
  940. {
  941. if (!$subforums_to_id)
  942. {
  943. return array($user->lang['NO_DESTINATION_FORUM']);
  944. }
  945. $sql = 'SELECT forum_name
  946. FROM ' . FORUMS_TABLE . '
  947. WHERE forum_id = ' . $subforums_to_id;
  948. $result = $db->sql_query($sql);
  949. $_row = $db->sql_fetchrow($result);
  950. $db->sql_freeresult($result);
  951. if (!$_row)
  952. {
  953. return array($user->lang['NO_FORUM']);
  954. }
  955. $subforums_to_name = $_row['forum_name'];
  956. $sql = 'SELECT forum_id
  957. FROM ' . FORUMS_TABLE . "
  958. WHERE parent_id = {$row['forum_id']}";
  959. $result = $db->sql_query($sql);
  960. while ($_row = $db->sql_fetchrow($result))
  961. {
  962. $this->move_forum($_row['forum_id'], $subforums_to_id);
  963. }
  964. $db->sql_freeresult($result);
  965. $sql = 'UPDATE ' . FORUMS_TABLE . "
  966. SET parent_id = $subforums_to_id
  967. WHERE parent_id = {$row['forum_id']}";
  968. $db->sql_query($sql);
  969. }
  970. // Adjust the left/right id
  971. $sql = 'UPDATE ' . FORUMS_TABLE . '
  972. SET right_id = left_id + 1
  973. WHERE forum_id = ' . $row['forum_id'];
  974. $db->sql_query($sql);
  975. }
  976. }
  977. else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_POST)
  978. {
  979. // Changing a category to a forum? Reset the data (you can't post directly in a cat, you must use a forum)
  980. $forum_data_sql['forum_posts'] = 0;
  981. $forum_data_sql['forum_topics'] = 0;
  982. $forum_data_sql['forum_topics_real'] = 0;
  983. $forum_data_sql['forum_last_post_id'] = 0;
  984. $forum_data_sql['forum_last_post_subject'] = '';
  985. $forum_data_sql['forum_last_post_time'] = 0;
  986. $forum_data_sql['forum_last_poster_id'] = 0;
  987. $forum_data_sql['forum_last_poster_name'] = '';
  988. $forum_data_sql['forum_last_poster_colour'] = '';
  989. }
  990. if (sizeof($errors))
  991. {
  992. return $errors;
  993. }
  994. if ($row['parent_id'] != $forum_data_sql['parent_id'])
  995. {
  996. if ($row['forum_id'] != $forum_data_sql['parent_id'])
  997. {
  998. $errors = $this->move_forum($forum_data_sql['forum_id'], $forum_data_sql['parent_id']);
  999. }
  1000. else
  1001. {
  1002. $forum_data_sql['parent_id'] = $row['parent_id'];
  1003. }
  1004. }
  1005. if (sizeof($errors))
  1006. {
  1007. return $errors;
  1008. }
  1009. unset($forum_data_sql['type_action']);
  1010. if ($row['forum_name'] != $forum_data_sql['forum_name'])
  1011. {
  1012. // the forum name has changed, clear the parents list of all forums (for safety)
  1013. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1014. SET forum_parents = ''";
  1015. $db->sql_query($sql);
  1016. }
  1017. // Setting the forum id to the forum id is not really received well by some dbs. ;)
  1018. $forum_id = $forum_data_sql['forum_id'];
  1019. unset($forum_data_sql['forum_id']);
  1020. $sql = 'UPDATE ' . FORUMS_TABLE . '
  1021. SET ' . $db->sql_build_array('UPDATE', $forum_data_sql) . '
  1022. WHERE forum_id = ' . $forum_id;
  1023. $db->sql_query($sql);
  1024. // Add it back
  1025. $forum_data['forum_id'] = $forum_id;
  1026. add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']);
  1027. }
  1028. return $errors;
  1029. }
  1030. /**
  1031. * Move forum
  1032. */
  1033. function move_forum($from_id, $to_id)
  1034. {
  1035. global $db, $user;
  1036. $to_data = $moved_ids = $errors = array();
  1037. // Check if we want to move to a parent with link type
  1038. if ($to_id > 0)
  1039. {
  1040. $to_data = $this->get_forum_info($to_id);
  1041. if ($to_data['forum_type'] == FORUM_LINK)
  1042. {
  1043. $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
  1044. return $errors;
  1045. }
  1046. }
  1047. $moved_forums = get_forum_branch($from_id, 'children', 'descending');
  1048. $from_data = $moved_forums[0];
  1049. $diff = sizeof($moved_forums) * 2;
  1050. $moved_ids = array();
  1051. for ($i = 0; $i < sizeof($moved_forums); ++$i)
  1052. {
  1053. $moved_ids[] = $moved_forums[$i]['forum_id'];
  1054. }
  1055. // Resync parents
  1056. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1057. SET right_id = right_id - $diff, forum_parents = ''
  1058. WHERE left_id < " . $from_data['right_id'] . "
  1059. AND right_id > " . $from_data['right_id'];
  1060. $db->sql_query($sql);
  1061. // Resync righthand side of tree
  1062. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1063. SET left_id = left_id - $diff, right_id = right_id - $diff, forum_parents = ''
  1064. WHERE left_id > " . $from_data['right_id'];
  1065. $db->sql_query($sql);
  1066. if ($to_id > 0)
  1067. {
  1068. // Retrieve $to_data again, it may have been changed...
  1069. $to_data = $this->get_forum_info($to_id);
  1070. // Resync new parents
  1071. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1072. SET right_id = right_id + $diff, forum_parents = ''
  1073. WHERE " . $to_data['right_id'] . ' BETWEEN left_id AND right_id
  1074. AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
  1075. $db->sql_query($sql);
  1076. // Resync the righthand side of the tree
  1077. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1078. SET left_id = left_id + $diff, right_id = right_id + $diff, forum_parents = ''
  1079. WHERE left_id > " . $to_data['right_id'] . '
  1080. AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
  1081. $db->sql_query($sql);
  1082. // Resync moved branch
  1083. $to_data['right_id'] += $diff;
  1084. if ($to_data['right_id'] > $from_data['right_id'])
  1085. {
  1086. $diff = '+ ' . ($to_data['right_id'] - $from_data['right_id'] - 1);
  1087. }
  1088. else
  1089. {
  1090. $diff = '- ' . abs($to_data['right_id'] - $from_data['right_id'] - 1);
  1091. }
  1092. }
  1093. else
  1094. {
  1095. $sql = 'SELECT MAX(right_id) AS right_id
  1096. FROM ' . FORUMS_TABLE . '
  1097. WHERE ' . $db->sql_in_set('forum_id', $moved_ids, true);
  1098. $result = $db->sql_query($sql);
  1099. $row = $db->sql_fetchrow($result);
  1100. $db->sql_freeresult($result);
  1101. $diff = '+ ' . ($row['right_id'] - $from_data['left_id'] + 1);
  1102. }
  1103. $sql = 'UPDATE ' . FORUMS_TABLE . "
  1104. SET left_id = left_id $diff, right_id = right_id $diff, forum_parents = ''
  1105. WHERE " . $db->sql_in_set('forum_id', $moved_ids);
  1106. $db->sql_query($sql);
  1107. return $errors;
  1108. }
  1109. /**
  1110. * Move forum content from one to another forum
  1111. */
  1112. function move_forum_content($from_id, $to_id, $sync = true)
  1113. {
  1114. global $db;
  1115. //-- mod: Prime Trash Bin ---------------------------------------------------//
  1116. global $phpbb_root_path, $phpEx;
  1117. include($phpbb_root_path . 'includes/prime_trash_bin_b.' . $phpEx);
  1118. update_stifled_from($from_id, $to_id);
  1119. //-- end: Prime Trash Bin ---------------------------------------------------//
  1120. $table_ary = array(LOG_TABLE, POSTS_TABLE, TOPICS_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE);
  1121. foreach ($table_ary as $table)
  1122. {
  1123. $sql = "UPDATE $table
  1124. SET forum_id = $to_id
  1125. WHERE forum_id = $from_id";
  1126. $db->sql_query($sql);
  1127. }
  1128. unset($table_ary);
  1129. $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, MODERATOR_CACHE_TABLE);
  1130. foreach ($table_ary as $table)
  1131. {
  1132. $sql = "DELETE FROM $table
  1133. WHERE forum_id = $from_id";
  1134. $db->sql_query($sql);
  1135. }
  1136. if ($sync)
  1137. {
  1138. // Delete ghost topics that link back to the same forum then resync counters
  1139. sync('topic_moved');
  1140. sync('forum', 'forum_id', $to_id, false, true);
  1141. }
  1142. return array();
  1143. }
  1144. /**
  1145. * Remove complete forum
  1146. */
  1147. function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = 'delete', $posts_to_id = 0, $subforums_to_id = 0)
  1148. {
  1149. global $db, $user, $cache;
  1150. $forum_data = $this->get_forum_info($forum_id);
  1151. $errors = array();
  1152. $log_action_posts = $log_action_forums = $posts_to_name = $subforums_to_name = '';
  1153. $forum_ids = array($forum_id);
  1154. if ($action_posts == 'delete')
  1155. {
  1156. $log_action_posts = 'POSTS';
  1157. $errors = array_merge($errors, $this->delete_forum_content($forum_id));
  1158. }
  1159. else if ($action_posts == 'move')
  1160. {
  1161. if (!$posts_to_id)
  1162. {
  1163. $errors[] = $user->lang['NO_DESTINATION_FORUM'];
  1164. }
  1165. else
  1166. {
  1167. $log_action_posts = 'MOVE_POSTS';
  1168. $sql = 'SELECT forum_name
  1169. FROM ' . FORUMS_TABLE . '
  1170. WHERE forum_id = ' . $posts_to_id;
  1171. $result = $db->sql_query($sql);
  1172. $row = $db->sql_fetchrow($result);
  1173. $db->sql_freeresult($result);
  1174. if (!$row)
  1175. {
  1176. $errors[] = $user->lang['NO_FORUM'];
  1177. }
  1178. else
  1179. {
  1180. $posts_to_name = $row['forum_name'];
  1181. $errors = array_merge($errors, $this->move_forum_content($forum_id, $posts_to_id));
  1182. }
  1183. }
  1184. }
  1185. if (sizeof($errors))
  1186. {
  1187. return $errors;
  1188. }
  1189. if ($action_subforums == 'delete')
  1190. {
  1191. $log_action_forums = 'FORUMS';
  1192. $rows = get_forum_branch($forum_id, 'children', 'descending', false);
  1193. foreach ($rows as $row)
  1194. {
  1195. $forum_ids[] = $row['forum_id'];
  1196. $errors = array_merge($errors, $this->delete_forum_content($row['forum_id']));
  1197. }
  1198. if (sizeof($errors))
  1199. {
  1200. return $errors;
  1201. }
  1202. $diff = sizeof($forum_ids) * 2;
  1203. $sql = 'DELETE FROM ' . FORUMS_TABLE . '
  1204. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  1205. $db->sql_query($sql);
  1206. $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
  1207. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  1208. $db->sql_query($sql);
  1209. $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
  1210. WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
  1211. $db->sql_query($sql);
  1212. }
  1213. else if ($action_subforums == 'move')
  1214. {
  1215. if (!$subforums_to_id)
  1216. {
  1217. $errors[] = $user->lang['NO_DESTINATION_FORUM'];
  1218. }
  1219. else
  1220. {
  1221. $log_action_forums = 'MOVE_FORUMS';
  1222. $sql = 'SELECT forum_name
  1223. FROM ' . FORUMS_TABLE . '
  1224. WHERE forum_id = ' . $subforums_to_id;
  1225. $result = $db->sql_query($sql);
  1226. $row = $db->sql_fetchrow($result);
  1227. $db->sql_freeresult($result);
  1228. if (!$row)
  1229. {
  1230. $errors[] = $user->lang['NO_FORUM'];
  1231. }
  1232. else
  1233. {
  1234. $subforums_to_name = $row['forum…

Large files files are truncated, but you can click here to view the full file