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.6 -r1.7 --- openacs-4/packages/acs-templating/www/scripts/xinha/attach-file.adp 3 Sep 2006 17:23:56 -0000 1.6 +++ openacs-4/packages/acs-templating/www/scripts/xinha/attach-file.adp 9 Oct 2006 19:29:51 -0000 1.7 @@ -104,7 +104,7 @@ Choose File
- @formgroup.widget;noquote@ @formgroup.label@ + @formgroup.widget;noquote@ @formgroup.label;noquote@

  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.7 -r1.8 --- openacs-4/packages/acs-templating/www/scripts/xinha/attach-file.tcl 6 Oct 2006 02:07:43 -0000 1.7 +++ openacs-4/packages/acs-templating/www/scripts/xinha/attach-file.tcl 9 Oct 2006 19:29:51 -0000 1.8 @@ -20,18 +20,21 @@ # set recent files set recent_files_options [list] - db_multirow -unclobber recent_files recent_files \ + db_multirow -extend {mime_icon} -unclobber recent_files recent_files \ { - select ci.item_id, ci.name + select ci.item_id, ci.name, cr.mime_type 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 + and cr.mime_type is not null order by creation_date desc limit 6 } { - set name [regsub "${item_id}_" $name ""] + set mime_icon "/resources/acs-templating/mimetypes/gnome-mime-[string map {/ -} $mime_type].png" + set name [regsub "${item_id}_" $name ""] + set name " $name" lappend recent_files_options [list $name $item_id] } @@ -60,108 +63,120 @@ -on_submit { # check file name if {$choose_file eq "" && $upload_file eq ""} { - template::form::set_error upload_form upload_file \ - [_ acs-templating.HTMLArea_SpecifyUploadFilename] - break - } + if {[info exists ok_btn] && $ok_btn ne ""} { + template::form::set_error upload_form upload_file \ + [_ acs-templating.HTMLArea_SpecifyUploadFilename] + } + if {[info exists select_btn]} { + template::form::set_error upload_form choose_file \ + [_ acs-templating.Attach_File_Choose_a_file] + } + set share site + set f_title "" + set f_href "" - if {$upload_file ne ""} { - # 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 {[string match "image/*" $mime_type]} { - - 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 - } - 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 - # this isn't totally secure, because of course - # you need to be able to see the image somehow - # but we only allow read on the image if you can - # see the parent object - set f_href "/image/$item_id/private/$file_name" - } else { - set f_href "/file/$item_id/$file_name" - } + if {$upload_file ne ""} { + # 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 {[string match "image/*" $mime_type]} { + + 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] \ + -mime_type $mime_type + } + 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 + # this isn't totally secure, because of course + # you need to be able to see the image somehow + # but we only allow read on the image if you can + # see the parent object + set f_href "/image/${item_id}/private/${parent_id}/${file_name}" + + } else { + set f_href "/file/${item_id}/${file_name}" + } + } + } } else { Index: openacs-4/packages/acs-templating/www/scripts/xinha/attach-image.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/www/scripts/xinha/attach-image.adp,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-templating/www/scripts/xinha/attach-image.adp 3 Sep 2006 16:59:11 -0000 1.3 +++ openacs-4/packages/acs-templating/www/scripts/xinha/attach-image.adp 9 Oct 2006 19:29:51 -0000 1.4 @@ -148,7 +148,7 @@ - +

KEY = @parent_id@

Index: openacs-4/packages/acs-templating/www/scripts/xinha/attach-image.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/www/scripts/xinha/attach-image.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/acs-templating/www/scripts/xinha/attach-image.tcl 6 Oct 2006 02:07:43 -0000 1.4 +++ openacs-4/packages/acs-templating/www/scripts/xinha/attach-image.tcl 9 Oct 2006 19:29:51 -0000 1.5 @@ -110,10 +110,12 @@ -object_id $item_id \ -party_id $user_id \ -privilege admin - + + set f_url "/image/${item_id}/${file_name}" switch -- $share { private { permission::set_not_inherit -object_id $item_id + set f_url "/image/${item_id}/private/${parent_id}/${file_name}" } group { # Find the closest application group @@ -145,17 +147,7 @@ set file_name "" } - if {$share eq "private"} { - # need a private URL that allows viewers of this - # object to see the image - # this isn't totally secure, because of course - # you need to be able to see the image somehow - # but we only allow read on the image if you can - # see the parent object - set f_url "/image/$item_id/private/$file_name" - } else { - set f_url "/image/$item_id/file_name" - } + } } else {