2006 => 2007 Happy New Year\!
[platal.git] / include / profil / get_adresses.inc.php
index 341a563..d952e1a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2004 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,42 +32,54 @@ $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){
-    global $globals;
-    $globals->xdb->execute("DELETE FROM adresses WHERE uid = {?} AND adrid = {?}",Session::getInt('uid', -1), $adrid);
-    $globals->xdb->execute("DELETE FROM tels WHERE uid = {?} AND adrid = {?}",Session::getInt('uid', -1), $adrid);
-    if($in_request_array == true){
-      unset($_REQUEST['adrid'][$adrid]);
-    }
-    else{
-      unset($GLOBALS['adresses'][$adrid]);
+    XDB::execute("DELETE FROM adresses WHERE uid = {?} AND adrid = {?}",
+                 S::v('uid', -1), $adrid);
+    XDB::execute("DELETE FROM tels WHERE uid = {?} AND adrid = {?}",
+                 S::v('uid', -1), $adrid);
+    if ($in_request_array == true){
+        unset($_REQUEST['adrid'][$adrid]);
+    else{
+        unset($GLOBALS['adresses'][$adrid]);
     }
 }
 
 //on verifie si on nous a demande une suppression
-$req_adrid_del = Env::getMixed('adrid_del', Array());
-for($i = 1; $i <= $nb_adr_max; $i++){
-  if( isset( $req_adrid_del[$i] ) ) {
-    delete_address($i,true);
-  }
+$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 = $globals->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
-$res = $globals->xdb->iterRow(
+$res = XDB::iterRow(
        "SELECT
        FIND_IN_SET('res-secondaire', statut), FIND_IN_SET('courrier', statut),
        FIND_IN_SET('active', statut), FIND_IN_SET('temporaire', statut),
@@ -74,7 +88,7 @@ $res = $globals->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();
@@ -95,12 +109,12 @@ for ($i = 0; $i < $nb_adr; $i++) {
   $adresses[$adrid]['txt'] = get_address_text($adresses[$adrid]);
 }
 
-$restels = $globals->xdb->iterator(
+$restels = XDB::iterator(
     "SELECT
     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'];