Non significant spaces suck.
[platal.git] / modules / profile / update_adresses.inc.php
CommitLineData
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 22global $adresses;
0337d704 23reset($adresses);
24
79a5acea 25function 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 37foreach ($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 }
a3a049fc 60 XDB::execute("INSERT INTO adresses SET adr1 = {?}, adr2 = {?},
61 adr3 = {?}, postcode = {?}, city = {?}, cityid = {?},
62 country = {?}, region = {?}, regiontxt = {?},
63 pub = {?}, datemaj = NOW(), statut = {?}, uid = {?},
c9970cbe 64 adrid = {?}".$precise_coords, $adr['adr1'], $adr['adr2'],
a3a049fc 65 $adr['adr3'], $adr['postcode'], $adr['city'],
66 $adr['cityid'], $adr['country'], $adr['region'],
67 $adr['regiontxt'], $adr['pub'], $statut,
cab08090 68 S::v('uid', -1), $adrid);
eaf30d86 69 $telsvalues = "";
a3a049fc 70 foreach ($adr['tels'] as $tel) {
71 insert_new_tel($adrid, $tel);
72 }
eaf30d86 73 } else {
a7de4ef7 74 //c'est une mise à jour
a3a049fc 75 XDB::execute("UPDATE adresses SET adr1 = {?}, adr2 = {?},
76 adr3 = {?}, postcode = {?}, city = {?}, cityid = {?},
77 country = {?}, region = {?}, regiontxt = {?},
5912f6b6 78 pub = {?}, datemaj = NOW(), statut = {?}".$precise_coords."
a3a049fc 79 WHERE uid = {?} AND adrid = {?}", $adr['adr1'],
80 $adr['adr2'], $adr['adr3'], $adr['postcode'],
81 $adr['city'], $adr['cityid'], $adr['country'],
82 $adr['region'], $adr['regiontxt'], $adr['pub'],
cab08090 83 $statut, S::v('uid', -1), $adrid);
a3a049fc 84 foreach ($adr['tels'] as $tel) {
5ee95138 85 if (isset($tel['new_tel'])) {
86 if ($tel['new_tel'])
87 insert_new_tel($adrid, $tel);
a3a049fc 88 } else {
89 if ($tel['tel'] != "") {
90 XDB::execute(
91 "UPDATE tels SET
92 tel_type = {?},
93 tel_pub = {?},
94 tel = {?}
95 WHERE
96 uid = {?} AND
97 adrid = {?} AND
98 telid = {?}",
99 $tel['tel_type'],
100 $tel['tel_pub'],
101 $tel['tel'],
cab08090 102 S::v('uid', -1),
a3a049fc 103 $adrid,
104 $tel['telid']);
105 } else {
106 XDB::execute(
107 "DELETE FROM tels WHERE
108 uid = {?} AND
109 adrid = {?} AND
110 telid = {?}",
cab08090 111 S::v('uid', -1),
a3a049fc 112 $adrid,
113 $tel['telid']);
114 }
115 }
116 }
117 }// fin nouvelle / ancienne adresse
a7de4ef7 118 }//fin if nouvellement crée
0337d704 119}//fin foreach
907aa9fa 120
121
122//on vire les adresses vides :
123if(isset($adresses)){ // s'il y en a
124 reset($adresses);
125 foreach($adresses as $adrid => $adr){
126 // on vire les tels vides
127 foreach ($adr['tels'] as $telid => $tel) {
128 if ($tel['tel'] == '') unset($adresses[$adrid]['tels'][$telid]);
129 }
130 if(is_adr_empty($adrid)){
131 delete_address($adrid);
132 }
133 }
134}
135
a7de4ef7 136// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 137?>