05d12086eec691833488b6af7cba69ee453286e8
2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
24 function generate_new_adrid(){
26 if(!isset($adresses)) //aucune adresses => retourne 1
30 $adrid_array = Array();
31 foreach($adresses as $numero => $adr){
32 $adrid_array[$i] = $numero;
35 sort($adrid_array,SORT_NUMERIC
); // classe les adrid dans l'ordre croissant
37 while(list($key,$current_adrid) = each($adrid_array)){
38 if($current_adrid == $new_adrid)
41 return $new_adrid; //s'ils sont differents, il y a un trou dans la liste des adrid donc new_adrid convient
43 //si aucun convient, on retourne le plus grand des adrid actuel + 1
47 function generate_new_telid($adr){
49 $telid_array = Array();
50 foreach($adr['tels'] as $tel){
51 $telid_array[$i] = $tel['telid'];
54 sort($telid_array,SORT_NUMERIC
); // classe les adrid dans l'ordre croissant
56 foreach($telid_array as $current_telid)
57 if ($current_telid == $new_telid)
60 return $new_telid;//s'ils sont differents, il y a un trou dans la liste des telid donc new_telid convient
61 //si aucun convient, on retourne le plus grand des telid actuel + 1
65 function replace_ifset_adr($varname, $i){
66 $tab = Env
::v($varname, Array());
68 $GLOBALS['adresses'][$i][$varname] = $tab[$i];
71 function replace_ifset_tel($varname, $i, $t){
72 $tab = Env
::v($varname.$t, Array());
74 $GLOBALS['adresses'][$i]['tels'][$t][$varname] = $tab[$i];
77 function get_adr_arg($varname, $i) {
78 $tab = Env
::v($varname, Array());
82 function set_flag_adr($varname,$i){
83 $tab = Env
::v($varname, Array());
85 $GLOBALS['adresses'][$i][$varname] = 1;
88 $GLOBALS['adresses'][$i][$varname] = '0';
91 function replace_tel($i, $t){
92 replace_ifset_tel('telid', $i, $t);
93 replace_ifset_tel('tel', $i, $t);
94 replace_ifset_tel('tel_pub', $i, $t);
95 replace_ifset_tel('tel_type', $i, $t);
96 replace_ifset_tel('new_tel', $i, $t);
99 function replace_address($i){
100 global $adresses, $nb_tel_max;
101 if(!isset($adresses[$i])){
102 $adresses[$i]['nouvelle'] = 'ajout';
103 $adresses[$i]['adrid'] = $i;
106 replace_ifset_adr('secondaire', $i);
107 set_flag_adr('courrier', $i);
108 replace_ifset_adr('temporaire', $i);
109 if(Env
::i('adrid_active', $i+
1) == $i)
110 $adresses[$i]['active'] = 1;
112 $adresses[$i]['active'] = 0;
113 replace_ifset_adr('adr1', $i);
114 replace_ifset_adr('adr2', $i);
115 replace_ifset_adr('adr3', $i);
116 replace_ifset_adr('postcode', $i);
117 replace_ifset_adr('city', $i);
118 replace_ifset_adr('cityid', $i);
119 replace_ifset_adr('country', $i);
120 replace_ifset_adr('region', $i);
121 replace_ifset_adr('pub', $i);
123 for ($telid = 0; $telid <= $nb_tel_max; $telid++
) {
124 $tab = Env
::v('telid'.$telid, Array());
125 if(isset($tab[$i])){ //ce telid etait donc present dans le formulaire
126 replace_tel($i, $telid);
130 if (!get_adr_arg('parsevalid', $i)) replace_ifset_adr('txt', $i);
131 $tab = Env
::v('numero_formulaire', Array());
133 $adresses[$i]['numero_formulaire'] = $tab[$i];
135 $adresses[$i]['numero_formulaire'] = -1;
138 function geoloc_adresse($i) {
140 $change = Env
::v('change'.$i);
141 if (get_adr_arg('parsevalid', $i) ||
($adresses[$i]['txt'] && $change) ||
(!$adresses[$i]['cityid'])) {
142 require_once('geoloc.inc.php');
143 // erases the previous address (but not the phone or pub)
144 $adresses[$i] = array_merge($adresses[$i], empty_address());
145 // localize new address
146 $new = get_address_infos($adresses[$i]['txt']);
147 if (compare_addresses_text($adresses[$i]['txt'], $geotxt = get_address_text($new)) ||
get_adr_arg('parsevalid', $i))
148 $adresses[$i] = array_merge($adresses[$i], $new);
150 $adresses[$i] = array_merge($adresses[$i], cut_address($adresses[$i]['txt']));
151 $adresses[$i]['geoloc'] = $geotxt;
152 $adresses[$i]['geoloc_cityid'] = $new['cityid'];
155 $adresses[$i]['txt'] = get_address_text($adresses[$i]);
158 //remplace par les eventuelles nouvelles valeurs :
159 for ($adrid = 1; $adrid <= $nb_adr_max; $adrid++
) {
160 $tab = Env
::v('adrid', Array());
161 if(isset($tab[$adrid])){ //cet adrid etait donc present dans le formulaire
162 replace_address($adrid);
164 if (isset($adresses[$adrid]['txt']))
165 geoloc_adresse($adrid);
168 if ($opened_tab == 'adresses' && Env
::has('modifier')){ // on ne valide que qd on vient du formulaire
169 $adresses_principales = 0;
171 foreach($adresses as $adrid => $adr) {
172 //validité de chaque adresse
173 $description = (($adr['numero_formulaire'] > 0)?
"Adresse n°{$adr['numero_formulaire']}":"Nouvelle adresse");
174 if (strlen(strtok($adr['adr1'],"<>{}@~?!§*`|%$^=+")) < strlen($adr['adr1']))
176 $page->trig("Le champ '$description - Ligne 1' contient un caractère interdit.");
178 if (strlen(strtok($adr['adr2'],"<>{}@~?!§*`|%$^=+")) < strlen($adr['adr2']))
180 $page->trig("Le champ '$description - Ligne 2' contient un caractère interdit.");
182 if (strlen(strtok($adr['adr3'],"<>{}@~?!§*`|%$^=+")) < strlen($adr['adr3']))
184 $page->trig("Le champ '$description - Ligne 3' contient un caractère interdit.");
186 if (strlen(strtok($adr['postcode'],"<>{}@~?!§*`|%$^=+")) < strlen($adr['postcode']))
188 $page->trig("Le champ '$description - Code Postal' contient un caractère interdit.");
190 if (strlen(strtok($adr['city'],"<>{}@~?!§*`|%$^=+")) < strlen($adr['postcode']))
192 $page->trig("Le champ '$description - Ville' contient un caractère interdit.");
194 foreach ($adr['tels'] as $tel) {
195 if (strlen(strtok($tel['tel'],"<>{}@&#~\/:;?,!§*_`[]|%$^=\"")) < strlen($tel['tel']))
197 $page->trig("Le champ '$description - ".$tel['tel_type']."' contient un caractère interdit.");
200 if(!$adr['secondaire']){
201 if($adresses_principales == 1){ //deja une adresse principale
202 $page->trig("Tu ne peux avoir qu'une résidence principale.");
203 $adresses_principales++
;//pour eviter de repeter le message plusieurs fois
205 else $adresses_principales = 1;