update accounts_ldap

This commit is contained in:
ceb 2002-12-18 00:20:46 +00:00
parent 688aee7a14
commit 06a871dd7c
2 changed files with 229 additions and 102 deletions

View File

@ -2,10 +2,10 @@
/**************************************************************************\
* phpGroupWare API - Accounts manager for LDAP *
* This file written by Joseph Engo <jengo@phpgroupware.org> *
* and Lars Kneschke <kneschke@phpgroupware.org> *
* and Lars Kneschke <lkneschke@phpgw.de> *
* View and manipulate account records using LDAP *
* Copyright (C) 2000, 2001 Joseph Engo *
* -------------------------------------------------------------------------*
* Copyright (C) 2000 - 2002 Joseph Engo *
* ------------------------------------------------------------------------ *
* This library is part of the phpGroupWare API *
* http://www.phpgroupware.org/api *
* ------------------------------------------------------------------------ *
@ -21,7 +21,6 @@
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/
/* $Id$ */
class accounts_
@ -309,43 +308,39 @@
function get_list($_type='both', $start = '',$sort = '', $order = '', $query = '', $offset = '')
{
if($offset)
#print "\$_type=$_type, \$start=$start , \$sort=$sort, \$order=$order, \$query=$query, \$offset=$offset<br>";
$query = strtolower($query);
if ($offset)
{
$limitclause = '';//$phpgw->db->limit($start,$offset);
}
elseif($start && !$offset)
elseif ($start && !$offset)
{
$limitclause = '';//$phpgw->db->limit($start);
}
if(!$sort)
if (! $sort)
{
$sort = '';//"desc";
}
if($order)
if ($_type == 'accounts')
{
$orderclause = '';//"order by $order $sort";
if(empty($query) || $query == "*")
{
$filter = "(&(uidnumber=*)(phpgwaccounttype=u))";
}
else
{
$orderclause = '';//"order by account_lid,account_lastname,account_firstname asc";
$filter = "(&(uidnumber=*)(phpgwaccounttype=u)(|(uid=*$query*)(sn=*$query*)(cn=*$query*)(givenname=*$query*)))";
}
if($_type == 'both' || $_type == 'accounts')
{
$sri = ldap_search($this->ds, $this->user_context, '(&(uidnumber=*)(phpgwaccounttype=u))');
$sri = ldap_search($this->ds, $this->user_context, $filter);
$allValues = ldap_get_entries($this->ds, $sri);
while(list($null,$allVals) = @each($allValues))
while (list($null,$allVals) = @each($allValues))
{
settype($allVals,'array');
$test = @$allVals['uid'][0];
if(!$GLOBALS['phpgw_info']['server']['global_denied_users'][$test] && $allVals['uid'][0])
{
if(!$query ||
strpos(' ' . $allVals['cn'][0],$query) ||
strpos(' ' . $allVals['givenname'][0],$query) ||
strpos(' ' . $allVals['sn'][0],$query))
if (!$GLOBALS['phpgw_info']['server']['global_denied_users'][$test] && $allVals['uid'][0])
{
$accounts[] = Array(
'account_id' => $allVals['uidnumber'][0],
@ -358,21 +353,23 @@
}
}
}
}
elseif($_type == 'both' || $_type == 'groups')
elseif ($_type == 'groups')
{
$sri = ldap_search($this->ds, $this->group_context, '(&(gidnumber=*)(phpgwaccounttype=g))');
if(empty($query) || $query == "*")
{
$filter = "(&(gidnumber=*)(phpgwaccounttype=g))";
}
else
{
$filter = "(&(gidnumber=*)(phpgwaccounttype=g)(|(uid=*$query*)(sn=*$query*)(cn=*$query*)(givenname=*$query*)))";
}
$sri = ldap_search($this->ds, $this->group_context, $filter);
$allValues = ldap_get_entries($this->ds, $sri);
while(list($null,$allVals) = @each($allValues))
while (list($null,$allVals) = @each($allValues))
{
settype($allVals,'array');
$test = $allVals['cn'][0];
if(!$GLOBALS['phpgw_info']['server']['global_denied_groups'][$test] && $allVals['cn'][0])
{
if(!$query ||
strpos(' ' . $allVals['cn'][0],$query) ||
strpos(' ' . $allVals['givenname'][0],$query) ||
strpos(' ' . $allVals['sn'][0],$query))
if (!$GLOBALS['phpgw_info']['server']['global_denied_groups'][$test] && $allVals['cn'][0])
{
$accounts[] = Array(
'account_id' => $allVals['gidnumber'][0],
@ -385,9 +382,73 @@
}
}
}
else
{
if(empty($query) || $query == "*")
{
$filter = "(&(gidnumber=*)(phpgwaccounttype=*))";
}
else
{
$filter = "(&(gidnumber=*)(phpgwaccounttype=*)(|(uid=*$query*)(sn=*$query*)(cn=*$query*)(givenname=*$query*)))";
}
$sri = ldap_search($this->ds, $this->group_context, $filter);
$allValues = ldap_get_entries($this->ds, $sri);
while (list($null,$allVals) = @each($allValues))
{
settype($allVals,'array');
if($allVals['phpgwaccounttype'][0] == 'u')
{
$_uid = @$allVals['uid'][0];
}
else
{
$_uid = $allVals['cn'][0];
}
if (!$GLOBALS['phpgw_info']['server']['global_denied_groups'][$_uid] && $_uid)
{
$accounts[] = Array(
'account_id' => $allVals['gidnumber'][0],
'account_lid' => $_uid,
'account_type' => $allVals['phpgwaccounttype'][0],
'account_firstname' => $allVals['givenname'][0],
'account_lastname' => $allVals['sn'][0],
'account_status' => $allVals['phpgwaccountstatus'][0]
);
}
}
}
// sort the array
$arrayFunctions = CreateObject('phpgwapi.arrayfunctions');
if(empty($order))
{
$order = 'account_lid';
}
$sortedAccounts = $arrayFunctions->arfsort($accounts,array($order));
$this->total = count($accounts);
return $accounts;
// return only the wanted accounts
if (is_array($sortedAccounts))
{
reset($sortedAccounts);
if(is_int($start) && is_int($offset))
{
return array_slice($sortedAccounts, $start, $offset);
}
elseif(is_int($start))
{
return array_slice($sortedAccounts, $start, $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']);
}
else
{
return $sortedAccounts;
}
}
return False;
}
function name2id($account_lid)

View File

@ -0,0 +1,66 @@
<?php
/**************************************************************************\
* phpGroupWare API - Arrayfunctions *
* This file written by Lars Kneschke <lkneschke@phpgw.de> *
* Copyright (C) 2002 Lars Kneschke *
* ------------------------------------------------------------------------ *
* This library is part of the phpGroupWare API *
* ------------------------------------------------------------------------ *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, *
* or any later version. *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/
/* $Id$ */
class arrayfunctions
{
function arrayfunctions($vars='')
{
}
/*
* arfsort() - (AR)ray (F)ield Sort.
* Sort a multi-dimensional array according
* to a list of fields.
* @param $a The array to sort
* @param $fl Field list (in order of importance)
*/
function arfsort( $a, $fl )
{
$GLOBALS['__ARFSORT_LIST__'] = $fl;
if (is_array($a))
{
usort( $a, array($this,'arfsort_func') );
return $a;
}
return False;
}
/*
* Internal sorting function for arfsort()
*/
function arfsort_func( $a, $b )
{
foreach( $GLOBALS['__ARFSORT_LIST__'] as $f )
{
$strc = strcmp( $a[$f], $b[$f] );
if ( $strc != 0 )
{
return $strc;
}
}
return 0;
}
} // end class arrayfunctions
?>