Source for file Admin.php
Documentation is available at Admin.php
// LiveUser: A framework for authentication and authorization in PHP applications
// Copyright (C) 2002-2003 Markus Wolff
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
require_once 'LiveUser.php';
* Attempt at a unified admin class
* $admin = new LiveUser_Admin($conf, 'FR');
* $found = $admin->getUser(3);
* var_dump($admin->perm->getRights());
* @see LiveUser::factory()
* @author Arnaud Limbourg
* @version $Id: Admin.php,v 1.45 2004/08/30 08:45:27 lsmith Exp $
* Name of the current selected auth container
* Array containing the auth objects.
var $_authContainers = array ();
* @param array liveuser conf array
* @param string two letters language code
if (isset ($this->_conf['autoInit']) && $this->_conf['autoInit'] === true ) {
* Merges the current configuration array with configuration array pases
* along with the method call.
* @param array configuration array
* @return boolean true upon success, false otherwise
* Makes your instance global.
* <b>You MUST call this method with the $var = &LiveUser_Admin::singleton() syntax.
* Without the ampersand (&) in front of the method name, you will not get
* a reference, you will get a copy.</b>
* @param array liveuser conf array
* @param string two letters language code
* @return object Returns an object of either LiveUser or PEAR_Error type
* @see LiveUser_Admin::LiveUser_Admin
if (!isset ($instances)) $instances = array ();
if (!isset ($instances[$signature])) {
if(PEAR ::isError ($obj)) {
$instances[$signature] = & $obj;
return $instances[$signature];
* creates an instance of an auth object
* @param mixed Array containing the configuration.
* @param string Name of the auth container.
* @return object Returns an object of an auth container
function &_authFactory ($conf, $name = null )
$classname = 'LiveUser_Admin_Auth_Container_' . $conf['type'];
$filename = 'LiveUser/Admin/Auth/Container/' . $conf['type'] . '.php';
'Missing file: '. $filename);
'Class not defined in file as expected: '. $filename, 'LiveUser');
$auth = &new $classname($conf, $name);
* creates an instance of an perm object
* @param mixed Name of array containing the configuration.
* @return object Returns an object of a perm container
function &_permFactory ($conf)
$classname = 'LiveUser_Admin_Perm_Container_' . $conf['type'];
$filename = 'LiveUser/Admin/Perm/Container/' . $conf['type'] . '.php';
'Missing file: '. $filename);
$this->_error = LiveUser::raiseError (LIVEUSER_NOT_SUPPORTED , null , null ,
'Class not defined in file as expected: '. $filename, 'LiveUser');
$perm = &new $classname($conf);
* Sets the current auth container to the one with the given auth container name
* Upon success it will return true. You can then
* access the auth backend container by using the
* auth property of this class.
* e.g.: $admin->auth->addUser();
* @param string auth container name
* @return boolean true upon success, false otherwise
if (!isset ($this->_authContainers[$authName])
|| !is_object($this->_authContainers[$authName])
if (!isset ($this->_conf['authContainers'][$authName])) {
$this->_authContainers[$authName] =
&$this->_authFactory ($this->_conf['authContainers'][$authName], $authName);
$this->auth = &$this->_authContainers[$authName];
* Sets the perm container
* Upon success it will return true. You can then
* access the perm backend container by using the
* perm properties of this class.
* e.g.: $admin->perm->addUser();
* @return boolean true upon success, false otherwise
$this->perm = &$this->_permFactory ($this->_conf['permContainer']);
$this->perm->setCurrentLanguage ($this->lang);
* Tries to find a user in any of the auth container.
* Upon success it will return true. You can then
* access the backend container by using the auth
* and perm properties of this class.
* e.g.: $admin->perm->updateAuthUserId();
* @param mixed user auth id
* @param string auth container name
* @return boolean true upon success, false otherwise
reset($this->_conf['authContainers']);
$authName = key($this->_conf['authContainers']);
foreach ($this->_conf['authContainers'] as $k => $v) {
if (!isset ($this->_authContainers[$k]) ||
$this->_authContainers[$k] = &$this->_authFactory ($v, $k);
$match = $this->_authContainers[$k]->getUsers (array ('auth_user_id' => $authId));
* Tries to add a user to both containers.
* If the optional $id parameter is passed it will be used
* In any case the auth and perm id will be equal when using this method.
* If this behaviour doesn't suit your needs please consider
* using directly the concerned method. This method is just
* implement to simplify things a bit and should satisfy most
* Note type is optional for DB, thus it's needed for MDB and MDB2,
* we recommend that you use type even though you use DB, so if you change to MDB[2],
* it will be no problem for you.
* usage example for addUser:
* $user_id = $admin->addUser('johndoe', 'dummypass', true, null, null, null);
* Untested: it most likely doesn't work.
* @param string user handle (username)
* @param string user password
* @param integer permission user type
* @param boolean is account active ?
* @param integer ID of the owning user.
* @param integer ID of the owning group.
* @param array values for the custom fields
* @return mixed userid or false
function addUser($handle, $password, $type = null , $active = true , $id = null , $owner_user_id = null ,
$owner_group_id = null , $customFields = array ())
$authId = $this->auth->addUser ($handle, $password, $active, $owner_user_id,
$owner_group_id, $id, $customFields);
'Perm or Auth container couldn\t be started.');
* Tried to changes user data for both containers.
* Note type is optional for DB, thus it's needed for MDB and MDB2,
* we recommend that you use type even though you use DB, so if you change to MDB[2],
* it will be no problem for you.
* usage example for updateUser:
* $admin->updateUser($user_id, 'johndoe', 'dummypass', true, null, null);
* Untested: it most likely doesn't work.
* @param string user handle (username)
* @param string user password
* @param integer permission user type
* @param boolean is account active ?
* @param integer ID of the owning user.
* @param integer ID of the owning group.
* @param array values for the custom fields
* @return mixed error object or true
function updateUser($permId, $handle, $password, $type = null , $active = true
, $owner_user_id = null , $owner_group_id = null , $customFields = array ())
$authData = $this->perm->getAuthUserId ($permId);
$auth = $this->auth->updateUser ($authData['auth_user_id'], $handle, $password, $active,
$owner_user_id, $owner_group_id, $customFields);
'Perm or Auth container couldn\t be started.');
* Removes user from both containers
* Untested: it most likely doesn't work.
* @return mixed error object or true
$authData = $this->perm->getAuthUserId ($permId);
$result = $this->auth->removeUser ($authData['auth_user_id']);
return $this->perm->removeUser ($permId);
'Perm or Auth container couldn\t be started.');
* Searches users with given filters and returns
* all users found with their handle, passwd, auth_user_id
* lastlogin, is_active and the customFields if they are specified
* Untested: it most likely doesn't work.
* @param array filters to apply to fetched data
* @param string if not null 'ORDER BY $order' will be appended to the query
* @param boolean will return an associative array with the auth_user_id
* as the key by using DB::getAssoc() instead of DB::getAll()
* @return mixed error object or array
function searchUsers($filters = array (), $order = null , $rekey = false )
$search = $this->auth->getUsers ($filters, $order, $rekey);
'Perm or Auth container couldn\t be started.');
* Finds and gets userinfo by his userID, customFields can
* Untested: it most likely doesn't work.
* @param mixed Perm User ID
* @return mixed Array with userinfo if found else error object
function getUser($permId, $permFilter = array (), $authFilter = array (),
$permFilter['perm_user_id'] = $permId;
$permData = $this->perm->getUsers ($permFilter, $permOptions);
'name' => $this->auth->authTableCols ['required']['auth_user_id']['name'],
'value' => $permData['auth_user_id'],
'type' => $this->auth->authTableCols ['required']['auth_user_id']['type'],
$authData = $this->auth->getUsers ($authFilter);
'Perm or Auth container couldn\t be started.');
Documentation generated on Mon, 11 Mar 2019 13:56:14 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|