ManageBoards.php 27 KB

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