Source for file MDB2_Simple.php
Documentation is available at MDB2_Simple.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/Admin/Perm/Common.php';
* Container for simple rights managements.
* With it you can only assign rights to users. For advanced uses like
* groups assignements and more see DB_Medium and DB_Complex.
* @category authentication
* @version $Id: MDB2_Simple.php,v 1.35 2004/08/28 15:46:37 lsmith Exp $
* @param array full liveuser configuration array
* @see LiveUser::factory()
foreach ($connectOptions as $key => $value) {
if (isset ($this->$key)) {
if (isset ($connectOptions['connection']) &&
MDB2 ::isConnection ($connectOptions['connection'])
$this->dbc = &$connectOptions['connection'];
} elseif (isset ($connectOptions['dsn'])) {
$this->dsn = $connectOptions['dsn'];
if (isset ($connectOptions['function'])) {
$function = $connectOptions['function'];
if (isset ($connectOptions['options'])) {
$options = $connectOptions['options'];
$options['portability'] = MDB2_PORTABILITY_ALL;
if ($function == 'singleton') {
$this->dbc = & MDB2 ::singleton ($connectOptions['dsn'], $options);
$this->dbc = & MDB2 ::connect ($connectOptions['dsn'], $options);
if (!MDB2 ::isError ($this->dbc)) {
* Gets the perm ID of a user.
* @param string Auth user ID.
* @param string Auth container name.
* @return mixed Permission ID or MDB2 error.
' . $this->prefix . 'perm_users
auth_user_id = '. $this->dbc->quote ($authId, 'text'). '
auth_container_name = '. $this->dbc->quote ($authName, 'text');
$permId = $this->dbc->queryOne ($query);
} // end func _getPermUserId
* Gets the auth ID of a user.
* @param string Perm user ID.
* @return mixed Permission ID or DB error.
auth_user_id, auth_container_name
' . $this->prefix . 'perm_users
perm_user_id = '. $this->dbc->quote ($permId, 'text');
$authId = $this->dbc->queryRow ($query, array ('text', 'text'), MDB2_FETCHMODE_ASSOC );
return $authId['auth_user_id'];
} // end func _getAuthUserId
* Reads all languages from databases and stores them in private variable
* $this->_langs is filled with this array structure:
* two_letter_code => language_id
* @return mixed boolean or MDB2 Error object
if (sizeof($this->_langs) < 1 ) {
$query = 'SELECT two_letter_name, language_id FROM ' . $this->prefix . 'languages';
$langs = $this->dbc->queryAll ($query, null , MDB2_FETCHMODE_ASSOC , true );
if (MDB2 ::isError ($langs)) {
* Returns false if the language is not known
* @param string language short name
* @return mixed boolean or MDB2 Error object or false
if (MDB2 ::isError ($result = $this->_getLanguages ())) {
// Check if language is a known one
if (!isset ($this->_langs[$language])) {
$this->_language = $language;
* @return string name of the current language
* Set current application
* @param integer id of application
* @return boolean always true
$this->_application = $applicationId;
* Get current application
* @return string name of the current application
return $this->_application;
* Assigns name (and description) in specified language to a section
* @param integer id of [section]
* @param integer type of section
* @param string language (two letter code) of name/description
* @param string name of [section]
* @param string description of [section]
* @return mixed boolean or MDB2 Error object
function addTranslation($sectionId, $section_type, $language, $name, $description = null )
if (MDB2 ::isError ($result = $this->_getLanguages ())) {
// Check if language is a known one
if (!isset ($this->_langs[$language])) {
' . $this->prefix . 'translations
(section_id, section_type, language_id, name, description)
' . $this->dbc->quote ($sectionId, 'integer') . ',
' . $this->dbc->quote ($section_type, 'integer') . ',
' . $this->dbc->quote ($this->_langs[$language], 'integer') . ',
' . $this->dbc->quote ($name, 'text') . ',
' . $this->dbc->quote ($description, 'text') . '
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// name (and description) added ...
* Updates name (and description) of [section] in specified language
* @param integer id of [section]
* @param integer type of section
* @param string language (two letter code) of name/description
* @param string name of [section]
* @param string description of [section]
* @return mixed boolean or MDB2 Error object
function updateTranslation($sectionId, $section_type, $language, $name, $description = null )
if (MDB2 ::isError ($result = $this->_getLanguages ())) {
// Check if language is a known one
if (!isset ($this->_langs[$language])) {
' . $this->prefix . 'translations
name = ' . $this->dbc->quote ($name, 'text') . ',
description = ' . $this->dbc->quote ($description, 'text') . '
section_id = ' . $this->dbc->quote ($sectionId, 'integer') . ' AND
section_type = ' . $this->dbc->quote ($section_type, 'integer') . ' AND
language_id = ' . $this->dbc->quote ($this->_langs[$language], 'integer');
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// Translation name (and description) updated ...
* Remove name (and description) of the [section] in specified language
* @param integer id of [section]
* @param integer type of section
* @param string language (two letter code) of name/description
* @param boolean recursive delete of all translations
* @return mixed boolean or MDB2 Error object
if (MDB2 ::isError ($result = $this->_getLanguages ())) {
// Check if language is a known one
if (!isset ($this->_langs[$language])) {
' . $this->prefix . 'translations
section_id = ' . $this->dbc->quote ($sectionId, 'integer') . ' AND
section_type = ' . $this->dbc->quote ($section_type, 'integer');
$query .= ' AND language_id = ' . $this->dbc->quote ($this->_langs[$language], 'integer');
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// Translation name (and description) removed ...
* Get name (and description) of the [section] in specified language
* @param integer id of [section]
* @param integer type of section
* @return mixed array or MDB2 Error object
translations.name AS name,
translations.description AS description
' . $this->prefix . 'translations translations
section_id = ' . $this->dbc->quote ($sectionId, 'integer') . ' AND
section_type = ' . $this->dbc->quote ($section_type, 'integer');
$translation = $this->dbc->queryRow ($query, null , MDB2_FETCHMODE_ASSOC );
if (MDB2 ::isError ($translation)) {
// Translation name (and description) removed ...
* @param string two letter code of language
* @param string name of language
* @param string description of language
* @return mixed integer (language_id) or MDB2 Error object
function addLanguage($two_letter_code, $language_name, $language_description = null )
$languageId = $this->dbc->nextId ($this->prefix . 'languages', true );
if (MDB2 ::isError ($languageId)) {
' . $this->prefix . 'languages
(language_id, two_letter_name)
' . $this->dbc->quote ($two_letter_code, 'text') . '
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// force language reload in case it is the first language we create
if (sizeof($this->_langs) == 1 ) {
$lang = $two_letter_code;
// Insert Language translation into Translations table
if (MDB2 ::isError ($result)) {
* @param integer language (two letter code)
* @return mixed boolean or MDB2 Error object
if (MDB2 ::isError ($result = $this->_getLanguages ())) {
// Check if language is a known one
if (!isset ($this->_langs[$language])) {
' . $this->prefix . 'languages
language_id = ' . $this->dbc->quote ($this->_langs[$language], 'integer');
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// Delete language translations
if (MDB2 ::isError ($result)) {
* @param integer language (two letter code)
* @param string name of language
* @param string description of language
* @return mixed boolean or MDB2 Error object
function updateLanguage($language, $language_name, $language_description = null )
if (MDB2 ::isError ($result = $this->_getLanguages ())) {
// Check if language is a known one
if (!isset ($this->_langs[$language])) {
// Update Language translation into Translations table
$this->_langs[$language],
if (MDB2 ::isError ($result)) {
* @param string name of application constant
* @param string name of application
* @param string description of application
* @return mixed integer (application_id) or MDB2 Error object
function addApplication($define_name = null , $application_name = null ,
$application_description = null )
// Get next application id
$applicationId = $this->dbc->nextId ($this->prefix . 'applications', true );
if (MDB2 ::isError ($applicationId)) {
// Register new application
' . $this->prefix . 'applications
(application_id, application_define_name)
' . $this->dbc->quote ($applicationId, 'integer') . ',
' . $this->dbc->quote ((is_null($define_name) ? $define_name : $applicationId), 'text') . '
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// Insert Application translation into Translations table
if (MDB2 ::isError ($result)) {
* @param string id of application
* @param string name of area constant
* @param string name of area
* @param string description of area
* @return mixed integer (area_id) or MDB2 Error object
function addArea($applicationId, $define_name = null , $area_name = null ,
$area_description = null )
$areaId = $this->dbc->nextId ($this->prefix . 'areas', true );
if (MDB2 ::isError ($areaId)) {
(area_id, area_define_name, application_id)
' . $this->dbc->quote ($areaId, 'integer') . ',
' . $this->dbc->quote ((is_null($define_name) ? $define_name : $areaId), 'text') . ',
' . $this->dbc->quote ($applicationId, 'integer') . '
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// Insert Area translation into Translations table
if (MDB2 ::isError ($result)) {
* @param integer id of application
* @return mixed boolean or MDB2 Error object or false
// Get all areas within the application, no matter what language
application_id=' . $this->dbc->quote ($applicationId, 'integer');
$areas = $this->dbc->queryAll ($query, null , MDB2_FETCHMODE_ASSOC );
if (MDB2 ::isError ($areas)) {
// Delete all areas within the application
foreach($areas as $area) {
if (MDB2 ::isError ($res)) {
// Delete application translations
if (MDB2 ::isError ($result)) {
// Delete application itself
' . $this->prefix . 'applications
application_id = ' . $applicationId;
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
* @param integer id of area
* @return mixed boolean or MDB2 Error object or false
// Delete all rights in this area
$result = $this->dbc->queryCol ($query);
if (MDB2 ::isError ($result)) {
foreach($result as $rightId) {
' . $this->prefix . 'area_admin_areas
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
area_id = ' . $this->dbc->quote ($areaId, 'integer');
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// Delete area translations
if (MDB2 ::isError ($result)) {
* @param integer id of application
* @param string name of application constant
* @param string name of application
* @param string description of application
* @return mixed boolean or MDB2 Error object
$application_name = null , $application_description = null )
' . $this->prefix . 'applications
application_define_name = ' . $this->dbc->quote ($define_name, 'text') . '
application_id = ' . $this->dbc->quote ($applicationId, 'integer');
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// Update Application translation into Translations table
if (MDB2 ::isError ($result)) {
* @param integer id of area
* @param int id of application
* @param string name of area constant
* @param string name of area
* @param string description of area
* @return mixed boolean or MDB2 Error object or false
function updateArea($areaId, $applicationId, $define_name = null ,
$area_name = null , $area_description = null )
application_id = ' . $this->dbc->quote ($applicationId, 'integer') . ',
area_define_name = ' . $this->dbc->quote ((is_null($define_name) ? $define_name : $applicationId), 'text') . '
area_id = ' . $this->dbc->quote ($areaId, 'integer');
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// Update Area translation into Translations table
if (MDB2 ::isError ($result)) {
* Add a right in special area
* @param integer id of area
* @param string name of right constant
* @param string name of right
* @param string description of right
* @return mixed integer (right_id) or MDB2 Error object
function addRight($areaId, $define_name = null , $right_name = null ,
$right_description = null )
$rightId = $this->dbc->nextId ($this->prefix . 'rights', true );
if (MDB2 ::isError ($rightId)) {
(right_id, area_id, right_define_name)
' . $this->dbc->quote ($rightId, 'integer') . ',
' . $this->dbc->quote ($areaId, 'integer') . ',
' . $this->dbc->quote ((is_null($define_name) ? $define_name : $rightId), 'text') . '
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// Insert Right translation into Translations table
if (MDB2 ::isError ($result)) {
* @param integer id of right
* @return boolean true on success or false on failure
' . $this->prefix . 'userrights
right_id = ' . $this->dbc->quote ($rightId, 'integer');
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// Delete right translations
if (MDB2 ::isError ($result)) {
right_id = ' . $this->dbc->quote ($rightId, 'integer');
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
* @param integer id of right
* @param integer id of area
* @param string name of right constant
* @param string name of right
* @param string description of right
* @return mixed boolean or MDB2 Error object
function updateRight($rightId, $areaId, $define_name = null ,
$right_name = null , $right_description = null )
area_id = ' . $this->dbc->quote ($areaId, 'integer') . ',
right_define_name = ' . $this->dbc->quote ((is_null($define_name) ? $define_name : $areaId), 'text') . '
right_id = ' . $this->dbc->quote ($rightId, 'integer');
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// Update Right translation into Translations table
if (MDB2 ::isError ($result)) {
* @param string $authId Auth user ID of the user that should be added.
* @param string $authname Auth container name.
* @param int $type User type (constants defined in Perm/Common.php) (optional).
* @param mixed $permId If specificed no new ID will be automatically generated instead
* @return mixed string (perm_user_id) or MDB2 Error object
function addUser($authId, $authName, $type = LIVEUSER_USER_TYPE_ID , $permId = null )
$permId = $this->dbc->nextId ($this->prefix . 'perm_users', true );
' . $this->prefix . 'perm_users
(perm_user_id, auth_user_id, perm_type, auth_container_name)
' . $this->dbc->quote ($permId, 'integer') . ',
' . $this->dbc->quote ($authId, 'text') . ',
' . $this->dbc->quote ($type, 'integer') . ',
' . $this->dbc->quote ($authName, 'text') . '
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
* Updates auth_user_id in the mapping table.
* @param int perm_user_id of the user
* @param mixed new Auth user ID
* @param mixed new Auth Container name
* @param mixed new perm type
* @return mixed true or MDB2 Error object or false if there was an error
function updateUser($permId, $authId = false , $authName = false , $type = false )
$update[] = ' auth_user_id=' . $this->dbc->quote ($authId, 'text');
if ($authName !== false ) {
$update[] = ' auth_container_name=' . $this->dbc->quote ($authName, 'text');
$update[] = ' perm_type=' . $this->dbc->quote ($type, 'text');
' . $this->prefix . 'perm_users
perm_user_id=' . $this->dbc->quote ($permId, 'integer');
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
* @param string id of user
* @return mixed boolean or MDB2 Error object
// Delete group assignments
' . $this->prefix . 'groupusers
perm_user_id = ' . $permId;
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// Delete right assignments
' . $this->prefix . 'userrights
perm_user_id = ' . $permId;
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
// remove user area admin relation
if (MDB2 ::isError ($result)) {
// Delete user from perm table (Perm/MDB2)
' . $this->prefix . 'perm_users
perm_user_id = ' . $permId;
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
* @param string id of user
* @param integer id of right
* @return mixed boolean or MDB2 Error object
//return if this user already has right
' . $this->prefix . 'userrights
perm_user_id = ' . $this->dbc->quote ($rightId, 'integer') . '
right_id = ' . $this->dbc->quote ($rightId, 'integer');
$count = $this->dbc->queryOne ($query);
if (MDB2 ::isError ($count) || $count != 0 ) {
' . $this->prefix . 'userrights
(perm_user_id, right_id, right_level)
' . $this->dbc->quote ($permId, 'integer') . ',
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
* Update right level of userRight
* @param string id of user
* @param integer id of right
* @param integer right level
* @return mixed boolean or MDB2 Error object
' . $this->prefix . 'userrights
right_level = ' . $this->dbc->quote ($right_level, 'integer') . '
perm_user_id = ' . $this->dbc->quote ($permId, 'integer') . '
right_id = ' . $this->dbc->quote ($rightId, 'integer');
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
* @param string id of user
* @param integer id of right
* @return mixed boolean or MDB2 Error object
' . $this->prefix . 'userrights
perm_user_id = ' . $this->dbc->quote ($permId, 'integer');
right_id = ' . $this->dbc->quote ($rightId, 'integer');
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
* Get list of all applications
* This method accepts the following options...
* 'where_application_id' = [APPLICATION_ID]
* @param array an array determining which fields and conditions to use
* @return mixed array or MDB2 Error object
applications.application_id AS application_id,
applications.application_define_name AS define_name,
translations.name AS name,
translations.description AS description
' . $this->prefix . 'applications applications,
' . $this->prefix . 'translations translations
if (isset ($options['where_application_id'])
&& is_numeric($options['where_application_id'])) {
$query .= ' applications.application_id = '
. $this->dbc->quote ($options['where_application_id'], 'integer') . ' AND ';
$query .= ' applications.application_id = translations.section_id AND
translations.section_type = '
translations.language_id = '
applications.application_id ASC';
$applications = $this->dbc->queryAll ($query, null , MDB2_FETCHMODE_ASSOC );
if (MDB2 ::isError ($applications)) {
* Get list of all areas within a given application
* This method accepts the following options...
* 'where_area_id' = [AREA_ID],
* 'where_application_id' = [APPLICATION_ID],
* 'with_applications' = [BOOLEAN]
* @param array an array determining which fields and conditions to use
* @return mixed array or MDB2 Error object
areas.area_id AS area_id,
areas.application_id AS application_id,
translations.name AS name,
translations.description AS description,
areas.area_define_name AS define_name
' . $this->prefix . 'areas areas,
' . $this->prefix . 'translations translations
if (isset ($options['where_area_id'])
$query .= ' areas.area_id=' . $this->dbc->quote ($options['where_area_id'], 'integer') . ' AND';
if (isset ($options['where_application_id'])
&& is_numeric($options['where_application_id'])) {
$query .= ' areas.application_id=' . $this->dbc->quote ($options['where_application_id'], 'integer') . ' AND';
$query .= ' areas.area_id = translations.section_id AND
translations.language_id = ' . $this->dbc->quote ($this->_langs[$this->getCurrentLanguage()], 'integer') . '
$areas = $this->dbc->queryAll ($query, null , MDB2_FETCHMODE_ASSOC );
if (MDB2 ::isError ($areas)) {
foreach($areas as $key => $value) {
if (isset ($options['with_applications'])) {
if (MDB2 ::isError ($_areas[$id]['application'])) {
return $_areas[$id]['application'];
* Get list of all languages
* This method accepts the following options...
* 'where_language_id' = [LANGUAGE_ID],
* 'with_translations' = [BOOLEAN]
* @param array an array determining which fields and conditions to use
* @return mixed array or MDB2 Error object
languages.language_id AS language_id,
languages.two_letter_name AS two_letter_code
' . $this->prefix . 'languages languages';
if (isset ($options['where_language_id'])
$query .= ' WHERE languages.language_id = ' . $this->dbc->quote ($options['where_language_id'], 'integer');
$langs = $this->dbc->queryAll ($query, null , MDB2_FETCHMODE_ASSOC );
if (MDB2 ::isError ($langs)) {
if (isset ($options['with_translations'])
&& $options['with_translations']
translations.section_id AS section_id,
translations.language_id AS language_id,
languages.two_letter_name AS two_letter_code,
translations.name AS name
' . $this->prefix . 'languages languages,
' . $this->prefix . 'translations translations
languages.language_id = translations.language_id
$trans = $this->dbc->queryAll ($query, null , MDB2_FETCHMODE_ASSOC );
if (MDB2 ::isError ($trans)) {
foreach($langs as $key => $value) {
$code = $value['two_letter_code'];
unset ($value['two_letter_code']);
if ($options['with_translations'] == true && is_array($trans)) {
foreach($trans as $translation) {
if ($translation['section_id'] == $value['language_id']) {
$langs[$code]['name'] = $translation['name'];
* This method accepts the following options...
* 'where_user_id' = [AUTH_USER_ID],
* 'where_group_id' = [GROUP_ID],
* 'where_right_id' = [RIGHT_ID],
* 'where_area_id' = [AREA_ID],
* 'where_application_id' = [APPLICATION_ID],
* 'with_areas' = [BOOLEAN],
* 'with_applications' = [BOOLEAN]
* @param array an array determining which fields and conditions to use
* @return mixed array or MDB2 Error object
$types = array ('integer', 'integer', 'integer', 'text', 'boolean', 'boolean', 'boolean', 'text', 'text');
rights.right_id AS right_id,
rights.area_id AS area_id,
areas.application_id AS application_id,
rights.right_define_name AS define_name,
rights.has_implied AS has_implied,
rights.has_level AS has_level,
rights.has_scope AS has_scope,
translations.name AS name,
translations.description AS description';
if (isset ($options['where_user_id'])) {
$query .= ', userrights.perm_user_id AS user_id';
} else if (isset ($options['where_group_id'])
$query .= ', grouprights.group_id AS group_id';
' . $this->prefix . 'rights rights,
' . $this->prefix . 'areas areas,
' . $this->prefix . 'applications applications,';
if (isset ($options['where_user_id'])) {
$query .= ' ' . $this->prefix . 'userrights userrights,';
if (isset ($options['where_group_id'])
$query .= ' ' . $this->prefix . 'grouprights grouprights,';
$query .= ' ' . $this->prefix . 'translations translations
if (isset ($options['where_right_id'])
$query .= ' rights.right_id = '
. $this->dbc->quote ($options['where_right_id'], 'integer') . ' AND';
if (isset ($options['where_area_id'])
$query .= ' rights.area_id = '
. $this->dbc->quote ($options['where_area_id'], 'integer') . ' AND';
if (isset ($options['where_application_id'])
&& is_numeric($options['where_application_id'])) {
$query .= ' areas.application_id = '
. $this->dbc->quote ($options['where_application_id'], 'integer') . ' AND';
if (isset ($options['where_user_id'])) {
$query .= ' userrights.perm_user_id = '
. $this->dbc->quote ($options['where_user_id'], 'integer') . ' AND
userrights.right_id = rights.right_id AND';
if (isset ($options['where_group_id'])
$query .= ' grouprights.' . $this->groupTableCols['required']['group_id']['name'] . ' = '
. $this->dbc->quote ($options['where_group_id'], 'integer') . ' AND
grouprights.right_id = rights.right_id AND';
$query .= ' rights.area_id = areas.area_id AND
rights.right_id = translations.section_id AND
translations.language_id = '
rights.right_id, rights.area_id, areas.application_id';
if (isset ($options['where_user_id'])) {
$query .= ',userrights.perm_user_id';
if (isset ($options['where_group_id'])
$query .= ',grouprights.group_id';
,rights.right_define_name, rights.has_implied,
rights.has_level, rights.has_scope,
translations.name, translations.description
$rights = $this->dbc->queryAll ($query, $types, MDB2_FETCHMODE_ASSOC );
if (MDB2 ::isError ($rights)) {
foreach($rights as $key => $value)
$id = $value['right_id'];
if (isset ($options['with_areas'])) {
$filter = array ('where_area_id' => $value['area_id']);
if (MDB2 ::isError ($_rights[$id]['area'])) {
return $_rights[$id]['area'];
if (isset ($options['with_applications'])) {
$filter = array ('where_application_id' => $value['application_id']);
$_rights[$id]['application'] =
if (MDB2 ::isError ($_rights[$id]['application'])) {
return $_rights[$id]['application'];
* Make a user an admin of a given area.
* @param mixed user identifier
* @param int area identifier
* @return mixed true on success, MDB2 Error object or false
' . $this->prefix . 'area_admin_areas
' . $permId . ', ' . $this->dbc->quote ($areaId, 'integer') . '
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
* Remove the privilege of being an admin.
* If no area_id is provided the user will be removed asan admin
* from all areas he was an admin for.
* @param mixed user identifier
* @param int area identifier
* @return mixed true on success, MDB2 Error object or false
' . $this->prefix . 'area_admin_areas
perm_user_id=' . $permId;
area_id= ' . $this->dbc->quote ($areaId, 'integer');
$result = $this->dbc->query ($query);
if (MDB2 ::isError ($result)) {
* Fetch users from the database.
* The only supported filter is perm_user_id => 'value'
* The array will look like this:
* $userData[0]['perm_user_id'] = 1;
* ['rights'] = array(); // the array returned by getRights()
* @param array filters to apply to fetched data
* @param boolean If true the rights for each user will be retrieved.
* @param boolean will return an associative array with the auth_user_id
* as the key by using the $rekey param in MDB2::fetchAll()
* @return mixed Array with user data or error object.
* @see LiveUser_Admin_Perm_DB_Common::getRights()
function getUsers($filters = array (), $options = array (), $rekey = false )
users.perm_user_id AS perm_user_id,
users.auth_user_id AS auth_user_id,
users.auth_container_name AS container
' . $this->prefix . 'perm_users users';
if (isset ($filters['group_id'])) {
$query .= ', ' . $this->prefix . 'groupusers groupusers';
if (isset ($filters['group_id'])) {
$filter_array[] = 'groupusers.perm_user_id=users.perm_user_id';
$filter_array[] = 'groupusers.group_id IN (' . $this->dbc->datatype ->implodeArray ($filters['group_id'], 'integer') . ')';
if (isset ($filters['perm_user_id'])) {
$filter_array[] = 'users.perm_user_id=' . $filters['perm_user_id'];
if (isset ($filter_array) && count($filter_array)) {
$query .= ' WHERE '. implode(' AND ', $filter_array);
$types = array ('integer', 'text', 'integer', 'text');
$res = $this->dbc->queryAll ($query, $types, MDB2_FETCHMODE_ASSOC , $rekey);
foreach ($res as $k => $v) {
if (isset ($options['with_rights'])) {
$res[$k]['rights'] = $this->getRights(array ('where_user_id' => $v['perm_user_id']));
if (isset ($options['with_groups'])) {
$res[$k]['groups'] = $this->getGroups (array ('where_user_id' => $v['perm_user_id']));
} else if (!MDB2 ::isError ($res)) {
Documentation generated on Mon, 11 Mar 2019 13:56:18 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|