ManageBoards.php 28 KB

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