Merged changes form main trunk (2.2.8, 2.2.9)
[fa-stable.git] / includes / current_user.inc
index 408addb427866289ae329ffa8de4ccdcd2396849..8a167e3ffe7acb0dd7ae39a6f0cff2cde818ac1b 100644 (file)
@@ -175,7 +175,7 @@ class current_user
                        update_user_prefs($this->user, $prefs);
                }
 
-               $this->prefs = new user_prefs($prefs);
+               $this->prefs = new user_prefs(get_user($this->user));
        }
 }
 
@@ -460,7 +460,10 @@ function array_append(&$array, $elements)
                        $array[$key] = $el;
        }
 }
-
+//
+//     Search $needle in $haystack or in $haystack[][$valuekey]
+//     returns $needle found or null.
+//
 function array_search_value($needle, $haystack, $valuekey=null)
 {
        foreach($haystack as $key => $value) {
@@ -471,15 +474,29 @@ function array_search_value($needle, $haystack, $valuekey=null)
        }
        return null;
 }
-
+//
+//     Search $needle in $haystack or in $haystack[][$valuekey]
+//     returns array of keys of $haystack elements found
+//
+function array_search_keys($needle, $haystack, $valuekey=null)
+{
+       $keys = array();
+       if($haystack)
+               foreach($haystack as $key => $value) {
+                       $val = isset($valuekey) ? $value[$valuekey] : $value;
+                       if ($needle == $val){
+                               $keys[] = $key;
+                       }
+               }
+       return $keys;
+}
+//
+//     Find first (single) $needle in $haystack or in $haystack[][$valuekey]
+//     returns $haystack element found or null
+//
 function array_search_key($needle, $haystack, $valuekey=null)
 {
-       foreach($haystack as $key => $value) {
-               $val = isset($valuekey) ? $value[$valuekey] : $value;
-               if ($needle == $val){
-                       return $key;
-               }
-       }
-       return null;
+       $keys = array_search_keys($needle, $haystack, $valuekey);
+       return @$keys[0];
 }
 ?>
\ No newline at end of file