Index: openacs-4/packages/attachments/www/attach-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/attach-2.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/attach-2.tcl 2 Jul 2002 04:18:54 -0000 1.1 @@ -0,0 +1,21 @@ +ad_page_contract { + + Attaches something to an object + + @author Arjun Sanyal (arjun@openforce.net), Ben Adida + @version $Id: attach-2.tcl,v 1.1 2002/07/02 04:18:54 ben Exp $ + +} -query { + {object_id:notnull} + {item_id:notnull} + {return_url:notnull} +} + +# Perms +permission::require_permission -object_id $object_id -privilege write + +# Perform the attachment +attachments::attach -object_id $object_id -attachment_id $item_id + +ad_returnredirect $return_url + Index: openacs-4/packages/attachments/www/attach.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/attach.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/attach.adp 2 Jul 2002 04:18:54 -0000 1.1 @@ -0,0 +1,82 @@ + +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 +may upload a new attachment. + +

+@fs_context_bar@ +

+ Upload a new attachment + file +   |   + Create a new URL + attachment +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 NameActionSizeTypeLast Modified
+ @contents.name@ +( new ) +   + @contents.content_size@ items + @contents.type@@contents.last_modified@ + @contents.name@ +( new ) + + [ +Choose + ] +  @contents.type@@contents.last_modified@ + @contents.name@ + + ( new ) + + + [ +Choose + ] + @contents.content_size@ bytes@contents.type@@contents.last_modified@
+
+ +

Folder @folder_name@ is empty

+ Index: openacs-4/packages/attachments/www/attach.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/attach.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/attach.tcl 2 Jul 2002 04:18:54 -0000 1.1 @@ -0,0 +1,52 @@ + +ad_page_contract { + + Attach something to an object + + @author arjun@openforce.net,ben@openforce + @version $Id: attach.tcl,v 1.1 2002/07/02 04:18:54 ben Exp $ + +} -query { + {object_id:notnull} + {folder_id ""} + {pretty_object_name ""} + {return_url:notnull} +} + +set user_id [ad_conn user_id] + +# We require the write permission on an object +permission::require_permission -object_id $object_id -privilege write + +# Give the object a nasty name if it doesn't have a pretty name +if {[empty_string_p $pretty_object_name]} { + set pretty_object_name "Object #$object_id" +} + +# Load up file storage information + +if {[empty_string_p $folder_id]} { + set folder_id [attachments::get_root_folder] +} + +# Check permission +permission::require_permission -object_id $folder_id -privilege read + +# Size of contents +set n_contents [fs::get_folder_contents_count -folder_id $folder_id -user_id $user_id] + +# Folder name +set folder_name [fs::get_object_name -object_id $folder_id] + +# Folder contents +set rows [fs::get_folder_contents \ + -folder_id $folder_id \ + -user_id $user_id] + +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]" + +ad_return_template Index: openacs-4/packages/attachments/www/file-add-2-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/Attic/file-add-2-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/file-add-2-oracle.xql 2 Jul 2002 04:18:54 -0000 1.1 @@ -0,0 +1,94 @@ + + + + oracle8.1.6 + + + + + begin + :1 := file_storage.new_file ( + title => :title, + folder_id => :folder_id, + creation_user => :user_id, + creation_ip => :creation_ip, + indb_p => 't' + ); + end; + + + + + + + + + begin + :1 := file_storage.new_file ( + title => :title, + folder_id => :folder_id, + creation_user => :user_id, + creation_ip => :creation_ip, + indb_p => 'f' + ); + + end; + + + + + + + + + begin + :1 := file_storage.new_version ( + filename => :filename, + description => :description, + mime_type => :mime_type, + item_id => :file_id, + creation_user => :user_id, + creation_ip => :creation_ip + ); + + end; + + + + + + + + + update cr_revisions + set content = empty_blob() + where revision_id = :version_id + returning content into :1 + + + + + + + + update cr_revisions + set content_length = dbms_lob.getlength(content) + where revision_id = :version_id + + + + + + + + + update cr_revisions + set filename = '$tmp_filename', + content_length = $tmp_size + where revision_id = :version_id + + + + + + Index: openacs-4/packages/attachments/www/file-add-2-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/Attic/file-add-2-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/file-add-2-postgresql.xql 2 Jul 2002 04:18:54 -0000 1.1 @@ -0,0 +1,87 @@ + + + + postgresql7.1 + + + + + select file_storage__new_file ( + :title, -- title + :folder_id, -- parent_id + :user_id, -- creation_user + :creation_ip, -- creation_ip + true -- indb_p + ); + + + + + + + + + select file_storage__new_file ( + :title, -- title + :folder_id, -- parent_id + :user_id, -- creation_user + :creation_ip, -- creation_ip + false -- indb_p + ); + + + + + + + + + select file_storage__new_version ( + :filename, -- filename + :description, -- description + :mime_type, -- mime_type + :file_id, -- item_id + :user_id, -- creation_user + :creation_ip -- creation_ip + ); + + + + + + + + + update cr_revisions + set lob = [set __lob_id [db_string get_lob_id "select empty_lob()"]] + where revision_id = :version_id + + + + + + + + update cr_revisions + set content_length = lob_length(lob) + where revision_id = :version_id + + + + + + + + + + update cr_revisions + set content = '$tmp_filename', + content_length = $tmp_size + where revision_id = :version_id + + + + + + + Index: openacs-4/packages/attachments/www/file-add-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/file-add-2.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/file-add-2.tcl 2 Jul 2002 04:18:54 -0000 1.1 @@ -0,0 +1,160 @@ +ad_page_contract { + script to recieve the new file and insert it into the database + + @author Kevin Scaldeferri (kevin@arsdigita.com) + @creation-date 6 Nov 2000 + @cvs-id $Id: file-add-2.tcl,v 1.1 2002/07/02 04:18:54 ben Exp $ +} { + folder_id:integer,notnull + upload_file:notnull,trim + upload_file.tmpfile:tmpfile + object_id:integer,notnull + return_url:notnull + title:notnull,trim + description +} -validate { + valid_folder -requires {folder_id:integer} { + if ![fs_folder_p $folder_id] { + ad_complain "The specified parent folder is not valid." + } + } + + max_size -requires {upload_file} { + set n_bytes [file size ${upload_file.tmpfile}] + set max_bytes [ad_parameter "MaximumFileSize"] + if { $n_bytes > $max_bytes } { + ad_complain "Your file is larger than the maximum file size allowed on this system ([util_commify_number $max_bytes] bytes)" + } + } +} + +# Check for write permission on this folder +ad_require_permission $folder_id write + +# Get the filename part of the upload file +if ![regexp {[^//\\]+$} $upload_file filename] { + # no match + set filename $upload_file +} + +# Get the user +set user_id [ad_conn user_id] + +# Get the ip +set creation_ip [ad_conn peeraddr] + +# The content repository is kinda stupid about mime types, +# so we have to check if we know about this one and possibly +# add it. +set mime_type [fs_maybe_create_new_mime_type $upload_file] + +# Get the storage type +set indb_p [ad_parameter "StoreFilesInDatabaseP" -package_id [ad_conn package_id]] + +db_transaction { + + # create the new item + if {$indb_p} { + + set file_id [db_exec_plsql new_lob_file " + begin + :1 := file_storage.new_file ( + title => :title, + folder_id => :folder_id, + creation_user => :user_id, + creation_ip => :creation_ip, + indb_p => 't' + ); + + end;"] + + set version_id [db_exec_plsql new_version " + begin + :1 := file_storage.new_version ( + filename => :filename, + description => :description, + mime_type => :mime_type, + item_id => :file_id, + creation_user => :user_id, + creation_ip => :creation_ip + ); + end;"] + + db_dml lob_content " + update cr_revisions + set content = empty_lob() + where revision_id = :version_id + returning content into :1" -blob_files [list ${upload_file.tmpfile}] + + + # Unfortunately, we can only calculate the file size after the lob is uploaded + db_dml lob_size " + update cr_revisions + set content_length = dbms_lob.getlength(content) + where revision_id = :version_id" + + } else { + + set file_id [db_exec_plsql new_fs_file " + begin + :1 := file_storage.new_file ( + title => :title, + folder_id => :folder_id, + creation_user => :user_id, + creation_ip => :creation_ip, + indb_p => 'f' + ); + end;"] + + + set version_id [db_exec_plsql new_version " + begin + + :1 := file_storage.new_version ( + filename => :filename, + description => :description, + mime_type => :mime_type, + item_id => :file_id, + creation_user => :user_id, + creation_ip => :creation_ip + ); + + end;"] + + set tmp_filename [cr_create_content_file $file_id $version_id ${upload_file.tmpfile}] + set tmp_size [cr_file_size $tmp_filename] + + db_dml fs_content_size " + update cr_revisions + set content = '$tmp_filename', + content_length = $tmp_size + where revision_id = :version_id" + + } + + # attach the file_id + attachments::attach -object_id $object_id -attachment_id $file_id + +} on_error { + + # most likely a duplicate name or a double click + +# if [db_string duplicate_check " +# select count(*) +# from cr_items +# where name = :filename +# and parent_id = :folder_id"] { +# ad_return_complaint 1 "Either there is already a file with the name \"$tmp_filename\" or you clicked on the button more than once. You can use the Back button to return and choose a new name, or return to the directory listing to see if your file is there." +# } else { +# ad_return_complaint 1 "We got an error that we couldn't readily identify. Please let the system owner know about this. +# +#
$errmsg
" +# } + + ad_return_complaint 1 "You probably clicked on the Add button more than once. Check if the file is properly loaded on the folder you wan, or you can use the Back button to return and re-enter the version file." + + return +} + + +ad_returnredirect $return_url Index: openacs-4/packages/attachments/www/file-add-2.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/Attic/file-add-2.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/file-add-2.xql 2 Jul 2002 04:18:54 -0000 1.1 @@ -0,0 +1,17 @@ + + + + + + + select count(*) + from cr_items + where name = :filename + and parent_id = :folder_id + + + + + + + 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/file-add.adp 2 Jul 2002 04:18:54 -0000 1.1 @@ -0,0 +1,51 @@ + +Upload New File +@context_bar@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Version filename :
 Use the "Browse..." button to locate your file, + then click "Open".
  
Title: @title@
Description:
+
+
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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/file-add.tcl 2 Jul 2002 04:18:54 -0000 1.1 @@ -0,0 +1,41 @@ +ad_page_contract { + page to add a new file to the system + + @author Kevin Scaldeferri (kevin@arsdigita.com) + @creation-date 6 Nov 2000 + @cvs-id $Id: file-add.tcl,v 1.1 2002/07/02 04:18:54 ben Exp $ +} { + folder_id:integer,notnull + object_id:integer,notnull + return_url:notnull + {title ""} + {lock_title_p 0} +} -validate { + valid_folder -requires {folder_id:integer} { + if ![fs_folder_p $folder_id] { + ad_complain "The specified parent folder is not valid." + } + } +} -properties { + folder_id:onevalue + context_bar:onevalue + title:onevalue + lock_title_p:onevalue +} + +# check for write permission on the folder + +ad_require_permission $folder_id write + +# set templating datasources + +set 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 + +# if title isn't passed in ignore lock_title_p +if {[empty_string_p $title]} { + set lock_title_p 0 +} + Index: openacs-4/packages/attachments/www/simple-add-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/simple-add-2.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/simple-add-2.tcl 2 Jul 2002 04:18:54 -0000 1.1 @@ -0,0 +1,34 @@ +ad_page_contract { + Add a nonversioned item + + @author Kevin Scaldeferri (kevin@arsdigita.com) + @creation-date 6 Nov 2000 + @cvs-id $Id: simple-add-2.tcl,v 1.1 2002/07/02 04:18:54 ben Exp $ +} { + folder_id:integer,notnull + object_id:integer,notnull + return_url:notnull + title:notnull,trim + description + url:notnull,trim +} -validate { + valid_folder -requires {folder_id:integer} { + if ![fs_folder_p $folder_id] { + ad_complain "The specified parent folder is not valid." + } + } + +} + +# Check for write permission on this folder +ad_require_permission $folder_id write + +db_transaction { + # Create the URL (for now) + set url_id [fs::url_new -url $url -name $title -description $description -folder_id $folder_id] + + # Attach the URL + attachments::attach -object_id $object_id -attachment_id $url_id +} + +ad_returnredirect "$return_url" 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/simple-add.adp 2 Jul 2002 04:18:54 -0000 1.1 @@ -0,0 +1,41 @@ + +Create @pretty_name@ +@context_bar@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title: @title@
URL:
Description:
+
+
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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/simple-add.tcl 2 Jul 2002 04:18:54 -0000 1.1 @@ -0,0 +1,47 @@ +ad_page_contract { + page to add a new nonversioned object to the system + + @author Ben Adida (ben@openforce) + @author arjun (arjun@openforce) + @creation-date 01 April 2002 + @cvs-id $Id: simple-add.tcl,v 1.1 2002/07/02 04:18:54 ben Exp $ +} { + folder_id:integer,notnull + object_id:integer,notnull + return_url:notnull + {type "fs_url"} + {title ""} + {lock_title_p 0} +} -validate { + valid_folder -requires {folder_id:integer} { + if ![fs_folder_p $folder_id] { + ad_complain "The specified parent folder is not valid." + } + } +} -properties { + folder_id:onevalue + context_bar:onevalue +} + +# check for write permission on the folder + +ad_require_permission $folder_id write + +# set templating datasources + +set pretty_name [fs::simple_get_type_pretty_name -type $type] +if {[empty_string_p $pretty_name]} { + return -code error "No such type" +} + +set 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 + + +# if title isn't passed in ignore lock_title_p +if {[empty_string_p $title]} { + set lock_title_p 0 +} + Index: openacs-4/packages/attachments/www/test.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/Attic/test.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/attachments/www/test.tcl 2 Jul 2002 04:18:54 -0000 1.1 @@ -0,0 +1,3 @@ + +attachments::map_root_folder -package_id 2736 -folder_id 2768 +doc_body_append "done"