Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/editname.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/editname.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/editname.tcl 25 Dec 2006 16:23:26 -0000 1.2 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/editname.tcl 8 Sep 2007 14:32:56 -0000 1.3 @@ -1,21 +1,47 @@ ad_page_contract { - Accepts the object_id and changes it to newname + Accepts the object_id and a new name for the object. + Returns 1 if update is successful, should return an error message if not. - @author Hamilton Chua (ham@solutiongrove.com) - @creation-date May 7, 2006 + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2006-05-07 } { - newname - object_id + newname + object_id type + url:optional } +set user_id [ad_conn user_id] + +# check permissions on parent folder +# see if the user has write +if { ![permission::permission_p -no_cache \ + -party_id $user_id \ + -object_id $object_id \ + -privilege "write"] } { + + ns_return 500 "text/html" "You do not have permission to rename." + ad_script_abort +} + +set result 1 + # change the name of the give object_id if { [exists_and_not_null newname] } { # determine if this is a folder or file - if { $type == "folder" } { - db_dml "rename_folder" "update cr_folders set label = :newname where folder_id = :object_id" - } else { - db_dml "rename_file" "update cr_revisions set title=:newname where revision_id=(select live_revision from cr_items where item_id=:object_id)" + db_transaction { + if { $type == "folder" } { + fs::rename_folder -folder_id $object_id -name $newname + } elseif { $type == "url" } { + content_extlink::edit -extlink_id $object_id -url $url -label $newname -description "" + } else { + set title $newname + set file_id $object_id + db_dml dbqd.file-storage.www.file-edit-2.edit_title {} + } + } on_error { + ns_return 500 "text/html" $errmsg + ad_script_abort } } \ No newline at end of file