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', 'aTsUser', 'aTsPassword');
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()->getObjectTplLanguage() );
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         // checking if cUrl is enabled
00135         $this->_aViewData["blCurlIsActive"] = ( !function_exists('curl_init') ) ? false : true;
00136 
00137         return $this->_sThisTemplate;
00138     }
00139 
00145     public function saveConfVars()
00146     {
00147         $myConfig = $this->getConfig();
00148 
00149 
00150         $sOxId      = oxConfig::getParameter( "oxid" );
00151         $aConfBools = oxConfig::getParameter( "confbools" );
00152         $aConfStrs  = oxConfig::getParameter( "confstrs" );
00153         $aConfArrs  = oxConfig::getParameter( "confarrs" );
00154         $aConfAarrs = oxConfig::getParameter( "confaarrs" );
00155 
00156         // special case for min order price value
00157         if ( $aConfStrs['iMinOrderPrice'] ) {
00158             $aConfStrs['iMinOrderPrice'] = str_replace( ',', '.', $aConfStrs['iMinOrderPrice'] );
00159         }
00160 
00161         if ( is_array( $aConfBools ) ) {
00162             foreach ( $aConfBools as $sVarName => $sVarVal ) {
00163                 $myConfig->saveShopConfVar( "bool", $sVarName, $sVarVal, $sOxId );
00164             }
00165         }
00166 
00167         if ( is_array( $aConfStrs ) ) {
00168             foreach ( $aConfStrs as $sVarName => $sVarVal ) {
00169                 $myConfig->saveShopConfVar( "str", $sVarName, $sVarVal, $sOxId );
00170             }
00171         }
00172 
00173         if ( is_array( $aConfArrs ) ) {
00174             foreach ( $aConfArrs as $sVarName => $aVarVal ) {
00175                 // home country multiple selectlist feature
00176                 if ( !is_array( $aVarVal ) ) {
00177                     $aVarVal = $this->_multilineToArray( $aVarVal );
00178                 }
00179                 $myConfig->saveShopConfVar( "arr", $sVarName, $aVarVal, $sOxId );
00180             }
00181         }
00182 
00183         if ( is_array( $aConfAarrs ) ) {
00184             foreach ( $aConfAarrs as $sVarName => $aVarVal ) {
00185                 $myConfig->saveShopConfVar( "aarr", $sVarName, $this->_multilineToAarray( $aVarVal ), $sOxId );
00186             }
00187         }
00188     }
00189 
00195     public function save()
00196     {
00197         // saving config params
00198         $this->saveConfVars();
00199 
00200         //saving additional fields ("oxshops__oxdefcat"") that goes directly to shop (not config)
00201         $oShop = oxNew( "oxshop" );
00202         if ( $oShop->load( oxConfig::getParameter( "oxid" ) ) ) {
00203             $oShop->assign( oxConfig::getParameter( "editval" ) );
00204             $oShop->save();
00205 
00206             oxUtils::getInstance()->rebuildCache();
00207         }
00208     }
00209 
00210 
00218     protected function _arrayToMultiline( $aInput )
00219     {
00220         $sVal = '';
00221         if ( is_array( $aInput ) ) {
00222             $sVal = implode( "\n", $aInput );
00223         }
00224         return $sVal;
00225     }
00226 
00234     protected function _multilineToArray( $sMultiline )
00235     {
00236         $aArr = explode( "\n", $sMultiline );
00237         if ( is_array( $aArr ) ) {
00238             foreach ( $aArr as $sKey => $sVal ) {
00239                 $aArr[$sKey] = trim( $sVal );
00240                 if ( $aArr[$sKey] == "" ) {
00241                     unset( $aArr[$sKey] );
00242                 }
00243             }
00244             return $aArr;
00245         }
00246     }
00247 
00255     protected function _aarrayToMultiline( $aInput )
00256     {
00257         if ( is_array( $aInput ) ) {
00258             $sMultiline = '';
00259             foreach ( $aInput as $sKey => $sVal ) {
00260                 if ( $sMultiline ) {
00261                     $sMultiline .= "\n";
00262                 }
00263                 $sMultiline .= $sKey." => ".$sVal;
00264             }
00265             return $sMultiline;
00266         }
00267     }
00268 
00276     protected function _multilineToAarray( $sMultiline )
00277     {
00278         $oStr = getStr();
00279         $aArr = array();
00280         $aLines = explode( "\n", $sMultiline );
00281         foreach ( $aLines as $sLine ) {
00282             $sLine = trim( $sLine );
00283             if ( $sLine != "" && $oStr->preg_match( "/(.+)=>(.+)/", $sLine, $aRegs ) ) {
00284                 $sKey = trim( $aRegs[1] );
00285                 $sVal = trim( $aRegs[2] );
00286                 if ( $sKey != "" && $sVal != "" ) {
00287                     $aArr[$sKey] = $sVal;
00288                 }
00289             }
00290         }
00291 
00292         return $aArr;
00293     }
00294 
00295 }