closes #535, autorise le caractere / dans les numeros de tel
[platal.git] / include / profil / update_adresses.inc.php
index d6f5213..9783ebc 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
+ *  Copyright (C) 2003-2007 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -25,14 +25,16 @@ reset($adresses);
 function insert_new_tel($adrid, $tel) {
     if ($tel['tel'] == "")
         return;
+    $r = XDB::query("SELECT MAX(telid+1) FROM tels WHERE uid = {?} AND adrid = {?}", S::v('uid',-1), $adrid);
+    $newid = $r->fetchOneCell();
+    if (!$newid) $newid = 0;
     XDB::execute( "INSERT INTO tels SET tel_type = {?}, tel_pub = {?},
                   tel = {?}, uid = {?}, adrid = {?}, telid = {?}",
                   $tel['tel_type'], $tel['tel_pub'], $tel['tel'],
-                  S::v('uid', -1), $adrid, $tel['telid']);
+                  S::v('uid', -1), $adrid, $newid);
 }
 
 foreach ($adresses as $adrid => $adr) {
-
     if ($adr['nouvelle'] != 'new') {
         // test si on vient de creer cette adresse dans verif_adresse.inc.php
 
@@ -43,14 +45,24 @@ foreach ($adresses as $adrid => $adr) {
         if ($adr["active"])        $statut .= 'active,';
         if ($adr["temporaire"])    $statut .= 'temporaire,';
         if (! empty($statut)) $statut = substr($statut, 0, -1);
+        $precise_coords = "";
+        if (isset($adr['precise_lat']) && isset($adr['precise_lon'])) {
+            $precise_coords  = ", glat = '".$adr['precise_lat']."'";
+            $precise_coords .= ", glng = '".$adr['precise_lon']."'";
+        }
 
         if ($adr["nouvelle"] == 'ajout') {
             //nouvelle adresse
+            if (is_adr_empty($adrid)) {
+                unset($adresses[$adrid]);
+                continue;
+            }
+            echo "Nouveau pas vide";
             XDB::execute("INSERT INTO adresses SET adr1 = {?}, adr2 = {?},
                          adr3 = {?}, postcode = {?}, city = {?}, cityid = {?},
                          country = {?}, region = {?}, regiontxt = {?},
                          pub = {?}, datemaj = NOW(), statut = {?}, uid = {?},
-                         adrid = {?}", $adr['adr1'], $adr['adr2'],
+                         adrid = {?}".$precise_coords, $adr['adr1'], $adr['adr2'],
                          $adr['adr3'], $adr['postcode'], $adr['city'],
                          $adr['cityid'], $adr['country'], $adr['region'],
                          $adr['regiontxt'], $adr['pub'], $statut,
@@ -64,15 +76,16 @@ foreach ($adresses as $adrid => $adr) {
             XDB::execute("UPDATE adresses SET adr1 = {?}, adr2 = {?},
                          adr3 = {?}, postcode = {?}, city = {?}, cityid = {?},
                          country = {?}, region = {?}, regiontxt = {?},
-                         pub = {?}, datemaj = NOW(), statut = {?}
+                         pub = {?}, datemaj = NOW(), statut = {?}".$precise_coords."
                          WHERE uid = {?} AND adrid = {?}", $adr['adr1'],
                          $adr['adr2'], $adr['adr3'], $adr['postcode'],
                          $adr['city'], $adr['cityid'], $adr['country'],
                          $adr['region'], $adr['regiontxt'], $adr['pub'],
                          $statut, S::v('uid', -1), $adrid);
             foreach ($adr['tels'] as $tel) {
-                if ($tel['new_tel']) {
-                    insert_new_tel($adrid, $tel);
+                if (isset($tel['new_tel'])) {
+                       if ($tel['new_tel'])
+                       insert_new_tel($adrid, $tel);
                 } else {
                     if ($tel['tel'] != "") {
                         XDB::execute(