Index: openacs-4/packages/file-storage/www/file-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/www/file-add.adp,v diff -u -r1.10 -r1.10.2.1 --- openacs-4/packages/file-storage/www/file-add.adp 15 Dec 2003 11:17:27 -0000 1.10 +++ openacs-4/packages/file-storage/www/file-add.adp 25 Apr 2004 19:19:39 -0000 1.10.2.1 @@ -2,4 +2,25 @@ #file-storage.Upload_New_File# @context;noquote@ + + + + + + Index: openacs-4/packages/file-storage/www/file-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/www/file-add.tcl,v diff -u -r1.8 -r1.8.2.1 --- openacs-4/packages/file-storage/www/file-add.tcl 8 Feb 2004 15:16:17 -0000 1.8 +++ openacs-4/packages/file-storage/www/file-add.tcl 25 Apr 2004 19:19:39 -0000 1.8.2.1 @@ -77,39 +77,85 @@ ad_form -extend -form { {description:text(textarea),optional {label \#file-storage.Description\#} {html "rows 5 cols 35"}} -} -select_query_name {get_file} -new_data { - # upload a new file - # if the user choose upload from the folder view - # and the file with the same name already exists - # we create a new revision - set name [template::util::file::get_property filename $upload_file] - if {[string equal $title ""]} { - set title $name + +} + +if {[ad_form_new_p -key file_id]} { + ad_form -extend -form { + {unpack_p:boolean(checkbox),optional {label \#file-storage.Multiple_files\#} {html {onclick "javascript:UnpackChanged(this);"}} {options { {\#file-storage.lt_This_is_a_ZIP\# t} }} } } - set existing_item_id [fs::get_item_id -name $name -folder_id $folder_id] - if {![empty_string_p $existing_item_id]} { - # file with the same name already exists - # in this folder, create a new revision - set file_id $existing_item_id - permission::require_permission \ - -object_id $file_id \ - -party_id $user_id \ - -privilege write - } +} + +ad_form -extend -form {} -select_query_name {get_file} -new_data { + + +set unpack_p [template::util::is_true $unpack_p] +set unzip_binary [string trim [parameter::get -parameter UnzipBinary]] + +if { $unpack_p && ![empty_string_p $unzip_binary] } { - fs::add_file \ - -name [template::util::file::get_property filename $upload_file] \ - -item_id $file_id \ - -parent_id $folder_id \ - -tmp_filename [template::util::file::get_property tmp_filename $upload_file] \ - -creation_user $user_id \ - -creation_ip [ad_conn peeraddr] \ - -title $title \ - -description $description \ - -package_id $package_id + set path [ns_tmpnam] + file mkdir $path + + catch { exec $unzip_binary -jd $path ${upload_file.tmpfile} } errmsg + + # More flexible parameter design could be: + # zip {unzip -jd {out_path} {in_file}} tar {tar xf {in_file} {out_path}} tgz {tar xzf {in_file} {out_path}} + + set upload_files [list] + set upload_tmpfiles [list] + + foreach file [glob -nocomplain "$path/*"] { + lappend upload_files [file tail $file] + lappend upload_tmpfiles $file + } + +} else { + set upload_files [list $upload_file] + set upload_tmpfiles [list ${upload_file.tmpfile}] +} + + foreach upload_file $upload_files tmpfile $upload_tmpfiles { + set this_file_id $file_id + set this_title $title + # upload a new file + # if the user choose upload from the folder view + # and the file with the same name already exists + # we create a new revision + + if {[string equal $this_title ""]} { + set this_title $upload_file + } + + set existing_item_id [fs::get_item_id -name $upload_file -folder_id $folder_id] + + if {![empty_string_p $existing_item_id]} { + # file with the same name already exists + # in this folder, create a new revision + set this_file_id $existing_item_id + permission::require_permission \ + -object_id $this_file_id \ + -party_id $user_id \ + -privilege write + } + + fs::add_file \ + -name $upload_file \ + -item_id $this_file_id \ + -parent_id $folder_id \ + -tmp_filename $tmpfile\ + -creation_user $user_id \ + -creation_ip [ad_conn peeraddr] \ + -title $this_title \ + -description $description \ + -package_id $package_id + + } + ad_returnredirect "./?[export_url_vars folder_id]" ad_script_abort + } -edit_data { fs::add_version \