ManageBoards.php 30 KB

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