OXID eShop CE  4.9.6
 All Classes Files Functions Variables Pages
shop_config.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
11  protected $_sThisTemplate = 'shop_config.tpl';
12  protected $_aSkipMultiline = array('aHomeCountry', 'iShopID_TrustedShops', 'aTsUser', 'aTsPassword');
13  protected $_aParseFloat = array('iMinOrderPrice');
14 
15  protected $_aConfParams = array(
16  "bool" => 'confbools',
17  "str" => 'confstrs',
18  "arr" => 'confarrs',
19  "aarr" => 'confaarrs',
20  "select" => 'confselects',
21  "num" => 'confnum',
22  );
23 
30  public function render()
31  {
32  $myConfig = $this->getConfig();
33 
35 
36  $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
37  if ($soxId != "-1" && isset($soxId)) {
38  // load object
39  $this->_aViewData["edit"] = $oShop = $this->_getEditShop($soxId);
40 
41  try {
42  // category choosen as default
43  $this->_aViewData["defcat"] = null;
44  if ($oShop->oxshops__oxdefcat->value) {
45  $oCat = oxNew("oxCategory");
46  if ($oCat->load($oShop->oxshops__oxdefcat->value)) {
47  $this->_aViewData["defcat"] = $oCat;
48  }
49  }
50  } catch (Exception $oExcp) {
51  // on most cases this means that views are broken, so just
52  // outputting notice and keeping functionality flow ..
53  $this->_aViewData["updateViews"] = 1;
54  }
55 
56  $iAoc = oxRegistry::getConfig()->getRequestParameter("aoc");
57  if ($iAoc == 1) {
58  $oShopDefaultCategoryAjax = oxNew('shop_default_category_ajax');
59  $this->_aViewData['oxajax'] = $oShopDefaultCategoryAjax->getColumns();
60 
61  return "popups/shop_default_category.tpl";
62  }
63 
64  }
65 
66  $aDbVariables = $this->loadConfVars($soxId, $this->_getModuleForConfigVars());
67  $aConfVars = $aDbVariables['vars'];
68  $aConfVars['str']['sVersion'] = $myConfig->getConfigParam('sVersion');
69 
70  $this->_aViewData["var_constraints"] = $aDbVariables['constraints'];
71  $this->_aViewData["var_grouping"] = $aDbVariables['grouping'];
72  foreach ($this->_aConfParams as $sType => $sParam) {
73  $this->_aViewData[$sParam] = $aConfVars[$sType];
74  }
75 
76  // #251A passing country list
77  $oCountryList = oxNew("oxCountryList");
78  $oCountryList->loadActiveCountries(oxRegistry::getLang()->getObjectTplLanguage());
79  if (isset($aConfVars['arr']["aHomeCountry"]) && count($aConfVars['arr']["aHomeCountry"]) && count($oCountryList)) {
80  foreach ($oCountryList as $sCountryId => $oCountry) {
81  if (in_array($oCountry->oxcountry__oxid->value, $aConfVars['arr']["aHomeCountry"])) {
82  $oCountryList[$sCountryId]->selected = "1";
83  }
84  }
85  }
86 
87  $this->_aViewData["countrylist"] = $oCountryList;
88 
89  // checking if cUrl is enabled
90  $this->_aViewData["blCurlIsActive"] = (!function_exists('curl_init')) ? false : true;
91 
92  return $this->_sThisTemplate;
93  }
94 
100  protected function _getModuleForConfigVars()
101  {
102  return '';
103  }
104 
108  public function saveConfVars()
109  {
110  $myConfig = $this->getConfig();
111 
112  $this->resetContentCache();
113 
114  $sShopId = $this->getEditObjectId();
115  $sModule = $this->_getModuleForConfigVars();
116  foreach ($this->_aConfParams as $sType => $sParam) {
117  $aConfVars = oxRegistry::getConfig()->getRequestParameter($sParam);
118  if (is_array($aConfVars)) {
119  foreach ($aConfVars as $sName => $sValue) {
120  $oldValue = $myConfig->getConfigParam($sName);
121  if ($sValue !== $oldValue) {
122  $myConfig->saveShopConfVar(
123  $sType,
124  $sName,
125  $this->_serializeConfVar($sType, $sName, $sValue),
126  $sShopId,
127  $sModule
128  );
129  }
130  }
131  }
132  }
133  }
134 
138  public function save()
139  {
140  // saving config params
141  $this->saveConfVars();
142 
143  //saving additional fields ("oxshops__oxdefcat"") that goes directly to shop (not config)
145  $oShop = oxNew("oxshop");
146  if ($oShop->load($this->getEditObjectId())) {
147  $oShop->assign(oxRegistry::getConfig()->getRequestParameter("editval"));
148  $oShop->save();
149  }
150  }
151 
164  public function loadConfVars($sShopId, $sModule)
165  {
166  $myConfig = $this->getConfig();
167  $aConfVars = array(
168  "bool" => array(),
169  "str" => array(),
170  "arr" => array(),
171  "aarr" => array(),
172  "select" => array(),
173  );
174  $aVarConstraints = array();
175  $aGrouping = array();
176  $oDb = oxDb::getDb();
177  $rs = $oDb->Execute(
178  "select cfg.oxvarname,
179  cfg.oxvartype,
180  DECODE( cfg.oxvarvalue, " . $oDb->quote($myConfig->getConfigParam('sConfigKey')) . ") as oxvarvalue,
181  disp.oxvarconstraint,
182  disp.oxgrouping
183  from oxconfig as cfg
184  left join oxconfigdisplay as disp
185  on cfg.oxmodule=disp.oxcfgmodule and cfg.oxvarname=disp.oxcfgvarname
186  where cfg.oxshopid = '$sShopId'
187  and cfg.oxmodule=" . $oDb->quote($sModule) . "
188  order by disp.oxpos, cfg.oxvarname"
189  );
190 
191  if ($rs != false && $rs->recordCount() > 0) {
192  while (!$rs->EOF) {
193  list($sName, $sType, $sValue, $sConstraint, $sGrouping) = $rs->fields;
194  $aConfVars[$sType][$sName] = $this->_unserializeConfVar($sType, $sName, $sValue);
195  $aVarConstraints[$sName] = $this->_parseConstraint($sType, $sConstraint);
196  if ($sGrouping) {
197  if (!isset($aGrouping[$sGrouping])) {
198  $aGrouping[$sGrouping] = array($sName => $sType);
199  } else {
200  $aGrouping[$sGrouping][$sName] = $sType;
201  }
202  }
203  $rs->moveNext();
204  }
205  }
206 
207  return array(
208  'vars' => $aConfVars,
209  'constraints' => $aVarConstraints,
210  'grouping' => $aGrouping,
211  );
212  }
213 
222  protected function _parseConstraint($sType, $sConstraint)
223  {
224  switch ($sType) {
225  case "select":
226  return array_map('trim', explode('|', $sConstraint));
227  break;
228  }
229  return null;
230  }
231 
240  protected function _serializeConstraint($sType, $sConstraint)
241  {
242  switch ($sType) {
243  case "select":
244  return implode('|', array_map('trim', $sConstraint));
245  break;
246  }
247  return '';
248  }
249 
259  public function _unserializeConfVar($sType, $sName, $sValue)
260  {
261  $oStr = getStr();
262  $mData = null;
263 
264  switch ($sType) {
265  case "bool":
266  $mData = ($sValue == "true" || $sValue == "1");
267  break;
268 
269  case "str":
270  case "select":
271  case "num":
272  case "int":
273  $mData = $oStr->htmlentities($sValue);
274  if (in_array($sName, $this->_aParseFloat)) {
275  $mData = str_replace(',', '.', $mData);
276  }
277  break;
278 
279  case "arr":
280  if (in_array($sName, $this->_aSkipMultiline)) {
281  $mData = unserialize($sValue);
282  } else {
283  $mData = $oStr->htmlentities($this->_arrayToMultiline(unserialize($sValue)));
284  }
285  break;
286 
287  case "aarr":
288  if (in_array($sName, $this->_aSkipMultiline)) {
289  $mData = unserialize($sValue);
290  } else {
291  $mData = $oStr->htmlentities($this->_aarrayToMultiline(unserialize($sValue)));
292  }
293  break;
294  }
295 
296  return $mData;
297  }
298 
308  public function _serializeConfVar($sType, $sName, $mValue)
309  {
310  $sData = $mValue;
311 
312  switch ($sType) {
313  case "bool":
314  break;
315 
316  case "str":
317  case "select":
318  case "int":
319  if (in_array($sName, $this->_aParseFloat)) {
320  $sData = str_replace(',', '.', $sData);
321  }
322  break;
323 
324  case "arr":
325  if (!is_array($mValue)) {
326  $sData = $this->_multilineToArray($mValue);
327  }
328  break;
329 
330  case "aarr":
331  $sData = $this->_multilineToAarray($mValue);
332  break;
333  }
334 
335  return $sData;
336  }
337 
345  protected function _arrayToMultiline($aInput)
346  {
347  $sVal = '';
348  if (is_array($aInput)) {
349  $sVal = implode("\n", $aInput);
350  }
351 
352  return $sVal;
353  }
354 
362  protected function _multilineToArray($sMultiline)
363  {
364  $aArr = explode("\n", $sMultiline);
365  if (is_array($aArr)) {
366  foreach ($aArr as $sKey => $sVal) {
367  $aArr[$sKey] = trim($sVal);
368  if ($aArr[$sKey] == "") {
369  unset($aArr[$sKey]);
370  }
371  }
372 
373  return $aArr;
374  }
375  }
376 
384  protected function _aarrayToMultiline($aInput)
385  {
386  if (is_array($aInput)) {
387  $sMultiline = '';
388  foreach ($aInput as $sKey => $sVal) {
389  if ($sMultiline) {
390  $sMultiline .= "\n";
391  }
392  $sMultiline .= $sKey . " => " . $sVal;
393  }
394 
395  return $sMultiline;
396  }
397  }
398 
406  protected function _multilineToAarray($sMultiline)
407  {
408  $oStr = getStr();
409  $aArr = array();
410  $aLines = explode("\n", $sMultiline);
411  foreach ($aLines as $sLine) {
412  $sLine = trim($sLine);
413  if ($sLine != "" && $oStr->preg_match("/(.+)=>(.+)/", $sLine, $aRegs)) {
414  $sKey = trim($aRegs[1]);
415  $sVal = trim($aRegs[2]);
416  if ($sKey != "" && $sVal != "") {
417  $aArr[$sKey] = $sVal;
418  }
419  }
420  }
421 
422  return $aArr;
423  }
424 
430  public function getEditObjectId()
431  {
432  $sEditId = parent::getEditObjectId();
433  if (!$sEditId) {
434  return $this->getConfig()->getShopId();
435  } else {
436  return $sEditId;
437  }
438  }
439 }