Index: openacs-4/packages/acs-mail-lite/lib/email.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-mail-lite/lib/Attic/email.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/acs-mail-lite/lib/email.tcl 30 Sep 2005 21:36:27 -0000 1.9 +++ openacs-4/packages/acs-mail-lite/lib/email.tcl 3 Oct 2005 19:07:59 -0000 1.10 @@ -11,7 +11,7 @@ } } -foreach optional_param {return_url content export_vars file_ids object_id no_callback_p} { +foreach optional_param {return_url content export_vars file_ids object_id} { if {![info exists $optional_param]} { set $optional_param {} } @@ -24,6 +24,10 @@ set cancel_url $return_url } +if {![info exists no_callback_p]} { + set no_callback_p f +} + # Somehow when the form is submited the party_ids values became # only one element of a list, this avoid that problem @@ -37,20 +41,44 @@ # 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) - {message_type:text(hidden) {value "email"}} - {check_uncheck:text(checkbox),multiple,optional - {label "Check/Uncheck"} - {options {{"" 1}}} - {section "[_ contacts.Recipients]"} - {html {onclick check_uncheck_boxes(this.checked)}} +set recipients_num [llength $recipients] +if { $recipients_num <= 1 } { + set form_elements { + message_id:key + return_url:text(hidden) + no_callback_p:text(hidden) + title:text(hidden),optional + {message_type:text(hidden) {value "email"}} + {to:text(checkbox),multiple + {label "[_ contacts.Recipients]"} + {options $recipients } + {html {checked 1}} + {section "[_ contacts.Recipients]"} + } + {cc:text(text),optional + {label "CC:"} + {html {size 56}} + {help_text "[_ contacts.cc_help]"} + } } - {to:text(checkbox),multiple - {label "[_ contacts.Recipients]"} - {options $recipients } - {html {checked 1}} +} else { + set form_elements { + message_id:key + return_url:text(hidden) + no_callback_p:text(hidden) + title:text(hidden),optional + {message_type:text(hidden) {value "email"}} + {check_uncheck:text(checkbox),multiple,optional + {label "[_ contacts.check_uncheck]"} + {options {{"" 1}}} + {section "[_ contacts.Recipients]"} + {html {onclick check_uncheck_boxes(this.checked)}} + } + {to:text(checkbox),multiple + {label "[_ contacts.Recipients]"} + {options $recipients } + {html {checked 1}} + } } } @@ -59,12 +87,12 @@ set files [list] foreach file $file_ids { set file_title [db_string get_file_title { select title from cr_revisions where revision_id = :file} -default "Untitled"] - lappend files "$file_title " + lappend files "$file_title " } set files [join $files ", "] append form_elements { - {files_ids:text(inform),optional {label "Associated Files:"} {value $files}} + {files_ids:text(inform),optional {label "[_ contacts.Associated_files]"} {value $files}} } } @@ -93,7 +121,7 @@ {html {size 55}} {section "[_ contacts.Message]"} } - {content:text(richtext),optional + {content_body:text(richtext),optional {label "[_ contacts.Message]"} {html {cols 55 rows 18}} {value $content_list} @@ -103,7 +131,11 @@ } } -ad_form -action [ad_conn url] \ +if { ![exists_and_not_null action] } { + set action [ad_conn url] +} + +ad_form -action $action \ -html {enctype multipart/form-data} \ -name email \ -cancel_label "[_ contacts.Cancel]" \ @@ -112,12 +144,40 @@ -form $form_elements \ -on_request { } -new_request { + 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 [ad_html_text_convert \ + -to "text/plain" \ + -from $message_info(content_format) \ + -- $message_info(content) \ + ] + 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 { } -on_submit { + # List to store know wich emails recieved the message + set recipients_addr [list] + set from [ad_conn user_id] set from_addr [cc_email_from_party $from] - template::multirow create messages message_type to_addr subject content + # Remove all spaces in cc + regsub -all " " $cc "" cc + + set cc_list [split $cc ";"] + + template::multirow create messages message_type to_addr subject content_body + # Insert the uploaded file linked under the package_id set package_id [ad_conn package_id] @@ -142,34 +202,65 @@ set date [lc_time_fmt [dt_sysdate] "%q"] set to $name set to_addr [cc_email_from_party $party_id] + lappend recipients_addr $to_addr + if {[empty_string_p $to_addr]} { - break - } + # We are going to check if this party_id has an employer and if this + # employer has an email + set employer_id [relation::get_object_two -object_id_one $party_id \ + -rel_type "contact_rels_employment"] + if { ![empty_string_p $employer_id] } { + # Get the employer email adress + set to_addr [contact::email -party_id $employer_id] + if {[empty_string_p $to_addr]} { + ad_return_error [_ contacts.Error] [_ contacts.lt_there_was_an_error_processing_this_request] + break + } + } else { + ad_return_error [_ contacts.Error] [_ contacts.lt_there_was_an_error_processing_this_request] + break + } + } set values [list] foreach element [list first_names last_name name date] { lappend values [list "{$element}" [set $element]] } - template::multirow append messages $message_type $to_addr [contact::message::interpolate -text $subject -values $values] [contact::message::interpolate -text $content -values $values] + template::multirow append messages $message_type $to_addr [contact::message::interpolate -text $subject -values $values] [contact::message::interpolate -text $content_body -values $values] # Link the file to all parties if {[exists_and_not_null revision_id]} { application_data_link::new -this_object_id $revision_id -target_object_id $party_id } } - + # Send the email to all CC in cc_list + foreach email_addr $cc_list { + set name $email_addr + set first_names [split $email_addr "@"] + set last_name $first_names + set date [lc_time_fmt [dt_sysdate] "%q"] + set to $name + set to_addr $email_addr + lappend recipients_addr $to_addr + set values [list] + foreach element [list first_names last_name name date] { + lappend values [list "{$element}" [set $element]] + } + template::multirow append messages $message_type $to_addr [contact::message::interpolate -text $subject -values $values] [contact::message::interpolate -text $content_body -values $values] + + } + template::multirow foreach messages { if {[exists_and_not_null file_ids]} { - # If the no_callback_p is set to "t" then no callback will be executed if { $no_callback_p } { acs_mail_lite::complex_send \ -to_addr $to_addr \ -from_addr "$from_addr" \ -subject "$subject" \ - -body "$content" \ + -body "$content_body" \ -package_id $package_id \ -file_ids $file_ids \ -mime_type $mime_type \ @@ -182,7 +273,7 @@ -to_addr $to_addr \ -from_addr "$from_addr" \ -subject "$subject" \ - -body "$content" \ + -body "$content_body" \ -package_id $package_id \ -file_ids $file_ids \ -mime_type $mime_type \ @@ -203,7 +294,7 @@ -to_addr $to_addr \ -from_addr "$from_addr" \ -subject "$subject" \ - -body "$content" \ + -body "$content_body" \ -package_id $package_id \ -mime_type $mime_type \ -object_id $object_id \ @@ -215,22 +306,23 @@ -to_addr $to_addr \ -from_addr "$from_addr" \ -subject "$subject" \ - -body "$content" \ + -body "$content_body" \ -package_id $package_id \ -mime_type $mime_type \ -object_id $object_id } } else { + if { [exists_and_not_null object_id] } { # If the no_callback_p is set to "t" then no callback will be executed if { $no_callback_p } { acs_mail_lite::complex_send \ -to_addr $to_addr \ -from_addr "$from_addr" \ -subject "$subject" \ - -body "$content" \ + -body "$content_body" \ -package_id $package_id \ -mime_type "text/html" \ -object_id $object_id \ @@ -241,7 +333,7 @@ -to_addr $to_addr \ -from_addr "$from_addr" \ -subject "$subject" \ - -body "$content" \ + -body "$content_body" \ -package_id $package_id \ -mime_type "text/html" \ -object_id $object_id @@ -254,7 +346,7 @@ -to_addr $to_addr \ -from_addr "$from_addr" \ -subject "$subject" \ - -body "$content" \ + -body "$content_body" \ -package_id $package_id \ -no_callback_p @@ -263,15 +355,30 @@ -to_addr $to_addr \ -from_addr "$from_addr" \ -subject "$subject" \ - -body "$content" \ + -body "$content_body" \ -package_id $package_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" + + lappend recipients "$to" + } + set recipients [join $recipients_addr ", "] + util_user_message -html -message "[_ contacts.Your_message_was_sent_to_-recipients-]" + } -after_submit { ad_returnredirect $return_url