[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/user/modules/ -> login.anakin.class.php (source)

   1  <?php
   2  /* Copyright (c) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (c) 2002-2003 Jean-Louis Bergamo   <jlb@j1b.org>
   4   * Copyright (c) 2004-2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   5   * Copyright (C) 2004      Sebastien Di Cintio  <sdicintio@ressource-toi.org>
   6   * Copyright (C) 2004      Benoit Mortier       <benoit.mortier@opensides.be>
   7   * 
   8   * This program is free software; you can redistribute it and/or modify
   9   * it under the terms of the GNU General Public License as published by
  10   * the Free Software Foundation; either version 2 of the License, or
  11   * (at your option) any later version.
  12   *
  13   * This program is distributed in the hope that it will be useful,
  14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16   * GNU General Public License for more details.
  17   *
  18   * You should have received a copy of the GNU General Public License
  19   * along with this program; if not, write to the Free Software
  20   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21   *
  22   * $Id: login.anakin.class.php,v 1.2 2005/07/10 20:51:13 eldy Exp $
  23   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/user/modules/login.anakin.class.php,v $
  24   */
  25  
  26  /**
  27          \file       htdocs/user/modules/login.anakin.class.php
  28            \brief      Fichier de la classe de génération de login anakin
  29            \author     Rodolphe Qiedeville
  30            \version    $Revision: 1.2 $
  31  */
  32  
  33  
  34  /**
  35          \class      LoginAnakin
  36          \brief      Classe permettant la génération de login anakin
  37  */
  38  
  39  class LoginAnakin
  40  {
  41    var $db;
  42    var $user;
  43  
  44    /**
  45     *    \brief      Constructeur de la classe
  46     *    \param      $DB         Handler accès base de données
  47     *    \param      $user       Objet de l'utilisateur
  48     */
  49    function LoginAnakin($DB, $user)
  50      {
  51        $this->db = $DB;
  52        $this->user = $user;
  53  
  54        return 0;
  55    }
  56  
  57  
  58    function generate_login()
  59    {
  60      $ok = 0;
  61      $step = 1;
  62      $this->else_step = 1;
  63  
  64      while ($ok == 0)
  65        {
  66      $func = 'generate_login_'.$step;
  67  
  68      if (method_exists($this, $func))
  69        {
  70          $this->$func();
  71        }
  72      else
  73        {
  74          $this->generate_login_else();
  75          $this->else_step++;
  76        }
  77  
  78      $ok = $this->dispo();
  79      $step++;
  80        }
  81      
  82      return 0;
  83  
  84    }
  85  
  86    /**
  87     *    \brief      Vérifie la disponibilité du login
  88     *    \return     1 si le login n'existe pas dans la base, 1 sinon
  89     */
  90    function dispo()
  91    {
  92      $sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='".$this->login."';";
  93  
  94      $resql=$this->db->query($sql);
  95  
  96      if ($resql)
  97        {
  98      $num = $this->db->num_rows($resql);
  99        }
 100  
 101      if ($num == 0)
 102        {
 103      return 1;
 104        }
 105      else
 106        {
 107      return 0;
 108        }
 109  
 110    }
 111  
 112  
 113    // Règle primaire
 114    // 8 premières lettre désaccentuées du nom en minuscule
 115    function generate_login_1()
 116    {
 117      $nom = unaccent(strtolower($this->user->nom));
 118      
 119      $this->login = substr($nom, 0, 8);
 120    }
 121  
 122  
 123    // Règle de défaut
 124    function generate_login_else()
 125    {
 126      $login = unaccent(strtolower($this->user->nom));
 127  
 128      $le = strlen($this->else_step);
 129  
 130      $this->login = substr($login, 0, (8-$le)) . $this->else_step;
 131    }
 132  
 133  
 134    // Règles annexes
 135    // première lettre du prénom + 7 premières lettres du nom, désaccentuées en minuscule
 136    function generate_login_2()
 137    {
 138      $nom = unaccent(strtolower($this->user->nom));
 139      $prenom = unaccent(strtolower($this->user->prenom));
 140      
 141      $this->login = substr($prenom, 0, 1) . substr($nom, 0, 7);
 142    }
 143  
 144  
 145    // 2 premières lettres du prénom + 6 premières lettres du nom, désaccentuées en minuscule
 146    function generate_login_3()
 147    {
 148      $nom = unaccent(strtolower($this->user->nom));
 149      $prenom = unaccent(strtolower($this->user->prenom));
 150      
 151      $this->login = substr($prenom, 0, 2) . substr($nom, 0, 6);
 152    }
 153  
 154  }
 155  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics