add getDb() changes, add perl import script

This commit is contained in:
Daniel Seifert 2012-06-15 13:49:09 +00:00
parent b75fb10507
commit d76f56d1d8
8 changed files with 223 additions and 217 deletions

6
.gitattributes vendored
View File

@ -32,6 +32,12 @@ setup+doku/geoip_data_parts/6.sql -text
setup+doku/geoip_data_parts/7.sql -text setup+doku/geoip_data_parts/7.sql -text
setup+doku/geoip_data_parts/8.sql -text setup+doku/geoip_data_parts/8.sql -text
setup+doku/licence.txt -text setup+doku/licence.txt -text
sources/CSVtoSQLconvert_perl.zip -text
sources/Doku/Drucken[!!-~]-[!!-~]Bartomedia[!!-~]-[!!-~]Web[!!-~]Design[!!-~]Distinction_[!!-~]Geo[!!-~]IP[!!-~]-[!!-~]install[!!-~]Maxmind[!!-~]GeoIP[!!-~]using[!!-~]PHP[!!-~]+[!!-~]MySQL.pdf -text svneol=unset#unset
sources/Doku/Drucken[!!-~]-[!!-~]Bartomedia[!!-~]-[!!-~]Web[!!-~]Design[!!-~]Distinction_[!!-~]Maxmind[!!-~]GeoIP[!!-~]install[!!-~]setup[!!-~]tutorial[!!-~]using[!!-~]PHPMyAdmin.pdf -text
sources/Doku/Drucken[!!-~]-[!!-~]MaxMind[!!-~]Forum[!!-~]•[!!-~]View[!!-~]topic[!!-~]-[!!-~]Fast[!!-~]SQL[!!-~]Queries[!!-~]Using[!!-~]the[!!-~]CSV[!!-~]Database.pdf -text
sources/Doku/Drucken[!!-~]-[!!-~]On[!!-~]efficiently[!!-~]geo-referencing[!!-~]IPs[!!-~]with[!!-~]MaxMind[!!-~]GeoIP[!!-~]and[!!-~]MySQL[!!-~]GIS[!!-~]«[!!-~]Jeremy[!!-~]Cole.pdf -text svneol=unset#unset
sources/Doku/Drucken[!!-~]-[!!-~]Vincent[!!-~]de[!!-~]Lau_[!!-~]HOW-TO[!!-~]Import[!!-~]the[!!-~]MaxMind[!!-~]GeoIP[!!-~]Free[!!-~]Country[!!-~]CSV[!!-~]file[!!-~]into[!!-~]MySQL[!!-~]and[!!-~]save[!!-~]diskspace.pdf -text svneol=unset#unset
sources/GeoIP-Installation.docx -text sources/GeoIP-Installation.docx -text
sources/GeoIPCountryCSV.zip -text sources/GeoIPCountryCSV.zip -text
sources/GeoIPv6.csv/GeoIPv6-20120304.csv -text sources/GeoIPv6.csv/GeoIPv6-20120304.csv -text

View File

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

Binary file not shown.