Index: openacs-4/packages/contacts/tcl/contact-message-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contact-message-procs.tcl,v diff -u -r1.33 -r1.34 --- openacs-4/packages/contacts/tcl/contact-message-procs.tcl 28 Oct 2006 16:51:50 -0000 1.33 +++ openacs-4/packages/contacts/tcl/contact-message-procs.tcl 14 Dec 2006 09:12:12 -0000 1.34 @@ -47,6 +47,7 @@ {-locale ""} {-banner ""} {-ps ""} + {-oo_template ""} {-package_id ""} } { save a contact message @@ -72,9 +73,9 @@ db_dml insert_into_message_items { insert into contact_message_items - ( item_id, owner_id, message_type, locale, banner, ps ) + ( item_id, owner_id, message_type, locale, banner, ps, oo_template ) values - ( :item_id, :owner_id, :message_type, :locale, :banner, :ps ) + ( :item_id, :owner_id, :message_type, :locale, :banner, :ps, :oo_template ) } # contact item new does not set the package_id in acs_object so # we do it here @@ -86,7 +87,7 @@ } else { db_dml update_message_item { - update contact_message_items set owner_id = :owner_id, message_type = :message_type, locale = :locale, banner = :banner, ps = :ps where item_id = :item_id + update contact_message_items set owner_id = :owner_id, message_type = :message_type, locale = :locale, banner = :banner, ps = :ps, oo_template = :oo_template where item_id = :item_id } } 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.51 -r1.52 --- openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl 13 Dec 2006 13:03:53 -0000 1.51 +++ openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl 14 Dec 2006 09:12:12 -0000 1.52 @@ -1129,3 +1129,77 @@ } } } + +# +# This is an example of how you can extend the entry forms. +# + +ad_proc -public -callback contact::contact_form -impl wieners { + {-package_id:required} + {-form:required} + {-object_type:required} + {-party_id} + {-group_ids ""} + {-rel_type ""} +} { + add locale form element for persons +} { + + # Allow for organizations and persons to set the locale + set list_of_locales [list] + db_foreach locale_loop { + select label, locale + from enabled_locales + order by label + } { + + if {[lang::message::message_exists_p $locale acs-lang.this-language]} { + set label [lang::message::lookup $locale acs-lang.this-language] + } + lappend list_of_locales [list $label $locale] + } + + if {[exists_and_not_null party_id]} { + set locale [lang::user::site_wide_locale -user_id $party_id] + } + + if { ![exists_and_not_null locale] } { + set locale [lang::system::site_wide_locale] + } + + ad_form -extend -name $form -form { + {locale:text(select),optional {label "[_ contacts.preferred_locale]"} {options $list_of_locales} {value $locale}} + } +} + +ad_proc -public -callback contact::special_attributes::ad_form_save -impl contacts { + {-form:required} + {-party:required} +} { + set locale for a new party +} { + upvar locale locale + + # get defaults for locale if locale is empty / not set + if { ![exists_and_not_null locale] } { + if {[exists_and_not_null party_id]} { + set locale [lang::user::site_wide_locale -user_id $party_id] + } + if { ![exists_and_not_null locale] } { + set locale [lang::system::site_wide_locale] + } + } + #--- + + # Create the entry in user_preferences. + # This only works if we drop the constraint on users. + db_dml insert_preference { + insert into user_preferences (user_id, locale) + select :party_id as user_id, :locale as locale + from dual + where not exists (select 1 from user_preferences where user_id = :party_id) + } + if {[exists_and_not_null locale]} { + lang::user::set_locale -user_id $party_id $locale + } +} \ No newline at end of file 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.102 -r1.103 --- openacs-4/packages/contacts/tcl/contacts-procs.tcl 14 Dec 2006 07:57:11 -0000 1.102 +++ openacs-4/packages/contacts/tcl/contacts-procs.tcl 14 Dec 2006 09:12:12 -0000 1.103 @@ -114,6 +114,7 @@ } ad_proc -private contacts::sweeper { + {-contacts_package_ids ""} } { So that contacts searches work correctly, and quickly every person or organization in the system @@ -124,28 +125,37 @@ by contacts (ones created by contacts automatically get associated item_id and live_revisions. } { - - set contact_package_ids [apm_package_ids_from_key -package_key "contacts" -mounted] - foreach contact_package_id $contact_package_ids { + if {$contacts_package_ids eq ""} { + set contacts_package_ids [apm_package_ids_from_key -package_key "contacts" -mounted] + } + foreach contact_package_id $contacts_package_ids { set default_group_id [contacts::default_group -package_id $contact_package_id] set contact_package($default_group_id) $contact_package_id lappend default_groups $default_group_id } # Try to insert the persons into the package_id of the first group found db_foreach get_persons_without_items {} { + foreach group_id $default_groups { if {[group::party_member_p -party_id $person_id -group_id $group_id]} { ns_log notice "contacts::sweeper creating content_item and content_revision for party_id: $person_id" - contact::revision::new -party_id $person_id -package_id $contact_package($group_id) + set contact_revision_id [contact::revision::new -party_id $person_id -package_id $contact_package($group_id)] break } } - # We did not found a group, so just use the first contacts instance. - ns_log notice "contacts::sweeper creating content_item and content_revision for party_id: $person_id" - contact::revision::new -party_id $person_id -package_id $contact_package_id - + if {$contact_revision_id eq ""} { + # We did not found a group, so just use the first contacts instance. + ns_log notice "contacts::sweeper creating content_item and content_revision for party_id: $person_id" + set contact_revision_id [contact::revision::new -party_id $person_id -package_id $contact_package_id] + } + + # Add the default ams attributes + ams::attribute::save::text -object_type "person" -object_id $contact_revision_id -attribute_name "first_names" -value $first_names + ams::attribute::save::text -object_type "person" -object_id $contact_revision_id -attribute_name "last_name" -value $last_name + ams::attribute::save::text -object_type "person" -object_id $contact_revision_id -attribute_name "email" -value $email + # And insert into the default group for this package. group::add_member -user_id $person_id -group_id $default_group_id }