Index: openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl,v diff -u -r1.29 -r1.30 --- openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl 12 Mar 2006 00:35:33 -0000 1.29 +++ openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl 12 Mar 2006 14:43:03 -0000 1.30 @@ -346,6 +346,16 @@ } -default ""] if {[empty_string_p $project_id]} { + set project_id [db_string get_linked_project_id { + select r.object_id_two as project_id + from acs_data_links r, cr_items p + where r.object_id_one = :folder_id + and r.object_id_two = p.item_id + and p.content_type = 'pm_project' + } -default ""] + } + + if {[empty_string_p $project_id]} { # no project -> mail to all organization contacts set contact_organizations [application_data_link::get_linked -from_object_id $community_id -to_object_type "organization"] set contact_list "" @@ -368,10 +378,12 @@ upvar $bulk_variable local_var upvar $var_export_list local_list upvar party_ids contact_ids_loc + upvar return_url return_url_loc + set return_url_loc "[ad_conn url]?[ad_conn query]" set contact_ids_loc $contact_list lappend local_var "[_ contacts.Mail_to_contact]" "/contacts/message" "[_ contacts.Mail_to_contact]" - lappend local_list "party_ids" + lappend local_list "party_ids" "return_url" # Add the message type automatically # lappend local_list "message_type" 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.67 -r1.68 --- openacs-4/packages/contacts/tcl/contacts-procs.tcl 10 Mar 2006 20:07:11 -0000 1.67 +++ openacs-4/packages/contacts/tcl/contacts-procs.tcl 12 Mar 2006 14:43:03 -0000 1.68 @@ -533,6 +533,12 @@ } { Flush memorized information related to this contact } { + util_memoize_flush "::contact::message::email_address_exists_p_not_cached -party_id $party_id" + util_memoize_flush "::contact::message::mailing_address_exists_p_not_cached -party_id $party_id" + util_memoize_flush "::contact::name_not_cached -party_id $party_id" + util_memoize_flush "::contact::email_not_cached -party_id $party_id" + util_memoize_flush_regexp "::contact::employee::get_not_cached -employee_id $party_id *" + util_memoize_flush_regexp "::contact::employee_not_cached -employee_id $party_id" util_memoize_flush_regexp "contact(.*?)-party_id ${party_id}" util_memoize_flush_regexp "contact(.*?)-employee_id ${party_id}" } @@ -923,6 +929,117 @@ } } +ad_proc -public contact::special_attributes::ad_form_values { + -party_id:required + -form:required +} { +} { + set object_type [contact::type -party_id $party_id] + + db_1row get_extra_info { + select email, url + from parties + where party_id = :party_id} + set element_list [list email url] + + if { [lsearch [list person user] $object_type] >= 0 } { + + array set person [person::get -person_id $party_id] + set first_names $person(first_names) + set last_name $person(last_name) + + lappend element_list first_names last_name + } elseif {$object_type == "organization" } { + + db_0or1row get_org_info { + select name, legal_name, reg_number, notes + from organizations + where organization_id = :party_id} + lappend element_list name legal_name reg_number notes + } + + foreach element $element_list { + if {[exists_and_not_null $element]} { + if {[template::element::exists $form $element]} { + template::element::set_value $form $element [set $element] + } + } + } +} + +ad_proc -public contact::special_attributes::ad_form_save { + -party_id:required + -form:required +} { +} { + set object_type [contact::type -party_id $party_id] + set element_list [list email url] + if { [lsearch [list person user] $object_type] >= 0 } { + lappend element_list first_names last_name + } elseif {$object_type == "organization" } { + lappend element_list name legal_name reg_number notes + } + foreach element $element_list { + if {[template::element::exists $form $element]} { + set value [template::element::get_value $form $element] + switch $element { + email { + if {[db_0or1row party_is_user_p {select '1' from users where user_id = :party_id}]} { + if {[exists_and_not_null value]} { + set username $value + } else { + set username $party_id + } + acs_user::update -user_id $party_id -username $username + } + party::update -party_id $party_id -email $value -url [db_string get_url {select url from parties where party_id = :party_id} -default {}] + } + url { + party::update -party_id $party_id -email [db_string get_email {select email from parties where party_id = :party_id} -default {}] -url $value + } + default { + set $element $value + } + } + } + } + if { [lsearch [list person user] $object_type] >= 0 } { + + # first_names and last_name are required + + if {[exists_and_not_null first_names] + && [exists_and_not_null last_name]} { + person::update -person_id $party_id -first_names $first_names -last_name $last_name + } else { + if {![exists_and_not_null first_names]} { + error "The object type was person but first_names (a required element) did not exist" + } + if {![exists_and_not_null last_name]} { + error "The object type was person but first_names (a required element) did not exist" + } + } + } elseif {$object_type == "organization" } { + + # name is required + + if {[exists_and_not_null name]} { + if {![exists_and_not_null legal_name]} {set legal_name "" } + if {![exists_and_not_null reg_number]} {set reg_number "" } + if {![exists_and_not_null notes]} {set notes "" } + db_dml update_org { + update organizations + set name = :name, + legal_name = :legal_name, + reg_number = :reg_number, + notes = :notes + where organization_id = :party_id} + } else { + error "The object type was organization but name (a required element) did not exist" + } + } + contact::flush -party_id $party_id +} + ad_proc -public contacts::get_values { {-attribute_name ""} {-group_name ""} Index: openacs-4/packages/contacts/www/message.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/message.tcl,v diff -u -r1.27 -r1.28 --- openacs-4/packages/contacts/www/message.tcl 20 Feb 2006 09:13:58 -0000 1.27 +++ openacs-4/packages/contacts/www/message.tcl 12 Mar 2006 14:43:04 -0000 1.28 @@ -6,8 +6,8 @@ @cvs-id $Id$ } { {object_id:integer,multiple,optional} - {party_id:integer,multiple,optional} - {party_ids:optional} + {party_id:multiple,optional} + {party_ids ""} {message_type ""} {message:optional} {header_id:integer ""} @@ -22,6 +22,7 @@ {to:integer,multiple,optional ""} {page:optional 1} {context_id:integer ""} + {cc ""} } -validate { valid_message_type -requires {message_type} { if { ![db_0or1row check_for_it { select 1 from contact_message_types where message_type = :message_type and message_type not in ('header','footer') }] } { @@ -35,22 +36,38 @@ set item_id [lindex [split $message "."] 1] } -if { [exists_and_not_null party_id] } { +if {[empty_string_p $party_ids]} { set party_ids [list] - foreach party_id $party_id { - lappend party_ids $party_id +} + +if { [exists_and_not_null party_id] } { + foreach p_id $party_id { + lappend party_ids $p_id } } if { [exists_and_not_null to] } { - set party_ids [list] foreach party_id $to { lappend party_ids $party_id } } + +if { [exists_and_not_null cc] } { + foreach email $cc { + set email_party_id [party::get_by_email -email $email] + lappend party_ids $email_party_id + } + + # We might not have a party_id + if {![exists_and_not_null party_id]} { + set party_id $email_party_id + } +} + foreach id $party_ids { contact::require_visiblity -party_id $id } + set party_count [llength $party_ids] set title "[_ contacts.Messages]" set user_id [ad_conn user_id]