dolibarr  7.0.0-beta
geoipmaxmind.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2009-2012 Laurent Destailleur <eldy@users.sourceforge.org>
3  * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php';
28 
29 // Security check
30 if (!$user->admin)
32 
33 $langs->load("admin");
34 $langs->load("errors");
35 
36 $action = GETPOST('action','aZ09');
37 
38 /*
39  * Actions
40  */
41 if ($action == 'set')
42 {
43  $error=0;
44 
45  $gimcdf= GETPOST("GEOIPMAXMIND_COUNTRY_DATAFILE");
46 
47  if (! $gimcdf && ! file_exists($gimcdf))
48  {
49  setEventMessages($langs->trans("ErrorFileNotFound",$gimcdf), null, 'errors');
50  $error++;
51  }
52 
53  if (! $error)
54  {
55  $res = dolibarr_set_const($db,"GEOIPMAXMIND_COUNTRY_DATAFILE",$gimcdf,'chaine',0,'',$conf->entity);
56  if (! $res > 0) $error++;
57 
58  if (! $error)
59  {
60  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
61  }
62  else
63  {
64  setEventMessages($langs->trans("Error"), null, 'errors');
65  }
66  }
67 }
68 
69 
70 /*
71  * View
72  */
73 
74 $form=new Form($db);
75 
76 llxHeader();
77 
78 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
79 print load_fiche_titre($langs->trans("GeoIPMaxmindSetup"),$linkback,'title_setup');
80 print '<br>';
81 
82 $version='';
83 $geoip='';
84 if (! empty($conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE))
85 {
86  $geoip=new DolGeoIP('country',$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE);
87  //if ($geoip->error) print dol_htmloutput_errors($geoip->errorlabel,'',1);
88  if ($geoip->gi == 'NOGI') $geointernal=true;
89  else $geointernal=false;
90 }
91 else
92 {
93  if (function_exists('geoip_country_code_by_name')) $geointernal=true;
94 }
95 
96 // Mode
97 $var=true;
98 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
99 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
100 print '<input type="hidden" name="action" value="set">';
101 
102 print '<table class="noborder" width="100%">';
103 print '<tr class="liste_titre">';
104 print '<td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td>';
105 print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
106 print "</tr>\n";
107 
108 
109 print '<tr class="oddeven"><td width=\"50%\">'.$langs->trans("PathToGeoIPMaxmindCountryDataFile").'</td>';
110 print '<td colspan="2">';
111 
112 if ($geointernal) print 'Using geoip PHP internal functions. Value must be '.geoip_db_filename(GEOIP_COUNTRY_EDITION).' or '.geoip_db_filename(GEOIP_CITY_EDITION_REV1).'<br>';
113 print '<input size="50" type="text" name="GEOIPMAXMIND_COUNTRY_DATAFILE" value="'.$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE.'">';
114 if ($geoip) $version=$geoip->getVersion();
115 if ($version)
116 {
117  print '<br>'.$langs->trans("Version").': '.$version;
118 }
119 print '</td></tr>';
120 
121 print '</table>';
122 
123 print "</form>\n";
124 
125 print '<br>';
126 
127 print $langs->trans("NoteOnPathLocation").'<br>';
128 
129 $url1='http://www.maxmind.com/en/city?rId=awstats';
130 print $langs->trans("YouCanDownloadFreeDatFileTo",'<a href="'.$url1.'" target="_blank">'.$url1.'</a>');
131 
132 print '<br>';
133 
134 $url2='http://www.maxmind.com/en/city?rId=awstats';
135 print $langs->trans("YouCanDownloadAdvancedDatFileTo",'<a href="'.$url2.'" target="_blank">'.$url2.'</a>');
136 
137 if ($geoip)
138 {
139  print '<br><br>';
140  print '<br>'.$langs->trans("TestGeoIPResult",$ip).':';
141 
142  $ip='24.24.24.24';
143  print '<br>'.$ip.' -> ';
144  $result=dol_print_ip($ip,1);
145  if ($result) print $result;
146  else print $langs->trans("Error");
147 
148  /* We disable this test because dol_print_ip need an ip as input
149  $ip='www.google.com';
150  print '<br>'.$ip.' -> ';
151  $result=dol_print_ip($ip,1);
152  if ($result) print $result;
153  else print $langs->trans("Error");
154  */
155  $geoip->close();
156 }
157 
158 llxFooter();
159 
160 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:485
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_ip($ip, $mode=0)
Return an IP formated to be shown on screen.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
print
Draft customers invoices.
Definition: index.php:91
Classe to manage GeoIP Usage: $geoip=new GeoIP('country',$datfile); $geoip->getCountryCodeFromIP($ip)...