comparison forum/Sources/ManageBoards.php @ 76:e3e11437ecea website

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