Index: openacs-4/packages/attachments/tcl/attachments-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/tcl/attachments-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/attachments/tcl/attachments-procs.tcl 1 Jul 2002 20:16:23 -0000 1.1 +++ openacs-4/packages/attachments/tcl/attachments-procs.tcl 2 Jul 2002 19:41:20 -0000 1.2 @@ -29,10 +29,16 @@ } ad_proc -public get_root_folder { - {-package_id:required} + {-package_id ""} } { } { - return [db_1row get_root_folder_select {}] + if {[empty_string_p $package_id]} { + # Get the package ID from the parent URL + array set parent_node [site_node::get_parent -node_id [ad_conn node_id]] + set package_id $parent_node(object_id) + } + + return [db_string get_root_folder_select {} -default {}] } ad_proc -public root_folder_map_p { @@ -59,5 +65,87 @@ } { db_dml unmap_root_folder_delete {} } + + ad_proc -public attach { + {-object_id:required} + {-attachment_id:required} + } { + perform the attachment + } { + db_dml insert_attachment {} + } + + ad_proc -public unattach { + {-object_id:required} + {-attachment_id:required} + } { + undo the attachment + } { + db_dml delete_attachment {} + } + + ad_proc -public add_attachment_url { + {-package_id ""} + {-object_id:required} + {-return_url ""} + {-pretty_name ""} + } { + # FIXME: absolute URL here!! + return "attach/attach?pretty_object_name=[ns_urlencode $pretty_name]&object_id=$object_id&return_url=[ns_urlencode $return_url]" + } + + ad_proc -public goto_attachment_url { + {-package_id ""} + {-object_id:required} + {-attachment_id:required} + } { + # FIXME: absolute URL! + return "attach/go-to-attachment?object_id=$object_id&attachment_id=$attachment_id" + } + + ad_proc -public graphic_url { + {-package_id ""} + } { + # FIXME: absolute URL! + return "" + } + + ad_proc -public get_attachments { + {-object_id:required} + } { + returns a list of attachment ids and names + } { + set lst [db_list_of_lists select_attachments {}] + set lst_with_urls [list] + + foreach el $lst { + set append_lst [list [goto_attachment_url -object_id $object_id -attachment_id [lindex $el 0]]] + lappend lst_with_urls [concat $el $append_lst] + } + + return $lst_with_urls + } + + ad_proc -public context_bar { + {-folder_id:required} + {-final ""} + {-extra_vars ""} + } { + set root_folder_id [attachments::get_root_folder] + + set cbar_list [fs_context_bar_list -extra_vars $extra_vars -folder_url "attach" -file_url "attach" -root_folder_id $root_folder_id -final $final $folder_id] + + set cbar_html "Top > " + + foreach el $cbar_list { + if {[llength $el] < 2} { + append cbar_html "$el" + } else { + append cbar_html "[lindex $el 1] > " + } + } + + return $cbar_html + } }