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.27 -r1.28 --- openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl 20 Feb 2006 09:13:58 -0000 1.27 +++ openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl 27 Feb 2006 03:46:17 -0000 1.28 @@ -146,6 +146,132 @@ } { } +ad_proc -public -callback contact::special_attributes::ad_form_values { + {-party_id:required} + {-form:required} +} { + This callback is executed last in the edit_request ad_form + block of editing a contact +} - + +ad_proc -public -callback contact::special_attributes::ad_form_save { + {-party_id:required} + {-form:required} +} { + This callback is executed first in the new_data or edit_data ad_from + blocks when creating or saving a contacts information +} - + +ad_proc -public -callback contact::special_attributes::ad_form_values -impl contacts { + -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 -callback contact::special_attributes::ad_form_save -impl contacts { + -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" + } + } +} + ad_proc -public -callback pm::project_new -impl contacts { {-package_id:required} {-project_id:required}