diff --git a/htdocs/admin/geoipmaxmind.php b/htdocs/admin/geoipmaxmind.php
index 3e4430aef9b..a8f1d797576 100644
--- a/htdocs/admin/geoipmaxmind.php
+++ b/htdocs/admin/geoipmaxmind.php
@@ -26,10 +26,6 @@
// Load Dolibarr environment
require '../main.inc.php';
-require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
-require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
-require_once DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php';
-
/**
* @var Conf $conf
* @var DoliDB $db
@@ -37,6 +33,11 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php';
* @var Translate $langs
* @var User $user
*/
+require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
// Security check
if (!$user->admin) {
@@ -48,6 +49,10 @@ $langs->loadLangs(array("admin", "errors"));
$action = GETPOST('action', 'aZ09');
+if (!isset($conf->global->GEOIP_VERSION)) {
+ $conf->global->GEOIP_VERSION = '2';
+}
+
/*
* Actions
@@ -56,21 +61,50 @@ $action = GETPOST('action', 'aZ09');
if ($action == 'set') {
$error = 0;
- $gimcdf = GETPOST("GEOIPMAXMIND_COUNTRY_DATAFILE");
-
- if ($gimcdf && !preg_match('/\.(dat|mmdb)$/', $gimcdf)) {
- setEventMessages($langs->trans("ErrorFileMustHaveFormat", '.dat|.mmdb'), null, 'errors');
- $error++;
- }
-
$res1 = dolibarr_set_const($db, "GEOIP_VERSION", GETPOST('geoipversion', 'aZ09'), 'chaine', 0, '', $conf->entity);
if (!($res1 > 0)) {
$error++;
}
- $res2 = dolibarr_set_const($db, "GEOIPMAXMIND_COUNTRY_DATAFILE", $gimcdf, 'chaine', 0, '', $conf->entity);
- if (!($res2 > 0)) {
- $error++;
+ if (getDolGlobalString('GEOIP_VERSION') == 'php') {
+ $gimcdf = GETPOST("GEOIPMAXMIND_COUNTRY_DATAFILE");
+ if ($gimcdf) {
+ if (!preg_match('/\.(dat|mmdb)$/', $gimcdf)) {
+ setEventMessages($langs->trans("ErrorFileMustHaveFormat", '.dat|.mmdb'), null, 'errors');
+ $error++;
+ }
+
+ if (!$error) {
+ $res2 = dolibarr_set_const($db, "GEOIPMAXMIND_COUNTRY_DATAFILE", $gimcdf, 'chaine', 0, '', $conf->entity);
+ if (!($res2 > 0)) {
+ $error++;
+ }
+ }
+ }
+ } else {
+ $gimcdf = GETPOST("GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED");
+ if ($gimcdf && !preg_match('/\.(dat|mmdb)$/', $gimcdf)) {
+ setEventMessages($langs->trans("ErrorFileMustHaveFormat", '.dat|.mmdb'), null, 'errors');
+ $error++;
+ }
+
+ if (!$error) {
+ $varname = 'GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED';
+ if (isset($_FILES[$varname]) && $_FILES[$varname]["name"]) {
+ $diroffile = getMultidirOutput(null, 'geoipmaxmind');
+ if ($diroffile) {
+ $dirforterms = $diroffile.'/';
+ $original_file = $_FILES[$varname]["name"];
+ $result = dol_move_uploaded_file($_FILES[$varname]["tmp_name"], $dirforterms.$original_file, 1, 0, $_FILES[$varname]['error']);
+ if ((int) $result > 0) {
+ dolibarr_set_const($db, $varname, $original_file, 'chaine', 0, '', $conf->entity);
+ } else {
+ $error++;
+ setEventMessages($langs->trans("Error").' '.$langs->transnoentitiesnoconv((string) $result), null, 'errors');
+ }
+ }
+ }
+ }
}
if (!$error) {
@@ -80,9 +114,7 @@ if ($action == 'set') {
}
}
-if (!isset($conf->global->GEOIP_VERSION)) {
- $conf->global->GEOIP_VERSION = '2';
-}
+$documenturl = getDolGlobalString('DOL_URL_ROOT_DOCUMENT_PHP', DOL_URL_ROOT.'/document.php');
/*
@@ -90,6 +122,7 @@ if (!isset($conf->global->GEOIP_VERSION)) {
*/
$form = new Form($db);
+$formfile = new FormFile($db);
llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-geoipmaxmind');
@@ -100,12 +133,18 @@ print '
';
$version = '';
$geoip = '';
-if (getDolGlobalString('GEOIPMAXMIND_COUNTRY_DATAFILE')) {
- $geoip = new DolGeoIP('country', $conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE);
+if (getDolGlobalString('GEOIP_VERSION') == 'php') {
+ $datafile = getDolGlobalString('GEOIPMAXMIND_COUNTRY_DATAFILE');
+} else {
+ $diroffile = getMultidirOutput(null, 'geoipmaxmind');
+ $datafile = $diroffile . '/' . getDolGlobalString('GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED');
+}
+if ($datafile) {
+ $geoip = new DolGeoIP('country', $datafile);
}
// Mode
-print '