Improvement: advanced search

Christian Couder christian@alcove.fr
Wed, 29 Nov 2000 19:36:50 +0100


---------------------- 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/d1a00f2a/adv_search.php

---------------------- multipart/mixed attachment
<script language="javascript">
var ToAddresses = new Object();
function toggleTo (address) {
	if (ToAddresses[address])
		ToAddresses[address] = null;
	else
		ToAddresses[address] = address;
}

var CcAddresses = new Object();
function toggleCc (address) {
	if (CcAddresses[address])
		CcAddresses[address] = null;
	else
		CcAddresses[address] = address;
}

var BccAddresses = new Object();
function toggleBcc (address) {
	if (BccAddresses[address])
		BccAddresses[address] = null;
	else
		BccAddresses[address] = address;
}

function compose () {
	var to = '';
	for (address in ToAddresses) {
		if (ToAddresses[address] != null) {
			if (to != '')
				to += ',%20';
			to += address;
		}
	}
  
	var cc = '';
	for (address in CcAddresses) {
		if (CcAddresses[address] != null) {
			if (cc != '')
				cc += ',%20';
			cc += address;
		}
	}
  
	var bcc = '';
	for (address in BccAddresses) {
		if (BccAddresses[address] != null) {
			if (bcc != '')
				bcc += ',%20';
			bcc += address;
		}
	}
  
	return '&to=' + to + '&cc=' + cc + '&bcc=' + bcc;
}

</script>

<form name="directory_search" action="adv_search.php" method="post">
<input type="hidden" name="actionID" value="1">

<table border="0" width="100%" cellpadding="0" cellspacing="0">

<tr class="header">
	<td class="header" align="left" colspan="6">
		<b><?= _("Advanced Directory Search") ?></b>
	</td>
</tr>

<tr>
	<td class="control">
		<?= _("From") ?>
	</td>
	<td class="control" colspan="5">
		<font size="-1">
		<select name="source">
			<?= $source_options ?>
		</select>
		</font>
	</td>
</tr>
<tr>
	<td class="control">
		<?= _("Find") ?>
	</td>
	<td class="control" colspan="5">&nbsp;</td>
</tr>

---------------------- multipart/mixed attachment
<tr>
	<td class="control">&nbsp;</td>
	<td class="control">
		<font size="-1">
		<?= _($criteria) ?>
		</font>
	</td>
	<td class="control">
		<font size="-1">
		<?= _("matching") ?>
		</font>
	</td>
	<td class="control">
		<font size="-1">
		<input type="text" size="15" name="<?= $criteria ?>">
		</font>
	</td>
	<td class="control" colspan="2">&nbsp;</td>
</tr>

---------------------- multipart/mixed attachment
<tr>
	<td class="control" colspan="6">
		<input type="submit" name="search" value="<?= _("Search") ?>">

	</td>
</tr>
</table>

<p>

<table border="0" cellpadding="1" cellspacing="0" width="100%"><tr class="header">
  <td class="smallheader">
    <b><?= ("Search&nbsp;Results") ?></b>
  </td>
  <td align="right" class="smallheader">
    <a class="menuitem" href="javascript:open_compose_win(compose());"><?= _("Send Message") ?></a> |
    <a class="menuitem" href="<?php Horde::purl('search.php?clear=1') ?>"><?= _("Clear Search") ?></a>
  </td>
</tr>

<tr><td colspan="2" class="item"><table border="0" cellpadding="1" cellspacing="1" width="100%">
<tr>
  <th class="item" width="1"><?= _("To") ?></th>
  <th class="item" width="1"><?= _("Cc") ?></th>
  <th class="item" width="1"><?= _("Bcc") ?></th>
  <th class="item" width="35%" align="left">
    <a href="javascript:sortby(<?php echo LASTNAME ?>);">
    <?= _("Name") ?></a></th>
  <th class="item" width="35%" align="left">
    <a href="javascript:sortby(<?php echo EMAIL ?>);">
    <?= _("Email") ?></a></th>
  <th class="item" width="35%" align="left">
    <a href="javascript:sortby(<?php echo ALIAS ?>);">
    <?= _("Nickname") ?></a></th>
</tr>

---------------------- multipart/mixed attachment--