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('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 choosen as default
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                 // on most cases this means that views are broken, so just
00055                 // outputting notice and keeping functionality flow ..
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         // check if we right now saved a new entry
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         // #251A passing country list
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         // special case for min order price value
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 => $aVarVal ) {
00172                 // home country multiple selectlist feature
00173                 if ( !is_array( $aVarVal ) ) {
00174                     $aVarVal = $this->_multilineToArray( $aVarVal );
00175                 }
00176                 $myConfig->saveShopConfVar( "arr", $sVarName, $aVarVal, $sOxId );
00177             }
00178         }
00179 
00180         if ( is_array( $aConfAarrs ) ) {
00181             foreach ( $aConfAarrs as $sVarName => $aVarVal ) {
00182                 $myConfig->saveShopConfVar( "aarr", $sVarName, $this->_multilineToAarray( $aVarVal ), $sOxId );
00183             }
00184         }
00185     }
00186 
00192     public function save()
00193     {
00194         // saving config params
00195         $this->saveConfVars();
00196 
00197         //saving additional fields ("oxshops__oxdefcat"") that goes directly to shop (not config)
00198         $oShop = oxNew( "oxshop" );
00199         if ( $oShop->load( oxConfig::getParameter( "oxid" ) ) ) {
00200             $oShop->assign( oxConfig::getParameter( "editval" ) );
00201             $oShop->save();
00202 
00203             oxUtils::getInstance()->rebuildCache();
00204         }
00205     }
00206 
00207 
00215     protected function _arrayToMultiline( $aInput )
00216     {
00217         $sVal = '';
00218         if ( is_array( $aInput ) ) {
00219             $sVal = implode( "\n", $aInput );
00220         }
00221         return $sVal;
00222     }
00223 
00231     protected function _multilineToArray( $sMultiline )
00232     {
00233         $aArr = explode( "\n", $sMultiline );
00234         if ( is_array( $aArr ) ) {
00235             foreach ( $aArr as $sKey => $sVal ) {
00236                 $aArr[$sKey] = trim( $sVal );
00237                 if ( $aArr[$sKey] == "" ) {
00238                     unset( $aArr[$sKey] );
00239                 }
00240             }
00241             return $aArr;
00242         }
00243     }
00244 
00252     protected function _aarrayToMultiline( $aInput )
00253     {
00254         if ( is_array( $aInput ) ) {
00255             $sMultiline = '';
00256             foreach ( $aInput as $sKey => $sVal ) {
00257                 if ( $sMultiline ) {
00258                     $sMultiline .= "\n";
00259                 }
00260                 $sMultiline .= $sKey." => ".$sVal;
00261             }
00262             return $sMultiline;
00263         }
00264     }
00265 
00273     protected function _multilineToAarray( $sMultiline )
00274     {
00275         $aArr = array();
00276         $aLines = explode( "\n", $sMultiline );
00277         foreach ( $aLines as $sLine ) {
00278             $sLine = trim( $sLine );
00279             if ( $sLine != "" && preg_match( "/(.+)=>(.+)/", $sLine, $aRegs ) ) {
00280                 $sKey = trim( $aRegs[1] );
00281                 $sVal = trim( $aRegs[2] );
00282                 if ( $sKey != "" && $sVal != "" ) {
00283                     $aArr[$sKey] = $sVal;
00284                 }
00285             }
00286         }
00287 
00288         return $aArr;
00289     }
00290 
00291 }

Generated by  doxygen 1.6.2