ad_user_group_add

one of the documented procedures in this installation of the ACS
Usage:
ad_user_group_add   db   group_type   group_name   { approved_p "t" }   { existence_public_p "f" }   { new_member_policy "closed" }   { multi_role_p "f" }   { extra_values "" }   { group_id "" }
What it does:
Creates a new group. Returns: The groud_id of the group if created or it existed already (double click protection); 0 on failure.
Defined in: /web/philip/packages/acs-core/user-groups-procs.tcl

Source code:



    # PARAMETERS
    # db: database handle
    # group_type: type of group
    # group_name: pretty name
    # approved_p (optional): is this an approved group?
    # existence_public_p (optional): Is the existence of this group public?
    # new_member_policy (optional): How can members join? (wait, closed, open)
    # permission_system(optional): What type of permission system (basic, advanced)
    # extra_values (optional): A ns_set containing 
    #     extra values that should be stored for this
    #     group.  These are items that will go in the [set group_type]_info
    #     tables. The keys of the ns_set contain the column names. The values
    #     contain the values.
    # group_id (optional): Group_id. If this is null, one will be created

    
    if [empty_string_p $group_id] {
	set group_id [database_to_tcl_string $db "select user_group_sequence.nextval from dual"]
    }

    ns_db dml $db "begin transaction"

    if [catch {
	set short_name [database_to_tcl_string $db "
	select short_name_from_group_name('[DoubleApos $group_name]') from dual"]

	ns_db dml $db "
	insert into user_groups
	(group_id, group_type, group_name, short_name, approved_p, existence_public_p, new_member_policy, multi_role_p,
 	creation_user, creation_ip_address, registration_date)
	values ($group_id, '[DoubleApos $group_type]', '[DoubleApos $group_name]', '[DoubleApos $short_name]',
	'$approved_p', '$existence_public_p', '[DoubleApos $new_member_policy]', '[DoubleApos $multi_role_p]',
	[ad_get_user_id], '[DoubleApos [peeraddr]]', sysdate)"   

    } errmsg] {
	ns_db dml $db "abort transaction"
	ns_log Error "$errmsg in ad-user_groups.tcl - ad_user_group_add insertion into user groups"

	# see if this group is already defined
	
	set selection [ns_db 0or1row $db "select group_id from user_groups where group_id = $group_id"]
	if [empty_string_p $selection] {
	    return 0
	} else {
	    set_variables_after_query
	    return $group_id
	}
    }
    
    # insert the extra values
    if ![empty_string_p $extra_values] {
	set extra_values_i 0
	lappend columns group_id
	lappend values $group_id
	
	set extra_values_limit [ns_set size $extra_values]
	while {$extra_values_i < $extra_values_limit} {
	    set key [ns_set key $extra_values $extra_values_i] 
	    lappend columns $key
	    lappend values '[DoubleApos [ns_set get $extra_values $key]]'
	    incr extra_values_i
	}
	if [catch {
	    ns_db dml $db "insert into [set group_type]_info ([join $columns ","]) values ([join $values ","])"
	} errmsg] {
	    # There was an error inserting the extra information (most likely to this is an administration group
	    # and the module and submodule are already there)
	    ns_db dml $db "abort transaction"
	    ns_log Error "$errmsg in ad-user_groups.tcl - ad_user_group_add extra values insertion"
	    return 0
	}
    }

    ns_db dml $db "end transaction"

    return $group_id


philg@mit.edu