[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] CVS: phpgwapi/inc class.contacts_ldap.inc.php,1.12,1.
From: |
Miles Lott <address@hidden> |
Subject: |
[Phpgroupware-cvs] CVS: phpgwapi/inc class.contacts_ldap.inc.php,1.12,1.13 class.contacts_shared.inc.php,1.10,1.11 |
Date: |
Wed, 24 Apr 2002 08:15:33 -0400 |
Update of /cvsroot/phpgroupware/phpgwapi/inc
In directory subversions:/tmp/cvs-serv5238
Modified Files:
class.contacts_ldap.inc.php class.contacts_shared.inc.php
Log Message:
Better ldap filtering (GNU Bug# 100340)
Index: class.contacts_ldap.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.contacts_ldap.inc.php,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** class.contacts_ldap.inc.php 8 Feb 2002 05:04:33 -0000 1.12
--- class.contacts_ldap.inc.php 24 Apr 2002 12:15:31 -0000 1.13
***************
*** 372,379 ****
/* $filterfields += array('phpgwcontactaccess'
=> 'public'); */
$grants = $this->grants;
! while(list($user) = each($grants))
{
! if($DEBUG) { echo '<br>DEBUG - Grant
from owner: '.$user; }
! $filterfields +=
array('phpgwcontactowner' => $user);
}
}
--- 372,381 ----
/* $filterfields += array('phpgwcontactaccess'
=> 'public'); */
$grants = $this->grants;
! if ($DEBUG) { echo '<br>DEBUG - My user id is:
' . $this->account_id; }
! while (list($user) = each($grants))
{
! if ($DEBUG) { echo '<br>DEBUG - Grant
from owner: '.$user; }
! /* I know this looks silly... */
! @$filterfields['phpgwcontactowner'][] =
array('phpgwcontactowner' => $user);
}
}
***************
*** 402,448 ****
}
if($query)
{
- $ldap_fields = array();
- $total = 0;
-
reset($this->stock_contact_fields);
! $lquery = '(&(|'; /* $lquery = '(|'; */
! while(list($name,$value) =
each($this->stock_contact_fields) )
! {
! $lquery .= '(' . $value . '=*' . $query
. '*)';
! }
! $lquery .= ')(phpgwcontactowner=*))'; /*
$lquery .= ')'; */
! /* echo $lquery; exit; */
!
! $sri = ldap_search($this->ldap,
$GLOBALS['phpgw_info']['server']['ldap_contact_context'], "$lquery");
!
! /* append the results */
! $ldap_fields += ldap_get_entries($this->ldap,
$sri);
!
! /* add the # rows to our total */
! $total = $total +
ldap_count_entries($this->ldap, $sri);
! /* _debug_array($ldap_fields);exit; */
!
! if($filterfields)
! {
! $ldap_fields =
$this->filter_ldap($ldap_fields,$filterfields,$DEBUG);
! }
!
! $this->total_records = count($ldap_fields);
! /* echo '<br>total="'.$this->total_records.'"';
*/
}
else
{
! $sri = ldap_search($this->ldap,
$GLOBALS['phpgw_info']['server']['ldap_contact_context'],
'phpgwcontactowner=*');
! $ldap_fields = ldap_get_entries($this->ldap,
$sri);
! $this->total_records =
ldap_count_entries($this->ldap, $sri);
!
! if($filterfields)
! {
! $ldap_fields =
$this->filter_ldap($ldap_fields,$filterfields,$DEBUG);
! }
}
/* Use shared sorting routines, based on sort and order
*/
if($sort == 'ASC')
--- 404,429 ----
}
+ $ldap_fields = array();
+ $myfilter = '';
+
if($query)
{
reset($this->stock_contact_fields);
! $myfilter =
$this->makefilter($filterfields,$this->stock_contact_fields,$query,$DEBUG);
}
else
{
! $myfilter =
$this->makefilter($filterfields,'','',$DEBUG);
}
+ $sri = ldap_search($this->ldap,
$GLOBALS['phpgw_info']['server']['ldap_contact_context'], $myfilter);
+
+ $ldap_fields = ldap_get_entries($this->ldap, $sri);
+ /* _debug_array($ldap_fields);exit; */
+
+ $this->total_records = ldap_count_entries($this->ldap,
$sri);
+ /* echo '<br>total="'.$this->total_records.'"'; */
+ if($DEBUG) { echo '<br>Query returned
"'.$this->total_records.'" records.'; }
+
/* Use shared sorting routines, based on sort and order
*/
if($sort == 'ASC')
***************
*** 514,517 ****
--- 495,608 ----
}
return $return_fields;
+ }
+
+ /* Used by read() above to build the ldap filter string */
+ function makefilter($qarray,$extra='',$query='', $DEBUG=False)
+ {
+ if(!is_array($qarray))
+ {
+ return $qarray;
+ }
+
+ if(is_array($extra))
+ {
+ if($DEBUG) { echo '<br>Searching...'; }
+ reset($extra);
+ while(list($name,$value) = each($extra))
+ {
+ $qarray[] = array($value => $query);
+ }
+ }
+ elseif($extra)
+ {
+ $tmp = split('=',$extra);
+ $qarray[] = array($tmp[0] => $tmp[1]);
+ }
+
+ @ksort($qarray);
+
+ $aquery = '(&';
+ $oquery = '(|';
+ $hasor = False;
+
+ while(list($name,$value) = @each($qarray))
+ {
+ if(is_array($value))
+ {
+ while(list($x,$y) = each($value))
+ {
+ if($y == '*')
+ {
+ $oquery .= '(' . $x .
'=*)';
+ $hasor = True;
+ }
+ elseif(is_array($y))
+ {
+ /* This was most likely
created from acl grants in read() above */
+ while(list($a,$b) =
each($y))
+ {
+ $tmp .= '(' .
$a . '=' . $b . ')';
+ }
+ }
+ else
+ {
+ $oquery .= '(' . $x .
'=*' . $y . '*)';
+ $hasor = True;
+ }
+ }
+ }
+ elseif($value == $query)
+ {
+ /* searching */
+ $oquery .= '(' . $name . '=*' . $value
. '*)';
+ $hasor = True;
+ }
+ else
+ {
+ /* exact value (filtering based on tid,
etc...) */
+ if($name == $lastname)
+ {
+ $aquery .= '(' . $name . '=' .
$value . ')';
+ }
+ else
+ {
+ $aquery .= '(' . $name . '=' .
$value . ')';
+ }
+ }
+
+ if($tmp)
+ {
+ if(strstr($tmp,')('))
+ {
+ $aquery .= '(|' . $tmp . ')';
+ }
+ else
+ {
+ $aquery .= $tmp;
+ }
+ unset($tmp);
+ }
+ }
+ $aquery .= ')';
+ $oquery .= ')';
+ if(!$hasor)
+ {
+ $oquery = '';
+ $fquery = $aquery;
+ }
+ else
+ {
+ $fquery = '(&' . $aquery . $oquery . ')';
+ }
+
+ if($DEBUG)
+ {
+ echo '<br>AND query: "' . $aquery . '"';
+ echo '<br>OR query: "' . $oquery . '"';
+ echo '<br>Full query: "' . $fquery . '"';
+ echo '<br>Will search in "' .
$GLOBALS['phpgw_info']['server']['ldap_contact_context'] . '"';
+ }
+
+ return $fquery;
}
Index: class.contacts_shared.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.contacts_shared.inc.php,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** class.contacts_shared.inc.php 8 Feb 2002 05:04:33 -0000 1.10
--- class.contacts_shared.inc.php 24 Apr 2002 12:15:31 -0000 1.11
***************
*** 198,293 ****
}
- function filter_ldap($ldap_fields,$filterfields,$DEBUG=0)
- {
- $match = 0;
- if($DEBUG) { echo '<br>'; }
- for($i=0;$i<count($ldap_fields);$i++)
- {
- $yes = True;
-
- if($ldap_fields[$i]['uidnumber'][0])
- {
- reset($filterfields);
- while(list($col,$filt) =
each($filterfields))
- {
- if($col == 'phpgwcontactcatid')
- {
- $colarray =
explode(',',$ldap_fields[$i][$col][0]);
- if($colarray[1])
- {
-
while(list($key,$val) = each ($colarray))
- {
-
if($DEBUG) { echo ' Testing "'.$col.'" for "'.$val.'"'; }
- if($val
== $filt)
- {
-
if($DEBUG) { echo ', and number '.$ldap_fields[$i]['uidnumber'][0].'
matched.'.' '; }
-
$yes &= True;
-
$match++;
-
break;
- }
- }
- }
- else
- {
- 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.'.' '; }
- $yes &=
True;
-
$match++;
- }
- else
- {
-
if($DEBUG) { echo ', but number '.$ldap_fields[$i]['uidnumber'][0].' did not
match.'.' '; }
- $yes &=
False;
-
$match--;
- }
- }
- }
- else
- {
- 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.'.' '; }
- $yes &= True;
- $match++;
- }
- else
- {
- if($DEBUG) {
echo ', but number '.$ldap_fields[$i]['uidnumber'][0].' did not
match.'.' '; }
- $yes &= False;
- $match--;
- }
- }
- }
-
- if($yes)
- {
- if($DEBUG) { echo
$ldap_fields[$i]['uidnumber'][0].' matched all!'.'<br>'; }
- $new_ldap[] = $ldap_fields[$i];
- }
- else
- {
- if($DEBUG) { echo
$ldap_fields[$i]['uidnumber'][0].' did not match all.'.'<br>'; }
- }
- }
- }
- if($DEBUG)
- {
- if($match)
- {
- echo '<br>'.$match.' total
matches.'."\n";
- }
- else
- {
- echo '<br>No matches :('."\n";
- }
- }
- $this->total_records = count($new_ldap);
-
- return $new_ldap;
- }
-
function formatted_address($id, $business = True, $afont = '',
$asize = '2')
{
--- 198,201 ----
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] CVS: phpgwapi/inc class.contacts_ldap.inc.php,1.12,1.13 class.contacts_shared.inc.php,1.10,1.11,
Miles Lott <address@hidden> <=