Index: openacs-4/packages/acs-templating/tcl/widget-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/Attic/widget-procs-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-templating/tcl/widget-procs-oracle.xql 22 Sep 2003 21:45:31 -0000 1.1 @@ -0,0 +1,31 @@ + + + + + + select (first_names || ' ' || last_name) as name, pe.person_id from persons pe, parties pa + where pe.person_id=pa.party_id and + lower(pe.first_names || ' ' || pe.last_name) like '%' || :search_string || '%' + or lower(pa.email) like '%' || :search_string || '%' + order by lower(first_names || ' ' || last_name) + + + + + + ( + select g1.group_name as party_name, g1.group_id as party_id from groups g1 + where lower(g1.group_name) like '%' || :search_string || '%' + ) + union + ( + select g2.group_name || ' : ' || s2.segment_name as party_name, s2.segment_id as party_id + from rel_segments s2, groups g2 + where s2.group_id=g2.group_id and + lower(g2.group_name || ' : ' || s2.segment_name) like '%' || :search_string || '%' + ) + order by party_name + + + + Index: openacs-4/packages/acs-templating/tcl/widget-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/Attic/widget-procs-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-templating/tcl/widget-procs-postgresql.xql 22 Sep 2003 21:45:31 -0000 1.1 @@ -0,0 +1,31 @@ + + + + + + select (first_names || ' ' || last_name) as name, pe.person_id from persons pe + join parties pa on pe.person_id=pa.party_id + where lower(pe.first_names || ' ' || pe.last_name) like '%' || :search_string || '%' + or lower(pa.email) like '%' || :search_string || '%' + order by lower(first_names || ' ' || last_name) + + + + + + ( + select g1.group_name as party_name, g1.group_id as party_id from groups g1 + where lower(g1.group_name) like '%' || :search_string || '%' + ) + union + ( + select g2.group_name || ' : ' || s2.segment_name as party_name, s2.segment_id as party_id + from rel_segments s2 + join groups g2 on s2.group_id=g2.group_id + where lower(g2.group_name || ' : ' || s2.segment_name) like '%' || :search_string || '%' + ) + order by party_name + + + + Index: openacs-4/packages/acs-templating/tcl/widget-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/widget-procs.tcl,v diff -u -r1.22 -r1.23 --- openacs-4/packages/acs-templating/tcl/widget-procs.tcl 22 Sep 2003 14:53:37 -0000 1.22 +++ openacs-4/packages/acs-templating/tcl/widget-procs.tcl 22 Sep 2003 21:45:31 -0000 1.23 @@ -29,6 +29,7 @@ @see template::widget::multiselect @see template::widget::numericRange @see template::widget::password + @see template::widget::party_search @see template::widget::radio @see template::util::richtext @see template::widget::search @@ -41,6 +42,125 @@ } - +ad_proc -public template::widget::party_search { element_reference tag_attributes } { + + A widget that searches for parties (persons, groups and relational_segments) and lets + the user select one from the search results. + +

+ + It only searches in all parties from the system currently. It should propably be extended to + allow to restrict the search to a specific subsite, as well as searching only + for groups or persons. + + @author Tilmann Singer +} { + + upvar $element_reference element + + if { ![info exists element(options)] } { + + # initial submission or no data (no options): a text box + set output [input text element $tag_attributes] + + } else { + + set output "" + append output "" + + if { ![info exists element(confirmed_p)] } { + append output "" + } + + append output [select $element_reference $tag_attributes] + } + return $output +} + +ad_proc -public template::data::validate::party_search { value_ref message_ref } { + return 1 +} + +ad_proc -public template::data::transform::party_search { element_ref } { + + upvar $element_ref element + set element_id $element(id) + + set value [string trim [ns_queryget $element_id]] + + if { [empty_string_p $value] } { + template::element::set_error $element(form_id) $element_id "Please enter a search string." + return [list] + } + + if { [string equal $value ":search:"] } { + # user has selected 'search again' previously + template::element::set_error $element(form_id) $element_id "Please enter a search string." + return [list] + } + + if { [ns_queryexists $element_id:search_string] } { + # request comes from a page with a select widget and the + # search string has been passed as hidden value + set search_string [ns_queryget $element_id:search_string] + set element(search_string) $search_string + + # the value to be returned + set value [ns_queryget $element_id] + } else { + # request is an initial search + set search_string $value + set element(search_string) $value + } + + # search in persons + set persons [db_list_of_lists search_persons {}] + + # search in groups and relsegs + set groups_relsegs [db_list_of_lists search_groups_relsegs {}] + + if { [llength $persons] == 0 && [llength $groups_relsegs] == 0 } { + # no search results so return text entry back to the user + + catch { unset element(options) } + + template::element::set_error $element(form_id) $element_id " + No matches were found for \"$search_string\".
Please + try again." + + } else { + # we need to return a select list + + set options [list] + + if { [llength $persons] > 0 } { + set options $persons + set options [concat $options [list [list "---" ""]]] + } + if { [llength $groups_relsegs] > 0 } { + set options [concat $options $groups_relsegs] + set options [concat $options [list [list "---" ""]]] + } + set element(options) [concat $options { { "Search again..." ":search:" } }] + if { ![info exists value] } { + # set value to first item + set value [lindex [lindex $options 0] 1] + } + + if { ![ns_queryexists $element_id:confirmed_p] } { + template::element::set_error $element(form_id) $element_id "Please choose an entry." + } + } + + if { [info exists element(result_datatype)] && + [ns_queryexists $element_id:select] } { + set element(datatype) $element(result_datatype) + } + + return $value +} + + ad_proc -public template::widget::search { element_reference tag_attributes } { upvar $element_reference element