Index: openacs-4/packages/attachments/attachments.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/attachments.info,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/attachments/attachments.info 1 Jul 2002 20:16:23 -0000 1.1 +++ openacs-4/packages/attachments/attachments.info 2 Jul 2002 19:41:20 -0000 1.2 @@ -1,7 +1,7 @@ - + attachments attachments f @@ -24,10 +24,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + - + Index: openacs-4/packages/attachments/sql/oracle/attachments-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/sql/oracle/attachments-create.sql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/attachments/sql/oracle/attachments-create.sql 1 Jul 2002 20:16:23 -0000 1.1 +++ openacs-4/packages/attachments/sql/oracle/attachments-create.sql 2 Jul 2002 19:41:20 -0000 1.2 @@ -35,7 +35,8 @@ references acs_objects(object_id) on delete cascade, item_id constraint attachments_item_id_fk - references cr_items(item_id), + references acs_objects(object_id) + on delete cascade, constraint attachments_pk primary key (object_id, item_id) ); Index: openacs-4/packages/attachments/tcl/attachments-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/tcl/Attic/attachments-procs-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/tcl/attachments-procs-oracle.xql 2 Jul 2002 19:41:20 -0000 1.1 @@ -0,0 +1,12 @@ + + +oracle8.1.6 + + + +select item_id, acs_object.name(item_id) from attachments +where object_id= :object_id + + + + 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 -N -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 + } } Index: openacs-4/packages/attachments/tcl/attachments-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/tcl/attachments-procs.xql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/attachments/tcl/attachments-procs.xql 1 Jul 2002 20:16:23 -0000 1.1 +++ openacs-4/packages/attachments/tcl/attachments-procs.xql 2 Jul 2002 19:41:20 -0000 1.2 @@ -3,21 +3,21 @@ -select 1 from attachments_folder_map +select 1 from attachments_fs_root_folder_map where package_id = :package_id -select folder_id from attachments_folder_map +select folder_id from attachments_fs_root_folder_map where package_id = :package_id -insert into attachments_folder_map +insert into attachments_fs_root_folder_map (package_id, folder_id) values (:package_id, :folder_id) @@ -26,10 +26,33 @@ -delete from attachments_folder_map where +delete from attachments_fs_root_folder_map where package_id = :package_id and folder_id = :folder_id + + + +insert into attachments +(object_id, item_id) values +(:object_id, :attachment_id) + + + + + +delete from attachments +where object_id = :object_id and +item_id = :attachment_id + + + + + +select item_id, acs_object.name(item_id) from attachments +where object_id= :object_id + + Index: openacs-4/packages/attachments/www/attach.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/attach.adp,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/attachments/www/attach.adp 2 Jul 2002 04:18:54 -0000 1.1 +++ openacs-4/packages/attachments/www/attach.adp 2 Jul 2002 19:41:20 -0000 1.2 @@ -1,18 +1,20 @@ - + +Attach A File to @pretty_object_name@ +@context_bar@ + You are attaching a document to @pretty_object_name@.

Choose a location for your attachment. If your attachment already -exists in the file storage folder, simply select it. Otherwise, you +exists in the file storage folder, simply select it.
+Otherwise, you may upload a new attachment.

-@fs_context_bar@ +@fs_context_bar_html@

- Upload a new attachment - file +Attach a new:    File   |   - Create a new URL - attachment + URL

Index: openacs-4/packages/attachments/www/attach.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/attach.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/attachments/www/attach.tcl 2 Jul 2002 04:18:54 -0000 1.1 +++ openacs-4/packages/attachments/www/attach.tcl 2 Jul 2002 19:41:20 -0000 1.2 @@ -25,8 +25,9 @@ # Load up file storage information +set root_folder_id [attachments::get_root_folder] if {[empty_string_p $folder_id]} { - set folder_id [attachments::get_root_folder] + set folder_id $root_folder_id } # Check permission @@ -45,8 +46,14 @@ template::util::list_of_ns_sets_to_multirow -rows $rows -var_name "contents" -set fs_context_bar [fs_context_bar_list -root_folder_id [attachments::get_root_folder] -final "Attach" $folder_id] - set passthrough_vars "object_id=$object_id&return_url=[ns_urlencode $return_url]&pretty_object_name=[ns_urlencode $pretty_object_name]" +if {$folder_id == $root_folder_id} { + set fs_context_bar_html "Top" +} else { + set fs_context_bar_html [attachments::context_bar -extra_vars $passthrough_vars -folder_id $folder_id] +} + +set context_bar {Attach} + ad_return_template Index: openacs-4/packages/attachments/www/file-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/file-add.adp,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/attachments/www/file-add.adp 2 Jul 2002 04:18:54 -0000 1.1 +++ openacs-4/packages/attachments/www/file-add.adp 2 Jul 2002 19:41:20 -0000 1.2 @@ -1,7 +1,9 @@ - -Upload New File + +Upload New Attachment @context_bar@ +You are attaching a document to @pretty_object_name@.

+
Index: openacs-4/packages/attachments/www/file-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/file-add.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/attachments/www/file-add.tcl 2 Jul 2002 04:18:54 -0000 1.1 +++ openacs-4/packages/attachments/www/file-add.tcl 2 Jul 2002 19:41:20 -0000 1.2 @@ -8,6 +8,7 @@ folder_id:integer,notnull object_id:integer,notnull return_url:notnull + pretty_object_name:notnull {title ""} {lock_title_p 0} } -validate { @@ -29,7 +30,8 @@ # set templating datasources -set context_bar [fs_context_bar_list -final "Add File" $folder_id] +set context_bar {{Attach File}} +set fs_context_bar [fs_context_bar_list -final "Add File" $folder_id] # Should probably generate the item_id and version_id now for # double-click protection Index: openacs-4/packages/attachments/www/go-to-attachment.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/go-to-attachment.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/go-to-attachment.tcl 2 Jul 2002 19:41:20 -0000 1.1 @@ -0,0 +1,38 @@ + +ad_page_contract { + Go to an attachment + + @author Ben Adida (ben@openforce) +} { + {object_id:integer,notnull} + {attachment_id:integer,notnull} +} + +# We check permissions on the object +permission::require_permission -object_id $object_id -privilege read + +# Get information about attachment +if {![db_0or1row select_attachment_data {}]} { + ad_return_complaint "No such attachment for this object" + return +} + +switch $object_type { + fs_url { + set url [db_string select_url {}] + ad_returnredirect $url + ad_script_abort + return + } + + content_item { + ad_returnredirect "download/$object_id?object_id=$object_id&attachment_id=$attachment_id" + ad_script_abort + return + } + + default { + ad_return_complaint "don't know how to deal with this attachment type" + return + } +} Index: openacs-4/packages/attachments/www/go-to-attachment.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/go-to-attachment.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/go-to-attachment.xql 2 Jul 2002 19:41:20 -0000 1.1 @@ -0,0 +1,27 @@ + + + + + +select +object_type +from attachments, acs_objects +where +attachments.object_id = :object_id and +attachments.item_id = :attachment_id and +attachments.item_id = acs_objects.object_id + + + + + +select +url +from fs_urls +where +url_id = :attachment_id + + + + + Index: openacs-4/packages/attachments/www/master.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/Attic/master.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/master.adp 2 Jul 2002 19:41:20 -0000 1.1 @@ -0,0 +1,10 @@ + +@title@ + +

@title@

+ +@context_bar@ + +
+ + Index: openacs-4/packages/attachments/www/master.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/Attic/master.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/master.tcl 2 Jul 2002 19:41:20 -0000 1.1 @@ -0,0 +1 @@ +set context_bar [eval ad_context_bar $context_bar] Index: openacs-4/packages/attachments/www/simple-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/simple-add.adp,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/attachments/www/simple-add.adp 2 Jul 2002 04:18:54 -0000 1.1 +++ openacs-4/packages/attachments/www/simple-add.adp 2 Jul 2002 19:41:20 -0000 1.2 @@ -1,7 +1,9 @@ - -Create @pretty_name@ + +Attach URL @context_bar@ +You are attaching a document to @pretty_object_name@.

+ Index: openacs-4/packages/attachments/www/simple-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/simple-add.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/attachments/www/simple-add.tcl 2 Jul 2002 04:18:54 -0000 1.1 +++ openacs-4/packages/attachments/www/simple-add.tcl 2 Jul 2002 19:41:20 -0000 1.2 @@ -9,6 +9,7 @@ folder_id:integer,notnull object_id:integer,notnull return_url:notnull + pretty_object_name:notnull {type "fs_url"} {title ""} {lock_title_p 0} @@ -34,7 +35,8 @@ return -code error "No such type" } -set context_bar [fs_context_bar_list -final "Add $pretty_name" $folder_id] +set context_bar {{Attach URL}} +set fs_context_bar [fs_context_bar_list -final "Add $pretty_name" $folder_id] # Should probably generate the item_id and version_id now for # double-click protection Index: openacs-4/packages/attachments/www/download/index.vuh =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/download/index.vuh,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/download/index.vuh 2 Jul 2002 19:41:20 -0000 1.1 @@ -0,0 +1,28 @@ +# packages/attachments/www/download/index.vuh + +ad_page_contract { + + Virtual URL handler for file downloads + + @author Ben Adida + @creation-date 2 July 2002 + @cvs-id $Id: index.vuh,v 1.1 2002/07/02 19:41:20 ben Exp $ +} { + object_id:integer,notnull + attachment_id:integer,notnull +} + +# Permission check +permission::require_permission -object_id $object_id -privilege read + +# Get the live version +# (and check that this is the right attachment while we're at it) +set version_id [db_string select_version_id {} -default {}] + +if {[empty_string_p $version_id]} { + ad_return_complaint "bad attachment" + ad_script_abort + return +} + +cr_write_content -revision_id $version_id Index: openacs-4/packages/attachments/www/download/index.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/download/index.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/download/index.xql 2 Jul 2002 19:41:20 -0000 1.1 @@ -0,0 +1,14 @@ + + + + + +select live_revision +from cr_items, attachments +where cr_items.item_id = attachments.item_id +and attachments.object_id = :object_id + + + + + Index: openacs-4/packages/attachments/www/graphics/file.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/graphics/file.gif,v diff -u -N Binary files differ Index: openacs-4/packages/attachments/www/graphics/folder.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/graphics/folder.gif,v diff -u -N Binary files differ