| 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 | if ($tel['tel'] == "") |
| 26 | return; |
| 27 | XDB::execute( "INSERT INTO tels SET tel_type = {?}, tel_pub = {?}, |
| 28 | tel = {?}, uid = {?}, adrid = {?}, telid = {?}", |
| 29 | $tel['tel_type'], $tel['tel_pub'], $tel['tel'], |
| 30 | S::v('uid', -1), $adrid, $tel['telid']); |
| 31 | } |
| 32 | |
| 33 | foreach ($adresses as $adrid => $adr) { |
| 34 | |
| 35 | if ($adr['nouvelle'] != 'new') { |
| 36 | // test si on vient de creer cette adresse dans verif_adresse.inc.php |
| 37 | |
| 38 | //construction des bits |
| 39 | $statut = ""; |
| 40 | if ($adr["secondaire"]) $statut .= 'res-secondaire,'; |
| 41 | if ($adr["courrier"]) $statut .= 'courrier,'; |
| 42 | if ($adr["active"]) $statut .= 'active,'; |
| 43 | if ($adr["temporaire"]) $statut .= 'temporaire,'; |
| 44 | if (! empty($statut)) $statut = substr($statut, 0, -1); |
| 45 | |
| 46 | if ($adr["nouvelle"] == 'ajout') { |
| 47 | //nouvelle adresse |
| 48 | XDB::execute("INSERT INTO adresses SET adr1 = {?}, adr2 = {?}, |
| 49 | adr3 = {?}, postcode = {?}, city = {?}, cityid = {?}, |
| 50 | country = {?}, region = {?}, regiontxt = {?}, |
| 51 | pub = {?}, datemaj = NOW(), statut = {?}, uid = {?}, |
| 52 | adrid = {?}", $adr['adr1'], $adr['adr2'], |
| 53 | $adr['adr3'], $adr['postcode'], $adr['city'], |
| 54 | $adr['cityid'], $adr['country'], $adr['region'], |
| 55 | $adr['regiontxt'], $adr['pub'], $statut, |
| 56 | S::v('uid', -1), $adrid); |
| 57 | $telsvalues = ""; |
| 58 | foreach ($adr['tels'] as $tel) { |
| 59 | insert_new_tel($adrid, $tel); |
| 60 | } |
| 61 | } else { |
| 62 | //c'est une mise à jour |
| 63 | XDB::execute("UPDATE adresses SET adr1 = {?}, adr2 = {?}, |
| 64 | adr3 = {?}, postcode = {?}, city = {?}, cityid = {?}, |
| 65 | country = {?}, region = {?}, regiontxt = {?}, |
| 66 | pub = {?}, datemaj = NOW(), statut = {?} |
| 67 | WHERE uid = {?} AND adrid = {?}", $adr['adr1'], |
| 68 | $adr['adr2'], $adr['adr3'], $adr['postcode'], |
| 69 | $adr['city'], $adr['cityid'], $adr['country'], |
| 70 | $adr['region'], $adr['regiontxt'], $adr['pub'], |
| 71 | $statut, S::v('uid', -1), $adrid); |
| 72 | foreach ($adr['tels'] as $tel) { |
| 73 | if ($tel['new_tel']) { |
| 74 | insert_new_tel($adrid, $tel); |
| 75 | } else { |
| 76 | if ($tel['tel'] != "") { |
| 77 | XDB::execute( |
| 78 | "UPDATE tels SET |
| 79 | tel_type = {?}, |
| 80 | tel_pub = {?}, |
| 81 | tel = {?} |
| 82 | WHERE |
| 83 | uid = {?} AND |
| 84 | adrid = {?} AND |
| 85 | telid = {?}", |
| 86 | $tel['tel_type'], |
| 87 | $tel['tel_pub'], |
| 88 | $tel['tel'], |
| 89 | S::v('uid', -1), |
| 90 | $adrid, |
| 91 | $tel['telid']); |
| 92 | } else { |
| 93 | XDB::execute( |
| 94 | "DELETE FROM tels WHERE |
| 95 | uid = {?} AND |
| 96 | adrid = {?} AND |
| 97 | telid = {?}", |
| 98 | S::v('uid', -1), |
| 99 | $adrid, |
| 100 | $tel['telid']); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | }// fin nouvelle / ancienne adresse |
| 105 | }//fin if nouvellement crée |
| 106 | }//fin foreach |
| 107 | ?> |