Index: openacs-4/packages/contacts/lib/contact-master.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/lib/contact-master.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/contacts/lib/contact-master.tcl 25 May 2005 02:09:52 -0000 1.4 +++ openacs-4/packages/contacts/lib/contact-master.tcl 27 May 2005 00:18:57 -0000 1.5 @@ -38,6 +38,9 @@ lappend link_list "${prefix}comments" lappend link_list "Comments" + lappend link_list "${prefix}files" + lappend link_list "Files" + if { [site_node::get_package_url -package_key "tasks"] != "" } { lappend link_list "/tasks/contact?party_id=$party_id" lappend link_list "Tasks" Index: openacs-4/packages/contacts/resources/forms/file-upload.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/resources/forms/file-upload.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/resources/forms/file-upload.adp 27 May 2005 00:18:58 -0000 1.1 @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @elements.label;noquote@ + + * + + + + + + + + + + + + + + + + +
FileRename to
+ + + +
+ + + + +
+ + + +
+ \@formgroup.widget;noquote@ + + +
+ + + + + + + + + + +
+ + \@formerror.@elements.id@;noquote\@ + +
+
+ + +

+ + + +

+
+ + + + + + + Index: openacs-4/packages/contacts/tcl/contacts-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contacts-procs-postgresql.xql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/contacts/tcl/contacts-procs-postgresql.xql 18 May 2005 16:45:49 -0000 1.4 +++ openacs-4/packages/contacts/tcl/contacts-procs-postgresql.xql 27 May 2005 00:18:58 -0000 1.5 @@ -1,6 +1,14 @@ + + + select name + from cr_items + where parent_id = :party_id + + + select groups.group_id, Index: openacs-4/packages/contacts/tcl/contacts-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contacts-procs.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/contacts/tcl/contacts-procs.tcl 25 May 2005 02:09:52 -0000 1.4 +++ openacs-4/packages/contacts/tcl/contacts-procs.tcl 27 May 2005 00:18:58 -0000 1.5 @@ -1,6 +1,6 @@ ad_library { - Support procs for the contacts package + Support procs for the contacts package @author Matthew Geddert openacs@geddert.com @creation-date 2004-07-28 @@ -48,6 +48,42 @@ } +ad_proc -private contact::util::generate_filename { + {-title:required} + {-extension:required} + {-existing_filenames ""} + {-party_id ""} +} { + Generate a pretty filename that relates to the title supplied + + @param party_id if supplied the filenames associated with this party will be used as existing_filenames if existing filenames is not provided + + @param existing_filenames a list of filenames that the generated filename must not be equal to +} { + if { [exists_and_not_null party_id] && [string is integer $party_id] && ![exists_and_not_null existing_filenames] } { + set existing_filenames [db_list get_parties_existing_filenames {}] + } + set filename [util_text_to_url -text ${title} -replacement "_"] + set output_filename "${filename}.${extension}" + set num 1 + while { [lsearch $existing_filenames $output_filename] >= 0 } { + set output_filename "${filename}${num}.${extension}" + incr num + } + return $output_filename +} + +ad_proc -private contact::util::get_file_extension { + {-filename:required} +} { + get the file extension from a file +} { + return [lindex [split $filename "."] end] +} + + + + ad_proc -public contact::name { {-party_id:required} } { Index: openacs-4/packages/contacts/www/files-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/files-delete.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/files-delete.tcl 27 May 2005 00:18:58 -0000 1.1 @@ -0,0 +1,19 @@ +ad_page_contract { + + Update sort order + + @author Matthew Geddert openacs@geddert.com + @creation-date 2005-05-24 + @cvs-id $Id: files-delete.tcl,v 1.1 2005/05/27 00:18:58 matthewg Exp $ + +} { + item_id:multiple,notnull + party_id +} + +db_transaction { + foreach item_id $item_id { + db_dml expire_item { update cr_items set publish_status = 'expired', live_revision = NULL where item_id = :item_id } + } +} +ad_returnredirect "${party_id}/files" Index: openacs-4/packages/contacts/www/files-update.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/files-update.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/files-update.tcl 27 May 2005 00:18:58 -0000 1.1 @@ -0,0 +1,41 @@ +ad_page_contract { + + Update sort order + + @author Matthew Geddert openacs@geddert.com + @creation-date 2005-05-24 + @cvs-id $Id: files-update.tcl,v 1.1 2005/05/27 00:18:58 matthewg Exp $ + +} { + rename:array + party_id:integer,notnull +} + +set item_ids [db_list get_item_ids { select item_id from cr_items where parent_id = :party_id and publish_status = 'ready' } ] +db_transaction { + foreach item_id $item_ids { + set new_title [string trim $rename(${item_id})] + if { [exists_and_not_null new_title] } { + db_0or1row get_item_date { +select ci.name, + cr.title, + cr.mime_type, + cr.content, + cr.content_length + from cr_items ci, cr_revisions cr, acs_objects ao + where ci.parent_id = :party_id + and ci.live_revision = cr.revision_id + and cr.revision_id = ao.object_id + and ci.item_id = :item_id } + + if { $new_title != $title } { + set filename [contact::util::generate_filename -title $new_title -extension [contact::util::get_file_extension -filename $name] -party_id $party_id] + set revision_id [content::revision::new -item_id $item_id -is_live "t" -title $new_title -mime_type $mime_type] + db_dml update_revision { update cr_revisions set content = :content, content_length = :content_length where revision_id = :revision_id } + db_dml update_item { update cr_items set name = :filename where item_id = :item_id } + } + } + + } +} +ad_returnredirect "${party_id}/files" Index: openacs-4/packages/contacts/www/files.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/files.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/files.adp 27 May 2005 00:18:58 -0000 1.1 @@ -0,0 +1,10 @@ + +@party_id@ + + + + + + + + Index: openacs-4/packages/contacts/www/files.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/files.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/files.tcl 27 May 2005 00:18:58 -0000 1.1 @@ -0,0 +1,171 @@ +ad_page_contract { + + List and manage files for a contact. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2005-05-24 + @cvs-id $Id: files.tcl,v 1.1 2005/05/27 00:18:58 matthewg Exp $ +} { + {party_id:integer,notnull} + {upload_count:integer "1"} + {orderby "file,asc"} +} -validate { + contact_exists -requires {party_id} { + if { ![contact::exists_p -party_id $party_id] } { + ad_complain "The contact specified does not exist" + } + } +} + +if { $upload_count != 10 } { + set upload_count 1 +} + +set contact_name [contact::name -party_id $party_id] +set form_elements [list {party_id:integer(hidden)}] +lappend form_elements [list {upload_count:integer(hidden)}] +lappend form_elements [list {orderby:text(hidden),optional}] +set upload_number 1 +while { $upload_number <= $upload_count } { + lappend form_elements [list "upload_file${upload_number}:file(file),optional" [list label ""] [list section "section$upload_number"]] + lappend form_elements [list "upload_title${upload_number}:text(text),optional" [list html "size 45 maxlength 100"] [list label ""]] + incr upload_number +} +if { $upload_count == 1 } { set upload_label "Upload" } else { set upload_label "Done" } +lappend form_elements [list "upload:text(submit),optional" [list "label" $upload_label]] +lappend form_elements [list "upload_more:text(submit),optional" [list "label" "Upload More"]] + +ad_form -name upload_files -html {enctype multipart/form-data} -form $form_elements -on_request { +} -on_submit { + set upload_number 1 + set message [list] + while { $upload_number <= $upload_count } { + set file [set "upload_file${upload_number}"] + set title [set "upload_title${upload_number}"] + set filename [template::util::file::get_property filename $file] + if { $filename != "" } { + set tmp_filename [template::util::file::get_property tmp_filename $file] + set mime_type [template::util::file::get_property mime_type $file] + set tmp_size [file size $tmp_filename] + set extension [contact::util::get_file_extension -filename $filename] + if { ![exists_and_not_null title] } { + regsub -all ".${extension}\$" $filename "" title + } + set filename [contact::util::generate_filename -title $title -extension $extension -party_id $party_id] + set revision_id [cr_import_content -storage_type "file" -title $title $party_id $tmp_filename $tmp_size $mime_type $filename] + + content::item::set_live_revision -revision_id $revision_id + + # if the file is an image we need to create thumbnails + # + #/sw/bin/convert -gravity Center -crop 75x75+0+0 fred.jpg fred.jpg + #/sw/bin/convert -gravity Center -geometry 100x100+0+0 04055_7.jpg fred.jpg + + lappend message "$title" + } + incr upload_number + } + if { [llength $message] == 1 } { + util_user_message -html -message "The file [lindex $message 0] was successfully uploaded" + } elseif { [llength $message] > 1 } { + util_user_message -html -message "The files [join $message ", "] were successfully uploaded" + } + +} -after_submit { + if { [exists_and_not_null upload_more] } { + ad_returnredirect [export_vars -base "files" -url {{upload_count 10}}] + } else { + ad_returnredirect "files" + } + ad_script_abort +} + + + + +template::list::create \ + -html {width 100%} \ + -name "files" \ + -multirow "files" \ + -row_pretty_plural "files" \ + -checkbox_name checkbox \ + -bulk_action_export_vars [list party_id orderby] \ + -bulk_actions { + "Delete" "../files-delete" "Delete the selectted files" + "Update" "../files-update" "Update filenames" + } -selected_format "normal" \ + -key item_id \ + -elements { + file { + label {File} + display_col title + link_url_eval $file_url + } + rename { + label {Rename} + display_template { + + } + } + type { + label "Type" + display_col extension + } + creation_date { + label "Updated On" + display_col creation_date_pretty + } + creation_user { + label "Updated By" + display_col creation_user_pretty + } + } -filters { + } -orderby { + file { + label "File" + orderby_asc "upper(cr.title) asc, ao.creation_date desc" + orderby_desc "upper(cr.title) desc, ao.creation_date desc" + default_direction asc + } + creation_date { + label "Updated On" + orderby_asc "ao.creation_date asc" + orderby_desc "ao.creation_date desc" + default_direction desc + } + creation_user { + label "Updated By" + orderby_asc "upper(contact__name(ao.creation_user)) asc, upper(cr.title) asc" + orderby_desc "upper(contact__name(ao.creation_user)) desc, upper(cr.title) asc" + default_direction desc + } + default_value file,asc + } -formats { + normal { + label "Table" + layout table + row { + } + } + } + +set package_url [ad_conn package_url] +db_multirow -extend {file_url extension} -unclobber files select_files " +select ci.item_id, + ci.name, + cr.title, + to_char(ao.creation_date,'FMMon DD FMHH12:MIam') as creation_date_pretty, + contact__name(ao.creation_user) as creation_user_pretty + from cr_items ci, cr_revisions cr, acs_objects ao + where ci.parent_id = :party_id + and ci.live_revision = cr.revision_id + and cr.revision_id = ao.object_id +[template::list::orderby_clause -orderby -name "files"] +" { + set file_url "${package_url}${party_id}/files/${name}" + set extension [lindex [split $name "."] end] + +} + + +ad_return_template Index: openacs-4/packages/contacts/www/index.vuh =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/index.vuh,v diff -u -r1.1 -r1.2 --- openacs-4/packages/contacts/www/index.vuh 25 May 2005 02:09:52 -0000 1.1 +++ openacs-4/packages/contacts/www/index.vuh 27 May 2005 00:18:58 -0000 1.2 @@ -17,6 +17,8 @@ } set action [lindex $file_list 1] + + if { $party_is_contact_p } { if { [llength $file_list] == "1" } { # we need to redirect the user to their "correct" summary page otherwise @@ -28,7 +30,7 @@ if { [lsearch $valid_pages $action] >= 0 && [llength $file_list] == "2" } { switch $action { edit { set file "contact-edit" } - files { set file "contact-files" } + files { set file "files" } groups { set file "contact-groups" } relationships { set file "contact-rels" } comments { set file "comments" } @@ -45,9 +47,19 @@ rp_form_put party_id $party_id } rp_internal_redirect $file - } else { + } elseif { $action == "files" && [llength $file_list] == "3" } { + # we may have a valid file request + set item_id [content::item::get_id -root_folder_id $party_id -item_path [lindex $file_list 2]] + set revision_id [content::item::get_live_revision -item_id $item_id] + if { [exists_and_not_null revision_id] } { + cr_write_content -revision_id $revision_id + } else { + ns_returnnotfound + ad_script_abort + } + } else { ns_returnnotfound - ad_script_abort + ad_script_abort } } else { ns_returnnotfound