mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-05 09:08:09 +01:00
enhance dol_print_ip (#33819)
* enhance dol_print_ip * fix cache * fix CI
This commit is contained in:
@@ -1256,7 +1256,7 @@ abstract class CommonObject
|
||||
return -2;
|
||||
}
|
||||
|
||||
if ($this->restrictiononfksoc && property_exists('socid', $this) && !empty($this->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
if ($this->restrictiononfksoc && property_exists($this, 'socid') && !empty($this->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql_allowed_contacts = 'SELECT COUNT(*) as cnt FROM '.$this->db->prefix().'societe_commerciaux as sc';
|
||||
$sql_allowed_contacts.= ' WHERE sc.fk_soc = '.(int) $this->socid;
|
||||
$sql_allowed_contacts.= ' AND sc.fk_user = '.(int) $user->id;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user