Author: ralfbecker
New Revision: 55280
URL: http://svn.stylite.de/viewvc/egroupware?rev=55280&view=rev
Log:
moved accounts classes to Api\Accounts
Added:
trunk/egroupware/api/src/Accounts/
trunk/egroupware/api/src/Accounts.php
- copied, changed from r55263, trunk/phpgwapi/inc/class.accounts.inc.php
trunk/egroupware/api/src/Accounts/Ads.php
- copied, changed from r55263, trunk/phpgwapi/inc/class.accounts_ads.inc.php
trunk/egroupware/api/src/Accounts/Ldap.php
- copied, changed from r55263, trunk/phpgwapi/inc/class.accounts_ldap.inc.php
trunk/egroupware/api/src/Accounts/Sql.php
- copied, changed from r55263, trunk/phpgwapi/inc/class.accounts_sql.inc.php
trunk/egroupware/api/src/Accounts/Univention.php
- copied, changed from r55263, trunk/phpgwapi/inc/class.accounts_univention.inc.php
Removed:
trunk/phpgwapi/inc/class.accounts_ads.inc.php
trunk/phpgwapi/inc/class.accounts_ldap.inc.php
trunk/phpgwapi/inc/class.accounts_sql.inc.php
trunk/phpgwapi/inc/class.accounts_univention.inc.php
trunk/phpgwapi/inc/class.ldap.inc.php
trunk/phpgwapi/inc/class.ldapserverinfo.inc.php
Modified:
trunk/egroupware/api/src/Contacts.php
trunk/egroupware/api/src/Contacts/Ads.php
trunk/egroupware/api/src/Contacts/Storage.php
trunk/egroupware/api/src/Contacts/Tracking.php
trunk/egroupware/api/src/Session.php
trunk/egroupware/api/src/Storage/Customfields.php
trunk/phpgwapi/inc/class.accounts.inc.php
trunk/phpgwapi/inc/class.auth_ads.inc.php
trunk/phpgwapi/inc/class.common.inc.php
trunk/phpgwapi/inc/class.contacts.inc.php
trunk/phpgwapi/inc/class.egw.inc.php
trunk/phpgwapi/inc/class.egw_customfields.inc.php
trunk/phpgwapi/inc/class.historylog.inc.php
trunk/phpgwapi/inc/class.preferences.inc.php
ā trunk/phpgwapi/inc/class.accounts.inc.php (original)
+++ trunk/egroupware/api/src/Accounts.php Sun Mar 6 16:54:07 2016
@@ -1,6 +1,6 @@
<?php
/**
- * EGroupware API - accounts
+ * EGroupware API - Accounts
*
* @link http://www.egroupware.org
* @author Ralf Becker complete rewrite in 6/2006 and earlier modifications
@@ -15,6 +15,11 @@
* @access public
* @version $Id$
*/
+
+namespace EGroupware\Api;
+
+// explicitly reference classes still in phpgwapi of old structure
+use egw;
/**
* API - accounts
@@ -33,26 +38,8 @@
*
* read and search return timestamps (account_(created|modified|lastlogin) in server-time!
*/
-class accounts
+class Accounts
{
- 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'
- ),
- );
/**
* Enables the session-cache, currently switched on independent of the backend
*
@@ -66,21 +53,6 @@
* @var array
*/
static $cache;
-
- /**
- * 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
- * @var array
- */
- var $data;
/**
* Keys for which both versions with 'account_' prefix and without (depricated!) can be used, if requested.
@@ -122,7 +94,7 @@
/**
* Backend to use
*
- * @var accounts_sql|accounts_ldap
+ * @var Accounts\Sql|Accounts\Ldap|Accounts\Ads|Accounts\Univention
*/
var $backend;
@@ -143,20 +115,20 @@
/**
* hold an instance of the accounts class
*
- * @var accounts the instance of the accounts class
+ * @var Accounts the instance of the accounts class
*/
private static $_instance = NULL;
/**
* Singleton
*
- * @return accounts
+ * @return Accounts
*/
public static function getInstance()
{
if (self::$_instance === NULL)
{
- self::$_instance = new accounts;
+ self::$_instance = new Accounts();
}
return self::$_instance;
}
@@ -168,11 +140,6 @@
*/
public function __construct($backend=null)
{
- 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;
@@ -201,30 +168,16 @@
}
$backend = $this->config['account_repository'];
}
- $backend_class = 'accounts_'.$backend;
+ $backend_class = 'EGroupware\\Api\\Accounts\\'.ucfirst($backend);
$this->backend = new $backend_class($this);
}
/**
- * set the accountId
- *
- * @param int $accountId
- * @deprecated
- */
- function setAccountId($accountId)
- {
- if($accountId && is_numeric($accountId))
- {
- $this->account_id = (int)$accountId;
- }
- }
-
- /**
* Searches / lists accounts: users and/or groups
*
* @param array with the following keys:
- * @param $param['type'] string/int 'accounts', 'groups', 'owngroups' (groups the user is a member of), 'both',
+ * @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)
* 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
@@ -335,8 +288,6 @@
}
$account_search[$serial]['total'] = $this->total = $this->backend->total;
}
- //echo "
accounts::search(".array2string(unserialize($serial)).")= returning ".count($account_search[$serial]['data'])." of $this->total entries
".print_r($account_search[$serial]['data'],True)."
\n";
- //echo "
accounts::search() end: ".microtime()."
\n";
return $account_search[$serial]['data'];
}
@@ -399,7 +350,7 @@
'order' => $order,
)) as $account)
{
- $accounts[$account['account_id']] = common::display_fullname($account['account_lid'],
+ $accounts[$account['account_id']] = self::format_username($account['account_lid'],
$account['account_firstname'],$account['account_lastname'],$account['account_id']);
}
return $accounts;
@@ -474,6 +425,85 @@
}
}
return json_encode($account);
+ }
+
+ /**
+ * Format lid, firstname, lastname according to use preferences
+ *
+ * @param $lid ='' account loginid
+ * @param $firstname ='' firstname
+ * @param $lastname ='' lastname
+ * @param $accountid =0 id, to check if it's a user or group, otherwise the lid will be used
+ */
+ static function format_username($lid = '', $firstname = '', $lastname = '', $accountid=0)
+ {
+ if (!$lid && !$firstname && !$lastname)
+ {
+ $lid = $GLOBALS['egw_info']['user']['account_lid'];
+ $firstname = $GLOBALS['egw_info']['user']['account_firstname'];
+ $lastname = $GLOBALS['egw_info']['user']['account_lastname'];
+ }
+ $is_group = $GLOBALS['egw']->accounts->get_type($accountid ? $accountid : $lid) == 'g';
+
+ if (empty($firstname)) $firstname = $lid;
+ if (empty($lastname) || $is_group)
+ {
+ $lastname = $is_group ? lang('Group') : lang('User');
+ }
+ $display = $GLOBALS['egw_info']['user']['preferences']['common']['account_display'];
+
+ if ($firstname && $lastname)
+ {
+ $delimiter = $is_group ? ' ' : ', ';
+ }
+ else
+ {
+ $delimiter = '';
+ }
+
+ $name = '';
+ switch($display)
+ {
+ case 'firstname':
+ $name = $firstname . ' ' . $lastname;
+ break;
+ case 'lastname':
+ $name = $lastname . $delimiter . $firstname;
+ break;
+ case 'username':
+ $name = $lid;
+ break;
+ case 'firstall':
+ $name = $firstname . ' ' . $lastname . ' ['.$lid.']';
+ break;
+ case 'lastall':
+ $name = $lastname . $delimiter . $firstname . ' ['.$lid.']';
+ break;
+ case 'allfirst':
+ $name = '['.$lid.'] ' . $firstname . ' ' . $lastname;
+ break;
+ case 'all':
+ /* fall through */
+ default:
+ $name = '['.$lid.'] ' . $lastname . $delimiter . $firstname;
+ }
+ return $name;
+ }
+
+ /**
+ * Return formatted username for a given account_id
+ *
+ * @param string $account_id =null account id
+ * @return string full name of user or "#$accountid" if user not found
+ */
+ static function username($account_id=null)
+ {
+ if ($account_id && !($account = self::cache_read($account_id)))
+ {
+ return '#'.$account_id;
+ }
+ return self::format_username($account['account_lid'],
+ $account['account_firstname'] , $account['account_lastname'], $account_id);
}
/**
@@ -682,7 +712,6 @@
unset($e);
return false;
}
- //echo "
accounts::id2name($account_id,$which)='{$data[$which]}'";
return $data[$which];
}
@@ -780,7 +809,6 @@
*/
function set_memberships($groups,$account_id)
{
- //echo "
accounts::set_memberships(".print_r($groups,true).",$account_id)
\n";
if (!is_int($account_id) && !is_numeric($account_id))
{
$account_id = $this->name2id($account_id);
@@ -830,7 +858,6 @@
*/
function set_members($members,$gid)
{
- //echo "
accounts::set_members(".print_r($members,true).",$gid)
\n";
if (($old_members = $this->members($gid, true, false)) != $members)
{
$this->backend->set_members($members, $gid);
@@ -898,7 +925,6 @@
{
$cache = $accounts;
}
- //echo "
accounts::split_accounts(".print_r($app_users,True).",'$use') =
".print_r($accounts,True)."
\n";
switch($use)
{
@@ -1054,7 +1080,7 @@
{
$instance = self::getInstance();
- egw_cache::unsetCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id);
+ Cache::unsetCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id);
unset(self::$request_cache[$account_id]);
}
@@ -1062,7 +1088,7 @@
// session-cache
if (self::$cache) self::$cache = array();
- egw_cache::unsetSession('accounts_cache','phpgwapi');
+ Cache::unsetSession('accounts_cache','phpgwapi');
if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited
{
@@ -1100,7 +1126,7 @@
{
$instance = self::getInstance();
- $account = egw_cache::getCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id);
+ $account = Cache::getCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id);
if (!isset($account)) // not in instance cache --> read from backend
{
@@ -1114,7 +1140,7 @@
{
if (!isset($account['members'])) $account['members'] = $instance->backend->members($account_id);
}
- egw_cache::setCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT);
+ Cache::setCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT);
}
//error_log(__METHOD__."($account_id) read from backend ".array2string($account));
}
@@ -1129,7 +1155,7 @@
{
if ($instance->is_active($id)) $account['members-active'][$id] = $lid;
}
- egw_cache::setCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT);
+ Cache::setCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT);
}
//error_log(__METHOD__."($account_id, $need_active) returning ".array2string($account));
return $account;
@@ -1155,210 +1181,13 @@
if (self::$use_session_cache && is_object($GLOBALS['egw']->session))
{
- self::$cache =& egw_cache::getSession('accounts_cache','phpgwapi');
- //echo "
restoring cache from session, ".count(call_user_func_array('array_merge',(array)self::$cache))." items
\n";
+ self::$cache =& Cache::getSession('accounts_cache','phpgwapi');
}
//error_log(__METHOD__."() use_session_cache=".array2string(self::$use_session_cache).", is_array(self::\$cache)=".array2string(is_array(self::$cache)));
if (!is_array(self::$cache))
{
- //echo "
initialising this->cache to array()
\n";
self::$cache = array();
}
}
-
- /**
- * @deprecated not used any more, as static cache is a reference to the session
- */
- function save_session_cache()
- {
-
- }
-
- /**
- * Depricated functions of the old accounts class.
- *
- * Do NOT use them in new code, they will be removed after the next major release!!!
- */
-
- /**
- * 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()
- {
- return $this->data = $this->account_id ? $this->read($this->account_id,true) : array();
- }
-
- /**
- * saves the account-data in the internal data-structure of this class to the repository
- *
- * @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
- */
- function get_list($_type='both',$start = null,$sort = '', $order = '', $query = '', $offset = null,$query_type='')
- {
- if (is_array($_type)) // XML-RPC
- {
- return array_values($this->search($_type));
- }
- return array_values($this->search(array(
- 'type' => $_type,
- 'start' => $start,
- 'order' => $order,
- 'sort' => $sort,
- 'query' => $query,
- 'offset' => $offset,
- 'query_type' => $query_type ,
- )));
- }
-
- /**
- * Create a new account with the given $account_info
- *
- * @deprecated use save
- * @param array $account_info account data for the new account
- * @param booelan $default_prefs =true 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)
- {
- unset($default_prefs); // not used, but required by function signature
- return $this->save($account_info);
- }
-
- /**
- * 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
- * @param int|string $_accountid ='' numeric account-id or alphanum. account-lid,
- * 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 "
accounts::membership($accountid)="; _debug_array($old);
- return $old;
- }
-
- /**
- * Get all members of the group $accountid
- *
- * @deprecated use members which returns acount_id => account_lid pairs
- * @param int|string $accountid ='' numeric account-id or alphanum. account-lid,
- * 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);
- }
- 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
- * @param int|string $accountid ='' numeric account-id or alphanum. account-lid,
- * 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
- */
- function get_account_name($accountid,&$lid,&$fname,&$lname)
- {
- if (!($data = $this->read($accountid))) return false;
-
- $lid = $data['account_lid'];
- $fname = $data['account_firstname'];
- $lname = $data['account_lastname'];
-
- 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
- * @param int $account_id numeric account-id
- * @return array with keys lid, firstname, lastname, fullname, type
- */
- function get_account_data($account_id)
- {
- $this->account_id = $account_id;
- $this->read_repository();
-
- $data = array();
- $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;
- }
}
Copied: trunk/egroupware/api/src/Accounts/Ads.php (from r55263, trunk/phpgwapi/inc/class.accounts_ads.inc.php)
URL: http://svn.stylite.de/viewvc/egroupware/trunk/egroupware/api/src/Accounts/Ads.php?p2=trunk/egroupware/api/src/Accounts/Ads.php&p1=trunk/phpgwapi/inc/class.accounts_ads.inc.php&r1=55263&r2=55280&rev=55280&view=diff
==============================================================================
--- trunk/phpgwapi/inc/class.accounts_ads.inc.php (original)
+++ trunk/egroupware/api/src/Accounts/Ads.php Sun Mar 6 16:54:07 2016
@@ -11,7 +11,12 @@
* @version $Id$
*/
+namespace EGroupware\Api\Accounts;
+
+use EGroupware\Api;
+
require_once EGW_API_INC.'/adldap/adLDAP.php';
+use adLDAPException;
/**
* Active directory backend for accounts
@@ -31,7 +36,7 @@
* @link http://www.selfadsi.org/attributes-e2k7.htm
* @link http://msdn.microsoft.com/en-us/library/ms675090(v=vs.85).aspx
*/
-class accounts_ads
+class Ads
{
/**
* Instance of adLDAP class
@@ -113,7 +118,6 @@
*
* @param accounts $frontend reference to the frontend class, to be able to call it's methods if needed
* @throws adLDAPException
- * @return accounts_ldap
*/
function __construct(accounts $frontend)
{
@@ -136,8 +140,8 @@
if (!isset($adldap[$config['ads_domain']]))
{
- if (empty($config['ads_host'])) throw new Exception("Required ADS host name(s) missing!");
- if (empty($config['ads_domain'])) throw new Exception("Required ADS domain missing!");
+ if (empty($config['ads_host'])) throw new Api\Exception("Required ADS host name(s) missing!");
+ if (empty($config['ads_domain'])) throw new Api\Exception("Required ADS domain missing!");
$base_dn_parts = array();
foreach(explode('.', $config['ads_domain']) as $dc)
@@ -153,9 +157,9 @@
'admin_password' => $config['ads_admin_passwd'],
'use_tls' => $config['ads_connection'] == 'tls',
'use_ssl' => $config['ads_connection'] == 'ssl',
- 'charset' => translation::charset(),
+ 'charset' => Api\Translation::charset(),
);
- $adldap[$config['ads_domain']] = new adLDAP_egw($options);
+ $adldap[$config['ads_domain']] = new adLDAP($options);
if (self::$debug) error_log(__METHOD__."() new adLDAP(".array2string($options).") returned ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace());
}
//else error_log(__METHOD__."() returning cached adLDAP ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace());
@@ -173,7 +177,7 @@
static $domain_sid = null;
if (!isset($domain_sid))
{
- $domain_sid = egw_cache::getCache($this->frontend->config['install_id'], __CLASS__, 'ads_domain_sid');
+ $domain_sid = Api\Cache::getCache($this->frontend->config['install_id'], __CLASS__, 'ads_domain_sid');
if ((!is_array($domain_sid) || !isset($domain_sid[$this->frontend->config['ads_domain']])) &&
($adldap = self::get_adldap($this->frontend->config)) &&
($sr = ldap_search($adldap->getLdapConnection(), $adldap->getBaseDn(), '(objectclass=domain)', array('objectsid'))) &&
@@ -181,7 +185,7 @@
{
$domain_sid = array();
$domain_sid[$this->frontend->config['ads_domain']] = $adldap->utilities()->getTextSID($entries[0]['objectsid'][0]);
- egw_cache::setCache($this->frontend->config['install_id'], __CLASS__, 'ads_domain_sid', $domain_sid);
+ Api\Cache::setCache($this->frontend->config['install_id'], __CLASS__, 'ads_domain_sid', $domain_sid);
}
}
$sid = $domain_sid[$this->frontend->config['ads_domain']];
@@ -234,7 +238,7 @@
$matches = null;
if (!preg_match('/^(.*),'.preg_quote($base, '/').'$/i', $context, $matches))
{
- throw new egw_exception_wrong_userinput("Wrong or not configured ADS context '$context' (baseDN='$base')!");
+ throw new Api\Exception\WrongUserinput("Wrong or not configured ADS context '$context' (baseDN='$base')!");
}
$container = $matches[1];
if (self::$debug) error_log(__METHOD__."() context='$context', base='$base' returning ".array2string($container));
@@ -348,7 +352,7 @@
function save(&$data)
{
$is_group = $data['account_id'] < 0 || $data['account_type'] === 'g';
- $data = translation::convert($data, translation::charset(), 'utf-8');
+ $data = Api\Translation::convert($data, Api\Translation::charset(), 'utf-8');
if ($data['account_id'] && !($old = $this->read($data['account_id'])))
{
@@ -362,7 +366,7 @@
error_log(__METHOD__.'('.array2string($data).") changing account-type user <--> group forbidden!");
return false;
}
- $old = translation::convert($old, translation::charset(), 'utf-8');
+ $old = Api\Translation::convert($old, Api\Translation::charset(), 'utf-8');
}
$ret = $is_group ? $this->_save_group($data, $old) : $this->_save_user($data, $old);
@@ -408,7 +412,7 @@
*/
protected function _ldap2group($_data)
{
- $data = translation::convert($_data, 'utf-8');
+ $data = Api\Translation::convert($_data, 'utf-8');
// no need to calculate sid, if already calculated
$sid = is_string($data['objectsid']) ? $data['objectsid'] :
@@ -469,7 +473,7 @@
*/
protected function _ldap2user(array $_data)
{
- $data = translation::convert($_data, 'utf-8');
+ $data = Api\Translation::convert($_data, 'utf-8');
// no need to calculate sid, if already calculated
$sid = is_string($data['objectsid']) ? $data['objectsid'] :
@@ -561,8 +565,8 @@
if (!isset($utc)) $utc = new DateTimeZone('UTC');
list($when) = explode('.', $_when); // remove .0Z not understood by createFromFormat
- $datetime = egw_time::createFromFormat(self::WHEN_FORMAT, $when, $utc);
- if (egw_time::$server_timezone) $datetime->setTimezone(egw_time::$server_timezone);
+ $datetime = Api\DateTime::createFromFormat(self::WHEN_FORMAT, $when, $utc);
+ if (Api\DateTime::$server_timezone) $datetime->setTimezone(Api\DateTime::$server_timezone);
return $datetime->getTimestamp();
}
@@ -945,7 +949,6 @@
$account_search[$unl_serial]['total'] = $this->total = count($accounts);
}
- //echo "
accounts_ldap::search() found $this->total: ".microtime()."
\n";
// return only the wanted accounts
reset($sortedAccounts);
if(is_numeric($start) && is_numeric($offset))
@@ -1072,7 +1075,7 @@
continue; // ignore system accounts incl. "Administrator"
}
$accounts[($data['samaccounttype'][0] == adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP ? '-' : '').$rid] =
- $attrs ? $data : translation::convert($data['samaccountname'][0], 'utf-8');
+ $attrs ? $data : Api\Translation::convert($data['samaccountname'][0], 'utf-8');
}
}
else if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter')=$sri allValues=".array2string($allValues));
@@ -1241,7 +1244,7 @@
* - allow to use utf-8 charset internally, not just an 8-bit iso-charset
* - support for Windows2008r2 (maybe earlier too) and Samba4 "CN=Users" DN as container to create users or groups
*/
-class adLDAP_egw extends adLDAP
+class adLDAP extends \adLDAP
{
/**
* Charset used for internal encoding
@@ -1286,7 +1289,7 @@
*/
public function user() {
if (!$this->userClass) {
- $this->userClass = new adLDAPUsers_egw($this);
+ $this->userClass = new adLDAPUsers($this);
}
return $this->userClass;
}
@@ -1298,7 +1301,7 @@
*/
public function group() {
if (!$this->groupClass) {
- $this->groupClass = new adLDAPGroups_egw($this);
+ $this->groupClass = new adLDAPGroups($this);
}
return $this->groupClass;
}
@@ -1310,7 +1313,7 @@
*/
public function utilities() {
if (!$this->utilClass) {
- $this->utilClass = new adLDAPUtils_egw($this);
+ $this->utilClass = new adLDAPUtils($this);
}
return $this->utilClass;
}
@@ -1319,7 +1322,7 @@
/**
* Fixes an enhancements for adLDAPUser required by EGroupware
*/
-class adLDAPUsers_egw extends adLDAPUsers
+class adLDAPUsers extends \adLDAPUsers
{
/**
* Create a user
@@ -1579,7 +1582,7 @@
/**
* Fixes an enhancements for adLDAPGroups required by EGroupware
*/
-class adLDAPGroups_egw extends adLDAPGroups
+class adLDAPGroups extends \adLDAPGroups
{
/**
* Create a group
@@ -1623,7 +1626,7 @@
/**
* Fixes an enhancements for adLDAPUtils required by EGroupware
*/
-class adLDAPUtils_egw extends adLDAPUtils
+class adLDAPUtils extends \adLDAPUtils
{
/**
* Convert 8bit characters e.g. accented characters to UTF8 encoded characters
Copied: trunk/egroupware/api/src/Accounts/Ldap.php (from r55263, trunk/phpgwapi/inc/class.accounts_ldap.inc.php)
URL: http://svn.stylite.de/viewvc/egroupware/trunk/egroupware/api/src/Accounts/Ldap.php?p2=trunk/egroupware/api/src/Accounts/Ldap.php&p1=trunk/phpgwapi/inc/class.accounts_ldap.inc.php&r1=55263&r2=55280&rev=55280&view=diff
==============================================================================
--- trunk/phpgwapi/inc/class.accounts_ldap.inc.php (original)
+++ trunk/egroupware/api/src/Accounts/Ldap.php Sun Mar 6 16:54:07 2016
@@ -17,6 +17,14 @@
* @version $Id$
*/
+namespace EGroupware\Api\Accounts;
+
+use EGroupware\Api;
+
+// explicitly reference classes still in phpgwapi or old structure
+use common; // next_id
+use auth;
+
/**
* LDAP Backend for accounts
*
@@ -34,11 +42,9 @@
*
* @author Ralf Becker
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
- * @package api
- * @subpackage accounts
* @access internal only use the interface provided by the accounts class
*/
-class accounts_ldap
+class Ldap
{
/**
* Name of mail attribute
@@ -144,7 +150,6 @@
* Constructor
*
* @param accounts $frontend reference to the frontend class, to be able to call it's methods if needed
- * @return accounts_ldap
*/
function __construct(accounts $frontend)
{
@@ -153,7 +158,7 @@
// enable the caching in the session, done by the accounts class extending this class.
$this->use_session_cache = true;
- $this->ldap = new ldap(true);
+ $this->ldap = new Api\Ldap(true);
$this->ds = $this->ldap->ldapConnect($this->frontend->config['ldap_host'],
$this->frontend->config['ldap_root_dn'],$this->frontend->config['ldap_root_pw']);
@@ -192,7 +197,7 @@
{
$is_group = $data['account_id'] < 0 || $data['account_type'] === 'g';
- $data_utf8 = translation::convert($data,translation::charset(),'utf-8');
+ $data_utf8 = Api\Translation::convert($data,Api\Translation::charset(),'utf-8');
$members = $data['account_members'];
if (!is_object($this->ldapServerInfo))
@@ -214,7 +219,7 @@
}
else
{
- $old = ldap::result2array($old[0]);
+ $old = Api\Ldap::result2array($old[0]);
$old['objectclass'] = array_map('strtolower', $old['objectclass']);
$key = false;
if ($is_group && ($key = array_search('namedobject',$old['objectclass'])) !== false ||
@@ -359,7 +364,7 @@
if (!$GLOBALS['egw_info']['server']['ldap_allow_systemusernames'] && !$old &&
function_exists('posix_getpwnam') && posix_getpwnam($data['account_lid']))
{
- throw new egw_exception_wrong_userinput(lang('There already is a system-user with this name. User\'s should not have the same name as a systemuser'));
+ throw new Api\Exception\WrongUserinput(lang('There already is a system-user with this name. User\'s should not have the same name as a systemuser'));
}
}
@@ -367,7 +372,6 @@
if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) {
unset($to_write['memberuid']);
}
- //echo "
ldap_".($old ? 'modify' : 'add')."(,$dn,".print_r($to_write,true).")
\n";
// modifying or adding the entry
if ($old && !@ldap_modify($this->ds,$dn,$to_write) ||
!$old && !@ldap_add($this->ds,$dn,$to_write))
@@ -453,7 +457,7 @@
{
return false; // group not found
}
- $data = translation::convert($ldap_data[0],'utf-8');
+ $data = Api\Translation::convert($ldap_data[0],'utf-8');
unset($data['objectclass']['count']);
$group += array(
@@ -504,7 +508,7 @@
{
return false; // user not found
}
- $data = translation::convert($ldap_data[0],'utf-8');
+ $data = Api\Translation::convert($ldap_data[0],'utf-8');
$utc_diff = date('Z');
$user = array(
@@ -534,7 +538,7 @@
'account_created' => isset($data['createtimestamp'][0]) ? self::accounts_ldap2ts($data['createtimestamp'][0]) : null,
'account_modified' => isset($data['modifytimestamp'][0]) ? self::accounts_ldap2ts($data['modifytimestamp'][0]) : null,
);
- //echo "
accounts_ldap::_read_user($account_id): shadowexpire={$data['shadowexpire'][0]} --> account_expires=$user[account_expires]=".date('Y-m-d H:i',$user['account_expires'])."
\n";
+
if ($this->frontend->config['ldap_extra_attributes'])
{
$user['homedirectory'] = $data['homedirectory'][0];
@@ -573,8 +577,6 @@
*/
protected function _merge_user($to_write,$data,$new_entry)
{
- //echo "
accounts_ldap::_merge_user(".print_r($to_write,true).','.print_r($data,true).",$new_entry)
\n";
-
$to_write['uidnumber'] = $data['account_id'];
$to_write['uid'] = $data['account_lid'];
$to_write['gidnumber'] = abs($data['account_primary_group']);
@@ -594,7 +596,7 @@
{
if (preg_match('/^[a-f0-9]{32}$/', $data['account_passwd'])) // md5 --> ldap md5
{
- $data['account_passwd'] = setup_cmd_ldap::hash_sql2ldap($data['account_passwd']);
+ $data['account_passwd'] = setup_cmd_Api\Ldap::hash_sql2ldap($data['account_passwd']);
}
elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd'])) // if it's not already entcrypted, do so now
{
@@ -609,7 +611,7 @@
// - if it's set to > 0, it will or already has expired --> acount is active if it not yet expired
// shadowexpire is in days since 1970/01/01 (equivalent to a timestamp (int UTC!) / (24*60*60)
$shadowexpire = ($data['account_expires']-$utc_diff) / (24*3600);
- //echo "
account_expires=".date('Y-m-d H:i',$data['account_expires'])." --> $shadowexpire --> ".date('Y-m-d H:i',$account_expire)."
\n";
+
$to_write['shadowexpire'] = !$data['account_status'] ?
($data['account_expires'] != -1 && $data['account_expires'] < time() ? round($shadowexpire) : 0) :
($data['account_expires'] != -1 ? round($shadowexpire) : array()); // array() = unset value
@@ -660,7 +662,7 @@
function search($param)
{
//error_log(__METHOD__."(".array2string($param).")");
- $account_search =& accounts::$cache['account_search'];
+ $account_search =& Api\Accounts::$cache['account_search'];
// check if the query is cached
$serial = serialize($param);
@@ -683,7 +685,7 @@
}
else // we need to run the unlimited query
{
- $query = ldap::quote(strtolower($param['query']));
+ $query = Api\Ldap::quote(strtolower($param['query']));
$accounts = array();
if($param['type'] != 'groups')
@@ -762,7 +764,6 @@
$filter = str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$filter);
}
$sri = ldap_search($this->ds, $this->user_context, $filter,array('uid','uidNumber','givenname','sn',static::MAIL_ATTR,'shadowExpire','createtimestamp','modifytimestamp','objectclass','gidNumber'));
- //echo "
ldap_search(,$this->user_context,'$filter',) ".($sri ? '' : ldap_error($this->ds)).microtime()."
\n";
$utc_diff = date('Z');
foreach(ldap_get_entries($this->ds, $sri) as $allVals)
@@ -773,10 +774,10 @@
{
$account = Array(
'account_id' => $allVals['uidnumber'][0],
- 'account_lid' => translation::convert($allVals['uid'][0],'utf-8'),
+ 'account_lid' => Api\Translation::convert($allVals['uid'][0],'utf-8'),
'account_type' => 'u',
- 'account_firstname' => translation::convert($allVals['givenname'][0],'utf-8'),
- 'account_lastname' => translation::convert($allVals['sn'][0],'utf-8'),
+ 'account_firstname' => Api\Translation::convert($allVals['givenname'][0],'utf-8'),
+ 'account_lastname' => Api\Translation::convert($allVals['sn'][0],'utf-8'),
'account_status' => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0]*24*3600-$utc_diff < time() ? false : 'A',
'account_expires' => isset($allVals['shadowexpire']) && $allVals['shadowexpire'][0] ? $allVals['shadowexpire'][0]*24*3600+$utc_diff : -1, // LDAP date is in UTC
'account_email' => $allVals[static::MAIL_ATTR][0],
@@ -790,7 +791,8 @@
if (isset($totalcount)) --$totalcount;
continue;
}
- $account['account_fullname'] = common::display_fullname($account['account_lid'],$account['account_firstname'],$account['account_lastname'],$allVals['uidnumber'][0]);
+ $account['account_fullname'] = Api\Accounts::format_username($account['account_lid'],
+ $account['account_firstname'], $account['account_lastname'], $allVals['uidnumber'][0]);
// return objectclass(es)
if ($param['objectclass'])
{
@@ -832,12 +834,12 @@
{
$accounts[(string)-$allVals['gidnumber'][0]] = Array(
'account_id' => -$allVals['gidnumber'][0],
- 'account_lid' => translation::convert($allVals['cn'][0],'utf-8'),
+ 'account_lid' => Api\Translation::convert($allVals['cn'][0],'utf-8'),
'account_type' => 'g',
- 'account_firstname' => translation::convert($allVals['cn'][0],'utf-8'),
+ 'account_firstname' => Api\Translation::convert($allVals['cn'][0],'utf-8'),
'account_lastname' => lang('Group'),
'account_status' => 'A',
- 'account_fullname' => translation::convert($allVals['cn'][0],'utf-8'),
+ 'account_fullname' => Api\Translation::convert($allVals['cn'][0],'utf-8'),
);
if (isset($totalcount)) ++$totalcount;
}
@@ -857,7 +859,6 @@
$account_search[$unl_serial]['total'] = $this->total;
}
}
- //echo "
accounts_ldap::search() found $this->total: ".microtime()."
\n";
// return only the wanted accounts
reset($sortedAccounts);
if(is_numeric($start) && is_numeric($offset))
@@ -939,7 +940,7 @@
*/
function name2id($_name,$which='account_lid',$account_type=null)
{
- $name = ldap::quote(translation::convert($_name,translation::charset(),'utf-8'));
+ $name = Api\Ldap::quote(Api\Translation::convert($_name,Api\Translation::charset(),'utf-8'));
if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid
{
@@ -1009,7 +1010,7 @@
{
if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) return false;
- $sri = ldap_search($this->ds,$this->group_context,'(&(objectClass=posixGroup)(memberuid='.ldap::quote($account_lid).'))',array('cn','gidnumber'));
+ $sri = ldap_search($this->ds,$this->group_context,'(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))',array('cn','gidnumber'));
$memberships = array();
foreach((array)ldap_get_entries($this->ds, $sri) as $key => $data)
{
@@ -1017,7 +1018,6 @@
$memberships[(string) -$data['gidnumber'][0]] = $data['cn'][0];
}
- //echo "accounts::memberships($account_id)"; _debug_array($memberships);
return $memberships;
}
@@ -1054,7 +1054,6 @@
}
}
}
- //echo "accounts_ldap::members($gid)"; _debug_array($members);
return $members;
}
@@ -1066,8 +1065,6 @@
*/
function set_memberships($groups,$account_id)
{
- //echo "
accounts_ldap::set_memberships(".print_r($groups,true).",$account_id)
\n";
-
// remove not longer existing memberships
if (($old_memberships = $this->memberships($account_id)))
{
@@ -1102,7 +1099,6 @@
*/
function set_members($members, $gid, array $objectclass=null, $use_cn=null)
{
- //echo "
accounts_ldap::set_members(".print_r($members,true).",$gid)
\n";
if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) return false;
// do that group is a groupOf(Unique)Names or univentionGroup?
@@ -1154,7 +1150,7 @@
}
}
}
- if (!ldap_modify($this->ds,'cn='.ldap::quote($cn).','.$this->group_context,$to_write))
+ if (!ldap_modify($this->ds,'cn='.Api\Ldap::quote($cn).','.$this->group_context,$to_write))
{
echo "ldap_modify(,'cn=$cn,$this->group_context',".print_r($to_write,true)."))\n";
return false;
Copied: trunk/egroupware/api/src/Accounts/Sql.php (from r55263, trunk/phpgwapi/inc/class.accounts_sql.inc.php)
URL: http://svn.stylite.de/viewvc/egroupware/trunk/egroupware/api/src/Accounts/Sql.php?p2=trunk/egroupware/api/src/Accounts/Sql.php&p1=trunk/phpgwapi/inc/class.accounts_sql.inc.php&r1=55263&r2=55280&rev=55280&view=diff
==============================================================================
--- trunk/phpgwapi/inc/class.accounts_sql.inc.php (original)
+++ trunk/egroupware/api/src/Accounts/Sql.php Sun Mar 6 16:54:07 2016
@@ -23,21 +23,27 @@
* @version $Id$
*/
+namespace EGroupware\Api\Accounts;
+
+use EGroupware\Api;
+
+// explicitly reference classes still in phpgwapi of old structure
+use emailadmin_smtp_sql;
+use acl;
+
/**
* SQL Backend for accounts
*
* @author Ralf Becker
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
- * @package api
- * @subpackage accounts
* @access internal only use the interface provided by the accounts class
*/
-class accounts_sql
+class Sql
{
/**
* instance of the db class
*
- * @var egw_db
+ * @var Api\Db
*/
var $db;
/**
@@ -74,9 +80,9 @@
private $frontend;
/**
- * Instance of contacts object / addressbook_bo, NOT automatic instanciated!
- *
- * @var addressbook_bo
+ * Instance of contacts object, NOT automatic instanciated!
+ *
+ * @var Api\Contacts
*/
private $contacts;
@@ -93,10 +99,9 @@
/**
* Constructor
*
- * @param accounts $frontend reference to the frontend class, to be able to call it's methods if needed
- * @return accounts_sql
- */
- function __construct(accounts $frontend)
+ * @param Api\Accounts $frontend reference to the frontend class, to be able to call it's methods if needed
+ */
+ function __construct(Api\Accounts $frontend)
{
$this->frontend = $frontend;
@@ -171,14 +176,13 @@
$data['account_lastname'] = $data['account_type'] == 'g' ? 'Group' : 'User';
// if we call lang() before the translation-class is correctly setup,
// we can't switch away from english language anymore!
- if (translation::$lang_arr)
+ if (Api\Translation::$lang_arr)
{
$data['account_lastname'] = lang($data['account_lastname']);
}
}
if (!$data['account_fullname']) $data['account_fullname'] = $data['account_firstname'].' '.$data['account_lastname'];
- //echo "accounts_sql::read($account_id)"; _debug_array($data);
return $data;
}
@@ -192,7 +196,6 @@
*/
function save(&$data)
{
- //echo "
accounts_sql::save(".print_r($data,true).")
\n";
$to_write = $data;
unset($to_write['account_passwd']);
// encrypt password if given or unset it if not
@@ -287,7 +290,7 @@
}
if ($contact_id)
{
- if (!isset($this->contacts)) $this->contacts = new addressbook_bo();
+ if (!isset($this->contacts)) $this->contacts = new Api\Contacts();
$this->contacts->delete($contact_id,false); // false = allow to delete accounts (!)
}
return true;
@@ -311,7 +314,6 @@
$memberships[(string) $gid] = $this->id2name($gid);
}
}
- //echo "accounts::memberships($account_id)"; _debug_array($memberships);
return $memberships;
}
@@ -357,7 +359,6 @@
{
$members[$row['account_id']] = $row['account_lid'];
}
- //echo "accounts::members($accountid)"; _debug_array($members);
return $members;
}
@@ -369,7 +370,6 @@
*/
function set_members($members,$gid)
{
- //echo "
accounts::set_members(".print_r($members,true).",$gid)
\n";
$GLOBALS['egw']->acl->delete_repository('phpgw_group',$gid,false);
if (is_array($members))
@@ -410,11 +410,11 @@
'account_email' => 'contact_email',
);
- // fetch order of account_fullname from common::display_fullname
+ // fetch order of account_fullname from Api\Accounts::format_username
if (strpos($param['order'],'account_fullname') !== false)
{
$param['order'] = str_replace('account_fullname', preg_replace('/[ ,]+/',',',str_replace(array('[',']'),'',
- common::display_fullname('account_lid','account_firstname','account_lastname'))), $param['order']);
+ Api\Accounts::format_username('account_lid','account_firstname','account_lastname'))), $param['order']);
}
$order = str_replace(array_keys($order2contact),array_values($order2contact),$param['order']);
// allways add 'account_lid', as it is only valid one for groups
@@ -490,7 +490,7 @@
}
if ($param['active'])
{
- $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),addressbook_sql::ACOUNT_ACTIVE_FILTER);
+ $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),Api\Contacts\Sql::ACOUNT_ACTIVE_FILTER);
}
$criteria = array();
$wildcard = $param['query_type'] == 'start' || $param['query_type'] == 'exact' ? '' : '%';
@@ -532,7 +532,7 @@
break;
}
}
- if (!isset($this->contacts)) $this->contacts = new addressbook_bo();
+ if (!isset($this->contacts)) $this->contacts = new Api\Contacts();
$accounts = array();
foreach((array) $this->contacts->search($criteria,
@@ -556,9 +556,9 @@
'account_status' => $contact['account_status'],
'account_expires' => $contact['account_expires'],
'account_primary_group' => $contact['account_primary_group'],
- // addressbook_bo::search() returns everything in user-time, need to convert to server-time
- 'account_created' => egw_time::user2server($contact['created']),
- 'account_modified' => egw_time::user2server($contact['modified']),
+ // Api\Contacts::search() returns everything in user-time, need to convert to server-time
+ 'account_created' => Api\DateTime::user2server($contact['created']),
+ 'account_modified' => Api\DateTime::user2server($contact['modified']),
'account_description' => $contact['account_description'],
);
}
@@ -607,7 +607,7 @@
// check if we need to treat username case-insensitive
if ($which == 'account_lid' && !$GLOBALS['egw_info']['server']['case_sensitive_username']) // = is case sensitiv eg. on postgres, but not on mysql!
{
- $where[] = 'account_lid '.$this->db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($where['account_lid']);
+ $where[] = 'account_lid '.$this->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($where['account_lid']);
unset($where['account_lid']);
}
}
Copied: trunk/egroupware/api/src/Accounts/Univention.php (from r55263, trunk/phpgwapi/inc/c