OXID eShop CE  4.10.7
 All Classes Namespaces Files Functions Variables Pages
oxadminview.php
Go to the documentation of this file.
1 <?php
2 
8 class oxAdminView extends oxView
9 {
10 
16  protected $_aSumType = array(
17  0 => 'abs',
18  1 => '%',
19  2 => 'itm'
20  );
21 
27  protected $_sThisTemplate = null;
28 
35  protected $_iDefEdit = 0;
36 
42  protected static $_oNaviTree = null;
43 
49  protected $_iEditLang = 0;
50 
56  protected $_sShopTitle = " - ";
57 
63  protected $_sShopVersion = null;
64 
72  protected $_sServiceUrl = null;
73 
79  protected static $_sAuthUserRights = null;
80 
86  protected $_oEditShop = null;
87 
93  protected $_sEditObjectId = null;
94 
98  public function __construct()
99  {
100  $myConfig = $this->getConfig();
101  $myConfig->setConfigParam('blAdmin', true);
102  $this->setAdminMode(true);
103 
104  if ($oShop = $this->_getEditShop($myConfig->getShopId())) {
105  // passing shop info
106  $this->_sShopTitle = $oShop->oxshops__oxname->getRawValue();
107  $this->_sShopVersion = $oShop->oxshops__oxversion->value;
108 
109  }
110  }
111 
119  protected function _getEditShop($sShopId)
120  {
121  if (!$this->_oEditShop) {
122  $this->_oEditShop = $this->getConfig()->getActiveShop();
123  if ($this->_oEditShop->getId() != $sShopId) {
124  $oEditShop = oxNew('oxshop');
125  if ($oEditShop->load($sShopId)) {
126  $this->_oEditShop = $oEditShop;
127  }
128  }
129  }
130 
131  return $this->_oEditShop;
132  }
133 
139  public function init()
140  {
141  $myConfig = $this->getConfig();
142 
143  // authorization check
144  if (!$this->_authorize()) {
145  oxRegistry::getUtils()->redirect('index.php', true, 302);
146  exit;
147  }
148 
149  $oLang = oxRegistry::getLang();
150 
151  // language handling
152  $this->_iEditLang = $oLang->getEditLanguage();
153  $oLang->setBaseLanguage();
154 
155  parent::init();
156 
157  $this->_aViewData['malladmin'] = oxRegistry::getSession()->getVariable('malladmin');
158  }
159 
168  public function addGlobalParams($oShop = null)
169  {
170  $mySession = $this->getSession();
171  $myConfig = $this->getConfig();
172  $oLang = oxRegistry::getLang();
173 
174  $oShop = parent::addGlobalParams($oShop);
175 
176  // override cause of admin dir
177  $sURL = $myConfig->getConfigParam('sShopURL') . $myConfig->getConfigParam('sAdminDir') . "/";
178 
179  if ($myConfig->getConfigParam('sAdminSSLURL')) {
180  $sURL = $myConfig->getConfigParam('sAdminSSLURL');
181  }
182 
183  $oViewConf = $this->getViewConfig();
184  $oViewConf->setViewConfigParam('selflink', oxRegistry::get("oxUtilsUrl")->processUrl($sURL . 'index.php?editlanguage=' . $this->_iEditLang, false));
185  $oViewConf->setViewConfigParam('ajaxlink', str_replace('&amp;', '&', oxRegistry::get("oxUtilsUrl")->processUrl($sURL . 'oxajax.php?editlanguage=' . $this->_iEditLang, false)));
186  $oViewConf->setViewConfigParam('sServiceUrl', $this->getServiceUrl());
187  $oViewConf->setViewConfigParam('blLoadDynContents', $myConfig->getConfigParam('blLoadDynContents'));
188  $oViewConf->setViewConfigParam('sShopCountry', $myConfig->getConfigParam('sShopCountry'));
189 
190  // set langugae in admin
191  $iDynInterfaceLanguage = $myConfig->getConfigParam('iDynInterfaceLanguage');
192  //$this->_aViewData['adminlang'] = isset( $iDynInterfaceLanguage )?$iDynInterfaceLanguage:$myConfig->getConfigParam( 'iAdminLanguage' );
193  $this->_aViewData['adminlang'] = isset($iDynInterfaceLanguage) ? $iDynInterfaceLanguage : $oLang->getTplLanguage();
194  $this->_aViewData['charset'] = $this->getCharSet();
195 
196  //setting active currency object
197  $this->_aViewData["oActCur"] = $myConfig->getActShopCurrencyObject();
198 
199  return $oShop;
200  }
201 
207  protected function _getServiceProtocol()
208  {
209  return $this->getConfig()->isSsl() ? 'https' : 'http';
210  }
211 
221  public function getServiceUrl($sLangAbbr = null)
222  {
223  if ($this->_sServiceUrl === null) {
224 
225  $sProtocol = $this->_getServiceProtocol();
226 
227 
228 
229  $sUrl = $sProtocol . '://admin.oxid-esales.com/CE/';
230 
231  $sCountry = $this->_getCountryByCode($this->getConfig()->getConfigParam('sShopCountry'));
232 
233  if (!$sLangAbbr) {
234  $oLang = oxRegistry::getLang();
235  $sLangAbbr = $oLang->getLanguageAbbr($oLang->getTplLanguage());
236  }
237 
238  if ($sLangAbbr != "de") {
239  $sLangAbbr = "en";
240  }
241 
242  $this->_sServiceUrl = $sUrl . $this->_getShopVersionNr() . "/{$sCountry}/{$sLangAbbr}/";
243  }
244 
245  return $this->_sServiceUrl;
246  }
247 
253  protected function _getShopVersionNr()
254  {
255  $myConfig = $this->getConfig();
256 
257  if ($sShopID = $myConfig->getShopId()) {
258  $sQ = "select oxversion from oxshops where oxid = '$sShopID' ";
259  $sVersion = oxDb::getDb()->getOne($sQ, false, false);
260  }
261 
262  $sVersion = preg_replace("/(^[^0-9]+)(.+)$/", "$2", $sVersion);
263 
264  return trim($sVersion);
265  }
266 
272  protected function _setupNavigation($sNode)
273  {
274  // navigation according to class
275  if ($sNode) {
276 
277  $myAdminNavig = $this->getNavigation();
278 
279  // active tab
280  $iActTab = oxRegistry::getConfig()->getRequestParameter('actedit');
281  $iActTab = $iActTab ? $iActTab : $this->_iDefEdit;
282 
283  $sActTab = $iActTab ? "&actedit=$iActTab" : '';
284 
285  // store navigation history
286  $this->_addNavigationHistory($sNode);
287 
288  // list url
289  $this->_aViewData['listurl'] = $myAdminNavig->getListUrl($sNode) . $sActTab;
290 
291  // edit url
292  $this->_aViewData['editurl'] = $myAdminNavig->getEditUrl($sNode, $iActTab) . $sActTab;
293  }
294  }
295 
301  protected function _addNavigationHistory($sNode)
302  {
303  $myUtilsServer = oxRegistry::get("oxUtilsServer");
304 
305  // store navigation history
306  $aHistory = explode('|', $myUtilsServer->getOxCookie('oxidadminhistory'));
307  if (!is_array($aHistory)) {
308  $aHistory = array();
309  }
310 
311  if (!in_array($sNode, $aHistory)) {
312  $aHistory[] = $sNode;
313  }
314 
315  $myUtilsServer->setOxCookie('oxidadminhistory', implode('|', $aHistory));
316  }
317 
324  public function render()
325  {
326  $sReturn = parent::render();
327 
328  $myConfig = $this->getConfig();
329  $oLang = oxRegistry::getLang();
330 
331  // sets up navigation data
332  $this->_setupNavigation(oxRegistry::getConfig()->getRequestParameter('cl'));
333 
334  // active object id
335  $sOxId = $this->getEditObjectId();
336  $this->_aViewData['oxid'] = (!$sOxId) ? -1 : $sOxId;
337  // add Sumtype to all templates
338  $this->_aViewData['sumtype'] = $this->_aSumType;
339 
340  // active shop title
341  $this->_aViewData['actshop'] = $this->_sShopTitle;
342  $this->_aViewData["shopid"] = $myConfig->getShopId();
343 
344  // loading active shop
345  if ($sActShopId = oxRegistry::getSession()->getVariable('actshop')) {
346  // load object
347  $this->_aViewData['actshopobj'] = $this->_getEditShop($sActShopId);
348  }
349 
350  // add language data to all templates
351  $this->_aViewData['actlang'] = $iLanguage = $oLang->getBaseLanguage();
352  $this->_aViewData['editlanguage'] = $this->_iEditLang;
353  $this->_aViewData['languages'] = $oLang->getLanguageArray($iLanguage);
354 
355  // setting maximum upload size
356  list($this->_aViewData['iMaxUploadFileSize'], $this->_aViewData['sMaxFormattedFileSize']) = $this->_getMaxUploadFileInfo(@ini_get("upload_max_filesize"));
357 
358  // "save-on-tab"
359  if (!isset($this->_aViewData['updatelist'])) {
360  $this->_aViewData['updatelist'] = oxRegistry::getConfig()->getRequestParameter('updatelist');
361  }
362 
363  return $sReturn;
364  }
365 
374  protected function _getMaxUploadFileInfo($iMaxFileSize, $blFormatted = false)
375  {
376  $iMaxFileSize = $iMaxFileSize ? $iMaxFileSize : '2M';
377 
378  // processing config
379  $iMaxFileSize = trim($iMaxFileSize);
380  $sParam = strtolower($iMaxFileSize{strlen($iMaxFileSize) - 1});
381  switch ($sParam) {
382  case 'g':
383  $iMaxFileSize *= 1024;
384  // no break
385  case 'm':
386  $iMaxFileSize *= 1024;
387  // no break
388  case 'k':
389  $iMaxFileSize *= 1024;
390  }
391 
392  // formatting
393  $aMarkers = array('KB', 'MB', 'GB');
394  $sFormattedMaxSize = '';
395 
396  $iSize = floor($iMaxFileSize / 1024);
397  while ($iSize && current($aMarkers)) {
398  $sFormattedMaxSize = $iSize . " " . current($aMarkers);
399  $iSize = floor($iSize / 1024);
400  next($aMarkers);
401  }
402 
403  return array($iMaxFileSize, $sFormattedMaxSize);
404  }
405 
409  public function save()
410  {
411  $this->resetContentCache();
412  }
413 
419  public function resetContentCache($blForceReset = null)
420  {
421  $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam('blClearCacheOnLogout');
422 
423  if (!$blDeleteCacheOnLogout || $blForceReset) {
424 
425 
426  oxRegistry::getUtils()->oxResetFileCache();
427 
428  }
429  }
430 
438  public function resetCounter($sCounterType, $sValue = null)
439  {
440  $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam('blClearCacheOnLogout');
441  $myUtilsCount = oxRegistry::get("oxUtilsCount");
442 
443  if (!$blDeleteCacheOnLogout) {
444  switch ($sCounterType) {
445  case 'priceCatArticle':
446  $myUtilsCount->resetPriceCatArticleCount($sValue);
447  break;
448  case 'catArticle':
449  $myUtilsCount->resetCatArticleCount($sValue);
450  break;
451  case 'vendorArticle':
452  $myUtilsCount->resetVendorArticleCount($sValue);
453  break;
454  case 'manufacturerArticle':
455  $myUtilsCount->resetManufacturerArticleCount($sValue);
456  break;
457  }
458  $this->_resetContentCache();
459  }
460  }
461 
465  protected function _resetContentCache()
466  {
467  }
468 
477  protected function _allowAdminEdit($sUserId)
478  {
479 
480  //otherwise return true
481  return true;
482  }
483 
491  protected function _getCountryByCode($sCountryCode)
492  {
493  $myConfig = $this->getConfig();
494 
495  //default country
496  $sCountry = 'international';
497 
498  if (!empty($sCountryCode)) {
499  $aLangIds = oxRegistry::getLang()->getLanguageIds();
500  $iEnglishId = array_search("en", $aLangIds);
501  if (false !== $iEnglishId) {
502  $sViewName = getViewName("oxcountry", $iEnglishId);
503  $sQ = "select oxtitle from {$sViewName} where oxisoalpha2 = " . oxDb::getDb()->quote($sCountryCode);
504  $sCountryName = oxDb::getDb()->getOne($sQ, false, false);
505  if ($sCountryName) {
506  $sCountry = $sCountryName;
507  }
508  } else {
509  // handling when english language is deleted
510  switch ($sCountryCode) {
511  case 'de':
512  return 'germany';
513  default:
514  return 'international';
515  }
516  }
517  }
518 
519  return strtolower($sCountry);
520  }
521 
527  protected function _authorize()
528  {
529  return ( bool ) (
530  $this->getSession()->checkSessionChallenge()
531  && count(oxRegistry::get("oxUtilsServer")->getOxCookie())
532  && oxRegistry::getUtils()->checkAccessRights()
533  );
534  }
535 
541  public function getNavigation()
542  {
543  if (self::$_oNaviTree == null) {
544  self::$_oNaviTree = oxNew('oxnavigationtree');
545  }
546 
547  return self::$_oNaviTree;
548  }
549 
555  public function getViewId()
556  {
557  $sClassName = strtolower(get_class($this));
558 
559  return $this->getNavigation()->getClassId($sClassName);
560  }
561 
565  public function chshp()
566  {
567  $sActShop = oxRegistry::getConfig()->getRequestParameter('shp');
568  oxRegistry::getSession()->setVariable("shp", $sActShop);
569  oxRegistry::getSession()->setVariable('currentadminshop', $sActShop);
570  }
571 
577  public function resetSeoData($sShopId)
578  {
579  $aTypes = array('oxarticle', 'oxcategory', 'oxvendor', 'oxcontent', 'dynamic', 'oxmanufacturer');
580  $oEncoder = oxRegistry::get("oxSeoEncoder");
581  foreach ($aTypes as $sType) {
582  $oEncoder->markAsExpired(null, $sShopId, 1, null, "oxtype = '{$sType}'");
583  }
584 
585  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
586  // resetting tag cache
587  $oTagCloud = oxNew('oxtagcloud');
588  $oTagCloud->resetCache();
589  // END deprecated
590  }
591 
597  public function getPreviewId()
598  {
599  return oxRegistry::getUtils()->getPreviewId();
600  }
601 
607  public function getEditObjectId()
608  {
609  if (null === ($sId = $this->_sEditObjectId)) {
610  if (null === ($sId = oxRegistry::getConfig()->getRequestParameter("oxid"))) {
611  $sId = oxRegistry::getSession()->getVariable("saved_oxid");
612  }
613  }
614 
615  return $sId;
616  }
617 
623  public function setEditObjectId($sId)
624  {
625  $this->_sEditObjectId = $sId;
626  $this->_aViewData["updatelist"] = 1;
627  }
628 }