2 /***************************************************************************
3 * Copyright (C) 2003-2007 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 $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;
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'],
34 S
::v('uid', -1), $adrid, $newid);
37 foreach ($adresses as $adrid => $adr) {
38 if ($adr['nouvelle'] != 'new') {
39 // test si on vient de creer cette adresse dans verif_adresse.inc.php
41 //construction des bits
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);
49 if (isset($adr['precise_lat']) && isset($adr['precise_lon'])) {
50 $precise_coords = ", glat = '".$adr['precise_lat']."'";
51 $precise_coords .= ", glng = '".$adr['precise_lon']."'";
54 if ($adr["nouvelle"] == 'ajout') {
56 if (is_adr_empty($adrid)) {
57 unset($adresses[$adrid]);
60 echo "Nouveau pas vide";
61 XDB
::execute("INSERT INTO adresses SET adr1 = {?}, adr2 = {?},
62 adr3 = {?}, postcode = {?}, city = {?}, cityid = {?},
63 country = {?}, region = {?}, regiontxt = {?},
64 pub = {?}, datemaj = NOW(), statut = {?}, uid = {?},
65 adrid = {?}".$precise_coords, $adr['adr1'], $adr['adr2'],
66 $adr['adr3'], $adr['postcode'], $adr['city'],
67 $adr['cityid'], $adr['country'], $adr['region'],
68 $adr['regiontxt'], $adr['pub'], $statut,
69 S
::v('uid', -1), $adrid);
71 foreach ($adr['tels'] as $tel) {
72 insert_new_tel($adrid, $tel);
75 //c'est une mise à jour
76 XDB
::execute("UPDATE adresses SET adr1 = {?}, adr2 = {?},
77 adr3 = {?}, postcode = {?}, city = {?}, cityid = {?},
78 country = {?}, region = {?}, regiontxt = {?},
79 pub = {?}, datemaj = NOW(), statut = {?}".$precise_coords."
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'],
84 $statut, S
::v('uid', -1), $adrid);
85 foreach ($adr['tels'] as $tel) {
86 if (isset($tel['new_tel'])) {
88 insert_new_tel($adrid, $tel);
90 if ($tel['tel'] != "") {
108 "DELETE FROM tels WHERE
118 }// fin nouvelle / ancienne adresse
119 }//fin if nouvellement crée
123 //on vire les adresses vides :
124 if(isset($adresses)){ // s'il y en a
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]);
131 if(is_adr_empty($adrid)){
132 delete_address($adrid);