shop_config.php

Go to the documentation of this file.
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             //$soxId = oxSession::getVar("actshop");
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             // for reloading upper frame
00037             $this->_aViewData["updatelist"] =  "1";
00038         }
00039 
00040         if ( $soxId != "-1" && isset( $soxId)) {
00041             // load object
00042             $this->_aViewData["edit"] = $oShop = $this->_getEditShop( $soxId );
00043 
00044             try {
00045                 // category choose list
00046                 $oCatTree = oxNew( "oxCategoryList" );
00047                 $oCatTree->buildList($myConfig->getConfigParam( 'bl_perfLoadCatTree' ));
00048 
00049                 foreach($oCatTree as $key => $val) {
00050                     if ( $val->oxcategories__oxid->value == $oShop->oxshops__oxdefcat->value) {
00051                         $val->selected = 1;
00052                         $oCatTree[$key] = $val;
00053                         break;
00054                     }
00055                 }
00056                 $this->_aViewData["cattree"]     =  $oCatTree;
00057             } catch ( Exception $oExcp ) {
00058                 // on most cases this means that views are broken, so just
00059                 // outputting notice and keeping functionality flow ..
00060                 $this->_aViewData["updateViews"] = 1;
00061             }
00062         }
00063 
00064         // check if we right now saved a new entry
00065         $sSavedID = oxConfig::getParameter( "saved_oxid");
00066 
00067         $aConfBools = array();
00068         $aConfStrs = array();
00069         $aConfArrs = array();
00070         $aConfAarrs = array();
00071 
00072 
00073         $rs = oxDb::getDb()->Execute("select oxvarname, oxvartype, DECODE( oxvarvalue, '".$myConfig->getConfigParam( 'sConfigKey' )."') as oxvarvalue from oxconfig where oxshopid = '$soxId'");
00074         if ($rs != false && $rs->recordCount() > 0) {
00075             $oStr = getStr();
00076             while (!$rs->EOF) {
00077                 $sVarName = $rs->fields[0];
00078                 $sVarType = $rs->fields[1];
00079                 $sVarVal  = $rs->fields[2];
00080 
00081                 if ($sVarType == "bool")
00082                     $aConfBools[$sVarName] = ($sVarVal == "true" || $sVarVal == "1");
00083                 if ($sVarType == "str" || $sVarType == "int") {
00084                     $aConfStrs[$sVarName] = $sVarVal;
00085                     if ( $aConfStrs[$sVarName] ) {
00086                         $aConfStrs[$sVarName] = $oStr->htmlentities( $aConfStrs[$sVarName] );
00087                     }
00088                 }
00089                 if ($sVarType == "arr") {
00090                     if (in_array($sVarName, $this->_aSkipMultiline)) {
00091                         $aConfArrs[$sVarName] = unserialize( $sVarVal );
00092                     } else {
00093                         $aConfArrs[$sVarName] = $oStr->htmlentities( $this->_arrayToMultiline( unserialize( $sVarVal ) ) );
00094                     }
00095                 }
00096                 if ($sVarType == "aarr") {
00097                     if (in_array($sVarName, $this->_aSkipMultiline)) {
00098                         $aConfAarrs[$sVarName] = unserialize( $sVarVal );
00099                     } else {
00100                         $aConfAarrs[$sVarName] = $oStr->htmlentities( $this->_aarrayToMultiline( unserialize( $sVarVal ) ) );
00101                     }
00102                 }
00103                 $rs->moveNext();
00104             }
00105         }
00106 
00107         $aConfStrs["sVersion"] = $myConfig->getConfigParam( 'sVersion' );
00108 
00109         $this->_aViewData["confbools"] = $aConfBools;
00110         $this->_aViewData["confstrs"] = $aConfStrs;
00111         $this->_aViewData["confarrs"] = $aConfArrs;
00112         $this->_aViewData["confaarrs"] = $aConfAarrs;
00113 
00114         $this->_aViewData["confarrs"] =  $aConfArrs;
00115 
00116         // #251A passing country list
00117         $oCountryList = oxNew( "oxCountryList" );
00118         $oCountryList->loadActiveCountries( oxLang::getInstance()->getTplLanguage() );
00119 
00120         if ( isset($aConfArrs["aHomeCountry"]) && count($aConfArrs["aHomeCountry"]) && count($oCountryList)) {
00121             foreach ( $oCountryList as $sCountryId => $oCountry) {
00122                 if ( in_array($oCountry->oxcountry__oxid->value, $aConfArrs["aHomeCountry"]))
00123                     $oCountryList[$sCountryId]->selected = "1";
00124             }
00125         }
00126 
00127         $this->_aViewData["countrylist"] = $oCountryList;
00128 
00129         return $this->_sThisTemplate;
00130     }
00131 
00137     public function saveConfVars()
00138     {
00139         $myConfig = $this->getConfig();
00140 
00141 
00142         $soxId      = oxConfig::getParameter( "oxid" );
00143         $aConfBools = oxConfig::getParameter( "confbools" );
00144         $aConfStrs  = oxConfig::getParameter( "confstrs" );
00145         $aConfArrs  = oxConfig::getParameter( "confarrs" );
00146         $aConfAarrs = oxConfig::getParameter( "confaarrs" );
00147 
00148         // special case for min order price value
00149         if ( $aConfStrs['iMinOrderPrice'] ) {
00150             $aConfStrs['iMinOrderPrice'] = str_replace( ',', '.', $aConfStrs['iMinOrderPrice'] );
00151         }
00152 
00153         if ( is_array( $aConfBools ) ) {
00154             foreach ( $aConfBools as $sVarName => $sVarVal ) {
00155                 $myConfig->saveShopConfVar( "bool", $sVarName, $sVarVal, $soxId );
00156             }
00157         }
00158 
00159         if ( is_array( $aConfStrs ) ) {
00160             foreach ( $aConfStrs as $sVarName => $sVarVal ) {
00161                 $myConfig->saveShopConfVar( "str", $sVarName, $sVarVal, $soxId );
00162             }
00163         }
00164 
00165         if ( is_array( $aConfArrs ) ) {
00166             foreach ( $aConfArrs as $sVarName => $sVarVal ) {
00167                 // home country multiple selectlist feature
00168                 if ( is_array( $sVarVal ) ) {
00169                     $sValue = serialize($sVarVal);
00170                 } else {
00171                     $sValue = serialize($this->_multilineToArray($sVarVal));
00172                 }
00173                 $myConfig->saveShopConfVar("arr", $sVarName, $sValue, $soxId);
00174             }
00175         }
00176 
00177         if ( is_array( $aConfAarrs ) ) {
00178             foreach ( $aConfAarrs as $sVarName => $sVarVal ) {
00179                 $myConfig->saveShopConfVar( "aarr", $sVarName, serialize( $this->_multilineToAarray( $sVarVal ) ), $soxId );
00180             }
00181         }
00182     }
00183 
00189     public function save()
00190     {
00191         // saving config params
00192         $this->saveConfVars();
00193 
00194         //saving additional fields ("oxshops__oxdefcat"") that goes directly to shop (not config)
00195         $soxId   = oxConfig::getParameter( "oxid" );
00196         $aParams = oxConfig::getParameter( "editval" );
00197 
00198         $oShop = oxNew( "oxshop" );
00199         $oShop->load( $soxId);
00200         $oShop->assign( $aParams);
00201         $oShop->save();
00202 
00203         oxUtils::getInstance()->rebuildCache();
00204     }
00205 
00206 
00214     protected function _arrayToMultiline($aInput)
00215     {
00216         if (!is_array($aInput)) {
00217             return '';
00218         }
00219         return implode("\n", $aInput);
00220     }
00221 
00229     protected function _multilineToArray($sMultiline)
00230     {
00231         $aArr = explode("\n", $sMultiline);
00232 
00233         if (!is_array($aArr))
00234             return ;
00235 
00236         foreach ($aArr as $key=>$val) {
00237             $aArr[$key] = trim($val);
00238             if ($aArr[$key] == "")
00239                 unset($aArr[$key]);
00240         }
00241         return $aArr;
00242     }
00243 
00251     protected function _aarrayToMultiline($aInput)
00252     {
00253         $sMultiline = "";
00254 
00255         if (!is_array($aInput))
00256             return ;
00257 
00258         foreach ($aInput as $key => $val) {
00259             $sMultiline .= $key." => ".$val."\n";
00260         }
00261         $sMultiline = getStr()->substr($sMultiline, 0, -1);
00262         return $sMultiline;
00263     }
00264 
00272     protected function _multilineToAarray($sMultiline)
00273     {
00274         $aArr = array();
00275 
00276         $aLines = explode("\n", $sMultiline);
00277 
00278         foreach ($aLines as $sLine) {
00279             $sLine = trim($sLine);
00280             if ($sLine != "" && ereg("(.+)=>(.+)", $sLine, $regs)) {
00281                 $key = trim($regs[1]);
00282                 $val = trim($regs[2]);
00283                 if ($key != "" && $val != "")
00284                     $aArr[$key] = $val;
00285             }
00286         }
00287 
00288         return $aArr;
00289     }
00290 
00291 }

Generated on Wed Apr 22 12:26:30 2009 for OXID eShop CE by  doxygen 1.5.5