diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 8eb808892b2..f8f0c7b863c 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4769,27 +4769,42 @@ function dol_print_phone($phone, $countrycode = '', $cid = 0, $socid = 0, $addli */ function dol_print_ip($ip, $mode = 0) { - global $langs; + global $conf, $langs; $ret = ''; - - if (empty($mode)) { - $ret .= $ip; + if (!isset($conf->cache['resolveips'])) { + $conf->cache['resolveips'] = []; } if ($mode != 2) { $countrycode = dolGetCountryCodeFromIp($ip); if ($countrycode) { // If success, countrycode is us, fr, ... if (file_exists(DOL_DOCUMENT_ROOT.'/theme/common/flags/'.$countrycode.'.png')) { - $ret .= ' '.img_picto($countrycode.' '.$langs->trans("AccordingToGeoIPDatabase"), DOL_URL_ROOT.'/theme/common/flags/'.$countrycode.'.png', '', 1); + $ret .= picto_from_langcode($countrycode); + // $ret .= img_picto($countrycode.' '.$langs->trans("AccordingToGeoIPDatabase"), DOL_URL_ROOT.'/theme/common/flags/'.$countrycode.'.png', '', 1); } else { - $ret .= ' ('.$countrycode.')'; + $ret .= '('.$countrycode.')'; } + $ret .= ' '; } else { // Nothing } } + if (in_array($mode, [0, 2])) { + if (empty($conf->cache['resolveips'][$ip])) { + $domain = gethostbyaddr($ip); + $conf->cache['resolveips'][$ip] = $domain; // false or domain + } else { + $domain = $conf->cache['resolveips'][$ip]; + } + if ($domain) { + $ret .= $domain; + } else { + $ret .= $ip; + } + } + return $ret; }