Ensure we always have a 'current' address (Closes #790)
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 17 Feb 2008 17:48:43 +0000 (18:48 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 17 Feb 2008 17:54:14 +0000 (18:54 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
ChangeLog
modules/profile/addresses.inc.php

index fe122be..410d12d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -24,6 +24,7 @@ Bug/Wish:
         - #742: Sub domain was hidden when editing profile                 -FRU
         - #752: Don't show vcard link on profile when the person is dead   -FRU
         - #764: Fix mentoring edition page                                 -FRU
+        - #790: Ensure we always have a current address                    -FRU
 
     * Search:
         - #741: Mentor search in advanced search                           -FRU
index 4c20bb2..2fe7a8d 100644 (file)
@@ -76,15 +76,19 @@ class ProfileAddress extends ProfileGeoloc
             }
         }
         $current = 0;
+        $success = true;
         foreach ($value as $key=>&$adr) {
             if (@$adr['current']) {
                 $current++;
             }
         }
-        if (!$init && $current != 1 && count($value) > 0) {
+        if ($current == 0 && count($value) > 0) {
+            foreach ($value as $key=>&$adr) {
+                $adr['current'] = true;
+                break;
+            }
+        } else if ($current > 1) {
             $success = false;
-        } else {
-            $success = true;
         }
         foreach ($value as $key=>&$adr) {
             $ls = true;