OXID eShop CE  4.9.8
 All Classes 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 
70  protected $_sServiceUrl = null;
71 
77  protected static $_sAuthUserRights = null;
78 
84  protected $_oEditShop = null;
85 
91  protected $_sEditObjectId = null;
92 
96  public function __construct()
97  {
98  $myConfig = $this->getConfig();
99  $myConfig->setConfigParam('blAdmin', true);
100  $this->setAdminMode(true);
101 
102  if ($oShop = $this->_getEditShop($myConfig->getShopId())) {
103  // passing shop info
104  $this->_sShopTitle = $oShop->oxshops__oxname->getRawValue();
105  $this->_sShopVersion = $oShop->oxshops__oxversion->value;
106 
107  }
108  }
109 
117  protected function _getEditShop($sShopId)
118  {
119  if (!$this->_oEditShop) {
120  $this->_oEditShop = $this->getConfig()->getActiveShop();
121  if ($this->_oEditShop->getId() != $sShopId) {
122  $oEditShop = oxNew('oxshop');
123  if ($oEditShop->load($sShopId)) {
124  $this->_oEditShop = $oEditShop;
125  }
126  }
127  }
128 
129  return $this->_oEditShop;
130  }
131 
137  public function init()
138  {
139  $myConfig = $this->getConfig();
140 
141  // authorization check
142  if (!$this->_authorize()) {
143  oxRegistry::getUtils()->redirect('index.php', true, 302);
144  exit;
145  }
146 
147  $oLang = oxRegistry::getLang();
148 
149  // language handling
150  $this->_iEditLang = $oLang->getEditLanguage();
151  $oLang->setBaseLanguage();
152 
153  parent::init();
154 
155  $this->_aViewData['malladmin'] = oxRegistry::getSession()->getVariable('malladmin');
156  }
157 
166  public function addGlobalParams($oShop = null)
167  {
168  $mySession = $this->getSession();
169  $myConfig = $this->getConfig();
170  $oLang = oxRegistry::getLang();
171 
172  $oShop = parent::addGlobalParams($oShop);
173 
174  // override cause of admin dir
175  $sURL = $myConfig->getConfigParam('sShopURL') . $myConfig->getConfigParam('sAdminDir') . "/";
176 
177  if ($myConfig->getConfigParam('sAdminSSLURL')) {
178  $sURL = $myConfig->getConfigParam('sAdminSSLURL');
179  }
180 
181  $oViewConf = $this->getViewConfig();
182  $oViewConf->setViewConfigParam('selflink', oxRegistry::get("oxUtilsUrl")->processUrl($sURL . 'index.php?editlanguage=' . $this->_iEditLang, false));
183  $oViewConf->setViewConfigParam('ajaxlink', str_replace('&amp;', '&', oxRegistry::get("oxUtilsUrl")->processUrl($sURL . 'oxajax.php?editlanguage=' . $this->_iEditLang, false)));
184  $oViewConf->setViewConfigParam('sServiceUrl', $this->getServiceUrl());
185  $oViewConf->setViewConfigParam('blLoadDynContents', $myConfig->getConfigParam('blLoadDynContents'));
186  $oViewConf->setViewConfigParam('sShopCountry', $myConfig->getConfigParam('sShopCountry'));
187 
188  // set langugae in admin
189  $iDynInterfaceLanguage = $myConfig->getConfigParam('iDynInterfaceLanguage');
190  //$this->_aViewData['adminlang'] = isset( $iDynInterfaceLanguage )?$iDynInterfaceLanguage:$myConfig->getConfigParam( 'iAdminLanguage' );
191  $this->_aViewData['adminlang'] = isset($iDynInterfaceLanguage) ? $iDynInterfaceLanguage : $oLang->getTplLanguage();
192  $this->_aViewData['charset'] = $this->getCharSet();
193 
194  //setting active currency object
195  $this->_aViewData["oActCur"] = $myConfig->getActShopCurrencyObject();
196 
197  return $oShop;
198  }
199 
205  protected function _getServiceProtocol()
206  {
207  return $this->getConfig()->isSsl() ? 'https' : 'http';
208  }
209 
217  public function getServiceUrl($sLangAbbr = null)
218  {
219  if ($this->_sServiceUrl === null) {
220 
221  $sProtocol = $this->_getServiceProtocol();
222 
223 
224 
225  $sUrl = $sProtocol . '://admin.oxid-esales.com/CE/';
226 
227  $sCountry = $this->_getCountryByCode($this->getConfig()->getConfigParam('sShopCountry'));
228 
229  if (!$sLangAbbr) {
230  $oLang = oxRegistry::getLang();
231  $sLangAbbr = $oLang->getLanguageAbbr($oLang->getTplLanguage());
232  }
233 
234  if ($sLangAbbr != "de") {
235  $sLangAbbr = "en";
236  }
237 
238  $this->_sServiceUrl = $sUrl . $this->_getShopVersionNr() . "/{$sCountry}/{$sLangAbbr}/";
239  }
240 
241  return $this->_sServiceUrl;
242  }
243 
249  protected function _getShopVersionNr()
250  {
251  $myConfig = $this->getConfig();
252 
253  if ($sShopID = $myConfig->getShopId()) {
254  $sQ = "select oxversion from oxshops where oxid = '$sShopID' ";
255  $sVersion = oxDb::getDb()->getOne($sQ, false, false);
256  }
257 
258  $sVersion = preg_replace("/(^[^0-9]+)(.+)$/", "$2", $sVersion);
259 
260  return trim($sVersion);
261  }
262 
268  protected function _setupNavigation($sNode)
269  {
270  // navigation according to class
271  if ($sNode) {
272 
273  $myAdminNavig = $this->getNavigation();
274 
275  // active tab
276  $iActTab = oxRegistry::getConfig()->getRequestParameter('actedit');
277  $iActTab = $iActTab ? $iActTab : $this->_iDefEdit;
278 
279  $sActTab = $iActTab ? "&actedit=$iActTab" : '';
280 
281  // store navigation history
282  $this->_addNavigationHistory($sNode);
283 
284  // list url
285  $this->_aViewData['listurl'] = $myAdminNavig->getListUrl($sNode) . $sActTab;
286 
287  // edit url
288  $this->_aViewData['editurl'] = $myAdminNavig->getEditUrl($sNode, $iActTab) . $sActTab;
289  }
290  }
291 
297  protected function _addNavigationHistory($sNode)
298  {
299  $myUtilsServer = oxRegistry::get("oxUtilsServer");
300 
301  // store navigation history
302  $aHistory = explode('|', $myUtilsServer->getOxCookie('oxidadminhistory'));
303  if (!is_array($aHistory)) {
304  $aHistory = array();
305  }
306 
307  if (!in_array($sNode, $aHistory)) {
308  $aHistory[] = $sNode;
309  }
310 
311  $myUtilsServer->setOxCookie('oxidadminhistory', implode('|', $aHistory));
312  }
313 
320  public function render()
321  {
322  $sReturn = parent::render();
323 
324  $myConfig = $this->getConfig();
325  $oLang = oxRegistry::getLang();
326 
327  // sets up navigation data
328  $this->_setupNavigation(oxRegistry::getConfig()->getRequestParameter('cl'));
329 
330  // active object id
331  $sOxId = $this->getEditObjectId();
332  $this->_aViewData['oxid'] = (!$sOxId) ? -1 : $sOxId;
333  // add Sumtype to all templates
334  $this->_aViewData['sumtype'] = $this->_aSumType;
335 
336  // active shop title
337  $this->_aViewData['actshop'] = $this->_sShopTitle;
338  $this->_aViewData["shopid"] = $myConfig->getShopId();
339 
340  // loading active shop
341  if ($sActShopId = oxRegistry::getSession()->getVariable('actshop')) {
342  // load object
343  $this->_aViewData['actshopobj'] = $this->_getEditShop($sActShopId);
344  }
345 
346  // add language data to all templates
347  $this->_aViewData['actlang'] = $iLanguage = $oLang->getBaseLanguage();
348  $this->_aViewData['editlanguage'] = $this->_iEditLang;
349  $this->_aViewData['languages'] = $oLang->getLanguageArray($iLanguage);
350 
351  // setting maximum upload size
352  list($this->_aViewData['iMaxUploadFileSize'], $this->_aViewData['sMaxFormattedFileSize']) = $this->_getMaxUploadFileInfo(@ini_get("upload_max_filesize"));
353 
354  // "save-on-tab"
355  if (!isset($this->_aViewData['updatelist'])) {
356  $this->_aViewData['updatelist'] = oxRegistry::getConfig()->getRequestParameter('updatelist');
357  }
358 
359  return $sReturn;
360  }
361 
370  protected function _getMaxUploadFileInfo($iMaxFileSize, $blFormatted = false)
371  {
372  $iMaxFileSize = $iMaxFileSize ? $iMaxFileSize : '2M';
373 
374  // processing config
375  $iMaxFileSize = trim($iMaxFileSize);
376  $sParam = strtolower($iMaxFileSize{strlen($iMaxFileSize) - 1});
377  switch ($sParam) {
378  case 'g':
379  $iMaxFileSize *= 1024;
380  // no break
381  case 'm':
382  $iMaxFileSize *= 1024;
383  // no break
384  case 'k':
385  $iMaxFileSize *= 1024;
386  }
387 
388  // formatting
389  $aMarkers = array('KB', 'MB', 'GB');
390  $sFormattedMaxSize = '';
391 
392  $iSize = floor($iMaxFileSize / 1024);
393  while ($iSize && current($aMarkers)) {
394  $sFormattedMaxSize = $iSize . " " . current($aMarkers);
395  $iSize = floor($iSize / 1024);
396  next($aMarkers);
397  }
398 
399  return array($iMaxFileSize, $sFormattedMaxSize);
400  }
401 
405  public function save()
406  {
407  $this->resetContentCache();
408  }
409 
415  public function resetContentCache($blForceReset = null)
416  {
417  $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam('blClearCacheOnLogout');
418 
419  if (!$blDeleteCacheOnLogout || $blForceReset) {
420 
421 
422  oxRegistry::getUtils()->oxResetFileCache();
423 
424  }
425  }
426 
434  public function resetCounter($sCounterType, $sValue = null)
435  {
436  $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam('blClearCacheOnLogout');
437  $myUtilsCount = oxRegistry::get("oxUtilsCount");
438 
439  if (!$blDeleteCacheOnLogout) {
440  switch ($sCounterType) {
441  case 'priceCatArticle':
442  $myUtilsCount->resetPriceCatArticleCount($sValue);
443  break;
444  case 'catArticle':
445  $myUtilsCount->resetCatArticleCount($sValue);
446  break;
447  case 'vendorArticle':
448  $myUtilsCount->resetVendorArticleCount($sValue);
449  break;
450  case 'manufacturerArticle':
451  $myUtilsCount->resetManufacturerArticleCount($sValue);
452  break;
453  }
454  $this->_resetContentCache();
455  }
456  }
457 
461  protected function _resetContentCache()
462  {
463  }
464 
473  protected function _allowAdminEdit($sUserId)
474  {
475 
476  //otherwise return true
477  return true;
478  }
479 
487  protected function _getCountryByCode($sCountryCode)
488  {
489  $myConfig = $this->getConfig();
490 
491  //default country
492  $sCountry = 'international';
493 
494  if (!empty($sCountryCode)) {
495  $aLangIds = oxRegistry::getLang()->getLanguageIds();
496  $iEnglishId = array_search("en", $aLangIds);
497  if (false !== $iEnglishId) {
498  $sViewName = getViewName("oxcountry", $iEnglishId);
499  $sQ = "select oxtitle from {$sViewName} where oxisoalpha2 = " . oxDb::getDb()->quote($sCountryCode);
500  $sCountryName = oxDb::getDb()->getOne($sQ, false, false);
501  if ($sCountryName) {
502  $sCountry = $sCountryName;
503  }
504  } else {
505  // handling when english language is deleted
506  switch ($sCountryCode) {
507  case 'de':
508  return 'germany';
509  default:
510  return 'international';
511  }
512  }
513  }
514 
515  return strtolower($sCountry);
516  }
517 
523  protected function _authorize()
524  {
525  return ( bool ) (
526  $this->getSession()->checkSessionChallenge()
527  && count(oxRegistry::get("oxUtilsServer")->getOxCookie())
528  && oxRegistry::getUtils()->checkAccessRights()
529  );
530  }
531 
537  public function getNavigation()
538  {
539  if (self::$_oNaviTree == null) {
540  self::$_oNaviTree = oxNew('oxnavigationtree');
541  }
542 
543  return self::$_oNaviTree;
544  }
545 
551  public function getViewId()
552  {
553  $sClassName = strtolower(get_class($this));
554 
555  return $this->getNavigation()->getClassId($sClassName);
556  }
557 
561  public function chshp()
562  {
563  $sActShop = oxRegistry::getConfig()->getRequestParameter('shp');
564  oxRegistry::getSession()->setVariable("shp", $sActShop);
565  oxRegistry::getSession()->setVariable('currentadminshop', $sActShop);
566  }
567 
573  public function resetSeoData($sShopId)
574  {
575  $aTypes = array('oxarticle', 'oxcategory', 'oxvendor', 'oxcontent', 'dynamic', 'oxmanufacturer');
576  $oEncoder = oxRegistry::get("oxSeoEncoder");
577  foreach ($aTypes as $sType) {
578  $oEncoder->markAsExpired(null, $sShopId, 1, null, "oxtype = '{$sType}'");
579  }
580 
581  // resetting tag cache
582  $oTagCloud = oxNew('oxtagcloud');
583  $oTagCloud->resetCache();
584  }
585 
591  public function getPreviewId()
592  {
593  return oxRegistry::getUtils()->getPreviewId();
594  }
595 
601  public function getEditObjectId()
602  {
603  if (null === ($sId = $this->_sEditObjectId)) {
604  if (null === ($sId = oxRegistry::getConfig()->getRequestParameter("oxid"))) {
605  $sId = oxRegistry::getSession()->getVariable("saved_oxid");
606  }
607  }
608 
609  return $sId;
610  }
611 
617  public function setEditObjectId($sId)
618  {
619  $this->_sEditObjectId = $sId;
620  $this->_aViewData["updatelist"] = 1;
621  }
622 }