Merge branch 'platal-0.10.0'
[platal.git] / include / user.func.inc.php
index 84aaa8c..1cbd1f9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2009 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -103,8 +103,10 @@ function get_not_registered_user($login, $iterator = false)
         return null;
     }
     @list($prenom, $nom, $promo) = explode('.', $login);
-    $where = 'REPLACE(REPLACE(REPLACE(nom, " ", ""), "-", ""), "\'", "") LIKE CONCAT("%", {?}, "%")
-          AND  REPLACE(REPLACE(REPLACE(prenom, " ", ""), "-", ""), "\'", "") LIKE CONCAT("%", {?}, "%")';
+    $where = 'REPLACE(REPLACE(REPLACE(nom, " ", ""), "-", ""), "\'", "")
+              LIKE CONCAT("%", REPLACE(REPLACE(REPLACE({?}, " ", ""), "-", ""), "\'", ""), "%")
+              AND  REPLACE(REPLACE(REPLACE(prenom, " ", ""), "-", ""), "\'", "")
+              LIKE CONCAT("%", REPLACE(REPLACE(REPLACE({?}, " ", ""), "-", ""), "\'", ""), "%")';
     if ($promo) {
         if (preg_match('/^[0-9]{2}$/', $promo)) {
             $where .= 'AND MOD(promo, 100) = {?}';
@@ -214,6 +216,7 @@ function get_user_details_adr($uid, $view = 'private') {
                      gp.pays AS countrytxt,a.region, a.regiontxt,
                      FIND_IN_SET('active', a.statut) AS active, a.adrid,
                      FIND_IN_SET('res-secondaire', a.statut) AS secondaire,
+                     FIND_IN_SET('courrier', a.statut) AS courier,
                      a.pub, gp.display
                FROM  adresses AS a
           LEFT JOIN  geoloc_pays AS gp ON (gp.a2=a.country)
@@ -527,18 +530,17 @@ function remove_user_pro($uid, $entrid) {
 // }}}
 // {{{ function set_user_details()
 function set_user_details_addresses($uid, $adrs) {
-    $res = XDB::query("SELECT adrid FROM adresses WHERE uid = {?} AND adrid >= 1 ORDER BY adrid", $uid);
-    $adrids = $res->fetchColumn();
+    $req = XDB::query('SELECT MAX(adrid) + 1
+                         FROM adresses
+                        WHERE uid = {?}', $uid);
+    $adrid = $req->fetchOneCell();
+    if (is_null($adrid)) {
+        $adrid = 0;
+    }
     foreach ($adrs as $adr) {
-        if (isset($adr['adrid']) && isset($adr['remove']) && $adr['remove']) {
-            remove_user_address($uid, $adr['adrid']);
-            if (isset($adrids[$adr['adrid']])) unset($adrids[$adr['adrid']]);
-        } else if (isset($adr['adrid'])) {
-            update_user_address($uid, $adr['adrid'], $adr);
-        } else {
-            for ($adrid = 1; isset($adrids[$adrid-1]) && ($adrids[$adrid-1] == $adrid); $adrid++);
+        if (!@$adr['remove']) {
             add_user_address($uid, $adrid, $adr);
-            $adrids[$adrid-1] = $adrid;
+            ++$adrid;
         }
     }
     require_once 'geoloc.inc.php';
@@ -549,17 +551,17 @@ function set_user_details_addresses($uid, $adrs) {
 
 function set_user_details_pro($uid, $pros)
 {
-    $res = XDB::query("SELECT entrid FROM entreprises WHERE uid = {?} ORDER BY entrid", $uid);
-    $entrids = $res->fetchColumn();
+    $req = XDB::query('SELECT MAX(entrid) + 1
+                         FROM entreprises
+                        WHERE uid = {?}', $uid);
+    $entrid = $req->fetchOneCell();
+    if (is_null($entrid)) {
+        $entrid = 0;
+    }
     foreach ($pros as $pro) {
-        if (isset($pro['entrid']) && isset($pro['remove']) && $pro['remove']) {
-            remove_user_pro($uid, $pro['entrid']);
-            if (isset($entrids[$pro['entrid']])) unset($entrids[$pro['entrid']]);
-        } else if (isset($pro['entrid'])) {
-            update_user_pro($uid, $pro['entrid'], $pro);
-        } else {
-            for ($entrid = 0; isset($entrids[$entrid]) && ($entrids[$entrid] == $entrid); $entrid++);
+        if (!@$pro['remove']) {
             add_user_pro($uid, $entrid, $pro);
+            ++$entrid;
         }
     }
 }