Source for file class.users.php
Documentation is available at class.users.php
* Logique des utilisateurs
* 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
* @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
* @version CVS:$Id: class.users.php 4361 2008-06-17 09:14:18Z cenou $
* Classe de logique des utilisateurs
* @author Ghislain Picard
* @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
* 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_users SET lang='$lang'")) or dberror();
switch($translationmode) {
$this->_setcontext('translationmode', 'setvalue', $translationmode);
* make the select for this logic
$list= $dao->findMany("status>0","rank,name","id,name");
foreach($list as $group) {
$arr[$group->id]= $group->name;
if (!$arr) $arr[1] = '--';
case 'gui_user_complexity' :
require_once 'commonselect.php';
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']);
$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 (!$context['usergroups']) $context['usergroups']= array(1);
// first delete the group
// 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 user is not duplicated in the main table...
if (!usemaindb()) return true; // use the main db, return if it is the same as the current one.
$ret= $db->getOne("SELECT 1 FROM ". lq("#_TP_". $this->maintable). " WHERE status>-64 AND id!='". $context['id']. "' AND username='". $context['username']. "'");
if ($db->errorno()) die($this->errormsg());
// 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', '+'),
'lang' => array('lang', '+'),
'userrights' => array('select', '+'),
'gui_user_complexity' => array('select', '+'),
'nickname' => array('text', ''),
'biography' => array('longtext', ''),
'photo' => array('image', ''),
'professional_website' => array('text', ''),
'url_professional_website' => array('url', ''),
'rss_professional_website' => array('url', ''),
'personal_website' => array('text', ''),
'url_personal_website' => array('url', ''),
'rss_personal_website' => array('url', ''),
'pgp_key' => array('longtext', ''),
'alternate_email' => array('email', ''),
'phonenumber' => array('text', ''),
'im_identifier' => array('text', ''),
'im_name' => array('text', ''));
// end{publicfields} automatic generation //
// begin{uniquefields} automatic generation //
* Retourne la liste des champs uniques
return array(array('username'), );
// end{uniquefields} automatic generation //
* Bloque un compte utilisateur tant que celui-ci n'a pas modifié son mot de passe
global $db, $id, $site, $lodeluser;
//on vérifie qu'on est bien administrateur
if($lodeluser['rights'] >= 40) {
$prefixe = ($site != '' && $site != "tous les sites") ? "#_TP_" : "#_MTP_";
$status = $db->getOne(lq("SELECT status FROM ". $prefixe. "users WHERE id = '". $id. "'"));
if($status != - 40 && $status != 32)
$db->execute(lq("UPDATE ". $prefixe. "users SET status = ". $stat. " WHERE id = '". $id. "'"));
die("ERROR : You don't have permissions to suspend this user. Contact your administrator.");
/*-----------------------------------*/
|