phpDocumentor lodel-logic
[ class tree: lodel-logic ] [ index: lodel-logic ] [ all elements ]

Source for file class.restricted_users.php

Documentation is available at class.restricted_users.php

  1. <?php
  2. /**    
  3.  * Logique des utilisateurs restreints
  4.  *
  5.  * PHP versions 4 et 5
  6.  *
  7.  * LODEL - Logiciel d'Edition ELectronique.
  8.  *
  9.  * Home page: http://www.lodel.org
  10.  * E-Mail: lodel@lodel.org
  11.  *
  12.  * All Rights Reserved
  13.  *
  14.  * This program is free software; you can redistribute it and/or modify
  15.  * it under the terms of the GNU General Public License as published by
  16.  * the Free Software Foundation; either version 2 of the License, or
  17.  * (at your option) any later version.
  18.  *
  19.  * This program is distributed in the hope that it will be useful,
  20.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22.  * GNU General Public License for more details.
  23.  *
  24.  * You should have received a copy of the GNU General Public License
  25.  * along with this program; if not, write to the Free Software
  26.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27.  *
  28.  * @package lodel/logic
  29.  * @author Ghislain Picard
  30.  * @author Jean Lamy
  31.  * @author Pierre-Alain Mignot
  32.  * @copyright 2001-2002, Ghislain Picard, Marin Dacos
  33.  * @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  34.  * @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  35.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  36.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  37.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  38.  * @licence http://www.gnu.org/copyleft/gpl.html
  39.  * @since Fichier ajouté depuis la version 0.8
  40.  */
  41.  
  42.  
  43. /**
  44.  * Classe de logique des utilisateurs restreints
  45.  * 
  46.  * @package lodel/logic
  47.  * @author Ghislain Picard
  48.  * @author Jean Lamy
  49.  * @author Pierre-Alain Mignot
  50.  * @copyright 2001-2002, Ghislain Picard, Marin Dacos
  51.  * @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  52.  * @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  53.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  54.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  55.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  56.  * @licence http://www.gnu.org/copyleft/gpl.html
  57.  * @since Classe ajouté depuis la version 0.8
  58.  * @see logic.php
  59.  */
  60. class Restricted_UsersLogic extends Logic 
  61. {
  62.  
  63.     /** Constructor
  64.     */
  65.     function Restricted_UsersLogic({
  66.         $this->Logic('restricted_users');
  67.     }
  68.  
  69.     /**
  70.     *  Indique si un objet est protégé en suppression
  71.     *
  72.     * Cette méthode indique si un objet, identifié par son identifiant numérique et
  73.     * éventuellement son status, ne peut pas être supprimé. Dans le cas où un objet ne serait
  74.     * pas supprimable un message est retourné indiquant la cause. Sinon la méthode renvoit le
  75.     * booleen false.
  76.     *
  77.     * @param integer $id identifiant de l'objet
  78.     * @param integer $status status de l'objet
  79.     * @return false si l'objet n'est pas protégé en suppression, un message sinon
  80.     */
  81.     function isdeletelocked($id,$status=0
  82.     {
  83.         global $lodeluser;
  84.         if ($lodeluser['id']==$id && 
  85.     ( ($GLOBALS['site'&& $lodeluser['rights']<LEVEL_ADMINLODEL||
  86.         (!$GLOBALS['site'&& $lodeluser['rights']==LEVEL_ADMINLODEL))) {
  87.             return getlodeltextcontents("cannot_delete_current_user","common");
  88.         else {
  89.             return false;
  90.         }
  91.         //) { $error["error_has_entities"]=$count; return "_back"; }
  92.     }
  93.  
  94.  
  95.     /**
  96.      * Suppression du log des sessions d'un utilisateur
  97.      *
  98.      * Cette action permet de supprimer soit :
  99.      * - toutes les sessions d'un utilisateur, do=deletesession&lo=users&id=xx
  100.      * - une session particulière : do=deletesession&lo=users&session=xx
  101.      *
  102.      * @param array $context le contexte passé par référence
  103.      * @param array $error les erreur éventuelles par référence
  104.      */
  105.     function deletesessionAction(&$context&$error)
  106.     {
  107.         global $db;
  108.         require_once 'func.php';
  109.         $id intval($context['id']);
  110.         $session     intval($context['session']);
  111.         usemaindb()// les sessions sont stockés dans la base principale
  112.         $ids array();
  113.         if ($id//suppression de toutes les sessions
  114.             $result $db->execute(lq("SELECT id FROM #_MTP_session WHERE iduser='".$id."'")) or dberror();
  115.             while(!$result->EOF{
  116.                 $ids[$result->fields['id'];
  117.                 $result->MoveNext();
  118.             }
  119.         elseif ($session//suppression d'une session
  120.             $ids[$session;
  121.         else {
  122.             die ('ERROR: unknown operation');
  123.         }
  124.         
  125.         if ($ids{
  126.             $idstr join(','$ids);
  127.             // remove the session
  128.             $db->execute(lq("DELETE FROM #_MTP_session WHERE id IN ($idstr)")) or dberror();
  129.             // remove the url related to the session
  130.             $db->execute(lq("DELETE FROM #_MTP_urlstack WHERE idsession IN ($idstr)")) or dberror();
  131.         }
  132.  
  133.         usecurrentdb();
  134.         update();
  135.         return '_back';
  136.     }
  137.  
  138.     /**
  139.      * Permet de régler la langue ou le mode traduction d'un utilisateur
  140.      *
  141.      * Pour changer la langue d'un utilisateur : lo=users&do=set&lang=fr
  142.      * Pour changer le mode traduction : lo=users&do=set&translationmode=off
  143.      * @param array $context le contexte passé par référence
  144.      * @param array $error les erreur éventuelles par référence
  145.      */
  146.     function setAction(&$context&$error)
  147.     {
  148.         global $db;
  149.         $lang $context['lang'];
  150.         $translationmode $context['translationmode'];
  151.         if ($lang{
  152.             if (!preg_match("/^\w\w(-\w\w)?$/",$lang)) {
  153.                 die("ERROR: invalid lang");
  154.             }
  155.             $db->execute(lq("UPDATE #_TP_restricted_users SET lang='$lang'")) or dberror();
  156.             $this->_setcontext('lang''setvalue'$lang);
  157.         }
  158.  
  159.         if ($translationmode{
  160.             switch($translationmode{
  161.             case 'off':
  162.                 $this->_setcontext('translationmode''clear');
  163.                 break;
  164.             case 'site':
  165.             case 'interface':
  166.                 $this->_setcontext('translationmode''setvalue'$translationmode);
  167.                 break;
  168.             }
  169.         }
  170.  
  171.     update();
  172.     return '_back';
  173.     }
  174.  
  175.  
  176.  
  177.     /**
  178.         * make the select for this logic
  179.         */
  180.     function makeSelect(&$context,$var)
  181.  
  182.     {
  183.         switch($var{
  184.         case 'userrights':
  185.             require_once 'commonselect.php';
  186.             makeSelectUserRights($context['userrights'],!$GLOBALS['site'|| SINGLESITE);
  187.             break;
  188.         case "lang" :
  189.             // get the language available in the interface
  190.             
  191.             $dao=&getDAO("translations");
  192.             $list=$dao->findMany("status>0 AND textgroups='interface'","rank,lang","lang,title");
  193.             $arr=array();
  194.             foreach($list as $lang{
  195.             $arr[$lang->lang]=$lang->title;
  196.             }
  197.             if (!$arr$arr['fr']="Francais";
  198.             renderOptions($arr,$context['lang']);
  199.         }
  200.     }
  201.  
  202.     /*---------------------------------------------------------------*/
  203.     //! Private or protected from this point
  204.     /**
  205.         * @private
  206.         */
  207.     /**
  208.      *
  209.      *
  210.      */
  211.     function _setcontext($var$operation$value '')
  212.     {
  213.         global $db;
  214.         usemaindb();
  215.         $where "name='"addslashes($_COOKIE[$GLOBALS['sessionname']])"' AND iduser='"$GLOBALS['lodeluser']['id']"'";
  216.         $context $db->getOne(lq("SELECT context FROM $GLOBALS[tp]session WHERE ".$where));
  217.         if ($db->errorno()) {
  218.             dberror();
  219.         }
  220.         $arr unserialize($context);
  221.         switch ($operation{
  222.         case 'toggle' :
  223.             $arr[$var$arr[$var1// toggle
  224.             break;
  225.         case 'setvalue' :
  226.             $arr[$var$value;  // set
  227.             break;
  228.         case 'clear' :
  229.             unset($arr[$var]);  // clear
  230.             break;
  231.         }
  232.     
  233.         $db->execute(lq("UPDATE #_MTP_session SET context='"addslashes(serialize($arr))"' WHERE ".$where)) or dberror();
  234.         usecurrentdb();
  235.     }
  236.  
  237.     /**
  238.     * Préparation de l'action Edit
  239.     *
  240.     * @access private
  241.     * @param object $dao la DAO utilisée
  242.     * @param array &$context le context passé par référence
  243.     */
  244.     function _prepareEdit($dao,&$context
  245.     {
  246.         // encode the password
  247.         if ($context['passwd']$context['passwd']=md5($context['passwd'].$context['username']);
  248.     }
  249.  
  250.  
  251.  
  252.     function _populateContextRelatedTables(&$vo,&$context)
  253.  
  254.     {
  255.     /*    if ($vo->userrights<=LEVEL_EDITOR) {
  256.             $dao=&getDAO("users_usergroups");
  257.             $list=$dao->findMany("iduser='". $vo->id."'", "", "idgroup");
  258.             $context['usergroups']=array();
  259.             foreach($list as $relationobj) {
  260.                 $context['usergroups'][] = $relationobj->idgroup;
  261.             }
  262.         }
  263.     */
  264.     }
  265.     /**
  266.     * Sauve des données dans des tables liées éventuellement
  267.     *
  268.     * Appelé par editAction pour effectuer des opérations supplémentaires de sauvegarde.
  269.     *
  270.     * @param object $vo l'objet qui a été créé
  271.     * @param array $context le contexte
  272.     */
  273.     function _saveRelatedTables($vo,$context
  274.  
  275.     {/*
  276.         global $db;
  277.         if ($vo->userrights<=LEVEL_EDITOR) {
  278.             if (!$context['usergroups']) $context['usergroups']=array(1);
  279.  
  280.             // change the usergroups     
  281.             // first delete the group
  282.             $this->_deleteRelatedTables($vo->id);
  283.             // now add the usergroups
  284.             foreach ($context['usergroups'] as $usergroup) {
  285.     $usergroup=intval($usergroup);
  286.     $db->execute(lq("INSERT INTO #_TP_users_usergroups (idgroup, iduser) VALUES  ('$usergroup','$id')")) or dberror();
  287.             }
  288.         }*/
  289.     }
  290.  
  291.     function _deleteRelatedTables($id{/*
  292.         global $db;
  293.         if ($GLOBALS['site']) { // only in the site table
  294.             $db->execute(lq("DELETE FROM #_TP_users_usergroups WHERE iduser='$id'")) or dberror();
  295.         }*/
  296.     }
  297.  
  298.  
  299.     function validateFields(&$context,&$error{
  300.         global $db,$lodeluser;
  301.  
  302.         if (!Logic::validateFields($context,$error)) return false;
  303.  
  304.         // check the user has the right equal or higher to the new user
  305.         if ($lodeluser['rights']<$context['userrights']die("ERROR: You don't have the right to create a user with rights higher than yours");
  306.  
  307.         usecurrentdb();
  308.  
  309.         // check the passwd is given for new user.
  310.         if (!$context['id'&& !trim($context['passwd'])) {
  311.             $error['passwd']=1;
  312.             return false;
  313.         }
  314.  
  315.         if ($ret{
  316.             $error['username']="1"// report the error on the first field
  317.             return false;
  318.         else {
  319.             return true;
  320.         }
  321.     }
  322.  
  323.  
  324.     // begin{publicfields} automatic generation  //
  325.  
  326.     /**
  327.      * Retourne la liste des champs publics
  328.      * @access private
  329.      */
  330.     function _publicfields(
  331.     {
  332.         return array('username' => array('username''+'),
  333.                                     'passwd' => array('passwd'''),
  334.                                     'lastname' => array('text'''),
  335.                                     'firstname' => array('text'''),
  336.                                     'email' => array('email'''),
  337.                                     'expiration' => array('date''+'),
  338.                                     'lang' => array('lang''+'));
  339.     }
  340.     // end{publicfields} automatic generation  //
  341.  
  342.     // begin{uniquefields} automatic generation  //
  343.  
  344.     /**
  345.      * Retourne la liste des champs uniques
  346.      * @access private
  347.      */
  348.     function _uniqueFields(
  349.     
  350.         return array(array('username'));
  351.     }
  352.     // end{uniquefields} automatic generation  //
  353.  
  354. // class 
  355.  
  356.  
  357. /*-----------------------------------*/
  358. /* loops                             */
  359.  
  360. ?>

Documentation generated on Thu, 24 Jul 2008 05:08:05 +0200 by phpDocumentor 1.4.0a2