This commit is contained in:
Daniel Seifert 2009-12-15 09:05:46 +00:00
parent e9235b0073
commit 1b87946f01
11 changed files with 110955 additions and 107609 deletions

5
.gitattributes vendored
View File

@ -1,7 +1,12 @@
* text=auto !eol
copy_this/admin/d3_country_geoip.php -text
copy_this/core/d3geoip.php -text
copy_this/modules/d3_geoip/menu.xml -text
copy_this/modules/d3_geoip/views/d3_oxcmp_cur_geoip.php -text
copy_this/modules/d3_geoip/views/d3_oxcmp_lang_geoip.php -text
copy_this/out/admin/de/d3_geoip_lang.php -text
copy_this/out/admin/tpl/d3_country_geoip.tpl -text
setup+doku/geoip.sql -text
setup+doku/install.sql -text
setup+doku/install.txt -text
setup+doku/licence.txt -text

View File

@ -0,0 +1,206 @@
<?
class d3_country_geoip extends oxAdminView
{
protected $_sDefSort = 'sort';
protected $_sThisTemplate = 'd3_country_geoip.tpl';
public function render()
{
$myConfig = $this->getConfig();
if ( !$myConfig->getConfigParam( 'blAllowSharedEdit' ) )
$this->_aViewData['readonly'] = true;
$ret = parent::render();
$soxId = oxConfig::getParameter( "oxid");
// check if we right now saved a new entry
$sSavedID = oxConfig::getParameter( "saved_oxid");
if ( ($soxId == "-1" || !isset( $soxId)) && isset( $sSavedID) ) {
$soxId = $sSavedID;
oxSession::deleteVar( "saved_oxid");
$this->_aViewData["oxid"] = $soxId;
// for reloading upper frame
$this->_aViewData["updatelist"] = "1";
}
if ( $soxId != "-1" && isset( $soxId)) {
// load object
$oCountry = oxNew( "oxcountry" );
$oCountry->loadInLang( $this->_iEditLang, $soxId );
if ($oCountry->isForeignCountry()) {
$this->_aViewData["blForeignCountry"] = true;
} else {
$this->_aViewData["blForeignCountry"] = false;
}
$oOtherLang = $oCountry->getAvailableInLangs();
if (!isset($oOtherLang[$this->_iEditLang])) {
// echo "language entry doesn't exist! using: ".key($oOtherLang);
$oCountry->loadInLang( key($oOtherLang), $soxId );
}
$this->_aViewData["edit"] = $this->oCountry = $oCountry;
// remove already created languages
$aLang = array_diff (oxLang::getInstance()->getLanguageNames(), $oOtherLang );
if ( count( $aLang))
$this->_aViewData["posslang"] = $aLang;
foreach ( $oOtherLang as $id => $language) {
$oLang= new oxStdClass();
$oLang->sLangDesc = $language;
$oLang->selected = ($id == $this->_iEditLang);
$this->_aViewData["otherlang"][$id] = clone $oLang;
}
} else {
$this->_aViewData["blForeignCountry"] = true;
}
$this->oShopList = &oxNew('oxshoplist');
$oShop = &oxNew('oxshop');
$sSelect = "SELECT * FROM ".$oShop->getViewName()." WHERE ".$oShop->getSqlActiveSnippet();
$this->oShopList->selectString($sSelect);
$this->getLangList();
return $ret;
}
public function saveshop()
{
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$_POST['editval']['oxcountry__d3geoiplang'] = '-1';
$_POST['editval']['oxcountry__d3geoipcur'] = '-1';
}
$this->save();
}
public function save()
{
$myConfig = $this->getConfig();
//allow malladmin only to perform this action
if ( !$myConfig->getConfigParam( 'blAllowSharedEdit' ) )
return;
$soxId = oxConfig::getParameter( "oxid");
$aParams = oxConfig::getParameter( "editval" );
$oCountry = oxNew( "oxcountry" );
if ( $soxId != "-1") {
$oCountry->loadInLang( $this->_iEditLang, $soxId );
} else {
$aParams['oxcountry__oxid'] = null;
}
//$aParams = $oCountry->ConvertNameArray2Idx( $aParams);
$oCountry->setLanguage(0);
$oCountry->assign( $aParams );
$oCountry->setLanguage($this->_iEditLang);
$oCountry = oxUtilsFile::getInstance()->processFiles( $oCountry );
$oCountry->save();
$this->_aViewData["updatelist"] = "1";
// set oxid if inserted
if ( $soxId == "-1")
oxSession::setVar( "saved_oxid", $oCountry->oxcountry__oxid->value);
}
public function getShopList()
{
return $this->oShopList;
}
public function getCurList()
{
$aCurrencies = array();
$sQ = "select DECODE( oxvarvalue, '".$this->getConfig()->getConfigParam( 'sConfigKey' )."') as oxvarvalue from oxconfig where oxshopid = '".$this->oCountry->getFieldData('d3geoipshop')."' AND oxvarname = 'aCurrencies'";
$sCurs = oxDb::getDb(1)->getOne($sQ);
foreach (unserialize($sCurs) as $sKey => $sValue)
{
$aFields = explode('@', $sValue);
$aCurrencies[$sKey]->id = $sKey;
$aCurrencies[$sKey]->name = $aFields[0];
$aCurrencies[$sKey]->sign = $aFields[4];
}
return $aCurrencies;
}
public function getLangList()
{
$aLanguages = array();
$aLangParams = $this->getConfig()->getShopConfVar('aLanguageParams', $this->oCountry->getFieldData('d3geoipshop'));
$aConfLanguages = $this->getConfig()->getShopConfVar('aLanguages', $this->oCountry->getFieldData('d3geoipshop'));
if ( is_array( $aConfLanguages ) ) {
$i = 0;
reset( $aConfLanguages );
while ( list( $key, $val ) = each( $aConfLanguages ) ) {
if ( $blOnlyActive && is_array($aLangParams) ) {
//skipping non active languages
if ( !$aLangParams[$key]['active'] ) {
$i++;
continue;
}
}
if ( $val) {
$oLang = new oxStdClass();
if ( isset($aLangParams[$key]['baseId']) ) {
$oLang->id = $aLangParams[$key]['baseId'];
} else {
$oLang->id = $i;
}
$oLang->oxid = $key;
$oLang->abbr = $key;
$oLang->name = $val;
if ( is_array($aLangParams) ) {
$oLang->active = $aLangParams[$key]['active'];
$oLang->sort = $aLangParams[$key]['sort'];
}
if ( isset( $iLanguage ) && $oLang->id == $iLanguage ) {
$oLang->selected = 1;
} else {
$oLang->selected = 0;
}
if ($oLang->active)
$aLanguages[$oLang->id] = $oLang;
}
++$i;
}
}
if ( $blSort && is_array($aLangParams) ) {
uasort( $aLanguages, array($this, '_sortLanguagesCallback') );
}
return $aLanguages;
}
protected function _sortLanguagesCallback( $oLang1, $oLang2 )
{
$sSortParam = $this->_sDefSort;
$sVal1 = is_string($oLang1->$sSortParam) ? strtolower( $oLang1->$sSortParam ) : $oLang1->$sSortParam;
$sVal2 = is_string($oLang2->$sSortParam) ? strtolower( $oLang2->$sSortParam ) : $oLang2->$sSortParam;
if ( $this->_sDefSortOrder == 'asc' ) {
return ($sVal1 < $sVal2) ? -1 : 1;
} else {
return ($sVal1 > $sVal2) ? -1 : 1;
}
}
}

View File

@ -27,11 +27,11 @@ class d3GeoIP extends oxI18n
{
$sIP = $_SERVER['REMOTE_ADDR'];
/*
$sIP = '62.4.77.32';
$sIP = '62.4.77.48';
$sIP = '41.188.100.127';
*/
// $sIP = '62.4.77.32'; // Deutschland
// $sIP = '62.4.77.48'; // Deutschland
// $sIP = '41.188.100.127'; // Mauretanien
// $sIP = '4.18.40.144'; // US
$iIPNum = $this->_getNumIp($sIP);
$sISOAlpha = $this->LoadByIPNum($iIPNum);
@ -57,12 +57,13 @@ class d3GeoIP extends oxI18n
public function getCountryObject($sISOAlpha)
{
$oCountry = &oxNew('oxcountry');
$sSelect = "SELECT oxid FROM ".$oCountry->getViewName()." WHERE OXISOALPHA2 = '".$sISOAlpha."'";
$sSelect = "SELECT oxid FROM ".$oCountry->getViewName()." WHERE OXISOALPHA2 = '".$sISOAlpha."' AND OXACTIVE = '1'";
$oCountry->load(oxDb::getDb()->getOne($sSelect));
return $oCountry;
}
/*
public function setUserCountry()
{
if (!$this->getUser()) {
@ -75,17 +76,18 @@ class d3GeoIP extends oxI18n
return;
}
*/
public function setCountryLanguage()
{
$oCountry = $this->getUserLocationCountryObject();
$aCountryLangs = $this->getConfig()->getConfigParam('aCountryLangs');
if (!$this->getSession()->getVar('d3isSetLang') && $aCountryLangs && $oCountry->getFieldData('oxisoalpha2') && isset($aCountryLangs[$oCountry->getFieldData('oxisoalpha2')]))
$this->performShopSwitch();
if (!$this->isAdmin() && oxUtils::getInstance()->isSearchEngine() === false && $this->getSession()->getVar('d3isSetLang') === null && $oCountry->getId() && $oCountry->getFieldData('d3geoiplang') > -1)
{
$iNewLanguage = $aCountryLangs[$oCountry->getFieldData('oxisoalpha2')];
oxLang::getInstance()->setTplLanguage((int) $iNewLanguage);
oxLang::getInstance()->setBaseLanguage((int) $iNewLanguage);
oxLang::getInstance()->setTplLanguage((int) $oCountry->getFieldData('d3geoiplang'));
oxLang::getInstance()->setBaseLanguage((int) $oCountry->getFieldData('d3geoiplang'));
$this->getSession()->setVar('d3isSetLang', true);
}
@ -94,14 +96,51 @@ class d3GeoIP extends oxI18n
public function setCountryCurrency()
{
$oCountry = $this->getUserLocationCountryObject();
$aCountryCurrs = $this->getConfig()->getConfigParam('aCountryCurrs');
if (!$this->getSession()->getVar('d3isSetCurr') && $aCountryCurrs && $oCountry->getFieldData('oxisoalpha2') && isset($aCountryCurrs[$oCountry->getFieldData('oxisoalpha2')]))
if (!$this->isAdmin() && oxUtils::getInstance()->isSearchEngine() === false && !$this->getSession()->getVar('d3isSetCurr') && $oCountry->getId() && $oCountry->getFieldData('d3geoipcur') > -1)
{
$iNewCurrency = $aCountryCurrs[$oCountry->getFieldData('oxisoalpha2')];
$this->getConfig()->setActShopCurrency((int) $iNewCurrency );
$this->getConfig()->setActShopCurrency((int) $oCountry->getFieldData('d3geoipcur'));
$this->getSession()->setVar('d3isSetCurr', true);
}
}
public function performShopSwitch()
{
$oCountry = $this->getUserLocationCountryObject();
$iNewShop = $oCountry->getFieldData('d3geoipshop');
$aShopLinks = $this->getShopUrls();
if (!$this->isAdmin() && oxUtils::getInstance()->isSearchEngine() === false && $oCountry->getId() && $this->getConfig()->isMall() && $iNewShop > -1 && $iNewShop != $this->getConfig()->getShopId())
{
$oNewConf = new oxConfig();
$oNewConf->setShopId($iNewShop);
$oNewConf->init();
$this->getConfig()->onShopChange();
if (!$this->getSession()->getVar('d3isSetLang') && $oCountry->getFieldData('d3geoiplang') > -1)
$sLangId = $oCountry->getFieldData('d3geoiplang');
else
$sLangId = '';
header("Location: ".$oNewConf->getShopHomeUrl($sLangId));
exit();
}
}
public function getShopUrls()
{
$oShoplist = oxNew( 'oxshoplist' );
$oShoplist->getList();
$aShopUrls = array();
foreach ( $oShoplist as $sId => $oShop ) {
$aShopUrls[$sId] = $this->getConfig()->getShopConfVar( 'sMallShopURL', $sId );
}
return $aShopUrls;
}
}

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="ISO-8859-15"?>
<OX>
<OXMENU id="NAVIGATION_ESHOPADMIN">
<MAINMENU id="mxmainmenu">
<SUBMENU id="mxcountries" cl="country" list="country_list">
<TAB id="tbclcountry_geoip" cl="d3_country_geoip" />
</SUBMENU>
</MAINMENU>
</OXMENU>
</OX>

View File

@ -7,7 +7,7 @@ class d3_oxcmp_cur_geoip extends d3_oxcmp_cur_geoip_parent
{
$oLocation = &oxNew('d3geoip');
$oLocation->setUserCountry();
//$oLocation->setUserCountry();
$oLocation->setCountryCurrency();
return parent::init();

View File

@ -5,7 +5,7 @@ class d3_oxcmp_lang_geoip extends d3_oxcmp_lang_geoip_parent
public function init()
{
$oLocation = &oxNew('d3geoip');
$oLocation->setUserCountry();
//$oLocation->setUserCountry();
$oLocation->setCountryLanguage();
return parent::init();

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,110 @@
[{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign}]
<script type="text/javascript">
<!--
window.onload = function ()
{
[{ if $updatelist == 1}]
top.oxid.admin.updateList('[{ $oxid }]');
[{ /if}]
var oField = top.oxid.admin.getLockTarget();
oField.onchange = oField.onkeyup = oField.onmouseout = top.oxid.admin.unlockSave;
}
//-->
</script>
[{ if $readonly }]
[{assign var="readonly" value="readonly disabled"}]
[{else}]
[{assign var="readonly" value=""}]
[{/if}]
<form name="transfer" id="transfer" action="[{ $shop->selflink }]" method="post">
[{ $shop->hiddensid }]
<input type="hidden" name="oxid" value="[{ $oxid }]">
<input type="hidden" name="oxidCopy" value="[{ $oxid }]">
<input type="hidden" name="cl" value="country_main">
<input type="hidden" name="language" value="[{ $actlang }]">
</form>
<form name="myedit" id="myedit" action="[{ $shop->selflink }]" method="post">
[{ $shop->hiddensid }]
<input type="hidden" name="cl" value="d3_country_geoip">
<input type="hidden" name="fnc" value="">
<input type="hidden" name="oxid" value="[{ $oxid }]">
<input type="hidden" name="voxid" value="[{ $oxid }]">
<input type="hidden" name="oxparentid" value="[{ $oxparentid }]">
<input type="hidden" name="editval[oxcountry__oxid]" value="[{ $oxid }]">
<input type="hidden" name="language" value="[{ $actlang }]">
<table cellspacing="0" cellpadding="0" border="0" width="98%">
<tr>
<td valign="top" class="edittext">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td class="edittext" width="120">
[{oxmultilang ident="D3_GEOIP_SELSHOP"}]:
</td>
<td class="edittext">
<SELECT name="editval[oxcountry__d3geoipshop]" class="edittext" onchange="document.getElementById('myedit').fnc.value = 'saveshop'; document.getElementById('myedit').submit();">
<option value="-1">[{oxmultilang ident="D3_GEOIP_CUSTSELSHOP"}]</option>
[{foreach from=$oView->getShopList() item=shop}]
<option value="[{$shop->oxshops__oxid->value}]" [{if $edit->oxcountry__d3geoipshop->value == $shop->oxshops__oxid->value}]selected[{/if}]>[{$shop->oxshops__oxname->value}]</option>
[{/foreach}]
</SELECT>
</td>
</tr>
<tr>
<td class="edittext">
[{oxmultilang ident="D3_GEOIP_SELLANG"}]:
</td>
<td class="edittext">
<SELECT name="editval[oxcountry__d3geoiplang]" class="edittext">
<option value="-1">[{oxmultilang ident="D3_GEOIP_CUSTSELLANG"}]</option>
[{foreach from=$oView->getLangList() item=lang}]
<option value="[{$lang->id}]" [{if $edit->oxcountry__d3geoiplang->value == $lang->id}]selected[{/if}]>[{$lang->name}]</option>
[{/foreach}]
</SELECT>
</td>
</tr>
<tr>
<td class="edittext">
[{oxmultilang ident="D3_GEOIP_SELCUR"}]:
</td>
<td class="edittext">
<SELECT name="editval[oxcountry__d3geoipcur]" class="edittext">
<option value="-1">[{oxmultilang ident="D3_GEOIP_CUSTSELCUR"}]</option>
[{foreach from=$oView->getCurList() item=cur}]
<option value="[{$cur->id}]" [{if $edit->oxcountry__d3geoipcur->value == $cur->id}]selected[{/if}]>[{$cur->name}] ([{$cur->sign}])</option>
[{/foreach}]
</SELECT>
</td>
</tr>
<tr>
<td class="edittext"><br><br>
</td>
<td class="edittext"><br><br>
<input type="submit" class="edittext" id="oLockButton" name="saveArticle" value="[{ oxmultilang ident="GENERAL_SAVE" }]" onClick="Javascript:document.myedit.fnc.value='save'"" [{ $readonly }] [{ if !$edit->oxcountry__oxtitle->value && !$oxparentid }]disabled[{/if}]><br>
</td>
</tr>
</table>
</td>
<!-- Anfang rechte Seite -->
<td valign="top" class="edittext" align="left" width="55%">
</td>
<!-- Ende rechte Seite -->
</tr>
</table>
</form>
[{include file="bottomnaviitem.tpl"}]
[{include file="bottomitem.tpl"}]

108757
setup+doku/geoip.sql Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,72 @@
oxcmp_cur => d3_geoip/views/d3_oxcmp_cur_geoip
oxcmp_lang => d3_geoip/views/d3_oxcmp_lang_geoip
********************************************************************************************
* *
* Modul "GeoIP-Kundenleitsystem" für OXID eSales Version EE 4.2.0 *
* Version 1.0 (30.10.2009) *
* Datenbasis: MaxMind GeoLite Country, Version Oktober 2009
* (C) D³ Data Development *
* Bearbeiter: DS *
* *
********************************************************************************************
* *
* Bei Fragen, Kritiken bzw. Probleme erreichen Sie uns wie folgt: *
* *
* D³ Data Development *
* Herr Thomas Dartsch *
* Stollberger Straße 23 *
* 09380, Thalheim *
* *
* Tel.: 03721-268090 *
* *
* http://www.shopmodule.com *
* info@shopmodule.com *
* *
* Achtung: Für Fehlermeldungen und Supportanfragen bitte ausschließlich folgende *
* Emailadresse nutzen: support@shopmodule.com *
* *
********************************************************************************************
Voraussetzung: OXID eShop Version ab EE 4.2.0
Installation:
-------------
1) Kopieren Sie bitte die im Verzeichnis "copy_this" liegenden Dateien in den Shop. Achten Sie darauf, daß
speziell die PHP-Dateien im Binär-Modus übertragen werden. Behalten Sie die Verzeichnisstruktur bei!
2) Modul aktivieren über Admin -> Stammdaten -> Grundeinstellungen -> System -> Textfeld "Module"
Hier Folgendes eintragen:
oxcmp_cur => d3_geoip/views/d3_oxcmp_cur_geoip
oxcmp_lang => d3_geoip/views/d3_oxcmp_lang_geoip
Achtung: Wenn in Ihrem Shop bereits die genannten Klassen per Modul erweitert wurde, muß das Modul an die
bestehende Erweiterung gehängt werden.
Beispiel:
oxcmp_lang => anderes_oxcmp_lang_Modul&d3_geoip/views/d3_oxcmp_lang_geoip
3) Liegt dem Modul eine Datei "install.sql" bei, führen Sie diese bitte im Adminbereich unter "Service => Tools" aus.
4) Führen Sie an der selben Stelle bitte auch die Datei "geoip.sql" aus.
5) Fügen Sie ind ei config.inc.php folgende Variable:
$this->blForceSessionStart = true;
6) Leeren Sie bitte unbedingt das Verzeichnis /tmp im Shop.
7) Im Adminbereich unter "Stammdaten -> Länder -> GeoIP-Kundenumleitungen" können Sie nun einstellen, welche Kunden
an welche Stelle umgeleitet werden sollen.
config.inc.php:
Wir wünschen Ihnen mit Ihrem neuen Modul viel Erfolg.
// Key ist ISO-Alpha2-Code in Großbuchstaben (analog Datenbank) // Value ist ID der Sprache (beginnend bei 0)
$this->aCountryLangs = array();
$this->aCountryLangs['DE'] = 0;
$this->aCountryLangs['EN'] = 1;
$this->aCountryLangs['MR'] = 1;
==================== Anmerkung zur Datenbasis ==============================
// Key ist ISO-Alpha2-Code in Großbuchstaben (analog Datenbank) // Value ist ID der Währung (beginnend bei 0)
$this->aCountryCurrs = array();
$this->aCountryCurrs['DE'] = 0;
$this->aCountryCurrs['EN'] = 1;
$this->aCountryCurrs['MR'] = 1;
Dieses Modul verwendet als Datenbasis die GeoIP-Daten der Firma MaxMind. In der Standard-Installation wird die
im Kopfbereich dieses Dokuments genannte Version installiert.
Nach dem aktuellen Stand gibt MaxMind eine Genauigkeit von 99,5 % für die Lite-Version vor. MaxMind bietet gegen
Entgelt auch eine genauere Version an, die zum Beispiel die Unterscheidung der AOL-User verstehen soll. Bei Bedarf
können Sie die Datenbank mit der aktuellen Fassung beider Versionen updaten. Solang sich an der Struktur der Daten
nichts ändert, können diese mit diesem Shopmodul verwendet werden.
Nähere Informationen zu den Produkten der Firma MaxMind finden Sie auf deren Homepage unter www.maxmind.com