00001 <?php
00002
00008 class Shop_Config extends oxAdminDetails
00009 {
00010 protected $_sThisTemplate = 'shop_config.tpl';
00011 protected $_aSkipMultiline = array('aRssSelected', 'aHomeCountry', 'iShopID_TrustedShops');
00012
00019 public function render()
00020 {
00021 $myConfig = $this->getConfig();
00022
00023 parent::render();
00024
00025
00026 $soxId = oxConfig::getParameter( "oxid");
00027 if ( !$soxId)
00028 $soxId = $myConfig->getShopId();
00029
00030
00031 $sSavedID = oxConfig::getParameter( "saved_oxid");
00032 if ( ($soxId == "-1" || !isset( $soxId)) && isset( $sSavedID) ) {
00033 $soxId = $sSavedID;
00034 oxSession::deleteVar( "saved_oxid");
00035 $this->_aViewData["oxid"] = $soxId;
00036
00037 $this->_aViewData["updatelist"] = "1";
00038 }
00039
00040 if ( $soxId != "-1" && isset( $soxId)) {
00041
00042 $this->_aViewData["edit"] = $oShop = $this->_getEditShop( $soxId );
00043
00044 try {
00045
00046 $this->_aViewData["defcat"] = null;
00047 if ($oShop->oxshops__oxdefcat->value) {
00048 $oCat = oxNew( "oxCategory" );
00049 if ($oCat->load($oShop->oxshops__oxdefcat->value)) {
00050 $this->_aViewData["defcat"] = $oCat;
00051 }
00052 }
00053 } catch ( Exception $oExcp ) {
00054
00055
00056 $this->_aViewData["updateViews"] = 1;
00057 }
00058
00059 $iAoc = oxConfig::getParameter("aoc");
00060 if ( $iAoc == 1 ) {
00061 include_once 'inc/shop_default_category.inc.php';
00062 $this->_aViewData['oxajax'] = $aColumns;
00063
00064 return "popups/shop_default_category.tpl";
00065 }
00066
00067 }
00068
00069
00070 $sSavedID = oxConfig::getParameter( "saved_oxid");
00071
00072 $aConfBools = array();
00073 $aConfStrs = array();
00074 $aConfArrs = array();
00075 $aConfAarrs = array();
00076
00077 $oDb = oxDb::getDb();
00078 $rs = $oDb->Execute("select oxvarname, oxvartype, DECODE( oxvarvalue, ".$oDb->quote( $myConfig->getConfigParam( 'sConfigKey' ) ).") as oxvarvalue from oxconfig where oxshopid = '$soxId'");
00079 if ($rs != false && $rs->recordCount() > 0) {
00080 $oStr = getStr();
00081 while (!$rs->EOF) {
00082 $sVarName = $rs->fields[0];
00083 $sVarType = $rs->fields[1];
00084 $sVarVal = $rs->fields[2];
00085
00086 if ($sVarType == "bool")
00087 $aConfBools[$sVarName] = ($sVarVal == "true" || $sVarVal == "1");
00088 if ($sVarType == "str" || $sVarType == "int") {
00089 $aConfStrs[$sVarName] = $sVarVal;
00090 if ( $aConfStrs[$sVarName] ) {
00091 $aConfStrs[$sVarName] = $oStr->htmlentities( $aConfStrs[$sVarName] );
00092 }
00093 }
00094 if ($sVarType == "arr") {
00095 if (in_array($sVarName, $this->_aSkipMultiline)) {
00096 $aConfArrs[$sVarName] = unserialize( $sVarVal );
00097 } else {
00098 $aConfArrs[$sVarName] = $oStr->htmlentities( $this->_arrayToMultiline( unserialize( $sVarVal ) ) );
00099 }
00100 }
00101 if ($sVarType == "aarr") {
00102 if (in_array($sVarName, $this->_aSkipMultiline)) {
00103 $aConfAarrs[$sVarName] = unserialize( $sVarVal );
00104 } else {
00105 $aConfAarrs[$sVarName] = $oStr->htmlentities( $this->_aarrayToMultiline( unserialize( $sVarVal ) ) );
00106 }
00107 }
00108 $rs->moveNext();
00109 }
00110 }
00111
00112 $aConfStrs["sVersion"] = $myConfig->getConfigParam( 'sVersion' );
00113
00114 $this->_aViewData["confbools"] = $aConfBools;
00115 $this->_aViewData["confstrs"] = $aConfStrs;
00116 $this->_aViewData["confarrs"] = $aConfArrs;
00117 $this->_aViewData["confaarrs"] = $aConfAarrs;
00118
00119 $this->_aViewData["confarrs"] = $aConfArrs;
00120
00121
00122 $oCountryList = oxNew( "oxCountryList" );
00123 $oCountryList->loadActiveCountries( oxLang::getInstance()->getTplLanguage() );
00124
00125 if ( isset($aConfArrs["aHomeCountry"]) && count($aConfArrs["aHomeCountry"]) && count($oCountryList)) {
00126 foreach ( $oCountryList as $sCountryId => $oCountry) {
00127 if ( in_array($oCountry->oxcountry__oxid->value, $aConfArrs["aHomeCountry"]))
00128 $oCountryList[$sCountryId]->selected = "1";
00129 }
00130 }
00131
00132 $this->_aViewData["countrylist"] = $oCountryList;
00133
00134 return $this->_sThisTemplate;
00135 }
00136
00142 public function saveConfVars()
00143 {
00144 $myConfig = $this->getConfig();
00145
00146
00147 $soxId = oxConfig::getParameter( "oxid" );
00148 $aConfBools = oxConfig::getParameter( "confbools" );
00149 $aConfStrs = oxConfig::getParameter( "confstrs" );
00150 $aConfArrs = oxConfig::getParameter( "confarrs" );
00151 $aConfAarrs = oxConfig::getParameter( "confaarrs" );
00152
00153
00154 if ( $aConfStrs['iMinOrderPrice'] ) {
00155 $aConfStrs['iMinOrderPrice'] = str_replace( ',', '.', $aConfStrs['iMinOrderPrice'] );
00156 }
00157
00158 if ( is_array( $aConfBools ) ) {
00159 foreach ( $aConfBools as $sVarName => $sVarVal ) {
00160 $myConfig->saveShopConfVar( "bool", $sVarName, $sVarVal, $soxId );
00161 }
00162 }
00163
00164 if ( is_array( $aConfStrs ) ) {
00165 foreach ( $aConfStrs as $sVarName => $sVarVal ) {
00166 $myConfig->saveShopConfVar( "str", $sVarName, $sVarVal, $soxId );
00167 }
00168 }
00169
00170 if ( is_array( $aConfArrs ) ) {
00171 foreach ( $aConfArrs as $sVarName => $sVarVal ) {
00172
00173 if ( is_array( $sVarVal ) ) {
00174 $sValue = serialize($sVarVal);
00175 } else {
00176 $sValue = serialize($this->_multilineToArray($sVarVal));
00177 }
00178 $myConfig->saveShopConfVar("arr", $sVarName, $sValue, $soxId);
00179 }
00180 }
00181
00182 if ( is_array( $aConfAarrs ) ) {
00183 foreach ( $aConfAarrs as $sVarName => $sVarVal ) {
00184 $myConfig->saveShopConfVar( "aarr", $sVarName, serialize( $this->_multilineToAarray( $sVarVal ) ), $soxId );
00185 }
00186 }
00187 }
00188
00194 public function save()
00195 {
00196
00197 $this->saveConfVars();
00198
00199
00200 $soxId = oxConfig::getParameter( "oxid" );
00201 $aParams = oxConfig::getParameter( "editval" );
00202
00203 $oShop = oxNew( "oxshop" );
00204 $oShop->load( $soxId);
00205 $oShop->assign( $aParams);
00206 $oShop->save();
00207
00208 oxUtils::getInstance()->rebuildCache();
00209 }
00210
00211
00219 protected function _arrayToMultiline($aInput)
00220 {
00221 if (!is_array($aInput)) {
00222 return '';
00223 }
00224 return implode("\n", $aInput);
00225 }
00226
00234 protected function _multilineToArray($sMultiline)
00235 {
00236 $aArr = explode("\n", $sMultiline);
00237
00238 if (!is_array($aArr))
00239 return ;
00240
00241 foreach ($aArr as $key=>$val) {
00242 $aArr[$key] = trim($val);
00243 if ($aArr[$key] == "")
00244 unset($aArr[$key]);
00245 }
00246 return $aArr;
00247 }
00248
00256 protected function _aarrayToMultiline($aInput)
00257 {
00258 $sMultiline = "";
00259
00260 if (!is_array($aInput))
00261 return ;
00262
00263 foreach ($aInput as $key => $val) {
00264 $sMultiline .= $key." => ".$val."\n";
00265 }
00266 $sMultiline = getStr()->substr($sMultiline, 0, -1);
00267 return $sMultiline;
00268 }
00269
00277 protected function _multilineToAarray($sMultiline)
00278 {
00279 $aArr = array();
00280
00281 $aLines = explode("\n", $sMultiline);
00282
00283 foreach ($aLines as $sLine) {
00284 $sLine = trim($sLine);
00285 if ($sLine != "" && preg_match("/(.+)=>(.+)/", $sLine, $regs)) {
00286 $key = trim($regs[1]);
00287 $val = trim($regs[2]);
00288 if ($key != "" && $val != "")
00289 $aArr[$key] = $val;
00290 }
00291 }
00292
00293 return $aArr;
00294 }
00295
00296 }