2001-02-06 21:13:06 +01:00
|
|
|
<?php
|
2004-05-29 18:11:35 +02:00
|
|
|
/**************************************************************************\
|
|
|
|
* eGroupWare API - Accounts manager shared functions *
|
|
|
|
* Written by Joseph Engo <jengo@phpgroupware.org> *
|
|
|
|
* and Bettina Gille [ceb@phpgroupware.org] *
|
|
|
|
* shared functions for other account repository managers *
|
|
|
|
* Copyright (C) 2000 - 2002 Joseph Engo *
|
|
|
|
* Copyright (C) 2003 Joseph Engo, Bettina Gille *
|
|
|
|
* -------------------------------------------------------------------------*
|
|
|
|
* This library is part of the eGroupWare API *
|
|
|
|
* http://www.egroupware.org *
|
|
|
|
* ------------------------------------------------------------------------ *
|
|
|
|
* 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$ */
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
if (empty($GLOBALS['egw_info']['server']['account_repository']))
|
2001-05-02 14:08:11 +02:00
|
|
|
{
|
2005-03-24 14:15:12 +01:00
|
|
|
if (!empty($GLOBALS['egw_info']['server']['auth_type']))
|
2001-05-02 14:08:11 +02:00
|
|
|
{
|
2005-03-24 14:15:12 +01:00
|
|
|
$GLOBALS['egw_info']['server']['account_repository'] = $GLOBALS['egw_info']['server']['auth_type'];
|
2001-05-02 14:08:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-24 14:15:12 +01:00
|
|
|
$GLOBALS['egw_info']['server']['account_repository'] = 'sql';
|
2001-05-02 14:08:11 +02:00
|
|
|
}
|
|
|
|
}
|
2005-03-24 14:15:12 +01:00
|
|
|
include_once(EGW_API_INC . '/class.accounts_' . $GLOBALS['egw_info']['server']['account_repository'] . '.inc.php');
|
2004-05-29 18:11:35 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Dont know where to put this (seek3r)
|
|
|
|
This is where it belongs (jengo)
|
|
|
|
This is where it ended up (milosch)
|
|
|
|
Moved again at least temporarily since sql and ldap use it.
|
|
|
|
*/
|
2005-03-24 14:15:12 +01:00
|
|
|
$GLOBALS['egw_info']['server']['global_denied_users'] = array(
|
2004-05-29 18:11:35 +02:00
|
|
|
'root' => True, 'bin' => True, 'daemon' => True,
|
|
|
|
'adm' => True, 'lp' => True, 'sync' => True,
|
|
|
|
'shutdown' => True, 'halt' => True, 'ldap' => True,
|
|
|
|
'mail' => True, 'news' => True, 'uucp' => True,
|
|
|
|
'operator' => True, 'games' => True, 'gopher' => True,
|
|
|
|
'nobody' => True, 'xfs' => True, 'pgsql' => True,
|
|
|
|
'mysql' => True, 'postgres' => True, 'oracle' => True,
|
|
|
|
'ftp' => True, 'gdm' => True, 'named' => True,
|
|
|
|
'alias' => True, 'web' => True, 'sweep' => True,
|
|
|
|
'cvs' => True, 'qmaild' => True, 'qmaill' => True,
|
|
|
|
'qmaillog' => True, 'qmailp' => True, 'qmailq' => True,
|
|
|
|
'qmailr' => True, 'qmails' => True, 'rpc' => True,
|
|
|
|
'rpcuser' => True, 'amanda' => True, 'apache' => True,
|
|
|
|
'pvm' => True, 'squid' => True, 'ident' => True,
|
|
|
|
'nscd' => True, 'mailnull' => True, 'cyrus' => True,
|
|
|
|
'backup' => True
|
|
|
|
);
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
$GLOBALS['egw_info']['server']['global_denied_groups'] = array(
|
2004-05-29 18:11:35 +02:00
|
|
|
'root' => True, 'bin' => True, 'daemon' => True,
|
|
|
|
'sys' => True, 'adm' => True, 'tty' => True,
|
|
|
|
'disk' => True, 'lp' => True, 'mem' => True,
|
|
|
|
'kmem' => True, 'wheel' => True, 'mail' => True,
|
|
|
|
'uucp' => True, 'man' => True, 'games' => True,
|
|
|
|
'dip' => True, 'ftp' => True, 'nobody' => True,
|
|
|
|
'floppy' => True, 'xfs' => True, 'console' => True,
|
|
|
|
'utmp' => True, 'pppusers' => True, 'popusers' => True,
|
|
|
|
'slipusers' => True, 'slocate' => True, 'mysql' => True,
|
|
|
|
'dnstools' => True, 'web' => True, 'named' => True,
|
|
|
|
'dba' => True, 'oinstall' => True, 'oracle' => True,
|
|
|
|
'gdm' => True, 'sweep' => True, 'cvs' => True,
|
|
|
|
'postgres' => True, 'qmail' => True, 'nofiles' => True,
|
|
|
|
'ldap' => True, 'backup' => True
|
|
|
|
);
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* @class_start accounts
|
|
|
|
* Class for handling user and group accounts
|
|
|
|
*
|
|
|
|
*/
|
2004-05-29 18:11:35 +02:00
|
|
|
|
|
|
|
class accounts extends accounts_
|
|
|
|
{
|
|
|
|
var $memberships = array();
|
|
|
|
var $members = array();
|
|
|
|
var $xmlrpc_methods = array();
|
|
|
|
// enables the session-cache
|
|
|
|
var $use_session_cache = True;
|
|
|
|
|
|
|
|
/**************************************************************************\
|
|
|
|
* Standard constructor for setting $this->account_id *
|
|
|
|
* This constructor sets the account id, if string is sent, converts to id *
|
|
|
|
* I might move this to the accounts_shared if it stays around *
|
|
|
|
\**************************************************************************/
|
|
|
|
function accounts($account_id = '', $account_type='')
|
|
|
|
{
|
|
|
|
// enable the caching in the session onyl for ldap
|
2005-03-24 14:15:12 +01:00
|
|
|
$this->use_session_cache = $GLOBALS['egw_info']['server']['account_repository'] == 'ldap';
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
$this->db = $GLOBALS['egw']->db;
|
2004-05-29 18:11:35 +02:00
|
|
|
|
|
|
|
if($account_id != '')
|
|
|
|
{
|
|
|
|
$this->account_id = get_account_id($account_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($account_type != '')
|
|
|
|
{
|
|
|
|
$this->account_type = $account_type;
|
|
|
|
}
|
|
|
|
|
2004-06-13 22:11:31 +02:00
|
|
|
$this->query_types = array(
|
|
|
|
'all' => 'all fields',
|
|
|
|
'firstname' => 'firstname',
|
|
|
|
'lastname' => 'lastname',
|
|
|
|
'lid' => 'LoginID',
|
2004-07-04 20:34:18 +02:00
|
|
|
'email' => 'email',
|
2004-06-13 22:11:31 +02:00
|
|
|
'start' => 'start with',
|
|
|
|
'exact' => 'exact',
|
|
|
|
);
|
2004-05-29 18:11:35 +02:00
|
|
|
$this->accounts_(); // call constructor of extended class
|
|
|
|
|
|
|
|
$this->xmlrpc_methods[] = array(
|
|
|
|
'name' => 'get_list',
|
|
|
|
'description' => 'Returns a list of accounts and/or groups'
|
|
|
|
);
|
|
|
|
$this->xmlrpc_methods[] = array(
|
|
|
|
'name' => 'name2id',
|
|
|
|
'description' => 'Cross reference account_lid with account_id'
|
|
|
|
);
|
|
|
|
$this->xmlrpc_methods[] = array(
|
|
|
|
'name' => 'id2name',
|
|
|
|
'description' => 'Cross reference account_id with account_lid'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the account-data cache
|
|
|
|
*
|
|
|
|
* The cache is shared between all instances of the account-class and it can be save in the session,
|
|
|
|
* if use_session_cache is set to True
|
|
|
|
*/
|
|
|
|
function setup_cache()
|
|
|
|
{
|
|
|
|
if ($this->use_session_cache && // are we supposed to use a session-cache
|
2005-03-24 14:15:12 +01:00
|
|
|
!@$GLOBALS['egw_info']['accounts']['session_cache_setup'] && // is it already setup
|
2004-05-29 18:11:35 +02:00
|
|
|
// is the account-class ready (startup !)
|
2005-03-24 14:15:12 +01:00
|
|
|
is_object($GLOBALS['egw']->session) && $GLOBALS['egw']->session->account_id)
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
|
|
|
// setting up the session-cache
|
2005-03-24 14:15:12 +01:00
|
|
|
$GLOBALS['egw_info']['accounts']['cache'] = $GLOBALS['egw']->session->appsession('accounts_cache','phpgwapi');
|
|
|
|
$GLOBALS['egw_info']['accounts']['session_cache_setup'] = True;
|
|
|
|
//echo "accounts::setup_cache() cache=<pre>".print_r($GLOBALS['egw_info']['accounts']['cache'],True)."</pre>\n";
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
if (!isset($this->cache))
|
|
|
|
{
|
2005-03-24 14:15:12 +01:00
|
|
|
$this->cache = &$GLOBALS['egw_info']['accounts']['cache'];
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves the account-data cache in the session
|
|
|
|
*
|
|
|
|
* Gets called from common::phpgw_final()
|
|
|
|
*/
|
|
|
|
function save_session_cache()
|
|
|
|
{
|
|
|
|
if ($this->use_session_cache && // are we supposed to use a session-cache
|
2005-03-24 14:15:12 +01:00
|
|
|
$GLOBALS['egw_info']['accounts']['session_cache_setup'] && // is it already setup
|
2004-05-29 18:11:35 +02:00
|
|
|
// is the account-class ready (startup !)
|
2005-03-24 14:15:12 +01:00
|
|
|
is_object($GLOBALS['egw']->session))
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2005-03-24 14:15:12 +01:00
|
|
|
$GLOBALS['egw']->session->appsession('accounts_cache','phpgwapi',$GLOBALS['egw_info']['accounts']['cache']);
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-16 02:31:48 +02:00
|
|
|
/**
|
|
|
|
* Searches / lists accounts: users and/or groups
|
|
|
|
*
|
|
|
|
* @param $param['type'] string/int 'accounts', 'groups', 'owngroups' (groups the user is a member of), 'both'
|
|
|
|
* or integer group-id for a list of members of that group
|
|
|
|
* @param $param['start'] int first account to return (returns offset or max_matches entries) or all if not set
|
|
|
|
* @param $param['sort'] string column to sort after, default account_lid if unset
|
|
|
|
* @param $param['order'] string 'ASC' or 'DESC', default 'DESC' if not set
|
|
|
|
* @param $param['query'] string to search for, no search if unset or empty
|
|
|
|
* @param $param['query_type'] string:
|
|
|
|
* 'all' - query all fields for containing $param[query]
|
|
|
|
* 'start' - query all fields starting with $param[query]
|
|
|
|
* 'exact' - query all fields for exact $param[query]
|
|
|
|
* 'lid','firstname','lastname','email' - query only the given field for containing $param[query]
|
|
|
|
* @param $param['app'] string with an app-name, to limit result on accounts with run-right for that app
|
|
|
|
* @param $param['offset'] int - number of matches to return if start given, default use the value in the prefs
|
|
|
|
* @return array with uid / data pairs, data is an array with account_id, account_lid, account_firstname,
|
|
|
|
* account_lastname, person_id (id of the linked addressbook entry), account_status, account_expires, account_primary_group
|
|
|
|
*/
|
|
|
|
function search($param)
|
|
|
|
{
|
|
|
|
//echo "<p>accounts::search(".print_r($param,True).")</p>\n";
|
|
|
|
$this->setup_cache();
|
|
|
|
$account_search = &$this->cache['account_search'];
|
2004-07-04 19:27:42 +02:00
|
|
|
|
2004-06-16 02:31:48 +02:00
|
|
|
$serial = serialize($param);
|
|
|
|
|
|
|
|
if (isset($account_search[$serial]))
|
|
|
|
{
|
|
|
|
$this->total = $account_search[$serial]['total'];
|
|
|
|
}
|
|
|
|
elseif (function_exists('accounts_::search')) // implements its on search function ==> use it
|
|
|
|
{
|
|
|
|
$account_search[$serial]['data'] = accounts_::search($param);
|
|
|
|
$account_search[$serial]['total'] = $this->total;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$serial2 = $serial;
|
2004-07-04 19:27:42 +02:00
|
|
|
if (is_numeric($param['type']) || $param['app'] || $param['type'] == 'owngroups') // do we need to limit the search on a group or app?
|
2004-06-16 02:31:48 +02:00
|
|
|
{
|
2004-07-04 19:27:42 +02:00
|
|
|
$app = $param['app'];
|
2004-06-16 02:31:48 +02:00
|
|
|
unset($param['app']);
|
|
|
|
if (is_numeric($param['type']))
|
|
|
|
{
|
|
|
|
$group = (int) $param['type'];
|
|
|
|
$param['type'] = 'accounts';
|
|
|
|
}
|
|
|
|
elseif ($param['type'] == 'owngroups')
|
|
|
|
{
|
|
|
|
$group = -1;
|
|
|
|
$param['type'] = 'groups';
|
|
|
|
}
|
|
|
|
$start = $param['start'];
|
|
|
|
unset($param['start']);
|
|
|
|
$serial2 = serialize($param);
|
|
|
|
}
|
|
|
|
if (!isset($account_search[$serial2])) // check if we already did this general search
|
|
|
|
{
|
|
|
|
$account_search[$serial2]['data'] = array();
|
2004-07-04 19:27:42 +02:00
|
|
|
$accounts = accounts_::get_list($param['type'],$param['start'],$param['sort'],$param['order'],$param['query'],$param['offset'],$param['query_type']);
|
2004-06-16 02:31:48 +02:00
|
|
|
if (!$accounts) $accounts = array();
|
|
|
|
foreach($accounts as $data)
|
|
|
|
{
|
|
|
|
$account_search[$serial2]['data'][$data['account_id']] = $data;
|
|
|
|
}
|
|
|
|
$account_search[$serial2]['total'] = $this->total;
|
|
|
|
}
|
2004-07-04 20:34:18 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->total = $account_search[$serial2]['total'];
|
|
|
|
}
|
2004-07-07 11:41:00 +02:00
|
|
|
//echo "accounts_::get_list($param[type],$param[start],$param[sort],$param[order],$param[query],$param[offset],$param[query_type]) returned<pre>".print_r($account_search[$serial2],True)."</pre>\n";
|
2004-06-16 02:31:48 +02:00
|
|
|
if ($app || $group) // limit the search on accounts with run-rights for app or a group
|
|
|
|
{
|
|
|
|
$valid = array();
|
|
|
|
if ($app)
|
|
|
|
{
|
2004-07-07 11:41:00 +02:00
|
|
|
$valid = $this->split_accounts($app,$param['type'] == 'both' ? 'merge' : $param['type']);
|
2004-06-16 02:31:48 +02:00
|
|
|
}
|
|
|
|
if ($group)
|
|
|
|
{
|
2005-03-24 14:15:12 +01:00
|
|
|
$members = $group > 0 ? $GLOBALS['egw']->acl->get_ids_for_location($group, 1, 'phpgw_group') :
|
|
|
|
$GLOBALS['egw']->acl->get_location_list_for_id('phpgw_group', 1,$GLOBALS['egw_info']['user']['account_id']);
|
2004-06-16 02:31:48 +02:00
|
|
|
if (!$members) $members = array();
|
|
|
|
$valid = !$app ? $members : array_intersect($valid,$members); // use the intersection
|
|
|
|
}
|
2004-07-04 20:34:18 +02:00
|
|
|
//echo "<p>limiting result to app='app' and/or group=$group valid-ids=".print_r($valid,true)."</p>\n";
|
2005-03-24 14:15:12 +01:00
|
|
|
$offset = $param['offset'] ? $param['offset'] : $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
|
2004-06-16 02:31:48 +02:00
|
|
|
$stop = $start + $offset;
|
|
|
|
$n = 0;
|
|
|
|
$account_search[$serial]['data'] = array();
|
|
|
|
foreach ($account_search[$serial2]['data'] as $id => $data)
|
|
|
|
{
|
|
|
|
if (!in_array($id,$valid))
|
2004-07-07 11:43:01 +02:00
|
|
|
{
|
2004-06-16 02:31:48 +02:00
|
|
|
$this->total--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// now we have a valid entry
|
|
|
|
if (!is_int($start) || $start <= $n && $n < $stop)
|
|
|
|
{
|
|
|
|
$account_search[$serial]['data'][$id] = $data;
|
|
|
|
}
|
|
|
|
$n++;
|
|
|
|
}
|
|
|
|
$account_search[$serial]['total'] = $this->total;
|
|
|
|
}
|
|
|
|
}
|
2004-07-04 19:27:42 +02:00
|
|
|
//echo "<p>accounts::search('$serial')=<pre>".print_r($account_search[$serial]['data'],True).")</pre>\n";
|
2004-06-16 02:31:48 +02:00
|
|
|
return $account_search[$serial]['data'];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-13 22:11:31 +02:00
|
|
|
function get_list($_type='both',$start = '',$sort = '', $order = '', $query = '', $offset = '',$query_type='')
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
|
|
|
//echo "<p>accounts::get_list(".print_r($_type,True).",start='$start',sort='$sort',order='$order',query='$query',offset='$offset')</p>\n";
|
|
|
|
$this->setup_cache();
|
|
|
|
$account_list = &$this->cache['account_list'];
|
|
|
|
|
|
|
|
// For XML-RPC
|
|
|
|
if (is_array($_type))
|
|
|
|
{
|
2004-06-16 02:31:48 +02:00
|
|
|
$p = $_type;
|
2004-05-29 18:11:35 +02:00
|
|
|
$_type = $p['type'];
|
|
|
|
$start = $p['start'];
|
|
|
|
$order = $p['order'];
|
|
|
|
$query = $p['query'];
|
|
|
|
$offset = $p['offset'];
|
2004-06-13 22:11:31 +02:00
|
|
|
$query_type = $p['query_type'];
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$p = array(
|
|
|
|
'type' => $_type,
|
|
|
|
'start' => $start,
|
|
|
|
'order' => $order,
|
|
|
|
'query' => $query,
|
2004-06-13 22:11:31 +02:00
|
|
|
'offset' => $offset,
|
|
|
|
'query_type' => $query_type ,
|
2004-05-29 18:11:35 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
$serial = serialize($p);
|
|
|
|
|
|
|
|
if (isset($account_list[$serial]))
|
|
|
|
{
|
|
|
|
$this->total = $account_list[$serial]['total'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-13 22:11:31 +02:00
|
|
|
$account_list[$serial]['data'] = accounts_::get_list($_type,$start,$sort,$order,$query,$offset,$query_type);
|
2004-05-29 18:11:35 +02:00
|
|
|
$account_list[$serial]['total'] = $this->total;
|
|
|
|
}
|
|
|
|
return $account_list[$serial]['data'];
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_expired()
|
|
|
|
{
|
|
|
|
if ($this->data['expires'] != -1 && $this->data['expires'] < time())
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invalidate the cache (or parts of it) after change in $account_id
|
|
|
|
*
|
|
|
|
* Atm simplest approach - delete it all ;-)
|
|
|
|
*/
|
|
|
|
function cache_invalidate($account_id)
|
|
|
|
{
|
|
|
|
//echo "<p>accounts::cache_invalidate($account_id)</p>\n";
|
2005-03-24 14:15:12 +01:00
|
|
|
$GLOBALS['egw_info']['accounts']['cache'] = array();
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function save_repository()
|
|
|
|
{
|
|
|
|
$this->cache_invalidate($this->account_id);
|
|
|
|
accounts_::save_repository();
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete($accountid)
|
|
|
|
{
|
|
|
|
$this->cache_invalidate($accountid);
|
|
|
|
accounts_::delete($accountid);
|
2004-08-07 14:46:58 +02:00
|
|
|
|
|
|
|
// delete all acl_entries belonging to that user or group
|
2005-03-24 14:15:12 +01:00
|
|
|
$GLOBALS['egw']->acl->delete_account($accountid);
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function create($account_info,$default_prefs=True)
|
|
|
|
{
|
|
|
|
$account_id = accounts_::create($account_info,$default_prefs);
|
|
|
|
$this->cache_invalidate($account_id);
|
|
|
|
|
|
|
|
return $account_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
function read_repository()
|
|
|
|
{
|
|
|
|
$this->setup_cache();
|
|
|
|
$account_data = &$this->cache['account_data'];
|
|
|
|
|
|
|
|
if (isset($account_data[$this->account_id]))
|
|
|
|
{
|
|
|
|
return $this->data = $account_data[$this->account_id];
|
|
|
|
}
|
|
|
|
return $account_data[$this->account_id] = accounts_::read_repository();
|
|
|
|
}
|
|
|
|
|
|
|
|
function read()
|
|
|
|
{
|
|
|
|
if (count($this->data) == 0)
|
|
|
|
{
|
|
|
|
$this->read_repository();
|
|
|
|
}
|
|
|
|
|
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_data($data)
|
|
|
|
{
|
|
|
|
reset($data);
|
|
|
|
$this->data = Array();
|
|
|
|
$this->data = $data;
|
|
|
|
|
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function membership($accountid = '')
|
|
|
|
{
|
|
|
|
$this->setup_cache();
|
|
|
|
$membership_list = &$this->cache['membership_list'];
|
|
|
|
|
|
|
|
$account_id = get_account_id($accountid);
|
|
|
|
|
|
|
|
if (isset($membership_list[$account_id]))
|
|
|
|
{
|
|
|
|
return $membership_list[$account_id];
|
|
|
|
}
|
|
|
|
|
|
|
|
$security_equals = Array();
|
2005-03-24 14:15:12 +01:00
|
|
|
$security_equals = $GLOBALS['egw']->acl->get_location_list_for_id('phpgw_group', 1, $account_id);
|
2004-05-29 18:11:35 +02:00
|
|
|
|
|
|
|
if ($security_equals == False)
|
|
|
|
{
|
|
|
|
return $membership_list[$account_id] = False;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->memberships = Array();
|
|
|
|
|
|
|
|
for ($idx=0; $idx<count($security_equals); $idx++)
|
|
|
|
{
|
|
|
|
$groups = (int)$security_equals[$idx];
|
|
|
|
$this->memberships[] = Array('account_id' => $groups, 'account_name' => $this->id2name($groups));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $membership_list[$account_id] = $this->memberships;
|
|
|
|
}
|
|
|
|
|
|
|
|
function member($accountid = '')
|
|
|
|
{
|
|
|
|
$account_id = get_account_id($accountid);
|
|
|
|
|
|
|
|
$security_equals = Array();
|
2005-03-24 14:15:12 +01:00
|
|
|
$acl =& CreateObject('phpgwapi.acl');
|
2004-05-29 18:11:35 +02:00
|
|
|
$security_equals = $acl->get_ids_for_location($account_id, 1, 'phpgw_group');
|
|
|
|
unset($acl);
|
|
|
|
|
|
|
|
if ($security_equals == False)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ($idx=0; $idx<count($security_equals); $idx++)
|
|
|
|
{
|
|
|
|
$name = $this->id2name((int)$security_equals[$idx]);
|
|
|
|
$this->members[] = Array('account_id' => (int)$security_equals[$idx], 'account_name' => $name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->members;
|
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* Using the common functions next_id and last_id, find the next available account_id
|
|
|
|
*
|
|
|
|
* @param $account_type (optional, default to 'u')
|
|
|
|
*/
|
2004-06-16 02:31:48 +02:00
|
|
|
// NOTE: to my knowledge this is not used any more RalfBecker 2004/06/15
|
2004-05-29 18:11:35 +02:00
|
|
|
function get_nextid($account_type='u')
|
|
|
|
{
|
2005-03-24 14:15:12 +01:00
|
|
|
$min = $GLOBALS['egw_info']['server']['account_min_id'] ? $GLOBALS['egw_info']['server']['account_min_id'] : 0;
|
|
|
|
$max = $GLOBALS['egw_info']['server']['account_max_id'] ? $GLOBALS['egw_info']['server']['account_max_id'] : 0;
|
2004-05-29 18:11:35 +02:00
|
|
|
|
|
|
|
if ($account_type == 'g')
|
|
|
|
{
|
|
|
|
$type = 'groups';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$type = 'accounts';
|
|
|
|
}
|
2005-03-24 14:15:12 +01:00
|
|
|
$nextid = (int)$GLOBALS['egw']->common->last_id($type,$min,$max);
|
2004-05-29 18:11:35 +02:00
|
|
|
|
|
|
|
/* Loop until we find a free id */
|
|
|
|
$free = 0;
|
|
|
|
while (!$free)
|
|
|
|
{
|
|
|
|
$account_lid = '';
|
|
|
|
//echo '<br>calling search for id: '.$nextid;
|
|
|
|
if ($this->exists($nextid))
|
|
|
|
{
|
2005-03-24 14:15:12 +01:00
|
|
|
$nextid = (int)$GLOBALS['egw']->common->next_id($type,$min,$max);
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$account_lid = $this->id2name($nextid);
|
|
|
|
/* echo '<br>calling search for lid: '.$account_lid . '(from account_id=' . $nextid . ')'; */
|
|
|
|
if ($this->exists($account_lid))
|
|
|
|
{
|
2005-03-24 14:15:12 +01:00
|
|
|
$nextid = (int)$GLOBALS['egw']->common->next_id($type,$min,$max);
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$free = True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-03-24 14:15:12 +01:00
|
|
|
if ($GLOBALS['egw_info']['server']['account_max_id'] &&
|
|
|
|
($nextid > $GLOBALS['egw_info']['server']['account_max_id']))
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
/* echo '<br>using'.$nextid;exit; */
|
|
|
|
return $nextid;
|
|
|
|
}
|
|
|
|
|
2004-06-16 02:31:48 +02:00
|
|
|
|
2004-05-29 18:11:35 +02:00
|
|
|
/**
|
2004-06-16 02:31:48 +02:00
|
|
|
* splits users and groups from a array of id's or the accounts with run-rights for a given app-name
|
2004-05-29 18:11:35 +02:00
|
|
|
*
|
2004-06-16 02:31:48 +02:00
|
|
|
* @param $app_users array of user-id's or app-name (if you use app-name the result gets cached!)
|
|
|
|
* @param $use string what should be returned only an array with id's of either 'accounts' or 'groups'.
|
2004-07-07 11:41:00 +02:00
|
|
|
* Or an array with arrays for 'both' under the keys 'groups' and 'accounts' or 'merge' for accounts
|
|
|
|
* and groups merged into one array
|
2004-06-16 02:31:48 +02:00
|
|
|
* @return see $use
|
2004-05-29 18:11:35 +02:00
|
|
|
*/
|
2004-06-16 02:31:48 +02:00
|
|
|
function split_accounts($app_users,$use='both')
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2004-06-16 02:31:48 +02:00
|
|
|
if (!is_array($app_users))
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2004-06-16 02:31:48 +02:00
|
|
|
$this->setup_cache();
|
|
|
|
$cache = &$this->cache['account_split'][$app_user];
|
|
|
|
|
|
|
|
if (is_array($cache))
|
|
|
|
{
|
|
|
|
return $cache;
|
|
|
|
}
|
2005-03-24 14:15:12 +01:00
|
|
|
$app_users = $GLOBALS['egw']->acl->get_ids_for_location('run',1,$app_users);
|
2004-06-16 02:31:48 +02:00
|
|
|
}
|
|
|
|
$accounts = array(
|
|
|
|
'accounts' => array(),
|
|
|
|
'groups' => array(),
|
|
|
|
);
|
|
|
|
foreach($app_users as $id)
|
|
|
|
{
|
2005-03-24 14:15:12 +01:00
|
|
|
$type = $GLOBALS['egw']->accounts->get_type($id);
|
2004-05-29 18:11:35 +02:00
|
|
|
if($type == 'g')
|
|
|
|
{
|
2004-06-16 02:31:48 +02:00
|
|
|
$accounts['groups'][$id] = $id;
|
2005-03-24 14:15:12 +01:00
|
|
|
foreach((array)$GLOBALS['egw']->acl->get_ids_for_location($id,1,'phpgw_group') as $id)
|
2004-06-16 02:31:48 +02:00
|
|
|
{
|
|
|
|
$accounts['accounts'][$id] = $id;
|
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-16 02:31:48 +02:00
|
|
|
$accounts['accounts'][$id] = $id;
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-16 02:31:48 +02:00
|
|
|
// not sure why they need to be sorted, but we need to remove the keys anyway
|
|
|
|
sort($accounts['groups']);
|
|
|
|
sort($accounts['accounts']);
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2004-06-16 02:31:48 +02:00
|
|
|
if (isset($cache))
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2004-06-16 02:31:48 +02:00
|
|
|
$cache = $accounts;
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2004-06-16 02:31:48 +02:00
|
|
|
//echo "<p>accounts::split_accounts(".print_r($app_users,True).",'$use') = <pre>".print_r($accounts,True)."</pre>\n";
|
|
|
|
|
|
|
|
switch($use)
|
2004-06-10 17:07:40 +02:00
|
|
|
{
|
2004-06-16 02:31:48 +02:00
|
|
|
case 'both':
|
|
|
|
return $accounts;
|
|
|
|
case 'groups':
|
|
|
|
return $accounts['groups'];
|
|
|
|
case 'accounts':
|
|
|
|
return $accounts['accounts'];
|
2004-07-07 11:41:00 +02:00
|
|
|
case 'merge':
|
|
|
|
return array_merge($accounts['accounts'],$accounts['groups']);
|
2004-06-10 17:07:40 +02:00
|
|
|
}
|
2004-07-07 11:41:00 +02:00
|
|
|
return False;
|
2004-06-16 02:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* phpgw compatibility function, better use split_accounts
|
|
|
|
*/
|
|
|
|
function return_members($accounts)
|
|
|
|
{
|
|
|
|
$arr = $this->split_accounts($accounts);
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'users' => $arr['accounts'],
|
|
|
|
'groups' => $arr['groups'],
|
|
|
|
);
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
|
2004-07-04 19:27:42 +02:00
|
|
|
function name2id($name,$which='account_lid')
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
|
|
|
$this->setup_cache();
|
|
|
|
$name_list = &$this->cache['name_list'];
|
|
|
|
|
2004-07-04 19:27:42 +02:00
|
|
|
if(@isset($name_list[$which][$name]) && $name_list[$which][$name])
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2004-07-04 19:27:42 +02:00
|
|
|
return $name_list[$which][$name];
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't bother searching for empty account_lid */
|
2004-07-04 19:27:42 +02:00
|
|
|
if(empty($name))
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2004-07-04 19:27:42 +02:00
|
|
|
return $name_list[$which][$name] = accounts_::name2id($name,$which);
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
|
2004-07-04 19:27:42 +02:00
|
|
|
function id2name($account_id,$which='account_lid')
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
|
|
|
$this->setup_cache();
|
|
|
|
$id_list = &$this->cache['id_list'];
|
|
|
|
|
|
|
|
if (! $account_id)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2004-07-04 19:27:42 +02:00
|
|
|
if($id_list[$account_id][$which])
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2004-07-04 19:27:42 +02:00
|
|
|
return $id_list[$account_id][$which];
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2004-07-04 19:27:42 +02:00
|
|
|
return $id_list[$account_id][$which] = accounts_::id2name($account_id,$which);
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_type($accountid)
|
|
|
|
{
|
|
|
|
$this->setup_cache();
|
|
|
|
$account_type = &$this->cache['account_type'];
|
|
|
|
|
|
|
|
$account_id = get_account_id($accountid);
|
|
|
|
|
|
|
|
if (isset($this->account_type) && $account_id == $this->account_id)
|
|
|
|
{
|
|
|
|
return $this->account_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(@isset($account_type[$account_id]) && @$account_type[$account_id])
|
|
|
|
{
|
|
|
|
return $account_type[$account_id];
|
|
|
|
}
|
|
|
|
elseif($account_id == '')
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
return $account_type[$account_id] = accounts_::get_type($account_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_account_name($accountid,&$lid,&$fname,&$lname)
|
|
|
|
{
|
|
|
|
$this->setup_cache();
|
|
|
|
$account_name = &$this->cache['account_name'];
|
|
|
|
|
|
|
|
$account_id = get_account_id($accountid);
|
|
|
|
if(isset($account_name[$account_id]))
|
|
|
|
{
|
|
|
|
$lid = $account_name[$account_id]['lid'];
|
|
|
|
$fname = $account_name[$account_id]['fname'];
|
|
|
|
$lname = $account_name[$account_id]['lname'];
|
|
|
|
return $account_name[$account_id] !== False;
|
|
|
|
}
|
|
|
|
$Ok = accounts_::get_account_name($accountid,$lid,$fname,$lname);
|
|
|
|
|
|
|
|
$account_name[$account_id] = array(
|
|
|
|
'lid' => $lid,
|
|
|
|
'fname' => $fname,
|
|
|
|
'lname' => $lname,
|
|
|
|
);
|
|
|
|
return $Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_account_data($account_id)
|
|
|
|
{
|
|
|
|
$this->account_id = $account_id;
|
|
|
|
$this->read_repository();
|
|
|
|
|
|
|
|
$data[$this->data['account_id']]['lid'] = $this->data['account_lid'];
|
|
|
|
$data[$this->data['account_id']]['firstname'] = $this->data['firstname'];
|
|
|
|
$data[$this->data['account_id']]['lastname'] = $this->data['lastname'];
|
|
|
|
$data[$this->data['account_id']]['fullname'] = $this->data['fullname'];
|
|
|
|
$data[$this->data['account_id']]['type'] = $this->data['account_type'];
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|