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 | |
8303b851 |
22 | global $adresses; |
0337d704 |
23 | reset($adresses); |
24 | |
79a5acea |
25 | function insert_new_tel($adrid, $tel) { |
a3a049fc |
26 | if ($tel['tel'] == "") |
27 | return; |
5ee95138 |
28 | $r = XDB::query("SELECT MAX(telid+1) FROM tels WHERE uid = {?} AND adrid = {?}", S::v('uid',-1), $adrid); |
29 | $newid = $r->fetchOneCell(); |
30 | if (!$newid) $newid = 0; |
a3a049fc |
31 | XDB::execute( "INSERT INTO tels SET tel_type = {?}, tel_pub = {?}, |
32 | tel = {?}, uid = {?}, adrid = {?}, telid = {?}", |
33 | $tel['tel_type'], $tel['tel_pub'], $tel['tel'], |
5ee95138 |
34 | S::v('uid', -1), $adrid, $newid); |
79a5acea |
35 | } |
36 | |
a3a049fc |
37 | foreach ($adresses as $adrid => $adr) { |
a3a049fc |
38 | if ($adr['nouvelle'] != 'new') { |
39 | // test si on vient de creer cette adresse dans verif_adresse.inc.php |
0337d704 |
40 | |
a3a049fc |
41 | //construction des bits |
42 | $statut = ""; |
43 | if ($adr["secondaire"]) $statut .= 'res-secondaire,'; |
44 | if ($adr["courrier"]) $statut .= 'courrier,'; |
45 | if ($adr["active"]) $statut .= 'active,'; |
46 | if ($adr["temporaire"]) $statut .= 'temporaire,'; |
47 | if (! empty($statut)) $statut = substr($statut, 0, -1); |
c9970cbe |
48 | $precise_coords = ""; |
49 | if (isset($adr['precise_lat']) && isset($adr['precise_lon'])) { |
50 | $precise_coords = ", glat = '".$adr['precise_lat']."'"; |
51 | $precise_coords .= ", glng = '".$adr['precise_lon']."'"; |
52 | } |
a3a049fc |
53 | |
54 | if ($adr["nouvelle"] == 'ajout') { |
55 | //nouvelle adresse |
5ee95138 |
56 | if (is_adr_empty($adrid)) { |
57 | unset($adresses[$adrid]); |
58 | continue; |
59 | } |
60 | echo "Nouveau pas vide"; |
a3a049fc |
61 | XDB::execute("INSERT INTO adresses SET adr1 = {?}, adr2 = {?}, |
62 | adr3 = {?}, postcode = {?}, city = {?}, cityid = {?}, |
63 | country = {?}, region = {?}, regiontxt = {?}, |
64 | pub = {?}, datemaj = NOW(), statut = {?}, uid = {?}, |
c9970cbe |
65 | adrid = {?}".$precise_coords, $adr['adr1'], $adr['adr2'], |
a3a049fc |
66 | $adr['adr3'], $adr['postcode'], $adr['city'], |
67 | $adr['cityid'], $adr['country'], $adr['region'], |
68 | $adr['regiontxt'], $adr['pub'], $statut, |
cab08090 |
69 | S::v('uid', -1), $adrid); |
a3a049fc |
70 | $telsvalues = ""; |
71 | foreach ($adr['tels'] as $tel) { |
72 | insert_new_tel($adrid, $tel); |
73 | } |
74 | } else { |
a7de4ef7 |
75 | //c'est une mise à jour |
a3a049fc |
76 | XDB::execute("UPDATE adresses SET adr1 = {?}, adr2 = {?}, |
77 | adr3 = {?}, postcode = {?}, city = {?}, cityid = {?}, |
78 | country = {?}, region = {?}, regiontxt = {?}, |
5912f6b6 |
79 | pub = {?}, datemaj = NOW(), statut = {?}".$precise_coords." |
a3a049fc |
80 | WHERE uid = {?} AND adrid = {?}", $adr['adr1'], |
81 | $adr['adr2'], $adr['adr3'], $adr['postcode'], |
82 | $adr['city'], $adr['cityid'], $adr['country'], |
83 | $adr['region'], $adr['regiontxt'], $adr['pub'], |
cab08090 |
84 | $statut, S::v('uid', -1), $adrid); |
a3a049fc |
85 | foreach ($adr['tels'] as $tel) { |
5ee95138 |
86 | if (isset($tel['new_tel'])) { |
87 | if ($tel['new_tel']) |
88 | insert_new_tel($adrid, $tel); |
a3a049fc |
89 | } else { |
90 | if ($tel['tel'] != "") { |
91 | XDB::execute( |
92 | "UPDATE tels SET |
93 | tel_type = {?}, |
94 | tel_pub = {?}, |
95 | tel = {?} |
96 | WHERE |
97 | uid = {?} AND |
98 | adrid = {?} AND |
99 | telid = {?}", |
100 | $tel['tel_type'], |
101 | $tel['tel_pub'], |
102 | $tel['tel'], |
cab08090 |
103 | S::v('uid', -1), |
a3a049fc |
104 | $adrid, |
105 | $tel['telid']); |
106 | } else { |
107 | XDB::execute( |
108 | "DELETE FROM tels WHERE |
109 | uid = {?} AND |
110 | adrid = {?} AND |
111 | telid = {?}", |
cab08090 |
112 | S::v('uid', -1), |
a3a049fc |
113 | $adrid, |
114 | $tel['telid']); |
115 | } |
116 | } |
117 | } |
118 | }// fin nouvelle / ancienne adresse |
a7de4ef7 |
119 | }//fin if nouvellement crée |
0337d704 |
120 | }//fin foreach |
907aa9fa |
121 | |
122 | |
123 | //on vire les adresses vides : |
124 | if(isset($adresses)){ // s'il y en a |
125 | reset($adresses); |
126 | foreach($adresses as $adrid => $adr){ |
127 | // on vire les tels vides |
128 | foreach ($adr['tels'] as $telid => $tel) { |
129 | if ($tel['tel'] == '') unset($adresses[$adrid]['tels'][$telid]); |
130 | } |
131 | if(is_adr_empty($adrid)){ |
132 | delete_address($adrid); |
133 | } |
134 | } |
135 | } |
136 | |
a7de4ef7 |
137 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 |
138 | ?> |