phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] CVS: phpgwapi/inc class.contacts_ldap.inc.php,1.11,1.


From: Miles Lott <address@hidden>
Subject: [Phpgroupware-cvs] CVS: phpgwapi/inc class.contacts_ldap.inc.php,1.11,1.11.2.1 class.contacts_shared.inc.php,1.9,1.9.2.1
Date: Wed, 24 Apr 2002 07:35:07 -0400

Update of /cvsroot/phpgroupware/phpgwapi/inc
In directory subversions:/tmp/cvs-serv3074

Modified Files:
      Tag: Version-0_9_14-branch
        class.contacts_ldap.inc.php class.contacts_shared.inc.php 
Log Message:
Fix for #100340 (ldap filtering)



Index: class.contacts_ldap.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.contacts_ldap.inc.php,v
retrieving revision 1.11
retrieving revision 1.11.2.1
diff -C2 -r1.11 -r1.11.2.1
*** class.contacts_ldap.inc.php 28 Dec 2001 04:29:31 -0000      1.11
--- class.contacts_ldap.inc.php 24 Apr 2002 11:35:03 -0000      1.11.2.1
***************
*** 351,363 ****
                                /* $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);
                                }
                        }
                        /*
!                       if ($DEBUG) {
!                               while(list($name,$value) = each($filterfields)) 
{
                                        echo "<br>DEBUG - Filter strings: 
#".$name.",".$value."#";
                                }
--- 351,367 ----
                                /* $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);
                                }
                        }
                        /*
!                       if ($DEBUG)
!                       {
!                               while(list($name,$value) = each($filterfields))
!                               {
                                        echo "<br>DEBUG - Filter strings: 
#".$name.",".$value."#";
                                }
***************
*** 377,424 ****
                        }
  
!                       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')
                        {
--- 381,408 ----
                        }
  
!                       $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 
*/
+                       @set_time_limit(0); /* Try not to die, this can take 
some time on slow machines... */
                        if ($sort == 'ASC')
                        {
***************
*** 489,492 ****
--- 473,579 ----
                        }
                        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)
+                               {
+                                       $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.9
retrieving revision 1.9.2.1
diff -C2 -r1.9 -r1.9.2.1
*** class.contacts_shared.inc.php       5 Jan 2002 23:57:41 -0000       1.9
--- class.contacts_shared.inc.php       24 Apr 2002 11:35:03 -0000      1.9.2.1
***************
*** 187,191 ****
                }
  
!               function filter_ldap ($ldap_fields,$filterfields,$DEBUG=0)
                {
                        $match = 0;
--- 187,192 ----
                }
  
!               /* This function is deprecated, fortunately. */
!               function filter_ldap($ldap_fields,$filterfields,$DEBUG=0)
                {
                        $match = 0;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]