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.1.2.3 -r1.1.2.4 --- openacs-4/packages/contacts/tcl/contacts-procs.tcl 18 Aug 2004 20:03:11 -0000 1.1.2.3 +++ openacs-4/packages/contacts/tcl/contacts-procs.tcl 19 Aug 2004 01:02:10 -0000 1.1.2.4 @@ -146,8 +146,30 @@ return $sort_first_names } + ad_proc -public custom_field_list { + party_id + } { + set custom_field_list [list email url] + set object_type [contact::get::object_type $party_id] + if { $object_type == "organization" } { + lappend custom_field_list "organization_type" + lappend custom_field_list "organization_name" + lappend custom_field_list "legal_name" + lappend custom_field_list "reg_number" + } + if { $object_type == "person" } { + lappend custom_field_list "first_names" + lappend custom_field_list "last_name" + } + return $custom_field_list } + + +} + + + namespace eval contacts::util:: { ad_proc -public party_is_user_p { @@ -186,7 +208,7 @@ # some of this codes was borrowed from the directory module - ad_proc letter_bar { + ad_proc -public letter_bar { {-export_vars ""} {-letter ""} {-initial_list:required} @@ -218,18 +240,27 @@ return "[join $html_list " | "]" } + + ad_proc -public sqlify_list { + variable_list + } { + set output_list {} + foreach item $variable_list { + if { [exists_and_not_null output_list] } { + append output_list ", " + } + append output_list "'$item'" + } + return $output_list + } + } - - - - - - namespace eval contacts::get { + ad_proc -public ad_form_elements { object_id party_id @@ -260,7 +291,7 @@ set active_group_id "" set element_list "" - if { [contact::exists_p $party_id] } { + if { [string is true [contact::exists_p $party_id]] } { set object_type [contact::get::object_type $party_id] } else { # since the party doesn't exist yet, we assume that @@ -274,10 +305,7 @@ } db_foreach select_attributes $query { - -# set custom_fields [list organization_name legal_name reg_number first_names last_name email url] - set custom_fields [list first_names last_name email url] - if { [lsearch $custom_fields $attribute] >= 0 } { + if { [lsearch [list first_names last_name email url] $attribute] >= 0 } { if { [contacts::util::party_is_user_p $party_id] } { if { ![string compare $party_id [ad_conn user_id]] } { set help_text "This will change your account info." @@ -295,14 +323,12 @@ set required_p 1 } if { $object_type == "person" } { - set custom_fields [list first_names last_name] - if { [lsearch $custom_fields $attribute] >= 0 } { + if { [lsearch [list first_names last_name] $attribute] >= 0 } { set required_p 1 } } if { $object_type == "organization" } { - set custom_fields [list organization_name organization_type] - if { [lsearch $custom_fields $attribute] >= 0 } { + if { [lsearch [list organization_name organization_type] $attribute] >= 0 } { set required_p 1 } } @@ -391,113 +417,164 @@ get the attribute_values for a contact } { + if { [string is true [contact::exists_p $party_id]] } { + set user_id [ad_conn user_id] + - if { [contact::exists_p $party_id] } { - set user_id [ad_conn user_id] + contacts::get::values::multirow -multirow_name "ad_form_values" -party_id $party_id -object_id $object_id -permission "write" + set courses_info_set [ns_set create] - set query { + template::multirow -unclobber foreach ad_form_values { + ns_set put $courses_info_set contact_attribute__$attribute_name $ad_form_value + } - select ca.attribute_id, - ca.attribute, - cav.option_map_id, - cav.address_id, - cav.number_id, - to_char(cav.time,'YYYY MM DD') as time, - cav.value, - cav.value_format, - cw.storage_column - from contact_attributes ca, - contact_widgets cw, - contact_attribute_object_map caom left join - ( select * - from contact_attribute_values - where party_id = :party_id - and not deleted_p ) cav on (caom.attribute_id = cav.attribute_id) - where caom.object_id = :object_id - and caom.attribute_id = ca.attribute_id - and ca.widget_id = cw.widget_id - and not ca.depreciated_p - and acs_permission__permission_p(ca.attribute_id,:user_id,'write') + # Now, set the variables in the caller's environment + ad_ns_set_to_tcl_vars -level 2 $courses_info_set + ns_set free $courses_info_set + } + } - set courses_info_set [ns_set create] - db_foreach select_attributes $query { - set attribute_value $value +} - if { $storage_column == "address_id" } { - if { [exists_and_not_null address_id] } { - contacts::postal_address::get -address_id "$address_id" -array "address_info" - set attribute_value [list $address_info(delivery_address) $address_info(municipality) $address_info(region) $address_info(postal_code) $address_info(country_code)] - } else { - set attribute_value [list {} {} {} {} {US}] - } - } - if { $storage_column == "number_id" && [exists_and_not_null number_id] } { - contacts::telecom_number::get -number_id $number_id -array "telecom_info" - set attribute_value $telecom_info(subscriber_number) - } - if { $storage_column == "time" && [exists_and_not_null time] } { set attribute_value $time } - if { $storage_column == "option_map_id" && [exists_and_not_null option_map_id] } { - set attribute_value_temp "" - db_foreach select_options_from_map { select option_id from contact_attribute_option_map where option_map_id = :option_map_id } { - lappend attribute_value_temp $option_id - } - set attribute_value_temp [string trim $attribute_value_temp] - if { [exists_and_not_null attribute_value_temp] } { - set attribute_value $attribute_value_temp - } - } +namespace eval contacts::get::values:: { - set custom_fields [list organization_name legal_name reg_number first_names last_name email url] + ad_proc multirow { + {-multirow_name} + {-permission "read"} + {-object_id} + {-party_id} + {-orderby "sort_order,asc"} + } { + Returns a multirow + } { + + set user_id [ad_conn user_id] + + template::multirow create $multirow_name attribute_name attribute_id pretty_attribute_name ad_form_value pretty_value pretty_value_html sort_order sort_key + + set custom_field_list [contact::get::custom_field_list $party_id] + set custom_field_sql_list [contacts::util::sqlify_list $custom_field_list] - if { [lsearch $custom_fields $attribute] >= 0 } { - db_0or1row get_attribute_value " - select $attribute as attribute_value - from contacts - where party_id = $party_id - " - } - if { $attribute == "organization_type" } { - set attribute_value [db_list_of_lists get_org_types { - select option_id - from contact_attribute_options cao, - organization_types ot, - organization_type_map otm - where cao.option = ot.type - and cao.attribute_id = :attribute_id - and otm.organization_type_id = ot.organization_type_id - and otm.organization_id = :party_id + set sort_order "0" - }] - } + db_foreach select_attribute_values "" { + + set attribute_name $attribute + set attribute_id $attribute_id + set pretty_attribute_name [contacts::attribute::name $attribute_id] + + if { [lsearch $custom_field_list $attribute] >= 0 } { + + if { $attribute == "organization_name" } { + set ad_form_value [db_string organization_name_from_party_id {} -default {}] + set pretty_value $ad_form_value + } + if { $attribute == "organization_type" } { + set ad_form_value [list] + set pretty_value {} + db_foreach organization_types_from_party_and_attribute_id {} { + if { [llength $ad_form_value] > 0 } { + append pretty_value "\n" + } + lappend ad_form_value $option_id + append pretty_value $option + } + } + if { $attribute == "legal_name" } { + set ad_form_value [db_string legal_name_from_party_id {} -default {}] + set pretty_value $ad_form_value + } + if { $attribute == "reg_number" } { + set ad_form_value [db_string reg_number_from_party_id {} -default {}] + set pretty_value $ad_form_value + } + if { $attribute == "first_names" } { + set ad_form_value [db_string first_names_from_party_id {} -default {}] + set pretty_value $ad_form_value + } + if { $attribute == "last_name" } { + set ad_form_value [db_string last_name_from_party_id {} -default {}] + set pretty_value $ad_form_value + } + if { $attribute == "email" } { + set ad_form_value [db_string email_from_party_id {} -default {}] + set pretty_value $ad_form_value + } + if { $attribute == "url" } { + set ad_form_value [db_string url_from_party_id {} -default {}] + set pretty_value $ad_form_value + } + + } else { + + set pretty_value $value + set ad_form_value $value + + if { $storage_column == "address_id" } { + contacts::postal_address::get -address_id "$address_id" -array "address_info" + set ad_form_value [list $address_info(delivery_address) $address_info(municipality) $address_info(region) $address_info(postal_code) $address_info(country_code)] + set pretty_value "$address_info(delivery_address)\n$address_info(municipality), $address_info(region) $address_info(postal_code)\n$address_info(country_code)" + } + if { $storage_column == "number_id" && [exists_and_not_null number_id] } { + contacts::telecom_number::get -number_id $number_id -array "telecom_info" + set ad_form_value $telecom_info(subscriber_number) + set pretty_value $telecom_info(subscriber_number) + } + if { $storage_column == "time" && [exists_and_not_null time] } { + set ad_form_value $time + set pretty_value $time + } + if { $storage_column == "option_map_id" && [exists_and_not_null option_map_id] } { + set pretty_value {} + set ad_form_value [list] + db_foreach select_options_from_map { + select cao.option, cao.option_id + from contact_attribute_options cao, + contact_attribute_option_map caom + where caom.option_id = cao.option_id + and caom.option_map_id = :option_map_id + } { + if { [llength $ad_form_value] > 0 } { + # we know there has been a previous entry so we can put in a comma + append pretty_value "\n" + } + append pretty_value $option + lappend ad_form_value $option_id + } + } + + } + if { [exists_and_not_null ad_form_value] || [exists_and_not_null pretty_value] } { + incr sort_order + set pretty_value_html [ad_convert_to_html $pretty_value] + template::multirow append $multirow_name $attribute_name $attribute_id $pretty_attribute_name $ad_form_value $pretty_value $pretty_value_html $sort_order + } + + } - ns_set put $courses_info_set contact_attribute__$attribute $attribute_value + set orderby [split $orderby ","] + set orderby_field [lindex $orderby 0] + if { [lindex $orderby 1] == "asc" } { + set orderby_direction {-increasing} + } else { + set orderby_direction {-decreasing} } - - # Now, set the variables in the caller's environment - ad_ns_set_to_tcl_vars -level 2 $courses_info_set - ns_set free $courses_info_set - - + template::multirow sort $multirow_name -dictionary $orderby_direction $orderby_field + } - } - - - + + } - - namespace eval contacts::save::ad_form { - - ad_proc -public values { object_id party_id Fisheye: Tag 1.1 refers to a dead (removed) revision in file `openacs-4/packages/contacts/tcl/contacts-procs.xql'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/contacts/tcl/view-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/Attic/view-procs.tcl,v diff -u -r1.1.2.2 -r1.1.2.3 --- openacs-4/packages/contacts/tcl/view-procs.tcl 16 Aug 2004 20:36:38 -0000 1.1.2.2 +++ openacs-4/packages/contacts/tcl/view-procs.tcl 19 Aug 2004 01:02:10 -0000 1.1.2.3 @@ -74,7 +74,7 @@ initialize views } { - if { ![db_0or1row views_exist_p { select '1' from contact_views limit 1 } ] } { + if { [string is false [db_0or1row views_exist_p { select '1' from contact_views limit 1 } ]] } { db_1row get_package_id { select package_id from apm_packages where package_key = 'contacts' } Index: openacs-4/packages/contacts/www/contact-ae.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/Attic/contact-ae.tcl,v diff -u -r1.1.2.1 -r1.1.2.2 --- openacs-4/packages/contacts/www/contact-ae.tcl 12 Aug 2004 17:38:41 -0000 1.1.2.1 +++ openacs-4/packages/contacts/www/contact-ae.tcl 19 Aug 2004 01:02:10 -0000 1.1.2.2 @@ -12,7 +12,7 @@ set user_id [auth::require_login] permission::require_write_permission -object_id [ad_conn package_id] -action "write" -if { [contact::exists_p $party_id] } { +if { [string is true [contact::exists_p $party_id]] } { set context [list "\#acs-kernel.common_Edit\#"] set title "\#acs-kernel.common_Edit\# [contact::get::name $party_id]" set object_type [contact::get::object_type $party_id] @@ -44,7 +44,7 @@ ad_form -extend -name entry -form [contacts::get::ad_form_elements $object_id $party_id] -if { [contacts::categories::enabled_p]} { +if { [string is true [contacts::categories::enabled_p]]} { ad_form -extend -name entry -form { {category_ids:integer(category),multiple,optional {label "Categories"} {html {size 7}} {value {$party_id [ad_conn package_id]}}} Index: openacs-4/packages/contacts/www/view/contact-view.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/view/Attic/contact-view.tcl,v diff -u -r1.1.2.1 -r1.1.2.2 --- openacs-4/packages/contacts/www/view/contact-view.tcl 12 Aug 2004 17:38:42 -0000 1.1.2.1 +++ openacs-4/packages/contacts/www/view/contact-view.tcl 19 Aug 2004 01:02:10 -0000 1.1.2.2 @@ -13,7 +13,6 @@ {status "normal"} } - set actions_list [list "Edit" "[apm_package_url_from_id [ad_conn package_id]]contact-ae?party_id=$party_id\&return_url=$return_url" "Edit [contact::name $party_id]"] list::create \ @@ -33,11 +32,11 @@ } -elements { attribute { label "Attribute" - display_col attribute_name + display_col pretty_attribute_name } attribute_value { label "Value" - display_col attribute_value_html;noquote + display_col pretty_value_html;noquote } } -filters { } -groupby { @@ -53,9 +52,6 @@ } } - - - set user_id [ad_conn user_id] set object_type [contact::get::object_type $party_id] if { $object_type == "organization" } { @@ -66,85 +62,9 @@ set object_id [contacts::util::person_object_id] } -db_multirow -extend { attribute_value_html attribute_name } attributes select_attributes { +contacts::get::values::multirow -multirow_name "attributes" -party_id $party_id -object_id $object_id - select ca.attribute_id, - ca.attribute, - cav.option_map_id, - cav.address_id, - cav.number_id, - to_char(cav.time,'YYYY MM DD') as time, - cav.value, - cav.value_format, - cw.storage_column - from contact_attributes ca, - contact_widgets cw, - contact_attribute_object_map caom, - ( select * - from contact_attribute_values - where party_id = :party_id - and not deleted_p ) cav - where caom.attribute_id = cav.attribute_id - and caom.object_id = :object_id - and caom.attribute_id = ca.attribute_id - and ca.widget_id = cw.widget_id - and not ca.depreciated_p - and acs_permission__permission_p(ca.attribute_id,:user_id,'read') - order by caom.sort_order - } { - set attribute_name [contacts::attribute::name $attribute_id] - set attribute_value $value - - if { $storage_column == "address_id" } { - contacts::postal_address::get -address_id "$address_id" -array "address_info" - set attribute_value "$address_info(delivery_address) -$address_info(municipality), $address_info(region) $address_info(postal_code) -$address_info(country_code)" - } - if { $storage_column == "number_id" && [exists_and_not_null number_id] } { - contacts::telecom_number::get -number_id $number_id -array "telecom_info" - set attribute_value $telecom_info(subscriber_number) - } - if { $storage_column == "time" && [exists_and_not_null time] } { set attribute_value $time } - if { $storage_column == "option_map_id" && [exists_and_not_null option_map_id] } { - set attribute_value_temp "" - db_foreach select_options_from_map { -select cao.option - from contact_attribute_options cao, - contact_attribute_option_map caom - where caom.option_id = cao.option_id - and caom.option_map_id = :option_map_id } { - if { [exists_and_not_null attribute_value_temp] } { - # we know there has been a previous entry so we can put in a comma - append attribute_value_temp ", " - } - append attribute_value_temp $option - } - set attribute_value_temp [string trim $attribute_value_temp] - if { [exists_and_not_null attribute_value_temp] } { - set attribute_value $attribute_value_temp - } - } - - set attribute_value_html [ad_convert_to_html $attribute_value] - } - - - - - - - - - - - - - - - - ad_return_template