| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2006 Polytechnique.org * |
| 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 | |
| 22 | global $adresses; |
| 23 | reset($adresses); |
| 24 | |
| 25 | function insert_new_tel($adrid, $tel) { |
| 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'], |
| 31 | S::v('uid', -1), $adrid, $tel['telid']); |
| 32 | } |
| 33 | |
| 34 | foreach ($adresses as $adrid => $adr) { |
| 35 | |
| 36 | if ($adr['nouvelle'] != 'new') { |
| 37 | // test si on vient de creer cette adresse dans verif_adresse.inc.php |
| 38 | |
| 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 | $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 | } |
| 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 = {?}, |
| 58 | adrid = {?}".$precise_coords, $adr['adr1'], $adr['adr2'], |
| 59 | $adr['adr3'], $adr['postcode'], $adr['city'], |
| 60 | $adr['cityid'], $adr['country'], $adr['region'], |
| 61 | $adr['regiontxt'], $adr['pub'], $statut, |
| 62 | S::v('uid', -1), $adrid); |
| 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 = {?}, |
| 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); |
| 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'], |
| 95 | S::v('uid', -1), |
| 96 | $adrid, |
| 97 | $tel['telid']); |
| 98 | } else { |
| 99 | XDB::execute( |
| 100 | "DELETE FROM tels WHERE |
| 101 | uid = {?} AND |
| 102 | adrid = {?} AND |
| 103 | telid = {?}", |
| 104 | S::v('uid', -1), |
| 105 | $adrid, |
| 106 | $tel['telid']); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | }// fin nouvelle / ancienne adresse |
| 111 | }//fin if nouvellement crée |
| 112 | }//fin foreach |
| 113 | |
| 114 | |
| 115 | //on vire les adresses vides : |
| 116 | if(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 | |
| 129 | ?> |