bm_export_to_netscape

one of the documented procedures in this installation of the ACS
Usage:
bm_export_to_netscape
What it does:
Outputs a set of bookmarks in the standard Netscape bookmark.htm format
Defined in: /web/philip/tcl/bookmarks-defs.tcl

Source code:



    set user_id [ad_verify_and_get_user_id]

    # redirect some one who hasn't logged on to the server front page
    if { $user_id == 0} {
	ad_returnredirect "/register/index?return_url=[ns_urlencode [ns_conn url]]"
	return
    }
    set db [ns_db gethandle subquery]

    set sql_query "
        select first_names||' '||last_name as name 
        from   users 
        where  user_id=$user_id"
    set name [database_to_tcl_string $db $sql_query]

    set sql_query "
        select   bookmark_id, bm_list.url_id, 
                 local_title, creation_date, parent_id
                 parent_id, complete_url, folder_p,
                 parent_sort_key||local_sort_key as sort_key
        from     bm_list, bm_urls
        where    owner_id=$user_id
        and      bm_list.url_id=bm_urls.url_id(+)
        order by sort_key"

    set selection [ns_db select $db $sql_query]

    set folder_list 0

    while {[ns_db getrow $db $selection]} {
	set_variables_after_query

	set previous_parent_id [lindex $folder_list [expr [llength $folder_list]-1]]
	
	if {$parent_id!=$previous_parent_id} {

	    set parent_location [lsearch -exact $folder_list $parent_id]
	    
	    if {$parent_location==-1} {
		lappend folder_list $parent_id
		append bookmark_html "<DL><p>\n\n"
	    } else { 	    
		set drop [expr [llength $folder_list]-$parent_location]
		set folder_list [lrange $folder_list 0 $parent_location]
		for {set i 1} {$i<$drop} {incr i} {
		    append bookmark_html "</DL><p>\n\n"
		}
	    }
	}

	if {$folder_p=="t"} {
	    append bookmark_html "<DT><H3 ADD_DATE=\"[ns_time]\">$local_title</H3>\n\n"
	} else {
	    append bookmark_html "<DT><A HREF=\"$complete_url\" ADD_DATE=\"[ns_time]\" LAST_VISIT=\"0\" LAST_MODIFIED=\"0\">$local_title</A>\n\n"
	}
	
    }

    set html "<!DOCTYPE NETSCAPE-Bookmark-file-1>

<!-- This is an automatically generated file.

It will be read and overwritten.

Do Not Edit! -->

<TITLE>Bookmarks for $name</TITLE>

<H1>Bookmarks for $name</H1>


<DL><p>

$bookmark_html

</DL><p>
"

    ns_db releasehandle $db
    ns_return 200 text/html $html
    


philg@mit.edu