deux titres pour la nl : un pour le mail, un pour le vrai titre
[platal.git] / include / profil / update_adresses.inc.php
CommitLineData
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 22global $adresses;
0337d704 23reset($adresses);
24
79a5acea 25function 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 34foreach ($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);
c9970cbe 46 $precise_coords = "";
47 if (isset($adr['precise_lat']) && isset($adr['precise_lon'])) {
48 $precise_coords = ", glat = '".$adr['precise_lat']."'";
49 $precise_coords .= ", glng = '".$adr['precise_lon']."'";
50 }
a3a049fc 51
52 if ($adr["nouvelle"] == 'ajout') {
53 //nouvelle adresse
54 XDB::execute("INSERT INTO adresses SET adr1 = {?}, adr2 = {?},
55 adr3 = {?}, postcode = {?}, city = {?}, cityid = {?},
56 country = {?}, region = {?}, regiontxt = {?},
57 pub = {?}, datemaj = NOW(), statut = {?}, uid = {?},
c9970cbe 58 adrid = {?}".$precise_coords, $adr['adr1'], $adr['adr2'],
a3a049fc 59 $adr['adr3'], $adr['postcode'], $adr['city'],
60 $adr['cityid'], $adr['country'], $adr['region'],
61 $adr['regiontxt'], $adr['pub'], $statut,
cab08090 62 S::v('uid', -1), $adrid);
a3a049fc 63 $telsvalues = "";
64 foreach ($adr['tels'] as $tel) {
65 insert_new_tel($adrid, $tel);
66 }
67 } else {
68 //c'est une mise à jour
69 XDB::execute("UPDATE adresses SET adr1 = {?}, adr2 = {?},
70 adr3 = {?}, postcode = {?}, city = {?}, cityid = {?},
71 country = {?}, region = {?}, regiontxt = {?},
5912f6b6 72 pub = {?}, datemaj = NOW(), statut = {?}".$precise_coords."
a3a049fc 73 WHERE uid = {?} AND adrid = {?}", $adr['adr1'],
74 $adr['adr2'], $adr['adr3'], $adr['postcode'],
75 $adr['city'], $adr['cityid'], $adr['country'],
76 $adr['region'], $adr['regiontxt'], $adr['pub'],
cab08090 77 $statut, S::v('uid', -1), $adrid);
a3a049fc 78 foreach ($adr['tels'] as $tel) {
79 if ($tel['new_tel']) {
80 insert_new_tel($adrid, $tel);
81 } else {
82 if ($tel['tel'] != "") {
83 XDB::execute(
84 "UPDATE tels SET
85 tel_type = {?},
86 tel_pub = {?},
87 tel = {?}
88 WHERE
89 uid = {?} AND
90 adrid = {?} AND
91 telid = {?}",
92 $tel['tel_type'],
93 $tel['tel_pub'],
94 $tel['tel'],
cab08090 95 S::v('uid', -1),
a3a049fc 96 $adrid,
97 $tel['telid']);
98 } else {
99 XDB::execute(
100 "DELETE FROM tels WHERE
101 uid = {?} AND
102 adrid = {?} AND
103 telid = {?}",
cab08090 104 S::v('uid', -1),
a3a049fc 105 $adrid,
106 $tel['telid']);
107 }
108 }
109 }
110 }// fin nouvelle / ancienne adresse
111 }//fin if nouvellement crée
0337d704 112}//fin foreach
907aa9fa 113
114
115//on vire les adresses vides :
116if(isset($adresses)){ // s'il y en a
117 reset($adresses);
118 foreach($adresses as $adrid => $adr){
119 // on vire les tels vides
120 foreach ($adr['tels'] as $telid => $tel) {
121 if ($tel['tel'] == '') unset($adresses[$adrid]['tels'][$telid]);
122 }
123 if(is_adr_empty($adrid)){
124 delete_address($adrid);
125 }
126 }
127}
128
0337d704 129?>