Esempio n. 1
0
/**
 * Editing a membergroup.
 * Screen to edit a specific membergroup.
 * Called by ?action=admin;area=membergroups;sa=edit;group=x.
 * It requires the manage_membergroups permission.
 * Also handles the delete button of the edit form.
 * Redirects to ?action=admin;area=membergroups.
 *
 * @uses the edit_group sub template of ManageMembergroups.
 */
function EditMembergroup()
{
    global $context, $txt, $sourcedir, $modSettings, $smcFunc;
    $_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0;
    if (!empty($modSettings['deny_boards_access'])) {
        loadLanguage('ManagePermissions');
    }
    // Make sure this group is editable.
    if (!empty($_REQUEST['group'])) {
        $request = $smcFunc['db_query']('', '
			SELECT id_group
			FROM {db_prefix}membergroups
			WHERE id_group = {int:current_group}' . (allowedTo('admin_forum') ? '' : '
				AND group_type != {int:is_protected}') . '
			LIMIT {int:limit}', array('current_group' => $_REQUEST['group'], 'is_protected' => 1, 'limit' => 1));
        list($_REQUEST['group']) = $smcFunc['db_fetch_row']($request);
        $smcFunc['db_free_result']($request);
    }
    // Now, do we have a valid id?
    if (empty($_REQUEST['group'])) {
        fatal_lang_error('membergroup_does_not_exist', false);
    }
    // The delete this membergroup button was pressed.
    if (isset($_POST['delete'])) {
        checkSession();
        validateToken('admin-mmg');
        require_once $sourcedir . '/Subs-Membergroups.php';
        deleteMembergroups($_REQUEST['group']);
        redirectexit('action=admin;area=membergroups;');
    } elseif (isset($_POST['save'])) {
        // Validate the session.
        checkSession();
        validateToken('admin-mmg');
        // Can they really inherit from this group?
        if (isset($_POST['group_inherit']) && $_POST['group_inherit'] != -2 && !allowedTo('admin_forum')) {
            $request = $smcFunc['db_query']('', '
				SELECT group_type
				FROM {db_prefix}membergroups
				WHERE id_group = {int:inherit_from}
				LIMIT {int:limit}', array('inherit_from' => $_POST['group_inherit'], 'limit' => 1));
            list($inherit_type) = $smcFunc['db_fetch_row']($request);
            $smcFunc['db_free_result']($request);
        }
        // Set variables to their proper value.
        $_POST['max_messages'] = isset($_POST['max_messages']) ? (int) $_POST['max_messages'] : 0;
        $_POST['min_posts'] = isset($_POST['min_posts']) && isset($_POST['group_type']) && $_POST['group_type'] == -1 && $_REQUEST['group'] > 3 ? abs($_POST['min_posts']) : ($_REQUEST['group'] == 4 ? 0 : -1);
        $_POST['icons'] = empty($_POST['icon_count']) || $_POST['icon_count'] < 0 ? '' : min((int) $_POST['icon_count'], 99) . '#' . $_POST['icon_image'];
        $_POST['group_desc'] = isset($_POST['group_desc']) && ($_REQUEST['group'] == 1 || isset($_POST['group_type']) && $_POST['group_type'] != -1) ? trim($_POST['group_desc']) : '';
        $_POST['group_type'] = !isset($_POST['group_type']) || $_POST['group_type'] < 0 || $_POST['group_type'] > 3 || $_POST['group_type'] == 1 && !allowedTo('admin_forum') ? 0 : (int) $_POST['group_type'];
        $_POST['group_hidden'] = empty($_POST['group_hidden']) || $_POST['min_posts'] != -1 || $_REQUEST['group'] == 3 ? 0 : (int) $_POST['group_hidden'];
        $_POST['group_inherit'] = $_REQUEST['group'] > 1 && $_REQUEST['group'] != 3 && (empty($inherit_type) || $inherit_type != 1) ? (int) $_POST['group_inherit'] : -2;
        //@todo Don't set online_color for the Moderators group?
        // Do the update of the membergroup settings.
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}membergroups
			SET group_name = {string:group_name}, online_color = {string:online_color},
				max_messages = {int:max_messages}, min_posts = {int:min_posts}, icons = {string:icons},
				description = {string:group_desc}, group_type = {int:group_type}, hidden = {int:group_hidden},
				id_parent = {int:group_inherit}
			WHERE id_group = {int:current_group}', array('max_messages' => $_POST['max_messages'], 'min_posts' => $_POST['min_posts'], 'group_type' => $_POST['group_type'], 'group_hidden' => $_POST['group_hidden'], 'group_inherit' => $_POST['group_inherit'], 'current_group' => (int) $_REQUEST['group'], 'group_name' => $smcFunc['htmlspecialchars']($_POST['group_name']), 'online_color' => $_POST['online_color'], 'icons' => $_POST['icons'], 'group_desc' => $_POST['group_desc']));
        call_integration_hook('integrate_save_membergroup', array((int) $_REQUEST['group']));
        // Time to update the boards this membergroup has access to.
        if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3) {
            $accesses = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? array() : $_POST['boardaccess'];
            $changed_boards['allow'] = array();
            $changed_boards['deny'] = array();
            $changed_boards['ignore'] = array();
            foreach ($accesses as $group_id => $action) {
                $changed_boards[$action][] = (int) $group_id;
            }
            foreach (array('allow', 'deny') as $board_action) {
                // Find all board this group is in, but shouldn't be in.
                $request = $smcFunc['db_query']('', '
					SELECT id_board, {raw:column}
					FROM {db_prefix}boards
					WHERE FIND_IN_SET({string:current_group}, {raw:column}) != 0' . (empty($changed_boards[$board_action]) ? '' : '
						AND id_board NOT IN ({array_int:board_access_list})'), array('current_group' => (int) $_REQUEST['group'], 'board_access_list' => $changed_boards[$board_action], 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups'));
                while ($row = $smcFunc['db_fetch_assoc']($request)) {
                    $smcFunc['db_query']('', '
						UPDATE {db_prefix}boards
						SET {raw:column} = {string:member_group_access}
						WHERE id_board = {int:current_board}', array('current_board' => $row['id_board'], 'member_group_access' => implode(',', array_diff(explode(',', $row['member_groups']), array($_REQUEST['group']))), 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups'));
                }
                $smcFunc['db_free_result']($request);
                // Add the membergroup to all boards that hadn't been set yet.
                if (!empty($changed_boards[$board_action])) {
                    $smcFunc['db_query']('', '
						UPDATE {db_prefix}boards
						SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
						WHERE id_board IN ({array_int:board_list})
							AND FIND_IN_SET({int:current_group}, {raw:column}) = 0', array('board_list' => $changed_boards[$board_action], 'blank_string' => '', 'current_group' => (int) $_REQUEST['group'], 'group_id_string' => (string) (int) $_REQUEST['group'], 'comma_group' => ',' . $_REQUEST['group'], 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups'));
                }
            }
        }
        // Remove everyone from this group!
        if ($_POST['min_posts'] != -1) {
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}members
				SET id_group = {int:regular_member}
				WHERE id_group = {int:current_group}', array('regular_member' => 0, 'current_group' => (int) $_REQUEST['group']));
            $request = $smcFunc['db_query']('', '
				SELECT id_member, additional_groups
				FROM {db_prefix}members
				WHERE FIND_IN_SET({string:current_group}, additional_groups) != 0', array('current_group' => (int) $_REQUEST['group']));
            $updates = array();
            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                $updates[$row['additional_groups']][] = $row['id_member'];
            }
            $smcFunc['db_free_result']($request);
            foreach ($updates as $additional_groups => $memberArray) {
                updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
            }
        } elseif ($_REQUEST['group'] != 3) {
            // Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional).
            if ($_POST['group_hidden'] == 2) {
                $request = $smcFunc['db_query']('', '
					SELECT id_member, additional_groups
					FROM {db_prefix}members
					WHERE id_group = {int:current_group}
						AND FIND_IN_SET({int:current_group}, additional_groups) = 0', array('current_group' => (int) $_REQUEST['group']));
                $updates = array();
                while ($row = $smcFunc['db_fetch_assoc']($request)) {
                    $updates[$row['additional_groups']][] = $row['id_member'];
                }
                $smcFunc['db_free_result']($request);
                foreach ($updates as $additional_groups => $memberArray) {
                    updateMemberData($memberArray, array('additional_groups' => implode(',', array_merge(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
                }
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}members
					SET id_group = {int:regular_member}
					WHERE id_group = {int:current_group}', array('regular_member' => 0, 'current_group' => $_REQUEST['group']));
            }
            // Either way, let's check our "show group membership" setting is correct.
            $request = $smcFunc['db_query']('', '
				SELECT COUNT(*)
				FROM {db_prefix}membergroups
				WHERE group_type > {int:non_joinable}', array('non_joinable' => 1));
            list($have_joinable) = $smcFunc['db_fetch_row']($request);
            $smcFunc['db_free_result']($request);
            // Do we need to update the setting?
            if (empty($modSettings['show_group_membership']) && $have_joinable || !empty($modSettings['show_group_membership']) && !$have_joinable) {
                updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0));
            }
        }
        // Do we need to set inherited permissions?
        if ($_POST['group_inherit'] != -2 && $_POST['group_inherit'] != $_POST['old_inherit']) {
            require_once $sourcedir . '/ManagePermissions.php';
            updateChildPermissions($_POST['group_inherit']);
        }
        // Finally, moderators!
        $moderator_string = isset($_POST['group_moderators']) ? trim($_POST['group_moderators']) : '';
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}group_moderators
			WHERE id_group = {int:current_group}', array('current_group' => $_REQUEST['group']));
        if ((!empty($moderator_string) || !empty($_POST['moderator_list'])) && $_POST['min_posts'] == -1 && $_REQUEST['group'] != 3) {
            // Get all the usernames from the string
            if (!empty($moderator_string)) {
                $moderator_string = strtr(preg_replace('~&amp;#(\\d{4,5}|[2-9]\\d{2,4}|1[2-9]\\d);~', '&#$1;', htmlspecialchars($moderator_string), ENT_QUOTES), array('&quot;' => '"'));
                preg_match_all('~"([^"]+)"~', $moderator_string, $matches);
                $moderators = array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $moderator_string)));
                for ($k = 0, $n = count($moderators); $k < $n; $k++) {
                    $moderators[$k] = trim($moderators[$k]);
                    if (strlen($moderators[$k]) == 0) {
                        unset($moderators[$k]);
                    }
                }
                // Find all the id_member's for the member_name's in the list.
                $group_moderators = array();
                if (!empty($moderators)) {
                    $request = $smcFunc['db_query']('', '
						SELECT id_member
						FROM {db_prefix}members
						WHERE member_name IN ({array_string:moderators}) OR real_name IN ({array_string:moderators})
						LIMIT ' . count($moderators), array('moderators' => $moderators));
                    while ($row = $smcFunc['db_fetch_assoc']($request)) {
                        $group_moderators[] = $row['id_member'];
                    }
                    $smcFunc['db_free_result']($request);
                }
            } else {
                $moderators = array();
                foreach ($_POST['moderator_list'] as $moderator) {
                    $moderators[] = (int) $moderator;
                }
                $group_moderators = array();
                if (!empty($moderators)) {
                    $request = $smcFunc['db_query']('', '
						SELECT id_member
						FROM {db_prefix}members
						WHERE id_member IN ({array_int:moderators})
						LIMIT {int:num_moderators}', array('moderators' => $moderators, 'num_moderators' => count($moderators)));
                    while ($row = $smcFunc['db_fetch_assoc']($request)) {
                        $group_moderators[] = $row['id_member'];
                    }
                    $smcFunc['db_free_result']($request);
                }
            }
            // Found some?
            if (!empty($group_moderators)) {
                $mod_insert = array();
                foreach ($group_moderators as $moderator) {
                    $mod_insert[] = array($_REQUEST['group'], $moderator);
                }
                $smcFunc['db_insert']('insert', '{db_prefix}group_moderators', array('id_group' => 'int', 'id_member' => 'int'), $mod_insert, array('id_group', 'id_member'));
            }
        }
        // There might have been some post group changes.
        updateStats('postgroups');
        // We've definitely changed some group stuff.
        updateSettings(array('settings_updated' => time()));
        // Log the edit.
        logAction('edited_group', array('group' => $_POST['group_name']), 'admin');
        redirectexit('action=admin;area=membergroups');
    }
    // Fetch the current group information.
    $request = $smcFunc['db_query']('', '
		SELECT group_name, description, min_posts, online_color, max_messages, icons, group_type, hidden, id_parent
		FROM {db_prefix}membergroups
		WHERE id_group = {int:current_group}
		LIMIT 1', array('current_group' => (int) $_REQUEST['group']));
    if ($smcFunc['db_num_rows']($request) == 0) {
        fatal_lang_error('membergroup_does_not_exist', false);
    }
    $row = $smcFunc['db_fetch_assoc']($request);
    $smcFunc['db_free_result']($request);
    $row['icons'] = explode('#', $row['icons']);
    $context['group'] = array('id' => $_REQUEST['group'], 'name' => $row['group_name'], 'description' => htmlspecialchars($row['description']), 'editable_name' => $row['group_name'], 'color' => $row['online_color'], 'min_posts' => $row['min_posts'], 'max_messages' => $row['max_messages'], 'icon_count' => (int) $row['icons'][0], 'icon_image' => isset($row['icons'][1]) ? $row['icons'][1] : '', 'is_post_group' => $row['min_posts'] != -1, 'type' => $row['min_posts'] != -1 ? 0 : $row['group_type'], 'hidden' => $row['min_posts'] == -1 ? $row['hidden'] : 0, 'inherited_from' => $row['id_parent'], 'allow_post_group' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4, 'allow_delete' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4, 'allow_protected' => allowedTo('admin_forum'));
    // Get any moderators for this group
    $request = $smcFunc['db_query']('', '
		SELECT mem.id_member, mem.real_name
		FROM {db_prefix}group_moderators AS mods
			INNER JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member)
		WHERE mods.id_group = {int:current_group}', array('current_group' => $_REQUEST['group']));
    $context['group']['moderators'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $context['group']['moderators'][$row['id_member']] = $row['real_name'];
    }
    $smcFunc['db_free_result']($request);
    $context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['group']['moderators']) . '&quot;';
    if (!empty($context['group']['moderators'])) {
        list($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
    }
    // Get a list of boards this membergroup is allowed to see.
    $context['boards'] = array();
    if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3) {
        $request = $smcFunc['db_query']('', '
			SELECT b.id_cat, c.name as cat_name, b.id_board, b.name, b.child_level,
			FIND_IN_SET({string:current_group}, b.member_groups) != 0 AS can_access, FIND_IN_SET({string:current_group}, b.deny_member_groups) != 0 AS cannot_access
			FROM {db_prefix}boards AS b
				LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
			ORDER BY board_order', array('current_group' => (int) $_REQUEST['group']));
        $context['categories'] = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            // This category hasn't been set up yet..
            if (!isset($context['categories'][$row['id_cat']])) {
                $context['categories'][$row['id_cat']] = array('id' => $row['id_cat'], 'name' => $row['cat_name'], 'boards' => array());
            }
            // Set this board up, and let the template know when it's a child.  (indent them..)
            $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array('id' => $row['id_board'], 'name' => $row['name'], 'child_level' => $row['child_level'], 'allow' => !(empty($row['can_access']) || $row['can_access'] == 'f'), 'deny' => !(empty($row['cannot_access']) || $row['cannot_access'] == 'f'));
        }
        $smcFunc['db_free_result']($request);
        // Now, let's sort the list of categories into the boards for templates that like that.
        $temp_boards = array();
        foreach ($context['categories'] as $category) {
            $temp_boards[] = array('name' => $category['name'], 'child_ids' => array_keys($category['boards']));
            $temp_boards = array_merge($temp_boards, array_values($category['boards']));
            // Include a list of boards per category for easy toggling.
            $context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']);
        }
        $max_boards = ceil(count($temp_boards) / 2);
        if ($max_boards == 1) {
            $max_boards = 2;
        }
    }
    // Finally, get all the groups this could be inherited off.
    $request = $smcFunc['db_query']('', '
		SELECT id_group, group_name
		FROM {db_prefix}membergroups
		WHERE id_group != {int:current_group}' . (empty($modSettings['permission_enable_postgroups']) ? '
			AND min_posts = {int:min_posts}' : '') . (allowedTo('admin_forum') ? '' : '
			AND group_type != {int:is_protected}') . '
			AND id_group NOT IN (1, 3)
			AND id_parent = {int:not_inherited}', array('current_group' => (int) $_REQUEST['group'], 'min_posts' => -1, 'not_inherited' => -2, 'is_protected' => 1));
    $context['inheritable_groups'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $context['inheritable_groups'][$row['id_group']] = $row['group_name'];
    }
    $smcFunc['db_free_result']($request);
    call_integration_hook('integrate_view_membergroup');
    $context['sub_template'] = 'edit_group';
    $context['page_title'] = $txt['membergroups_edit_group'];
    createToken('admin-mmg');
}
 /**
  * Editing a membergroup.
  *
  * What it does:
  * - Screen to edit a specific membergroup.
  * - Called by ?action=admin;area=membergroups;sa=edit;group=x.
  * - It requires the manage_membergroups permission.
  * - Also handles the delete button of the edit form.
  * - Redirects to ?action=admin;area=membergroups.
  *
  * @uses the edit_group sub template of ManageMembergroups.
  */
 public function action_edit()
 {
     global $context, $txt, $modSettings;
     $current_group_id = isset($_REQUEST['group']) ? (int) $_REQUEST['group'] : 0;
     if (!empty($modSettings['deny_boards_access'])) {
         loadLanguage('ManagePermissions');
     }
     require_once SUBSDIR . '/Membergroups.subs.php';
     // Make sure this group is editable.
     if (!empty($current_group_id)) {
         $current_group = membergroupById($current_group_id);
     }
     // Now, do we have a valid id?
     if (!allowedTo('admin_forum') && !empty($current_group_id) && $current_group['group_type'] == 1) {
         fatal_lang_error('membergroup_does_not_exist', false);
     }
     // The delete this membergroup button was pressed.
     if (isset($_POST['delete'])) {
         checkSession();
         validateToken('admin-mmg');
         if (empty($current_group_id)) {
             fatal_lang_error('membergroup_does_not_exist', false);
         }
         // Let's delete the group
         deleteMembergroups($current_group['id_group']);
         redirectexit('action=admin;area=membergroups;');
     } elseif (isset($_POST['save'])) {
         // Validate the session.
         checkSession();
         validateToken('admin-mmg');
         if (empty($current_group_id)) {
             fatal_lang_error('membergroup_does_not_exist', false);
         }
         require_once SUBSDIR . '/DataValidator.class.php';
         $validator = new Data_Validator();
         // Cleanup the inputs! :D
         $validator->sanitation_rules(array('max_messages' => 'intval', 'min_posts' => 'intval|abs', 'group_type' => 'intval', 'group_desc' => 'trim|Util::htmlspecialchars', 'group_name' => 'trim|Util::htmlspecialchars', 'group_hidden' => 'intval', 'group_inherit' => 'intval', 'icon_count' => 'intval', 'icon_image' => 'trim|Util::htmlspecialchars', 'online_color' => 'trim|valid_color'));
         $validator->input_processing(array('boardaccess' => 'array'));
         $validator->validation_rules(array('boardaccess' => 'contains[allow,ignore,deny]'));
         $validator->validate($_POST);
         // Can they really inherit from this group?
         if ($validator->group_inherit != -2 && !allowedTo('admin_forum')) {
             $inherit_type = membergroupById($validator->group_inherit);
         }
         $min_posts = $validator->group_type == -1 && $validator->min_posts >= 0 && $current_group['id_group'] > 3 ? $validator->min_posts : ($current_group['id_group'] == 4 ? 0 : -1);
         $group_inherit = $current_group['id_group'] > 1 && $current_group['id_group'] != 3 && (empty($inherit_type['group_type']) || $inherit_type['group_type'] != 1) ? $validator->group_inherit : -2;
         //@todo Don't set online_color for the Moderators group?
         // Do the update of the membergroup settings.
         $properties = array('max_messages' => $validator->max_messages, 'min_posts' => $min_posts, 'group_type' => $validator->group_type < 0 || $validator->group_type > 3 || $validator->group_type == 1 && !allowedTo('admin_forum') ? 0 : $validator->group_type, 'hidden' => !$validator->group_hidden || $min_posts != -1 || $current_group['id_group'] == 3 ? 0 : $validator->group_hidden, 'id_parent' => $group_inherit, 'current_group' => $current_group['id_group'], 'group_name' => $validator->group_name, 'online_color' => $validator->online_color, 'icons' => $validator->icon_count <= 0 ? '' : min($validator->icon_count, 10) . '#' . $validator->icon_image, 'description' => $current_group['id_group'] == 1 || $validator->group_type != -1 ? $validator->group_desc : '');
         updateMembergroupProperties($properties);
         call_integration_hook('integrate_save_membergroup', array($current_group['id_group']));
         // Time to update the boards this membergroup has access to.
         if ($current_group['id_group'] == 2 || $current_group['id_group'] > 3) {
             $changed_boards = array();
             $changed_boards['allow'] = array();
             $changed_boards['deny'] = array();
             $changed_boards['ignore'] = array();
             if ($validator->boardaccess) {
                 foreach ($validator->boardaccess as $group_id => $action) {
                     $changed_boards[$action][] = (int) $group_id;
                 }
             }
             foreach (array('allow', 'deny') as $board_action) {
                 // Find all board this group is in, but shouldn't be in.
                 detachGroupFromBoards($current_group['id_group'], $changed_boards, $board_action);
                 // Add the membergroup to all boards that hadn't been set yet.
                 if (!empty($changed_boards[$board_action])) {
                     assignGroupToBoards($current_group['id_group'], $changed_boards, $board_action);
                 }
             }
         }
         // Remove everyone from this group!
         if ($min_posts != -1) {
             detachDeletedGroupFromMembers($current_group['id_group']);
         } elseif ($current_group['id_group'] != 3) {
             // Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional).
             if ($validator->group_hidden == 2) {
                 setGroupToHidden($current_group['id_group']);
             }
             // Either way, let's check our "show group membership" setting is correct.
             validateShowGroupMembership();
         }
         // Do we need to set inherited permissions?
         if ($group_inherit != -2 && $group_inherit != $_POST['old_inherit']) {
             require_once SUBSDIR . '/Permission.subs.php';
             updateChildPermissions($group_inherit);
         }
         // Finally, moderators!
         $moderator_string = isset($_POST['group_moderators']) ? trim($_POST['group_moderators']) : '';
         detachGroupModerators($current_group['id_group']);
         if ((!empty($moderator_string) || !empty($_POST['moderator_list'])) && $min_posts == -1 && $current_group['id_group'] != 3) {
             // Get all the usernames from the string
             if (!empty($moderator_string)) {
                 $moderator_string = strtr(preg_replace('~&amp;#(\\d{4,5}|[2-9]\\d{2,4}|1[2-9]\\d);~', '&#$1;', htmlspecialchars($moderator_string, ENT_QUOTES, 'UTF-8')), array('&quot;' => '"'));
                 preg_match_all('~"([^"]+)"~', $moderator_string, $matches);
                 $moderators = array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $moderator_string)));
                 for ($k = 0, $n = count($moderators); $k < $n; $k++) {
                     $moderators[$k] = trim($moderators[$k]);
                     if (strlen($moderators[$k]) == 0) {
                         unset($moderators[$k]);
                     }
                 }
                 // Find all the id_member's for the member_name's in the list.
                 if (!empty($moderators)) {
                     $group_moderators = getIDMemberFromGroupModerators($moderators);
                 }
             } else {
                 $moderators = array();
                 foreach ($_POST['moderator_list'] as $moderator) {
                     $moderators[] = (int) $moderator;
                 }
                 $group_moderators = array();
                 if (!empty($moderators)) {
                     require_once SUBSDIR . '/Members.subs.php';
                     $members = getBasicMemberData($moderators);
                     foreach ($members as $member) {
                         $group_moderators[] = $member['id_member'];
                     }
                 }
             }
             // Found some?
             if (!empty($group_moderators)) {
                 assignGroupModerators($current_group['id_group'], $group_moderators);
             }
         }
         // There might have been some post group changes.
         updateStats('postgroups');
         // We've definitely changed some group stuff.
         updateSettings(array('settings_updated' => time()));
         // Log the edit.
         logAction('edited_group', array('group' => $validator->group_name), 'admin');
         redirectexit('action=admin;area=membergroups');
     }
     // Fetch the current group information.
     $row = membergroupById($current_group['id_group'], true);
     if (empty($row) || !allowedTo('admin_forum') && $row['group_type'] == 1) {
         fatal_lang_error('membergroup_does_not_exist', false);
     }
     $row['icons'] = explode('#', $row['icons']);
     $context['group'] = array('id' => $row['id_group'], 'name' => $row['group_name'], 'description' => htmlspecialchars($row['description'], ENT_COMPAT, 'UTF-8'), 'editable_name' => $row['group_name'], 'color' => $row['online_color'], 'min_posts' => $row['min_posts'], 'max_messages' => $row['max_messages'], 'icon_count' => (int) $row['icons'][0], 'icon_image' => isset($row['icons'][1]) ? $row['icons'][1] : '', 'is_post_group' => $row['min_posts'] != -1, 'type' => $row['min_posts'] != -1 ? 0 : $row['group_type'], 'hidden' => $row['min_posts'] == -1 ? $row['hidden'] : 0, 'inherited_from' => $row['id_parent'], 'allow_post_group' => $row['id_group'] == 2 || $row['id_group'] > 4, 'allow_delete' => $row['id_group'] == 2 || $row['id_group'] > 4, 'allow_protected' => allowedTo('admin_forum'));
     // Get any moderators for this group
     $context['group']['moderators'] = getGroupModerators($row['id_group']);
     $context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['group']['moderators']) . '&quot;';
     if (!empty($context['group']['moderators'])) {
         list($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
     }
     // Get a list of boards this membergroup is allowed to see.
     $context['boards'] = array();
     if ($row['id_group'] == 2 || $row['id_group'] > 3) {
         require_once SUBSDIR . '/Boards.subs.php';
         $context += getBoardList(array('override_permissions' => true, 'access' => $row['id_group'], 'not_redirection' => true));
         // Include a list of boards per category for easy toggling.
         foreach ($context['categories'] as $category) {
             $context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']);
         }
     }
     // Finally, get all the groups this could be inherited off.
     $context['inheritable_groups'] = getInheritableGroups($row['id_group']);
     call_integration_hook('integrate_view_membergroup');
     $context['sub_template'] = 'edit_group';
     $context['page_title'] = $txt['membergroups_edit_group'];
     // Use the autosuggest script when needed
     if ($context['group']['id'] != 3 && $context['group']['id'] != 4) {
         loadJavascriptFile('suggest.js', array('defer' => true));
     }
     createToken('admin-mmg');
 }
Esempio n. 3
0
function EditMembergroup()
{
    global $db_prefix, $context, $txt, $sourcedir;
    // Make sure this group is editable.
    if (empty($_REQUEST['group']) || (int) $_REQUEST['group'] < 1) {
        fatal_lang_error('membergroup_does_not_exist', false);
    }
    $_REQUEST['group'] = (int) $_REQUEST['group'];
    // The delete this membergroup button was pressed.
    if (isset($_POST['delete'])) {
        checkSession();
        require_once $sourcedir . '/Subs-Members.php';
        deleteMembergroups($_REQUEST['group']);
        redirectexit('action=membergroups;');
    } elseif (isset($_POST['submit'])) {
        // Validate the session.
        checkSession();
        // Set variables to their proper value.
        $_POST['max_messages'] = isset($_POST['max_messages']) ? (int) $_POST['max_messages'] : 0;
        $_POST['min_posts'] = isset($_POST['min_posts']) && $_POST['post_group'] == '1' && $_REQUEST['group'] > 3 ? abs($_POST['min_posts']) : ($_REQUEST['group'] == 4 ? 0 : -1);
        $_POST['stars'] = empty($_POST['star_count']) || $_POST['star_count'] < 0 ? '' : min((int) $_POST['star_count'], 99) . '#' . $_POST['star_image'];
        // !!! Don't set onlineColor for the Moderators group?
        // Do the update of the membergroup settings.
        db_query("\n\t\t\tUPDATE {$db_prefix}membergroups\n\t\t\tSET groupName = '{$_POST['group_name']}', onlineColor = '{$_POST['online_color']}',\n\t\t\t\tmaxMessages = {$_POST['max_messages']}, minPosts = {$_POST['min_posts']}, stars = '{$_POST['stars']}'\n\t\t\tWHERE ID_GROUP = " . (int) $_REQUEST['group'] . "\n\t\t\tLIMIT 1", __FILE__, __LINE__);
        // Time to update the boards this membergroup has access to.
        if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3) {
            $_POST['boardaccess'] = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? array() : $_POST['boardaccess'];
            foreach ($_POST['boardaccess'] as $key => $value) {
                $_POST['boardaccess'][$key] = (int) $value;
            }
            // Find all board this group is in, but shouldn't be in.
            $request = db_query("\n\t\t\t\tSELECT ID_BOARD, memberGroups\n\t\t\t\tFROM {$db_prefix}boards\n\t\t\t\tWHERE FIND_IN_SET(" . (int) $_REQUEST['group'] . ", memberGroups)" . (empty($_POST['boardaccess']) ? '' : "\n\t\t\t\t\tAND ID_BOARD NOT IN (" . implode(', ', $_POST['boardaccess']) . ')'), __FILE__, __LINE__);
            while ($row = mysql_fetch_assoc($request)) {
                db_query("\n\t\t\t\t\tUPDATE {$db_prefix}boards\n\t\t\t\t\tSET memberGroups = '" . implode(',', array_diff(explode(',', $row['memberGroups']), array($_REQUEST['group']))) . "'\n\t\t\t\t\tWHERE ID_BOARD = {$row['ID_BOARD']}\n\t\t\t\t\tLIMIT 1", __FILE__, __LINE__);
            }
            mysql_free_result($request);
            // Add the membergroup to all boards that hadn't been set yet.
            if (!empty($_POST['boardaccess'])) {
                db_query("\n\t\t\t\t\tUPDATE {$db_prefix}boards\n\t\t\t\t\tSET memberGroups = IF(memberGroups = '', '" . (int) $_REQUEST['group'] . "', CONCAT(memberGroups, '," . (int) $_REQUEST['group'] . "'))\n\t\t\t\t\tWHERE ID_BOARD IN (" . implode(', ', $_POST['boardaccess']) . ")\n\t\t\t\t\t\tAND NOT FIND_IN_SET(" . (int) $_REQUEST['group'] . ", memberGroups)", __FILE__, __LINE__);
            }
        }
        // Remove everyone from this group!
        if ($_POST['min_posts'] != -1) {
            db_query("\n\t\t\t\tUPDATE {$db_prefix}members\n\t\t\t\tSET ID_GROUP = 0\n\t\t\t\tWHERE ID_GROUP = " . (int) $_REQUEST['group'], __FILE__, __LINE__);
            $request = db_query("\n\t\t\t\tSELECT ID_MEMBER, additionalGroups\n\t\t\t\tFROM {$db_prefix}members\n\t\t\t\tWHERE FIND_IN_SET(" . (int) $_REQUEST['group'] . ", additionalGroups)", __FILE__, __LINE__);
            $updates = array();
            while ($row = mysql_fetch_assoc($request)) {
                $updates[$row['additionalGroups']][] = $row['ID_MEMBER'];
            }
            mysql_free_result($request);
            foreach ($updates as $additionalGroups => $memberArray) {
                updateMemberData($memberArray, array('additionalGroups' => '\'' . implode(',', array_diff(explode(',', $additionalGroups), array((int) $_REQUEST['group']))) . '\''));
            }
        }
        // There might have been some post group changes.
        updateStats('postgroups');
        redirectexit('action=membergroups');
    }
    // Fetch the current group information.
    $request = db_query("\n\t\tSELECT groupName, minPosts, onlineColor, maxMessages, stars\n\t\tFROM {$db_prefix}membergroups\n\t\tWHERE ID_GROUP = " . (int) $_REQUEST['group'] . "\n\t\tLIMIT 1", __FILE__, __LINE__);
    if (mysql_num_rows($request) == 0) {
        fatal_lang_error('membergroup_does_not_exist', false);
    }
    $row = mysql_fetch_assoc($request);
    mysql_free_result($request);
    $row['stars'] = explode('#', $row['stars']);
    $context['group'] = array('id' => $_REQUEST['group'], 'name' => $row['groupName'], 'editable_name' => htmlspecialchars($row['groupName']), 'color' => $row['onlineColor'], 'min_posts' => $row['minPosts'], 'max_messages' => $row['maxMessages'], 'star_count' => (int) $row['stars'][0], 'star_image' => isset($row['stars'][1]) ? $row['stars'][1] : '', 'is_post_group' => $row['minPosts'] != -1, 'allow_post_group' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4, 'allow_delete' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4);
    // Get a list of boards this membergroup is allowed to see.
    $context['boards'] = array();
    if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3) {
        $result = db_query("\n\t\t\tSELECT ID_BOARD, name, childLevel, FIND_IN_SET(" . (int) $_REQUEST['group'] . ", memberGroups) AS can_access\n\t\t\tFROM {$db_prefix}boards", __FILE__, __LINE__);
        while ($row = mysql_fetch_assoc($result)) {
            $context['boards'][] = array('id' => $row['ID_BOARD'], 'name' => $row['name'], 'child_level' => $row['childLevel'], 'selected' => !empty($row['can_access']));
        }
        mysql_free_result($result);
    }
    $context['sub_template'] = 'edit_group';
    $context['page_title'] = $txt['membergroups_edit_group'];
}
Esempio n. 4
0
function EditMembergroup()
{
    global $context, $txt, $sourcedir, $modSettings, $smcFunc;
    // Make sure this group is editable.
    if (empty($_REQUEST['group']) || (int) $_REQUEST['group'] < 1) {
        fatal_lang_error('membergroup_does_not_exist', false);
    }
    $_REQUEST['group'] = (int) $_REQUEST['group'];
    // The delete this membergroup button was pressed.
    if (isset($_POST['delete'])) {
        checkSession();
        require_once $sourcedir . '/Subs-Membergroups.php';
        deleteMembergroups($_REQUEST['group']);
        redirectexit('action=admin;area=membergroups;');
    } elseif (isset($_POST['submit'])) {
        // Validate the session.
        checkSession();
        // Set variables to their proper value.
        $_POST['max_messages'] = isset($_POST['max_messages']) ? (int) $_POST['max_messages'] : 0;
        $_POST['min_posts'] = isset($_POST['min_posts']) && isset($_POST['group_type']) && $_POST['group_type'] == -1 && $_REQUEST['group'] > 3 ? abs($_POST['min_posts']) : ($_REQUEST['group'] == 4 ? 0 : -1);
        $_POST['stars'] = empty($_POST['star_count']) || $_POST['star_count'] < 0 ? '' : min((int) $_POST['star_count'], 99) . '#' . $_POST['star_image'];
        $_POST['group_desc'] = isset($_POST['group_desc']) && ($_REQUEST['group'] == 1 || isset($_POST['group_type']) && $_POST['group_type'] != -1) ? trim($_POST['group_desc']) : '';
        $_POST['group_type'] = isset($_POST['group_type']) && $_POST['group_type'] >= 0 && $_POST['group_type'] <= 2 ? (int) $_POST['group_type'] : 0;
        $_POST['group_hidden'] = empty($_POST['group_hidden']) || $_POST['min_posts'] != -1 || $_REQUEST['group'] == 3 ? 0 : (int) $_POST['group_hidden'];
        $_POST['group_inherit'] = $_REQUEST['group'] > 1 && $_REQUEST['group'] != 3 ? (int) $_POST['group_inherit'] : -2;
        // !!! Don't set online_color for the Moderators group?
        // Do the update of the membergroup settings.
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}membergroups
			SET group_name = {string:group_name}, online_color = {string:online_color},
				max_messages = {int:max_messages}, min_posts = {int:min_posts}, stars = {string:stars},
				description = {string:group_desc}, group_type = {int:group_type}, hidden = {int:group_hidden},
				id_parent = {int:group_inherit}
			WHERE id_group = {int:current_group}', array('max_messages' => $_POST['max_messages'], 'min_posts' => $_POST['min_posts'], 'group_type' => $_POST['group_type'], 'group_hidden' => $_POST['group_hidden'], 'group_inherit' => $_POST['group_inherit'], 'current_group' => (int) $_REQUEST['group'], 'group_name' => $_POST['group_name'], 'online_color' => $_POST['online_color'], 'stars' => $_POST['stars'], 'group_desc' => $_POST['group_desc']));
        // Time to update the boards this membergroup has access to.
        if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3) {
            $_POST['boardaccess'] = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? array() : $_POST['boardaccess'];
            foreach ($_POST['boardaccess'] as $key => $value) {
                $_POST['boardaccess'][$key] = (int) $value;
            }
            // Find all board this group is in, but shouldn't be in.
            $request = $smcFunc['db_query']('', '
				SELECT id_board, member_groups
				FROM {db_prefix}boards
				WHERE FIND_IN_SET({string:current_group}, member_groups) != 0' . (empty($_POST['boardaccess']) ? '' : '
					AND id_board NOT IN ({array_int:board_access_list})'), array('current_group' => (int) $_REQUEST['group'], 'board_access_list' => $_POST['boardaccess']));
            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}boards
					SET member_groups = {string:member_group_access}
					WHERE id_board = {int:current_board}', array('current_board' => $row['id_board'], 'member_group_access' => implode(',', array_diff(explode(',', $row['member_groups']), array($_REQUEST['group'])))));
            }
            $smcFunc['db_free_result']($request);
            // Add the membergroup to all boards that hadn't been set yet.
            if (!empty($_POST['boardaccess'])) {
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}boards
					SET member_groups = CASE WHEN member_groups = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT(member_groups, {string:comma_group}) END
					WHERE id_board IN ({array_int:board_list})
						AND FIND_IN_SET({int:current_group}, member_groups) = 0', array('board_list' => $_POST['boardaccess'], 'blank_string' => '', 'current_group' => (int) $_REQUEST['group'], 'group_id_string' => (string) (int) $_REQUEST['group'], 'comma_group' => ',' . $_REQUEST['group']));
            }
        }
        // Remove everyone from this group!
        if ($_POST['min_posts'] != -1) {
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}members
				SET id_group = {int:regular_member}
				WHERE id_group = {int:current_group}', array('regular_member' => 0, 'current_group' => (int) $_REQUEST['group']));
            $request = $smcFunc['db_query']('', '
				SELECT id_member, additional_groups
				FROM {db_prefix}members
				WHERE FIND_IN_SET({string:current_group}, additional_groups) != 0', array('current_group' => (int) $_REQUEST['group']));
            $updates = array();
            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                $updates[$row['additional_groups']][] = $row['id_member'];
            }
            $smcFunc['db_free_result']($request);
            foreach ($updates as $additional_groups => $memberArray) {
                updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
            }
        } elseif ($_REQUEST['group'] != 3) {
            // Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional).
            if ($_POST['group_hidden'] == 2) {
                $request = $smcFunc['db_query']('', '
					SELECT id_member, additional_groups
					FROM {db_prefix}members
					WHERE id_group = {int:current_group}
						AND FIND_IN_SET({int:current_group}, additional_groups) = 0', array('current_group' => (int) $_REQUEST['group']));
                $updates = array();
                while ($row = $smcFunc['db_fetch_assoc']($request)) {
                    $updates[$row['additional_groups']][] = $row['id_member'];
                }
                $smcFunc['db_free_result']($request);
                foreach ($updates as $additional_groups => $memberArray) {
                    updateMemberData($memberArray, array('additional_groups' => implode(',', array_merge(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
                }
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}members
					SET id_group = {int:regular_member}
					WHERE id_group = {int:current_group}', array('regular_member' => 0, 'current_group' => $_REQUEST['group']));
            }
            // Either way, let's check our "show group membership" setting is correct.
            $request = $smcFunc['db_query']('', '
				SELECT COUNT(*)
				FROM {db_prefix}membergroups
				WHERE group_type != {int:regular_type}', array('regular_type' => 0));
            list($have_joinable) = $smcFunc['db_fetch_row']($request);
            $smcFunc['db_free_result']($request);
            // Do we need to update the setting?
            if (empty($modSettings['show_group_membership']) && $have_joinable || !empty($modSettings['show_group_membership']) && !$have_joinable) {
                updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0));
            }
        }
        // Do we need to set inherited permissions?
        if ($_POST['group_inherit'] != -2 && $_POST['group_inherit'] != $_POST['old_inherit']) {
            require_once $sourcedir . '/ManagePermissions.php';
            updateChildPermissions($_POST['group_inherit']);
        }
        // Finally, moderators!
        $moderator_string = isset($_POST['group_moderators']) ? trim($_POST['group_moderators']) : '';
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}group_moderators
			WHERE id_group = {int:current_group}', array('current_group' => $_REQUEST['group']));
        if ((!empty($moderator_string) || !empty($_POST['moderator_list'])) && $_POST['min_posts'] == -1 && $_REQUEST['group'] != 3) {
            // Get all the usernames from the string
            if (!empty($moderator_string)) {
                $moderator_string = strtr(preg_replace('~&amp;#(\\d{4,5}|[2-9]\\d{2,4}|1[2-9]\\d);~', '&#$1;', htmlspecialchars($moderator_string), ENT_QUOTES), array('&quot;' => '"'));
                preg_match_all('~"([^"]+)"~', $moderator_string, $matches);
                $moderators = array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $moderator_string)));
                for ($k = 0, $n = count($moderators); $k < $n; $k++) {
                    $moderators[$k] = trim($moderators[$k]);
                    if (strlen($moderators[$k]) == 0) {
                        unset($moderators[$k]);
                    }
                }
                // Find all the id_member's for the member_name's in the list.
                $group_moderators = array();
                if (!empty($moderators)) {
                    $request = $smcFunc['db_query']('', '
						SELECT id_member
						FROM {db_prefix}members
						WHERE member_name IN ({array_string:moderators}) OR real_name IN ({array_string:moderators})
						LIMIT ' . count($moderators), array('moderators' => $moderators));
                    while ($row = $smcFunc['db_fetch_assoc']($request)) {
                        $group_moderators[] = $row['id_member'];
                    }
                    $smcFunc['db_free_result']($request);
                }
            } else {
                $moderators = array();
                foreach ($_POST['moderator_list'] as $moderator) {
                    $moderators[] = (int) $moderator;
                }
                $group_moderators = array();
                if (!empty($moderators)) {
                    $request = $smcFunc['db_query']('', '
						SELECT id_member
						FROM {db_prefix}members
						WHERE id_member IN ({array_int:moderators})
						LIMIT {int:num_moderators}', array('moderators' => $moderators, 'num_moderators' => count($moderators)));
                    while ($row = $smcFunc['db_fetch_assoc']($request)) {
                        $group_moderators[] = $row['id_member'];
                    }
                    $smcFunc['db_free_result']($request);
                }
            }
            // Found some?
            if (!empty($group_moderators)) {
                $mod_insert = array();
                foreach ($group_moderators as $moderator) {
                    $mod_insert[] = array($_REQUEST['group'], $moderator);
                }
                $smcFunc['db_insert']('insert', '{db_prefix}group_moderators', array('id_group' => 'int', 'id_member' => 'int'), $mod_insert, array('id_group', 'id_member'));
            }
        }
        // There might have been some post group changes.
        updateStats('postgroups');
        // We've definetely changed some group stuff.
        updateSettings(array('settings_updated' => time()));
        // Log the edit.
        logAction('edited_group', array('group' => $_POST['group_name']), 'admin');
        redirectexit('action=admin;area=membergroups');
    }
    // Fetch the current group information.
    $request = $smcFunc['db_query']('', '
		SELECT group_name, description, min_posts, online_color, max_messages, stars, group_type, hidden, id_parent
		FROM {db_prefix}membergroups
		WHERE id_group = {int:current_group}
		LIMIT 1', array('current_group' => (int) $_REQUEST['group']));
    if ($smcFunc['db_num_rows']($request) == 0) {
        fatal_lang_error('membergroup_does_not_exist', false);
    }
    $row = $smcFunc['db_fetch_assoc']($request);
    $smcFunc['db_free_result']($request);
    $row['stars'] = explode('#', $row['stars']);
    $context['group'] = array('id' => $_REQUEST['group'], 'name' => $row['group_name'], 'description' => htmlspecialchars($row['description']), 'editable_name' => htmlspecialchars($row['group_name']), 'color' => $row['online_color'], 'min_posts' => $row['min_posts'], 'max_messages' => $row['max_messages'], 'star_count' => (int) $row['stars'][0], 'star_image' => isset($row['stars'][1]) ? $row['stars'][1] : '', 'is_post_group' => $row['min_posts'] != -1, 'type' => $row['min_posts'] != -1 ? 0 : $row['group_type'], 'hidden' => $row['min_posts'] == -1 ? $row['hidden'] : 0, 'inherited_from' => $row['id_parent'], 'allow_post_group' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4, 'allow_delete' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4);
    // Get any moderators for this group
    $request = $smcFunc['db_query']('', '
		SELECT mem.id_member, mem.real_name
		FROM {db_prefix}group_moderators AS mods
			INNER JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member)
		WHERE mods.id_group = {int:current_group}', array('current_group' => $_REQUEST['group']));
    $context['group']['moderators'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $context['group']['moderators'][$row['id_member']] = $row['real_name'];
    }
    $smcFunc['db_free_result']($request);
    $context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['group']['moderators']) . '&quot;';
    if (!empty($context['group']['moderators'])) {
        list($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
    }
    // Get a list of boards this membergroup is allowed to see.
    $context['boards'] = array();
    if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3) {
        $result = $smcFunc['db_query']('', '
			SELECT id_board, name, child_level, FIND_IN_SET({string:current_group}, member_groups) != 0 AS can_access
			FROM {db_prefix}boards', array('current_group' => (int) $_REQUEST['group']));
        while ($row = $smcFunc['db_fetch_assoc']($result)) {
            $context['boards'][] = array('id' => $row['id_board'], 'name' => $row['name'], 'child_level' => $row['child_level'], 'selected' => !empty($row['can_access']));
        }
        $smcFunc['db_free_result']($result);
    }
    // Finally, get all the groups this could be inherited off.
    $request = $smcFunc['db_query']('', '
		SELECT id_group, group_name
		FROM {db_prefix}membergroups
		WHERE id_group != {int:current_group}' . (empty($modSettings['permission_enable_postgroups']) ? '
			AND min_posts = {int:min_posts}' : '') . '
			AND id_group NOT IN (1, 3)
			AND id_parent = {int:not_inherited}', array('current_group' => (int) $_REQUEST['group'], 'min_posts' => -1, 'not_inherited' => -2));
    $context['inheritable_groups'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $context['inheritable_groups'][$row['id_group']] = $row['group_name'];
    }
    $smcFunc['db_free_result']($request);
    $context['sub_template'] = 'edit_group';
    $context['page_title'] = $txt['membergroups_edit_group'];
}