Esempio n. 1
0
/**
 * Removes a subscription from a user, as in removes the groups.
 *
 * @param int $id_subscribe
 * @param int $id_member
 * @param boolean $delete
 */
function removeSubscription($id_subscribe, $id_member, $delete = false)
{
    global $context;
    $db = database();
    loadSubscriptions();
    // Load the user core bits.
    require_once SUBSDIR . '/Members.subs.php';
    $member_info = getBasicMemberData($id_member, array('moderation' => true));
    // Just in case of errors.
    if (empty($member_info)) {
        $db->query('', '
			DELETE FROM {db_prefix}log_subscribed
			WHERE id_member = {int:current_member}', array('current_member' => $id_member));
        return;
    }
    // Get all of the subscriptions for this user that are active - it will be necessary!
    $request = $db->query('', '
		SELECT
			id_subscribe, old_id_group
		FROM {db_prefix}log_subscribed
		WHERE id_member = {int:current_member}
			AND status = {int:is_active}', array('current_member' => $id_member, 'is_active' => 1));
    // These variables will be handy, honest ;)
    $removals = array();
    $allowed = array();
    $member = array();
    $member['id_group'] = 0;
    $new_id_group = -1;
    while ($row = $db->fetch_assoc($request)) {
        if (!isset($context['subscriptions'][$row['id_subscribe']])) {
            continue;
        }
        // The one we're removing?
        if ($row['id_subscribe'] == $id_subscribe) {
            $removals = explode(',', $context['subscriptions'][$row['id_subscribe']]['add_groups']);
            if ($context['subscriptions'][$row['id_subscribe']]['prim_group'] != 0) {
                $removals[] = $context['subscriptions'][$row['id_subscribe']]['prim_group'];
            }
            $member['id_group'] = $row['old_id_group'];
        } else {
            $allowed = array_merge($allowed, explode(',', $context['subscriptions'][$row['id_subscribe']]['add_groups']));
            if ($context['subscriptions'][$row['id_subscribe']]['prim_group'] != 0) {
                $allowed[] = $context['subscriptions'][$row['id_subscribe']]['prim_group'];
                $new_id_group = $context['subscriptions'][$row['id_subscribe']]['prim_group'];
            }
        }
    }
    $db->free_result($request);
    // Now, for everything we are removing check they defintely are not allowed it.
    $existingGroups = explode(',', $member_info['additional_groups']);
    foreach ($existingGroups as $key => $group) {
        if (empty($group) || in_array($group, $removals) && !in_array($group, $allowed)) {
            unset($existingGroups[$key]);
        }
    }
    // Finally, do something with the current primary group.
    if (in_array($member_info['id_group'], $removals)) {
        // If this primary group is actually allowed keep it.
        if (in_array($member_info['id_group'], $allowed)) {
            $existingGroups[] = $member_info['id_group'];
        }
        // Either way, change the id_group back.
        if ($new_id_group < 1) {
            // If we revert to the old id-group we need to ensure it wasn't from a subscription.
            foreach ($context['subscriptions'] as $id => $group) {
                // It was? Make them a regular member then!
                if ($group['prim_group'] == $member['id_group']) {
                    $member['id_group'] = 0;
                }
            }
            $member_info['id_group'] = $member['id_group'];
        } else {
            $member_info['id_group'] = $new_id_group;
        }
    }
    // Crazy stuff, we seem to have our groups fixed, just make them unique
    $existingGroups = array_unique($existingGroups);
    // Update the member
    assignGroupsToMember($id_member, $member_info['id_group'], $existingGroups);
    // Disable the subscription.
    if (!$delete) {
        $db->query('', '
			UPDATE {db_prefix}log_subscribed
			SET status = {int:not_active}
			WHERE id_member = {int:current_member}
				AND id_subscribe = {int:current_subscription}', array('not_active' => 0, 'current_member' => $id_member, 'current_subscription' => $id_subscribe));
    } else {
        $db->query('', '
			DELETE FROM {db_prefix}log_subscribed
			WHERE id_member = {int:current_member}
				AND id_subscribe = {int:current_subscription}', array('current_member' => $id_member, 'current_subscription' => $id_subscribe));
    }
}
Esempio n. 2
0
    /**
     * Show and manage all group requests.
     */
    public function action_requests()
    {
        global $txt, $context, $scripturl, $user_info, $modSettings;
        // Set up the template stuff...
        $context['page_title'] = $txt['mc_group_requests'];
        $context['sub_template'] = 'show_list';
        $context[$context['moderation_menu_name']]['tab_data'] = array('title' => $txt['mc_group_requests']);
        // Verify we can be here.
        if ($user_info['mod_cache']['gq'] == '0=1') {
            isAllowedTo('manage_membergroups');
        }
        // Normally, we act normally...
        $where = $user_info['mod_cache']['gq'] == '1=1' || $user_info['mod_cache']['gq'] == '0=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq'];
        $where_parameters = array();
        // We've submitted?
        if (isset($_POST[$context['session_var']]) && !empty($_POST['groupr']) && !empty($_POST['req_action'])) {
            checkSession('post');
            validateToken('mod-gr');
            require_once SUBSDIR . '/Membergroups.subs.php';
            // Clean the values.
            foreach ($_POST['groupr'] as $k => $request) {
                $_POST['groupr'][$k] = (int) $request;
            }
            // If we are giving a reason (And why shouldn't we?), then we don't actually do much.
            if ($_POST['req_action'] == 'reason') {
                // Different sub template...
                $context['sub_template'] = 'group_request_reason';
                // And a limitation. We don't care that the page number bit makes no sense, as we don't need it!
                $where .= ' AND lgr.id_request IN ({array_int:request_ids})';
                $where_parameters['request_ids'] = $_POST['groupr'];
                $context['group_requests'] = list_getGroupRequests(0, $modSettings['defaultMaxMessages'], 'lgr.id_request', $where, $where_parameters);
                createToken('mod-gr');
                // Let obExit etc sort things out.
                obExit();
            } else {
                // Get the details of all the members concerned...
                require_once SUBSDIR . '/Members.subs.php';
                $concerned = getConcernedMembers($_POST['groupr'], $where);
                // Cleanup old group requests..
                deleteGroupRequests($_POST['groupr']);
                // Ensure everyone who is online gets their changes right away.
                updateSettings(array('settings_updated' => time()));
                if (!empty($concerned['email_details'])) {
                    require_once SUBSDIR . '/Mail.subs.php';
                    // They are being approved?
                    if ($_POST['req_action'] == 'approve') {
                        // Make the group changes.
                        foreach ($concerned['group_changes'] as $id => $groups) {
                            // Sanity check!
                            foreach ($groups['add'] as $key => $value) {
                                if ($value == 0 || trim($value) == '') {
                                    unset($groups['add'][$key]);
                                }
                            }
                            assignGroupsToMember($id, $groups['primary'], $groups['add']);
                        }
                        foreach ($concerned['email_details'] as $email) {
                            $replacements = array('USERNAME' => $email['member_name'], 'GROUPNAME' => $email['group_name']);
                            $emaildata = loadEmailTemplate('mc_group_approve', $replacements, $email['language']);
                            sendmail($email['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 2);
                        }
                    } else {
                        // Same as for approving, kind of.
                        foreach ($concerned['email_details'] as $email) {
                            $custom_reason = isset($_POST['groupreason']) && isset($_POST['groupreason'][$email['rid']]) ? $_POST['groupreason'][$email['rid']] : '';
                            $replacements = array('USERNAME' => $email['member_name'], 'GROUPNAME' => $email['group_name']);
                            if (!empty($custom_reason)) {
                                $replacements['REASON'] = $custom_reason;
                            }
                            $emaildata = loadEmailTemplate(empty($custom_reason) ? 'mc_group_reject' : 'mc_group_reject_reason', $replacements, $email['language']);
                            sendmail($email['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 2);
                        }
                    }
                }
                // Restore the current language.
                loadLanguage('ModerationCenter');
            }
        }
        // We're going to want this for making our list.
        require_once SUBSDIR . '/GenericList.class.php';
        require_once SUBSDIR . '/Membergroups.subs.php';
        // This is all the information required for a group listing.
        $listOptions = array('id' => 'group_request_list', 'width' => '100%', 'items_per_page' => $modSettings['defaultMaxMessages'], 'no_items_label' => $txt['mc_groupr_none_found'], 'base_href' => $scripturl . '?action=groups;sa=requests', 'default_sort_col' => 'member', 'get_items' => array('function' => 'list_getGroupRequests', 'params' => array($where, $where_parameters)), 'get_count' => array('function' => 'list_getGroupRequestCount', 'params' => array($where, $where_parameters)), 'columns' => array('member' => array('header' => array('value' => $txt['mc_groupr_member']), 'data' => array('db' => 'member_link'), 'sort' => array('default' => 'mem.member_name', 'reverse' => 'mem.member_name DESC')), 'group' => array('header' => array('value' => $txt['mc_groupr_group']), 'data' => array('db' => 'group_link'), 'sort' => array('default' => 'mg.group_name', 'reverse' => 'mg.group_name DESC')), 'reason' => array('header' => array('value' => $txt['mc_groupr_reason']), 'data' => array('db' => 'reason')), 'date' => array('header' => array('value' => $txt['date'], 'style' => 'width: 18%; white-space:nowrap;'), 'data' => array('db' => 'time_submitted')), 'action' => array('header' => array('value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);" />', 'style' => 'width: 4%;text-align: center;'), 'data' => array('sprintf' => array('format' => '<input type="checkbox" name="groupr[]" value="%1$d" class="input_check" />', 'params' => array('id' => false)), 'class' => 'centertext'))), 'form' => array('href' => $scripturl . '?action=groups;sa=requests', 'include_sort' => true, 'include_start' => true, 'hidden_fields' => array($context['session_var'] => $context['session_id']), 'token' => 'mod-gr'), 'additional_rows' => array(array('position' => 'bottom_of_list', 'value' => '
						<select name="req_action" onchange="if (this.value != 0 &amp;&amp; (this.value == \'reason\' || confirm(\'' . $txt['mc_groupr_warning'] . '\'))) this.form.submit();">
							<option value="0">' . $txt['with_selected'] . ':</option>
							<option value="0" disabled="disabled">' . str_repeat('&#8212;', strlen($txt['mc_groupr_approve'])) . '</option>
							<option value="approve">' . (isBrowser('ie8') ? '&#187;' : '&#10148;') . '&nbsp;' . $txt['mc_groupr_approve'] . '</option>
							<option value="reject">' . (isBrowser('ie8') ? '&#187;' : '&#10148;') . '&nbsp;' . $txt['mc_groupr_reject'] . '</option>
							<option value="reason">' . (isBrowser('ie8') ? '&#187;' : '&#10148;') . '&nbsp;' . $txt['mc_groupr_reject_w_reason'] . '</option>
						</select>
						<input type="submit" name="go" value="' . $txt['go'] . '" onclick="var sel = document.getElementById(\'req_action\'); if (sel.value != 0 &amp;&amp; sel.value != \'reason\' &amp;&amp; !confirm(\'' . $txt['mc_groupr_warning'] . '\')) return false;" class="right_submit" />', 'class' => 'floatright')));
        // Create the request list.
        createToken('mod-gr');
        createList($listOptions);
        $context['default_list'] = 'group_request_list';
    }