From 5d38e707eee6fe1bbf9ede14b555f9c2b9a446f5 Mon Sep 17 00:00:00 2001 From: David Coutadeur Date: Mon, 18 Nov 2024 16:18:18 +0100 Subject: [PATCH] use correct key of $attributes_map for sorting LDAP multivalued attributes (#171) --- htdocs/display.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/htdocs/display.php b/htdocs/display.php index 60d2fe4..85cdc44 100644 --- a/htdocs/display.php +++ b/htdocs/display.php @@ -92,9 +92,29 @@ # Sort attributes values foreach ($entry[0] as $attr => $values) { if ( is_array($values) && $values['count'] > 1 ) { - if(isset($attributes_map[$attr]['sort'])) + + # Find key in attributes_map + $attributes_map_filter = array_filter($attributes_map, function($v) use(&$attr) { + return $v['attribute'] == "$attr"; + }); + if( count($attributes_map_filter) < 1 ) + { + $k = ""; + error_log("WARN: no key found for attribute $attr in \$attributes_map"); + } + elseif( count($attributes_map_filter) > 1 ) + { + $k = array_key_first($attributes_map_filter); + error_log("WARN: multiple keys found for attribute $attr in \$attributes_map, using first one: $k"); + } + else + { + $k = array_key_first($attributes_map_filter); + } + + if(isset($attributes_map[$k]['sort'])) { - if($attributes_map[$attr]['sort'] == "descending" ) + if($attributes_map[$k]['sort'] == "descending" ) { # descending sort arsort($values);