PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/admin/geoipmaxmind.php

https://github.com/asterix14/dolibarr
PHP | 148 lines | 87 code | 32 blank | 29 comment | 14 complexity | f17ca3b0cacbe8c85ef6b6943dc2061d MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.org>
  3. * Copyright (C) 2011 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 2 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. /**
  19. * \file htdocs/admin/geoipmaxmind.php
  20. * \ingroup geoipmaxmind
  21. * \brief Setup page for geoipmaxmind module
  22. */
  23. require("../main.inc.php");
  24. require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
  25. require_once(DOL_DOCUMENT_ROOT."/core/class/dolgeoip.class.php");
  26. // Security check
  27. if (!$user->admin)
  28. accessforbidden();
  29. $langs->load("admin");
  30. $langs->load("errors");
  31. $action = GETPOST("action");
  32. /*
  33. * Actions
  34. */
  35. if ($action == 'set')
  36. {
  37. $error=0;
  38. $gimcdf= GETPOST("GEOIPMAXMIND_COUNTRY_DATAFILE");
  39. if (! $gimcdf && ! file_exists($gimcdf))
  40. {
  41. $mesg='<div class="error">'.$langs->trans("ErrorFileNotFound",$gimcdf).'</div>';
  42. $error++;
  43. }
  44. if (! $error)
  45. {
  46. $res = dolibarr_set_const($db,"GEOIPMAXMIND_COUNTRY_DATAFILE",$gimcdf,'chaine',0,'',$conf->entity);
  47. if (! $res > 0) $error++;
  48. if (! $error)
  49. {
  50. $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  51. }
  52. else
  53. {
  54. $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  55. }
  56. }
  57. }
  58. /*
  59. * View
  60. */
  61. $form=new Form($db);
  62. llxHeader();
  63. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  64. print_fiche_titre($langs->trans("GeoIPMaxmindSetup"),$linkback,'setup');
  65. print '<br>';
  66. $version='';
  67. $geoip='';
  68. if (! empty($conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE))
  69. {
  70. $geoip=new DolGeoIP('country',$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE);
  71. }
  72. // Mode
  73. $var=true;
  74. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  75. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  76. print '<input type="hidden" name="action" value="set">';
  77. print '<table class="noborder" width="100%">';
  78. print '<tr class="liste_titre">';
  79. print '<td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td>';
  80. print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  81. print "</tr>\n";
  82. $var=!$var;
  83. print '<tr '.$bc[$var].'><td width=\"50%\">'.$langs->trans("PathToGeoIPMaxmindCountryDataFile").'</td>';
  84. print '<td colspan="2">';
  85. print '<input size="50" type="text" name="GEOIPMAXMIND_COUNTRY_DATAFILE" value="'.$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE.'">';
  86. if ($geoip) $version=$geoip->getVersion();
  87. if ($version)
  88. {
  89. print '<br>'.$langs->trans("Version").': '.$version;
  90. }
  91. print '</td></tr>';
  92. print '</table>';
  93. print "</form>\n";
  94. print '<br>';
  95. print $langs->trans("NoteOnPathLocation").'<br>';
  96. $url1='http://www.maxmind.com/app/perl?rId=awstats';
  97. print $langs->trans("YouCanDownloadFreeDatFileTo",'<a href="'.$url1.'" target="_blank">'.$url1.'</a>');
  98. print '<br>';
  99. $url2='http://www.maxmind.com/app/perl?rId=awstats';
  100. print $langs->trans("YouCanDownloadAdvancedDatFileTo",'<a href="'.$url2.'" target="_blank">'.$url2.'</a>');
  101. if ($geoip)
  102. {
  103. print '<br><br>';
  104. print '<br>';
  105. $ip='24.24.24.24';
  106. print $langs->trans("TestGeoIPResult",$ip).':<br>';
  107. print $ip.' -> ';
  108. $result=dol_print_ip($ip,1);
  109. if ($result) print $result;
  110. else print $langs->trans("Error");
  111. $geoip->close();
  112. }
  113. dol_htmloutput_mesg($mesg);
  114. $db->close();
  115. llxFooter();
  116. ?>