2012-06-15 15:49:09 +02:00
|
|
|
<?php
|
2013-04-22 11:40:11 +02:00
|
|
|
/**
|
|
|
|
* This Software is the property of Data Development and is protected
|
|
|
|
* by copyright law - it is NOT Freeware.
|
|
|
|
*
|
|
|
|
* Any unauthorized use of this software without a valid license
|
|
|
|
* is a violation of the license agreement and will be prosecuted by
|
|
|
|
* civil and criminal law.
|
|
|
|
*
|
|
|
|
* http://www.shopmodule.com
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <ds@shopmodule.com>
|
|
|
|
* @link http://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
2020-04-17 09:29:09 +02:00
|
|
|
namespace D3\GeoIp\Application\Controller\Admin;
|
|
|
|
|
|
|
|
use D3\ModCfg\Application\Model\Configuration\d3_cfg_mod;
|
2020-06-10 10:28:16 +02:00
|
|
|
use Doctrine\DBAL\DBALException;
|
2020-04-17 09:29:09 +02:00
|
|
|
use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
|
2020-06-10 10:28:16 +02:00
|
|
|
use OxidEsales\Eshop\Application\Model\Country;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Shop;
|
|
|
|
use OxidEsales\Eshop\Application\Model\ShopList;
|
2020-04-17 09:29:09 +02:00
|
|
|
use OxidEsales\Eshop\Core\DatabaseProvider;
|
2020-06-10 10:28:16 +02:00
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
|
2020-04-17 09:29:09 +02:00
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
use stdClass;
|
|
|
|
|
|
|
|
class d3_country_geoip extends AdminDetailsController
|
2012-06-15 15:49:09 +02:00
|
|
|
{
|
|
|
|
protected $_sDefSort = 'sort';
|
2013-04-22 11:40:11 +02:00
|
|
|
protected $_sDefSortOrder = 'asc';
|
2012-06-15 15:49:09 +02:00
|
|
|
protected $_sThisTemplate = 'd3_country_geoip.tpl';
|
|
|
|
private $_sModId = 'd3_geoip';
|
2020-06-10 10:28:16 +02:00
|
|
|
/** @var Country */
|
2013-04-22 11:40:11 +02:00
|
|
|
public $oCountry;
|
2020-06-10 10:28:16 +02:00
|
|
|
/** @var ShopList */
|
2013-04-22 11:40:11 +02:00
|
|
|
public $oShopList;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-06-15 15:49:09 +02:00
|
|
|
public function render()
|
|
|
|
{
|
2020-04-17 09:29:09 +02:00
|
|
|
if (false == Registry::getConfig()->getConfigParam('blAllowSharedEdit')) {
|
2015-06-23 11:29:07 +02:00
|
|
|
$this->addTplParam('readonly', true);
|
2013-04-22 11:40:11 +02:00
|
|
|
}
|
2012-06-15 15:49:09 +02:00
|
|
|
|
|
|
|
$ret = parent::render();
|
|
|
|
|
2020-06-10 10:28:16 +02:00
|
|
|
$soxId = Registry::getRequest()->getRequestEscapedParameter("oxid");
|
2012-06-15 15:49:09 +02:00
|
|
|
// check if we right now saved a new entry
|
2020-06-10 10:28:16 +02:00
|
|
|
$sSavedID = Registry::getRequest()->getRequestEscapedParameter("saved_oxid");
|
2015-06-23 11:29:07 +02:00
|
|
|
if (($soxId == "-1" || !isset($soxId)) && isset($sSavedID)) {
|
2012-06-15 15:49:09 +02:00
|
|
|
$soxId = $sSavedID;
|
2020-04-17 09:29:09 +02:00
|
|
|
Registry::getSession()->deleteVariable("saved_oxid");
|
2015-06-23 11:29:07 +02:00
|
|
|
$this->addTplParam("oxid", $soxId);
|
2012-06-15 15:49:09 +02:00
|
|
|
// for reloading upper frame
|
2013-04-22 11:40:11 +02:00
|
|
|
$this->addTplParam("updatelist", "1");
|
2012-06-15 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
2015-06-23 11:29:07 +02:00
|
|
|
if ($soxId != "-1" && isset($soxId)) {
|
2012-06-15 15:49:09 +02:00
|
|
|
// load object
|
2020-06-10 10:28:16 +02:00
|
|
|
/** @var $oCountry Country */
|
|
|
|
$oCountry = oxNew(Country::class);
|
2015-06-23 11:29:07 +02:00
|
|
|
$oCountry->loadInLang($this->_iEditLang, $soxId);
|
|
|
|
|
|
|
|
if ($oCountry->isForeignCountry()) {
|
|
|
|
$this->addTplParam("blForeignCountry", true);
|
|
|
|
} else {
|
|
|
|
$this->addTplParam("blForeignCountry", false);
|
2012-06-15 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$oOtherLang = $oCountry->getAvailableInLangs();
|
2015-06-23 11:29:07 +02:00
|
|
|
if (!isset($oOtherLang[$this->_iEditLang])) {
|
|
|
|
$oCountry->loadInLang(key($oOtherLang), $soxId);
|
2012-06-15 15:49:09 +02:00
|
|
|
}
|
2013-04-22 11:40:11 +02:00
|
|
|
|
|
|
|
$this->oCountry = $oCountry;
|
|
|
|
$this->addTplParam("edit", $oCountry);
|
2012-06-15 15:49:09 +02:00
|
|
|
|
|
|
|
// remove already created languages
|
2020-04-17 09:29:09 +02:00
|
|
|
$aLang = array_diff(Registry::getLang()->getLanguageNames(), $oOtherLang);
|
2013-04-22 11:40:11 +02:00
|
|
|
|
2015-06-23 11:29:07 +02:00
|
|
|
if (count($aLang)) {
|
2013-04-22 11:40:11 +02:00
|
|
|
$this->addTplParam("posslang", $aLang);
|
|
|
|
}
|
2012-06-15 15:49:09 +02:00
|
|
|
|
2015-06-23 11:29:07 +02:00
|
|
|
foreach ($oOtherLang as $id => $language) {
|
2013-04-22 11:40:11 +02:00
|
|
|
$oLang= new stdClass();
|
2012-06-15 15:49:09 +02:00
|
|
|
$oLang->sLangDesc = $language;
|
|
|
|
$oLang->selected = ($id == $this->_iEditLang);
|
|
|
|
$this->_aViewData["otherlang"][$id] = clone $oLang;
|
|
|
|
}
|
2015-06-23 11:29:07 +02:00
|
|
|
} else {
|
|
|
|
$this->addTplParam("blForeignCountry", true);
|
2012-06-15 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 10:28:16 +02:00
|
|
|
$this->oShopList = oxNew(ShopList::class);
|
|
|
|
/** @var $oShop Shop */
|
|
|
|
$oShop = oxNew(Shop::class);
|
2012-06-15 15:49:09 +02:00
|
|
|
$sSelect = "SELECT * FROM ".$oShop->getViewName()." WHERE ".$oShop->getSqlActiveSnippet();
|
|
|
|
$this->oShopList->selectString($sSelect);
|
|
|
|
$this->getLangList();
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2013-04-22 11:40:11 +02:00
|
|
|
/**
|
|
|
|
* @param $sIdent
|
|
|
|
* @return mixed
|
2020-06-10 10:28:16 +02:00
|
|
|
* @throws DBALException
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
2013-04-22 11:40:11 +02:00
|
|
|
*/
|
2012-06-15 15:49:09 +02:00
|
|
|
public function getModCfgValue($sIdent)
|
|
|
|
{
|
2013-04-22 11:40:11 +02:00
|
|
|
return d3_cfg_mod::get($this->_sModId)->getValue($sIdent);
|
2012-06-15 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function saveshop()
|
|
|
|
{
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
|
|
$_POST['editval']['oxcountry__d3geoiplang'] = '-1';
|
|
|
|
$_POST['editval']['oxcountry__d3geoipcur'] = '-1';
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function save()
|
|
|
|
{
|
|
|
|
//allow malladmin only to perform this action
|
2020-04-17 09:29:09 +02:00
|
|
|
if (false == Registry::getConfig()->getConfigParam('blAllowSharedEdit')) {
|
2012-06-15 15:49:09 +02:00
|
|
|
return;
|
2013-04-22 11:40:11 +02:00
|
|
|
}
|
2012-06-15 15:49:09 +02:00
|
|
|
|
2020-06-10 10:28:16 +02:00
|
|
|
$soxId = Registry::getRequest()->getRequestEscapedParameter("oxid");
|
|
|
|
$aParams = Registry::getRequest()->getRequestEscapedParameter("editval");
|
2012-06-15 15:49:09 +02:00
|
|
|
|
2020-06-10 10:28:16 +02:00
|
|
|
/** @var $oCountry Country */
|
|
|
|
$oCountry = oxNew(Country::class);
|
2012-06-15 15:49:09 +02:00
|
|
|
|
2015-06-23 11:29:07 +02:00
|
|
|
if ($soxId != "-1") {
|
|
|
|
$oCountry->loadInLang($this->_iEditLang, $soxId);
|
|
|
|
} else {
|
|
|
|
$aParams['oxcountry__oxid'] = null;
|
2012-06-15 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$oCountry->setLanguage(0);
|
2015-06-23 11:29:07 +02:00
|
|
|
$oCountry->assign($aParams);
|
2012-06-15 15:49:09 +02:00
|
|
|
$oCountry->setLanguage($this->_iEditLang);
|
2020-04-17 09:29:09 +02:00
|
|
|
$oCountry = Registry::get('oxUtilsFile')->processFiles($oCountry);
|
2012-06-15 15:49:09 +02:00
|
|
|
|
|
|
|
$oCountry->save();
|
2013-04-22 11:40:11 +02:00
|
|
|
$this->addTplParam("updatelist", "1");
|
2012-06-15 15:49:09 +02:00
|
|
|
|
|
|
|
// set oxid if inserted
|
2015-06-23 11:29:07 +02:00
|
|
|
if ($soxId == "-1") {
|
2020-04-17 09:29:09 +02:00
|
|
|
Registry::getSession()->setVariable("saved_oxid", $oCountry->getId());
|
2013-04-22 11:40:11 +02:00
|
|
|
}
|
2012-06-15 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
2013-04-22 11:40:11 +02:00
|
|
|
/**
|
2020-06-10 10:28:16 +02:00
|
|
|
* @return ShopList
|
2013-04-22 11:40:11 +02:00
|
|
|
*/
|
2012-06-15 15:49:09 +02:00
|
|
|
public function getShopList()
|
|
|
|
{
|
|
|
|
return $this->oShopList;
|
|
|
|
}
|
|
|
|
|
2013-04-22 11:40:11 +02:00
|
|
|
/**
|
|
|
|
* @return array
|
2020-06-10 10:28:16 +02:00
|
|
|
* @throws DBALException
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
2013-04-22 11:40:11 +02:00
|
|
|
*/
|
2012-06-15 15:49:09 +02:00
|
|
|
public function getCurList()
|
|
|
|
{
|
2016-02-25 17:47:32 +01:00
|
|
|
if ($this->getModCfgValue('blChangeShop')
|
|
|
|
&& $this->oCountry->getFieldData('d3geoipshop')
|
|
|
|
&& $this->oCountry->getFieldData('d3geoipshop') > 0 // -1 is user choice
|
|
|
|
) {
|
2013-04-22 11:28:59 +02:00
|
|
|
$sShopId = $this->oCountry->getFieldData('d3geoipshop');
|
2015-06-23 11:29:07 +02:00
|
|
|
} else {
|
2020-04-17 09:29:09 +02:00
|
|
|
$sShopId = Registry::getConfig()->getActiveView()->getViewConfig()->getActiveShopId();
|
2013-04-22 11:28:59 +02:00
|
|
|
}
|
|
|
|
|
2020-04-17 09:29:09 +02:00
|
|
|
$sQ = "select DECODE( oxvarvalue, '".Registry::getConfig()->getConfigParam('sConfigKey').
|
2015-06-23 11:29:07 +02:00
|
|
|
"') as oxvarvalue from oxconfig where oxshopid = '".$sShopId."' AND oxvarname = 'aCurrencies'";
|
2013-04-22 11:28:59 +02:00
|
|
|
|
2020-04-17 09:29:09 +02:00
|
|
|
$oDB = DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
|
|
|
|
$sCurs = $oDB->getOne($sQ);
|
2013-04-22 11:40:11 +02:00
|
|
|
|
2015-07-21 21:12:55 +02:00
|
|
|
return $this->d3ExtractCurList($sCurs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sCurrencies
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function d3ExtractCurList($sCurrencies)
|
|
|
|
{
|
|
|
|
$aCurrencies = array();
|
|
|
|
|
|
|
|
if ($sCurrencies) {
|
|
|
|
foreach (unserialize($sCurrencies) as $sKey => $sValue) {
|
2013-04-22 11:48:59 +02:00
|
|
|
$aFields = explode('@', $sValue);
|
2020-06-10 10:28:16 +02:00
|
|
|
$cur = new stdClass();
|
|
|
|
$cur->id = trim($sKey);
|
|
|
|
$cur->name = trim($aFields[0]);
|
|
|
|
$cur->sign = trim($aFields[4]);
|
|
|
|
$aCurrencies[$sKey] = $cur;
|
2013-04-22 11:48:59 +02:00
|
|
|
}
|
2012-06-15 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $aCurrencies;
|
|
|
|
}
|
|
|
|
|
2013-04-22 11:40:11 +02:00
|
|
|
/**
|
|
|
|
* ToDo: has to be refactored
|
|
|
|
* @return array
|
2020-06-10 10:28:16 +02:00
|
|
|
* @throws DBALException
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
2013-04-22 11:40:11 +02:00
|
|
|
*/
|
2012-06-15 15:49:09 +02:00
|
|
|
public function getLangList()
|
|
|
|
{
|
2016-02-25 17:47:32 +01:00
|
|
|
if ($this->getModCfgValue('blChangeShop')
|
|
|
|
&& $this->oCountry->getFieldData('d3geoipshop')
|
|
|
|
&& $this->oCountry->getFieldData('d3geoipshop') > 0 // -1 is user choice
|
|
|
|
) {
|
2013-04-22 11:28:59 +02:00
|
|
|
$sShopId = $this->oCountry->getFieldData('d3geoipshop');
|
2015-06-23 11:29:07 +02:00
|
|
|
} else {
|
2020-04-17 09:29:09 +02:00
|
|
|
$sShopId = Registry::getConfig()->getActiveView()->getViewConfig()->getActiveShopId();
|
2013-04-22 11:28:59 +02:00
|
|
|
}
|
2012-06-15 15:49:09 +02:00
|
|
|
|
|
|
|
$aLanguages = array();
|
2020-04-17 09:29:09 +02:00
|
|
|
$aLangParams = Registry::getConfig()->getShopConfVar('aLanguageParams', $sShopId);
|
|
|
|
$aConfLanguages = Registry::getConfig()->getShopConfVar('aLanguages', $sShopId);
|
2012-06-15 15:49:09 +02:00
|
|
|
|
2015-06-23 11:29:07 +02:00
|
|
|
if (is_array($aConfLanguages)) {
|
2012-06-15 15:49:09 +02:00
|
|
|
$i = 0;
|
2015-06-23 11:29:07 +02:00
|
|
|
reset($aConfLanguages);
|
|
|
|
while ((list($key, $val) = each($aConfLanguages))) {
|
|
|
|
if (is_array($aLangParams)) {
|
2012-06-15 15:49:09 +02:00
|
|
|
//skipping non active languages
|
2015-06-23 11:29:07 +02:00
|
|
|
if (false == $aLangParams[$key]['active']) {
|
2012-06-15 15:49:09 +02:00
|
|
|
$i++;
|
2015-06-23 11:29:07 +02:00
|
|
|
continue;
|
2012-06-15 15:49:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-23 11:29:07 +02:00
|
|
|
if ($val) {
|
2013-04-22 11:40:11 +02:00
|
|
|
$oLang = new stdClass();
|
2015-06-23 11:29:07 +02:00
|
|
|
if (isset($aLangParams[$key]['baseId'])) {
|
2012-06-15 15:49:09 +02:00
|
|
|
$oLang->id = $aLangParams[$key]['baseId'];
|
2015-06-23 11:29:07 +02:00
|
|
|
} else {
|
2012-06-15 15:49:09 +02:00
|
|
|
$oLang->id = $i;
|
|
|
|
}
|
|
|
|
$oLang->oxid = $key;
|
|
|
|
$oLang->abbr = $key;
|
|
|
|
$oLang->name = $val;
|
|
|
|
|
2015-06-23 11:29:07 +02:00
|
|
|
if (is_array($aLangParams)) {
|
2012-06-15 15:49:09 +02:00
|
|
|
$oLang->active = $aLangParams[$key]['active'];
|
|
|
|
$oLang->sort = $aLangParams[$key]['sort'];
|
|
|
|
}
|
|
|
|
|
2015-06-23 11:29:07 +02:00
|
|
|
if ($oLang->active) {
|
2012-06-15 15:49:09 +02:00
|
|
|
$aLanguages[$oLang->id] = $oLang;
|
2015-06-23 11:29:07 +02:00
|
|
|
}
|
2012-06-15 15:49:09 +02:00
|
|
|
}
|
|
|
|
++$i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-23 11:29:07 +02:00
|
|
|
if (is_array($aLangParams)) {
|
|
|
|
uasort($aLanguages, array($this, '_sortLanguagesCallback'));
|
2012-06-15 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $aLanguages;
|
|
|
|
}
|
|
|
|
|
2013-04-22 11:40:11 +02:00
|
|
|
/**
|
|
|
|
* @param $oLang1
|
|
|
|
* @param $oLang2
|
|
|
|
* @return int
|
|
|
|
*/
|
2015-06-23 11:29:07 +02:00
|
|
|
protected function _sortLanguagesCallback($oLang1, $oLang2)
|
2012-06-15 15:49:09 +02:00
|
|
|
{
|
|
|
|
$sSortParam = $this->_sDefSort;
|
2015-06-23 11:29:07 +02:00
|
|
|
$sVal1 = is_string($oLang1->$sSortParam) ? strtolower($oLang1->$sSortParam) : $oLang1->$sSortParam;
|
|
|
|
$sVal2 = is_string($oLang2->$sSortParam) ? strtolower($oLang2->$sSortParam) : $oLang2->$sSortParam;
|
2012-06-15 15:49:09 +02:00
|
|
|
|
2015-06-23 11:29:07 +02:00
|
|
|
if ($this->_sDefSortOrder == 'asc') {
|
2012-06-15 15:49:09 +02:00
|
|
|
return ($sVal1 < $sVal2) ? -1 : 1;
|
2015-06-23 11:29:07 +02:00
|
|
|
} else {
|
2012-06-15 15:49:09 +02:00
|
|
|
return ($sVal1 > $sVal2) ? -1 : 1;
|
|
|
|
}
|
|
|
|
}
|
2015-06-23 11:29:07 +02:00
|
|
|
}
|