Index: openacs-4/packages/contacts/tcl/contact-search-widget-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contact-search-widget-procs.tcl,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/contacts/tcl/contact-search-widget-procs.tcl 24 Apr 2006 08:17:44 -0000 1.3 +++ openacs-4/packages/contacts/tcl/contact-search-widget-procs.tcl 16 May 2006 16:42:41 -0000 1.4 @@ -13,7 +13,10 @@ namespace eval template::data::transform {} namespace eval template::data::validate {} namespace eval template::widget {} +namespace eval template::util {} +namespace eval template::util::contact_search {} + ad_proc -public template::widget::contact_search { element_reference tag_attributes } { A widget that searches for contacts (persons and organizations) and lets @@ -111,7 +114,7 @@ if { [info exists element(search)] } { set search $element(search) } else { - set search "contacts" + set search "parties" } switch $search { @@ -123,14 +126,14 @@ set persons_p 0 set orgs_p 1 } - contacts { + parties { set persons_p 1 set orgs_p 1 } default { # this error will be caught by developers and does not need # to be converted to an acs-lang message - error "The type of '$search' was specified and is not valid for the widget '$element_id', the only valid options are: persons, organizations and contacts (default)" + error "The type of '$search' was specified and is not valid for the widget '$element_id', the only valid options are: persons, organizations and parties (default)" } } @@ -147,18 +150,18 @@ error "You cannot use the contact_search widget without specifying a package_id of a contacts instance in which to search (done the same way you would specifiy html attributes)" } } - set persons [list] - set orgs [list] + set person_ids [list] + set organization_ids [list] # search in persons if { $persons_p } { - set persons [db_list_of_lists search_persons {}] + set person_ids [db_list search_persons {}] } # search in orgs if { $orgs_p } { - set orgs [db_list_of_lists search_orgs {}] + set organization_ids [db_list search_orgs {}] } - if { [llength $persons] == 0 && [llength $orgs] == 0 } { + if { [llength $person_ids] == 0 && [llength $organization_ids] == 0 } { # no search results so return text entry back to the user catch { unset element(options) } @@ -168,27 +171,27 @@ # we need to return a select list set options [list] - if { [llength $persons] > 0 } { - if { [llength $persons] > 50 } { + if { [llength $person_ids] > 0 } { + if { [llength $person_ids] > 50 } { set options [list [list [_ contacts.lt_Search_again_over_50_people] ":search:"]] template::element::set_error $element(form_id) $element_id [_ contacts.lt_To_many_people_found_search_again] } else { - foreach person_with_id $persons { - lappend options [list [lindex $person_with_id 0] [lindex $person_with_id 1] [_ contacts.Select_a_person]] + foreach person_id $person_ids { + lappend options [list [template::util::contact_search::contact_option -party_id $person_id] $person_id [_ contacts.Select_a_person]] } } } - if { [llength $orgs] > 0 } { - if { [llength $orgs] > 50 } { + if { [llength $organization_ids] > 0 } { + if { [llength $organization_ids] > 50 } { set options [concat $options [list [list [_ contacts.lt_Search_again_over_50_orgs] ":search:"]]] - if { [llength $persons] > 50 || [llength $persons] == 0 } { + if { [llength $person_ids] > 50 || [llength $person_ids] == 0 } { template::element::set_error $element(form_id) $element_id [_ contacts.Search_again] } else { template::element::set_error $element(form_id) $element_id [_ contacts.lt_To_many_orgs_found_search_again] } } else { - foreach org_with_id $orgs { - lappend options [list [lindex $org_with_id 0] [lindex $org_with_id 1] [_ contacts.Select_an_organization]] + foreach organization_id $organization_ids { + lappend options [list [template::util::contact_search::contact_option -party_id $organization_id] $organization_id [_ contacts.Select_an_organization]] } } } @@ -211,3 +214,20 @@ return $value } + + +ad_proc -public template::util::contact_search::contact_option { + {-party_id:required} +} { + this returns the contact's name to be returned in the contact search widget. + this exists in a seperate proc so that it can be customized on a per site + basis if need be. +} { + set option "[contact::name -party_id $party_id]" + set email [party::email -party_id $party_id] + if { $email ne "" } { + append option " <${email}>" + } + append option " \#$party_id" + return $option +} Index: openacs-4/packages/contacts/tcl/contact-search-widget-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contact-search-widget-procs.xql,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/contacts/tcl/contact-search-widget-procs.xql 17 Apr 2006 06:29:36 -0000 1.3 +++ openacs-4/packages/contacts/tcl/contact-search-widget-procs.xql 16 May 2006 16:42:41 -0000 1.4 @@ -4,10 +4,9 @@ - select CASE WHEN parties.email is not null THEN contact__name(persons.person_id) || ' <' || parties.email || '>' ELSE contact__name(persons.person_id) END || to_char(persons.person_id,' #FM999999999999999999999999'), persons.person_id - from persons, parties, group_distinct_member_map - where persons.person_id = parties.party_id - and persons.person_id = group_distinct_member_map.member_id + select persons.person_id + from persons, group_distinct_member_map + where persons.person_id = group_distinct_member_map.member_id and group_distinct_member_map.group_id in ([template::util::tcl_to_sql_list [contacts::default_groups -package_id $package_id]]) [contact::search::query_clause -and -query $query -party_id "persons.person_id"] order by upper(persons.first_names) asc, upper(persons.last_name) asc @@ -17,10 +16,9 @@ - select contact__name(organizations.organization_id) || to_char(organizations.organization_id,' #FM999999999999999999999999'), organizations.organization_id - from organizations, parties, group_distinct_member_map - where organizations.organization_id = parties.party_id - and organizations.organization_id = group_distinct_member_map.member_id + select organizations.organization_id + from organizations, group_distinct_member_map + where organizations.organization_id = group_distinct_member_map.member_id and group_distinct_member_map.group_id in ([template::util::tcl_to_sql_list [contacts::default_groups -package_id $package_id]]) [contact::search::query_clause -and -query $query -party_id "organizations.organization_id"] order by upper(organizations.name) asc