00001 <?php
00002
00008 class Shop_Config extends oxAdminDetails
00009 {
00010 protected $_sThisTemplate = 'shop_config.tpl';
00011 protected $_aSkipMultiline = array('aHomeCountry', 'iShopID_TrustedShops', 'aTsUser', 'aTsPassword');
00012 protected $_aParseFloat = array('iMinOrderPrice');
00013
00014 protected $_aConfParams = array(
00015 "bool" => 'confbools',
00016 "str" => 'confstrs',
00017 "arr" => 'confarrs',
00018 "aarr" => 'confaarrs',
00019 "select" => 'confselects',
00020 );
00021
00028 public function render()
00029 {
00030 $myConfig = $this->getConfig();
00031
00032 parent::render();
00033
00034
00035 $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
00036 if ( $soxId != "-1" && isset( $soxId)) {
00037
00038 $this->_aViewData["edit"] = $oShop = $this->_getEditShop( $soxId );
00039
00040 try {
00041
00042 $this->_aViewData["defcat"] = null;
00043 if ($oShop->oxshops__oxdefcat->value) {
00044 $oCat = oxNew( "oxCategory" );
00045 if ($oCat->load($oShop->oxshops__oxdefcat->value)) {
00046 $this->_aViewData["defcat"] = $oCat;
00047 }
00048 }
00049 } catch ( Exception $oExcp ) {
00050
00051
00052 $this->_aViewData["updateViews"] = 1;
00053 }
00054
00055 $iAoc = oxConfig::getParameter("aoc");
00056 if ( $iAoc == 1 ) {
00057 include_once 'inc/shop_default_category.inc.php';
00058 $this->_aViewData['oxajax'] = $aColumns;
00059
00060 return "popups/shop_default_category.tpl";
00061 }
00062
00063 }
00064
00065 $aDbVariables = $this->_loadConfVars($soxId, $this->_getModuleForConfigVars());
00066 $aConfVars = $aDbVariables['vars'];
00067 $aConfVars['str']['sVersion'] = $myConfig->getConfigParam( 'sVersion' );
00068
00069 $this->_aViewData["var_constraints"] = $aDbVariables['constraints'];
00070 $this->_aViewData["var_grouping"] = $aDbVariables['grouping'];
00071
00072 foreach ($this->_aConfParams as $sType => $sParam) {
00073 $this->_aViewData[$sParam] = $aConfVars[$sType];
00074 }
00075
00076
00077 $oCountryList = oxNew( "oxCountryList" );
00078 $oCountryList->loadActiveCountries( oxLang::getInstance()->getObjectTplLanguage() );
00079
00080 if ( isset($aConfVars['aarr']["aHomeCountry"]) && count($$aConfVars['aarr']["aHomeCountry"]) && count($oCountryList)) {
00081 foreach ( $oCountryList as $sCountryId => $oCountry) {
00082 if ( in_array($oCountry->oxcountry__oxid->value, $aConfVars['aarr']["aHomeCountry"]))
00083 $oCountryList[$sCountryId]->selected = "1";
00084 }
00085 }
00086
00087 $this->_aViewData["countrylist"] = $oCountryList;
00088
00089
00090 $this->_aViewData["blCurlIsActive"] = ( !function_exists('curl_init') ) ? false : true;
00091
00092 return $this->_sThisTemplate;
00093 }
00094
00100 protected function _getModuleForConfigVars()
00101 {
00102 return '';
00103 }
00104
00110 public function saveConfVars()
00111 {
00112 $myConfig = $this->getConfig();
00113
00114
00115 $sShopId = $this->getEditObjectId();
00116 $sModule = $this->_getModuleForConfigVars();
00117
00118 foreach ($this->_aConfParams as $sType => $sParam) {
00119 $aConfVars = oxConfig::getParameter($sParam);
00120 if (is_array($aConfVars)) {
00121 foreach ( $aConfVars as $sName => $sValue ) {
00122 $myConfig->saveShopConfVar(
00123 $sType,
00124 $sName,
00125 $this->_serializeConfVar($sType, $sName, $sValue),
00126 $sShopId,
00127 $sModule
00128 );
00129 }
00130 }
00131 }
00132 }
00133
00139 public function save()
00140 {
00141
00142 $this->saveConfVars();
00143
00144
00145 $oShop = oxNew( "oxshop" );
00146 if ( $oShop->load( $this->getEditObjectId() ) ) {
00147 $oShop->assign( oxConfig::getParameter( "editval" ) );
00148 $oShop->save();
00149
00150 oxUtils::getInstance()->rebuildCache();
00151 }
00152 }
00153
00166 public function _loadConfVars($sShopId, $sModule)
00167 {
00168 $myConfig = $this->getConfig();
00169 $aConfVars = array(
00170 "bool" => array(),
00171 "str" => array(),
00172 "arr" => array(),
00173 "aarr" => array(),
00174 "select" => array(),
00175 );
00176 $aVarConstraints = array();
00177 $aGrouping = array();
00178 $oDb = oxDb::getDb();
00179 $rs = $oDb->Execute(
00180 "select cfg.oxvarname,
00181 cfg.oxvartype,
00182 DECODE( cfg.oxvarvalue, ".$oDb->quote( $myConfig->getConfigParam( 'sConfigKey' ) ).") as oxvarvalue,
00183 disp.oxvarconstraint,
00184 disp.oxgrouping
00185 from oxconfig as cfg
00186 left join oxconfigdisplay as disp
00187 on cfg.oxmodule=disp.oxcfgmodule and cfg.oxvarname=disp.oxcfgvarname
00188 where cfg.oxshopid = '$sShopId'
00189 and cfg.oxmodule=".$oDb->quote($sModule)."
00190 order by disp.oxpos, cfg.oxvarname"
00191 );
00192
00193 if ($rs != false && $rs->recordCount() > 0) {
00194 while (!$rs->EOF) {
00195 list($sName, $sType, $sValue, $sConstraint, $sGrouping) = $rs->fields;
00196 $aConfVars[$sType][$sName] = $this->_unserializeConfVar($sType, $sName, $sValue);
00197 $aVarConstraints[$sName] = $this->_parseConstraint( $sType, $sConstraint );
00198 if ($sGrouping) {
00199 if (!isset($aGrouping[$sGrouping])) {
00200 $aGrouping[$sGrouping] = array($sName=>$sType);
00201 } else {
00202 $aGrouping[$sGrouping][$sName] = $sType;
00203 }
00204 }
00205 $rs->moveNext();
00206 }
00207 }
00208
00209 return array(
00210 'vars' => $aConfVars,
00211 'constraints' => $aVarConstraints,
00212 'grouping' => $aGrouping,
00213 );
00214 }
00215
00224 protected function _parseConstraint($sType, $sConstraint)
00225 {
00226 switch ($sType) {
00227 case "select":
00228 return array_map('trim', explode('|', $sConstraint));
00229 break;
00230 }
00231 return null;
00232 }
00233
00242 protected function _serializeConstraint($sType, $sConstraint)
00243 {
00244 switch ($sType) {
00245 case "select":
00246 return implode('|', array_map('trim', $sConstraint));
00247 break;
00248 }
00249 return '';
00250 }
00251
00261 public function _unserializeConfVar($sType, $sName, $sValue)
00262 {
00263 $oStr = getStr();
00264 $mData = null;
00265
00266 switch ($sType) {
00267 case "bool":
00268 $mData = ($sValue == "true" || $sValue == "1");
00269 break;
00270
00271 case "str":
00272 case "select":
00273 case "int":
00274 if (in_array($sName, $this->_aParseFloat)) {
00275 $mData = str_replace( ',', '.', $mData );
00276 }
00277 $mData = $oStr->htmlentities( $sValue );
00278 break;
00279
00280 case "arr":
00281 if (in_array($sName, $this->_aSkipMultiline)) {
00282 $mData = unserialize( $sValue );
00283 } else {
00284 $mData = $oStr->htmlentities( $this->_arrayToMultiline( unserialize( $sValue ) ) );
00285 }
00286 break;
00287
00288 case "aarr":
00289 if (in_array($sName, $this->_aSkipMultiline)) {
00290 $mData = unserialize( $sValue );
00291 } else {
00292 $mData = $oStr->htmlentities( $this->_aarrayToMultiline( unserialize( $sValue ) ) );
00293 }
00294 break;
00295 }
00296 return $mData;
00297 }
00298
00308 public function _serializeConfVar($sType, $sName, $mValue)
00309 {
00310 $sData = '';
00311
00312 switch ($sType) {
00313 case "bool":
00314 $sData = $mValue;
00315 break;
00316
00317 case "str":
00318 case "select":
00319 case "int":
00320 if (in_array($sName, $this->_aParseFloat)) {
00321 $mData = str_replace( ',', '.', $mData );
00322 }
00323 $sData = $mValue;
00324 break;
00325
00326 case "arr":
00327 $sData = $mValue;
00328 if ( !is_array( $mValue ) ) {
00329 $sData = $this->_multilineToArray( $mValue );
00330 }
00331 break;
00332
00333 case "aarr":
00334 $sData = $this->_multilineToAarray( $mValue );
00335 break;
00336 }
00337 return $sData;
00338 }
00339
00347 protected function _arrayToMultiline( $aInput )
00348 {
00349 $sVal = '';
00350 if ( is_array( $aInput ) ) {
00351 $sVal = implode( "\n", $aInput );
00352 }
00353 return $sVal;
00354 }
00355
00363 protected function _multilineToArray( $sMultiline )
00364 {
00365 $aArr = explode( "\n", $sMultiline );
00366 if ( is_array( $aArr ) ) {
00367 foreach ( $aArr as $sKey => $sVal ) {
00368 $aArr[$sKey] = trim( $sVal );
00369 if ( $aArr[$sKey] == "" ) {
00370 unset( $aArr[$sKey] );
00371 }
00372 }
00373 return $aArr;
00374 }
00375 }
00376
00384 protected function _aarrayToMultiline( $aInput )
00385 {
00386 if ( is_array( $aInput ) ) {
00387 $sMultiline = '';
00388 foreach ( $aInput as $sKey => $sVal ) {
00389 if ( $sMultiline ) {
00390 $sMultiline .= "\n";
00391 }
00392 $sMultiline .= $sKey." => ".$sVal;
00393 }
00394 return $sMultiline;
00395 }
00396 }
00397
00405 protected function _multilineToAarray( $sMultiline )
00406 {
00407 $oStr = getStr();
00408 $aArr = array();
00409 $aLines = explode( "\n", $sMultiline );
00410 foreach ( $aLines as $sLine ) {
00411 $sLine = trim( $sLine );
00412 if ( $sLine != "" && $oStr->preg_match( "/(.+)=>(.+)/", $sLine, $aRegs ) ) {
00413 $sKey = trim( $aRegs[1] );
00414 $sVal = trim( $aRegs[2] );
00415 if ( $sKey != "" && $sVal != "" ) {
00416 $aArr[$sKey] = $sVal;
00417 }
00418 }
00419 }
00420
00421 return $aArr;
00422 }
00423
00429 public function getEditObjectId()
00430 {
00431 $sEditId = parent::getEditObjectId();
00432 if ( !$sEditId ) {
00433 return $this->getConfig()->getShopId();
00434 } else {
00435 return $sEditId;
00436 }
00437 }
00438
00439 }