From christian@alcove.fr Wed Nov 29 18:36:50 2000 From: christian@alcove.fr (Christian Couder) Date: Wed, 29 Nov 2000 19:36:50 +0100 Subject: Improvement: advanced search Message-ID: <3A254CC2.BCCA6570@alcove.fr> ---------------------- multipart/mixed attachment Hi, A few month ago Stuart send a mail on this list to jump start this project. I answered to him that my company was willong to donate some GPL code and some of my time to help integrate the code in Turba. So I sent the code to Chuck and Jim but unfortunately a few days latter my company (Alc=F4ve) sent me for nearly 2 monthes to southern France to work in a client company... So now I am back and hopefully I will have more time to work on Turba. Anyway, here is some code to implement an advanced search. It is not completely finished but it should work. One thing that remains to be done though is to reload the adv_search.php page when the source select is used on this page to select another source, because I attached the new files. The adv_search.php file should be put in the "turba" directory and the other files in the "turba/templates/search" directory. Or perhaps you can create a new "turba/templates/adv_search" directory and put the .inc files in it (but you will need to modify adv_search.php a little). And here are some patches needed to make it work. The fisrt patch just add 2 new functions to the Turba_Source class and the second fix a problem when searching with many criterias. --- horde/turba/lib/Source.php 2000/10/26 21:33:13 1.14 +++ horde/turba/lib/Source.php 2000/11/29 18:14:12 @@ -277,6 +277,42 @@ list($object_key, $object_id) =3D each($this->toDriverKeys(array('__key' =3D> $object->getValue('__key'))))= ; $this->driver->removeObject($object_key, $object_id); } + + /** + * Returns the criterias available for this source except '__key'. + * + * @return An array containing the criterias. + */ + function get_criterias() + { + $criterias =3D array(); + foreach($this->map as $key =3D> $value) { + if($key !=3D "__key") { + $criterias[] =3D $key; + } + } + return $criterias; + } + + /** + * Returns an array made of the criterias set globally + * except '__key'. + * + * @return Array of criterias set globally. + */ + function get_globals_criterias() + { + $criterias =3D array(); + foreach($this->map as $key =3D> $value) { + if($key !=3D "__key") { + if(isset($GLOBALS[$key]) && $GLOBALS[$key] !=3D "") { + $criterias[$key] =3D $GLOBALS[$key]; + } + } + } + return $criterias; + } + } ?> --- horde/turba/lib/Driver/ldap.php 2000/10/30 18:16:53 1.9 +++ horde/turba/lib/Driver/ldap.php 2000/11/29 18:25:52 @@ -63,13 +63,14 @@ { // FIXME: implement strict_fields - $filter =3D ''; + $filter =3D '(&'; reset($criteria); while (list($key, $val) =3D each($criteria)) { - if ($filter !=3D '') $filter .=3D ', '; - $filter .=3D '(' . $key . '=3D*' . $val . '*)'; + // if ($filter !=3D '') $filter .=3D ', '; + $filter .=3D ' (' . $key . '=3D*' . $val . '*)'; } - + $filter .=3D ' )'; + /* * Four11 (at least) doesn't seem to return 'cn' if you don't ask * for 'sn' as well. Add 'sn' implicitly. Bye, -- Christian COUDER christian@alcove.fr Ing=E9nieur Informatique Libre Alc=F4ve - http://www.alcove.fr/ ---------------------- multipart/mixed attachment A non-text attachment was scrubbed... Name: adv_search.php Type: application/x-httpd-php Size: 4489 bytes Desc: not available Url : http://lists.horde.org/archives/turba/attachments/c7bc3321/adv_search.php ---------------------- multipart/mixed attachment