Beispiel #1
0
	})
	</script>
<?php 
    die;
}
if ($action == 'update-nonmemberships') {
    if (empty($userid)) {
        die;
    }
    global $spThisUser;
    $usergroups = spdb_table(SFUSERGROUPS, '', '', '', '', ARRAY_A);
    if ($usergroups && ($spThisUser->ID != $userid || !$spThisUser->admin)) {
        $alt = 'spOdd';
        $first = true;
        foreach ($usergroups as $userGroup) {
            if (!sp_check_membership($userGroup['usergroup_id'], $userid) && ($userGroup['usergroup_join'] == 1 || $spThisUser->admin)) {
                $submit = true;
                if ($first) {
                    echo '<div class="spProfileUsergroupsNonMemberships">';
                    echo '<p class="spHeaderName">' . sp_text('Non-Memberships') . ':</p>';
                    $first = false;
                }
                echo "<div class='spProfileUsergroup {$alt}'>";
                echo '<div class="spColumnSection">';
                echo '<div class="spHeaderName">' . $userGroup['usergroup_name'] . '</div>';
                echo '<div class="spHeaderDescription">' . $userGroup['usergroup_desc'] . '</div>';
                echo '</div>';
                echo '<div class="spColumnSection spProfileMembershipsJoin">';
                echo '<div class="spInRowLabel">';
                echo '<input type="checkbox" name="usergroup_join[]" id="sfusergroup_join_' . $userGroup['usergroup_id'] . '" value="' . $userGroup['usergroup_id'] . '" />';
                echo '<label for="sfusergroup_join_' . $userGroup['usergroup_id'] . '">' . sp_text('Join Usergroup') . '</label>';
function sp_add_membership($usergroup_id, $user_id)
{
    # make sure we have valid membership to set
    if (empty($usergroup_id) || empty($user_id)) {
        return false;
    }
    # dont allow admins to be added to user groups
    if (sp_is_forum_admin($user_id)) {
        return false;
    }
    $success = false;
    # if only one membership allowed, remove all current memberships
    $sfmemberopts = sp_get_option('sfmemberopts');
    if (isset($sfmemberopts['sfsinglemembership']) && $sfmemberopts['sfsinglemembership']) {
        spdb_query('DELETE FROM ' . SFMEMBERSHIPS . " WHERE user_id={$user_id}");
    }
    # dont add membership if it already exists
    $check = sp_check_membership($usergroup_id, $user_id);
    if (empty($check)) {
        $sql = 'INSERT INTO ' . SFMEMBERSHIPS . ' (user_id, usergroup_id) ';
        $sql .= "VALUES ('{$user_id}', '{$usergroup_id}');";
        $success = spdb_query($sql);
        # reset auths and memberships for added user
        sp_reset_memberships($user_id);
        sp_reset_auths($user_id);
        sp_update_member_moderator_flag($user_id);
    }
    return $success;
}