From 367ae6f97f12736b002a9bed25015d0c716b6072 Mon Sep 17 00:00:00 2001 From: Pascal Corpet Date: Sat, 5 Feb 2005 12:35:58 +0000 Subject: [PATCH] gestion des accents pour le nomet le prenom git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-447 --- ChangeLog | 1 + include/profil/get_general.inc.php | 43 +++++++++++++++++++++++++++++++++-- include/profil/update_general.inc.php | 10 +++++--- include/profil/verif_general.inc.php | 21 +++++++++++++++++ templates/profil/general.tpl | 22 ++++++++++++++++-- 5 files changed, 90 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index d853949..7ec8528 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ New : * Profile : - One can choose precisely which fields appear on his public fiche. -Car + - Accents and special chars in name and first name -Car * Search : - Public searches display more information. -Car diff --git a/include/profil/get_general.inc.php b/include/profil/get_general.inc.php index 846dba4..547b482 100644 --- a/include/profil/get_general.inc.php +++ b/include/profil/get_general.inc.php @@ -20,7 +20,7 @@ ***************************************************************************/ // on ramène les données du profil connecté (uid paramètre de session) -$sql = "SELECT u.nom, u.prenom, u.promo, u.epouse, FIND_IN_SET('femme',u.flags), u.nationalite, +$sql = "SELECT u.nom, u.prenom, u.nom_ini, u.prenom_ini, u.promo, u.epouse, FIND_IN_SET('femme',u.flags), u.nationalite, q.profile_mobile, q.profile_mobile_pub, q.profile_web, q.profile_web_pub, q.profile_freetext, q.profile_freetext_pub, q.profile_nick, a1.aid, a1.type, a2.aid, a2.type FROM auth_user_md5 AS u @@ -30,13 +30,19 @@ $sql = "SELECT u.nom, u.prenom, u.promo, u.epouse, FIND_IN_SET('femme',u.flags) WHERE u.user_id = {?}"; $result = $globals->xdb->query($sql, Session::getInt('uid', -1)); -list($nom, $prenom, $promo, $epouse, $femme, $nationalite, +list($nom, $prenom, $nom_ini, $prenom_ini, $promo, $epouse, $femme, $nationalite, $mobile, $mobile_pub, $web, $web_pub, $freetext, $freetext_pub, $nickname, $appli_id1,$appli_type1, $appli_id2,$appli_type2) = $result->fetchOneRow(); $result = $globals->xdb->query("SELECT pub FROM photo WHERE uid = {?}", Session::getInt('uid', -1)); $photo_pub = $result->fetchOneCell(); +$nom_anc = $nom; +$prenom_anc = $prenom; +$nationalite_anc = $nationalite; + +replace_ifset($nom,'nom'); +replace_ifset($prenom,'prenom'); replace_ifset($nationalite,'nationalite'); replace_ifset($mobile,'mobile'); replace_ifset($web,"web"); @@ -54,7 +60,40 @@ if(Env::has('modifier') || Env::has('suivant')) { $photo_pub = Env::has('photo_pub')?'public':'private'; } + $accents_minuscules = "àáâãäåæçèéêëìíîïñòóôõöøùúûýÿ"; + $minuscules = "aaaaaaaceeeeiiiinoooooouuuyy"; + $accents_majuscules = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝ"; + $majuscules = "AAAAAAACEEEEIIIINOOOOOOUUUYY"; + + function strtoupper_accents($s) { + global $accents_minuscules, $accents_majuscules; + return strtr(strtoupper($s), $accents_minuscules, $accents_majuscules); + } + function strtolower_accents($s) { + global $accents_minuscules, $accents_majuscules; + return strtr(strtolower($s), $accents_majuscules, $accents_minuscules); + } + function no_accents($s) { + global $accents_minuscules, $accents_majuscules, $minuscules, $majuscules; + return strtr($s, $accents_minuscules.$accents_majuscules, $minuscules.$majuscules); + } + + $nom = strtoupper_accents($nom); + $nom_comp = no_accents($nom); + $nom_anc_comp = no_accents($nom_anc); + + $prenom = strtolower_accents($prenom); + $prenom_comp = no_accents($prenom); + $prenom_anc_comp = strtolower(no_accents($prenom_anc)); + $prenom_ini = strtolower($prenom_ini); + for ($i=-1;$i !== false;$i = strpos($prenom,'-',$i+1)) + $prenom{$i+1} = strtoupper_accents($prenom{$i+1}); + for ($i=0;($i = strpos($prenom,' ',$i))!==false;$i++) + $prenom{$i+1} = strtoupper_accents($prenom{$i+1}); + // Y a-t-il une photo en attente de confirmation ? $sql = $globals->xdb->query("SELECT COUNT(*) FROM requests WHERE type='photo' AND user_id = {?}", Session::getInt('uid', -1)); $nouvellephoto=$sql->fetchOneCell(); + +// vim:set et sws=4 sw=4 sts=4: ?> diff --git a/include/profil/update_general.inc.php b/include/profil/update_general.inc.php index f076dad..55adde5 100644 --- a/include/profil/update_general.inc.php +++ b/include/profil/update_general.inc.php @@ -29,9 +29,13 @@ if ($appli_id2>0) else $globals->xdb->execute("DELETE FROM applis_ins WHERE uid= {?} AND ordre=1", Session::getInt('uid', -1)); -$sql = "UPDATE auth_user_md5 - SET nationalite= {?} WHERE user_id= {?}"; -$globals->xdb->execute($sql, $nationalite, Session::getInt('uid', -1)); +if ($nationalite != $nationalite_anc || $nom != $nom_anc || $prenom != $prenom_anc) { + $sql = "UPDATE auth_user_md5 + SET nationalite= {?}, + nom = {?}, + prenom = {?} WHERE user_id= {?}"; + $globals->xdb->execute($sql, $nationalite, $nom, $prenom, Session::getInt('uid', -1)); +} $globals->xdb->execute( "UPDATE auth_user_quick SET profile_nick={?}, diff --git a/include/profil/verif_general.inc.php b/include/profil/verif_general.inc.php index 0df12c5..1097175 100644 --- a/include/profil/verif_general.inc.php +++ b/include/profil/verif_general.inc.php @@ -18,7 +18,27 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ + +function strmatch_whole_words($nouveau, $ancien) { + $nouveau = strtoupper($nouveau); + $ancien = strtoupper($ancien); + $len_nouveau = strlen($nouveau); + return (($i = strpos($ancien, $nouveau)) !== false && ($i == 0 || $ancien{$i-1} == ' ' || $ancien{$i-1} == '-') && ($i + $len_nouveau == strlen($ancien) || $ancien{$i + $len_nouveau} == ' ' || $ancien{$i+$len_nouveau} == '-')); +} + +// validite du nom +if ($nom != $nom_anc && + !strmatch_whole_words($nom_comp, $nom_anc_comp) && + ($nom_anc_comp == $nom_ini || !strmatch_whole_words($nom_comp, $nom_ini))) { + $page->trig("Le nom que tu as choisi ($nom) est trop loin de ton nom initial ($nom_ini)".(($nom_ini==$nom_anc_comp)?"":" et de ton nom précédent ($nom_anc)")); +} +// validite du prenom +if ($prenom != $prenom_anc && + !strmatch_whole_words($prenom_comp, $prenom_anc_comp) && + ($prenom_anc_comp == $prenom_ini || !strmatch_whole_words($prenom_comp, $prenom_ini))) { + $page->trig("Le prénom que tu as choisi ($prenom) est trop loin de ton prénom initial ($prenom_ini)".(($prenom_ini==$prenom_anc_comp)?"":" et de ton prénom précédent ($prenom_anc)")); +} // validité du mobile if (strlen(strtok($mobile,"<>{}@&#~\/:;?,!§*_`[]|%$^=")) < strlen($mobile)) { @@ -42,4 +62,5 @@ if (strlen(strtok($freetext,"<>")) < strlen($freetext)) $page->trig("Le champ 'Complément libre' contient un caractère interdit."); } +// vim:set et sws=4 sts=4 sw=4: ?> diff --git a/templates/profil/general.tpl b/templates/profil/general.tpl index 33b439e..7f75266 100644 --- a/templates/profil/general.tpl +++ b/templates/profil/general.tpl @@ -44,10 +44,28 @@ - Identité + Nom + - {$prenom} {$nom} X{$promo} + + + + + + Prénom + + + + + + + + + Promotion + + + X{$promo} {if $femme} -- 2.1.4