0337d704 |
1 | <?php |
2 | /*************************************************************************** |
50a40a33 |
3 | * Copyright (C) 2003-2006 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; |
28 | XDB::execute( "INSERT INTO tels SET tel_type = {?}, tel_pub = {?}, |
29 | tel = {?}, uid = {?}, adrid = {?}, telid = {?}", |
30 | $tel['tel_type'], $tel['tel_pub'], $tel['tel'], |
cab08090 |
31 | S::v('uid', -1), $adrid, $tel['telid']); |
79a5acea |
32 | } |
33 | |
a3a049fc |
34 | foreach ($adresses as $adrid => $adr) { |
0337d704 |
35 | |
a3a049fc |
36 | if ($adr['nouvelle'] != 'new') { |
37 | // test si on vient de creer cette adresse dans verif_adresse.inc.php |
0337d704 |
38 | |
a3a049fc |
39 | //construction des bits |
40 | $statut = ""; |
41 | if ($adr["secondaire"]) $statut .= 'res-secondaire,'; |
42 | if ($adr["courrier"]) $statut .= 'courrier,'; |
43 | if ($adr["active"]) $statut .= 'active,'; |
44 | if ($adr["temporaire"]) $statut .= 'temporaire,'; |
45 | if (! empty($statut)) $statut = substr($statut, 0, -1); |
46 | |
47 | if ($adr["nouvelle"] == 'ajout') { |
48 | //nouvelle adresse |
49 | XDB::execute("INSERT INTO adresses SET adr1 = {?}, adr2 = {?}, |
50 | adr3 = {?}, postcode = {?}, city = {?}, cityid = {?}, |
51 | country = {?}, region = {?}, regiontxt = {?}, |
52 | pub = {?}, datemaj = NOW(), statut = {?}, uid = {?}, |
53 | adrid = {?}", $adr['adr1'], $adr['adr2'], |
54 | $adr['adr3'], $adr['postcode'], $adr['city'], |
55 | $adr['cityid'], $adr['country'], $adr['region'], |
56 | $adr['regiontxt'], $adr['pub'], $statut, |
cab08090 |
57 | S::v('uid', -1), $adrid); |
a3a049fc |
58 | $telsvalues = ""; |
59 | foreach ($adr['tels'] as $tel) { |
60 | insert_new_tel($adrid, $tel); |
61 | } |
62 | } else { |
63 | //c'est une mise à jour |
64 | XDB::execute("UPDATE adresses SET adr1 = {?}, adr2 = {?}, |
65 | adr3 = {?}, postcode = {?}, city = {?}, cityid = {?}, |
66 | country = {?}, region = {?}, regiontxt = {?}, |
67 | pub = {?}, datemaj = NOW(), statut = {?} |
68 | WHERE uid = {?} AND adrid = {?}", $adr['adr1'], |
69 | $adr['adr2'], $adr['adr3'], $adr['postcode'], |
70 | $adr['city'], $adr['cityid'], $adr['country'], |
71 | $adr['region'], $adr['regiontxt'], $adr['pub'], |
cab08090 |
72 | $statut, S::v('uid', -1), $adrid); |
a3a049fc |
73 | foreach ($adr['tels'] as $tel) { |
74 | if ($tel['new_tel']) { |
75 | insert_new_tel($adrid, $tel); |
76 | } else { |
77 | if ($tel['tel'] != "") { |
78 | XDB::execute( |
79 | "UPDATE tels SET |
80 | tel_type = {?}, |
81 | tel_pub = {?}, |
82 | tel = {?} |
83 | WHERE |
84 | uid = {?} AND |
85 | adrid = {?} AND |
86 | telid = {?}", |
87 | $tel['tel_type'], |
88 | $tel['tel_pub'], |
89 | $tel['tel'], |
cab08090 |
90 | S::v('uid', -1), |
a3a049fc |
91 | $adrid, |
92 | $tel['telid']); |
93 | } else { |
94 | XDB::execute( |
95 | "DELETE FROM tels WHERE |
96 | uid = {?} AND |
97 | adrid = {?} AND |
98 | telid = {?}", |
cab08090 |
99 | S::v('uid', -1), |
a3a049fc |
100 | $adrid, |
101 | $tel['telid']); |
102 | } |
103 | } |
104 | } |
105 | }// fin nouvelle / ancienne adresse |
106 | }//fin if nouvellement crée |
0337d704 |
107 | }//fin foreach |
907aa9fa |
108 | |
109 | |
110 | //on vire les adresses vides : |
111 | if(isset($adresses)){ // s'il y en a |
112 | reset($adresses); |
113 | foreach($adresses as $adrid => $adr){ |
114 | // on vire les tels vides |
115 | foreach ($adr['tels'] as $telid => $tel) { |
116 | if ($tel['tel'] == '') unset($adresses[$adrid]['tels'][$telid]); |
117 | } |
118 | if(is_adr_empty($adrid)){ |
119 | delete_address($adrid); |
120 | } |
121 | } |
122 | } |
123 | |
0337d704 |
124 | ?> |