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         if ( is_array( $aConfAarrs ) ) {
00179             foreach ( $aConfAarrs as $sVarName => $sVarVal ) {
00180                 $myConfig->saveShopConfVar( "aarr", $sVarName, serialize( $this->_multilineToAarray( $sVarVal ) ), $soxId );
00181             }
00182         }
00183     }
00184 
00190     public function save()
00191     {
00192         // saving config params
00193         $this->saveConfVars();
00194 
00195         //saving additional fields ("oxshops__oxdefcat"") that goes directly to shop (not config)
00196         $soxId   = oxConfig::getParameter( "oxid" );
00197         $aParams = oxConfig::getParameter( "editval" );
00198 
00199         $oShop = oxNew( "oxshop" );
00200         $oShop->load( $soxId);
00201         $oShop->assign( $aParams);
00202         $oShop->save();
00203 
00204         oxUtils::getInstance()->rebuildCache();
00205 
00206         return $this->autosave();
00207     }
00208 
00209 
00217     protected function _arrayToMultiline($aInput)
00218     {
00219         if (!is_array($aInput)) {
00220             return '';
00221         }
00222         return implode("\n", $aInput);
00223     }
00224 
00232     protected function _multilineToArray($sMultiline)
00233     {
00234         $aArr = explode("\n", $sMultiline);
00235 
00236         if (!is_array($aArr))
00237             return ;
00238 
00239         foreach ($aArr as $key=>$val) {
00240             $aArr[$key] = trim($val);
00241             if ($aArr[$key] == "")
00242                 unset($aArr[$key]);
00243         }
00244         return $aArr;
00245     }
00246 
00254     protected function _aarrayToMultiline($aInput)
00255     {
00256         $sMultiline = "";
00257 
00258         if (!is_array($aInput))
00259             return ;
00260 
00261         foreach ($aInput as $key => $val) {
00262             $sMultiline .= $key." => ".$val."\n";
00263         }
00264         $sMultiline = substr($sMultiline, 0, -1);
00265         return $sMultiline;
00266     }
00267 
00275     protected function _multilineToAarray($sMultiline)
00276     {
00277         $aArr = array();
00278 
00279         $aLines = explode("\n", $sMultiline);
00280 
00281         foreach ($aLines as $sLine) {
00282             $sLine = trim($sLine);
00283             if ($sLine != "" && ereg("(.+)=>(.+)", $sLine, $regs)) {
00284                 $key = trim($regs[1]);
00285                 $val = trim($regs[2]);
00286                 if ($key != "" && $val != "")
00287                     $aArr[$key] = $val;
00288             }
00289         }
00290 
00291         return $aArr;
00292     }
00293 
00294 }

Generated on Thu Dec 4 12:04:56 2008 for OXID eShop CE by  doxygen 1.5.5