| 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 | reset($adresses); |
| 23 | |
| 24 | function insert_new_tel($adrid, $tel) { |
| 25 | global $globals; |
| 26 | if ($tel['tel'] == "") return; |
| 27 | $globals->xdb->execute( |
| 28 | "INSERT INTO tels SET |
| 29 | tel_type = {?}, |
| 30 | tel_pub = {?}, |
| 31 | tel = {?}, |
| 32 | uid = {?}, |
| 33 | adrid = {?}, |
| 34 | telid = {?}", |
| 35 | $tel['tel_type'], |
| 36 | $tel['tel_pub'], |
| 37 | $tel['tel'], |
| 38 | Session::getInt('uid', -1), |
| 39 | $adrid, |
| 40 | $tel['telid']); |
| 41 | } |
| 42 | |
| 43 | foreach($adresses as $adrid => $adr){ |
| 44 | |
| 45 | if($adr['nouvelle'] != 'new'){ // test si on vient de creer cette adresse dans verif_adresse.inc.php |
| 46 | |
| 47 | //construction des bits |
| 48 | $statut = ""; |
| 49 | if ($adr["secondaire"]) $statut .= 'res-secondaire,'; |
| 50 | if ($adr["courrier"]) $statut .= 'courrier,'; |
| 51 | if ($adr["active"]) $statut .= 'active,'; |
| 52 | if ($adr["temporaire"]) $statut .= 'temporaire,'; |
| 53 | if (! empty($statut)) $statut = substr($statut, 0, -1); |
| 54 | |
| 55 | if ($adr["nouvelle"] == 'ajout') { |
| 56 | //nouvelle adresse |
| 57 | $globals->xdb->execute("INSERT INTO adresses SET |
| 58 | adr1 = {?}, |
| 59 | adr2 = {?}, |
| 60 | adr3 = {?}, |
| 61 | postcode = {?}, |
| 62 | city = {?}, |
| 63 | cityid = {?}, |
| 64 | country = {?}, |
| 65 | region = {?}, |
| 66 | regiontxt = {?}, |
| 67 | pub = {?}, |
| 68 | datemaj = NOW(), |
| 69 | statut = {?}, |
| 70 | uid = {?}, adrid = {?}", |
| 71 | $adr['adr1'], |
| 72 | $adr['adr2'], |
| 73 | $adr['adr3'], |
| 74 | $adr['postcode'], |
| 75 | $adr['city'], |
| 76 | $adr['cityid'], |
| 77 | $adr['country'], |
| 78 | $adr['region'], |
| 79 | $adr['regiontxt'], |
| 80 | $adr['pub'], |
| 81 | $statut, |
| 82 | Session::getInt('uid', -1), $adrid); |
| 83 | $telsvalues = ""; |
| 84 | foreach ($adr['tels'] as $tel) |
| 85 | insert_new_tel($adrid, $tel); |
| 86 | } |
| 87 | |
| 88 | else{ |
| 89 | //c'est une mise à jour |
| 90 | $globals->xdb->execute( |
| 91 | "UPDATE adresses SET |
| 92 | adr1 = {?}, |
| 93 | adr2 = {?}, |
| 94 | adr3 = {?}, |
| 95 | postcode = {?}, |
| 96 | city = {?}, |
| 97 | cityid = {?}, |
| 98 | country = {?}, |
| 99 | region = {?}, |
| 100 | regiontxt = {?}, |
| 101 | pub = {?}, |
| 102 | datemaj = NOW(), |
| 103 | statut = {?} |
| 104 | WHERE uid = {?} AND adrid = {?}", |
| 105 | $adr['adr1'], |
| 106 | $adr['adr2'], |
| 107 | $adr['adr3'], |
| 108 | $adr['postcode'], |
| 109 | $adr['city'], |
| 110 | $adr['cityid'], |
| 111 | $adr['country'], |
| 112 | $adr['region'], |
| 113 | $adr['regiontxt'], |
| 114 | $adr['pub'], |
| 115 | $statut, |
| 116 | Session::getInt('uid', -1), $adrid |
| 117 | ); |
| 118 | foreach ($adr['tels'] as $tel) { |
| 119 | if ($tel['new_tel']) |
| 120 | insert_new_tel($adrid, $tel); |
| 121 | else |
| 122 | if ($tel['tel'] != "") { |
| 123 | $globals->xdb->execute( |
| 124 | "UPDATE tels SET |
| 125 | tel_type = {?}, |
| 126 | tel_pub = {?}, |
| 127 | tel = {?} |
| 128 | WHERE |
| 129 | uid = {?} AND |
| 130 | adrid = {?} AND |
| 131 | telid = {?}", |
| 132 | $tel['tel_type'], |
| 133 | $tel['tel_pub'], |
| 134 | $tel['tel'], |
| 135 | Session::getInt('uid', -1), |
| 136 | $adrid, |
| 137 | $tel['telid']); |
| 138 | } else { |
| 139 | $globals->xdb->execute( |
| 140 | "DELETE FROM tels WHERE |
| 141 | uid = {?} AND |
| 142 | adrid = {?} AND |
| 143 | telid = {?}", |
| 144 | Session::getInt('uid', -1), |
| 145 | $adrid, |
| 146 | $tel['telid']); |
| 147 | } |
| 148 | } |
| 149 | }// fin nouvelle / ancienne adresse |
| 150 | }//fin if nouvellement crée |
| 151 | }//fin foreach |
| 152 | ?> |