Index: openacs-4/packages/contacts/lib/email_group.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/lib/Attic/email_group.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/lib/email_group.adp 23 Jun 2007 10:18:17 -0000 1.1 @@ -0,0 +1,10 @@ + + Index: openacs-4/packages/contacts/lib/email_group.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/lib/Attic/email_group.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/lib/email_group.tcl 23 Jun 2007 10:18:17 -0000 1.1 @@ -0,0 +1,333 @@ +# packages/contacts/lib/email.tcl +# Template for email inclusion +# @author Malte Sussdorff (sussdorff@sussdorff.de) +# @creation-date 2005-06-14 +# @arch-tag: 48fe00a8-a527-4848-b5de-0f76dfb60291 +# @cvs-id $Id: email_group.tcl,v 1.1 2007/06/23 10:18:17 maltes Exp $ + +foreach required_param {group_id} { + if {![info exists $required_param]} { + return -code error "$required_param is a required parameter." + } +} + +foreach optional_param {return_url content export_vars file_ids cc bcc item_id context_id} { + if {![info exists $optional_param]} { + set $optional_param {} + } +} + +if {![info exists cancel_url]} { + set cancel_url $return_url +} + +if {![info exists no_callback_p]} { + set no_callback_p f +} + +# The element check_uncheck only calls a javascript function +# to check or uncheck all recipients +set form_elements { + message_id:key + return_url:text(hidden) + no_callback_p:text(hidden) + title:text(hidden),optional + group_id:text(hidden) + {message_type:text(hidden) {value "email"}} + {-section "sec1" {legendtext "[_ contacts.Recipients]"}} + {recipients:text(inform) + {label "[_ contacts.Recipients]"} + {value "$recipients"} + } + {cc:text(text),optional + {label "[_ contacts.CC]:"} + {html {size 60}} + {help_text "[_ contacts.cc_help]"} + } + {bcc:text(text),optional + {label "[_ acs-mail-lite.BCC]:"} + {html {size 60}} + {help_text "[_ contacts.cc_help]"} + } +} + +# Set single_email_p in the form +set single_email_p 0 + +# Get the list of files from the file storage folder +set file_folder_id [parameter::get_from_package_key -package_key "acs-mail-lite" -parameter "FolderID"] +if {![string eq "" $file_folder_id]} { + # get the list of files in an option + set file_options [db_list_of_lists files { + select r.title, i.item_id + from cr_items i, cr_revisions r + where i.parent_id = :file_folder_id + and i.content_type = 'file_storage_object' + and r.revision_id = i.latest_revision + }] + if {![string eq "" $file_options]} { + append form_elements { + {files_extend:text(checkbox),optional + {label "[_ acs-mail-lite.Additional_files]"} + {options $file_options} + } + } + } +} + +# See if the contacts and mail-tracking packages are installed. +set contacts_p [apm_package_installed_p "contacts"] +set tracking_p [apm_package_installed_p "mail-tracking"] + +if { [exists_and_not_null file_ids] } { + set files [list] + foreach file $file_ids { + set file_item_id [content::revision::item_id -revision_id $file] + if {$file_item_id eq ""} { + set file_item_id $file + } + set file_title [lang::util::localize [content::item::get_title -item_id $file_item_id]] + if {[empty_string_p $file_title]} { + set file_title "empty" + } + if { $tracking_p } { + lappend files "$file_title " + } else { + lappend files "$file_title " + } + } + set files [join $files ", "] + + append form_elements { + {file_ids:text(hidden) {value $file_ids}} + {context_id:text(hidden) {value $context_id}} + {files:text(inform),optional {label "[_ acs-mail-lite.Associated_files]"} {value $files}} + } +} + +foreach var $export_vars { + upvar $var var_value + + # We need to split to construct the element with two lappends + # becasue if we put something like this {value $value} the value + # of the variable is not interpreted + + set element [list] + lappend element "${var}:text(hidden)" + lappend element "value $var_value" + + # Adding the element to the form + lappend form_elements $element +} + +if {![exists_and_not_null mime_type]} { + set mime_type text/plain +} + +set content_list [list $content $mime_type] + +append form_elements { + {-section "sec2" {legendtext "[_ contacts.Message]"}} + {subject:text(text),optional + {label "[_ contacts.Subject]"} + {html {size 60}} + } + {content_body:richtext(richtext),optional + {label "[_ contacts.Message]"} + {html {cols 80 rows 18}} + {help_text "[_ contacts.lt_remember_that_you_can]"} + {value $content_list} + } + {upload_file:file(file),optional + {label "[_ contacts.Upload_file]"} + } + {mail_through_p:integer(radio) + {label "[_ contacts.Mail_through_p]"} + {options {{"Yes" "1"} {"No" "0"}}} + {value "1"} + {help_text "[_ contacts.lt_Mail_through_p_help]"} + } +} + +if { [exists_and_not_null item_id] } { + append form_elements { + {item_id:text(hidden),optional + {value $item_id} + } + } +} + +if { ![exists_and_not_null action] } { + set action [ad_conn url] +} + +set edit_buttons [list [list [_ contacts.Send] send]] + +ad_form -action $action \ + -html {enctype multipart/form-data} \ + -name email \ + -cancel_label "[_ acs-kernel.common_Cancel]" \ + -cancel_url $cancel_url \ + -edit_buttons $edit_buttons \ + -form $form_elements \ + -on_request { + } -new_request { + if {![exists_and_not_null mime_type]} { + set mime_type "text/html" + } + + if {[exists_and_not_null folder_id] } { + callback contacts::email_subject -folder_id $folder_id + } + if {[exists_and_not_null item_id] } { + contact::message::get -item_id $item_id -array message_info + set subject $message_info(description) + set content_body [list $message_info(content) $message_info(content_format)] + set title $message_info(title) + } + if {[exists_and_not_null signature_id] } { + set signature [contact::signature::get -signature_id $signature_id] + if { [exists_and_not_null signature] } { + append content_body "{

$signature } text/html" + } + } + } -edit_request { + if {![exists_and_not_null mime_type]} { + set mime_type "text/html" + } + + } -on_submit { + + # We get the attribute_id of the salutation attribute + set attribute_id [attribute::id -object_type "person" -attribute_name "salutation"] + + # List to store know wich emails recieved the message + set recipients_addr [list] + + set from [ad_conn user_id] + set from_addr [contact::email -party_id $from] + + # Remove all spaces in cc and bcc + regsub -all " " $cc "" cc + regsub -all " " $bcc "" bcc + + set cc_list [split $cc ";"] + set bcc_list [split $bcc ";"] + + set mime_type [template::util::richtext::get_property format $content_body] + set content_body [template::util::richtext::get_property contents $content_body] + + + # Insert the uploaded file linked under the package_id + set package_id [ad_conn package_id] + + if {![empty_string_p $upload_file] } { + set revision_id [content::item::upload_file \ + -package_id $package_id \ + -upload_file $upload_file \ + -parent_id $party_id] + + lappend file_ids $revision_id + } + + # Append the additional files + if {[exists_and_not_null files_extend]} { + foreach file_id $files_extend { + lappend file_ids $file_id + } + } + + + # Send the mail to all parties. + ns_log Notice "Recipients: $group_id" + foreach party_id [group::get_members -group_id $group_id] { + + # Differentiate between person and organization + if {[person::person_p -party_id $party_id]} { + set salutation [contact::salutation -party_id $party_id] + db_1row names "select first_names, last_name from persons where person_id = :party_id" + set name "$first_names $last_name" + } else { + set name [contact::name -party_id $party_id] + set salutation "Dear ladies and gentlemen" + # the following is a hot fix (nfl 2006/10/20) + set first_names "" + set last_name "" + } + + + set date [lc_time_fmt [dt_sysdate] "%q"] + + set values [list] + foreach element [list first_names last_name salutation name date] { + lappend values [list "{$element}" [set $element]] + } + + set subject [contact::message::interpolate -text $subject -values $values] + + set content_body [contact::message::interpolate -text $content_body -values $values] + + # If we are doing mail through for tracking purposes + # Set the reply_to_addr accordingly + if {$mail_through_p} { + regsub -all {@} $from_addr {#} reply_to + set reply_to_addr "${reply_to}@[acs_mail_lite::address_domain]" + } else { + set reply_to_addr $from_addr + } + + ns_log Notice "Recipients: $party_id" + + acs_mail_lite::complex_send \ + -to_party_ids $party_id \ + -cc_addr $cc_list \ + -bcc_addr $bcc_list \ + -from_addr "$from_addr" \ + -reply_to "$reply_to_addr" \ + -subject "$subject" \ + -body "$content_body" \ + -package_id $package_id \ + -file_ids $file_ids \ + -mime_type $mime_type \ + -object_id $context_id \ + -no_callback_p $no_callback_p \ + -single_email + + # Link the files to all parties + if {[exists_and_not_null revision_id]} { + application_data_link::new -this_object_id $revision_id -target_object_id $party_id + } + + # Log the sending of the mail in contacts history + if { ![empty_string_p $item_id]} { + + contact::message::log \ + -message_type "email" \ + -sender_id $from \ + -recipient_id $party_id \ + -title $title \ + -description $subject \ + -content $content_body \ + -content_format "text/plain" \ + -item_id "$item_id" + + } + } + + ad_returnredirect $return_url + + # Prepare the user message + foreach cc_addr [concat $cc_list $bcc_list] { + set cc_id [party::get_by_email -email $cc_addr] + if {$cc_id eq ""} { + lappend recipients $cc_addr + } else { + lappend recipients "[contact::name -party_id $cc_id]" + } + } + util_user_message -html -message "[_ contacts.Your_message_was_sent_to_-recipients-]" + + } -after_submit { + ad_script_abort + } + Index: openacs-4/packages/contacts/www/message.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/message.adp,v diff -u -N -r1.26 -r1.27 --- openacs-4/packages/contacts/www/message.adp 28 Nov 2006 17:33:41 -0000 1.26 +++ openacs-4/packages/contacts/www/message.adp 23 Jun 2007 10:18:17 -0000 1.27 @@ -11,7 +11,7 @@ ${contact_name}" - set sort_key [string toupper $contact_name] - # Check if the party has a valid e-mail address we can send to - lappend recipients [list $contact_name $party_id $contact_link] -} - -set sorted_recipients [ams::util::sort_list_of_lists -list $recipients] set recipients [list] set invalid_recipients [list] set party_ids [list] - -foreach recipient $sorted_recipients { - set party_id [lindex $recipient 1] - set contact_link [lindex $recipient 2] +# Make sure that we can actually send the message +foreach party_id $valid_party_ids { if { [lsearch [list "letter" "label" "envelope"] $message_type] >= 0 } { # Check if we can send a letter to this party set letter_p [contact::message::mailing_address_exists_p -party_id $party_id] if { $letter_p } { lappend party_ids $party_id - lappend recipients $contact_link } else { lappend invalid_party_ids $party_id - lappend invalid_recipients $contact_link } } elseif { $message_type == "email" } { @@ -127,27 +120,43 @@ set emp_addr [contact::email -party_id $employer_id] if { ![empty_string_p $emp_addr] } { lappend party_ids $employer_id - lappend recipients $contact_link } else { lappend invalid_party_ids $party_id - lappend invalid_recipients $contact_link } } else { lappend invalid_party_ids $party_id - lappend invalid_recipients $contact_link } } else { lappend party_ids $party_id - lappend recipients $contact_link } } else { # We are unsure what to send, so just assume for the time being we can send it to them lappend party_ids $party_id - lappend recipients $contact_link } } +# If we are passing in a group, do not show the individual users +if { [empty_string_p $group_id] } { + + # Prepare the recipients + foreach party_id $party_ids { + set contact_name [contact::name -party_id $party_id] + set contact_url [contact::url -party_id $party_id] + lappend recipients "${contact_name}" + } + +} else { + lappend recipients "[group::title -group_id $group_id]" +} + +# Deal with the invalid recipients +foreach party_id $invalid_party_ids { + set contact_name [contact::name -party_id $party_id] + set contact_url [contact::url -party_id $party_id] + lappend invalid_recipients "${contact_name}" +} + set recipients [join $recipients ", "] set invalid_recipients [join $invalid_recipients ", "] if { [llength $invalid_recipients] > 0 } { @@ -199,6 +208,7 @@ set form_elements { file_ids:text(hidden) party_ids:text(hidden) + group_id:text(hidden) return_url:text(hidden) folder_id:text(hidden) object_id:text(hidden) @@ -218,10 +228,8 @@ set message_type [lindex $op 1] if { [lsearch [list "header" "footer"] $message_type] < 0 } { lappend message_options [list "-- [_ contacts.New] [lindex $op 0] --" $message_type] - } else { - set ${message_type}_options [list [list [_ contacts.--none--] ""]] } - + # set email_text and letter_text and others in the future set "${message_type}_text" [lindex $op 0] } @@ -274,12 +282,19 @@ } else { set title [_ contacts.create_$message_type] + + if {$group_id ne ""} { + # Get the group template + set message_src "/packages/contacts/lib/${message_type}_group" + } else { + set message_src "/packages/contacts/lib/${message_type}" + } } set context [list $title] if { [string is false [exists_and_not_null message]] } { - set signature_list [list [list [_ contacts.--none--] ""]] + set signature_list [list] set reset_title $title set reset_signature_id $signature_id db_foreach signatures "select title, signature_id, default_p @@ -293,10 +308,12 @@ } set title $reset_title set signature_id $reset_signature_id - append form_elements { - {signature_id:text(select) - {label "[_ contacts.Signature]"} - {options {$signature_list}} + if {$signature_list ne ""} { + append form_elements { + {signature_id:text(select) + {label "[_ contacts.Signature]"} + {options {$signature_list}} + } } } } @@ -311,7 +328,7 @@ set edit_buttons [list [list "[_ contacts.Next]" create]] -# the message form will rest party_ids so we need to carry it over +# the message form will reset party_ids so we need to carry it over set new_party_ids $party_ids ad_form -action message \ -name message \