/admin/includes/classes/geoip.php

https://github.com/LisaX/oscommerce · PHP · 195 lines · 109 code · 32 blank · 54 comment · 7 complexity · ac744a796d4484bad4300dfe0087725d MD5 · raw file

  1. <?php
  2. /*
  3. $Id: $
  4. osCommerce, Open Source E-Commerce Solutions
  5. http://www.oscommerce.com
  6. Copyright (c) 2007 osCommerce
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License v2 (1991)
  9. as published by the Free Software Foundation.
  10. */
  11. class osC_GeoIP_Admin {
  12. var $_group = 'geoip',
  13. $_status = false,
  14. $_active = false;
  15. // class methods
  16. function load() {
  17. global $osC_Language;
  18. if (defined('MODULE_DEFAULT_GEOIP') && !osc_empty(MODULE_DEFAULT_GEOIP) && file_exists('includes/modules/geoip/' . MODULE_DEFAULT_GEOIP . '.php')) {
  19. $osC_Language->loadIniFile('modules/geoip/' . MODULE_DEFAULT_GEOIP . '.php');
  20. include('includes/modules/geoip/' . MODULE_DEFAULT_GEOIP . '.php');
  21. $module = 'osC_GeoIP_' . MODULE_DEFAULT_GEOIP;
  22. return new $module();
  23. } else {
  24. return new osC_GeoIP_Admin();
  25. }
  26. }
  27. function activate() {
  28. }
  29. function deactivate() {
  30. }
  31. function getCountryISOCode2() {
  32. }
  33. function getCountryName() {
  34. }
  35. function getData() {
  36. return array();
  37. }
  38. function isValid() {
  39. return false;
  40. }
  41. function isActive() {
  42. return $this->_active;
  43. }
  44. function getCode() {
  45. return $this->_code;
  46. }
  47. function getTitle() {
  48. return $this->_title;
  49. }
  50. function getDescription() {
  51. return $this->_description;
  52. }
  53. function getAuthorName() {
  54. return $this->_author_name;
  55. }
  56. function getAuthorAddress() {
  57. return $this->_author_www;
  58. }
  59. function hasKeys() {
  60. static $has_keys;
  61. if (isset($has_keys) === false) {
  62. $has_keys = (sizeof($this->getKeys()) > 0) ? true : false;
  63. }
  64. return $has_keys;
  65. }
  66. function getKeys() {
  67. return array();
  68. }
  69. function isInstalled() {
  70. return $this->_status;
  71. }
  72. function install() {
  73. global $osC_Database, $osC_Language;
  74. if (defined('MODULE_DEFAULT_GEOIP')) {
  75. include('includes/modules/geoip/' . MODULE_DEFAULT_GEOIP . '.php');
  76. $module = 'osC_GeoIP_' . MODULE_DEFAULT_GEOIP;
  77. $module = new module();
  78. $module->remove();
  79. }
  80. $Qcfg = $osC_Database->query('insert into :table_configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, date_added) values (:configuration_title, :configuration_key, :configuration_value, :configuration_description, :configuration_group_id, :date_added)');
  81. $Qcfg->bindTable(':table_configuration', TABLE_CONFIGURATION);
  82. $Qcfg->bindValue(':configuration_title', 'Default GeoIP Module');
  83. $Qcfg->bindValue(':configuration_key', 'MODULE_DEFAULT_GEOIP');
  84. $Qcfg->bindValue(':configuration_value', $this->_code);
  85. $Qcfg->bindvalue(':configuration_description', 'Default GeoIP module.');
  86. $Qcfg->bindInt(':configuration_group_id', 6);
  87. $Qcfg->bindRaw(':date_added', 'now()');
  88. $Qcfg->execute();
  89. $Qinstall = $osC_Database->query('insert into :table_templates_boxes (title, code, author_name, author_www, modules_group) values (:title, :code, :author_name, :author_www, :modules_group)');
  90. $Qinstall->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
  91. $Qinstall->bindValue(':title', $this->_title);
  92. $Qinstall->bindValue(':code', $this->_code);
  93. $Qinstall->bindValue(':author_name', $this->_author_name);
  94. $Qinstall->bindValue(':author_www', $this->_author_www);
  95. $Qinstall->bindValue(':modules_group', $this->_group);
  96. $Qinstall->execute();
  97. /*
  98. foreach ($osC_Language->getAll() as $key => $value) {
  99. if (file_exists('../includes/languages/' . $key . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
  100. foreach ($osC_Language->extractDefinitions($key . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
  101. $Qcheck = $osC_Database->query('select id from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group and languages_id = :languages_id limit 1');
  102. $Qcheck->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
  103. $Qcheck->bindValue(':definition_key', $def['key']);
  104. $Qcheck->bindValue(':content_group', $def['group']);
  105. $Qcheck->bindInt(':languages_id', $value['id']);
  106. $Qcheck->execute();
  107. if ($Qcheck->numberOfRows() === 1) {
  108. $Qdef = $osC_Database->query('update :table_languages_definitions set definition_value = :definition_value where definition_key = :definition_key and content_group = :content_group and languages_id = :languages_id');
  109. } else {
  110. $Qdef = $osC_Database->query('insert into :table_languages_definitions (languages_id, content_group, definition_key, definition_value) values (:languages_id, :content_group, :definition_key, :definition_value)');
  111. }
  112. $Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
  113. $Qdef->bindInt(':languages_id', $value['id']);
  114. $Qdef->bindValue(':content_group', $def['group']);
  115. $Qdef->bindValue(':definition_key', $def['key']);
  116. $Qdef->bindValue(':definition_value', $def['value']);
  117. $Qdef->execute();
  118. }
  119. }
  120. }
  121. osC_Cache::clear('languages');
  122. */
  123. osC_Cache::clear('configuration');
  124. }
  125. function remove() {
  126. global $osC_Database, $osC_Language;
  127. $Qdel = $osC_Database->query('delete from :table_configuration where configuration_key = :configuration_key');
  128. $Qdel->bindTable(':table_configuration', TABLE_CONFIGURATION);
  129. $Qdel->bindValue(':configuration_key', 'MODULE_DEFAULT_GEOIP');
  130. $Qdel->execute();
  131. $Qdel = $osC_Database->query('delete from :table_templates_boxes where code = :code and modules_group = :modules_group');
  132. $Qdel->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
  133. $Qdel->bindValue(':code', $this->_code);
  134. $Qdel->bindValue(':modules_group', $this->_group);
  135. $Qdel->execute();
  136. if ($this->hasKeys()) {
  137. $Qdel = $osC_Database->query('delete from :table_configuration where configuration_key in (":configuration_key")');
  138. $Qdel->bindTable(':table_configuration', TABLE_CONFIGURATION);
  139. $Qdel->bindRaw(':configuration_key', implode('", "', $this->getKeys()));
  140. $Qdel->execute();
  141. }
  142. /*
  143. if (file_exists('../includes/languages/' . $osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
  144. foreach ($osC_Language->extractDefinitions($osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
  145. $Qdel = $osC_Database->query('delete from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group');
  146. $Qdel->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
  147. $Qdel->bindValue(':definition_key', $def['key']);
  148. $Qdel->bindValue(':content_group', $def['group']);
  149. $Qdel->execute();
  150. }
  151. osC_Cache::clear('languages');
  152. }
  153. */
  154. osC_Cache::clear('configuration');
  155. }
  156. }
  157. ?>