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
*/
2012-06-15 15:49:09 +02:00
class d3_country_geoip extends oxAdminView
{
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' ;
2013-04-22 11:40:11 +02:00
/** @var oxcountry */
public $oCountry ;
/** @var oxshoplist */
public $oShopList ;
/**
* @ return string
*/
2012-06-15 15:49:09 +02:00
public function render ()
{
2013-04-22 11:40:11 +02:00
if ( ! oxRegistry :: getConfig () -> getConfigParam ( 'blAllowSharedEdit' ) )
{
$this -> addTplParam ( 'readonly' , TRUE );
}
2012-06-15 15:49:09 +02:00
$ret = parent :: render ();
2013-04-22 11:40:11 +02:00
$soxId = oxRegistry :: getConfig () -> getRequestParameter ( " oxid " );
2012-06-15 15:49:09 +02:00
// check if we right now saved a new entry
2013-04-22 11:40:11 +02:00
$sSavedID = oxRegistry :: getConfig () -> getRequestParameter ( " saved_oxid " );
if ( ( $soxId == " -1 " || ! isset ( $soxId )) && isset ( $sSavedID ) )
{
2012-06-15 15:49:09 +02:00
$soxId = $sSavedID ;
2013-04-22 11:40:11 +02:00
oxRegistry :: getSession () -> deleteVariable ( " saved_oxid " );
$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
}
2013-04-22 11:40:11 +02:00
if ( $soxId != " -1 " && isset ( $soxId ))
{
2012-06-15 15:49:09 +02:00
// load object
2013-04-22 11:40:11 +02:00
/** @var $oCountry oxcountry */
2012-06-15 15:49:09 +02:00
$oCountry = oxNew ( " oxcountry " );
$oCountry -> loadInLang ( $this -> _iEditLang , $soxId );
2013-04-22 11:40:11 +02:00
if ( $oCountry -> isForeignCountry ())
{
$this -> addTplParam ( " blForeignCountry " , TRUE );
}
else
{
$this -> addTplParam ( " blForeignCountry " , FALSE );
2012-06-15 15:49:09 +02:00
}
$oOtherLang = $oCountry -> getAvailableInLangs ();
2013-04-22 11:40:11 +02:00
if ( ! isset ( $oOtherLang [ $this -> _iEditLang ]))
{
2012-06-15 15:49:09 +02:00
$oCountry -> loadInLang ( key ( $oOtherLang ), $soxId );
}
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
2013-04-22 11:40:11 +02:00
$aLang = array_diff ( oxRegistry :: getLang () -> getLanguageNames (), $oOtherLang );
2012-06-15 15:49:09 +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
2013-04-22 11:40:11 +02:00
foreach ( $oOtherLang as $id => $language )
{
$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 ;
}
2013-04-22 11:40:11 +02:00
}
else
{
$this -> addTplParam ( " blForeignCountry " , TRUE );
2012-06-15 15:49:09 +02:00
}
2013-04-22 11:40:11 +02:00
$this -> oShopList = oxNew ( 'oxshoplist' );
/** @var $oShop oxshop */
$oShop = oxNew ( 'oxshop' );
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
*/
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
2013-04-22 11:40:11 +02:00
if ( ! oxRegistry :: 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
2013-04-22 11:40:11 +02:00
$soxId = oxRegistry :: getConfig () -> getRequestParameter ( " oxid " );
$aParams = oxRegistry :: getConfig () -> getRequestParameter ( " editval " );
2012-06-15 15:49:09 +02:00
2013-04-22 11:40:11 +02:00
/** @var $oCountry oxcountry */
2012-06-15 15:49:09 +02:00
$oCountry = oxNew ( " oxcountry " );
2013-04-22 11:40:11 +02:00
if ( $soxId != " -1 " )
{
2012-06-15 15:49:09 +02:00
$oCountry -> loadInLang ( $this -> _iEditLang , $soxId );
2013-04-22 11:40:11 +02:00
}
else
{
$aParams [ 'oxcountry__oxid' ] = NULL ;
2012-06-15 15:49:09 +02:00
}
$oCountry -> setLanguage ( 0 );
$oCountry -> assign ( $aParams );
$oCountry -> setLanguage ( $this -> _iEditLang );
2013-04-22 11:40:11 +02:00
$oCountry = oxRegistry :: 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
if ( $soxId == " -1 " )
2013-04-22 11:40:11 +02:00
{
oxRegistry :: getSession () -> setVariable ( " saved_oxid " , $oCountry -> getId ());
}
2012-06-15 15:49:09 +02:00
}
2013-04-22 11:40:11 +02:00
/**
* @ return oxshoplist
*/
2012-06-15 15:49:09 +02:00
public function getShopList ()
{
return $this -> oShopList ;
}
2013-04-22 11:40:11 +02:00
/**
* @ return array
*/
2012-06-15 15:49:09 +02:00
public function getCurList ()
{
$aCurrencies = array ();
2013-04-22 11:28:59 +02:00
if ( $this -> getModCfgValue ( 'blChangeShop' ) && $this -> oCountry -> getFieldData ( 'd3geoipshop' ))
{
$sShopId = $this -> oCountry -> getFieldData ( 'd3geoipshop' );
}
else
{
2013-04-22 11:40:11 +02:00
$sShopId = oxRegistry :: getConfig () -> getActiveView () -> getViewConfig () -> getActiveShopId ();
2013-04-22 11:28:59 +02:00
}
$sQ = " select DECODE( oxvarvalue, ' " . $this -> getConfig () -> getConfigParam ( 'sConfigKey' ) . " ') as oxvarvalue from oxconfig where oxshopid = ' " . $sShopId . " ' AND oxvarname = 'aCurrencies' " ;
2013-04-22 11:40:11 +02:00
$sCurs = oxDb :: getDb ( oxDb :: FETCH_MODE_ASSOC ) -> getOne ( $sQ );
2013-04-22 11:48:59 +02:00
if ( $sCurs )
2012-06-15 15:49:09 +02:00
{
2013-04-22 11:48:59 +02:00
foreach ( unserialize ( $sCurs ) as $sKey => $sValue )
{
$aFields = explode ( '@' , $sValue );
$aCurrencies [ $sKey ] -> id = $sKey ;
$aCurrencies [ $sKey ] -> name = $aFields [ 0 ];
$aCurrencies [ $sKey ] -> sign = $aFields [ 4 ];
}
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
*/
2012-06-15 15:49:09 +02:00
public function getLangList ()
{
2013-04-22 11:28:59 +02:00
if ( $this -> getModCfgValue ( 'blChangeShop' ) && $this -> oCountry -> getFieldData ( 'd3geoipshop' ))
{
$sShopId = $this -> oCountry -> getFieldData ( 'd3geoipshop' );
}
else
{
2013-04-22 11:40:11 +02:00
$sShopId = oxRegistry :: getConfig () -> getActiveView () -> getViewConfig () -> getActiveShopId ();
2013-04-22 11:28:59 +02:00
}
2012-06-15 15:49:09 +02:00
$aLanguages = array ();
2013-04-22 11:40:11 +02:00
$aLangParams = oxRegistry :: getConfig () -> getShopConfVar ( 'aLanguageParams' , $sShopId );
$aConfLanguages = oxRegistry :: getConfig () -> getShopConfVar ( 'aLanguages' , $sShopId );
2012-06-15 15:49:09 +02:00
2013-04-22 11:40:11 +02:00
if ( is_array ( $aConfLanguages ) )
{
2012-06-15 15:49:09 +02:00
$i = 0 ;
reset ( $aConfLanguages );
2013-04-22 11:40:11 +02:00
while ( list ( $key , $val ) = each ( $aConfLanguages ) )
{
if ( is_array ( $aLangParams ) )
{
2012-06-15 15:49:09 +02:00
//skipping non active languages
2013-04-22 11:40:11 +02:00
if ( ! $aLangParams [ $key ][ 'active' ] )
{
2012-06-15 15:49:09 +02:00
$i ++ ;
continue ;
}
}
2013-04-22 11:40:11 +02:00
if ( $val )
{
$oLang = new stdClass ();
if ( isset ( $aLangParams [ $key ][ 'baseId' ]) )
{
2012-06-15 15:49:09 +02:00
$oLang -> id = $aLangParams [ $key ][ 'baseId' ];
2013-04-22 11:40:11 +02:00
}
else
{
2012-06-15 15:49:09 +02:00
$oLang -> id = $i ;
}
$oLang -> oxid = $key ;
$oLang -> abbr = $key ;
$oLang -> name = $val ;
2013-04-22 11:40:11 +02:00
if ( is_array ( $aLangParams ) )
{
2012-06-15 15:49:09 +02:00
$oLang -> active = $aLangParams [ $key ][ 'active' ];
$oLang -> sort = $aLangParams [ $key ][ 'sort' ];
}
2013-04-22 11:40:11 +02:00
if ( isset ( $iLanguage ) && $oLang -> id == $iLanguage )
{
2012-06-15 15:49:09 +02:00
$oLang -> selected = 1 ;
2013-04-22 11:40:11 +02:00
}
else
{
2012-06-15 15:49:09 +02:00
$oLang -> selected = 0 ;
}
if ( $oLang -> active )
$aLanguages [ $oLang -> id ] = $oLang ;
}
++ $i ;
}
}
2013-04-22 11:40:11 +02:00
if ( is_array ( $aLangParams ) ) {
2012-06-15 15:49:09 +02:00
uasort ( $aLanguages , array ( $this , '_sortLanguagesCallback' ) );
}
return $aLanguages ;
}
2013-04-22 11:40:11 +02:00
/**
* @ param $oLang1
* @ param $oLang2
* @ return int
*/
2012-06-15 15:49:09 +02:00
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 ;
2013-04-22 11:40:11 +02:00
if ( $this -> _sDefSortOrder == 'asc' )
{
2012-06-15 15:49:09 +02:00
return ( $sVal1 < $sVal2 ) ? - 1 : 1 ;
2013-04-22 11:40:11 +02:00
}
else
{
2012-06-15 15:49:09 +02:00
return ( $sVal1 > $sVal2 ) ? - 1 : 1 ;
}
}
2009-12-15 10:05:46 +01:00
}