Index: openacs-4/packages/contacts/tcl/contact-search-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contact-search-procs.tcl,v diff -u -N -r1.21 -r1.22 --- openacs-4/packages/contacts/tcl/contact-search-procs.tcl 15 Feb 2006 10:06:36 -0000 1.21 +++ openacs-4/packages/contacts/tcl/contact-search-procs.tcl 12 Mar 2006 00:35:33 -0000 1.22 @@ -330,29 +330,41 @@ } { set query [string trim $query] regsub -all "'" $query "''" query + set query_clauses [list] + set callback_query_clauses [callback contact::search::query_clauses -query $query -party_id $party_id] - # If we have a query, we need to do a subselect with an "in" clause. - # We are assuming that people usually want to get a small number of the - # base for the selection, therefore the subselects will return a very small - # number of rows, justifying the union cum in clause. - if { [string is integer $query] } { - lappend query_clauses "$party_id = $query" - } elseif { [exists_and_not_null query] } { - foreach term $query { + if { [llength $callback_query_clauses] > 0 } { + # the callback returns a list of the lists from the callbacks + foreach callback_clauses $callback_query_clauses { + foreach clause $callback_clauses { + lappend query_clauses $clause + } + } + } else { - # We want to enable searches with "*", to select all users who's - # last_name starts with "Ab", searching for "Ab*" - # For this we check if the term starts or ends with "*" and if yes - # we do a regsub to replace the "*" with "%" for reuse in SQL - if {[string length [string trim $term "*"]] == [string length $term]} { - set term_clause "%${term}%" - } else { - regsub -all "*" $term "%" term - } + # If we have a query, we need to do a subselect with an "in" clause. + # We are assuming that people usually want to get a small number of the + # base for the selection, therefore the subselects will return a very small + # number of rows, justifying the union in clause. + if { [string is integer $query] } { + lappend query_clauses "$party_id = $query" + } elseif { [exists_and_not_null query] } { + foreach term $query { + + # We want to enable searches with "*", to select all users who's + # last_name starts with "Ab", searching for "Ab*" + # For this we check if the term starts or ends with "*" and if yes + # we do a regsub to replace the "*" with "%" for reuse in SQL + if {[string length [string trim $term "*"]] == [string length $term]} { + set term_clause "%${term}%" + } else { + regsub -all "*" $term "%" term + } - lappend query_clauses "party_id in (select organization_id from organizations where upper(organizations.name) like upper('%${term}%') union select person_id from persons where upper(last_name) like upper('%${term}%') or upper(first_names) like upper ('%${term}%'))" - } + lappend query_clauses "$party_id in (select organization_id from organizations where upper(organizations.name) like upper('%${term}%') union select person_id from persons where upper(last_name) like upper('%${term}%') or upper(first_names) like upper ('%${term}%'))" + } + } } set result {} 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 -N -r1.28 -r1.29 --- openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl 27 Feb 2006 03:46:17 -0000 1.28 +++ openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl 12 Mar 2006 00:35:33 -0000 1.29 @@ -146,6 +146,18 @@ } { } +ad_proc -public -callback contact::search::query_clauses { + {-query:required} + {-party_id:required} +} { + This callback is executed by the contact::search::query_clause + and allows a site to customize the behavior or the entered + query string in the primary contacts search box it should + return a list of conditions. These conditions will be joined by + and in the sql query, so if you want it to be or you should + return the conditions in quotes with or's already in place +} - + ad_proc -public -callback contact::special_attributes::ad_form_values { {-party_id:required} {-form:required}