nb de tels variables par adresse, wish 400
[platal.git] / include / profil / update_adresses.inc.php
index cf4a150..cf85507 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-
 reset($adresses);
 
+function insert_new_tel($adrid, $tel) {
+  global $globals;
+  if ($tel['tel'] == "") return;
+ $globals->xdb->execute(
+   "INSERT INTO tels SET
+    tel_type = {?},
+    tel_pub = {?},
+    tel = {?},
+    uid = {?},
+    adrid = {?},
+    telid = {?}",
+    $tel['tel_type'],
+    $tel['tel_pub'],
+    $tel['tel'],
+    Session::getInt('uid', -1),
+    $adrid,
+    $tel['telid']);
+}
+
 foreach($adresses as $adrid => $adr){
 
   if($adr['nouvelle'] != 'new'){ // test si on vient de creer cette adresse dans verif_adresse.inc.php
@@ -45,10 +63,8 @@ foreach($adresses as $adrid => $adr){
                         cityid = {?},
                         country = {?},
                         region = {?},
-                        tel = {?},
-                        fax = {?},
+                        regiontxt = {?},
                         pub = {?},
-                        tel_pub = {?},
                         datemaj = NOW(),
                         statut = {?},
                         uid = {?}, adrid = {?}",
@@ -60,12 +76,13 @@ foreach($adresses as $adrid => $adr){
                         $adr['cityid'],
                         $adr['country'],
                         $adr['region'],
-                        $adr['tel'],
-                        $adr['fax'],
+                        $adr['regiontxt'],
                         $adr['pub'],
-                        $adr['tel_pub'],
                         $statut,
                         Session::getInt('uid', -1), $adrid);
+       $telsvalues = "";                
+       foreach ($adr['tels'] as $tel) 
+         insert_new_tel($adrid, $tel);
     }
     
     else{ 
@@ -80,10 +97,8 @@ foreach($adresses as $adrid => $adr){
                                 cityid = {?},
                                 country = {?},
                                 region = {?},
-                                tel = {?},
-                                fax = {?},
+                                regiontxt = {?},
                                 pub = {?},
-                                tel_pub = {?},
                                 datemaj = NOW(),
                                 statut = {?}
                                 WHERE uid = {?} AND adrid = {?}",
@@ -95,13 +110,42 @@ foreach($adresses as $adrid => $adr){
                                 $adr['cityid'],
                                 $adr['country'],
                                 $adr['region'],
-                                $adr['tel'],
-                                $adr['fax'],
+                                $adr['regiontxt'],
                                 $adr['pub'],
-                                $adr['tel_pub'],
                                 $statut,
                                 Session::getInt('uid', -1), $adrid
                    );
+       foreach ($adr['tels'] as $tel) {
+         if ($tel['new_tel'])
+          insert_new_tel($adrid, $tel);
+        else
+          if ($tel['tel'] != "") {
+          $globals->xdb->execute(
+           "UPDATE tels SET
+            tel_type = {?},
+            tel_pub = {?},
+            tel = {?}
+            WHERE
+            uid = {?} AND
+            adrid = {?} AND
+            telid = {?}",
+            $tel['tel_type'],
+            $tel['tel_pub'],
+            $tel['tel'],
+            Session::getInt('uid', -1),
+            $adrid,
+            $tel['telid']);
+          } else {
+          $globals->xdb->execute(
+           "DELETE FROM tels WHERE
+            uid = {?} AND
+            adrid = {?} AND
+            telid = {?}",
+            Session::getInt('uid', -1),
+            $adrid,
+            $tel['telid']);
+          }
+       }
     }// fin nouvelle / ancienne adresse
   }//fin if nouvellement crée
 }//fin foreach