edu_serve_util_pages

one of the documented procedures in this installation of the ACS
Usage:
edu_serve_util_pages
What it does:
This procedure determines if there is a file at the requested URL. If there it, it serves that file. If there is not, it naively looks for it in the /education/util directory
Defined in: /web/philip/tcl/education.tcl

Source code:



    set pageroot [ns_info pageroot]
    set url_list [ns_conn urlv]
    
    # page_name is the last element of the list
    set page_name [lindex $url_list [expr [llength $url_list] - 1]]
    set actual_url [ns_conn url]

    # if they are requesting a directory without the file, serve up 
    # index.tcl page
    if { [regexp {/$} $actual_url] } {
	set file_extension index.tcl
    } else {
	set file_extension ""
    }
    
    if {![regexp {html$} $actual_url] && ![regexp {tcl$} $actual_url] && ![regexp {adp$} $actual_url] && ![regexp {/$} $actual_url] && ![regexp {gif} $actual_url] && ![regexp {jpg} $actual_url]} {
	ns_returnredirect "$actual_url/index"
	return
    }

    if {[file exists [ns_info pageroot][ns_conn url]$file_extension]} {
	source [ns_info pageroot][ns_conn url]$file_extension
    } else {
	set extension [list "/education/util"]

	set count [expr [llength $url_list] - 2]
	while {$count >= 0} {
	    # lets see if this is a sub directory of anything (e.g. users)
	    set subdir [lindex $url_list $count]
	    if {[string compare $subdir admin] != 0 && [string compare $subdir department] != 0 && [string compare $subdir class] != 0 && [string compare $subdir subject] != 0} {
		lappend extension $subdir
	    } else {
		break
	    }
	    incr count -1
	}

	if {[file exists [ns_info pageroot][join $extension "/"]/$page_name]} {
	    source [ns_info pageroot][join $extension "/"]/$page_name
	} elseif {[file exists [ns_info pageroot]/education/util/$page_name]} {
	    source [ns_info pageroot]/education/util/$page_name
	} else {
	    ns_returnnotfound
	    return
	}   
    }
    


philg@mit.edu