ManageBoards.php 27 KB

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