@@ -45,20 +45,27 @@ public static function contact_search()
4545 $ adv = isset ($ _POST ['_adv ' ]);
4646 $ sid = rcube_utils::get_input_string ('_sid ' , rcube_utils::INPUT_GET );
4747 $ search = null ;
48+ $ scope = null ;
4849
4950 // get search criteria from saved search
5051 if ($ sid && ($ search = $ rcmail ->user ->get_search ($ sid ))) {
5152 $ fields = $ search ['data ' ]['fields ' ];
53+ // scope param added in 1.7, existence check for backwards compatibility
54+ $ scope = $ search ['data ' ]['scope ' ] ?? null ;
5255 $ search = $ search ['data ' ]['search ' ];
5356 }
5457 // get fields/values from advanced search form
5558 elseif ($ adv ) {
5659 $ fields = [];
5760 foreach (array_keys ($ _POST ) as $ key ) {
5861 $ s = trim (rcube_utils::get_input_string ($ key , rcube_utils::INPUT_POST , true ));
59- if (strlen ($ s ) && preg_match ('/^_search_([a-zA-Z0-9_-]+)$/ ' , $ key , $ m )) {
60- $ search [] = $ s ;
61- $ fields [] = $ m [1 ];
62+ if (strlen ($ s )) {
63+ if (preg_match ('/^_search_([a-zA-Z0-9_-]+)$/ ' , $ key , $ m )) {
64+ $ search [] = $ s ;
65+ $ fields [] = $ m [1 ];
66+ } elseif ($ key == '_scope ' ) {
67+ $ scope = $ s ;
68+ }
6269 }
6370 }
6471
@@ -71,6 +78,7 @@ public static function contact_search()
7178 else {
7279 $ search = trim (rcube_utils::get_input_string ('_q ' , rcube_utils::INPUT_GET , true ));
7380 $ fields = rcube_utils::get_input_string ('_headers ' , rcube_utils::INPUT_GET );
81+ $ scope = isset ($ _GET ['_scope ' ]) && strlen ($ _GET ['_scope ' ]) ? rcube_utils::get_input_string ('_scope ' , rcube_utils::INPUT_GET ) : null ;
7482
7583 if (empty ($ fields )) {
7684 $ fields = array_keys (self ::$ SEARCH_MODS_DEFAULT );
@@ -104,6 +112,10 @@ public static function contact_search()
104112 $ records = [];
105113
106114 foreach ($ sources as $ s ) {
115+ if (isset ($ scope ) && $ scope !== $ s ['id ' ]) {
116+ continue ;
117+ }
118+
107119 $ source = $ rcmail ->get_address_book ($ s ['id ' ]);
108120
109121 // check if search fields are supported....
@@ -167,7 +179,7 @@ public static function contact_search()
167179
168180 // save search settings in session
169181 $ _SESSION ['contact_search ' ][$ search_request ] = $ search_set ;
170- $ _SESSION ['contact_search_params ' ] = ['id ' => $ search_request , 'data ' => [$ fields , $ search ]];
182+ $ _SESSION ['contact_search_params ' ] = ['id ' => $ search_request , 'data ' => [$ fields , $ search ], ' scope ' => $ scope ];
171183 $ _SESSION ['page ' ] = 1 ;
172184
173185 if ($ adv ) {
@@ -249,6 +261,20 @@ public static function contact_search_form($attrib)
249261 }
250262 }
251263
264+ // add search scope field
265+ $ coltypes ['_scope ' ] = [
266+ 'id ' => 'scope ' ,
267+ 'type ' => 'select ' ,
268+ 'category ' => 'main ' ,
269+ 'label ' => $ rcmail ->gettext ('searchscope ' ),
270+ 'options ' => [
271+ 'base ' => $ rcmail ->gettext ('currentaddressbook ' ),
272+ 'all ' => $ rcmail ->gettext ('alladdressbooks ' ),
273+ ],
274+ 'value ' => 'all ' ,
275+ 'skip-empty ' => true ,
276+ ];
277+
252278 // build form fields list
253279 foreach ($ coltypes as $ col => $ colprop ) {
254280 if (!isset ($ colprop ['type ' ])) {
@@ -266,11 +292,12 @@ public static function contact_search_form($attrib)
266292 $ colprop ['size ' ] = $ i_size ;
267293 }
268294
269- $ colprop ['id ' ] = '_search_ ' . $ col ;
295+ $ fname = !empty ($ colprop ['id ' ]) ? $ colprop ['id ' ] : 'search_ ' . $ col ;
296+ $ colprop ['id ' ] = !empty ($ colprop ['id ' ]) ? '_ ' . $ colprop ['id ' ] : '_search_ ' . $ col ;
270297
271298 $ content = html::div ('row ' ,
272299 html::label (['class ' => 'contactfieldlabel label ' , 'for ' => $ colprop ['id ' ]], rcube::Q ($ label ))
273- . html::div ('contactfieldcontent ' , rcube_output::get_edit_field (' search_ ' . $ col , '' , $ colprop , $ ftype ))
300+ . html::div ('contactfieldcontent ' , rcube_output::get_edit_field ($ fname , $ colprop [ ' value ' ] ?? '' , $ colprop , $ ftype ))
274301 );
275302
276303 $ form [$ category ]['content ' ][] = $ content ;
0 commit comments