From f3a1ada8527a6682f8c0e3b2f4dcd71c20cc6c2a Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 1 May 2023 14:43:10 -0600 Subject: [PATCH] Fix wrong name shown for Et2EmailTag if multiple contacts share the same email address --- api/src/Etemplate/Widget/Url.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/api/src/Etemplate/Widget/Url.php b/api/src/Etemplate/Widget/Url.php index 782eb34373..d61d5b3982 100644 --- a/api/src/Etemplate/Widget/Url.php +++ b/api/src/Etemplate/Widget/Url.php @@ -161,8 +161,22 @@ class Url extends Etemplate\Widget $result = $GLOBALS['egw']->contacts->search( array('contact_email' => $email[0], 'contact_email_home' => $email[0]), array('contact_id', 'email', 'email_home', 'n_fn'), - '', '', '', false, 'OR', false + '', '', '%', false, 'OR', false ); - $response->data($result ? $result[0] : false); + // iterate through the possibilities and find the best match to what was entered + $best_match = null; + $best_match_score = -1; + foreach($result as $possibility) + { + $score = max(similar_text(strtolower($_email), strtolower($possibility['n_fn'] . " " . $possibility['email'])), + similar_text(strtolower($_email), strtolower($possibility['n_fn'] . " " . $possibility['email_home'])) + ); + if($score > $best_match_score) + { + $best_match_score = $score; + $best_match = $possibility; + } + } + $response->data($result ? $best_match : false); } } \ No newline at end of file