Exemple #1
0
function EditBoard2()
{
    global $txt, $db_prefix, $sourcedir, $modSettings;
    checkSession();
    require_once $sourcedir . '/Subs-Boards.php';
    $_POST['boardid'] = (int) $_POST['boardid'];
    // Mode: modify aka. don't delete.
    if (isset($_POST['edit']) || isset($_POST['add'])) {
        $boardOptions = array();
        // Move this board to a new category?
        if (!empty($_POST['new_cat'])) {
            $boardOptions['move_to'] = 'bottom';
            $boardOptions['target_category'] = (int) $_POST['new_cat'];
        } elseif (!empty($_POST['placement']) && !empty($_POST['board_order'])) {
            if (!in_array($_POST['placement'], array('before', 'after', 'child'))) {
                fatal_lang_error('mangled_post', false);
            }
            $boardOptions['move_to'] = $_POST['placement'];
            $boardOptions['target_board'] = (int) $_POST['board_order'];
        }
        // Checkboxes....
        $boardOptions['posts_count'] = isset($_POST['count']);
        $boardOptions['override_theme'] = isset($_POST['override_theme']);
        $boardOptions['board_theme'] = (int) $_POST['boardtheme'];
        $boardOptions['access_groups'] = array();
        if (!empty($_POST['groups'])) {
            foreach ($_POST['groups'] as $group) {
                $boardOptions['access_groups'][] = (int) $group;
            }
        }
        // Change '1 & 2' to '1 & 2', but not '&' to '&'...
        $boardOptions['board_name'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&$1', $_POST['board_name']);
        $boardOptions['board_description'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&$1', $_POST['desc']);
        // With permission_enable_by_board disabled you can set some predefined permissions.
        if (empty($modSettings['permission_enable_by_board'])) {
            $boardOptions['permission_mode'] = (int) $_POST['permission_mode'];
            $boardOptions['inherit_permissions'] = false;
        }
        $boardOptions['moderator_string'] = $_POST['moderators'];
        // Create a new board...
        if (isset($_POST['add'])) {
            // New boards by default go to the bottom of the category.
            if (empty($_POST['new_cat'])) {
                $boardOptions['target_category'] = (int) $_POST['cur_cat'];
            }
            if (!isset($boardOptions['move_to'])) {
                $boardOptions['move_to'] = 'bottom';
            }
            createBoard($boardOptions);
        } else {
            modifyBoard($_POST['boardid'], $boardOptions);
        }
    } elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) {
        EditBoard();
        return;
    } elseif (isset($_POST['delete'])) {
        // First off - check if we are moving all the current child boards first - before we start deleting!
        if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) {
            if (empty($_POST['board_to'])) {
                fatal_error($txt['mboards_delete_board_error']);
            }
            deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']);
        } else {
            deleteBoards(array($_POST['boardid']), 0);
        }
    }
    redirectexit('action=manageboards');
}
Exemple #2
0
/**
 * Make changes to/delete a board.
 * (function for handling a submitted form saving the board.)
 * It also handles deletion of a board.
 * Called by ?action=admin;area=manageboards;sa=board2
 * Redirects to ?action=admin;area=manageboards.
 * It requires manage_boards permission.
 */
function EditBoard2()
{
    global $txt, $sourcedir, $modSettings, $smcFunc, $context;
    $_POST['boardid'] = (int) $_POST['boardid'];
    checkSession();
    validateToken('admin-be-' . $_REQUEST['boardid']);
    require_once $sourcedir . '/Subs-Boards.php';
    // Mode: modify aka. don't delete.
    if (isset($_POST['edit']) || isset($_POST['add'])) {
        $boardOptions = array();
        // Move this board to a new category?
        if (!empty($_POST['new_cat'])) {
            $boardOptions['move_to'] = 'bottom';
            $boardOptions['target_category'] = (int) $_POST['new_cat'];
        } elseif (!empty($_POST['placement']) && !empty($_POST['board_order'])) {
            if (!in_array($_POST['placement'], array('before', 'after', 'child'))) {
                fatal_lang_error('mangled_post', false);
            }
            $boardOptions['move_to'] = $_POST['placement'];
            $boardOptions['target_board'] = (int) $_POST['board_order'];
        }
        // Checkboxes....
        $boardOptions['posts_count'] = isset($_POST['count']);
        $boardOptions['override_theme'] = isset($_POST['override_theme']);
        $boardOptions['board_theme'] = (int) $_POST['boardtheme'];
        $boardOptions['access_groups'] = array();
        $boardOptions['deny_groups'] = array();
        if (!empty($_POST['groups'])) {
            foreach ($_POST['groups'] as $group => $action) {
                if ($action == 'allow') {
                    $boardOptions['access_groups'][] = (int) $group;
                } elseif ($action == 'deny') {
                    $boardOptions['deny_groups'][] = (int) $group;
                }
            }
        }
        if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) {
            fatal_lang_error('too_many_groups', false);
        }
        // Change '1 & 2' to '1 & 2', but not '&' to '&'...
        $boardOptions['board_name'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&$1', $_POST['board_name']);
        $boardOptions['board_description'] = preg_replace('~[&]([^;]{8}|[^;]{0,8}$)~', '&$1', $_POST['desc']);
        $boardOptions['moderator_string'] = $_POST['moderators'];
        if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list'])) {
            $moderators = array();
            foreach ($_POST['moderator_list'] as $moderator) {
                $moderators[(int) $moderator] = (int) $moderator;
            }
            $boardOptions['moderators'] = $moderators;
        }
        // Are they doing redirection?
        $boardOptions['redirect'] = !empty($_POST['redirect_enable']) && isset($_POST['redirect_address']) && trim($_POST['redirect_address']) != '' ? trim($_POST['redirect_address']) : '';
        // Profiles...
        $boardOptions['profile'] = $_POST['profile'];
        $boardOptions['inherit_permissions'] = $_POST['profile'] == -1;
        // We need to know what used to be case in terms of redirection.
        if (!empty($_POST['boardid'])) {
            $request = $smcFunc['db_query']('', '
				SELECT redirect, num_posts
				FROM {db_prefix}boards
				WHERE id_board = {int:current_board}', array('current_board' => $_POST['boardid']));
            list($oldRedirect, $numPosts) = $smcFunc['db_fetch_row']($request);
            $smcFunc['db_free_result']($request);
            // 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.
            if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) {
                unset($boardOptions['redirect']);
            } elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) {
                $boardOptions['num_posts'] = 0;
            } elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) {
                $boardOptions['num_posts'] = 0;
            }
        }
        // Create a new board...
        if (isset($_POST['add'])) {
            // New boards by default go to the bottom of the category.
            if (empty($_POST['new_cat'])) {
                $boardOptions['target_category'] = (int) $_POST['cur_cat'];
            }
            if (!isset($boardOptions['move_to'])) {
                $boardOptions['move_to'] = 'bottom';
            }
            createBoard($boardOptions);
        } else {
            modifyBoard($_POST['boardid'], $boardOptions);
        }
    } elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) {
        EditBoard();
        return;
    } elseif (isset($_POST['delete'])) {
        // First off - check if we are moving all the current child boards first - before we start deleting!
        if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) {
            if (empty($_POST['board_to'])) {
                fatal_lang_error('mboards_delete_board_error');
            }
            deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']);
        } else {
            deleteBoards(array($_POST['boardid']), 0);
        }
    }
    if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') {
        redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']);
    } else {
        redirectexit('action=admin;area=manageboards');
    }
}