OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxadminview.php
Go to the documentation of this file.
1 <?php
2 
8 class oxAdminView extends oxView
9 {
15  protected $_aSumType = array(
16  0 => 'abs',
17  1 => '%',
18  2 => 'itm'
19  );
20 
26  protected $_sThisTemplate = null;
27 
34  protected $_iDefEdit = 0;
35 
41  protected static $_oNaviTree = null;
42 
48  protected $_iEditLang = 0;
49 
55  protected $_sShopTitle = " - ";
56 
62  protected $_sShopVersion = null;
63 
69  protected $_sServiceUrl = null;
70 
76  protected static $_sAuthUserRights = null;
77 
82  protected $_oEditShop = null;
83 
89  protected $_sEditObjectId = null;
90 
94  public function __construct()
95  {
96  $myConfig = $this->getConfig();
97  $myConfig->setConfigParam( 'blAdmin', true );
98  $this->setAdminMode( true );
99 
100  if ( $oShop = $this->_getEditShop( $myConfig->getShopId() ) ) {
101  // passing shop info
102  $this->_sShopTitle = $oShop->oxshops__oxname->getRawValue();
103  $this->_sShopVersion = $oShop->oxshops__oxversion->value;
104 
105  }
106  }
107 
115  protected function _getEditShop( $sShopId )
116  {
117  if ( !$this->_oEditShop ) {
118  $this->_oEditShop = $this->getConfig()->getActiveShop();
119  if ( $this->_oEditShop->getId() != $sShopId ) {
120  $oEditShop = oxNew( 'oxshop' );
121  if ( $oEditShop->load( $sShopId ) ) {
122  $this->_oEditShop = $oEditShop;
123  }
124  }
125  }
126  return $this->_oEditShop;
127  }
128 
136  public function init()
137  {
138  $myConfig = $this->getConfig();
139 
140  // authorization check
141  if ( !$this->_authorize() ) {
142  oxRegistry::getUtils()->redirect( 'index.php', true, 302 );
143  exit;
144  }
145 
146  $oLang = oxRegistry::getLang();
147 
148  // language handling
149  $this->_iEditLang = $oLang->getEditLanguage();
150  $oLang->setBaseLanguage();
151 
152  parent::init();
153 
154  $this->_aViewData['malladmin'] = oxSession::getVar( 'malladmin' );
155  }
156 
165  public function addGlobalParams( $oShop = null)
166  {
167  $mySession = $this->getSession();
168  $myConfig = $this->getConfig();
169  $oLang = oxRegistry::getLang();
170 
171  $oShop = parent::addGlobalParams( $oShop );
172 
173  // override cause of admin dir
174  $sURL = $myConfig->getConfigParam( 'sShopURL' ). $myConfig->getConfigParam( 'sAdminDir' ) . "/";
175 
176  if ($myConfig->getConfigParam('sAdminSSLURL')) {
177  $sURL = $myConfig->getConfigParam('sAdminSSLURL');
178  }
179 
180  $oViewConf = $this->getViewConfig();
181  $oViewConf->setViewConfigParam( 'selflink', oxRegistry::get("oxUtilsUrl")->processUrl($sURL.'index.php?editlanguage='.$this->_iEditLang, false) );
182  $oViewConf->setViewConfigParam( 'ajaxlink', str_replace( '&amp;', '&', oxRegistry::get("oxUtilsUrl")->processUrl( $sURL.'oxajax.php?editlanguage='.$this->_iEditLang, false ) ) );
183  $oViewConf->setViewConfigParam( 'sServiceUrl', $this->getServiceUrl() );
184  $oViewConf->setViewConfigParam( 'blLoadDynContents', $myConfig->getConfigParam( 'blLoadDynContents' ) );
185  $oViewConf->setViewConfigParam( 'sShopCountry', $myConfig->getConfigParam( 'sShopCountry' ) );
186 
187  // set langugae in admin
188  $iDynInterfaceLanguage = $myConfig->getConfigParam( 'iDynInterfaceLanguage' );
189  //$this->_aViewData['adminlang'] = isset( $iDynInterfaceLanguage )?$iDynInterfaceLanguage:$myConfig->getConfigParam( 'iAdminLanguage' );
190  $this->_aViewData['adminlang'] = isset( $iDynInterfaceLanguage )?$iDynInterfaceLanguage:$oLang->getTplLanguage();
191  $this->_aViewData['charset'] = $this->getCharSet();
192 
193  //setting active currency object
194  $this->_aViewData["oActCur"] = $myConfig->getActShopCurrencyObject();
195 
196  return $oShop;
197  }
198 
204  protected function _getServiceProtocol()
205  {
206  return $this->getConfig()->isSsl() ? 'https' : 'http';
207  }
208 
216  public function getServiceUrl( $sLangAbbr = null )
217  {
218  if ( $this->_sServiceUrl === null ) {
219 
220  $sProtocol = $this->_getServiceProtocol();
221 
222 
223 
224  $sUrl = $sProtocol . '://admin.oxid-esales.com/CE/';
225 
226  $sCountry = $this->_getCountryByCode( $this->getConfig()->getConfigParam( 'sShopCountry' ) );
227 
228  if ( !$sLangAbbr ) {
229  $oLang = oxRegistry::getLang();
230  $sLangAbbr = $oLang->getLanguageAbbr( $oLang->getTplLanguage() );
231  }
232 
233  if ( $sLangAbbr != "de" ) {
234  $sLangAbbr = "en";
235  }
236 
237  $this->_sServiceUrl = $sUrl . $this->_getShopVersionNr()."/{$sCountry}/{$sLangAbbr}/";
238  }
239 
240  return $this->_sServiceUrl;
241  }
242 
248  protected function _getShopVersionNr()
249  {
250  $myConfig = $this->getConfig();
251 
252  if ( $sShopID = $myConfig->getShopId() ) {
253  $sQ = "select oxversion from oxshops where oxid = '$sShopID' ";
254  $sVersion = oxDb::getDb()->getOne( $sQ, false, false );
255  }
256 
257  $sVersion = preg_replace( "/(^[^0-9]+)(.+)$/", "$2", $sVersion );
258  return trim( $sVersion );
259  }
260 
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 = oxConfig::getParameter( '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 
299  protected function _addNavigationHistory( $sNode )
300  {
301  $myUtilsServer = oxRegistry::get("oxUtilsServer");
302 
303  // store navigation history
304  $aHistory = explode('|', $myUtilsServer->getOxCookie('oxidadminhistory'));
305  if (!is_array($aHistory)) {
306  $aHistory = array();
307  }
308 
309  if (!in_array($sNode, $aHistory)) {
310  $aHistory[] = $sNode;
311  }
312 
313  $myUtilsServer->setOxCookie('oxidadminhistory', implode('|', $aHistory));
314  }
315 
322  public function render()
323  {
324  $sReturn = parent::render();
325 
326  $myConfig = $this->getConfig();
327  $oLang = oxRegistry::getLang();
328 
329  // sets up navigation data
330  $this->_setupNavigation( oxConfig::getParameter( 'cl' ) );
331 
332  // active object id
333  $sOxId = $this->getEditObjectId();
334  $this->_aViewData['oxid'] = ( !$sOxId )?-1:$sOxId;
335  // add Sumtype to all templates
336  $this->_aViewData['sumtype'] = $this->_aSumType;
337 
338  // active shop title
339  $this->_aViewData['actshop'] = $this->_sShopTitle;
340  $this->_aViewData["shopid"] = $myConfig->getShopId();
341 
342  // loading active shop
343  if ( $sActShopId = oxSession::getVar( 'actshop' ) ) {
344  // load object
345  $this->_aViewData['actshopobj'] = $this->_getEditShop( $sActShopId );
346  }
347 
348  // add language data to all templates
349  $this->_aViewData['actlang'] = $iLanguage = $oLang->getBaseLanguage();
350  $this->_aViewData['editlanguage'] = $this->_iEditLang;
351  $this->_aViewData['languages'] = $oLang->getLanguageArray( $iLanguage );
352 
353  // setting maximum upload size
354  list( $this->_aViewData['iMaxUploadFileSize'], $this->_aViewData['sMaxFormattedFileSize']) = $this->_getMaxUploadFileInfo( @ini_get("upload_max_filesize") );
355 
356  // "save-on-tab"
357  if ( !isset( $this->_aViewData['updatelist'] ) ) {
358  $this->_aViewData['updatelist'] = oxConfig::getParameter( 'updatelist' );
359  }
360 
361  return $sReturn;
362  }
363 
372  protected function _getMaxUploadFileInfo( $iMaxFileSize, $blFormatted = false )
373  {
374  $iMaxFileSize = $iMaxFileSize?$iMaxFileSize:'2M';
375 
376  // processing config
377  $iMaxFileSize = trim( $iMaxFileSize );
378  $sParam = strtolower( $iMaxFileSize{ strlen( $iMaxFileSize )-1 } );
379  switch( $sParam ) {
380  case 'g':
381  $iMaxFileSize *= 1024;
382  case 'm':
383  $iMaxFileSize *= 1024;
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 
407  public function save()
408  {
409  }
410 
418  public function resetContentCache( $blForceReset = null )
419  {
420  $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam( 'blClearCacheOnLogout' );
421 
422  if ( !$blDeleteCacheOnLogout || $blForceReset ) {
423 
424 
425  oxRegistry::getUtils()->oxResetFileCache();
426 
427  }
428  }
429 
439  public function resetCounter( $sCounterType, $sValue = null )
440  {
441  $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam( 'blClearCacheOnLogout' );
442  $myUtilsCount = oxRegistry::get("oxUtilsCount");
443 
444  if ( !$blDeleteCacheOnLogout ) {
445  switch ( $sCounterType ) {
446  case 'priceCatArticle':
447  $myUtilsCount->resetPriceCatArticleCount( $sValue );
448  break;
449  case 'catArticle':
450  $myUtilsCount->resetCatArticleCount( $sValue );
451  break;
452  case 'vendorArticle':
453  $myUtilsCount->resetVendorArticleCount( $sValue );
454  break;
455  case 'manufacturerArticle':
456  $myUtilsCount->resetManufacturerArticleCount( $sValue );
457  break;
458  }
459  }
460  }
461 
470  protected function _allowAdminEdit( $sUserId )
471  {
472 
473  //otherwise return true
474  return true;
475  }
476 
484  protected function _getCountryByCode( $sCountryCode )
485  {
486  $myConfig = $this->getConfig();
487 
488  //default country
489  $sCountry = 'international';
490 
491  if ( !empty( $sCountryCode ) ) {
492  $aLangIds = oxRegistry::getLang()->getLanguageIds();
493  $iEnglishId = array_search("en", $aLangIds);
494  if ( false !== $iEnglishId ) {
495  $sViewName = getViewName( "oxcountry", $iEnglishId );
496  $sQ = "select oxtitle from {$sViewName} where oxisoalpha2 = " . oxDb::getDb()->quote( $sCountryCode );
497  $sCountryName = oxDb::getDb()->getOne( $sQ, false, false );
498  if ( $sCountryName ) {
499  $sCountry = $sCountryName;
500  }
501  } else {
502  // handling when english language is deleted
503  switch ( $sCountryCode ) {
504  case 'de':
505  return 'germany';
506  default:
507  return 'international';
508  }
509  }
510  }
511  return strtolower( $sCountry );
512  }
513 
519  protected function _authorize()
520  {
521  return ( bool ) (
522  $this->getSession()->checkSessionChallenge()
523  && count( oxRegistry::get("oxUtilsServer")->getOxCookie() )
524  && oxRegistry::getUtils()->checkAccessRights()
525  );
526  }
527 
533  public function getNavigation()
534  {
535  if ( self::$_oNaviTree == null ) {
536  self::$_oNaviTree = oxNew( 'oxnavigationtree' );
537  }
538  return self::$_oNaviTree;
539  }
540 
546  public function getViewId()
547  {
548  $sClassName = strtolower( get_class( $this ) );
549  return $this->getNavigation()->getClassId( $sClassName );
550  }
551 
557  public function chshp()
558  {
559  $sActShop = oxConfig::getParameter( 'shp' );
560  oxSession::setVar( "shp", $sActShop );
561  oxSession::setVar( 'currentadminshop', $sActShop );
562  }
563 
571  public function resetSeoData( $sShopId )
572  {
573  $aTypes = array( 'oxarticle', 'oxcategory', 'oxvendor', 'oxcontent', 'dynamic', 'oxmanufacturer' );
574  $oEncoder = oxRegistry::get("oxSeoEncoder");
575  foreach ( $aTypes as $sType ) {
576  $oEncoder->markAsExpired( null, $sShopId, 1, null, "oxtype = '{$sType}'" );
577  }
578 
579  // resetting tag cache
580  $oTagCloud = oxNew('oxtagcloud');
581  $oTagCloud->resetCache();
582  }
583 
589  public function getPreviewId()
590  {
591  return oxRegistry::getUtils()->getPreviewId();
592  }
593 
599  public function getEditObjectId()
600  {
601  if ( null === ( $sId = $this->_sEditObjectId ) ) {
602  if ( null === ( $sId = oxConfig::getParameter( "oxid" ) ) ) {
603  $sId = oxSession::getVar( "saved_oxid" );
604  }
605  }
606  return $sId;
607  }
608 
616  public function setEditObjectId( $sId )
617  {
618  $this->_sEditObjectId = $sId;
619  $this->_aViewData["updatelist"] = 1;
620  }
621 }