PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/sources/admin/ManageBoards.php

https://github.com/Arantor/Elkarte
PHP | 808 lines | 571 code | 107 blank | 130 comment | 110 complexity | 24e7b06dd84ed41da454a2fdaa7d20b0 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /**
  3. * @name ElkArte Forum
  4. * @copyright ElkArte Forum contributors
  5. * @license BSD http://opensource.org/licenses/BSD-3-Clause
  6. *
  7. * This software is a derived product, based on:
  8. *
  9. * Simple Machines Forum (SMF)
  10. * copyright: 2011 Simple Machines (http://www.simplemachines.org)
  11. * license: BSD, See included LICENSE.TXT for terms and conditions.
  12. *
  13. * @version 1.0 Alpha
  14. *
  15. * Manage and maintain the boards and categories of the forum.
  16. *
  17. */
  18. if (!defined('ELKARTE'))
  19. die('No access...');
  20. /**
  21. * The main dispatcher; doesn't do anything, just delegates.
  22. * This is the main entry point for all the manageboards admin screens.
  23. * Called by ?action=admin;area=manageboards.
  24. * It checks the permissions, based on the sub-action, and calls a function based on the sub-action.
  25. *
  26. * @uses ManageBoards language file.
  27. */
  28. function ManageBoards()
  29. {
  30. global $context, $txt, $scripturl;
  31. // Everything's gonna need this.
  32. loadLanguage('ManageBoards');
  33. // Format: 'sub-action' => array('function', 'permission')
  34. $subActions = array(
  35. 'board' => array('EditBoard', 'manage_boards'),
  36. 'board2' => array('EditBoard2', 'manage_boards'),
  37. 'cat' => array('EditCategory', 'manage_boards'),
  38. 'cat2' => array('EditCategory2', 'manage_boards'),
  39. 'main' => array('ManageBoardsMain', 'manage_boards'),
  40. 'move' => array('ManageBoardsMain', 'manage_boards'),
  41. 'newcat' => array('EditCategory', 'manage_boards'),
  42. 'newboard' => array('EditBoard', 'manage_boards'),
  43. 'settings' => array('EditBoardSettings', 'admin_forum'),
  44. );
  45. call_integration_hook('integrate_manage_boards', array($subActions));
  46. // Default to sub action 'main' or 'settings' depending on permissions.
  47. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_boards') ? 'main' : 'settings');
  48. // Have you got the proper permissions?
  49. isAllowedTo($subActions[$_REQUEST['sa']][1]);
  50. // Create the tabs for the template.
  51. $context[$context['admin_menu_name']]['tab_data'] = array(
  52. 'title' => $txt['boards_and_cats'],
  53. 'help' => 'manage_boards',
  54. 'description' => $txt['boards_and_cats_desc'],
  55. 'tabs' => array(
  56. 'main' => array(
  57. ),
  58. 'newcat' => array(
  59. ),
  60. 'settings' => array(
  61. 'description' => $txt['mboards_settings_desc'],
  62. ),
  63. ),
  64. );
  65. $subActions[$_REQUEST['sa']][0]();
  66. }
  67. /**
  68. * The main control panel thing, the screen showing all boards and categories.
  69. * Called by ?action=admin;area=manageboards or ?action=admin;area=manageboards;sa=move.
  70. * Requires manage_boards permission.
  71. * It also handles the interface for moving boards.
  72. *
  73. * @uses ManageBoards template, main sub-template.
  74. */
  75. function ManageBoardsMain()
  76. {
  77. global $txt, $context, $cat_tree, $boards, $boardList, $scripturl, $txt;
  78. loadTemplate('ManageBoards');
  79. require_once(SUBSDIR . '/Boards.subs.php');
  80. if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'move' && in_array($_REQUEST['move_to'], array('child', 'before', 'after', 'top')))
  81. {
  82. checkSession('get');
  83. validateToken('admin-bm-' . (int) $_REQUEST['src_board'], 'request');
  84. if ($_REQUEST['move_to'] === 'top')
  85. $boardOptions = array(
  86. 'move_to' => $_REQUEST['move_to'],
  87. 'target_category' => (int) $_REQUEST['target_cat'],
  88. 'move_first_child' => true,
  89. );
  90. else
  91. $boardOptions = array(
  92. 'move_to' => $_REQUEST['move_to'],
  93. 'target_board' => (int) $_REQUEST['target_board'],
  94. 'move_first_child' => true,
  95. );
  96. modifyBoard((int) $_REQUEST['src_board'], $boardOptions);
  97. }
  98. getBoardTree();
  99. $context['move_board'] = !empty($_REQUEST['move']) && isset($boards[(int) $_REQUEST['move']]) ? (int) $_REQUEST['move'] : 0;
  100. $context['categories'] = array();
  101. foreach ($cat_tree as $catid => $tree)
  102. {
  103. $context['categories'][$catid] = array(
  104. 'name' => &$tree['node']['name'],
  105. 'id' => &$tree['node']['id'],
  106. 'boards' => array()
  107. );
  108. $move_cat = !empty($context['move_board']) && $boards[$context['move_board']]['category'] == $catid;
  109. foreach ($boardList[$catid] as $boardid)
  110. {
  111. $context['categories'][$catid]['boards'][$boardid] = array(
  112. 'id' => &$boards[$boardid]['id'],
  113. 'name' => &$boards[$boardid]['name'],
  114. 'description' => &$boards[$boardid]['description'],
  115. 'child_level' => &$boards[$boardid]['level'],
  116. 'move' => $move_cat && ($boardid == $context['move_board'] || isChildOf($boardid, $context['move_board'])),
  117. 'permission_profile' => &$boards[$boardid]['profile'],
  118. );
  119. }
  120. }
  121. if (!empty($context['move_board']))
  122. {
  123. createToken('admin-bm-' . $context['move_board'], 'request');
  124. $context['move_title'] = sprintf($txt['mboards_select_destination'], htmlspecialchars($boards[$context['move_board']]['name']));
  125. foreach ($cat_tree as $catid => $tree)
  126. {
  127. $prev_child_level = 0;
  128. $prev_board = 0;
  129. $stack = array();
  130. // Just a shortcut, this is the same for all the urls
  131. $security = $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-bm-' . $context['move_board'] . '_token_var'] . '=' . $context['admin-bm-' . $context['move_board'] . '_token'];
  132. foreach ($boardList[$catid] as $boardid)
  133. {
  134. if (!isset($context['categories'][$catid]['move_link']))
  135. $context['categories'][$catid]['move_link'] = array(
  136. 'child_level' => 0,
  137. 'label' => $txt['mboards_order_before'] . ' \'' . htmlspecialchars($boards[$boardid]['name']) . '\'',
  138. 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=before;' . $security,
  139. );
  140. if (!$context['categories'][$catid]['boards'][$boardid]['move'])
  141. $context['categories'][$catid]['boards'][$boardid]['move_links'] = array(
  142. array(
  143. 'child_level' => $boards[$boardid]['level'],
  144. 'label' => $txt['mboards_order_after'] . '\'' . htmlspecialchars($boards[$boardid]['name']) . '\'',
  145. 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=after;' . $security,
  146. ),
  147. array(
  148. 'child_level' => $boards[$boardid]['level'] + 1,
  149. 'label' => $txt['mboards_order_child_of'] . ' \'' . htmlspecialchars($boards[$boardid]['name']) . '\'',
  150. 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=child;' . $security,
  151. ),
  152. );
  153. $difference = $boards[$boardid]['level'] - $prev_child_level;
  154. if ($difference == 1)
  155. array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null);
  156. elseif ($difference < 0)
  157. {
  158. if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links']))
  159. $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array();
  160. for ($i = 0; $i < -$difference; $i++)
  161. if (($temp = array_pop($stack)) != null)
  162. array_unshift($context['categories'][$catid]['boards'][$prev_board]['move_links'], $temp);
  163. }
  164. $prev_board = $boardid;
  165. $prev_child_level = $boards[$boardid]['level'];
  166. }
  167. if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']))
  168. $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']);
  169. elseif (!empty($stack))
  170. $context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack;
  171. if (empty($boardList[$catid]))
  172. $context['categories'][$catid]['move_link'] = array(
  173. 'child_level' => 0,
  174. 'label' => $txt['mboards_order_before'] . ' \'' . htmlspecialchars($tree['node']['name']) . '\'',
  175. 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_cat=' . $catid . ';move_to=top;' . $security,
  176. );
  177. }
  178. }
  179. call_integration_hook('integrate_boards_main');
  180. $context['page_title'] = $txt['boards_and_cats'];
  181. $context['can_manage_permissions'] = allowedTo('manage_permissions');
  182. }
  183. /**
  184. * Modify a specific category.
  185. * (screen for editing and repositioning a category.)
  186. * Also used to show the confirm deletion of category screen
  187. * (sub-template confirm_category_delete).
  188. * Called by ?action=admin;area=manageboards;sa=cat
  189. * Requires manage_boards permission.
  190. *
  191. * @uses ManageBoards template, modify_category sub-template.
  192. */
  193. function EditCategory()
  194. {
  195. global $txt, $context, $cat_tree, $boardList, $boards;
  196. loadTemplate('ManageBoards');
  197. require_once(SUBSDIR . '/Boards.subs.php');
  198. getBoardTree();
  199. // id_cat must be a number.... if it exists.
  200. $_REQUEST['cat'] = isset($_REQUEST['cat']) ? (int) $_REQUEST['cat'] : 0;
  201. // Start with one - "In first place".
  202. $context['category_order'] = array(
  203. array(
  204. 'id' => 0,
  205. 'name' => $txt['mboards_order_first'],
  206. 'selected' => !empty($_REQUEST['cat']) ? $cat_tree[$_REQUEST['cat']]['is_first'] : false,
  207. 'true_name' => ''
  208. )
  209. );
  210. // If this is a new category set up some defaults.
  211. if ($_REQUEST['sa'] == 'newcat')
  212. {
  213. $context['category'] = array(
  214. 'id' => 0,
  215. 'name' => $txt['mboards_new_cat_name'],
  216. 'editable_name' => htmlspecialchars($txt['mboards_new_cat_name']),
  217. 'can_collapse' => true,
  218. 'is_new' => true,
  219. 'is_empty' => true
  220. );
  221. }
  222. // Category doesn't exist, man... sorry.
  223. elseif (!isset($cat_tree[$_REQUEST['cat']]))
  224. redirectexit('action=admin;area=manageboards');
  225. else
  226. {
  227. $context['category'] = array(
  228. 'id' => $_REQUEST['cat'],
  229. 'name' => $cat_tree[$_REQUEST['cat']]['node']['name'],
  230. 'editable_name' => htmlspecialchars($cat_tree[$_REQUEST['cat']]['node']['name']),
  231. 'can_collapse' => !empty($cat_tree[$_REQUEST['cat']]['node']['can_collapse']),
  232. 'children' => array(),
  233. 'is_empty' => empty($cat_tree[$_REQUEST['cat']]['children'])
  234. );
  235. foreach ($boardList[$_REQUEST['cat']] as $child_board)
  236. $context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name'];
  237. }
  238. $prevCat = 0;
  239. foreach ($cat_tree as $catid => $tree)
  240. {
  241. if ($catid == $_REQUEST['cat'] && $prevCat > 0)
  242. $context['category_order'][$prevCat]['selected'] = true;
  243. elseif ($catid != $_REQUEST['cat'])
  244. $context['category_order'][$catid] = array(
  245. 'id' => $catid,
  246. 'name' => $txt['mboards_order_after'] . $tree['node']['name'],
  247. 'selected' => false,
  248. 'true_name' => $tree['node']['name']
  249. );
  250. $prevCat = $catid;
  251. }
  252. if (!isset($_REQUEST['delete']))
  253. {
  254. $context['sub_template'] = 'modify_category';
  255. $context['page_title'] = $_REQUEST['sa'] == 'newcat' ? $txt['mboards_new_cat_name'] : $txt['catEdit'];
  256. }
  257. else
  258. {
  259. $context['sub_template'] = 'confirm_category_delete';
  260. $context['page_title'] = $txt['mboards_delete_cat'];
  261. }
  262. // Create a special token.
  263. createToken('admin-bc-' . $_REQUEST['cat']);
  264. $context['token_check'] = 'admin-bc-' . $_REQUEST['cat'];
  265. call_integration_hook('integrate_edit_category');
  266. }
  267. /**
  268. * Function for handling a submitted form saving the category.
  269. * (complete the modifications to a specific category.)
  270. * It also handles deletion of a category.
  271. * It requires manage_boards permission.
  272. * Called by ?action=admin;area=manageboards;sa=cat2
  273. * Redirects to ?action=admin;area=manageboards.
  274. */
  275. function EditCategory2()
  276. {
  277. checkSession();
  278. validateToken('admin-bc-' . $_REQUEST['cat']);
  279. require_once(SUBSDIR . '/Categories.subs.php');
  280. $_POST['cat'] = (int) $_POST['cat'];
  281. // Add a new category or modify an existing one..
  282. if (isset($_POST['edit']) || isset($_POST['add']))
  283. {
  284. $catOptions = array();
  285. if (isset($_POST['cat_order']))
  286. $catOptions['move_after'] = (int) $_POST['cat_order'];
  287. // Change "This & That" to "This &amp; That" but don't change "&cent" to "&amp;cent;"...
  288. $catOptions['cat_name'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&amp;$1', $_POST['cat_name']);
  289. $catOptions['is_collapsible'] = isset($_POST['collapse']);
  290. if (isset($_POST['add']))
  291. createCategory($catOptions);
  292. else
  293. modifyCategory($_POST['cat'], $catOptions);
  294. }
  295. // If they want to delete - first give them confirmation.
  296. elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['empty']))
  297. {
  298. // We need a new token.
  299. validateToken('admin-bc-' . $_REQUEST['cat']);
  300. EditCategory();
  301. return;
  302. }
  303. // Delete the category!
  304. elseif (isset($_POST['delete']))
  305. {
  306. // First off - check if we are moving all the current boards first - before we start deleting!
  307. if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1)
  308. {
  309. if (empty($_POST['cat_to']))
  310. fatal_lang_error('mboards_delete_error');
  311. deleteCategories(array($_POST['cat']), (int) $_POST['cat_to']);
  312. }
  313. else
  314. deleteCategories(array($_POST['cat']));
  315. }
  316. redirectexit('action=admin;area=manageboards');
  317. }
  318. /**
  319. * Modify a specific board...
  320. * screen for editing and repositioning a board.
  321. * called by ?action=admin;area=manageboards;sa=board
  322. * uses the modify_board sub-template of the ManageBoards template.
  323. * requires manage_boards permission.
  324. * also used to show the confirm deletion of category screen (sub-template confirm_board_delete).
  325. */
  326. function EditBoard()
  327. {
  328. global $txt, $context, $cat_tree, $boards, $boardList, $smcFunc, $modSettings;
  329. loadTemplate('ManageBoards');
  330. require_once(SUBSDIR . '/Boards.subs.php');
  331. getBoardTree();
  332. // For editing the profile we'll need this.
  333. loadLanguage('ManagePermissions');
  334. require_once(ADMINDIR . '/ManagePermissions.php');
  335. loadPermissionProfiles();
  336. // id_board must be a number....
  337. $_REQUEST['boardid'] = isset($_REQUEST['boardid']) ? (int) $_REQUEST['boardid'] : 0;
  338. if (!isset($boards[$_REQUEST['boardid']]))
  339. {
  340. $_REQUEST['boardid'] = 0;
  341. $_REQUEST['sa'] = 'newboard';
  342. }
  343. if ($_REQUEST['sa'] == 'newboard')
  344. {
  345. // Category doesn't exist, man... sorry.
  346. if (empty($_REQUEST['cat']))
  347. redirectexit('action=admin;area=manageboards');
  348. // Some things that need to be setup for a new board.
  349. $curBoard = array(
  350. 'member_groups' => array(0, -1),
  351. 'deny_groups' => array(),
  352. 'category' => (int) $_REQUEST['cat']
  353. );
  354. $context['board_order'] = array();
  355. $context['board'] = array(
  356. 'is_new' => true,
  357. 'id' => 0,
  358. 'name' => $txt['mboards_new_board_name'],
  359. 'description' => '',
  360. 'count_posts' => 1,
  361. 'posts' => 0,
  362. 'topics' => 0,
  363. 'theme' => 0,
  364. 'profile' => 1,
  365. 'override_theme' => 0,
  366. 'redirect' => '',
  367. 'category' => (int) $_REQUEST['cat'],
  368. 'no_children' => true,
  369. );
  370. }
  371. else
  372. {
  373. // Just some easy shortcuts.
  374. $curBoard = &$boards[$_REQUEST['boardid']];
  375. $context['board'] = $boards[$_REQUEST['boardid']];
  376. $context['board']['name'] = htmlspecialchars(strtr($context['board']['name'], array('&amp;' => '&')));
  377. $context['board']['description'] = htmlspecialchars($context['board']['description']);
  378. $context['board']['no_children'] = empty($boards[$_REQUEST['boardid']]['tree']['children']);
  379. $context['board']['is_recycle'] = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) && $modSettings['recycle_board'] == $context['board']['id'];
  380. }
  381. // As we may have come from the permissions screen keep track of where we should go on save.
  382. $context['redirect_location'] = isset($_GET['rid']) && $_GET['rid'] == 'permissions' ? 'permissions' : 'boards';
  383. // We might need this to hide links to certain areas.
  384. $context['can_manage_permissions'] = allowedTo('manage_permissions');
  385. // Default membergroups.
  386. $context['groups'] = array(
  387. -1 => array(
  388. 'id' => '-1',
  389. 'name' => $txt['parent_guests_only'],
  390. 'allow' => in_array('-1', $curBoard['member_groups']),
  391. 'deny' => in_array('-1', $curBoard['deny_groups']),
  392. 'is_post_group' => false,
  393. ),
  394. 0 => array(
  395. 'id' => '0',
  396. 'name' => $txt['parent_members_only'],
  397. 'allow' => in_array('0', $curBoard['member_groups']),
  398. 'deny' => in_array('0', $curBoard['deny_groups']),
  399. 'is_post_group' => false,
  400. )
  401. );
  402. // Load membergroups.
  403. $request = $smcFunc['db_query']('', '
  404. SELECT group_name, id_group, min_posts
  405. FROM {db_prefix}membergroups
  406. WHERE id_group > {int:moderator_group} OR id_group = {int:global_moderator}
  407. ORDER BY min_posts, id_group != {int:global_moderator}, group_name',
  408. array(
  409. 'moderator_group' => 3,
  410. 'global_moderator' => 2,
  411. )
  412. );
  413. while ($row = $smcFunc['db_fetch_assoc']($request))
  414. {
  415. if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1)
  416. $curBoard['member_groups'][] = $row['id_group'];
  417. $context['groups'][(int) $row['id_group']] = array(
  418. 'id' => $row['id_group'],
  419. 'name' => trim($row['group_name']),
  420. 'allow' => in_array($row['id_group'], $curBoard['member_groups']),
  421. 'deny' => in_array($row['id_group'], $curBoard['deny_groups']),
  422. 'is_post_group' => $row['min_posts'] != -1,
  423. );
  424. }
  425. $smcFunc['db_free_result']($request);
  426. // Category doesn't exist, man... sorry.
  427. if (!isset($boardList[$curBoard['category']]))
  428. redirectexit('action=admin;area=manageboards');
  429. foreach ($boardList[$curBoard['category']] as $boardid)
  430. {
  431. if ($boardid == $_REQUEST['boardid'])
  432. {
  433. $context['board_order'][] = array(
  434. 'id' => $boardid,
  435. 'name' => str_repeat('-', $boards[$boardid]['level']) . ' (' . $txt['mboards_current_position'] . ')',
  436. 'children' => $boards[$boardid]['tree']['children'],
  437. 'no_children' => empty($boards[$boardid]['tree']['children']),
  438. 'is_child' => false,
  439. 'selected' => true
  440. );
  441. }
  442. else
  443. {
  444. $context['board_order'][] = array(
  445. 'id' => $boardid,
  446. 'name' => str_repeat('-', $boards[$boardid]['level']) . ' ' . $boards[$boardid]['name'],
  447. 'is_child' => empty($_REQUEST['boardid']) ? false : isChildOf($boardid, $_REQUEST['boardid']),
  448. 'selected' => false
  449. );
  450. }
  451. }
  452. // Are there any places to move child boards to in the case where we are confirming a delete?
  453. if (!empty($_REQUEST['boardid']))
  454. {
  455. $context['can_move_children'] = false;
  456. $context['children'] = $boards[$_REQUEST['boardid']]['tree']['children'];
  457. foreach ($context['board_order'] as $board)
  458. if ($board['is_child'] == false && $board['selected'] == false)
  459. $context['can_move_children'] = true;
  460. }
  461. // Get other available categories.
  462. $context['categories'] = array();
  463. foreach ($cat_tree as $catID => $tree)
  464. $context['categories'][] = array(
  465. 'id' => $catID == $curBoard['category'] ? 0 : $catID,
  466. 'name' => $tree['node']['name'],
  467. 'selected' => $catID == $curBoard['category']
  468. );
  469. $request = $smcFunc['db_query']('', '
  470. SELECT mem.id_member, mem.real_name
  471. FROM {db_prefix}moderators AS mods
  472. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member)
  473. WHERE mods.id_board = {int:current_board}',
  474. array(
  475. 'current_board' => $_REQUEST['boardid'],
  476. )
  477. );
  478. $context['board']['moderators'] = array();
  479. while ($row = $smcFunc['db_fetch_assoc']($request))
  480. $context['board']['moderators'][$row['id_member']] = $row['real_name'];
  481. $smcFunc['db_free_result']($request);
  482. $context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['board']['moderators']) . '&quot;';
  483. if (!empty($context['board']['moderators']))
  484. list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1);
  485. // Get all the themes...
  486. $request = $smcFunc['db_query']('', '
  487. SELECT id_theme AS id, value AS name
  488. FROM {db_prefix}themes
  489. WHERE variable = {string:name}',
  490. array(
  491. 'name' => 'name',
  492. )
  493. );
  494. $context['themes'] = array();
  495. while ($row = $smcFunc['db_fetch_assoc']($request))
  496. $context['themes'][] = $row;
  497. $smcFunc['db_free_result']($request);
  498. if (!isset($_REQUEST['delete']))
  499. {
  500. $context['sub_template'] = 'modify_board';
  501. $context['page_title'] = $txt['boardsEdit'];
  502. }
  503. else
  504. {
  505. $context['sub_template'] = 'confirm_board_delete';
  506. $context['page_title'] = $txt['mboards_delete_board'];
  507. }
  508. // Create a special token.
  509. createToken('admin-be-' . $_REQUEST['boardid']);
  510. call_integration_hook('integrate_edit_board');
  511. }
  512. /**
  513. * Make changes to/delete a board.
  514. * (function for handling a submitted form saving the board.)
  515. * It also handles deletion of a board.
  516. * Called by ?action=admin;area=manageboards;sa=board2
  517. * Redirects to ?action=admin;area=manageboards.
  518. * It requires manage_boards permission.
  519. */
  520. function EditBoard2()
  521. {
  522. global $txt, $modSettings, $smcFunc, $context;
  523. $_POST['boardid'] = (int) $_POST['boardid'];
  524. checkSession();
  525. validateToken('admin-be-' . $_REQUEST['boardid']);
  526. require_once(SUBSDIR . '/Boards.subs.php');
  527. // Mode: modify aka. don't delete.
  528. if (isset($_POST['edit']) || isset($_POST['add']))
  529. {
  530. $boardOptions = array();
  531. // Move this board to a new category?
  532. if (!empty($_POST['new_cat']))
  533. {
  534. $boardOptions['move_to'] = 'bottom';
  535. $boardOptions['target_category'] = (int) $_POST['new_cat'];
  536. }
  537. // Change the boardorder of this board?
  538. elseif (!empty($_POST['placement']) && !empty($_POST['board_order']))
  539. {
  540. if (!in_array($_POST['placement'], array('before', 'after', 'child')))
  541. fatal_lang_error('mangled_post', false);
  542. $boardOptions['move_to'] = $_POST['placement'];
  543. $boardOptions['target_board'] = (int) $_POST['board_order'];
  544. }
  545. // Checkboxes....
  546. $boardOptions['posts_count'] = isset($_POST['count']);
  547. $boardOptions['override_theme'] = isset($_POST['override_theme']);
  548. $boardOptions['board_theme'] = (int) $_POST['boardtheme'];
  549. $boardOptions['access_groups'] = array();
  550. $boardOptions['deny_groups'] = array();
  551. if (!empty($_POST['groups']))
  552. foreach ($_POST['groups'] as $group => $action)
  553. {
  554. if ($action == 'allow')
  555. $boardOptions['access_groups'][] = (int) $group;
  556. elseif ($action == 'deny')
  557. $boardOptions['deny_groups'][] = (int) $group;
  558. }
  559. if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255)
  560. fatal_lang_error('too_many_groups', false);
  561. // Change '1 & 2' to '1 &amp; 2', but not '&amp;' to '&amp;amp;'...
  562. $boardOptions['board_name'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&amp;$1', $_POST['board_name']);
  563. $boardOptions['board_description'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&amp;$1', $_POST['desc']);
  564. $boardOptions['moderator_string'] = $_POST['moderators'];
  565. if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list']))
  566. {
  567. $moderators = array();
  568. foreach ($_POST['moderator_list'] as $moderator)
  569. $moderators[(int) $moderator] = (int) $moderator;
  570. $boardOptions['moderators'] = $moderators;
  571. }
  572. // Are they doing redirection?
  573. $boardOptions['redirect'] = !empty($_POST['redirect_enable']) && isset($_POST['redirect_address']) && trim($_POST['redirect_address']) != '' ? trim($_POST['redirect_address']) : '';
  574. // Profiles...
  575. $boardOptions['profile'] = $_POST['profile'];
  576. $boardOptions['inherit_permissions'] = $_POST['profile'] == -1;
  577. // We need to know what used to be case in terms of redirection.
  578. if (!empty($_POST['boardid']))
  579. {
  580. $request = $smcFunc['db_query']('', '
  581. SELECT redirect, num_posts
  582. FROM {db_prefix}boards
  583. WHERE id_board = {int:current_board}',
  584. array(
  585. 'current_board' => $_POST['boardid'],
  586. )
  587. );
  588. list ($oldRedirect, $numPosts) = $smcFunc['db_fetch_row']($request);
  589. $smcFunc['db_free_result']($request);
  590. // If we're turning redirection on check the board doesn't have posts in it - if it does don't make it a redirection board.
  591. if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts)
  592. unset($boardOptions['redirect']);
  593. // Reset the redirection count when switching on/off.
  594. elseif (empty($boardOptions['redirect']) != empty($oldRedirect))
  595. $boardOptions['num_posts'] = 0;
  596. // Resetting the count?
  597. elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect']))
  598. $boardOptions['num_posts'] = 0;
  599. }
  600. // Create a new board...
  601. if (isset($_POST['add']))
  602. {
  603. // New boards by default go to the bottom of the category.
  604. if (empty($_POST['new_cat']))
  605. $boardOptions['target_category'] = (int) $_POST['cur_cat'];
  606. if (!isset($boardOptions['move_to']))
  607. $boardOptions['move_to'] = 'bottom';
  608. createBoard($boardOptions);
  609. }
  610. // ...or update an existing board.
  611. else
  612. modifyBoard($_POST['boardid'], $boardOptions);
  613. }
  614. elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children']))
  615. {
  616. EditBoard();
  617. return;
  618. }
  619. elseif (isset($_POST['delete']))
  620. {
  621. // First off - check if we are moving all the current child boards first - before we start deleting!
  622. if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1)
  623. {
  624. if (empty($_POST['board_to']))
  625. fatal_lang_error('mboards_delete_board_error');
  626. deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']);
  627. }
  628. else
  629. deleteBoards(array($_POST['boardid']), 0);
  630. }
  631. if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions')
  632. redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']);
  633. else
  634. redirectexit('action=admin;area=manageboards');
  635. }
  636. /**
  637. * A screen to set a few general board and category settings.
  638. *
  639. * @uses modify_general_settings sub-template.
  640. * @param $return_config
  641. */
  642. function EditBoardSettings($return_config = false)
  643. {
  644. global $context, $txt, $modSettings, $scripturl, $smcFunc;
  645. // Load the boards list - for the recycle bin!
  646. $recycle_boards = array('');
  647. $request = $smcFunc['db_query']('order_by_board_order', '
  648. SELECT b.id_board, b.name AS board_name, c.name AS cat_name
  649. FROM {db_prefix}boards AS b
  650. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  651. WHERE redirect = {string:empty_string}',
  652. array(
  653. 'empty_string' => '',
  654. )
  655. );
  656. while ($row = $smcFunc['db_fetch_assoc']($request))
  657. $recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
  658. $smcFunc['db_free_result']($request);
  659. // Here and the board settings...
  660. $config_vars = array(
  661. array('title', 'settings'),
  662. // Inline permissions.
  663. array('permissions', 'manage_boards'),
  664. '',
  665. // Other board settings.
  666. array('check', 'countChildPosts'),
  667. array('check', 'recycle_enable', 'onclick' => 'document.getElementById(\'recycle_board\').disabled = !this.checked;'),
  668. array('select', 'recycle_board', $recycle_boards),
  669. array('check', 'allow_ignore_boards'),
  670. array('check', 'deny_boards_access'),
  671. );
  672. call_integration_hook('integrate_modify_board_settings', array($config_vars));
  673. if ($return_config)
  674. return $config_vars;
  675. // Needed for the settings template.
  676. require_once(ADMINDIR . '/ManageServer.php');
  677. // Don't let guests have these permissions.
  678. $context['post_url'] = $scripturl . '?action=admin;area=manageboards;save;sa=settings';
  679. $context['permissions_excluded'] = array(-1);
  680. $context['page_title'] = $txt['boards_and_cats'] . ' - ' . $txt['settings'];
  681. loadTemplate('ManageBoards');
  682. $context['sub_template'] = 'show_settings';
  683. // Add some javascript stuff for the recycle box.
  684. addInlineJavascript('
  685. document.getElementById("recycle_board").disabled = !document.getElementById("recycle_enable").checked;', true);
  686. // Warn the admin against selecting the recycle topic without selecting a board.
  687. $context['force_form_onsubmit'] = 'if(document.getElementById(\'recycle_enable\').checked && document.getElementById(\'recycle_board\').value == 0) { return confirm(\'' . $txt['recycle_board_unselected_notice'] . '\');} return true;';
  688. // Doing a save?
  689. if (isset($_GET['save']))
  690. {
  691. checkSession();
  692. call_integration_hook('integrate_save_board_settings');
  693. saveDBSettings($config_vars);
  694. redirectexit('action=admin;area=manageboards;sa=settings');
  695. }
  696. // We need this for the in-line permissions
  697. createToken('admin-mp');
  698. // Prepare the settings...
  699. prepareDBSettingContext($config_vars);
  700. }