Fix: Fonction de conversion des accents plus propre

This commit is contained in:
Laurent Destailleur 2007-11-29 01:19:23 +00:00
parent 802c37c75c
commit 017a7fabcd
2 changed files with 366 additions and 342 deletions

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
* Copyright (c) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (c) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
@ -20,136 +20,141 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* *
* $Id$ * $Id$
* $Source$
*/ */
/** /**
\file htdocs/user/modules/login.anakin.class.php \file htdocs/user/modules/login.anakin.class.php
\brief Fichier de la classe de génération de login anakin \brief Fichier de la classe de generation de login anakin
\author Rodolphe Qiedeville \author Rodolphe Qiedeville
\version $Revision$ \version $Revision$
*/ */
/** /**
\class LoginAnakin \class LoginAnakin
\brief Classe permettant la génération de login anakin \brief Classe permettant la generation de login anakin
*/ */
class LoginAnakin class LoginAnakin
{ {
var $db; var $error;
var $user; var $db;
var $user;
/** var $login;
* \brief Constructeur de la classe
* \param $DB Handler accès base de données
* \param $user Objet de l'utilisateur
*/
function LoginAnakin($DB, $user)
{
$this->db = $DB;
$this->user = $user;
return 0;
} /**
* \brief Constructeur de la classe
* \param $DB Handler acces base de donnees
* \param $user Objet de l'utilisateur
*/
function LoginAnakin($DB, $user)
{
$this->db = $DB;
$this->user = $user;
return 0;
}
function generate_login() /**
{ * \brief Verifie la disponibilite du login
$ok = 0; * \return 1 si le login n'existe pas dans la base, 1 sinon
$step = 1; */
$this->else_step = 1; function dispo()
{
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='".$this->login."';";
while ($ok == 0) $resql=$this->db->query($sql);
{
$func = 'generate_login_'.$step;
if (method_exists($this, $func)) if ($resql)
{ {
$this->$func(); $num = $this->db->num_rows($resql);
} }
else
{
$this->generate_login_else();
$this->else_step++;
}
$ok = $this->dispo(); if ($num == 0)
$step++; {
} return 1;
}
return 0; else
{
return 0;
}
} }
/** /**
* \brief Vérifie la disponibilité du login * \brief Genere un login depuis nom
* \return 1 si le login n'existe pas dans la base, 1 sinon * Ce login est stocke dans ->login
*/ */
function dispo() function generate_login()
{ {
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='".$this->login."';"; $ok = 0;
$step = 1;
$this->else_step = 1;
$resql=$this->db->query($sql); while ($ok == 0)
{
$func = 'generate_login_'.$step;
if ($resql) if (method_exists($this, $func))
{ {
$num = $this->db->num_rows($resql); $this->$func();
} }
else
{
$this->generate_login_else();
$this->else_step++;
}
if ($num == 0) $ok = $this->dispo();
{ $step++;
return 1; }
}
else
{
return 0;
}
} return 0;
}
// Regle primaire
// 8 premieres lettre desaccentuees du nom en minuscule
function generate_login_1()
{
$nom = strtolower(unaccent_isostring(sanitize_string($this->user->nom)));
$this->login = substr($nom, 0, 8);
}
// Règle primaire // Regle de defaut
// 8 premières lettre désaccentuées du nom en minuscule function generate_login_else()
function generate_login_1() {
{ $login = strtolower(unaccent_isostring(sanitize_string($this->user->nom)));
$nom = unaccent(strtolower($this->user->nom));
$le = strlen($this->else_step);
$this->login = substr($nom, 0, 8);
} $this->login = substr($login, 0, (8-$le)) . $this->else_step;
}
// Règle de défaut // Regles annexes
function generate_login_else() // premiere lettre du prenom + 7 premieres lettres du nom, desaccentuees en minuscule
{ function generate_login_2()
$login = unaccent(strtolower($this->user->nom)); {
$nom = strtolower(unaccent_isostring(sanitize_string($this->user->nom)));
$prenom = strtolower(unaccent_isostring(sanitize_string($this->user->prenom)));
$le = strlen($this->else_step); $this->login = substr($prenom, 0, 1) . substr($nom, 0, 7);
}
$this->login = substr($login, 0, (8-$le)) . $this->else_step;
}
// Règles annexes // 2 premieres lettres du prenom + 6 premieres lettres du nom, desaccentuees en minuscule
// première lettre du prénom + 7 premières lettres du nom, désaccentuées en minuscule function generate_login_3()
function generate_login_2() {
{ $nom = strtolower(unaccent_isostring(sanitize_string($this->user->nom)));
$nom = unaccent(strtolower($this->user->nom)); $prenom = strtolower(unaccent_isostring(sanitize_string($this->user->prenom)));
$prenom = unaccent(strtolower($this->user->prenom));
$this->login = substr($prenom, 0, 1) . substr($nom, 0, 7);
}
$this->login = substr($prenom, 0, 2) . substr($nom, 0, 6);
// 2 premières lettres du prénom + 6 premières lettres du nom, désaccentuées en minuscule }
function generate_login_3()
{
$nom = unaccent(strtolower($this->user->nom));
$prenom = unaccent(strtolower($this->user->prenom));
$this->login = substr($prenom, 0, 2) . substr($nom, 0, 6);
}
} }
?> ?>