diff --git a/htdocs/admin/geoipmaxmind.php b/htdocs/admin/geoipmaxmind.php index f2a4e3c7fba44358b1e8479422451bff1f5fdea4..3d384a4b832426ba8ebf30e802c33a29bbb753dd 100644 --- a/htdocs/admin/geoipmaxmind.php +++ b/htdocs/admin/geoipmaxmind.php @@ -1,6 +1,6 @@ <?php -/* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.org> - * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es> +/* Copyright (C) 2009-2012 Laurent Destailleur <eldy@users.sourceforge.org> + * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -129,20 +129,27 @@ print $langs->trans("YouCanDownloadAdvancedDatFileTo",'<a href="'.$url2.'" targe if ($geoip) { print '<br><br>'; - print '<br>'; + print '<br>'.$langs->trans("TestGeoIPResult",$ip).':'; + $ip='24.24.24.24'; - print $langs->trans("TestGeoIPResult",$ip).':<br>'; - print $ip.' -> '; + print '<br>'.$ip.' -> '; $result=dol_print_ip($ip,1); if ($result) print $result; else print $langs->trans("Error"); + /* We disable this test because dol_print_ip need an ip as input + $ip='www.google.com'; + print '<br>'.$ip.' -> '; + $result=dol_print_ip($ip,1); + if ($result) print $result; + else print $langs->trans("Error"); + */ $geoip->close(); } dol_htmloutput_mesg($mesg); -$db->close(); - llxFooter(); + +$db->close(); ?> diff --git a/htdocs/core/class/dolgeoip.class.php b/htdocs/core/class/dolgeoip.class.php index 4710b531fb70e4f42b6d14dba61f1b9d6b3d3538..ccb68c992c62199eb80fea4a456c46420f8e7a4d 100644 --- a/htdocs/core/class/dolgeoip.class.php +++ b/htdocs/core/class/dolgeoip.class.php @@ -1,5 +1,5 @@ <?php -/* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net> +/* Copyright (C) 2009-2012 Laurent Destailleur <eldy@users.sourceforge.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,17 +19,17 @@ /** * \file htdocs/core/class/dolgeoip.class.php * \ingroup geoip - * \brief Library for managing module geoip + * \brief File of class to manage module geoip */ /** * \class DolGeoIP * \brief Classe to manage GeoIP - * \remarks Usage: - * \remarks $geoip=new GeoIP('country',$datfile); - * \remarks $geoip->getCountryCodeFromIP($ip); - * \remarks $geoip->close(); + * Usage: + * $geoip=new GeoIP('country',$datfile); + * $geoip->getCountryCodeFromIP($ip); + * $geoip->close(); */ class DolGeoIP { @@ -56,6 +56,7 @@ class DolGeoIP } else { print 'ErrorBadParameterInConstructor'; return 0; } + // Here, function exists (embedded into PHP or exists because we made include) if (empty($type) || empty($datfile)) { //dol_syslog("DolGeoIP::DolGeoIP parameter datafile not defined", LOG_ERR); @@ -73,7 +74,16 @@ class DolGeoIP return 0; } - $this->gi = geoip_open($datfile,GEOIP_STANDARD); + if (function_exists('geoip_open')) + { + $this->gi = geoip_open($datfile,GEOIP_STANDARD); + } + else + { + $this->gi = 'NOGI'; // We are using embedded php geoip functions + //print 'function_exists(geoip_country_code_by_name))='.function_exists('geoip_country_code_by_name'); + //print geoip_database_info(); + } } /** @@ -88,7 +98,16 @@ class DolGeoIP { return ''; } - return strtolower(geoip_country_code_by_addr($this->gi, $ip)); + if ($this->gi == 'NOGI') + { + // geoip_country_code_by_addr does not exists + return strtolower(geoip_country_code_by_name($ip)); + } + else + { + if (! function_exists('geoip_country_code_by_addr')) return strtolower(geoip_country_code_by_name($this->gi, $ip)); + return strtolower(geoip_country_code_by_addr($this->gi, $ip)); + } } /** @@ -113,6 +132,7 @@ class DolGeoIP */ function getVersion() { + if ($this->gi == 'NOGI') return geoip_database_info(); return ''; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 25f78395f6d327736d40881b9069299f55661f8f..47a10261d6cc0621cd9cac058cb9f245ce93ad44 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -195,7 +195,7 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port) /** * Get entity to use - * + * * @param string $element Current element * @param int $shared 1=Return shared entities * @return mixed Entity id(s) to use @@ -203,7 +203,7 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port) function getEntity($element=false, $shared=false) { global $conf, $mc; - + if (is_object($mc)) { return $mc->getEntity($element, $shared); @@ -211,12 +211,12 @@ function getEntity($element=false, $shared=false) else { $out=''; - + $addzero = array('user', 'usergroup'); if (in_array($element, $addzero)) $out.= '0,'; - + $out.= $conf->entity; - + return $out; } } @@ -1334,7 +1334,7 @@ function dol_print_phone($phone,$country="FR",$cid=0,$socid=0,$addlink=0,$separ= * Return an IP formated to be shown on screen * * @param string $ip IP - * @param int $mode 1=return only country/flag,2=return only IP + * @param int $mode 0=return IP + country/flag, 1=return only country/flag, 2=return only IP * @return string Formated IP, with country if GeoIP module is enabled */ function dol_print_ip($ip,$mode=0) @@ -2223,7 +2223,7 @@ function restrictedArea($user, $features='societe', $objectid=0, $dbtablename='' // More features to check $features = explode("&",$features); - + // More parameters list($dbtablename, $sharedelement) = explode('&', $dbtablename);