2001-02-06 21:13:06 +01:00
|
|
|
<?php
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
2012-03-14 16:22:51 +01:00
|
|
|
* EGroupware API - accounts
|
2006-06-07 01:42:36 +02:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> complete rewrite in 6/2006 and earlier modifications
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
|
|
|
* Implements the (now depricated) interfaces on the former accounts class written by
|
2006-06-07 01:42:36 +02:00
|
|
|
* Joseph Engo <jengo@phpgroupware.org> and Bettina Gille <ceb@phpgroupware.org>
|
|
|
|
* Copyright (C) 2000 - 2002 Joseph Engo, Copyright (C) 2003 Joseph Engo, Bettina Gille
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
2006-06-07 01:42:36 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package api
|
|
|
|
* @subpackage accounts
|
|
|
|
* @access public
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* API - accounts
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
2007-12-13 03:32:44 +01:00
|
|
|
* This class uses a backend class (at them moment SQL or LDAP) and implements some
|
2012-08-06 12:06:59 +02:00
|
|
|
* caching on to top of the backend functions:
|
|
|
|
*
|
|
|
|
* a) instance-wide account-data cache queried by account_id including also members(hips)
|
|
|
|
* implemented by self::cache_read($account_id) and self::cache_invalidate($account_ids)
|
|
|
|
*
|
|
|
|
* b) session based cache for search, split_accounts and name2id
|
|
|
|
* implemented by self::setup_cache() and self::cache_invalidate()
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
|
|
|
* The backend only implements the read, save, delete, name2id and the {set_}members{hips} methods.
|
2006-06-07 01:42:36 +02:00
|
|
|
* The account class implements all other (eg. name2id, id2name) functions on top of these.
|
|
|
|
*
|
2012-03-14 16:22:51 +01:00
|
|
|
* read and search return timestamps (account_(created|modified|lastlogin) in server-time!
|
2006-06-07 01:42:36 +02:00
|
|
|
*/
|
2007-12-13 03:32:44 +01:00
|
|
|
class accounts
|
2006-06-07 01:42:36 +02:00
|
|
|
{
|
|
|
|
var $xmlrpc_methods = array(
|
|
|
|
array(
|
|
|
|
'name' => 'search',
|
|
|
|
'description' => 'Returns a list of accounts and/or groups'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'name2id',
|
|
|
|
'description' => 'Cross reference account_lid with account_id'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'id2name',
|
|
|
|
'description' => 'Cross reference account_id with account_lid'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'get_list',
|
|
|
|
'description' => 'Depricated: use search. Returns a list of accounts and/or groups'
|
|
|
|
),
|
2004-05-29 18:11:35 +02:00
|
|
|
);
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
2009-12-07 18:56:31 +01:00
|
|
|
* Enables the session-cache, currently switched on independent of the backend
|
|
|
|
*
|
2006-06-07 01:42:36 +02:00
|
|
|
* @var boolean $use_session_cache
|
|
|
|
*/
|
2009-12-07 18:56:31 +01:00
|
|
|
static $use_session_cache = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cache, stored in sesssion
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
static $cache;
|
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Depricated: Account this class was instanciated for
|
|
|
|
*
|
|
|
|
* @deprecated dont use this in new code, always explcitly specify the account to use
|
|
|
|
* @var int account_id
|
|
|
|
*/
|
|
|
|
var $account_id;
|
|
|
|
/**
|
|
|
|
* Depricated: Account data of $this->account_id
|
|
|
|
*
|
|
|
|
* @deprecated dont use this in new code, store the data in your own code
|
2007-12-13 03:32:44 +01:00
|
|
|
* @var array
|
2006-06-07 01:42:36 +02:00
|
|
|
*/
|
|
|
|
var $data;
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
2006-06-07 01:42:36 +02:00
|
|
|
* Keys for which both versions with 'account_' prefix and without (depricated!) can be used, if requested.
|
|
|
|
* Migrate your code to always use the 'account_' prefix!!!
|
2005-04-25 12:09:10 +02:00
|
|
|
*
|
2006-06-07 01:42:36 +02:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $depricated_names = array('firstname','lastname','fullname','email','type',
|
|
|
|
'status','expires','lastlogin','lastloginfrom','lastpasswd_change');
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-10-28 11:32:56 +02:00
|
|
|
/**
|
|
|
|
* Querytypes for the account-search
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $query_types = array(
|
|
|
|
'all' => 'all fields',
|
|
|
|
'firstname' => 'firstname',
|
|
|
|
'lastname' => 'lastname',
|
|
|
|
'lid' => 'LoginID',
|
2009-12-07 18:56:31 +01:00
|
|
|
'email' => 'email',
|
2006-10-28 11:32:56 +02:00
|
|
|
'start' => 'start with',
|
|
|
|
'exact' => 'exact',
|
|
|
|
);
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2007-12-13 03:32:44 +01:00
|
|
|
/**
|
|
|
|
* Backend to use
|
|
|
|
*
|
|
|
|
* @var accounts_sql|accounts_ldap
|
|
|
|
*/
|
|
|
|
var $backend;
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2007-12-13 03:32:44 +01:00
|
|
|
/**
|
|
|
|
* total number of found entries
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
var $total;
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2007-12-13 03:32:44 +01:00
|
|
|
/**
|
|
|
|
* Current configuration
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $config;
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2008-02-08 12:16:09 +01:00
|
|
|
/**
|
|
|
|
* hold an instance of the accounts class
|
|
|
|
*
|
|
|
|
* @var accounts the instance of the accounts class
|
|
|
|
*/
|
|
|
|
private static $_instance = NULL;
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2008-02-08 12:16:09 +01:00
|
|
|
/**
|
|
|
|
* the singleton passtern
|
|
|
|
*
|
|
|
|
* @return accounts
|
|
|
|
*/
|
|
|
|
public static function getInstance()
|
|
|
|
{
|
2009-12-07 18:56:31 +01:00
|
|
|
if (self::$_instance === NULL)
|
|
|
|
{
|
2008-02-08 12:16:09 +01:00
|
|
|
self::$_instance = new accounts;
|
|
|
|
}
|
|
|
|
return self::$_instance;
|
2009-12-07 18:56:31 +01:00
|
|
|
}
|
2007-12-13 03:32:44 +01:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
2007-12-13 03:32:44 +01:00
|
|
|
* @param string|array $backend=null string with backend 'sql'|'ldap', or whole config array, default read from global egw_info
|
|
|
|
*/
|
2008-02-08 12:16:09 +01:00
|
|
|
public function __construct($backend=null)
|
2007-12-13 03:32:44 +01:00
|
|
|
{
|
|
|
|
if (is_numeric($backend)) // depricated use with account_id
|
|
|
|
{
|
|
|
|
if ((int)$backend) $this->account_id = (int) $backend;
|
|
|
|
$backend = null;
|
|
|
|
}
|
|
|
|
if (is_array($backend))
|
|
|
|
{
|
|
|
|
$this->config = $backend;
|
|
|
|
$backend = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->config =& $GLOBALS['egw_info']['server'];
|
|
|
|
}
|
|
|
|
if (is_null($backend))
|
|
|
|
{
|
|
|
|
if (empty($this->config['account_repository']))
|
|
|
|
{
|
|
|
|
if (!empty($this->config['auth_type']))
|
|
|
|
{
|
|
|
|
$this->config['account_repository'] = $this->config['auth_type'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->config['account_repository'] = 'sql';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$backend = $this->config['account_repository'];
|
|
|
|
}
|
|
|
|
$backend_class = 'accounts_'.$backend;
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2007-12-13 03:32:44 +01:00
|
|
|
$this->backend = new $backend_class($this);
|
|
|
|
}
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2007-12-13 03:32:44 +01:00
|
|
|
/**
|
|
|
|
* Old constructor name
|
|
|
|
*
|
|
|
|
* @param int $account_id=0 depricated param to instanciate for the given account_id
|
|
|
|
* @deprecated use __construct
|
2006-06-07 01:42:36 +02:00
|
|
|
*/
|
|
|
|
function accounts($account_id=0)
|
|
|
|
{
|
2007-12-13 03:32:44 +01:00
|
|
|
$this->account_id = (int) $account_id;
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2007-12-13 03:32:44 +01:00
|
|
|
$this->__construct();
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2008-02-08 12:16:09 +01:00
|
|
|
/**
|
|
|
|
* set the accountId
|
|
|
|
*
|
|
|
|
* @param int $accountId
|
2009-12-07 18:56:31 +01:00
|
|
|
* @deprecated
|
2008-02-08 12:16:09 +01:00
|
|
|
*/
|
|
|
|
function setAccountId($accountId)
|
|
|
|
{
|
2009-12-07 18:56:31 +01:00
|
|
|
if($accountId && is_numeric($accountId))
|
|
|
|
{
|
2008-02-08 12:16:09 +01:00
|
|
|
$this->account_id = (int)$accountId;
|
|
|
|
}
|
|
|
|
}
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Searches / lists accounts: users and/or groups
|
|
|
|
*
|
|
|
|
* @param array with the following keys:
|
2011-09-07 18:44:00 +02:00
|
|
|
* @param $param['type'] string/int 'accounts', 'groups', 'owngroups' (groups the user is a member of), 'both',
|
|
|
|
* 'groupmembers' (members of groups the user is a member of), 'groupmembers+memberships' (incl. memberships too)
|
2006-06-07 01:42:36 +02:00
|
|
|
* 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
|
2007-01-08 09:57:33 +01:00
|
|
|
* @param $param['order'] string column to sort after, default account_lid if unset
|
|
|
|
* @param $param['sort'] string 'ASC' or 'DESC', default 'DESC' if not set
|
2006-06-07 01:42:36 +02:00
|
|
|
* @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
|
2013-01-25 14:21:31 +01:00
|
|
|
* @param $param['active']=true boolean - true: return only acctive accounts, false: return expired or deactivated too
|
2010-03-20 14:24:01 +01:00
|
|
|
* @return array with account_id => data pairs, data is an array with account_id, account_lid, account_firstname,
|
2006-06-07 01:42:36 +02:00
|
|
|
* account_lastname, person_id (id of the linked addressbook entry), account_status, account_expires, account_primary_group
|
|
|
|
*/
|
|
|
|
function search($param)
|
|
|
|
{
|
2013-01-25 14:21:31 +01:00
|
|
|
//error_log(__METHOD__.'('.array2string($param).') '.function_backtrace());
|
|
|
|
if (!isset($param['active'])) $param['active'] = true; // default is true = only return active accounts
|
|
|
|
|
2009-12-07 18:56:31 +01:00
|
|
|
self::setup_cache();
|
|
|
|
$account_search = &self::$cache['account_search'];
|
2006-06-07 01:42:36 +02:00
|
|
|
$serial = serialize($param);
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
if (isset($account_search[$serial]))
|
|
|
|
{
|
|
|
|
$this->total = $account_search[$serial]['total'];
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2010-03-20 14:24:01 +01:00
|
|
|
// no backend understands $param['app'] and sql does not understand group-parameters
|
|
|
|
// --> do an full search first and then filter and limit that search
|
|
|
|
elseif($param['app'] || $this->config['account_repository'] != 'ldap' &&
|
2011-09-07 18:44:00 +02:00
|
|
|
(is_numeric($param['type']) || in_array($param['type'],array('owngroups','groupmembers','groupmembers+memberships'))))
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2010-03-20 14:24:01 +01:00
|
|
|
$app = $param['app'];
|
|
|
|
unset($param['app']);
|
|
|
|
$start = $param['start'];
|
|
|
|
unset($param['start']);
|
|
|
|
|
2010-04-23 12:55:09 +02:00
|
|
|
if ($this->config['account_repository'] != 'ldap' && is_numeric($param['type']))
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2011-09-08 11:57:32 +02:00
|
|
|
$members = $this->members($param['type'],true);
|
2010-04-23 12:55:09 +02:00
|
|
|
$param['type'] = 'accounts';
|
|
|
|
}
|
|
|
|
elseif ($param['type'] == 'owngroups')
|
|
|
|
{
|
2011-09-07 18:44:00 +02:00
|
|
|
$members = $this->memberships($GLOBALS['egw_info']['user']['account_id'],true);
|
2010-04-23 12:55:09 +02:00
|
|
|
$param['type'] = 'groups';
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2011-09-07 18:44:00 +02:00
|
|
|
elseif(in_array($param['type'],array('groupmembers','groupmembers+memberships')))
|
|
|
|
{
|
|
|
|
$members = array();
|
2012-08-09 10:56:28 +02:00
|
|
|
foreach((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $grp)
|
2011-09-07 18:44:00 +02:00
|
|
|
{
|
2012-08-09 10:56:28 +02:00
|
|
|
$members = array_unique(array_merge($members, (array)$this->members($grp,true)));
|
2011-09-07 18:44:00 +02:00
|
|
|
if ($param['type'] == 'groupmembers+memberships') $members[] = $grp;
|
|
|
|
}
|
|
|
|
$param['type'] = $param['type'] == 'groupmembers+memberships' ? 'both' : 'accounts';
|
|
|
|
}
|
2010-03-20 14:24:01 +01:00
|
|
|
// call ourself recursive to get (evtl. cached) full search
|
|
|
|
$full_search = $this->search($param);
|
|
|
|
|
|
|
|
// filter search now on accounts with run-rights for app or a group
|
|
|
|
$valid = array();
|
|
|
|
if ($app)
|
2004-06-16 02:31:48 +02:00
|
|
|
{
|
2010-03-24 14:53:28 +01:00
|
|
|
// we want the result merged, whatever it takes, as we only care for the ids
|
2010-03-25 09:48:58 +01:00
|
|
|
$valid = $this->split_accounts($app,!in_array($param['type'],array('accounts','groups')) ? 'merge' : $param['type']);
|
2004-06-16 02:31:48 +02:00
|
|
|
}
|
2011-09-07 18:44:00 +02:00
|
|
|
if (isset($members))
|
2004-06-16 02:31:48 +02:00
|
|
|
{
|
2011-09-07 18:44:00 +02:00
|
|
|
//error_log(__METHOD__.'() members='.array2string($members));
|
2010-03-20 14:24:01 +01:00
|
|
|
if (!$members) $members = array();
|
|
|
|
$valid = !$app ? $members : array_intersect($valid,$members); // use the intersection
|
2004-06-16 02:31:48 +02:00
|
|
|
}
|
2010-03-24 14:53:28 +01:00
|
|
|
//echo "<p>limiting result to app='$app' and/or group=$group valid-ids=".print_r($valid,true)."</p>\n";
|
2010-03-20 14:24:01 +01:00
|
|
|
$offset = $param['offset'] ? $param['offset'] : $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
|
|
|
|
$stop = $start + $offset;
|
|
|
|
$n = 0;
|
|
|
|
$account_search[$serial]['data'] = array();
|
|
|
|
foreach ($full_search as $id => $data)
|
2004-06-16 02:31:48 +02:00
|
|
|
{
|
2010-03-20 14:24:01 +01:00
|
|
|
if (!in_array($id,$valid))
|
2004-06-16 02:31:48 +02:00
|
|
|
{
|
2010-03-20 14:24:01 +01:00
|
|
|
$this->total--;
|
|
|
|
continue;
|
2004-06-16 02:31:48 +02:00
|
|
|
}
|
2010-03-20 14:24:01 +01:00
|
|
|
// now we have a valid entry
|
|
|
|
if (!is_int($start) || $start <= $n && $n < $stop)
|
2004-07-04 20:34:18 +02:00
|
|
|
{
|
2010-03-20 14:24:01 +01:00
|
|
|
$account_search[$serial]['data'][$id] = $data;
|
2004-06-16 02:31:48 +02:00
|
|
|
}
|
2010-03-20 14:24:01 +01:00
|
|
|
$n++;
|
2004-06-16 02:31:48 +02:00
|
|
|
}
|
2010-03-20 14:24:01 +01:00
|
|
|
$account_search[$serial]['total'] = $this->total;
|
|
|
|
}
|
|
|
|
// search via ldap backend
|
|
|
|
elseif ($this->config['account_repository'] == 'ldap')
|
|
|
|
//not correct for php<5.1 elseif ((method_exists($this,'search')) // implements its on search function ==> use it
|
|
|
|
{
|
|
|
|
$account_search[$serial]['data'] = $this->backend->search($param);
|
|
|
|
$account_search[$serial]['total'] = $this->total = $this->backend->total;
|
|
|
|
}
|
|
|
|
// search by old accounts_sql backend
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$account_search[$serial]['data'] = array();
|
2013-01-25 14:21:31 +01:00
|
|
|
$accounts = $this->backend->get_list($param['type'],$param['start'],$param['sort'],$param['order'],$param['query'],$param['offset'],$param['query_type'],$param['active']);
|
2010-03-20 14:24:01 +01:00
|
|
|
if (!$accounts) $accounts = array();
|
|
|
|
foreach($accounts as $data)
|
|
|
|
{
|
|
|
|
$account_search[$serial]['data'][$data['account_id']] = $data;
|
|
|
|
}
|
|
|
|
$account_search[$serial]['total'] = $this->total = $this->backend->total;
|
2004-06-16 02:31:48 +02:00
|
|
|
}
|
2010-03-20 14:24:01 +01:00
|
|
|
//echo "<p>accounts::search(".array2string(unserialize($serial)).")= returning ".count($account_search[$serial]['data'])." of $this->total entries<pre>".print_r($account_search[$serial]['data'],True)."</pre>\n";
|
2006-09-15 18:19:39 +02:00
|
|
|
//echo "<p>accounts::search() end: ".microtime()."</p>\n";
|
2006-06-07 01:42:36 +02:00
|
|
|
return $account_search[$serial]['data'];
|
|
|
|
}
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2011-09-07 16:47:51 +02:00
|
|
|
/**
|
|
|
|
* Query for accounts
|
|
|
|
*
|
|
|
|
* @param string|array $pattern
|
|
|
|
* @param array $options
|
|
|
|
* @return array with id - title pairs of the matching entries
|
|
|
|
*/
|
|
|
|
public static function link_query($pattern, array &$options = array())
|
|
|
|
{
|
|
|
|
if (isset($options['filter']) && !is_array($options['filter']))
|
|
|
|
{
|
|
|
|
$options['filter'] = (array)$options['filter'];
|
|
|
|
}
|
2011-09-07 18:44:00 +02:00
|
|
|
switch($GLOBALS['egw_info']['user']['preferences']['common']['account_display'])
|
|
|
|
{
|
|
|
|
case 'firstname':
|
|
|
|
case 'firstall':
|
|
|
|
$order = 'account_firstname,account_lastname';
|
|
|
|
break;
|
|
|
|
case 'lastname':
|
|
|
|
case 'lastall':
|
|
|
|
$order = 'account_lastname,account_firstname';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$order = 'account_lid';
|
|
|
|
break;
|
|
|
|
}
|
2011-09-07 16:47:51 +02:00
|
|
|
$accounts = array();
|
2012-05-30 00:24:15 +02:00
|
|
|
$type = $GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' &&
|
|
|
|
!isset($GLOBALS['egw_info']['user']['apps']['admin']) ? 'groupmembers+memberships' : 'both';
|
2011-09-07 16:47:51 +02:00
|
|
|
foreach(self::getInstance()->search(array(
|
2012-05-30 00:24:15 +02:00
|
|
|
'type' => $options['filter']['group'] ? $options['filter']['group'] : $type,
|
2011-09-07 16:47:51 +02:00
|
|
|
'query' => $pattern,
|
|
|
|
'query_type' => 'all',
|
2011-09-07 18:44:00 +02:00
|
|
|
'order' => $order,
|
2011-09-07 16:47:51 +02:00
|
|
|
)) as $account)
|
|
|
|
{
|
|
|
|
$accounts[$account['account_id']] = common::display_fullname($account['account_lid'],
|
|
|
|
$account['account_firstname'],$account['account_lastname'],$account['account_id']);
|
|
|
|
}
|
|
|
|
return $accounts;
|
|
|
|
}
|
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Reads the data of one account
|
|
|
|
*
|
|
|
|
* It's depricated to use read with out parameter to read the internal data of this class!!!
|
2009-12-07 18:56:31 +01:00
|
|
|
* All key of the returned array use the 'account_' prefix.
|
2006-06-07 01:42:36 +02:00
|
|
|
* For backward compatibility some values are additionaly availible without the prefix, using them is depricated!
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
2006-06-07 01:42:36 +02:00
|
|
|
* @param int/string $id numeric account_id or string with account_lid (use of default value of 0 is depricated!!!)
|
|
|
|
* @param boolean $set_depricated_names=false set _additionaly_ the depricated keys without 'account_' prefix
|
|
|
|
* @return array/boolean array with account data (keys: account_id, account_lid, ...) or false if account not found
|
|
|
|
*/
|
|
|
|
function read($id=0,$set_depricated_names=false)
|
|
|
|
{
|
|
|
|
if (!$id) // deprecated use!!!
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2006-06-07 01:42:36 +02:00
|
|
|
return $this->data ? $this->data : $this->read_repository();
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
if (!is_int($id) && !is_numeric($id))
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2006-06-07 01:42:36 +02:00
|
|
|
$id = $this->name2id($id);
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
if (!$id) return false;
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2012-08-06 12:06:59 +02:00
|
|
|
$data = self::cache_read($id);
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2012-08-06 12:06:59 +02:00
|
|
|
if ($set_depricated_names && $data)
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2012-08-06 12:06:59 +02:00
|
|
|
foreach($this->depricated_names as $name)
|
|
|
|
{
|
|
|
|
$data[$name] =& $data['account_'.$name];
|
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2011-08-31 14:17:34 +02:00
|
|
|
/**
|
|
|
|
* Get an account as json, returns only whitelisted fields:
|
|
|
|
* - 'account_id','account_lid','person_id','account_status',
|
|
|
|
* - 'account_firstname','account_lastname','account_email','account_fullname','account_phone'
|
|
|
|
*
|
|
|
|
* @param int|string $id
|
|
|
|
* @return string|boolean json or false if not found
|
|
|
|
*/
|
|
|
|
function json($id)
|
|
|
|
{
|
|
|
|
static $keys = array(
|
|
|
|
'account_id','account_lid','person_id','account_status',
|
|
|
|
'account_firstname','account_lastname','account_email','account_fullname','account_phone',
|
|
|
|
);
|
|
|
|
if (($account = $this->read($id)))
|
|
|
|
{
|
|
|
|
$account = array_intersect_key($account, array_flip($keys));
|
|
|
|
}
|
2011-09-08 14:24:53 +02:00
|
|
|
// for current user, add the apps available to him
|
|
|
|
if ($id == $GLOBALS['egw_info']['user']['account_id'])
|
|
|
|
{
|
2012-03-14 16:22:51 +01:00
|
|
|
foreach((array)$GLOBALS['egw_info']['user']['apps'] as $app => $data)
|
2011-09-09 16:56:34 +02:00
|
|
|
{
|
|
|
|
unset($data['table_defs']); // no need for that on the client
|
|
|
|
$account['apps'][$app] = $data;
|
|
|
|
}
|
2011-09-08 14:24:53 +02:00
|
|
|
}
|
2011-08-31 14:17:34 +02:00
|
|
|
return json_encode($account);
|
|
|
|
}
|
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Saves / adds the data of one account
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
2006-06-07 01:42:36 +02:00
|
|
|
* If no account_id is set in data the account is added and the new id is set in $data.
|
|
|
|
*
|
|
|
|
* @param array $data array with account-data
|
|
|
|
* @param boolean $check_depricated_names=false check _additionaly_ the depricated keys without 'account_' prefix
|
|
|
|
* @return int/boolean the account_id or false on error
|
|
|
|
*/
|
|
|
|
function save(&$data,$check_depricated_names=false)
|
|
|
|
{
|
|
|
|
if ($check_depricated_names)
|
|
|
|
{
|
|
|
|
foreach($this->depricated_names as $name)
|
2005-11-20 09:03:06 +01:00
|
|
|
{
|
2006-06-07 01:42:36 +02:00
|
|
|
if (isset($data[$name]) && !isset($data['account_'.$name]))
|
|
|
|
{
|
|
|
|
$data['account_'.$name] =& $data[$name];
|
|
|
|
}
|
2005-11-20 09:03:06 +01:00
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2007-12-13 03:32:44 +01:00
|
|
|
if (($id = $this->backend->save($data)) && $data['account_type'] != 'g')
|
2009-12-07 18:56:31 +01:00
|
|
|
{
|
2006-07-08 02:20:27 +02:00
|
|
|
// if we are not on a pure LDAP system, we have to write the account-date via the contacts class now
|
2007-12-13 03:32:44 +01:00
|
|
|
if (($this->config['account_repository'] != 'ldap' ||
|
|
|
|
$this->config['contact_repository'] == 'sql-ldap') &&
|
2006-07-08 02:20:27 +02:00
|
|
|
(!($old = $this->read($data['account_id'])) || // only for new account or changed contact-data
|
|
|
|
$old['account_firstname'] != $data['account_firstname'] ||
|
|
|
|
$old['account_lastname'] != $data['account_lastname'] ||
|
|
|
|
$old['account_email'] != $data['account_email']))
|
|
|
|
{
|
|
|
|
if (!$data['person_id']) $data['person_id'] = $old['person_id'];
|
|
|
|
|
|
|
|
$contact = array(
|
|
|
|
'n_given' => $data['account_firstname'],
|
|
|
|
'n_family' => $data['account_lastname'],
|
|
|
|
'email' => $data['account_email'],
|
|
|
|
'account_id' => $data['account_id'],
|
|
|
|
'id' => $data['person_id'],
|
|
|
|
'owner' => 0,
|
|
|
|
);
|
|
|
|
$GLOBALS['egw']->contacts->save($contact,true); // true = ignore addressbook acl
|
|
|
|
}
|
|
|
|
// save primary group if necessary
|
2009-12-07 18:56:31 +01:00
|
|
|
if ($data['account_primary_group'] && (!($memberships = $this->memberships($id,true)) ||
|
2006-07-08 02:20:27 +02:00
|
|
|
!in_array($data['account_primary_group'],$memberships)))
|
|
|
|
{
|
|
|
|
$memberships[] = $data['account_primary_group'];
|
2012-08-06 12:06:59 +02:00
|
|
|
$this->set_memberships($memberships, $id); // invalidates cache for account_id and primary group
|
2006-07-08 02:20:27 +02:00
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2009-12-07 18:56:31 +01:00
|
|
|
self::cache_invalidate($data['account_id']);
|
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
return $id;
|
|
|
|
}
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Delete one account, deletes also all acl-entries for that account
|
|
|
|
*
|
|
|
|
* @param int/string $id numeric account_id or string with account_lid
|
|
|
|
* @return boolean true on success, false otherwise
|
|
|
|
*/
|
|
|
|
function delete($id)
|
|
|
|
{
|
|
|
|
if (!is_int($id) && !is_numeric($id))
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2006-06-07 01:42:36 +02:00
|
|
|
$id = $this->name2id($id);
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
if (!$id) return false;
|
|
|
|
|
2012-08-06 12:06:59 +02:00
|
|
|
if ($this->get_type($id) == 'u')
|
|
|
|
{
|
|
|
|
$invalidate = $this->memberships($id, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-25 14:21:31 +01:00
|
|
|
$invalidate = $this->members($id, true, false);
|
2012-08-06 12:06:59 +02:00
|
|
|
}
|
|
|
|
$invalidate[] = $id;
|
|
|
|
|
2007-12-13 03:32:44 +01:00
|
|
|
$this->backend->delete($id);
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2012-08-08 18:25:03 +02:00
|
|
|
self::cache_invalidate($invalidate);
|
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
// delete all acl_entries belonging to that user or group
|
|
|
|
$GLOBALS['egw']->acl->delete_account($id);
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2012-08-08 18:25:03 +02:00
|
|
|
// delete all categories belonging to that user or group
|
2012-09-21 16:36:02 +02:00
|
|
|
categories::delete_account($id);
|
2012-08-06 12:06:59 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* test if an account is expired
|
|
|
|
*
|
|
|
|
* @param array $data=null array with account data, not specifying the account is depricated!!!
|
|
|
|
* @return boolean true=expired (no more login possible), false otherwise
|
|
|
|
*/
|
|
|
|
function is_expired($data=null)
|
|
|
|
{
|
|
|
|
if (is_null($data)) $data = $this->data; // depricated use
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
$expires = isset($data['account_expires']) ? $data['account_expires'] : $data['expires'];
|
2006-06-07 07:16:56 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
return $expires != -1 && $expires < time();
|
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2013-01-25 14:21:31 +01:00
|
|
|
/**
|
|
|
|
* Test if an account is active - NOT deactivated or expired
|
|
|
|
*
|
|
|
|
* @param int|array $data account_id or array with account-data
|
|
|
|
* @return boolean false if account does not exist, is expired or decativated, true otherwise
|
|
|
|
*/
|
|
|
|
function is_active($data)
|
|
|
|
{
|
|
|
|
if (!is_array($data)) $data = $this->read($data);
|
|
|
|
|
|
|
|
return $data && !($this->is_expired($data) || $data['account_status'] != 'A');
|
|
|
|
}
|
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* convert an alphanumeric account-value (account_lid, account_email) to the account_id
|
|
|
|
*
|
|
|
|
* Please note:
|
|
|
|
* - if a group and an user have the same account_lid the group will be returned (LDAP only)
|
|
|
|
* - if multiple user have the same email address, the returned user is undefined
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
2006-06-07 01:42:36 +02:00
|
|
|
* @param string $name value to convert
|
|
|
|
* @param string $which='account_lid' type of $name: account_lid (default), account_email, person_id, account_fullname
|
|
|
|
* @param string $account_type=null u = user or g = group, or default null = try both
|
|
|
|
* @return int/false numeric account_id or false on error ($name not found)
|
|
|
|
*/
|
|
|
|
function name2id($name,$which='account_lid',$account_type=null)
|
|
|
|
{
|
2012-07-17 15:59:37 +02:00
|
|
|
// Don't bother searching for empty or non-scalar account_lid
|
|
|
|
if(empty($name) || !is_scalar($name))
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2009-12-07 18:56:31 +01:00
|
|
|
self::setup_cache();
|
|
|
|
$name_list = &self::$cache['name_list'];
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
if(@isset($name_list[$which][$name]) && $name_list[$which][$name])
|
|
|
|
{
|
|
|
|
return $name_list[$which][$name];
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
|
|
|
|
2007-12-13 03:32:44 +01:00
|
|
|
return $name_list[$which][$name] = $this->backend->name2id($name,$which,$account_type);
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Convert an numeric account_id to any other value of that account (account_lid, account_email, ...)
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
2006-06-07 01:42:36 +02:00
|
|
|
* Uses the read method to fetch all data.
|
|
|
|
*
|
2012-08-13 16:26:00 +02:00
|
|
|
* @param int|string $account_id numeric account_id or account_lid
|
2006-06-07 01:42:36 +02:00
|
|
|
* @param string $which='account_lid' type to convert to: account_lid (default), account_email, ...
|
2012-08-07 18:09:54 +02:00
|
|
|
* @return string|boolean converted value or false on error ($account_id not found)
|
2006-06-07 01:42:36 +02:00
|
|
|
*/
|
2012-08-06 12:06:59 +02:00
|
|
|
static function id2name($account_id, $which='account_lid')
|
2006-06-07 01:42:36 +02:00
|
|
|
{
|
2012-08-13 16:26:00 +02:00
|
|
|
if (!is_numeric($account_id) && !($account_id = self::getInstance()->name2id($account_id)))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-07 18:09:54 +02:00
|
|
|
try {
|
|
|
|
if (!($data = self::cache_read($account_id))) return false;
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-05-20 17:16:15 +02:00
|
|
|
//echo "<p>accounts::id2name($account_id,$which)='{$data[$which]}'";
|
2006-06-07 01:42:36 +02:00
|
|
|
return $data[$which];
|
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* get the type of an account: 'u' = user, 'g' = group
|
|
|
|
*
|
2009-12-07 18:56:31 +01:00
|
|
|
* @param int/string $accountid numeric account-id or alphanum. account-lid,
|
2006-06-07 01:42:36 +02:00
|
|
|
* if !$accountid account of the user of this session
|
|
|
|
* @return string/false 'u' = user, 'g' = group or false on error ($accountid not found)
|
|
|
|
*/
|
|
|
|
function get_type($account_id)
|
|
|
|
{
|
|
|
|
if (!is_int($account_id) && !is_numeric($account_id))
|
|
|
|
{
|
|
|
|
$account_id = $this->name2id($account_id);
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
return $account_id > 0 ? 'u' : ($account_id < 0 ? 'g' : false);
|
|
|
|
}
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* check if an account exists and if it is an user or group
|
|
|
|
*
|
|
|
|
* @param int/string $account_id numeric account_id or account_lid
|
2009-12-07 18:56:31 +01:00
|
|
|
* @return int 0 = acount does not exist, 1 = user, 2 = group
|
2006-06-07 01:42:36 +02:00
|
|
|
*/
|
|
|
|
function exists($account_id)
|
|
|
|
{
|
|
|
|
if (!($data = $this->read($account_id)))
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2006-06-07 01:42:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return $data['account_type'] == 'u' ? 1 : 2;
|
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2012-04-12 12:44:00 +02:00
|
|
|
/**
|
|
|
|
* Checks if a given account is visible to current user
|
|
|
|
*
|
|
|
|
* Not all existing accounts are visible because off account_selection preference: 'none' or 'groupmembers'
|
|
|
|
*
|
|
|
|
* @param int|string $account_id nummeric account_id or account_lid
|
|
|
|
* @return boolean true = account is visible, false = account not visible, null = account does not exist
|
|
|
|
*/
|
|
|
|
function visible($account_id)
|
|
|
|
{
|
|
|
|
if (!is_numeric($account_id)) // account_lid given
|
|
|
|
{
|
|
|
|
$account_lid = $account_id;
|
|
|
|
if (!($account_id = $this->name2id($account_lid))) return null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!($account_lid = $this->id2name($account_id))) return null;
|
|
|
|
}
|
|
|
|
if (!isset($GLOBALS['egw_info']['user']['apps']['admin']) &&
|
|
|
|
// do NOT allow other user, if account-selection is none
|
|
|
|
($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'none' &&
|
|
|
|
$account_lid != $GLOBALS['egw_info']['user']['account_lid'] ||
|
|
|
|
// only allow group-members for account-selection is groupmembers
|
|
|
|
$GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' &&
|
2012-08-09 10:56:28 +02:00
|
|
|
!array_intersect((array)$this->memberships($account_id,true),
|
|
|
|
(array)$this->memberships($GLOBALS['egw_info']['user']['account_id'],true))))
|
2012-04-12 12:44:00 +02:00
|
|
|
{
|
|
|
|
//error_log(__METHOD__."($account_id='$account_lid') returning FALSE");
|
|
|
|
return false; // user is not allowed to see given account
|
|
|
|
}
|
|
|
|
return true; // user allowed to see given account
|
|
|
|
}
|
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Get all memberships of an account $account_id / groups the account is a member off
|
|
|
|
*
|
|
|
|
* @param int/string $account_id numeric account-id or alphanum. account-lid
|
|
|
|
* @param boolean $just_id=false return just account_id's or account_id => account_lid pairs
|
|
|
|
* @return array with account_id's ($just_id) or account_id => account_lid pairs (!$just_id)
|
|
|
|
*/
|
2012-08-06 12:06:59 +02:00
|
|
|
function memberships($account_id, $just_id=false)
|
2006-06-07 01:42:36 +02:00
|
|
|
{
|
|
|
|
if (!is_int($account_id) && !is_numeric($account_id))
|
|
|
|
{
|
|
|
|
$account_id = $this->name2id($account_id,'account_lid','u');
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2012-08-06 12:06:59 +02:00
|
|
|
if ($account_id && ($data = self::cache_read($account_id)))
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2012-08-06 12:06:59 +02:00
|
|
|
return $just_id && $data['memberships'] ? array_keys($data['memberships']) : $data['memberships'];
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
2012-08-06 12:06:59 +02:00
|
|
|
return null;
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Sets the memberships of a given account
|
|
|
|
*
|
|
|
|
* @param array $groups array with gidnumbers
|
|
|
|
* @param int $account_id uidnumber
|
|
|
|
*/
|
|
|
|
function set_memberships($groups,$account_id)
|
|
|
|
{
|
2007-07-27 09:46:55 +02:00
|
|
|
//echo "<p>accounts::set_memberships(".print_r($groups,true).",$account_id)</p>\n";
|
2006-06-07 01:42:36 +02:00
|
|
|
if (!is_int($account_id) && !is_numeric($account_id))
|
|
|
|
{
|
|
|
|
$account_id = $this->name2id($account_id);
|
|
|
|
}
|
2012-08-06 12:06:59 +02:00
|
|
|
if (($old_memberships = $this->memberships($account_id, true)) != $groups)
|
|
|
|
{
|
|
|
|
$this->backend->set_memberships($groups, $account_id);
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2012-08-06 12:06:59 +02:00
|
|
|
self::cache_invalidate(array_unique(array_merge(
|
|
|
|
array($account_id),
|
|
|
|
array_diff($old_memberships, $groups),
|
|
|
|
array_diff($groups, $old_memberships)
|
|
|
|
)));
|
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Get all members of the group $account_id
|
|
|
|
*
|
2009-12-07 18:56:31 +01:00
|
|
|
* @param int/string $accountid='' numeric account-id or alphanum. account-lid,
|
2006-06-07 01:42:36 +02:00
|
|
|
* default account of the user of this session
|
|
|
|
* @param boolean $just_id=false return just an array of id's and not id => lid pairs, default false
|
2013-01-25 14:21:31 +01:00
|
|
|
* @param boolean $active=false true: return only active (not expired or deactived) members, false: return all accounts
|
2006-06-07 01:42:36 +02:00
|
|
|
* @return array with account_id ($just_id) or account_id => account_lid pairs (!$just_id)
|
|
|
|
*/
|
2013-01-25 14:21:31 +01:00
|
|
|
function members($account_id, $just_id=false, $active=true)
|
2006-06-07 01:42:36 +02:00
|
|
|
{
|
|
|
|
if (!is_int($account_id) && !is_numeric($account_id))
|
|
|
|
{
|
|
|
|
$account_id = $this->name2id($account_id);
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2013-01-25 14:21:31 +01:00
|
|
|
if ($account_id && ($data = self::cache_read($account_id, $active)))
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2013-01-25 14:21:31 +01:00
|
|
|
$members = $active ? $data['members-active'] : $data['members'];
|
|
|
|
|
|
|
|
return $just_id && $members ? array_keys($members) : $members;
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
2012-08-06 12:06:59 +02:00
|
|
|
return null;
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Set the members of a group
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
2006-06-07 01:42:36 +02:00
|
|
|
* @param array $members array with uidnumber or uid's
|
|
|
|
* @param int $gid gidnumber of group to set
|
|
|
|
*/
|
|
|
|
function set_members($members,$gid)
|
|
|
|
{
|
|
|
|
//echo "<p>accounts::set_members(".print_r($members,true).",$gid)</p>\n";
|
2013-01-25 14:21:31 +01:00
|
|
|
if (($old_members = $this->members($gid, true, false)) != $members)
|
2012-08-06 12:06:59 +02:00
|
|
|
{
|
|
|
|
$this->backend->set_members($members, $gid);
|
2005-12-15 00:33:07 +01:00
|
|
|
|
2012-08-06 12:06:59 +02:00
|
|
|
self::cache_invalidate(array_unique(array_merge(
|
|
|
|
array($gid),
|
|
|
|
array_diff($old_members, $members),
|
|
|
|
array_diff($members, $old_members)
|
|
|
|
)));
|
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* splits users and groups from a array of id's or the accounts with run-rights for a given app-name
|
|
|
|
*
|
|
|
|
* @param array $app_users array of user-id's or app-name (if you use app-name the result gets cached!)
|
|
|
|
* @param string $use what should be returned only an array with id's of either 'accounts' or 'groups'.
|
|
|
|
* Or an array with arrays for 'both' under the keys 'groups' and 'accounts' or 'merge' for accounts
|
|
|
|
* and groups merged into one array
|
|
|
|
* @return array/boolean see $use, false on error (wront $use)
|
|
|
|
*/
|
|
|
|
function split_accounts($app_users,$use='both')
|
|
|
|
{
|
|
|
|
if (!is_array($app_users))
|
|
|
|
{
|
2009-12-07 18:56:31 +01:00
|
|
|
self::setup_cache();
|
|
|
|
$cache = &self::$cache['account_split'][$app_user];
|
2006-06-07 01:42:36 +02:00
|
|
|
|
|
|
|
if (is_array($cache))
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2006-06-07 01:42:36 +02:00
|
|
|
return $cache;
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
$app_users = $GLOBALS['egw']->acl->get_ids_for_location('run',1,$app_users);
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
$accounts = array(
|
|
|
|
'accounts' => array(),
|
|
|
|
'groups' => array(),
|
|
|
|
);
|
|
|
|
foreach($app_users as $id)
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2006-06-07 01:42:36 +02:00
|
|
|
$type = $this->get_type($id);
|
|
|
|
if($type == 'g')
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2006-06-07 01:42:36 +02:00
|
|
|
$accounts['groups'][$id] = $id;
|
2006-09-15 18:19:39 +02:00
|
|
|
if ($use != 'groups')
|
2004-06-16 02:31:48 +02:00
|
|
|
{
|
2013-01-25 14:21:31 +01:00
|
|
|
foreach((array)$this->members($id, true) as $id)
|
2006-09-15 18:19:39 +02:00
|
|
|
{
|
|
|
|
$accounts['accounts'][$id] = $id;
|
|
|
|
}
|
2004-06-16 02:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
else
|
2004-06-16 02:31:48 +02:00
|
|
|
{
|
2006-06-07 01:42:36 +02:00
|
|
|
$accounts['accounts'][$id] = $id;
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +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
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
if (isset($cache))
|
|
|
|
{
|
|
|
|
$cache = $accounts;
|
|
|
|
}
|
|
|
|
//echo "<p>accounts::split_accounts(".print_r($app_users,True).",'$use') = <pre>".print_r($accounts,True)."</pre>\n";
|
2004-06-16 02:31:48 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
switch($use)
|
|
|
|
{
|
|
|
|
case 'both':
|
|
|
|
return $accounts;
|
|
|
|
case 'groups':
|
|
|
|
return $accounts['groups'];
|
|
|
|
case 'accounts':
|
|
|
|
return $accounts['accounts'];
|
|
|
|
case 'merge':
|
|
|
|
return array_merge($accounts['accounts'],$accounts['groups']);
|
2004-06-16 02:31:48 +02:00
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
return False;
|
|
|
|
}
|
2004-06-16 02:31:48 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Add an account for an authenticated user
|
|
|
|
*
|
|
|
|
* Expiration date and primary group are read from the system configuration.
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
2006-06-07 01:42:36 +02:00
|
|
|
* @param string $account_lid
|
|
|
|
* @param string $passwd
|
|
|
|
* @param array $GLOBALS['auto_create_acct'] values for 'firstname', 'lastname', 'email' and 'primary_group'
|
|
|
|
* @return int/boolean account_id or false on error
|
|
|
|
*/
|
|
|
|
function auto_add($account_lid, $passwd)
|
|
|
|
{
|
2007-12-13 03:32:44 +01:00
|
|
|
$expires = !isset($this->config['auto_create_expire']) ||
|
|
|
|
$this->config['auto_create_expire'] == 'never' ? -1 :
|
|
|
|
time() + $this->config['auto_create_expire'] + 2;
|
2004-06-16 02:31:48 +02:00
|
|
|
|
2010-03-29 09:39:09 +02:00
|
|
|
if (!($default_group_id = $this->name2id($this->config['default_group_lid'],'account_lid','g')))
|
2006-06-07 01:42:36 +02:00
|
|
|
{
|
2010-03-29 09:39:09 +02:00
|
|
|
// check if we have a comma or semicolon delimited list of groups --> add first as primary and rest as memberships
|
|
|
|
foreach(preg_split('/[,;] */',$this->config['default_group_lid']) as $n => $group_lid)
|
|
|
|
{
|
|
|
|
if (($group_id = $this->name2id($group_lid,'account_lid','g')))
|
|
|
|
{
|
|
|
|
if (!$default_group_id) $default_group_id = $group_id;
|
|
|
|
$memberships[] = $group_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$default_group_id) $default_group_id = $this->name2id('Default','account_lid','g');
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
|
|
|
$primary_group = $GLOBALS['auto_create_acct']['primary_group'] &&
|
|
|
|
$this->get_type((int)$GLOBALS['auto_create_acct']['primary_group']) === 'g' ?
|
|
|
|
(int)$GLOBALS['auto_create_acct']['primary_group'] : $default_group_id;
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'account_lid' => $account_lid,
|
|
|
|
'account_type' => 'u',
|
|
|
|
'account_passwd' => $passwd,
|
|
|
|
'account_firstname' => $GLOBALS['auto_create_acct']['firstname'] ? $GLOBALS['auto_create_acct']['firstname'] : 'New',
|
|
|
|
'account_lastname' => $GLOBALS['auto_create_acct']['lastname'] ? $GLOBALS['auto_create_acct']['lastname'] : 'User',
|
|
|
|
'account_email' => $GLOBALS['auto_create_acct']['email'],
|
|
|
|
'account_status' => 'A',
|
|
|
|
'account_expires' => $expires,
|
|
|
|
'account_primary_group' => $primary_group,
|
|
|
|
);
|
|
|
|
// use given account_id, if it's not already used
|
2009-12-07 18:56:31 +01:00
|
|
|
if (isset($GLOBALS['auto_create_acct']['account_id']) &&
|
|
|
|
is_numeric($GLOBALS['auto_create_acct']['account_id']) &&
|
2006-06-07 01:42:36 +02:00
|
|
|
!$this->id2name($GLOBALS['auto_create_acct']['account_id']))
|
|
|
|
{
|
|
|
|
$data['account_id'] = $GLOBALS['auto_create_acct']['account_id'];
|
|
|
|
}
|
|
|
|
if (!($data['account_id'] = $this->save($data)))
|
|
|
|
{
|
|
|
|
return false;
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2012-06-29 13:38:58 +02:00
|
|
|
// set the appropriate value for the can change password flag (assume users can, if the admin requires users to change their password)
|
|
|
|
$data['changepassword'] = (bool)$GLOBALS['egw_info']['server']['change_pwd_every_x_days'];
|
|
|
|
if(!$data['changepassword'])
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->acl->add_repository('preferences','nopasswordchange',$data['account_id'],1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->acl->delete_repository('preferences','nopasswordchange',$data['account_id']);
|
|
|
|
}
|
2012-06-29 15:54:13 +02:00
|
|
|
// call hook to notify interested apps about the new account
|
|
|
|
$GLOBALS['hook_values'] = $data;
|
|
|
|
$GLOBALS['egw']->hooks->process($data+array(
|
|
|
|
'location' => 'addaccount',
|
|
|
|
// at login-time only the hooks from the following apps will be called
|
|
|
|
'order' => array('felamimail','fudforum'),
|
|
|
|
),False,True); // called for every app now, not only enabled ones
|
2012-06-29 13:38:58 +02:00
|
|
|
unset($data['changepassword']);
|
2010-03-29 09:39:09 +02:00
|
|
|
// set memberships if given
|
|
|
|
if ($memberships)
|
|
|
|
{
|
|
|
|
$this->set_memberships($memberships,$data['account_id']);
|
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
return $data['account_id'];
|
|
|
|
}
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2007-12-13 03:32:44 +01:00
|
|
|
/**
|
|
|
|
* Update the last login timestamps and the IP
|
|
|
|
*
|
|
|
|
* @param int $account_id
|
|
|
|
* @param string $ip
|
|
|
|
* @return int lastlogin time
|
|
|
|
*/
|
|
|
|
function update_lastlogin($account_id, $ip)
|
|
|
|
{
|
|
|
|
return $this->backend->update_lastlogin($account_id, $ip);
|
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
function list_methods($_type='xmlrpc')
|
|
|
|
{
|
|
|
|
if (is_array($_type))
|
2004-05-29 18:11:35 +02:00
|
|
|
{
|
2006-06-07 01:42:36 +02:00
|
|
|
$_type = $_type['type'] ? $_type['type'] : $_type[0];
|
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
switch($_type)
|
|
|
|
{
|
|
|
|
case 'xmlrpc':
|
|
|
|
$xml_functions = array(
|
2006-09-15 18:19:39 +02:00
|
|
|
'search' => array(
|
|
|
|
'function' => 'search',
|
2006-06-07 01:42:36 +02:00
|
|
|
'signature' => array(array(xmlrpcStruct)),
|
|
|
|
'docstring' => lang('Returns a full list of accounts on the system. Warning: This is return can be quite large')
|
|
|
|
),
|
|
|
|
'list_methods' => array(
|
|
|
|
'function' => 'list_methods',
|
|
|
|
'signature' => array(array(xmlrpcStruct,xmlrpcString)),
|
|
|
|
'docstring' => lang('Read this list of methods.')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return $xml_functions;
|
|
|
|
break;
|
|
|
|
case 'soap':
|
|
|
|
return $this->soap_functions;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return array();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2007-07-27 09:46:55 +02:00
|
|
|
/**
|
2012-08-06 12:06:59 +02:00
|
|
|
* Invalidate cache (or parts of it) after change in $account_ids
|
2007-07-27 09:46:55 +02:00
|
|
|
*
|
2012-08-06 12:06:59 +02:00
|
|
|
* We use now an instance-wide read-cache storing account-data and members(hips).
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
2012-08-06 12:06:59 +02:00
|
|
|
* @param int|array $account_ids user- or group-id(s) for which cache should be invalidated, default 0 = only search/name2id cache
|
2007-07-27 09:46:55 +02:00
|
|
|
*/
|
2012-08-06 12:06:59 +02:00
|
|
|
static function cache_invalidate($account_ids=0)
|
2007-07-27 09:46:55 +02:00
|
|
|
{
|
2012-08-06 12:06:59 +02:00
|
|
|
//error_log(__METHOD__.'('.array2string($account_ids).')');
|
|
|
|
|
|
|
|
// instance-wide cache
|
|
|
|
if ($account_ids)
|
|
|
|
{
|
|
|
|
foreach((array)$account_ids as $account_id)
|
|
|
|
{
|
|
|
|
egw_cache::unsetInstance(__CLASS__, 'account-'.$account_id);
|
|
|
|
|
|
|
|
unset(self::$request_cache[$account_id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// session-cache
|
2009-12-07 18:56:31 +01:00
|
|
|
if (self::$cache) self::$cache = array();
|
2010-08-29 10:16:27 +02:00
|
|
|
egw_cache::unsetSession('accounts_cache','phpgwapi');
|
2007-07-27 09:46:55 +02:00
|
|
|
|
|
|
|
if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited
|
|
|
|
{
|
2010-08-29 10:16:27 +02:00
|
|
|
egw::invalidate_session_cache(); // invalidates whole egw-enviroment if stored in the session
|
2007-07-27 09:46:55 +02:00
|
|
|
}
|
|
|
|
}
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2012-08-06 12:06:59 +02:00
|
|
|
/**
|
|
|
|
* Timeout of instance wide cache for reading account-data and members(hips)
|
|
|
|
*/
|
|
|
|
const READ_CACHE_TIMEOUT = 43200;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Local per request cache, to minimize calls to instance cache
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
static $request_cache = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read account incl. members/memberships from cache (or backend and cache it)
|
|
|
|
*
|
|
|
|
* @param int $account_id
|
2013-01-25 14:21:31 +01:00
|
|
|
* @param boolean $need_active=false true = 'members-active' required
|
2012-08-06 12:06:59 +02:00
|
|
|
* @return array
|
2012-08-07 18:09:54 +02:00
|
|
|
* @throws egw_exception_wrong_parameter if no integer was passed as $account_id
|
2012-08-06 12:06:59 +02:00
|
|
|
*/
|
2013-01-25 14:21:31 +01:00
|
|
|
static function cache_read($account_id, $need_active=false)
|
2012-08-06 12:06:59 +02:00
|
|
|
{
|
|
|
|
if (!is_numeric($account_id)) throw new egw_exception_wrong_parameter('Not an integer!');
|
|
|
|
|
|
|
|
$account =& self::$request_cache[$account_id];
|
|
|
|
|
2012-11-19 09:24:47 +01:00
|
|
|
if (!isset($account)) // not in request cache --> try instance cache
|
2012-08-06 12:06:59 +02:00
|
|
|
{
|
|
|
|
$account = egw_cache::getInstance(__CLASS__, 'account-'.$account_id);
|
|
|
|
|
|
|
|
if (!isset($account)) // not in instance cache --> read from backend
|
|
|
|
{
|
|
|
|
$instance = self::getInstance();
|
|
|
|
|
|
|
|
if (($account = $instance->backend->read($account_id)))
|
|
|
|
{
|
|
|
|
if ($instance->get_type($account_id) == 'u')
|
|
|
|
{
|
|
|
|
$account['memberships'] = $instance->backend->memberships($account_id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$account['members'] = $instance->backend->members($account_id);
|
|
|
|
}
|
|
|
|
egw_cache::setInstance(__CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT);
|
|
|
|
}
|
|
|
|
//error_log(__METHOD__."($account_id) read from backend ".array2string($account));
|
|
|
|
}
|
|
|
|
//else error_log(__METHOD__."($account_id) read from instance cache ".array2string($account));
|
|
|
|
}
|
2013-01-25 14:21:31 +01:00
|
|
|
// if required and not already set, query active members AND cache them too
|
|
|
|
if ($need_active && $account_id < 0 && !isset($account['members-active']))
|
|
|
|
{
|
|
|
|
$instance = self::getInstance();
|
|
|
|
$account['members-active'] = array();
|
|
|
|
foreach($account['members'] as $id => $lid)
|
|
|
|
{
|
|
|
|
if ($instance->is_active($id)) $account['members-active'][$id] = $lid;
|
|
|
|
}
|
|
|
|
egw_cache::setInstance(__CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT);
|
|
|
|
}
|
|
|
|
//error_log(__METHOD__."($account_id, $need_active) returning ".array2string($account));
|
2012-08-06 12:06:59 +02:00
|
|
|
return $account;
|
|
|
|
}
|
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Internal functions not meant to use outside this class!!!
|
|
|
|
*/
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
2012-08-06 12:06:59 +02:00
|
|
|
* Sets up session cache, now only used for search and name2id list
|
|
|
|
*
|
|
|
|
* Other account-data is cached on instance-level
|
2006-06-07 01:42:36 +02:00
|
|
|
*
|
|
|
|
* 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
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
|
|
|
* @internal
|
2006-06-07 01:42:36 +02:00
|
|
|
*/
|
2012-08-06 12:06:59 +02:00
|
|
|
private static function setup_cache()
|
2006-06-07 01:42:36 +02:00
|
|
|
{
|
2009-12-07 18:56:31 +01:00
|
|
|
if (is_array(self::$cache)) return; // cache is already setup
|
2007-07-27 09:46:55 +02:00
|
|
|
|
2009-12-07 18:56:31 +01:00
|
|
|
if (self::$use_session_cache && is_object($GLOBALS['egw']->session))
|
2006-06-07 01:42:36 +02:00
|
|
|
{
|
2009-12-07 18:56:31 +01:00
|
|
|
self::$cache =& egw_cache::getSession('accounts_cache','phpgwapi');
|
|
|
|
//echo "<p>restoring cache from session, ".count(call_user_func_array('array_merge',(array)self::$cache))." items</p>\n";
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2012-08-06 12:06:59 +02:00
|
|
|
//error_log(__METHOD__."() use_session_cache=".array2string(self::$use_session_cache).", is_array(self::\$cache)=".array2string(is_array(self::$cache)));
|
|
|
|
|
2009-12-07 18:56:31 +01:00
|
|
|
if (!is_array(self::$cache))
|
2006-06-07 01:42:36 +02:00
|
|
|
{
|
2007-07-27 09:46:55 +02:00
|
|
|
//echo "<p>initialising this->cache to array()</p>\n";
|
2009-12-07 18:56:31 +01:00
|
|
|
self::$cache = array();
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
2007-07-27 09:46:55 +02:00
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
2009-12-07 18:56:31 +01:00
|
|
|
* @deprecated not used any more, as static cache is a reference to the session
|
2006-06-07 01:42:36 +02:00
|
|
|
*/
|
|
|
|
function save_session_cache()
|
|
|
|
{
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
2009-12-07 18:56:31 +01:00
|
|
|
* Depricated functions of the old accounts class.
|
2006-06-07 01:42:36 +02:00
|
|
|
*
|
|
|
|
* Do NOT use them in new code, they will be removed after the next major release!!!
|
|
|
|
*/
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Reads the data of the account this class is instanciated for
|
|
|
|
*
|
|
|
|
* @deprecated use read of $GLOBALS['egw']->accounts and not own instances of the accounts class
|
|
|
|
* @return array with the internal data
|
|
|
|
*/
|
|
|
|
function read_repository()
|
|
|
|
{
|
2006-06-18 06:58:02 +02:00
|
|
|
return $this->data = $this->account_id ? $this->read($this->account_id,true) : array();
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* saves the account-data in the internal data-structure of this class to the repository
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
2006-06-07 01:42:36 +02:00
|
|
|
* @deprecated use save of $GLOBALS['egw']->accounts and not own instances of the accounts class
|
|
|
|
*/
|
|
|
|
function save_repository()
|
|
|
|
{
|
|
|
|
$this->save($this->data,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Searches / lists accounts: users and/or groups
|
|
|
|
*
|
|
|
|
* @deprecated use search
|
|
|
|
*/
|
2006-09-06 10:13:56 +02:00
|
|
|
function get_list($_type='both',$start = null,$sort = '', $order = '', $query = '', $offset = null,$query_type='')
|
2006-06-07 01:42:36 +02:00
|
|
|
{
|
2006-09-15 18:19:39 +02:00
|
|
|
if (is_array($_type)) // XML-RPC
|
|
|
|
{
|
2006-09-24 10:06:16 +02:00
|
|
|
return array_values($this->search($_type));
|
2006-09-15 18:19:39 +02:00
|
|
|
}
|
2006-09-24 10:06:16 +02:00
|
|
|
return array_values($this->search(array(
|
2006-09-15 18:19:39 +02:00
|
|
|
'type' => $_type,
|
|
|
|
'start' => $start,
|
|
|
|
'order' => $order,
|
2007-01-08 09:57:33 +01:00
|
|
|
'sort' => $sort,
|
2006-09-15 18:19:39 +02:00
|
|
|
'query' => $query,
|
|
|
|
'offset' => $offset,
|
|
|
|
'query_type' => $query_type ,
|
2006-09-24 10:06:16 +02:00
|
|
|
)));
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Create a new account with the given $account_info
|
2009-12-07 18:56:31 +01:00
|
|
|
*
|
2006-06-07 01:42:36 +02:00
|
|
|
* @deprecated use save
|
|
|
|
* @param array $data account data for the new account
|
|
|
|
* @param booelan $default_prefs has no meaning any more, as we use "real" default prefs since 1.0
|
|
|
|
* @return int new nummeric account-id
|
|
|
|
*/
|
|
|
|
function create($account_info,$default_prefs=True)
|
|
|
|
{
|
|
|
|
return $this->save($account_info);
|
|
|
|
}
|
2004-05-29 18:11:35 +02:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* copies the given $data into the internal array $this->data
|
|
|
|
*
|
|
|
|
* @deprecated store data in your own code and use save to save it
|
|
|
|
* @param array $data array with account data
|
|
|
|
* @return array $this->data = $data
|
|
|
|
*/
|
|
|
|
function update_data($data)
|
|
|
|
{
|
|
|
|
return $this->data = $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all memberships of an account $accountid / groups the account is a member off
|
|
|
|
*
|
|
|
|
* @deprecated use memberships() which account_id => account_lid pairs
|
2009-12-07 18:56:31 +01:00
|
|
|
* @param int/string $accountid='' numeric account-id or alphanum. account-lid,
|
2006-06-07 01:42:36 +02:00
|
|
|
* default account of the user of this session
|
|
|
|
* @return array or arrays with keys 'account_id' and 'account_name' for the groups $accountid is a member of
|
|
|
|
*/
|
|
|
|
function membership($accountid = '')
|
|
|
|
{
|
|
|
|
$accountid = get_account_id($accountid);
|
|
|
|
|
|
|
|
if (!($memberships = $this->memberships($accountid)))
|
|
|
|
{
|
|
|
|
return $memberships;
|
|
|
|
}
|
|
|
|
$old = array();
|
|
|
|
foreach($memberships as $id => $lid)
|
|
|
|
{
|
|
|
|
$old[] = array('account_id' => $id, 'account_name' => $lid);
|
|
|
|
}
|
|
|
|
//echo "<p>accounts::membership($accountid)="; _debug_array($old);
|
|
|
|
return $old;
|
|
|
|
}
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
/**
|
|
|
|
* Get all members of the group $accountid
|
|
|
|
*
|
|
|
|
* @deprecated use members which returns acount_id => account_lid pairs
|
2009-12-07 18:56:31 +01:00
|
|
|
* @param int/string $accountid='' numeric account-id or alphanum. account-lid,
|
2006-06-07 01:42:36 +02:00
|
|
|
* default account of the user of this session
|
|
|
|
* @return array of arrays with keys 'account_id' and 'account_name'
|
|
|
|
*/
|
|
|
|
function member($accountid)
|
|
|
|
{
|
|
|
|
if (!($members = $this->members($accountid)))
|
|
|
|
{
|
|
|
|
return $members;
|
|
|
|
}
|
|
|
|
$old = array();
|
|
|
|
foreach($members as $uid => $lid)
|
|
|
|
{
|
|
|
|
$old[] = array('account_id' => $uid, 'account_name' => $lid);
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
return $old;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* phpGW compatibility function, better use split_accounts
|
|
|
|
*
|
|
|
|
* @deprecated use split_accounts
|
|
|
|
*/
|
|
|
|
function return_members($accounts)
|
|
|
|
{
|
|
|
|
$arr = $this->split_accounts($accounts);
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'users' => $arr['accounts'],
|
|
|
|
'groups' => $arr['groups'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets account-name (lid), firstname and lastname of an account $accountid
|
|
|
|
*
|
|
|
|
* @deprecated use read to read account data
|
2009-12-07 18:56:31 +01:00
|
|
|
* @param int/string $accountid='' numeric account-id or alphanum. account-lid,
|
2006-06-07 01:42:36 +02:00
|
|
|
* if !$accountid account of the user of this session
|
|
|
|
* @param string &$lid on return: alphanumeric account-name (lid)
|
|
|
|
* @param string &$fname on return: first name
|
|
|
|
* @param string &$lname on return: last name
|
|
|
|
* @return boolean true if $accountid was found, false otherwise
|
2009-12-07 18:56:31 +01:00
|
|
|
*/
|
2006-06-07 01:42:36 +02:00
|
|
|
function get_account_name($accountid,&$lid,&$fname,&$lname)
|
|
|
|
{
|
|
|
|
if (!($data = $this->read($accountid))) return false;
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
$lid = $data['account_lid'];
|
|
|
|
$fname = $data['account_firstname'];
|
|
|
|
$lname = $data['account_lastname'];
|
2009-12-07 18:56:31 +01:00
|
|
|
|
2006-06-07 01:42:36 +02:00
|
|
|
if (empty($fname)) $fname = $lid;
|
|
|
|
if (empty($lname)) $lname = $this->get_type($accountid) == 'g' ? lang('Group') : lang('user');
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads account-data for a given $account_id from the repository AND sets the class-vars with it
|
|
|
|
*
|
|
|
|
* Same effect as instanciating the class with that account, dont do it with $GLOBALS['egw']->account !!!
|
|
|
|
*
|
|
|
|
* @deprecated use read to read account data and store it in your own code
|
2009-12-07 18:56:31 +01:00
|
|
|
* @param int $accountid numeric account-id
|
2006-06-07 01:42:36 +02:00
|
|
|
* @return array with keys lid, firstname, lastname, fullname, type
|
|
|
|
*/
|
|
|
|
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;
|
2004-05-29 18:11:35 +02:00
|
|
|
}
|
2006-06-07 01:42:36 +02:00
|
|
|
}
|