ad_scope_error_check { default_scope "public" }What it does:
this procedure does scope error checking. if scope is not set in topmost environment, then the scope will be set to the value of default_scope. if scope=group this procedure will check whether group_id is provided and if not it will return error to the user. if scope=table and on_which_table or on_what_id are not provided this procedure will return error to the user. if everything went fine this procedure returns 1. if scope=group and the group_vars_set is not set in the topmost environment, then this procedure will set group_vars_set variables corresponding to the group_id. if scope=user and user_id is not provided, then user_id will be set to the user_id of the visitor if visitor is logged in, otherwise error will be returned to the user.Defined in: /web/philip/tcl/ad-scope.tcl
Source code:
if { [uplevel [ad_scope_upvar_level] {info exists scope}] } {
upvar [ad_scope_upvar_level] scope scope
} else {
set scope $default_scope
# create scope in topmost environment and give it initial value of 0
uplevel [ad_scope_upvar_level] { set scope 0 }
upvar [ad_scope_upvar_level] scope new_scope
# set scope in the topmost environment to the value of default_scope
set new_scope $default_scope
}
switch $scope {
public {
return 1
}
group {
if { ![uplevel [ad_scope_upvar_level] {info exists group_id}] } {
ad_return_error "Error: group_id not supplied" "<ul><li>group_id must be supplied in order to access this page.</ul>"
ad_script_abort
} else {
upvar [ad_scope_upvar_level] group_id group_id
# in the case group_vars_set was not provided, put default values to this set
if { ![uplevel [ad_scope_upvar_level] {info exists group_vars_set}] } {
set db [ns_db gethandle subquery]
set selection [ns_db 0or1row $db "
select group_name, short_name, admin_email from user_groups where group_id=$group_id"]
ns_db releasehandle $db
if { [empty_string_p $selection] } {
# Invalid group id provided
ad_return_error "Error: invalid group_id not supplied" "<ul><li>The specified group_id, #$group_id, does not exist</ul>"
ad_script_abort
}
set_variables_after_query
uplevel [ad_scope_upvar_level] { set group_vars_set [ns_set create] }
upvar [ad_scope_upvar_level] group_vars_set group_vars_set
ns_set put $group_vars_set group_id $group_id
ns_set put $group_vars_set group_short_name $short_name
ns_set put $group_vars_set group_name $group_name
ns_set put $group_vars_set group_admin_email $admin_email
ns_set put $group_vars_set group_public_url /[ad_parameter GroupsDirectory ug]
ns_set put $group_vars_set group_admin_url /[ad_parameter GroupsDirectory ug]/[ad_parameter GroupsAdminDirectory ug]
ns_set put $group_vars_set group_type_url_p 0
ns_set put $group_vars_set group_context_bar_list [list]
ns_set put $group_vars_set group_navbar_list [list]
}
return 1
}
}
user {
if { ![uplevel [ad_scope_upvar_level] {info exists user_id}] } {
set user_id [ad_verify_and_get_user_id]
if { $user_id==0 } {
# user is not logged in and user_id was not set in the topmost environment,
# so redirect the user for registration
ad_redirect_for_registration
ad_script_abort
}
uplevel [ad_scope_upvar_level] { set user_id 0 }
upvar [ad_scope_upvar_level] user_id user_id_temp
set user_id_temp $user_id
return 1
}
}
table {
if { ![uplevel [ad_scope_upvar_level] {info exists on_which_table}] } {
ad_return_error "Error: on_which_table is not supplied" "<ul><li>on_which_table must be supplied in order to access this page.</ul>"
ad_script_abort
} elseif { ![uplevel [ad_scope_upvar_level] {info exists on_what_id}] } {
ad_return_error "Error: on_what_id is not supplied" "<ul><li>on_what_id must be supplied in order to access this page.</ul>"
} else {
return 1
}
}
}