From 9917a3911681f9fbe48dca3caecebb759be47fad Mon Sep 17 00:00:00 2001 From: Miles Lott Date: Tue, 27 Mar 2001 17:15:47 +0000 Subject: [PATCH] More ldap filtering fixes --- addressbook/inc/class.contacts_ldap.inc.php | 2 +- addressbook/inc/class.contacts_shared.inc.php | 77 +++++++++++++------ 2 files changed, 56 insertions(+), 23 deletions(-) diff --git a/addressbook/inc/class.contacts_ldap.inc.php b/addressbook/inc/class.contacts_ldap.inc.php index 45323bbc80..8a5ac27307 100644 --- a/addressbook/inc/class.contacts_ldap.inc.php +++ b/addressbook/inc/class.contacts_ldap.inc.php @@ -491,7 +491,7 @@ $ldap_fields['phpgwtypeid'] = $tid; $ldap_fields['phpgwowner'] = $owner; $ldap_fields['phpgwaccess'] = $access; - $ldap_fields["cat_id"] = $cat_id; + $ldap_fields["phpgwcatid"] = $cat_id; $ldap_fields['uidnumber'] = $this->nextid; $ldap_fields['objectclass'][0] = 'person'; $ldap_fields['objectclass'][1] = 'organizationalPerson'; diff --git a/addressbook/inc/class.contacts_shared.inc.php b/addressbook/inc/class.contacts_shared.inc.php index 2f51a2587c..63bf3cf5c6 100644 --- a/addressbook/inc/class.contacts_shared.inc.php +++ b/addressbook/inc/class.contacts_shared.inc.php @@ -135,13 +135,17 @@ * case of a user array this is the username; with the group array it is the group name. * asortby */ - function asortbyindex ($sortarray, $index) { + function asortbyindex ($sortarray, $index) + { $lastindex = count($sortarray) - 2; - for ($subindex = 0; $subindex < $lastindex; $subindex++) { + for ($subindex = 0; $subindex < $lastindex; $subindex++) + { $lastiteration = $lastindex - $subindex; - for ($iteration = 0; $iteration < $lastiteration; $iteration++) { + for ($iteration = 0; $iteration < $lastiteration; $iteration++) + { $nextchar = 0; - if ($this->comesafter($sortarray[$iteration][$index], $sortarray[$iteration + 1][$index])) { + if ($this->comesafter($sortarray[$iteration][$index], $sortarray[$iteration + 1][$index])) + { $temp = $sortarray[$iteration]; $sortarray[$iteration] = $sortarray[$iteration + 1]; $sortarray[$iteration + 1] = $temp; @@ -151,13 +155,17 @@ return ($sortarray); } - function arsortbyindex ($sortarray, $index) { + function arsortbyindex ($sortarray, $index) + { $lastindex = count($sortarray) - 1; - for ($subindex = $lastindex; $subindex > 0; $subindex--) { + for ($subindex = $lastindex; $subindex > 0; $subindex--) + { $lastiteration = $lastindex - $subindex; - for ($iteration = $lastiteration; $iteration > 0; $iteration--) { + for ($iteration = $lastiteration; $iteration > 0; $iteration--) + { $nextchar = 0; - if ($this->comesafter($sortarray[$iteration][$index], $sortarray[$iteration - 1][$index])) { + if ($this->comesafter($sortarray[$iteration][$index], $sortarray[$iteration - 1][$index])) + { $temp = $sortarray[$iteration]; $sortarray[$iteration] = $sortarray[$iteration - 1]; $sortarray[$iteration - 1] = $temp; @@ -167,28 +175,53 @@ return ($sortarray); } - function filter_ldap ($ldap_fields,$filterfields,$DEBUG=0) { + function filter_ldap ($ldap_fields,$filterfields,$DEBUG=0) + { $match = 0; - reset($filterfields); + if($DEBUG) { echo "
"; } for($i=0;$iTesting "'.$col.'" for "'.$filt.'"'."\n"; } - if ($ldap_fields[$i][$col][0] == $filt) { - if($DEBUG) { echo ', and number '.$ldap_fields[$i]["uidnumber"][0].' matched!'."\n"; } - $matched[$col][$i] = True; + $matched = ""; + $allmatched = False; + reset($filterfields); + + while (list($col,$filt) = each($filterfields)) + { + if($DEBUG) { echo '  Testing "'.$col.'" for "'.$filt.'"'; } + if ($ldap_fields[$i][$col][0] == $filt) + { + if($DEBUG) { echo ', and number '.$ldap_fields[$i]["uidnumber"][0].' matched.'."  "; } + $matched[$col] = True; $match++; - } else { - $matched[$col][$i] = False; - if($DEBUG) { echo ', and number '.$ldap_fields[$i]["uidnumber"][0].' did not match!'."\n"; } + } + else + { + $matched[$col] = False; + if($DEBUG) { echo ', but number '.$ldap_fields[$i]["uidnumber"][0].' did not match.'."  "; } $match--; } - if ($matched[$col][$i]) { $allmatched[$i] = True; } + + while (list($colmatch) = each($matched)) + { + if ($matched[$col]) + { + $allmatched = True; + } + else + { + $allmatched = False; + } + } } - reset($filterfields); - if ($allmatched[$i]) { - if($DEBUG) { echo ', and number '.$ldap_fields[$i]["uidnumber"][0].' matched!'."\n"; } + + if ($allmatched) + { + if($DEBUG) { echo $ldap_fields[$i]["uidnumber"][0].' matched all!'."
"; } $new_ldap[$i] = $ldap_fields[$i]; } + else + { + if($DEBUG) { echo $ldap_fields[$i]["uidnumber"][0].' did not match all.'."
"; } + } } if ($match) { if($DEBUG) { echo 'No matches :('."\n"; } }