Index: openacs-4/packages/contacts/lib/oo_mailing.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/lib/oo_mailing.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/contacts/lib/oo_mailing.tcl 28 Dec 2005 12:38:11 -0000 1.4 +++ openacs-4/packages/contacts/lib/oo_mailing.tcl 3 Jan 2006 22:14:55 -0000 1.5 @@ -39,8 +39,9 @@ set footer "" } -set spoiler_options [util::find_all_files -extension jpg -path "/web/wieners/packages/wieners/templates/spoiler"] - +set template_path "[acs_root_dir][parameter::get_from_package_key -package_key contacts -parameter OOMailingPath]" +set banner_options [util::find_all_files -extension jpg -path "${template_path}/banner"] + set date [split [dt_sysdate] "-"] append form_elements { message_id:key @@ -54,28 +55,39 @@ {date:date(date) {label "[_ contacts.Date]"} } - {spoiler:text(select),optional - {label "[_ contacts.Spoiler]"} - {help_text "[_ contacts.Spoiler_help_text]"} - {options $spoiler_options} + {banner:text(select),optional + {label "[_ contacts.Banner]"} + {help_text "[_ contacts.Banner_help_text]"} + {options $banner_options} + {section "[_ contacts.oo_message]"} } {content:richtext(richtext) - {label "[_ contacts.Message]"} + {label "[_ contacts.oo_message]"} {html {cols 70 rows 24}} - {help_text {[_ contacts.lt_remember_that_you_can]}} + {help_text {[_ contacts.oo_content_help]}} } {ps:text(text),optional {label "[_ contacts.PS]"} {help_text "[_ contacts.PS_help_text]"} {html {size 45 maxlength 1000}} } + {subject:text(text),optional + {label "[_ contacts.Subject]"} + {html {size 55}} + {section "[_ contacts.oo_email_content]"} + {help_text {[_ contacts.oo_email_subject_help]}} + } + {email_content:text(textarea),optional + {label "[_ contacts.oo_email_content]"} + {html {cols 65 rows 12}} + {help_text {[_ contacts.oo_email_help]}} + } } ad_form -action message \ -name letter \ -cancel_label "[_ contacts.Cancel]" \ -cancel_url $return_url \ - -edit_buttons [list [list [_ contacts.Print] print]] \ -form $form_elements \ -on_request { } -new_request { @@ -90,7 +102,7 @@ set content [list $content $message_info(content_format)] set title $message_info(title) set ps $message_info(ps) - set spoiler $message_info(spoiler) + set banner $message_info(banner) } else { if { [exists_and_not_null signature] } { set content [list $signature "text/html"] @@ -99,6 +111,7 @@ set paper_type "letterhead" } -edit_request { } -on_submit { + # Make sure the content actually exists set content_raw [string trim \ [ad_html_text_convert \ @@ -110,17 +123,21 @@ if {$content_raw == "" } { template::element set_error message content "[_ contacts.Message_is_required]" } - + # Now parse the content for openoffice set content_format [template::util::richtext::get_property format $content] set content [contact::oo::convert -content [string trim [template::util::richtext::get_property content $content]]] - + # Retrieve information about the user so it can be used in the template set user_id [ad_conn user_id] if {![contact::employee::get -employee_id $user_id -array user_info]} { ad_return_error $user_id "User is not an employee" } + template::multirow create messages revision_id to_addr to_party_id subject content_body + + set file_revisions [list] + foreach party_id $party_ids { # get the user information if {[contact::employee::get -employee_id $party_id -array employee]} { @@ -130,42 +147,98 @@ ad_return_error [_ contacts.Error] [_ contacts.lt_there_was_an_error_processing_this_request] break } - - set file [open "/web/wieners/vorlage.xml"] + + set file [open "${template_path}/content.xml"] fconfigure $file -translation binary set template_content [read $file] close $file + set file [open "${template_path}/styles.xml"] + fconfigure $file -translation binary + set style_content [read $file] + close $file + eval [template::adp_compile -string $template_content] - set letter $__adp_output + set content $__adp_output - set odt_filename [contact::oo::change_content -document_filename "vorlage.odt" -path "/web" -contents [list "content.xml" "$letter"]] - set revision_id [contact::oo::import_oo_pdf -oo_file $odt_filename -parent_id $party_id] + eval [template::adp_compile -string $style_content] + set style $__adp_output + set odt_filename [contact::oo::change_content -path "${template_path}" -document_filename "document.odt" -contents [list "content.xml" $content "styles.xml" $style]] + + set item_id [contact::oo::import_oo_pdf -oo_file $odt_filename -parent_id $party_id -title "${title}.pdf"] + set revision_id [content::item::get_best_revision -item_id $item_id] + lappend file_revisions $revision_id + + # Now we need to find a way to join all these files. Probably using a new procedure to join all the revision ids + + # Subject is set => we send an email. + if {$subject ne ""} { + + # Differentiate between person and organization + if {[person::person_p -party_id $party_id]} { + contact::employee::get -employee_id $party_id -array employee + set first_names $employee(first_names) + set last_name $employee(last_name) + set name "$first_names $last_name" + set salutation $employee(salutation) + set locale $employee(locale) + set to_addr $employee(email) + } else { + set name [contact::name -party_id $party_id] + set to_addr [cc_email_from_party $party_id] + set salutation "Dear ladies and gentlemen" + set locale [lang::user::site_wide_locale -user_id $party_id] + } + set date [lc_time_fmt [dt_sysdate] "%q"] + + set values [list] + foreach element [list first_names last_name name date salutation] { + lappend values [list "{$element}" [set $element]] + } + + # We are going to create a multirow which knows about the file (revision_id) and contains + # the parsed e-mail. + template::multirow append messages $revision_id $to_addr "" [contact::message::interpolate -text $subject -values $values] [contact::message::interpolate -text $email_content -values $values] + } + + # Log that we have been sending this oo-mailing contact::message::log \ -message_type "oo_mailing" \ -sender_id $user_id \ -recipient_id $party_id \ -title $title \ -description "" \ - -content $letter \ + -content $content \ -content_format "text/html" + } - } - + if {$subject ne ""} { + set from [ad_conn user_id] + set from_addr [cc_email_from_party $from] + set package_id [ad_conn package_id] - # onLoad=\"window.print()\" - ns_return 200 text/html " - - -[_ contacts.Print_Letter] - - -$letter - - - -" - ad_script_abort + template::multirow foreach messages { + + ad_return_error "toaddr" "$to_addr" + # Send the e-mail to each of the users + acs_mail_lite::complex_send \ + -to_addr $to_addr \ + -from_addr "$from_addr" \ + -subject "$subject" \ + -body "$content_body" \ + -package_id $package_id \ + -file_ids $revision_id \ + -mime_type "text/plain" \ + -object_id $item_id + } + } else { + + # We are not sending the e-mail but write the file back to the user + if {[llength $file_revisions]==1} { + cr_write_content -revision_id [lindex $file_revisions 0] + } + } + ad_returnredirect "/contacts/$party_id" }