Index: openacs-4/packages/acs-templating/www/scripts/xinha/attach-file.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/www/scripts/xinha/attach-file.adp,v diff -u -r1.5 -r1.6 --- openacs-4/packages/acs-templating/www/scripts/xinha/attach-file.adp 31 Aug 2006 14:30:00 -0000 1.5 +++ openacs-4/packages/acs-templating/www/scripts/xinha/attach-file.adp 3 Sep 2006 17:23:56 -0000 1.6 @@ -92,34 +92,40 @@ -
- @HTML_UploadTitle@ + + + - - - - - -
+
+ Choose File + +
+ @formgroup.widget;noquote@ @formgroup.label@ +
+
+   +
+
+
+ or Upload a New File #acs-templating.Link_Title#
@formerror.f_title@

-
- - - - +
@formerror.upload_file@
@@ -133,13 +139,12 @@
@formerror.share@
+   +
-   -
Index: openacs-4/packages/acs-templating/www/scripts/xinha/attach-file.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/www/scripts/xinha/attach-file.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/acs-templating/www/scripts/xinha/attach-file.tcl 3 Sep 2006 16:58:24 -0000 1.4 +++ openacs-4/packages/acs-templating/www/scripts/xinha/attach-file.tcl 3 Sep 2006 17:23:56 -0000 1.5 @@ -18,6 +18,22 @@ set write_p 1 + # set recent images + db_multirow -unclobber recent_files recent_files \ + { + select ci.item_id, ci.name + from cr_items ci, cr_revisionsx cr + where ci.live_revision=cr.revision_id + and ci.content_type='content_revision' + and storage_type='file' + and cr.creation_user=:user_id + order by creation_date desc + limit 6 + } { + lappend recent_files_options [list $name $item_id] + } + + set share_options [list [list "[_ acs-templating.Only_myself]" private] [list "[_ acs-templating.This_Group]" group] [list "[_ acs-templating.Anyone_on_this_system]" site] [list "[_ acs-templating.Anyone_on_the_internet]" public]] ad_form \ -name upload_form \ @@ -27,8 +43,10 @@ -form { item_id:key {f_title:text,optional {label "[_ acs-templating.Link_Text]"} {html {size 50 id f_title} } } + {choose_file:text(radio),optional {options $recent_files_options}} {upload_file:file(file) {html {size 30}} } {share:text(radio),optional {label "[_ acs-templating.This_file_can_be_reused_by]"} {options $share_options} {help_text "[_ acs-templating.This_file_can_be_reused_help]"}} + {select_btn:text(submit) {label "Select"}} {ok_btn:text(submit) {label "[_ acs-templating.HTMLArea_SelectUploadBtn]"} } } \ @@ -39,90 +57,97 @@ } \ -on_submit { # check file name - if {$upload_file eq ""} { + if {$choose_file eq "" && $upload_file eq ""} { template::form::set_error upload_form upload_file \ [_ acs-templating.HTMLArea_SpecifyUploadFilename] break } - # check quota - # FIXME quota is a good idea, set per-user upload quota?? -# set maximum_folder_size [ad_parameter "MaximumFolderSize"] - -# if { $maximum_folder_size ne "" } { -# set max [ad_parameter "MaximumFolderSize"] -# if { $folder_size+[file size ${upload_file.tmpfile}] > $max } { -# template::form::set_error upload_form upload_file \ - [_ file-storage.out_of_space] - # break - # } - # } - - set file_name [template::util::file::get_property filename $upload_file] - set upload_tmpfile [template::util::file::get_property tmp_filename $upload_file] - set mime_type [template::util::file::get_property mime_type $upload_file] - if {$mime_type eq ""} { - set mime_type [ns_guesstype $file_name] - } - if {$f_title eq ""} { - element set_value upload_form f_title $file_name - } - if {[string match "image/*" $mime_type]} { + if {$upload_file ne ""} { + # check quota + # FIXME quota is a good idea, set per-user upload quota?? + # set maximum_folder_size [ad_parameter "MaximumFolderSize"] - image::new \ - -item_id $item_id \ - -name ${item_id}_$file_name \ - -parent_id $parent_id \ - -title $f_title \ - -tmp_filename $upload_tmpfile \ - -creation_user $user_id \ - -creation_ip [ad_conn peeraddr] \ - -package_id [ad_conn package_id] - } else { - content::item::new \ - -item_id $item_id \ - -name ${item_id}_$file_name \ - -title $f_title \ - -parent_id $parent_id \ - -tmp_filename $upload_tmpfile \ - -creation_user $user_id \ - -creation_ip [ad_conn peeraddr] \ - -package_id [ad_conn package_id] - } - file delete $upload_tmpfile - permission::grant \ - -object_id $item_id \ - -party_id $user_id \ - -privilege admin - - switch -- $share { - private { - permission::set_not_inherit -object_id $item_id + # if { $maximum_folder_size ne "" } { + # set max [ad_parameter "MaximumFolderSize"] + # if { $folder_size+[file size ${upload_file.tmpfile}] > $max } { + # template::form::set_error upload_form upload_file \ + [_ file-storage.out_of_space] + # break + # } + # } + + set file_name [template::util::file::get_property filename $upload_file] + set upload_tmpfile [template::util::file::get_property tmp_filename $upload_file] + set mime_type [template::util::file::get_property mime_type $upload_file] + if {$mime_type eq ""} { + set mime_type [ns_guesstype $file_name] } - group { - # Find the closest application group - # either dotlrn or acs-subsite + + if {[string match "image/*" $mime_type]} { - permission::grant \ - -party_id [acs_magic_object "registered_users"] \ - -object_id $item_id \ - -privilege "read" + image::new \ + -item_id $item_id \ + -name ${item_id}_$file_name \ + -parent_id $parent_id \ + -title $f_title \ + -tmp_filename $upload_tmpfile \ + -creation_user $user_id \ + -creation_ip [ad_conn peeraddr] \ + -package_id [ad_conn package_id] + } else { + content::item::new \ + -item_id $item_id \ + -name ${item_id}_$file_name \ + -title $f_title \ + -parent_id $parent_id \ + -tmp_filename $upload_tmpfile \ + -creation_user $user_id \ + -creation_ip [ad_conn peeraddr] \ + -package_id [ad_conn package_id] } - public { - permission::grant \ - -party_id [acs_magic_object "the_public"] \ - -object_id $item_id \ - -privilege "read" - } - site - - default { - permission::grant \ - -party_id [acs_magic_object "registered_users"] \ - -object_id $item_id \ - -privilege "read" - } + file delete $upload_tmpfile + permission::grant \ + -object_id $item_id \ + -party_id $user_id \ + -privilege admin + switch -- $share { + private { + permission::set_not_inherit -object_id $item_id + } + group { + # Find the closest application group + # either dotlrn or acs-subsite + + permission::grant \ + -party_id [acs_magic_object "registered_users"] \ + -object_id $item_id \ + -privilege "read" + } + public { + permission::grant \ + -party_id [acs_magic_object "the_public"] \ + -object_id $item_id \ + -privilege "read" + } + site - + default { + permission::grant \ + -party_id [acs_magic_object "registered_users"] \ + -object_id $item_id \ + -privilege "read" + } + + } + } else { + set item_id $choose_file + set file_name [lindex [lindex $recent_files_options [util_search_list_of_lists $recent_files_options $item_id 1]] 0] } + + if {$f_title eq ""} { + element set_value upload_form f_title $file_name + } if {$share eq "private" && [string match "image/*" $mime_type]} { # need a private URL that allows viewers of this # object to see the image