shop_config.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Shop_Config extends oxAdminDetails
00010 {
00011     protected $_sThisTemplate = 'shop_config.tpl';
00012     protected $_aSkipMultiline = array('aRssSelected', 'aHomeCountry', 'iShopID_TrustedShops');
00013 
00020     public function render()
00021     {
00022         $myConfig  = $this->getConfig();
00023 
00024         parent::render();
00025 
00026 
00027         $soxId = oxConfig::getParameter( "oxid");
00028         if ( !$soxId)
00029             $soxId = $myConfig->getShopId();
00030             //$soxId = oxSession::getVar("actshop");
00031 
00032         $sSavedID = oxConfig::getParameter( "saved_oxid");
00033         if ( ($soxId == "-1" || !isset( $soxId)) && isset( $sSavedID) ) {
00034             $soxId = $sSavedID;
00035             oxSession::deleteVar( "saved_oxid");
00036             $this->_aViewData["oxid"] =  $soxId;
00037             // for reloading upper frame
00038             $this->_aViewData["updatelist"] =  "1";
00039         }
00040 
00041         if ( $soxId != "-1" && isset( $soxId)) {
00042             // load object
00043             $oShop = oxNew( "oxshop" );
00044             $oShop->load( $soxId);
00045             $this->_aViewData["edit"] =  $oShop;
00046 
00047             try {
00048                 // category choose list
00049                 $oCatTree = oxNew( "oxCategoryList" );
00050                 $oCatTree->buildList($myConfig->getConfigParam( 'bl_perfLoadCatTree' ));
00051 
00052                 foreach($oCatTree as $key => $val) {
00053                     if ( $val->oxcategories__oxid->value == $oShop->oxshops__oxdefcat->value) {
00054                         $val->selected = 1;
00055                         $oCatTree[$key] = $val;
00056                         break;
00057                     }
00058                 }
00059                 $this->_aViewData["cattree"]     =  $oCatTree;
00060             } catch ( Exception $oExcp ) {
00061                 // on most cases this means that views are broken, so just
00062                 // outputting notice and keeping functionality flow ..
00063                 $this->_aViewData["updateViews"] = 1;
00064             }
00065         }
00066 
00067         // check if we right now saved a new entry
00068         $sSavedID = oxConfig::getParameter( "saved_oxid");
00069 
00070         $aConfBools = array();
00071         $aConfStrs = array();
00072         $aConfArrs = array();
00073         $aConfAarrs = array();
00074 
00075 
00076         $rs = oxDb::getDb()->Execute("select oxvarname, oxvartype, DECODE( oxvarvalue, '".$myConfig->getConfigParam( 'sConfigKey' )."') as oxvarvalue from oxconfig where oxshopid = '$soxId'");
00077         if ($rs != false && $rs->recordCount() > 0) {
00078             while (!$rs->EOF) {
00079                 $sVarName = $rs->fields[0];
00080                 $sVarType = $rs->fields[1];
00081                 $sVarVal  = $rs->fields[2];
00082 
00083                 if ($sVarType == "bool")
00084                     $aConfBools[$sVarName] = ($sVarVal == "true" || $sVarVal == "1");
00085                 if ($sVarType == "str" || $sVarType == "int") {
00086                     $aConfStrs[$sVarName] = $sVarVal;
00087                     if ( $aConfStrs[$sVarName] ) {
00088                         $aConfStrs[$sVarName] = htmlentities( $aConfStrs[$sVarName] );
00089                     }
00090                 }
00091                 if ($sVarType == "arr") {
00092                     if (in_array($sVarName, $this->_aSkipMultiline)) {
00093                         $aConfArrs[$sVarName] = unserialize( $sVarVal );
00094                     } else {
00095                         $aConfArrs[$sVarName] = htmlentities( $this->_arrayToMultiline( unserialize( $sVarVal ) ) );
00096                     }
00097                 }
00098                 if ($sVarType == "aarr") {
00099                     if (in_array($sVarName, $this->_aSkipMultiline)) {
00100                         $aConfAarrs[$sVarName] = unserialize( $sVarVal );
00101                     } else {
00102                         $aConfAarrs[$sVarName] = htmlentities( $this->_aarrayToMultiline( unserialize( $sVarVal ) ) );
00103                     }
00104                 }
00105                 $rs->moveNext();
00106             }
00107         }
00108 
00109         $aConfStrs["sVersion"] = $myConfig->getConfigParam( 'sVersion' );
00110 
00111         $this->_aViewData["confbools"] = $aConfBools;
00112         $this->_aViewData["confstrs"] = $aConfStrs;
00113         $this->_aViewData["confarrs"] = $aConfArrs;
00114         $this->_aViewData["confaarrs"] = $aConfAarrs;
00115 
00116         $this->_aViewData["confarrs"] =  $aConfArrs;
00117 
00118         // #251A passing country list
00119         $oCountryList = oxNew( "oxCountryList" );
00120         $oCountryList->loadActiveCountries( oxLang::getInstance()->getTplLanguage() );
00121 
00122         if ( isset($aConfArrs["aHomeCountry"]) && count($aConfArrs["aHomeCountry"]) && count($oCountryList)) {
00123             foreach ( $oCountryList as $sCountryId => $oCountry) {
00124                 if ( in_array($oCountry->oxcountry__oxid->value, $aConfArrs["aHomeCountry"]))
00125                     $oCountryList[$sCountryId]->selected = "1";
00126             }
00127         }
00128 
00129         $this->_aViewData["countrylist"] = $oCountryList;
00130 
00131         return $this->_sThisTemplate;
00132     }
00133 
00139     public function saveConfVars()
00140     {
00141         $myConfig = $this->getConfig();
00142 
00143 
00144         $soxId      = oxConfig::getParameter( "oxid" );
00145         $aConfBools = oxConfig::getParameter( "confbools" );
00146         $aConfStrs  = oxConfig::getParameter( "confstrs" );
00147         $aConfArrs  = oxConfig::getParameter( "confarrs" );
00148         $aConfAarrs = oxConfig::getParameter( "confaarrs" );
00149 
00150         // special case for min order price value
00151         if ( $aConfStrs['iMinOrderPrice'] ) {
00152             $aConfStrs['iMinOrderPrice'] = str_replace( ',', '.', $aConfStrs['iMinOrderPrice'] );
00153         }
00154 
00155         if ( is_array( $aConfBools ) ) {
00156             foreach ( $aConfBools as $sVarName => $sVarVal ) {
00157                 $myConfig->saveShopConfVar( "bool", $sVarName, $sVarVal, $soxId );
00158             }
00159         }
00160 
00161         if ( is_array( $aConfStrs ) ) {
00162             foreach ( $aConfStrs as $sVarName => $sVarVal ) {
00163                 $myConfig->saveShopConfVar( "str", $sVarName, $sVarVal, $soxId );
00164             }
00165         }
00166 
00167         if ( is_array( $aConfArrs ) ) {
00168             foreach ( $aConfArrs as $sVarName => $sVarVal ) {
00169                 // home country multiple selectlist feature
00170                 if ( is_array( $sVarVal ) ) {
00171                     $sValue = serialize($sVarVal);
00172                 } else {
00173                     $sValue = serialize($this->_multilineToArray($sVarVal));
00174                 }
00175                 $myConfig->saveShopConfVar("arr", $sVarName, $sValue, $soxId);
00176             }
00177         }
00178 
00179         // on language array change all shop SEO urls must be revalidated
00180         if ( isset( $aConfAarrs['aLanguages'] ) && serialize( $this->_multilineToAarray( $aConfAarrs['aLanguages'] ) ) != serialize( $myConfig->getShopConfVar( 'aLanguages', $soxId ) ) ) {
00181             $this->resetSeoData( $soxId );
00182         }
00183 
00184         if ( is_array( $aConfAarrs ) ) {
00185             foreach ( $aConfAarrs as $sVarName => $sVarVal ) {
00186                 $myConfig->saveShopConfVar( "aarr", $sVarName, serialize( $this->_multilineToAarray( $sVarVal ) ), $soxId );
00187             }
00188         }
00189     }
00190 
00196     public function save()
00197     {
00198         // saving config params
00199         $this->saveConfVars();
00200 
00201         //saving additional fields ("oxshops__oxdefcat"") that goes directly to shop (not config)
00202         $soxId   = oxConfig::getParameter( "oxid" );
00203         $aParams = oxConfig::getParameter( "editval" );
00204 
00205         $oShop = oxNew( "oxshop" );
00206         $oShop->load( $soxId);
00207         $oShop->assign( $aParams);
00208         $oShop->save();
00209 
00210         oxUtils::getInstance()->rebuildCache();
00211 
00212         return $this->autosave();
00213     }
00214 
00215 
00223     protected function _arrayToMultiline($aInput)
00224     {
00225         if (!is_array($aInput)) {
00226             return '';
00227         }
00228         return implode("\n", $aInput);
00229     }
00230 
00238     protected function _multilineToArray($sMultiline)
00239     {
00240         $aArr = explode("\n", $sMultiline);
00241 
00242         if (!is_array($aArr))
00243             return ;
00244 
00245         foreach ($aArr as $key=>$val) {
00246             $aArr[$key] = trim($val);
00247             if ($aArr[$key] == "")
00248                 unset($aArr[$key]);
00249         }
00250         return $aArr;
00251     }
00252 
00260     protected function _aarrayToMultiline($aInput)
00261     {
00262         $sMultiline = "";
00263 
00264         if (!is_array($aInput))
00265             return ;
00266 
00267         foreach ($aInput as $key => $val) {
00268             $sMultiline .= $key." => ".$val."\n";
00269         }
00270         $sMultiline = substr($sMultiline, 0, -1);
00271         return $sMultiline;
00272     }
00273 
00281     protected function _multilineToAarray($sMultiline)
00282     {
00283         $aArr = array();
00284 
00285         $aLines = explode("\n", $sMultiline);
00286 
00287         foreach ($aLines as $sLine) {
00288             $sLine = trim($sLine);
00289             if ($sLine != "" && ereg("(.+)=>(.+)", $sLine, $regs)) {
00290                 $key = trim($regs[1]);
00291                 $val = trim($regs[2]);
00292                 if ($key != "" && $val != "")
00293                     $aArr[$key] = $val;
00294             }
00295         }
00296 
00297         return $aArr;
00298     }
00299 
00300 }

Generated on Fri Dec 19 14:20:28 2008 for OXID eShop CE by  doxygen 1.5.5