123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740 |
- <?php
- /**
- * This file contains functions regarding manipulation of and information about membergroups.
- *
- * Simple Machines Forum (SMF)
- *
- * @package SMF
- * @author Simple Machines http://www.simplemachines.org
- * @copyright 2011 Simple Machines
- * @license http://www.simplemachines.org/about/smf/license.php BSD
- *
- * @version 2.1 Alpha 1
- */
- if (!defined('SMF'))
- die('Hacking attempt...');
- /**
- * Delete one of more membergroups.
- * Requires the manage_membergroups permission.
- * Returns true on success or false on failure.
- * Has protection against deletion of protected membergroups.
- * Deletes the permissions linked to the membergroup.
- * Takes members out of the deleted membergroups.
- * @param array $groups
- * @return bool
- */
- function deleteMembergroups($groups)
- {
- global $sourcedir, $smcFunc, $modSettings;
- // Make sure it's an array.
- if (!is_array($groups))
- $groups = array((int) $groups);
- else
- {
- $groups = array_unique($groups);
- // Make sure all groups are integer.
- foreach ($groups as $key => $value)
- $groups[$key] = (int) $value;
- }
- // Some groups are protected (guests, administrators, moderators, newbies).
- $protected_groups = array(-1, 0, 1, 3, 4);
- // There maybe some others as well.
- if (!allowedTo('admin_forum'))
- {
- $request = $smcFunc['db_query']('', '
- SELECT id_group
- FROM {db_prefix}membergroups
- WHERE group_type = {int:is_protected}',
- array(
- 'is_protected' => 1,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $protected_groups[] = $row['id_group'];
- $smcFunc['db_free_result']($request);
- }
- // Make sure they don't delete protected groups!
- $groups = array_diff($groups, array_unique($protected_groups));
- if (empty($groups))
- return false;
- // Log the deletion.
- $request = $smcFunc['db_query']('', '
- SELECT group_name
- FROM {db_prefix}membergroups
- WHERE id_group IN ({array_int:group_list})',
- array(
- 'group_list' => $groups,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- logAction('delete_group', array('group' => $row['group_name']), 'admin');
- $smcFunc['db_free_result']($request);
- call_integration_hook('integrate_delete_membergroups', array($groups));
- // Remove the membergroups themselves.
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}membergroups
- WHERE id_group IN ({array_int:group_list})',
- array(
- 'group_list' => $groups,
- )
- );
- // Remove the permissions of the membergroups.
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}permissions
- WHERE id_group IN ({array_int:group_list})',
- array(
- 'group_list' => $groups,
- )
- );
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}board_permissions
- WHERE id_group IN ({array_int:group_list})',
- array(
- 'group_list' => $groups,
- )
- );
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}group_moderators
- WHERE id_group IN ({array_int:group_list})',
- array(
- 'group_list' => $groups,
- )
- );
- // Delete any outstanding requests.
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}log_group_requests
- WHERE id_group IN ({array_int:group_list})',
- array(
- 'group_list' => $groups,
- )
- );
- // Update the primary groups of members.
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}members
- SET id_group = {int:regular_group}
- WHERE id_group IN ({array_int:group_list})',
- array(
- 'group_list' => $groups,
- 'regular_group' => 0,
- )
- );
- // Update any inherited groups (Lose inheritance).
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}membergroups
- SET id_parent = {int:uninherited}
- WHERE id_parent IN ({array_int:group_list})',
- array(
- 'group_list' => $groups,
- 'uninherited' => -2,
- )
- );
- // Update the additional groups of members.
- $request = $smcFunc['db_query']('', '
- SELECT id_member, additional_groups
- FROM {db_prefix}members
- WHERE FIND_IN_SET({raw:additional_groups_explode}, additional_groups) != 0',
- array(
- 'additional_groups_explode' => implode(', additional_groups) != 0 OR FIND_IN_SET(', $groups),
- )
- );
- $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), $groups))));
- // No boards can provide access to these membergroups anymore.
- $request = $smcFunc['db_query']('', '
- SELECT id_board, member_groups
- FROM {db_prefix}boards
- WHERE FIND_IN_SET({raw:member_groups_explode}, member_groups) != 0',
- array(
- 'member_groups_explode' => implode(', member_groups) != 0 OR FIND_IN_SET(', $groups),
- )
- );
- $updates = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $updates[$row['member_groups']][] = $row['id_board'];
- $smcFunc['db_free_result']($request);
- foreach ($updates as $member_groups => $boardArray)
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}boards
- SET member_groups = {string:member_groups}
- WHERE id_board IN ({array_int:board_lists})',
- array(
- 'board_lists' => $boardArray,
- 'member_groups' => implode(',', array_diff(explode(',', $member_groups), $groups)),
- )
- );
- // Recalculate the post groups, as they likely changed.
- updateStats('postgroups');
- // Make a note of the fact that the cache may be wrong.
- $settings_update = array('settings_updated' => time());
- // Have we deleted the spider group?
- if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups))
- $settings_update['spider_group'] = 0;
- updateSettings($settings_update);
- // It was a success.
- return true;
- }
- /**
- * Remove one or more members from one or more membergroups.
- * Requires the manage_membergroups permission.
- * Function includes a protection against removing from implicit groups.
- * Non-admins are not able to remove members from the admin group.
- * @param array $members
- * @param array $groups = null if groups is null, the specified members are stripped from all their membergroups.
- * @param bool $permissionCheckDone = false
- * @return bool
- */
- function removeMembersFromGroups($members, $groups = null, $permissionCheckDone = false)
- {
- global $smcFunc, $user_info, $modSettings, $sourcedir;
- // You're getting nowhere without this permission, unless of course you are the group's moderator.
- if (!$permissionCheckDone)
- isAllowedTo('manage_membergroups');
- // Assume something will happen.
- updateSettings(array('settings_updated' => time()));
- // Cleaning the input.
- if (!is_array($members))
- $members = array((int) $members);
- else
- {
- $members = array_unique($members);
- // Cast the members to integer.
- foreach ($members as $key => $value)
- $members[$key] = (int) $value;
- }
- // Before we get started, let's check we won't leave the admin group empty!
- if ($groups === null || $groups == 1 || (is_array($groups) && in_array(1, $groups)))
- {
- $admins = array();
- listMembergroupMembers_Href($admins, 1);
- // Remove any admins if there are too many.
- $non_changing_admins = array_diff(array_keys($admins), $members);
- if (empty($non_changing_admins))
- $members = array_diff($members, array_keys($admins));
- }
- // Just in case.
- if (empty($members))
- return false;
- elseif ($groups === null)
- {
- // Wanna remove all groups from these members? That's easy.
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}members
- SET
- id_group = {int:regular_member},
- additional_groups = {string:blank_string}
- WHERE id_member IN ({array_int:member_list})' . (allowedTo('admin_forum') ? '' : '
- AND id_group != {int:admin_group}
- AND FIND_IN_SET({int:admin_group}, additional_groups) = 0'),
- array(
- 'member_list' => $members,
- 'regular_member' => 0,
- 'admin_group' => 1,
- 'blank_string' => '',
- )
- );
- updateStats('postgroups', $members);
- // Log what just happened.
- foreach ($members as $member)
- logAction('removed_all_groups', array('member' => $member), 'admin');
- return true;
- }
- elseif (!is_array($groups))
- $groups = array((int) $groups);
- else
- {
- $groups = array_unique($groups);
- // Make sure all groups are integer.
- foreach ($groups as $key => $value)
- $groups[$key] = (int) $value;
- }
- // Fetch a list of groups members cannot be assigned to explicitely, and the group names of the ones we want.
- $implicitGroups = array(-1, 0, 3);
- $request = $smcFunc['db_query']('', '
- SELECT id_group, group_name, min_posts
- FROM {db_prefix}membergroups
- WHERE id_group IN ({array_int:group_list})',
- array(
- 'group_list' => $groups,
- )
- );
- $group_names = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- if ($row['min_posts'] != -1)
- $implicitGroups[] = $row['id_group'];
- else
- $group_names[$row['id_group']] = $row['group_name'];
- }
- $smcFunc['db_free_result']($request);
- // Now get rid of those groups.
- $groups = array_diff($groups, $implicitGroups);
- // Don't forget the protected groups.
- if (!allowedTo('admin_forum'))
- {
- $request = $smcFunc['db_query']('', '
- SELECT id_group
- FROM {db_prefix}membergroups
- WHERE group_type = {int:is_protected}',
- array(
- 'is_protected' => 1,
- )
- );
- $protected_groups = array(1);
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $protected_groups[] = $row['id_group'];
- $smcFunc['db_free_result']($request);
- // If you're not an admin yourself, you can't touch protected groups!
- $groups = array_diff($groups, array_unique($protected_groups));
- }
- // Only continue if there are still groups and members left.
- if (empty($groups) || empty($members))
- return false;
- // First, reset those who have this as their primary group - this is the easy one.
- $log_inserts = array();
- $request = $smcFunc['db_query']('', '
- SELECT id_member, id_group
- FROM {db_prefix}members AS members
- WHERE id_group IN ({array_int:group_list})
- AND id_member IN ({array_int:member_list})',
- array(
- 'group_list' => $groups,
- 'member_list' => $members,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']);
- $smcFunc['db_free_result']($request);
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}members
- SET id_group = {int:regular_member}
- WHERE id_group IN ({array_int:group_list})
- AND id_member IN ({array_int:member_list})',
- array(
- 'group_list' => $groups,
- 'member_list' => $members,
- 'regular_member' => 0,
- )
- );
- // Those who have it as part of their additional group must be updated the long way... sadly.
- $request = $smcFunc['db_query']('', '
- SELECT id_member, additional_groups
- FROM {db_prefix}members
- WHERE (FIND_IN_SET({raw:additional_groups_implode}, additional_groups) != 0)
- AND id_member IN ({array_int:member_list})
- LIMIT ' . count($members),
- array(
- 'member_list' => $members,
- 'additional_groups_implode' => implode(', additional_groups) != 0 OR FIND_IN_SET(', $groups),
- )
- );
- $updates = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- // What log entries must we make for this one, eh?
- foreach (explode(',', $row['additional_groups']) as $group)
- if (in_array($group, $groups))
- $log_inserts[] = array('group' => $group_names[$group], 'member' => $row['id_member']);
- $updates[$row['additional_groups']][] = $row['id_member'];
- }
- $smcFunc['db_free_result']($request);
- foreach ($updates as $additional_groups => $memberArray)
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}members
- SET additional_groups = {string:additional_groups}
- WHERE id_member IN ({array_int:member_list})',
- array(
- 'member_list' => $memberArray,
- 'additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)),
- )
- );
- // Their post groups may have changed now...
- updateStats('postgroups', $members);
- // Do the log.
- if (!empty($log_inserts) && !empty($modSettings['modlog_enabled']))
- {
- require_once($sourcedir . '/Logging.php');
- foreach ($log_inserts as $extra)
- logAction('removed_from_group', $extra, 'admin');
- }
- // Mission successful.
- return true;
- }
- /**
- * Add one or more members to a membergroup
- *
- * Requires the manage_membergroups permission.
- * Function has protection against adding members to implicit groups.
- * Non-admins are not able to add members to the admin group.
- *
- * @param string|array $members
- * @param int $group
- * @param string $type = 'auto' specifies whether the group is added as primary or as additional group.
- * Supported types:
- * - only_primary - Assigns a membergroup as primary membergroup, but only
- * if a member has not yet a primary membergroup assigned,
- * unless the member is already part of the membergroup.
- * - only_additional - Assigns a membergroup to the additional membergroups,
- * unless the member is already part of the membergroup.
- * - force_primary - Assigns a membergroup as primary membergroup no matter
- * what the previous primary membergroup was.
- * - auto - Assigns a membergroup to the primary group if it's still
- * available. If not, assign it to the additional group.
- * @param bool $permissionCheckDone
- * @return bool success or failure
- */
- function addMembersToGroup($members, $group, $type = 'auto', $permissionCheckDone = false)
- {
- global $smcFunc, $user_info, $modSettings, $sourcedir;
- // Show your licence, but only if it hasn't been done yet.
- if (!$permissionCheckDone)
- isAllowedTo('manage_membergroups');
- // Make sure we don't keep old stuff cached.
- updateSettings(array('settings_updated' => time()));
- if (!is_array($members))
- $members = array((int) $members);
- else
- {
- $members = array_unique($members);
- // Make sure all members are integer.
- foreach ($members as $key => $value)
- $members[$key] = (int) $value;
- }
- $group = (int) $group;
- // Some groups just don't like explicitly having members.
- $implicitGroups = array(-1, 0, 3);
- $request = $smcFunc['db_query']('', '
- SELECT id_group, group_name, min_posts
- FROM {db_prefix}membergroups
- WHERE id_group = {int:current_group}',
- array(
- 'current_group' => $group,
- )
- );
- $group_names = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- if ($row['min_posts'] != -1)
- $implicitGroups[] = $row['id_group'];
- else
- $group_names[$row['id_group']] = $row['group_name'];
- }
- $smcFunc['db_free_result']($request);
- // Sorry, you can't join an implicit group.
- if (in_array($group, $implicitGroups) || empty($members))
- return false;
- // Only admins can add admins...
- if (!allowedTo('admin_forum') && $group == 1)
- return false;
- // ... and assign protected groups!
- elseif (!allowedTo('admin_forum'))
- {
- $request = $smcFunc['db_query']('', '
- SELECT group_type
- FROM {db_prefix}membergroups
- WHERE id_group = {int:current_group}
- LIMIT {int:limit}',
- array(
- 'current_group' => $group,
- 'limit' => 1,
- )
- );
- list ($is_protected) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- // Is it protected?
- if ($is_protected == 1)
- return false;
- }
- // Do the actual updates.
- if ($type == 'only_additional')
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}members
- SET additional_groups = CASE WHEN additional_groups = {string:blank_string} THEN {string:id_group_string} ELSE CONCAT(additional_groups, {string:id_group_string_extend}) END
- WHERE id_member IN ({array_int:member_list})
- AND id_group != {int:id_group}
- AND FIND_IN_SET({int:id_group}, additional_groups) = 0',
- array(
- 'member_list' => $members,
- 'id_group' => $group,
- 'id_group_string' => (string) $group,
- 'id_group_string_extend' => ',' . $group,
- 'blank_string' => '',
- )
- );
- elseif ($type == 'only_primary' || $type == 'force_primary')
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}members
- SET id_group = {int:id_group}
- WHERE id_member IN ({array_int:member_list})' . ($type == 'force_primary' ? '' : '
- AND id_group = {int:regular_group}
- AND FIND_IN_SET({int:id_group}, additional_groups) = 0'),
- array(
- 'member_list' => $members,
- 'id_group' => $group,
- 'regular_group' => 0,
- )
- );
- elseif ($type == 'auto')
- $smcFunc['db_query']('', '
- UPDATE {db_prefix}members
- SET
- id_group = CASE WHEN id_group = {int:regular_group} THEN {int:id_group} ELSE id_group END,
- additional_groups = CASE WHEN id_group = {int:id_group} THEN additional_groups
- WHEN additional_groups = {string:blank_string} THEN {string:id_group_string}
- ELSE CONCAT(additional_groups, {string:id_group_string_extend}) END
- WHERE id_member IN ({array_int:member_list})
- AND id_group != {int:id_group}
- AND FIND_IN_SET({int:id_group}, additional_groups) = 0',
- array(
- 'member_list' => $members,
- 'regular_group' => 0,
- 'id_group' => $group,
- 'blank_string' => '',
- 'id_group_string' => (string) $group,
- 'id_group_string_extend' => ',' . $group,
- )
- );
- // Ack!!? What happened?
- else
- trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING);
- // Update their postgroup statistics.
- updateStats('postgroups', $members);
- // Log the data.
- $log_inserts = array();
- require_once($sourcedir . '/Logging.php');
- foreach ($members as $member)
- logAction('added_to_group', array('group' => $group_names[$group], 'member' => $member), 'admin');
- call_integration_hook('integrate_add_members_to_group', array($log_inserts));
- return true;
- }
- /**
- *
- * @param array &$members
- * @param int $membergroup
- * @param int $limit = null
- * @return bool
- */
- function listMembergroupMembers_Href(&$members, $membergroup, $limit = null)
- {
- global $scripturl, $txt, $smcFunc;
- $request = $smcFunc['db_query']('', '
- SELECT id_member, real_name
- FROM {db_prefix}members
- WHERE id_group = {int:id_group} OR FIND_IN_SET({int:id_group}, additional_groups) != 0' . ($limit === null ? '' : '
- LIMIT ' . ($limit + 1)),
- array(
- 'id_group' => $membergroup,
- )
- );
- $members = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
- $smcFunc['db_free_result']($request);
- // If there are more than $limit members, add a 'more' link.
- if ($limit !== null && count($members) > $limit)
- {
- array_pop($members);
- return true;
- }
- else
- return false;
- }
- // Retrieve a list of (visible) membergroups used by the cache.
- function cache_getMembergroupList()
- {
- global $scripturl, $smcFunc;
- $request = $smcFunc['db_query']('', '
- SELECT id_group, group_name, online_color
- FROM {db_prefix}membergroups
- WHERE min_posts = {int:min_posts}
- AND hidden = {int:not_hidden}
- AND id_group != {int:mod_group}
- AND online_color != {string:blank_string}
- ORDER BY group_name',
- array(
- 'min_posts' => -1,
- 'not_hidden' => 0,
- 'mod_group' => 3,
- 'blank_string' => '',
- )
- );
- $groupCache = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
- $smcFunc['db_free_result']($request);
- return array(
- 'data' => $groupCache,
- 'expires' => time() + 3600,
- 'refresh_eval' => 'return $GLOBALS[\'modSettings\'][\'settings_updated\'] > ' . time() . ';',
- );
- }
- function list_getMembergroups($start, $items_per_page, $sort, $membergroup_type)
- {
- global $txt, $scripturl, $context, $settings, $smcFunc;
- $groups = array();
- // Get the basic group data.
- $request = $smcFunc['db_query']('substring_membergroups', '
- SELECT id_group, group_name, min_posts, online_color, stars, 0 AS num_members
- FROM {db_prefix}membergroups
- WHERE min_posts ' . ($membergroup_type === 'post_count' ? '!=' : '=') . ' -1' . (allowedTo('admin_forum') ? '' : '
- AND group_type != {int:is_protected}') . '
- ORDER BY {raw:sort}',
- array(
- 'is_protected' => 1,
- 'sort' => $sort,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $groups[$row['id_group']] = array(
- 'id_group' => $row['id_group'],
- 'group_name' => $row['group_name'],
- 'min_posts' => $row['min_posts'],
- 'online_color' => $row['online_color'],
- 'stars' => $row['stars'],
- 'num_members' => $row['num_members'],
- );
- $smcFunc['db_free_result']($request);
- // If we found any membergroups, get the amount of members in them.
- if (!empty($groups))
- {
- if ($membergroup_type === 'post_count')
- {
- $query = $smcFunc['db_query']('', '
- SELECT id_post_group AS id_group, COUNT(*) AS num_members
- FROM {db_prefix}members
- WHERE id_post_group IN ({array_int:group_list})
- GROUP BY id_post_group',
- array(
- 'group_list' => array_keys($groups),
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($query))
- $groups[$row['id_group']]['num_members'] += $row['num_members'];
- $smcFunc['db_free_result']($query);
- }
- else
- {
- $query = $smcFunc['db_query']('', '
- SELECT id_group, COUNT(*) AS num_members
- FROM {db_prefix}members
- WHERE id_group IN ({array_int:group_list})
- GROUP BY id_group',
- array(
- 'group_list' => array_keys($groups),
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($query))
- $groups[$row['id_group']]['num_members'] += $row['num_members'];
- $smcFunc['db_free_result']($query);
- $query = $smcFunc['db_query']('', '
- SELECT mg.id_group, COUNT(*) AS num_members
- FROM {db_prefix}membergroups AS mg
- INNER JOIN {db_prefix}members AS mem ON (mem.additional_groups != {string:blank_string}
- AND mem.id_group != mg.id_group
- AND FIND_IN_SET(mg.id_group, mem.additional_groups) != 0)
- WHERE mg.id_group IN ({array_int:group_list})
- GROUP BY mg.id_group',
- array(
- 'group_list' => array_keys($groups),
- 'blank_string' => '',
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($query))
- $groups[$row['id_group']]['num_members'] += $row['num_members'];
- $smcFunc['db_free_result']($query);
- }
- }
- // Apply manual sorting if the 'number of members' column is selected.
- if (substr($sort, 0, 1) == '1' || strpos($sort, ', 1') !== false)
- {
- $sort_ascending = strpos($sort, 'DESC') === false;
- foreach ($groups as $group)
- $sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1;
- array_multisort($sort_array, $sort_ascending ? SORT_ASC : SORT_DESC, SORT_REGULAR, $groups);
- }
- return $groups;
- }
- ?>
|