2006 => 2007 Happy New Year\!
[platal.git] / include / profil / get_adresses.inc.php
index 42b4e58..d952e1a 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   *
@@ -21,6 +21,8 @@
 
 require_once('geoloc.inc.php');
 
+global $adresses, $nb_adr_max, $nb_tel_max;
+
 // on limite à 6 adresses personnelles par utilisateur
 $nb_adr_max = 6; // ( = max(adrid possibles)
 // on limite à 4 numéros de téléphone par adresse
@@ -30,18 +32,26 @@ $nb_tel_max = 4; // ( = max(telid possibles)
 
 function is_adr_empty($adrid){
   $adr = &$GLOBALS['adresses'][$adrid];
+  $emptytel = count($adr['tels']) == 0;
+  if (!$emptytel) {
+       $emptytel = true;
+       foreach ($adr['tels'] as $t) if ($t['tel']) {
+               $emptytel = false;
+               break;
+       }
+  }
   return ( 
     ($adr['adr1'] == '') && ($adr['adr2'] == '') && ($adr['adr3'] == '') &&
     ($adr['postcode'] == '') && ($adr['city'] == '') && ($adr['country'] == '00') &&
-    (count($adr['tels']) == 0)
+    ($emptytel)
     );
 }
 
 function delete_address($adrid, $in_request_array = false){
     XDB::execute("DELETE FROM adresses WHERE uid = {?} AND adrid = {?}",
-                 Session::getInt('uid', -1), $adrid);
+                 S::v('uid', -1), $adrid);
     XDB::execute("DELETE FROM tels WHERE uid = {?} AND adrid = {?}",
-                 Session::getInt('uid', -1), $adrid);
+                 S::v('uid', -1), $adrid);
     if ($in_request_array == true){
         unset($_REQUEST['adrid'][$adrid]);
     } else{
@@ -50,18 +60,22 @@ function delete_address($adrid, $in_request_array = false){
 }
 
 //on verifie si on nous a demande une suppression
-$req_adrid_del = Env::getMixed('adrid_del', Array());
+$req_adrid_del = Env::v('adrid_del', Array());
 for ($i = 1; $i <= $nb_adr_max; $i++) {
     if (isset($req_adrid_del[$i])) {
         delete_address($i,true);
     }
 }
+if (Env::i('deltel')) {
+       XDB::execute("DELETE FROM tels WHERE uid = {?} AND adrid = {?} AND telid = {?}",
+               S::v('uid', -1), Env::i('adrid'), Env::i('telid'));
+}
 
 //$sql_order = "ORDER BY (NOT FIND_IN_SET('active', statut)), FIND_IN_SET('temporaire', statut)";
 $sql_order = '';
 
 //recuperation des adrid
-$res = XDB::query("SELECT adrid FROM adresses WHERE uid = {?} AND NOT FIND_IN_SET('pro', statut) ".$sql_order, Session::getInt('uid', -1));
+$res = XDB::query("SELECT adrid FROM adresses WHERE uid = {?} AND NOT FIND_IN_SET('pro', statut) ".$sql_order, S::v('uid', -1));
 $adrids = $res->fetchColumn();
 
 //recuperation des donnees de la bd
@@ -74,7 +88,7 @@ $res = XDB::iterRow(
        gp.pays AS countrytxt, gp.display
        FROM adresses AS a INNER JOIN geoloc_pays AS gp ON(gp.a2 = a.country)
        WHERE uid = {?} AND NOT FIND_IN_SET('pro',statut) ".$sql_order
-, Session::getInt('uid', -1)
+, S::v('uid', -1)
 );
 
 $nb_adr = $res->total();
@@ -100,7 +114,7 @@ $restels = XDB::iterator(
     t.adrid, telid, tel_type, t.tel_pub, t.tel
     FROM tels AS t INNER JOIN adresses AS a ON(t.uid = a.uid AND t.adrid = a.adrid)
     WHERE t.uid = {?} AND NOT FIND_IN_SET('pro',statut) ORDER BY t.adrid, tel_type DESC, telid"
-, Session::getInt('uid', -1)   
+, S::v('uid', -1)   
 );
 while ($tel = $restels->next()) {
     $adrid = $tel['adrid'];