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} 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.63 -r1.64 --- openacs-4/packages/contacts/tcl/contacts-procs.tcl 20 Feb 2006 21:24:21 -0000 1.63 +++ openacs-4/packages/contacts/tcl/contacts-procs.tcl 27 Feb 2006 03:46:17 -0000 1.64 @@ -12,7 +12,6 @@ namespace eval contact::util:: {} namespace eval contact::group:: {} namespace eval contact::revision:: {} -namespace eval contact::special_attributes:: {} namespace eval contact::rels:: {} namespace eval contact::employee {} @@ -633,11 +632,15 @@ ad_proc -public contact::url { {-party_id:required} + {-package_id ""} } { create a contact revision } { -# return "[apm_package_url_from_id [apm_package_id_from_key "contacts"]]$party_id/" - return "[ad_conn package_url]${party_id}/" + if { [exists_and_not_null package_id] } { + return "[apm_package_url_from_id $package_id]${party_id}/" + } else { + return "[ad_conn package_url]${party_id}/" + } } ad_proc -public contact::revision::new { @@ -848,116 +851,6 @@ } } -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" - } - } -} - ad_proc -public contacts::get_values { {-attribute_name ""} {-group_name ""} Index: openacs-4/packages/contacts/www/contact-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-add.tcl,v diff -u -r1.43 -r1.44 --- openacs-4/packages/contacts/www/contact-add.tcl 16 Feb 2006 15:44:59 -0000 1.43 +++ openacs-4/packages/contacts/www/contact-add.tcl 27 Feb 2006 03:46:17 -0000 1.44 @@ -267,7 +267,7 @@ # Save the contact information # No clue why this is not part of the db_transaction though .... - contact::special_attributes::ad_form_save -party_id $party_id -form "party_ae" + callback contact::special_attributes::ad_form_save -party_id $party_id -form "party_ae" set revision_id [contact::revision::new -party_id $party_id] foreach group_id $group_ids { ams::ad_form::save -package_key "contacts" \ Index: openacs-4/packages/contacts/www/contact-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-edit.tcl,v diff -u -r1.16 -r1.17 --- openacs-4/packages/contacts/www/contact-edit.tcl 15 Feb 2006 10:06:36 -0000 1.16 +++ openacs-4/packages/contacts/www/contact-edit.tcl 27 Feb 2006 03:46:17 -0000 1.17 @@ -90,7 +90,7 @@ -form_name "party_ae" \ -object_id $revision_id } - contact::special_attributes::ad_form_values -party_id $party_id -form "party_ae" + callback contact::special_attributes::ad_form_values -party_id $party_id -form "party_ae" } -on_submit { @@ -118,7 +118,7 @@ } -new_data { } -edit_data { - contact::special_attributes::ad_form_save -party_id $party_id -form "party_ae" + callback contact::special_attributes::ad_form_save -party_id $party_id -form "party_ae" set revision_id [contact::revision::new -party_id $party_id]