Source for file class.restricted_users.php
Documentation is available at class.restricted_users.php
* Logique des utilisateurs restreints
* LODEL - Logiciel d'Edition ELectronique.
* Home page: http://www.lodel.org
* E-Mail: lodel@lodel.org
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* @author Ghislain Picard
* @author Pierre-Alain Mignot
* @copyright 2001-2002, Ghislain Picard, Marin Dacos
* @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
* @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
* @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* @licence http://www.gnu.org/copyleft/gpl.html
* @since Fichier ajouté depuis la version 0.8
* Classe de logique des utilisateurs restreints
* @author Ghislain Picard
* @author Pierre-Alain Mignot
* @copyright 2001-2002, Ghislain Picard, Marin Dacos
* @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
* @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
* @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* @licence http://www.gnu.org/copyleft/gpl.html
* @since Classe ajouté depuis la version 0.8
$this->Logic('restricted_users');
* Indique si un objet est protégé en suppression
* Cette méthode indique si un objet, identifié par son identifiant numérique et
* éventuellement son status, ne peut pas être supprimé. Dans le cas où un objet ne serait
* pas supprimable un message est retourné indiquant la cause. Sinon la méthode renvoit le
* @param integer $id identifiant de l'objet
* @param integer $status status de l'objet
* @return false si l'objet n'est pas protégé en suppression, un message sinon
if ($lodeluser['id']== $id &&
//) { $error["error_has_entities"]=$count; return "_back"; }
* Suppression du log des sessions d'un utilisateur
* Cette action permet de supprimer soit :
* - toutes les sessions d'un utilisateur, do=deletesession&lo=users&id=xx
* - une session particulière : do=deletesession&lo=users&session=xx
* @param array $context le contexte passé par référence
* @param array $error les erreur éventuelles par référence
$session = intval($context['session']);
usemaindb(); // les sessions sont stockés dans la base principale
if ($id) { //suppression de toutes les sessions
$result = $db->execute(lq("SELECT id FROM #_MTP_session WHERE iduser='". $id. "'")) or dberror();
$ids[] = $result->fields['id'];
} elseif ($session) { //suppression d'une session
die ('ERROR: unknown operation');
$idstr = join(',', $ids);
$db->execute(lq("DELETE FROM #_MTP_session WHERE id IN ($idstr)")) or dberror();
// remove the url related to the session
$db->execute(lq("DELETE FROM #_MTP_urlstack WHERE idsession IN ($idstr)")) or dberror();
* Permet de régler la langue ou le mode traduction d'un utilisateur
* Pour changer la langue d'un utilisateur : lo=users&do=set&lang=fr
* Pour changer le mode traduction : lo=users&do=set&translationmode=off
* @param array $context le contexte passé par référence
* @param array $error les erreur éventuelles par référence
$lang = $context['lang'];
$translationmode = $context['translationmode'];
die("ERROR: invalid lang");
$db->execute(lq("UPDATE #_TP_restricted_users SET lang='$lang'")) or dberror();
switch($translationmode) {
$this->_setcontext('translationmode', 'setvalue', $translationmode);
* make the select for this logic
require_once 'commonselect.php';
// get the language available in the interface
$list= $dao->findMany("status>0 AND textgroups='interface'","rank,lang","lang,title");
foreach($list as $lang) {
$arr[$lang->lang]= $lang->title;
if (!$arr) $arr['fr']= "Francais";
/*---------------------------------------------------------------*/
//! Private or protected from this point
$where = "name='". addslashes($_COOKIE[$GLOBALS['sessionname']]). "' AND iduser='". $GLOBALS['lodeluser']['id']. "'";
$context = $db->getOne(lq("SELECT context FROM $GLOBALS[tp]session WHERE ". $where));
$arr[$var] = $arr[$var] ? 0 : 1; // toggle
$arr[$var] = $value; // set
unset ($arr[$var]); // clear
* Préparation de l'action Edit
* @param object $dao la DAO utilisée
* @param array &$context le context passé par référence
if ($context['passwd']) $context['passwd']= md5($context['passwd']. $context['username']);
/* if ($vo->userrights<=LEVEL_EDITOR) {
$dao=&getDAO("users_usergroups");
$list=$dao->findMany("iduser='". $vo->id."'", "", "idgroup");
$context['usergroups']=array();
foreach($list as $relationobj) {
$context['usergroups'][] = $relationobj->idgroup;
* Sauve des données dans des tables liées éventuellement
* Appelé par editAction pour effectuer des opérations supplémentaires de sauvegarde.
* @param object $vo l'objet qui a été créé
* @param array $context le contexte
if ($vo->userrights<=LEVEL_EDITOR) {
if (!$context['usergroups']) $context['usergroups']=array(1);
// first delete the group
$this->_deleteRelatedTables($vo->id);
// now add the usergroups
foreach ($context['usergroups'] as $usergroup) {
$usergroup=intval($usergroup);
$db->execute(lq("INSERT INTO #_TP_users_usergroups (idgroup, iduser) VALUES ('$usergroup','$id')")) or dberror();
if ($GLOBALS['site']) { // only in the site table
$db->execute(lq("DELETE FROM #_TP_users_usergroups WHERE iduser='$id'")) or dberror();
// check the user has the right equal or higher to the new user
if ($lodeluser['rights']< $context['userrights']) die("ERROR: You don't have the right to create a user with rights higher than yours");
// check the passwd is given for new user.
if (!$context['id'] && !trim($context['passwd'])) {
$error['username']= "1"; // report the error on the first field
// begin{publicfields} automatic generation //
* Retourne la liste des champs publics
return array('username' => array('username', '+'),
'passwd' => array('passwd', ''),
'lastname' => array('text', ''),
'firstname' => array('text', ''),
'email' => array('email', ''),
'expiration' => array('date', '+'),
'lang' => array('lang', '+'));
// end{publicfields} automatic generation //
// begin{uniquefields} automatic generation //
* Retourne la liste des champs uniques
return array(array('username'), );
// end{uniquefields} automatic generation //
/*-----------------------------------*/
|