Index: openacs-4/packages/acs-authentication/lib/local-search.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-authentication/lib/local-search.tcl,v diff -u -r1.8 -r1.9 --- openacs-4/packages/acs-authentication/lib/local-search.tcl 27 Jul 2018 08:54:02 -0000 1.8 +++ openacs-4/packages/acs-authentication/lib/local-search.tcl 27 Jul 2018 09:16:47 -0000 1.9 @@ -1,10 +1,34 @@ -# creation-date 2007-01-21 -# author Dave Bauer (dave@solutiongrove.com) -# includable search form -# results should be appended to multirow called users -# ADP level -# default local authority search +ad_include_contract { + Includable search form. + Results should be appended to multirow called users at ADP level + Default local authority search. + + @creation-date 2007-01-21 + @author Dave Bauer (dave@solutiongrove.com) + +} { + authority_id:naturalnum,notnull + {search_text ""} + {orderby:token ""} + {return_url:localurl ""} + {member_url:localurl ""} + group_id:naturalnum,notnull + {rel_type:token ""} + object_id:naturalnum,optional + privilege:token,optional +} -validate { + object_id_with_privilege { + if {[info exists object_id] && ![info exists privilege]} { + # needed for the message key + set formal_name "privilege" + ad_complain + } + } +} -errors { + object_id_with_privilege [_ acs-tcl.lt_You_must_supply_a_val] +} + ad_form -name user-search -method GET -export {authority_id object_id} -form { {search_text:text(text),optional {label "Search"} @@ -14,54 +38,39 @@ } -on_submit { } -if {![info exists orderby]} { - set orderby "" -} + set search_text [string tolower $search_text] -set search_terms [list] -foreach term [split $search_text] { - lappend search_terms $term -} set name_search "'()'" -if {[llength $search_terms]} { - set name_search "([join $search_terms |])" +if {[llength $search_text]} { + set name_search "([join $search_text |])" } set system_name [ad_system_name] - db_foreach get_users " -select -first_names, -last_name, -email, -username, -user_id, -authority_id -from cc_users -where -( - lower(first_names) ~ :name_search - or lower(last_name) ~ :name_search -) -or lower(username) like '%' || :search_text || '%' -or lower(email) like '%' || :search_text || '%' -" { - -set status [list] -if {[info exists object_id]} { - set group_member_p [permission::permission_p -object_id $object_id -party_id $user_id -privilege $privilege] - set status "" - -} else { - set group_member_p [group::member_p -group_id $group_id -user_id $user_id -cascade] - set group_name [group::get_element -element group_name -group_id $group_id] - if {$group_member_p} { - lappend status "[_ acs-authentication.Member_of_group_name]" +# Why dont't we use authority_id if we get one from the parent page? +db_foreach get_users { + select + first_names, last_name, email, username, user_id, authority_id + from cc_users + where ( + lower(first_names) ~ :name_search + or lower(last_name) ~ :name_search + ) + or lower(username) like '%' || :search_text || '%' + or lower(email) like '%' || :search_text || '%' +} { + if {[info exists object_id]} { + set group_member_p [permission::permission_p -object_id $object_id -party_id $user_id -privilege $privilege] + set status "" } else { - lappend status "[_ acs-authentication.Not_a_member_of_group_name]" + set group_member_p [group::member_p -group_id $group_id -user_id $user_id -cascade] + set group_name [group::get_element -element group_name -group_id $group_id] + if {$group_member_p} { + set status [_ acs-authentication.Member_of_group_name] + } else { + set status [_ acs-authentication.Not_a_member_of_group_name] + } } - set status [join $status "
"] -} template::multirow -ulevel 2 -local append users $first_names $last_name $username $email $status $group_member_p "" "" "" $user_id $authority_id }