2ba7a00084b4665a7239acff06189e8798e74e93
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 ***************************************************************************/
25 function insert_new_tel($adrid, $tel) {
26 if ($tel['tel'] == "")
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'],
31 S
::v('uid', -1), $adrid, $tel['telid']);
34 foreach ($adresses as $adrid => $adr) {
36 if ($adr['nouvelle'] != 'new') {
37 // test si on vient de creer cette adresse dans verif_adresse.inc.php
39 //construction des bits
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);
47 if ($adr["nouvelle"] == 'ajout') {
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,
57 S
::v('uid', -1), $adrid);
59 foreach ($adr['tels'] as $tel) {
60 insert_new_tel($adrid, $tel);
63 //c'est une mise à jour
65 if (isset($adr['precise_lat']) && isset($adr['precise_lon'])) {
66 $precise_coords = ", glat = '".$adr['precise_lat']."'";
67 $precise_coords .= ", glng = '".$adr['precise_lon']."'";
69 XDB
::execute("UPDATE adresses SET adr1 = {?}, adr2 = {?},
70 adr3 = {?}, postcode = {?}, city = {?}, cityid = {?},
71 country = {?}, region = {?}, regiontxt = {?},
72 pub = {?}, datemaj = NOW(), statut = {?}".$precise_coords."
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'],
77 $statut, S
::v('uid', -1), $adrid);
78 foreach ($adr['tels'] as $tel) {
79 if ($tel['new_tel']) {
80 insert_new_tel($adrid, $tel);
82 if ($tel['tel'] != "") {
100 "DELETE FROM tels WHERE
110 }// fin nouvelle / ancienne adresse
111 }//fin if nouvellement crée
115 //on vire les adresses vides :
116 if(isset($adresses)){ // s'il y en a
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]);
123 if(is_adr_empty($adrid)){
124 delete_address($adrid);