first reimport from platal
[platal.git] / include / profil / verif_general.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2004 Polytechnique.org *
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))) {
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)"));
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))) {
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)"));
41 }
42
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.");
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)) {
52 // validité de l'url donnée dans web
53 $page->trig("URL incorrecte dans le champ 'Page web perso', une url doit commencer par
54 http:// ou https:// ou ftp:// et ne pas contenir de caractères interdits");
55 } else {
56 $web = str_replace('&', '&amp;', $web);
57 }
58
59 //validité du champ libre
60 if (strlen(strtok($freetext,"<>")) < strlen($freetext))
61 {
62 $page->trig("Le champ 'Complément libre' contient un caractère interdit.");
63 }
64
65 // vim:set et sws=4 sts=4 sw=4:
66 ?>