Exemple #1
0
function EditBoard()
{
    global $txt, $db_prefix, $context, $cat_tree, $boards, $boardList, $sourcedir;
    loadTemplate('ManageBoards');
    require_once $sourcedir . '/Subs-Boards.php';
    getBoardTree();
    // ID_BOARD must be a number....
    $_REQUEST['boardid'] = isset($_REQUEST['boardid']) ? (int) $_REQUEST['boardid'] : 0;
    if (!isset($boards[$_REQUEST['boardid']])) {
        $_REQUEST['boardid'] = 0;
        $_REQUEST['sa'] = 'newboard';
    }
    if ($_REQUEST['sa'] == 'newboard') {
        // Some things that need to be setup for a new board.
        $curBoard = array('memberGroups' => array(0, -1), 'category' => (int) $_REQUEST['cat']);
        $context['board_order'] = array();
        $context['board'] = array('is_new' => true, 'id' => 0, 'name' => $txt['mboards_new_board_name'], 'description' => '', 'count_posts' => 1, 'theme' => 0, 'override_theme' => 0, 'category' => (int) $_REQUEST['cat'], 'no_children' => true, 'permission_mode' => 'normal');
    } else {
        // Just some easy shortcuts.
        $curBoard =& $boards[$_REQUEST['boardid']];
        $context['board'] = $boards[$_REQUEST['boardid']];
        $context['board']['name'] = htmlspecialchars($context['board']['name']);
        $context['board']['description'] = htmlspecialchars($context['board']['description']);
        $context['board']['no_children'] = empty($boards[$_REQUEST['boardid']]['tree']['children']);
    }
    // Default membergroups.
    $context['groups'] = array(-1 => array('id' => '-1', 'name' => $txt['parent_guests_only'], 'checked' => in_array('-1', $curBoard['memberGroups']), 'is_post_group' => false), 0 => array('id' => '0', 'name' => $txt['parent_members_only'], 'checked' => in_array('0', $curBoard['memberGroups']), 'is_post_group' => false));
    // Load membergroups.
    $request = db_query("\n\t\tSELECT groupName, ID_GROUP, minPosts\n\t\tFROM {$db_prefix}membergroups\n\t\tWHERE ID_GROUP > 3 OR ID_GROUP = 2\n\t\tORDER BY minPosts, ID_GROUP != 2, groupName", __FILE__, __LINE__);
    while ($row = mysql_fetch_assoc($request)) {
        if ($_REQUEST['sa'] == 'newboard' && $row['minPosts'] == -1) {
            $curBoard['memberGroups'][] = $row['ID_GROUP'];
        }
        $context['groups'][(int) $row['ID_GROUP']] = array('id' => $row['ID_GROUP'], 'name' => trim($row['groupName']), 'checked' => in_array($row['ID_GROUP'], $curBoard['memberGroups']), 'is_post_group' => $row['minPosts'] != -1);
    }
    mysql_free_result($request);
    foreach ($boardList[$curBoard['category']] as $boardid) {
        if ($boardid == $_REQUEST['boardid']) {
            $context['board_order'][] = array('id' => $boardid, 'name' => str_repeat('-', $boards[$boardid]['level']) . ' (' . $txt['mboards_current_position'] . ')', 'children' => $boards[$boardid]['tree']['children'], 'no_children' => empty($boards[$boardid]['tree']['children']), 'is_child' => false, 'selected' => true);
        } else {
            $context['board_order'][] = array('id' => $boardid, 'name' => str_repeat('-', $boards[$boardid]['level']) . ' ' . $boards[$boardid]['name'], 'is_child' => empty($_REQUEST['boardid']) ? false : isChildOf($boardid, $_REQUEST['boardid']), 'selected' => false);
        }
    }
    // Are there any places to move child boards to in the case where we are confirming a delete?
    if (!empty($_REQUEST['boardid'])) {
        $context['can_move_children'] = false;
        $context['children'] = $boards[$_REQUEST['boardid']]['tree']['children'];
        foreach ($context['board_order'] as $board) {
            if ($board['is_child'] == false && $board['selected'] == false) {
                $context['can_move_children'] = true;
            }
        }
    }
    // Get other available categories.
    $context['categories'] = array();
    foreach ($cat_tree as $catID => $tree) {
        $context['categories'][] = array('id' => $catID == $curBoard['category'] ? 0 : $catID, 'name' => $tree['node']['name'], 'selected' => $catID == $curBoard['category']);
    }
    $request = db_query("\n\t\tSELECT mem.realName\n\t\tFROM ({$db_prefix}moderators AS mods, {$db_prefix}members AS mem)\n\t\tWHERE mods.ID_BOARD = {$_REQUEST['boardid']}\n\t\t\tAND mem.ID_MEMBER = mods.ID_MEMBER", __FILE__, __LINE__);
    $context['board']['moderators'] = array();
    while ($row = mysql_fetch_assoc($request)) {
        $context['board']['moderators'][] = $row['realName'];
    }
    mysql_free_result($request);
    $context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '"' . implode('", "', $context['board']['moderators']) . '"';
    // Get all the themes...
    $request = db_query("\n\t\tSELECT ID_THEME AS id, value AS name\n\t\tFROM {$db_prefix}themes\n\t\tWHERE variable = 'name'", __FILE__, __LINE__);
    $context['themes'] = array();
    while ($row = mysql_fetch_assoc($request)) {
        $context['themes'][] = $row;
    }
    mysql_free_result($request);
    if (!isset($_REQUEST['delete'])) {
        $context['sub_template'] = 'modify_board';
        $context['page_title'] = $txt['boardsEdit'];
    } else {
        $context['sub_template'] = 'confirm_board_delete';
        $context['page_title'] = $txt['mboards_delete_board'];
    }
}
Exemple #2
0
/**
 * Modify a specific board...
 * screen for editing and repositioning a board.
 * called by ?action=admin;area=manageboards;sa=board
 * uses the modify_board sub-template of the ManageBoards template.
 * requires manage_boards permission.
 * also used to show the confirm deletion of category screen (sub-template confirm_board_delete).
		  (sub-template confirm_board_delete).
*/
function EditBoard()
{
    global $txt, $context, $cat_tree, $boards, $boardList, $sourcedir, $smcFunc, $modSettings;
    loadTemplate('ManageBoards');
    require_once $sourcedir . '/Subs-Boards.php';
    getBoardTree();
    // For editing the profile we'll need this.
    loadLanguage('ManagePermissions');
    require_once $sourcedir . '/ManagePermissions.php';
    loadPermissionProfiles();
    // id_board must be a number....
    $_REQUEST['boardid'] = isset($_REQUEST['boardid']) ? (int) $_REQUEST['boardid'] : 0;
    if (!isset($boards[$_REQUEST['boardid']])) {
        $_REQUEST['boardid'] = 0;
        $_REQUEST['sa'] = 'newboard';
    }
    if ($_REQUEST['sa'] == 'newboard') {
        // Category doesn't exist, man... sorry.
        if (empty($_REQUEST['cat'])) {
            redirectexit('action=admin;area=manageboards');
        }
        // Some things that need to be setup for a new board.
        $curBoard = array('member_groups' => array(0, -1), 'deny_groups' => array(), 'category' => (int) $_REQUEST['cat']);
        $context['board_order'] = array();
        $context['board'] = array('is_new' => true, 'id' => 0, 'name' => $txt['mboards_new_board_name'], 'description' => '', 'count_posts' => 1, 'posts' => 0, 'topics' => 0, 'theme' => 0, 'profile' => 1, 'override_theme' => 0, 'redirect' => '', 'category' => (int) $_REQUEST['cat'], 'no_children' => true);
    } else {
        // Just some easy shortcuts.
        $curBoard =& $boards[$_REQUEST['boardid']];
        $context['board'] = $boards[$_REQUEST['boardid']];
        $context['board']['name'] = htmlspecialchars(strtr($context['board']['name'], array('&' => '&')));
        $context['board']['description'] = htmlspecialchars($context['board']['description']);
        $context['board']['no_children'] = empty($boards[$_REQUEST['boardid']]['tree']['children']);
        $context['board']['is_recycle'] = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) && $modSettings['recycle_board'] == $context['board']['id'];
    }
    // As we may have come from the permissions screen keep track of where we should go on save.
    $context['redirect_location'] = isset($_GET['rid']) && $_GET['rid'] == 'permissions' ? 'permissions' : 'boards';
    // We might need this to hide links to certain areas.
    $context['can_manage_permissions'] = allowedTo('manage_permissions');
    // Default membergroups.
    $context['groups'] = array(-1 => array('id' => '-1', 'name' => $txt['parent_guests_only'], 'allow' => in_array('-1', $curBoard['member_groups']), 'deny' => in_array('-1', $curBoard['deny_groups']), 'is_post_group' => false), 0 => array('id' => '0', 'name' => $txt['parent_members_only'], 'allow' => in_array('0', $curBoard['member_groups']), 'deny' => in_array('0', $curBoard['deny_groups']), 'is_post_group' => false));
    // Load membergroups.
    $request = $smcFunc['db_query']('', '
		SELECT group_name, id_group, min_posts
		FROM {db_prefix}membergroups
		WHERE id_group > {int:moderator_group} OR id_group = {int:global_moderator}
		ORDER BY min_posts, id_group != {int:global_moderator}, group_name', array('moderator_group' => 3, 'global_moderator' => 2));
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) {
            $curBoard['member_groups'][] = $row['id_group'];
        }
        $context['groups'][(int) $row['id_group']] = array('id' => $row['id_group'], 'name' => trim($row['group_name']), 'allow' => in_array($row['id_group'], $curBoard['member_groups']), 'deny' => in_array($row['id_group'], $curBoard['deny_groups']), 'is_post_group' => $row['min_posts'] != -1);
    }
    $smcFunc['db_free_result']($request);
    // Category doesn't exist, man... sorry.
    if (!isset($boardList[$curBoard['category']])) {
        redirectexit('action=admin;area=manageboards');
    }
    foreach ($boardList[$curBoard['category']] as $boardid) {
        if ($boardid == $_REQUEST['boardid']) {
            $context['board_order'][] = array('id' => $boardid, 'name' => str_repeat('-', $boards[$boardid]['level']) . ' (' . $txt['mboards_current_position'] . ')', 'children' => $boards[$boardid]['tree']['children'], 'no_children' => empty($boards[$boardid]['tree']['children']), 'is_child' => false, 'selected' => true);
        } else {
            $context['board_order'][] = array('id' => $boardid, 'name' => str_repeat('-', $boards[$boardid]['level']) . ' ' . $boards[$boardid]['name'], 'is_child' => empty($_REQUEST['boardid']) ? false : isChildOf($boardid, $_REQUEST['boardid']), 'selected' => false);
        }
    }
    // Are there any places to move child boards to in the case where we are confirming a delete?
    if (!empty($_REQUEST['boardid'])) {
        $context['can_move_children'] = false;
        $context['children'] = $boards[$_REQUEST['boardid']]['tree']['children'];
        foreach ($context['board_order'] as $board) {
            if ($board['is_child'] == false && $board['selected'] == false) {
                $context['can_move_children'] = true;
            }
        }
    }
    // Get other available categories.
    $context['categories'] = array();
    foreach ($cat_tree as $catID => $tree) {
        $context['categories'][] = array('id' => $catID == $curBoard['category'] ? 0 : $catID, 'name' => $tree['node']['name'], 'selected' => $catID == $curBoard['category']);
    }
    $request = $smcFunc['db_query']('', '
		SELECT mem.id_member, mem.real_name
		FROM {db_prefix}moderators AS mods
			INNER JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member)
		WHERE mods.id_board = {int:current_board}', array('current_board' => $_REQUEST['boardid']));
    $context['board']['moderators'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $context['board']['moderators'][$row['id_member']] = $row['real_name'];
    }
    $smcFunc['db_free_result']($request);
    $context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '"' . implode('", "', $context['board']['moderators']) . '"';
    if (!empty($context['board']['moderators'])) {
        list($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1);
    }
    // Get all the themes...
    $request = $smcFunc['db_query']('', '
		SELECT id_theme AS id, value AS name
		FROM {db_prefix}themes
		WHERE variable = {string:name}', array('name' => 'name'));
    $context['themes'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $context['themes'][] = $row;
    }
    $smcFunc['db_free_result']($request);
    if (!isset($_REQUEST['delete'])) {
        $context['sub_template'] = 'modify_board';
        $context['page_title'] = $txt['boardsEdit'];
    } else {
        $context['sub_template'] = 'confirm_board_delete';
        $context['page_title'] = $txt['mboards_delete_board'];
    }
    // Create a special token.
    createToken('admin-be-' . $_REQUEST['boardid']);
    call_integration_hook('integrate_edit_board');
}
Exemple #3
0
function isChildOf($child, $parent)
{
    global $boards;
    if (empty($boards[$child]['parent'])) {
        return false;
    }
    if ($boards[$child]['parent'] == $parent) {
        return true;
    }
    return isChildOf($boards[$child]['parent'], $parent);
}
 /**
  * Modify a specific board...
  *
  * What it doews
  * - screen for editing and repositioning a board.
  * - called by ?action=admin;area=manageboards;sa=board
  * - also used to show the confirm deletion of category screen (sub-template confirm_board_delete).
  * - requires manage_boards permission.
  *
  * @uses the modify_board sub-template of the ManageBoards template.
  * @uses ManagePermissions language
  */
 public function action_board()
 {
     global $txt, $context, $cat_tree, $boards, $boardList, $modSettings;
     loadTemplate('ManageBoards');
     require_once SUBSDIR . '/Boards.subs.php';
     getBoardTree();
     // For editing the profile we'll need this.
     loadLanguage('ManagePermissions');
     require_once SUBSDIR . '/ManagePermissions.subs.php';
     loadPermissionProfiles();
     // id_board must be a number....
     $_REQUEST['boardid'] = isset($_REQUEST['boardid']) ? (int) $_REQUEST['boardid'] : 0;
     if (!isset($boards[$_REQUEST['boardid']])) {
         $_REQUEST['boardid'] = 0;
         $_REQUEST['sa'] = 'newboard';
     }
     if ($_REQUEST['sa'] == 'newboard') {
         // Category doesn't exist, man... sorry.
         if (empty($_REQUEST['cat'])) {
             redirectexit('action=admin;area=manageboards');
         }
         // Some things that need to be setup for a new board.
         $curBoard = array('member_groups' => array(0, -1), 'deny_groups' => array(), 'category' => (int) $_REQUEST['cat']);
         $context['board_order'] = array();
         $context['board'] = array('is_new' => true, 'id' => 0, 'name' => $txt['mboards_new_board_name'], 'description' => '', 'count_posts' => 1, 'posts' => 0, 'topics' => 0, 'theme' => 0, 'profile' => 1, 'override_theme' => 0, 'redirect' => '', 'category' => (int) $_REQUEST['cat'], 'no_children' => true);
     } else {
         // Just some easy shortcuts.
         $curBoard =& $boards[$_REQUEST['boardid']];
         $context['board'] = $boards[$_REQUEST['boardid']];
         $context['board']['name'] = htmlspecialchars(strtr($context['board']['name'], array('&' => '&')), ENT_COMPAT, 'UTF-8');
         $context['board']['description'] = htmlspecialchars($context['board']['description'], ENT_COMPAT, 'UTF-8');
         $context['board']['no_children'] = empty($boards[$_REQUEST['boardid']]['tree']['children']);
         $context['board']['is_recycle'] = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) && $modSettings['recycle_board'] == $context['board']['id'];
     }
     // As we may have come from the permissions screen keep track of where we should go on save.
     $context['redirect_location'] = isset($_GET['rid']) && $_GET['rid'] == 'permissions' ? 'permissions' : 'boards';
     // We might need this to hide links to certain areas.
     $context['can_manage_permissions'] = allowedTo('manage_permissions');
     // Default membergroups.
     $context['groups'] = array(-1 => array('id' => '-1', 'name' => $txt['parent_guests_only'], 'allow' => in_array('-1', $curBoard['member_groups']), 'deny' => in_array('-1', $curBoard['deny_groups']), 'is_post_group' => false), 0 => array('id' => '0', 'name' => $txt['parent_members_only'], 'allow' => in_array('0', $curBoard['member_groups']), 'deny' => in_array('0', $curBoard['deny_groups']), 'is_post_group' => false));
     $context['groups'] += getOtherGroups($curBoard);
     // Category doesn't exist, man... sorry.
     if (!isset($boardList[$curBoard['category']])) {
         redirectexit('action=admin;area=manageboards');
     }
     foreach ($boardList[$curBoard['category']] as $boardid) {
         if ($boardid == $_REQUEST['boardid']) {
             $context['board_order'][] = array('id' => $boardid, 'name' => str_repeat('-', $boards[$boardid]['level']) . ' (' . $txt['mboards_current_position'] . ')', 'children' => $boards[$boardid]['tree']['children'], 'no_children' => empty($boards[$boardid]['tree']['children']), 'is_child' => false, 'selected' => true);
         } else {
             $context['board_order'][] = array('id' => $boardid, 'name' => str_repeat('-', $boards[$boardid]['level']) . ' ' . $boards[$boardid]['name'], 'is_child' => empty($_REQUEST['boardid']) ? false : isChildOf($boardid, $_REQUEST['boardid']), 'selected' => false);
         }
     }
     // Are there any places to move sub-boards to in the case where we are confirming a delete?
     if (!empty($_REQUEST['boardid'])) {
         $context['can_move_children'] = false;
         $context['children'] = $boards[$_REQUEST['boardid']]['tree']['children'];
         foreach ($context['board_order'] as $board) {
             if ($board['is_child'] == false && $board['selected'] == false) {
                 $context['can_move_children'] = true;
             }
         }
     }
     // Get other available categories.
     $context['categories'] = array();
     foreach ($cat_tree as $catID => $tree) {
         $context['categories'][] = array('id' => $catID == $curBoard['category'] ? 0 : $catID, 'name' => $tree['node']['name'], 'selected' => $catID == $curBoard['category']);
     }
     $context['board']['moderators'] = getBoardModerators($_REQUEST['boardid']);
     $context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '"' . implode('", "', $context['board']['moderators']) . '"';
     if (!empty($context['board']['moderators'])) {
         list($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1);
     }
     $context['themes'] = getAllThemes();
     if (!isset($_REQUEST['delete'])) {
         $context['sub_template'] = 'modify_board';
         $context['page_title'] = $txt['boardsEdit'];
         loadJavascriptFile('suggest.js', array('defer' => true));
     } else {
         $context['sub_template'] = 'confirm_board_delete';
         $context['page_title'] = $txt['mboards_delete_board'];
     }
     // Create a special token.
     createToken('admin-be-' . $_REQUEST['boardid']);
     call_integration_hook('integrate_edit_board');
 }