Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/delete.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/delete.tcl 6 Nov 2006 13:15:58 -0000 1.1 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/delete.tcl 8 Sep 2007 14:32:56 -0000 1.2 @@ -1,48 +1,49 @@ ad_page_contract { - Delete a file from a folder. This page is called via XMLHTTP. - The xmlhttp call should pass the id of the element dropped to the trash icon. - This dropped element should have the file_id to be deleted. + Delete an fs item. @author Hamilton Chua (ham@solutiongrove.com) - + @creation-date 2007-06-03 + } { - file_element + object_id } -set fs_object_id [string range $file_element 4 [string length $file_element]] +set user_id [ad_conn user_id] + +set result 1 +set fs_object_ids [split $object_id ","] set viewing_user_id [ad_conn user_id] -# ns_log Notice "HAM : fs_object_id : $fs_object_id" +db_transaction { -set action "" -set error 0 + foreach fs_object_id $fs_object_ids { -if { ![fs::object_p -object_id $fs_object_id] || [fs::folder_p -object_id $fs_object_id]} { - set message "Sorry, this object is not a File Storage Object. Delete Failed." - set error 1 -} else { - # DEDS: for export - set fs_package_id [lindex [fs::get_folder_package_and_root $fs_object_id] 0] - # check if user has permission to delete the file - if { [permission::permission_p -party_id $viewing_user_id -object_id $fs_object_id -privilege "delete"] } { - set message "Success !! File has been deleted." - set action "\$('row_${fs_object_id}').style.display='none';" - - db_transaction { - db_exec_plsql file_delete "select file_storage__delete_file(:fs_object_id);" - # fs::delete_file -item_id $fs_object_id -parent_id [fs::get_parent -item_id $fs_object_id] - } on_error { - set message "Delete Failed." - set action "" - set error 1 - } - } else { - set message "You do not have permission to delete this file." - set error 1 - } -} + if { ![fs::object_p -object_id $fs_object_id]} { + set result "Sorry, this object is not a File Storage Object." + db_abort_transaction + break; + } else { + # check if user has permission to delete the file/folder + if { [permission::permission_p -party_id $viewing_user_id -object_id $fs_object_id -privilege "delete"] } { + if { [fs::folder_p -object_id $fs_object_id] } { + fs::delete_folder -folder_id $fs_object_id -parent_id [fs::get_parent -item_id $fs_object_id] + } else { + fs::delete_file -item_id $fs_object_id + } + } else { + set result "You do not have permission to delete this file." + db_abort_transaction + break; + } + } -if {[info exists fs_package_id]} { - fs::export::export_one_instance -package_id $fs_package_id + } + +} on_error { + + ns_return 500 "text/html" $errmsg + ad_script_abort + } +