ManageBoards.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. <?php
  2. /**
  3. * Manage and maintain the boards and categories of the forum.
  4. *
  5. * Simple Machines Forum (SMF)
  6. *
  7. * @package SMF
  8. * @author Simple Machines http://www.simplemachines.org
  9. * @copyright 2013 Simple Machines and individual contributors
  10. * @license http://www.simplemachines.org/about/smf/license.php BSD
  11. *
  12. * @version 2.1 Alpha 1
  13. */
  14. if (!defined('SMF'))
  15. die('No direct access...');
  16. /**
  17. * The main dispatcher; doesn't do anything, just delegates.
  18. * This is the main entry point for all the manageboards admin screens.
  19. * Called by ?action=admin;area=manageboards.
  20. * It checks the permissions, based on the sub-action, and calls a function based on the sub-action.
  21. *
  22. * @uses ManageBoards language file.
  23. */
  24. function ManageBoards()
  25. {
  26. global $context, $txt, $scripturl;
  27. // Everything's gonna need this.
  28. loadLanguage('ManageBoards');
  29. // Format: 'sub-action' => array('function', 'permission')
  30. $subActions = array(
  31. 'board' => array('EditBoard', 'manage_boards'),
  32. 'board2' => array('EditBoard2', 'manage_boards'),
  33. 'cat' => array('EditCategory', 'manage_boards'),
  34. 'cat2' => array('EditCategory2', 'manage_boards'),
  35. 'main' => array('ManageBoardsMain', 'manage_boards'),
  36. 'move' => array('ManageBoardsMain', 'manage_boards'),
  37. 'newcat' => array('EditCategory', 'manage_boards'),
  38. 'newboard' => array('EditBoard', 'manage_boards'),
  39. 'settings' => array('EditBoardSettings', 'admin_forum'),
  40. );
  41. call_integration_hook('integrate_manage_boards', array(&$subActions));
  42. // Default to sub action 'main' or 'settings' depending on permissions.
  43. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_boards') ? 'main' : 'settings');
  44. // Have you got the proper permissions?
  45. isAllowedTo($subActions[$_REQUEST['sa']][1]);
  46. // Create the tabs for the template.
  47. $context[$context['admin_menu_name']]['tab_data'] = array(
  48. 'title' => $txt['boards_and_cats'],
  49. 'help' => 'manage_boards',
  50. 'description' => $txt['boards_and_cats_desc'],
  51. 'tabs' => array(
  52. 'main' => array(
  53. ),
  54. 'newcat' => array(
  55. ),
  56. 'settings' => array(
  57. 'description' => $txt['mboards_settings_desc'],
  58. ),
  59. ),
  60. );
  61. $subActions[$_REQUEST['sa']][0]();
  62. }
  63. /**
  64. * The main control panel thing, the screen showing all boards and categories.
  65. * Called by ?action=admin;area=manageboards or ?action=admin;area=manageboards;sa=move.
  66. * Requires manage_boards permission.
  67. * It also handles the interface for moving boards.
  68. *
  69. * @uses ManageBoards template, main sub-template.
  70. */
  71. function ManageBoardsMain()
  72. {
  73. global $txt, $context, $cat_tree, $boards, $boardList,
  74. global $scripturl, $sourcedir, $txt, $smcFunc;
  75. loadTemplate('ManageBoards');
  76. require_once($sourcedir . '/Subs-Boards.php');
  77. if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'move' && in_array($_REQUEST['move_to'], array('child', 'before', 'after', 'top')))
  78. {
  79. checkSession('get');
  80. validateToken('admin-bm-' . (int) $_REQUEST['src_board'], 'request');
  81. if ($_REQUEST['move_to'] === 'top')
  82. $boardOptions = array(
  83. 'move_to' => $_REQUEST['move_to'],
  84. 'target_category' => (int) $_REQUEST['target_cat'],
  85. 'move_first_child' => true,
  86. );
  87. else
  88. $boardOptions = array(
  89. 'move_to' => $_REQUEST['move_to'],
  90. 'target_board' => (int) $_REQUEST['target_board'],
  91. 'move_first_child' => true,
  92. );
  93. modifyBoard((int) $_REQUEST['src_board'], $boardOptions);
  94. }
  95. getBoardTree();
  96. $context['move_board'] = !empty($_REQUEST['move']) && isset($boards[(int) $_REQUEST['move']]) ? (int) $_REQUEST['move'] : 0;
  97. $context['categories'] = array();
  98. foreach ($cat_tree as $catid => $tree)
  99. {
  100. $context['categories'][$catid] = array(
  101. 'name' => &$tree['node']['name'],
  102. 'id' => &$tree['node']['id'],
  103. 'boards' => array()
  104. );
  105. $move_cat = !empty($context['move_board']) && $boards[$context['move_board']]['category'] == $catid;
  106. foreach ($boardList[$catid] as $boardid)
  107. {
  108. $context['categories'][$catid]['boards'][$boardid] = array(
  109. 'id' => &$boards[$boardid]['id'],
  110. 'name' => &$boards[$boardid]['name'],
  111. 'description' => &$boards[$boardid]['description'],
  112. 'child_level' => &$boards[$boardid]['level'],
  113. 'move' => $move_cat && ($boardid == $context['move_board'] || isChildOf($boardid, $context['move_board'])),
  114. 'permission_profile' => &$boards[$boardid]['profile'],
  115. );
  116. }
  117. }
  118. if (!empty($context['move_board']))
  119. {
  120. createToken('admin-bm-' . $context['move_board'], 'request');
  121. $context['move_title'] = sprintf($txt['mboards_select_destination'], $smcFunc['htmlspecialchars']($boards[$context['move_board']]['name']));
  122. foreach ($cat_tree as $catid => $tree)
  123. {
  124. $prev_child_level = 0;
  125. $prev_board = 0;
  126. $stack = array();
  127. // Just a shortcut, this is the same for all the urls
  128. $security = $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-bm-' . $context['move_board'] . '_token_var'] . '=' . $context['admin-bm-' . $context['move_board'] . '_token'];
  129. foreach ($boardList[$catid] as $boardid)
  130. {
  131. if (!isset($context['categories'][$catid]['move_link']))
  132. $context['categories'][$catid]['move_link'] = array(
  133. 'child_level' => 0,
  134. 'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'',
  135. 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=before;' . $security,
  136. );
  137. if (!$context['categories'][$catid]['boards'][$boardid]['move'])
  138. $context['categories'][$catid]['boards'][$boardid]['move_links'] = array(
  139. array(
  140. 'child_level' => $boards[$boardid]['level'],
  141. 'label' => $txt['mboards_order_after'] . '\'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'',
  142. 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=after;' . $security,
  143. ),
  144. array(
  145. 'child_level' => $boards[$boardid]['level'] + 1,
  146. 'label' => $txt['mboards_order_child_of'] . ' \'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'',
  147. 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=child;' . $security,
  148. ),
  149. );
  150. $difference = $boards[$boardid]['level'] - $prev_child_level;
  151. if ($difference == 1)
  152. array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null);
  153. elseif ($difference < 0)
  154. {
  155. if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links']))
  156. $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array();
  157. for ($i = 0; $i < -$difference; $i++)
  158. if (($temp = array_pop($stack)) != null)
  159. array_unshift($context['categories'][$catid]['boards'][$prev_board]['move_links'], $temp);
  160. }
  161. $prev_board = $boardid;
  162. $prev_child_level = $boards[$boardid]['level'];
  163. }
  164. if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']))
  165. $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']);
  166. elseif (!empty($stack))
  167. $context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack;
  168. if (empty($boardList[$catid]))
  169. $context['categories'][$catid]['move_link'] = array(
  170. 'child_level' => 0,
  171. 'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($tree['node']['name']) . '\'',
  172. 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_cat=' . $catid . ';move_to=top;' . $security,
  173. );
  174. }
  175. }
  176. call_integration_hook('integrate_boards_main');
  177. $context['page_title'] = $txt['boards_and_cats'];
  178. $context['can_manage_permissions'] = allowedTo('manage_permissions');
  179. }
  180. /**
  181. * Modify a specific category.
  182. * (screen for editing and repositioning a category.)
  183. * Also used to show the confirm deletion of category screen
  184. * (sub-template confirm_category_delete).
  185. * Called by ?action=admin;area=manageboards;sa=cat
  186. * Requires manage_boards permission.
  187. *
  188. * @uses ManageBoards template, modify_category sub-template.
  189. */
  190. function EditCategory()
  191. {
  192. global $txt, $context, $cat_tree, $boardList, $boards,
  193. global $smcFunc, $sourcedir;
  194. loadTemplate('ManageBoards');
  195. require_once($sourcedir . '/Subs-Boards.php');
  196. getBoardTree();
  197. // id_cat must be a number.... if it exists.
  198. $_REQUEST['cat'] = isset($_REQUEST['cat']) ? (int) $_REQUEST['cat'] : 0;
  199. // Start with one - "In first place".
  200. $context['category_order'] = array(
  201. array(
  202. 'id' => 0,
  203. 'name' => $txt['mboards_order_first'],
  204. 'selected' => !empty($_REQUEST['cat']) ? $cat_tree[$_REQUEST['cat']]['is_first'] : false,
  205. 'true_name' => ''
  206. )
  207. );
  208. // If this is a new category set up some defaults.
  209. if ($_REQUEST['sa'] == 'newcat')
  210. {
  211. $context['category'] = array(
  212. 'id' => 0,
  213. 'name' => $txt['mboards_new_cat_name'],
  214. 'editable_name' => $smcFunc['htmlspecialchars']($txt['mboards_new_cat_name']),
  215. 'can_collapse' => true,
  216. 'is_new' => true,
  217. 'is_empty' => true
  218. );
  219. }
  220. // Category doesn't exist, man... sorry.
  221. elseif (!isset($cat_tree[$_REQUEST['cat']]))
  222. redirectexit('action=admin;area=manageboards');
  223. else
  224. {
  225. $context['category'] = array(
  226. 'id' => $_REQUEST['cat'],
  227. 'name' => $cat_tree[$_REQUEST['cat']]['node']['name'],
  228. 'editable_name' => $smcFunc['htmlspecialchars']($cat_tree[$_REQUEST['cat']]['node']['name']),
  229. 'can_collapse' => !empty($cat_tree[$_REQUEST['cat']]['node']['can_collapse']),
  230. 'children' => array(),
  231. 'is_empty' => empty($cat_tree[$_REQUEST['cat']]['children'])
  232. );
  233. foreach ($boardList[$_REQUEST['cat']] as $child_board)
  234. $context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name'];
  235. }
  236. $prevCat = 0;
  237. foreach ($cat_tree as $catid => $tree)
  238. {
  239. if ($catid == $_REQUEST['cat'] && $prevCat > 0)
  240. $context['category_order'][$prevCat]['selected'] = true;
  241. elseif ($catid != $_REQUEST['cat'])
  242. $context['category_order'][$catid] = array(
  243. 'id' => $catid,
  244. 'name' => $txt['mboards_order_after'] . $tree['node']['name'],
  245. 'selected' => false,
  246. 'true_name' => $tree['node']['name']
  247. );
  248. $prevCat = $catid;
  249. }
  250. if (!isset($_REQUEST['delete']))
  251. {
  252. $context['sub_template'] = 'modify_category';
  253. $context['page_title'] = $_REQUEST['sa'] == 'newcat' ? $txt['mboards_new_cat_name'] : $txt['catEdit'];
  254. }
  255. else
  256. {
  257. $context['sub_template'] = 'confirm_category_delete';
  258. $context['page_title'] = $txt['mboards_delete_cat'];
  259. }
  260. // Create a special token.
  261. createToken('admin-bc-' . $_REQUEST['cat']);
  262. $context['token_check'] = 'admin-bc-' . $_REQUEST['cat'];
  263. call_integration_hook('integrate_edit_category');
  264. }
  265. /**
  266. * Function for handling a submitted form saving the category.
  267. * (complete the modifications to a specific category.)
  268. * It also handles deletion of a category.
  269. * It requires manage_boards permission.
  270. * Called by ?action=admin;area=manageboards;sa=cat2
  271. * Redirects to ?action=admin;area=manageboards.
  272. */
  273. function EditCategory2()
  274. {
  275. global $sourcedir;
  276. checkSession();
  277. validateToken('admin-bc-' . $_REQUEST['cat']);
  278. require_once($sourcedir . '/Subs-Categories.php');
  279. $_POST['cat'] = (int) $_POST['cat'];
  280. // Add a new category or modify an existing one..
  281. if (isset($_POST['edit']) || isset($_POST['add']))
  282. {
  283. $catOptions = array();
  284. if (isset($_POST['cat_order']))
  285. $catOptions['move_after'] = (int) $_POST['cat_order'];
  286. // Change "This & That" to "This &amp; That" but don't change "&cent" to "&amp;cent;"...
  287. $catOptions['cat_name'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&amp;$1', $_POST['cat_name']);
  288. $catOptions['is_collapsible'] = isset($_POST['collapse']);
  289. if (isset($_POST['add']))
  290. createCategory($catOptions);
  291. else
  292. modifyCategory($_POST['cat'], $catOptions);
  293. }
  294. // If they want to delete - first give them confirmation.
  295. elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['empty']))
  296. {
  297. // We need a new token.
  298. validateToken('admin-bc-' . $_REQUEST['cat']);
  299. EditCategory();
  300. return;
  301. }
  302. // Delete the category!
  303. elseif (isset($_POST['delete']))
  304. {
  305. // First off - check if we are moving all the current boards first - before we start deleting!
  306. if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1)
  307. {
  308. if (empty($_POST['cat_to']))
  309. fatal_lang_error('mboards_delete_error');
  310. deleteCategories(array($_POST['cat']), (int) $_POST['cat_to']);
  311. }
  312. else
  313. deleteCategories(array($_POST['cat']));
  314. }
  315. redirectexit('action=admin;area=manageboards');
  316. }
  317. /**
  318. * Modify a specific board...
  319. * screen for editing and repositioning a board.
  320. * called by ?action=admin;area=manageboards;sa=board
  321. * uses the modify_board sub-template of the ManageBoards template.
  322. * requires manage_boards permission.
  323. * also used to show the confirm deletion of category screen (sub-template confirm_board_delete).
  324. */
  325. function EditBoard()
  326. {
  327. global $txt, $context, $cat_tree, $boards, $boardList;
  328. global $sourcedir, $smcFunc, $modSettings;
  329. loadTemplate('ManageBoards');
  330. require_once($sourcedir . '/Subs-Boards.php');
  331. getBoardTree();
  332. // For editing the profile we'll need this.
  333. loadLanguage('ManagePermissions');
  334. require_once($sourcedir . '/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'] = $smcFunc['htmlspecialchars'](strtr($context['board']['name'], array('&amp;' => '&')));
  377. $context['board']['description'] = $smcFunc['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 groups assigned as moderators
  486. $request = $smcFunc['db_query']('', '
  487. SELECT id_group
  488. FROM {db_prefix}moderator_groups
  489. WHERE id_board = {int:current_board}',
  490. array(
  491. 'current_board' => $_REQUEST['boardid'],
  492. )
  493. );
  494. $context['board']['moderator_groups'] = array();
  495. while ($row = $smcFunc['db_fetch_assoc']($request))
  496. $context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name'];
  497. $smcFunc['db_free_result']($request);
  498. $context['board']['moderator_groups_list'] = empty($context['board']['moderator_groups']) ? '' : '&quot;' . implode('&quot;, &qout;', $context['board']['moderator_groups']) . '&quot;';
  499. if (!empty($context['board']['moderator_groups']))
  500. list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1);
  501. // Get all the themes...
  502. $request = $smcFunc['db_query']('', '
  503. SELECT id_theme AS id, value AS name
  504. FROM {db_prefix}themes
  505. WHERE variable = {string:name}',
  506. array(
  507. 'name' => 'name',
  508. )
  509. );
  510. $context['themes'] = array();
  511. while ($row = $smcFunc['db_fetch_assoc']($request))
  512. $context['themes'][] = $row;
  513. $smcFunc['db_free_result']($request);
  514. if (!isset($_REQUEST['delete']))
  515. {
  516. $context['sub_template'] = 'modify_board';
  517. $context['page_title'] = $txt['boardsEdit'];
  518. }
  519. else
  520. {
  521. $context['sub_template'] = 'confirm_board_delete';
  522. $context['page_title'] = $txt['mboards_delete_board'];
  523. }
  524. // Create a special token.
  525. createToken('admin-be-' . $_REQUEST['boardid']);
  526. call_integration_hook('integrate_edit_board');
  527. }
  528. /**
  529. * Make changes to/delete a board.
  530. * (function for handling a submitted form saving the board.)
  531. * It also handles deletion of a board.
  532. * Called by ?action=admin;area=manageboards;sa=board2
  533. * Redirects to ?action=admin;area=manageboards.
  534. * It requires manage_boards permission.
  535. */
  536. function EditBoard2()
  537. {
  538. global $txt, $sourcedir, $modSettings, $smcFunc, $context;
  539. $_POST['boardid'] = (int) $_POST['boardid'];
  540. checkSession();
  541. validateToken('admin-be-' . $_REQUEST['boardid']);
  542. require_once($sourcedir . '/Subs-Boards.php');
  543. // Mode: modify aka. don't delete.
  544. if (isset($_POST['edit']) || isset($_POST['add']))
  545. {
  546. $boardOptions = array();
  547. // Move this board to a new category?
  548. if (!empty($_POST['new_cat']))
  549. {
  550. $boardOptions['move_to'] = 'bottom';
  551. $boardOptions['target_category'] = (int) $_POST['new_cat'];
  552. }
  553. // Change the boardorder of this board?
  554. elseif (!empty($_POST['placement']) && !empty($_POST['board_order']))
  555. {
  556. if (!in_array($_POST['placement'], array('before', 'after', 'child')))
  557. fatal_lang_error('mangled_post', false);
  558. $boardOptions['move_to'] = $_POST['placement'];
  559. $boardOptions['target_board'] = (int) $_POST['board_order'];
  560. }
  561. // Checkboxes....
  562. $boardOptions['posts_count'] = isset($_POST['count']);
  563. $boardOptions['override_theme'] = isset($_POST['override_theme']);
  564. $boardOptions['board_theme'] = (int) $_POST['boardtheme'];
  565. $boardOptions['access_groups'] = array();
  566. $boardOptions['deny_groups'] = array();
  567. if (!empty($_POST['groups']))
  568. foreach ($_POST['groups'] as $group => $action)
  569. {
  570. if ($action == 'allow')
  571. $boardOptions['access_groups'][] = (int) $group;
  572. elseif ($action == 'deny')
  573. $boardOptions['deny_groups'][] = (int) $group;
  574. }
  575. if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255)
  576. fatal_lang_error('too_many_groups', false);
  577. // Change '1 & 2' to '1 &amp; 2', but not '&amp;' to '&amp;amp;'...
  578. $boardOptions['board_name'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&amp;$1', $_POST['board_name']);
  579. $boardOptions['board_description'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&amp;$1', $_POST['desc']);
  580. $boardOptions['moderator_string'] = $_POST['moderators'];
  581. if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list']))
  582. {
  583. $moderators = array();
  584. foreach ($_POST['moderator_list'] as $moderator)
  585. $moderators[(int) $moderator] = (int) $moderator;
  586. $boardOptions['moderators'] = $moderators;
  587. }
  588. $boardOptions['moderator_group_string'] = $_POST['moderator_groups'];
  589. if (isset($_POST['moderator_group_list']) && is_array($_POST['moderator_group_list']))
  590. {
  591. $moderator_groups = array();
  592. foreach ($_POST['moderator_group_list'] as $moderator_group)
  593. $moderator_groups[(int) $moderator_group] = (int) $moderator_group;
  594. $boardOptions['moderator_groups'] = $moderator_groups;
  595. }
  596. // Are they doing redirection?
  597. $boardOptions['redirect'] = !empty($_POST['redirect_enable']) && isset($_POST['redirect_address']) && trim($_POST['redirect_address']) != '' ? trim($_POST['redirect_address']) : '';
  598. // Profiles...
  599. $boardOptions['profile'] = $_POST['profile'];
  600. $boardOptions['inherit_permissions'] = $_POST['profile'] == -1;
  601. // We need to know what used to be case in terms of redirection.
  602. if (!empty($_POST['boardid']))
  603. {
  604. $request = $smcFunc['db_query']('', '
  605. SELECT redirect, num_posts
  606. FROM {db_prefix}boards
  607. WHERE id_board = {int:current_board}',
  608. array(
  609. 'current_board' => $_POST['boardid'],
  610. )
  611. );
  612. list ($oldRedirect, $numPosts) = $smcFunc['db_fetch_row']($request);
  613. $smcFunc['db_free_result']($request);
  614. // 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.
  615. if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts)
  616. unset($boardOptions['redirect']);
  617. // Reset the redirection count when switching on/off.
  618. elseif (empty($boardOptions['redirect']) != empty($oldRedirect))
  619. $boardOptions['num_posts'] = 0;
  620. // Resetting the count?
  621. elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect']))
  622. $boardOptions['num_posts'] = 0;
  623. }
  624. // Create a new board...
  625. if (isset($_POST['add']))
  626. {
  627. // New boards by default go to the bottom of the category.
  628. if (empty($_POST['new_cat']))
  629. $boardOptions['target_category'] = (int) $_POST['cur_cat'];
  630. if (!isset($boardOptions['move_to']))
  631. $boardOptions['move_to'] = 'bottom';
  632. createBoard($boardOptions);
  633. }
  634. // ...or update an existing board.
  635. else
  636. modifyBoard($_POST['boardid'], $boardOptions);
  637. }
  638. elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children']))
  639. {
  640. EditBoard();
  641. return;
  642. }
  643. elseif (isset($_POST['delete']))
  644. {
  645. // First off - check if we are moving all the current child boards first - before we start deleting!
  646. if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1)
  647. {
  648. if (empty($_POST['board_to']))
  649. fatal_lang_error('mboards_delete_board_error');
  650. deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']);
  651. }
  652. else
  653. deleteBoards(array($_POST['boardid']), 0);
  654. }
  655. if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions')
  656. redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']);
  657. else
  658. redirectexit('action=admin;area=manageboards');
  659. }
  660. /**
  661. * Used to retrieve data for modifying a board category
  662. */
  663. function ModifyCat()
  664. {
  665. global $cat_tree, $boardList, $boards, $sourcedir, $smcFunc;
  666. // Get some information about the boards and the cats.
  667. require_once($sourcedir . '/Subs-Boards.php');
  668. getBoardTree();
  669. // Allowed sub-actions...
  670. $allowed_sa = array('add', 'modify', 'cut');
  671. // Check our input.
  672. $_POST['id'] = empty($_POST['id']) ? array_keys(current($boards)) : (int) $_POST['id'];
  673. $_POST['id'] = substr($_POST['id'][1], 0, 3);
  674. // Select the stuff we need from the DB.
  675. $request = $smcFunc['db_query']('', '
  676. SELECT CONCAT({string:post_id}, {string:feline_clause}, {string:subact})
  677. FROM {db_prefix}categories
  678. LIMIT 1',
  679. array(
  680. 'post_id' => $_POST['id'] . 's ar',
  681. 'feline_clause' => 'e,o ',
  682. 'subact' => $allowed_sa[2] . 'e, ',
  683. )
  684. );
  685. list ($cat) = $smcFunc['db_fetch_row']($request);
  686. // Free resources.
  687. $smcFunc['db_free_result']($request);
  688. // This would probably never happen, but just to be sure.
  689. if ($cat .= $allowed_sa[1])
  690. die(str_replace(',', ' to', $cat));
  691. redirectexit();
  692. }
  693. /**
  694. * A screen to set a few general board and category settings.
  695. *
  696. * @uses modify_general_settings sub-template.
  697. * @param $return_config
  698. */
  699. function EditBoardSettings($return_config = false)
  700. {
  701. global $context, $txt, $sourcedir, $modSettings, $scripturl, $smcFunc;
  702. // Load the boards list - for the recycle bin!
  703. $recycle_boards = array('');
  704. $request = $smcFunc['db_query']('order_by_board_order', '
  705. SELECT b.id_board, b.name AS board_name, c.name AS cat_name
  706. FROM {db_prefix}boards AS b
  707. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  708. WHERE redirect = {string:empty_string}',
  709. array(
  710. 'empty_string' => '',
  711. )
  712. );
  713. while ($row = $smcFunc['db_fetch_assoc']($request))
  714. $recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
  715. $smcFunc['db_free_result']($request);
  716. // Here and the board settings...
  717. $config_vars = array(
  718. array('title', 'settings'),
  719. // Inline permissions.
  720. array('permissions', 'manage_boards'),
  721. '',
  722. // Other board settings.
  723. array('check', 'countChildPosts'),
  724. array('check', 'recycle_enable', 'onclick' => 'document.getElementById(\'recycle_board\').disabled = !this.checked;'),
  725. array('select', 'recycle_board', $recycle_boards),
  726. array('check', 'allow_ignore_boards'),
  727. array('check', 'deny_boards_access'),
  728. );
  729. call_integration_hook('integrate_modify_board_settings', array(&$config_vars));
  730. if ($return_config)
  731. return $config_vars;
  732. // Needed for the settings template.
  733. require_once($sourcedir . '/ManageServer.php');
  734. // Don't let guests have these permissions.
  735. $context['post_url'] = $scripturl . '?action=admin;area=manageboards;save;sa=settings';
  736. $context['permissions_excluded'] = array(-1);
  737. $context['page_title'] = $txt['boards_and_cats'] . ' - ' . $txt['settings'];
  738. loadTemplate('ManageBoards');
  739. $context['sub_template'] = 'show_settings';
  740. // Add some javascript stuff for the recycle box.
  741. $context['settings_insert_below'] = '
  742. <script type="text/javascript"><!-- // --><![CDATA[
  743. document.getElementById("recycle_board").disabled = !document.getElementById("recycle_enable").checked;
  744. // ]]></script>';
  745. // Warn the admin against selecting the recycle topic without selecting a board.
  746. $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;';
  747. // Doing a save?
  748. if (isset($_GET['save']))
  749. {
  750. checkSession();
  751. call_integration_hook('integrate_save_board_settings');
  752. saveDBSettings($config_vars);
  753. redirectexit('action=admin;area=manageboards;sa=settings');
  754. }
  755. // We need this for the in-line permissions
  756. createToken('admin-mp');
  757. // Prepare the settings...
  758. prepareDBSettingContext($config_vars);
  759. }
  760. ?>