Exemplo n.º 1
0
 /**
  * The main entrance point for the Manage Members screen.
  *
  * What it does:
  * - As everyone else, it calls a function based on the given sub-action.
  * - Called by ?action=admin;area=viewmembers.
  * - Requires the moderate_forum permission.
  *
  * @uses ManageMembers template
  * @uses ManageMembers language file.
  * @see Action_Controller::action_index()
  */
 public function action_index()
 {
     global $txt, $scripturl, $context, $modSettings;
     // Load the essentials.
     loadLanguage('ManageMembers');
     loadTemplate('ManageMembers');
     $subActions = array('all' => array('controller' => $this, 'function' => 'action_list', 'permission' => 'moderate_forum'), 'approve' => array('controller' => $this, 'function' => 'action_approve', 'permission' => 'moderate_forum'), 'browse' => array('controller' => $this, 'function' => 'action_browse', 'permission' => 'moderate_forum'), 'search' => array('controller' => $this, 'function' => 'action_search', 'permission' => 'moderate_forum'), 'query' => array('controller' => $this, 'function' => 'action_list', 'permission' => 'moderate_forum'));
     // Prepare our action control
     $action = new Action();
     // Default to sub action 'all', needed for the tabs array below
     $subAction = $action->initialize($subActions, 'all');
     // You can't pass!
     $action->isAllowedTo($subAction);
     // Get counts on every type of activation - for sections and filtering alike.
     require_once SUBSDIR . '/Members.subs.php';
     $context['awaiting_activation'] = 0;
     $context['awaiting_approval'] = 0;
     $context['activation_numbers'] = countInactiveMembers();
     foreach ($context['activation_numbers'] as $activation_type => $total_members) {
         if (in_array($activation_type, array(0, 2))) {
             $context['awaiting_activation'] += $total_members;
         } elseif (in_array($activation_type, array(3, 4, 5))) {
             $context['awaiting_approval'] += $total_members;
         }
     }
     // For the page header... do we show activation?
     $context['show_activate'] = !empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 || !empty($context['awaiting_activation']);
     // What about approval?
     $context['show_approve'] = !empty($modSettings['registration_method']) && $modSettings['registration_method'] == 2 || !empty($context['awaiting_approval']) || !empty($modSettings['approveAccountDeletion']);
     // Setup the admin tabs.
     $context[$context['admin_menu_name']]['tab_data'] = array('title' => $txt['admin_members'], 'help' => 'view_members', 'description' => $txt['admin_members_list'], 'tabs' => array());
     $context['tabs'] = array('viewmembers' => array('label' => $txt['view_all_members'], 'description' => $txt['admin_members_list'], 'url' => $scripturl . '?action=admin;area=viewmembers;sa=all', 'is_selected' => $subAction == 'all'), 'search' => array('label' => $txt['mlist_search'], 'description' => $txt['admin_members_list'], 'url' => $scripturl . '?action=admin;area=viewmembers;sa=search', 'is_selected' => $subAction == 'search' || $subAction == 'query'), 'approve' => array('label' => sprintf($txt['admin_browse_awaiting_approval'], $context['awaiting_approval']), 'description' => $txt['admin_browse_approve_desc'], 'url' => $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve', 'is_selected' => false), 'activate' => array('label' => sprintf($txt['admin_browse_awaiting_activate'], $context['awaiting_activation']), 'description' => $txt['admin_browse_activate_desc'], 'url' => $scripturl . '?action=admin;area=viewmembers;sa=browse;type=activate', 'is_selected' => false, 'is_last' => true));
     // Call integrate_manage_members
     call_integration_hook('integrate_manage_members', array(&$subActions));
     // Sort out the tabs for the ones which may not exist!
     if (!$context['show_activate'] && ($subAction != 'browse' || $_REQUEST['type'] != 'activate')) {
         $context['tabs']['approve']['is_last'] = true;
         unset($context['tabs']['activate']);
     }
     // Unset approval tab if it shouldn't be there.
     if (!$context['show_approve'] && ($subAction != 'browse' || $_REQUEST['type'] != 'approve')) {
         if (!$context['show_activate'] && ($subAction != 'browse' || $_REQUEST['type'] != 'activate')) {
             $context['tabs']['search']['is_last'] = true;
         }
         unset($context['tabs']['approve']);
     }
     // Last items for the template
     $context['page_title'] = $txt['admin_members'];
     $context['sub_action'] = $subAction;
     // Off we go
     $action->dispatch($subAction);
 }
Exemplo n.º 2
0
/**
 * Loads the number of items awaiting moderation attention
 *  - Only loads the value a given permission level can see
 *  - If supplied a board number will load the values only for that board
 *  - Unapproved posts
 *  - Unapproved topics
 *  - Unapproved attachments
 *  - Failed emails
 *  - Reported posts
 *  - Members awaiting approval (activation, deletion, group requests)
 *
 * @param int|null $brd
 */
function loadModeratorMenuCounts($brd = null)
{
    global $modSettings, $user_info;
    static $menu_errors = array();
    // Work out what boards they can work in!
    $approve_boards = !empty($user_info['mod_cache']['ap']) ? $user_info['mod_cache']['ap'] : boardsAllowedTo('approve_posts');
    // Supplied a specific board to check?
    if (!empty($brd)) {
        $filter_board = array((int) $brd);
        $approve_boards = $approve_boards == array(0) ? $filter_board : array_intersect($approve_boards, $filter_board);
    }
    // Work out the query
    if ($approve_boards == array(0)) {
        $approve_query = '';
    } elseif (!empty($approve_boards)) {
        $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
    } else {
        $approve_query = ' AND 1=0';
    }
    // Set up the cache key for this permissions level
    $cache_key = md5($user_info['query_see_board'] . $approve_query . $user_info['mod_cache']['bq'] . $user_info['mod_cache']['gq'] . $user_info['mod_cache']['mq'] . (int) allowedTo('approve_emails') . '_' . (int) allowedTo('moderate_forum'));
    if (isset($menu_errors[$cache_key])) {
        return $menu_errors[$cache_key];
    }
    // If its been cached, guess what, thats right use it!
    $temp = cache_get_data('num_menu_errors', 900);
    if ($temp === null || !isset($temp[$cache_key])) {
        // Starting out with nothing is a good start
        $menu_errors[$cache_key] = array('memberreq' => 0, 'groupreq' => 0, 'attachments' => 0, 'reports' => 0, 'emailmod' => 0, 'postmod' => 0, 'topics' => 0, 'posts' => 0);
        if ($modSettings['postmod_active'] && !empty($approve_boards)) {
            $totals = recountUnapprovedPosts($approve_query);
            $menu_errors[$cache_key]['posts'] = $totals['posts'];
            $menu_errors[$cache_key]['topics'] = $totals['topics'];
            // Totals for the menu item unapproved posts and topics
            $menu_errors[$cache_key]['postmod'] = $menu_errors[$cache_key]['topics'] + $menu_errors[$cache_key]['posts'];
        }
        // Attachments
        if ($modSettings['postmod_active'] && !empty($approve_boards)) {
            require_once SUBSDIR . '/ManageAttachments.subs.php';
            $menu_errors[$cache_key]['attachments'] = list_getNumUnapprovedAttachments($approve_query);
        }
        // Reported posts
        if (!empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1') {
            $menu_errors[$cache_key]['reports'] = recountOpenReports(false);
        }
        // Email failures that require attention
        if (!empty($modSettings['maillist_enabled']) && allowedTo('approve_emails')) {
            $menu_errors[$cache_key]['emailmod'] = recountFailedEmails($approve_query);
        }
        // Group requests
        if (!empty($user_info['mod_cache']) && $user_info['mod_cache']['gq'] != '0=1') {
            $menu_errors[$cache_key]['groupreq'] = count(groupRequests());
        }
        // Member requests
        if (allowedTo('moderate_forum') && (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 2 || !empty($modSettings['approveAccountDeletion']))) {
            require_once SUBSDIR . '/Members.subs.php';
            $awaiting_activation = 0;
            $activation_numbers = countInactiveMembers();
            // 5 = COPPA, 4 = Awaiting Deletion, 3 = Awaiting Approval
            foreach ($activation_numbers as $activation_type => $total_members) {
                if (in_array($activation_type, array(3, 4, 5))) {
                    $awaiting_activation += $total_members;
                }
            }
            $menu_errors[$cache_key]['memberreq'] = $awaiting_activation;
        }
        // Grand Totals for the top most menus
        $menu_errors[$cache_key]['pt_total'] = $menu_errors[$cache_key]['emailmod'] + $menu_errors[$cache_key]['postmod'] + $menu_errors[$cache_key]['reports'] + $menu_errors[$cache_key]['attachments'];
        $menu_errors[$cache_key]['mg_total'] = $menu_errors[$cache_key]['memberreq'] + $menu_errors[$cache_key]['groupreq'];
        $menu_errors[$cache_key]['grand_total'] = $menu_errors[$cache_key]['pt_total'] + $menu_errors[$cache_key]['mg_total'];
        // Add this key in to the array, technically this resets the cache time for all keys
        // done this way as the entire thing needs to go null once *any* moderation action is taken
        $menu_errors = is_array($temp) ? array_merge($temp, $menu_errors) : $menu_errors;
        // Store it away for a while, not like this should change that often
        cache_put_data('num_menu_errors', $menu_errors, 900);
    } else {
        $menu_errors = $temp === null ? array() : $temp;
    }
    return $menu_errors[$cache_key];
}