protected function populateGroupList($selected_groups) { global $txt; require_once SUBSDIR . '/Membergroups.subs.php'; loadTemplate('GenericHelpers'); // We need group data, including which groups we have and who is in them $allgroups = getBasicMembergroupData(array('all'), array(), null, true); $groups = $allgroups['groups']; $groups[-1] = array('id' => -1, 'name' => $txt['guests'], 'member_count' => 0); ksort($groups); // All of the members in post based and member based groups $pg = array(); foreach ($allgroups['postgroups'] as $postgroup) { $pg[] = $postgroup['id']; } $mg = array(); foreach ($allgroups['membergroups'] as $membergroup) { $mg[] = $membergroup['id']; } // How many are in each group $mem_groups = membersInGroups($pg, $mg, true, true); foreach ($mem_groups as $id_group => $member_count) { if (isset($groups[$id_group]['member_count'])) { $groups[$id_group]['member_count'] += $member_count; } else { $groups[$id_group]['member_count'] = $member_count; } } foreach ($groups as $group) { $groups[$group['id']]['status'] = in_array($group['id'], $selected_groups) ? 'on' : 'off'; $groups[$group['id']]['is_postgroup'] = in_array($group['id'], $pg); } return array('select_group' => $txt['dismissnotices_groups_show_notice'], 'member_groups' => $groups); }
/** * This function allows a user to select the membergroups to send their mailing to. * * What it does: * - Called by ?action=admin;area=news;sa=mailingmembers. * - Requires the send_mail permission. * - Form is submitted to ?action=admin;area=news;mailingcompose. * * @uses the ManageNews template and email_members sub template. */ public function action_mailingmembers() { global $txt, $context; require_once SUBSDIR . '/Membergroups.subs.php'; require_once SUBSDIR . '/News.subs.php'; // Setup the template $context['page_title'] = $txt['admin_newsletters']; $context['sub_template'] = 'email_members'; loadJavascriptFile('suggest.js', array('defer' => true)); // We need group data, including which groups we have and who is in them $allgroups = getBasicMembergroupData(array('all'), array(), null, true); $groups = $allgroups['groups']; // All of the members in post based and member based groups $pg = array(); foreach ($allgroups['postgroups'] as $postgroup) { $pg[] = $postgroup['id']; } $mg = array(); foreach ($allgroups['membergroups'] as $membergroup) { $mg[] = $membergroup['id']; } // How many are in each group $mem_groups = membersInGroups($pg, $mg, true, true); foreach ($mem_groups as $id_group => $member_count) { if (isset($groups[$id_group]['member_count'])) { $groups[$id_group]['member_count'] += $member_count; } else { $groups[$id_group]['member_count'] = $member_count; } } // Generate the include and exclude group select lists for the template foreach ($groups as $group) { $groups[$group['id']]['status'] = 'on'; $groups[$group['id']]['is_postgroup'] = in_array($group['id'], $pg); } $context['groups'] = array('select_group' => $txt['admin_newsletters_select_groups'], 'member_groups' => $groups); foreach ($groups as $group) { $groups[$group['id']]['status'] = 'off'; } $context['exclude_groups'] = array('select_group' => $txt['admin_newsletters_exclude_groups'], 'member_groups' => $groups); // Needed if for the PM option in the mail to all $context['can_send_pm'] = allowedTo('pm_send'); }
/** * Helper function to generate a list of membergroups for display. * * @package Membergroups * @param int $start not used * @param int $items_per_page not used * @param string $sort * @param string $membergroup_type * @param int $user_id * @param bool $include_hidden * @param bool $include_all * @param bool $aggregate * @param bool $count_permissions * @param int|null $pid - profile id */ function list_getMembergroups($start, $items_per_page, $sort, $membergroup_type, $user_id, $include_hidden, $include_all = false, $aggregate = false, $count_permissions = false, $pid = null) { global $scripturl, $txt, $context; $db = database(); $request = $db->query('', ' SELECT mg.id_group, mg.group_name, mg.min_posts, mg.description, mg.group_type, mg.online_color, mg.hidden, mg.id_parent, mg.icons, IFNULL(gm.id_member, 0) AS can_moderate, 0 AS num_members FROM {db_prefix}membergroups AS mg LEFT JOIN {db_prefix}group_moderators AS gm ON (gm.id_group = mg.id_group AND gm.id_member = {int:current_member}) WHERE mg.min_posts {raw:min_posts}' . ($include_all ? '' : ' AND mg.id_group != {int:mod_group} AND mg.group_type != {int:is_protected}') . ' ORDER BY {raw:sort}', array('current_member' => $user_id, 'min_posts' => $membergroup_type === 'post_count' ? '!= -1' : '= -1', 'mod_group' => 3, 'is_protected' => 1, 'sort' => $sort)); // Start collecting the data. $groups = array(); $group_ids = array(); if ($membergroup_type === 'all') { // Determine the number of ungrouped members. $num_members = countMembersInGroup(0); // Fill the context variable with 'Guests' and 'Regular Members'. $groups = array(-1 => array('id_group' => -1, 'group_name' => $txt['membergroups_guests'], 'group_name_color' => $txt['membergroups_guests'], 'min_posts' => 0, 'desc' => '', 'num_members' => $txt['membergroups_guests_na'], 'icons' => '', 'can_search' => false, 'num_permissions' => array('allowed' => 0, 'denied' => 0)), 0 => array('id_group' => 0, 'group_name' => $txt['membergroups_members'], 'group_name_color' => $txt['membergroups_members'], 'min_posts' => 0, 'desc' => '', 'num_members' => $num_members, 'icons' => '', 'can_search' => true, 'num_permissions' => array('allowed' => 0, 'denied' => 0))); } while ($row = $db->fetch_assoc($request)) { // We only list the groups they can see. if ($row['hidden'] && !$row['can_moderate'] && !$include_hidden) { continue; } // If it's inherited, just add it as a child. if ($aggregate && $row['id_parent'] != -2) { if (isset($groups[$row['id_parent']])) { $groups[$row['id_parent']]['children'][$row['id_group']] = $row['group_name']; } continue; } $row['icons'] = explode('#', $row['icons']); $groups[$row['id_group']] = array('id_group' => $row['id_group'], 'group_name' => $row['group_name'], 'group_name_color' => empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>', 'min_posts' => $row['min_posts'], 'desc' => $row['description'], 'online_color' => $row['online_color'], 'type' => $row['group_type'], 'num_members' => $row['num_members'], 'moderators' => array(), 'icons' => $row['icons'], 'can_search' => $row['id_group'] != 3); if ($count_permissions) { $groups[$row['id_group']]['num_permissions'] = array('allowed' => $row['id_group'] == 1 ? '(' . $txt['permissions_all'] . ')' : 0, 'denied' => $row['id_group'] == 1 ? '(' . $txt['permissions_none'] . ')' : 0); } $include_hidden |= $row['can_moderate']; $group_ids[] = $row['id_group']; } $db->free_result($request); // If we found any membergroups, get the amount of members in them. if (!empty($group_ids)) { if ($membergroup_type === 'post_count') { $groups_count = membersInGroups($group_ids); } else { $groups_count = membersInGroups(array(), $group_ids, $include_hidden); } // @todo not sure why += wouldn't = be enough? foreach ($groups_count as $group_id => $num_members) { $groups[$group_id]['num_members'] += $num_members; } $query = $db->query('', ' SELECT mods.id_group, mods.id_member, mem.member_name, 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 IN ({array_int:group_list})', array('group_list' => $group_ids)); while ($row = $db->fetch_assoc($query)) { $groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; } $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; $sort_array = array(); 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); } if ($count_permissions) { // pid = profile id if (empty($pid)) { $groups = countPermissions($groups, $context['hidden_permissions']); // Get the "default" profile permissions too. $groups = countBoardPermissions($groups, $context['hidden_permissions'], 1); } else { $groups = countBoardPermissions($groups, null, $pid); } } return $groups; }