0337d704 |
1 | <?php |
2 | /*************************************************************************** |
5ddeb07c |
3 | * Copyright (C) 2003-2007 Polytechnique.org * |
0337d704 |
4 | * http://opensource.polytechnique.org/ * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * |
10 | * * |
11 | * This program is distributed in the hope that it will be useful, * |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 | * GNU General Public License for more details. * |
15 | * * |
16 | * You should have received a copy of the GNU General Public License * |
17 | * along with this program; if not, write to the Free Software * |
18 | * Foundation, Inc., * |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
20 | ***************************************************************************/ |
21 | |
22 | function strmatch_whole_words($nouveau, $ancien) { |
23 | $nouveau = strtoupper($nouveau); |
24 | $ancien = strtoupper($ancien); |
25 | $len_nouveau = strlen($nouveau); |
26 | 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} == '-')); |
27 | } |
28 | |
29 | // validite du nom |
30 | if ($nom != $nom_anc && |
31 | !strmatch_whole_words($nom_comp, $nom_anc_comp) && |
32 | ($nom_anc_comp == $nom_ini || !strmatch_whole_words($nom_comp, $nom_ini))) { |
a7de4ef7 |
33 | $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)")); |
0337d704 |
34 | } |
35 | |
36 | // validite du prenom |
37 | if ($prenom != $prenom_anc && |
38 | !strmatch_whole_words($prenom_comp, $prenom_anc_comp) && |
39 | ($prenom_anc_comp == $prenom_ini || !strmatch_whole_words($prenom_comp, $prenom_ini))) { |
a7de4ef7 |
40 | $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)")); |
0337d704 |
41 | } |
42 | |
a7de4ef7 |
43 | // validité du mobile |
44 | if (strlen(strtok($mobile,"<>{}@&#~\/:;?,!§*_`[]|%$^=")) < strlen($mobile)) { |
45 | $page->trig("Le champ 'Téléphone mobile' contient un caractère interdit."); |
0337d704 |
46 | } |
47 | |
48 | // correction du champ web si vide |
49 | if ($web=="http://" or $web == '') { |
50 | $web=''; |
51 | } elseif (!preg_match("{^(https?|ftp)://[a-zA-Z0-9._%#+/?=&~-]+$}i", $web)) { |
a7de4ef7 |
52 | // validité de l'url donnée dans web |
0337d704 |
53 | $page->trig("URL incorrecte dans le champ 'Page web perso', une url doit commencer par |
a7de4ef7 |
54 | http:// ou https:// ou ftp:// et ne pas contenir de caractères interdits"); |
0337d704 |
55 | } else { |
56 | $web = str_replace('&', '&', $web); |
57 | } |
58 | |
a7de4ef7 |
59 | //validité du champ libre |
0337d704 |
60 | if (strlen(strtok($freetext,"<>")) < strlen($freetext)) |
61 | { |
a7de4ef7 |
62 | $page->trig("Le champ 'Complément libre' contient un caractère interdit."); |
0337d704 |
63 | } |
64 | |
a7de4ef7 |
65 | // vim:set et sws=4 sts=4 sw=4 enc=utf-8: |
0337d704 |
66 | ?> |