oxadminview.php
Go to the documentation of this file.00001 <?php
00002
00008 class oxAdminView extends oxView
00009 {
00015 protected $_aSumType = array(
00016 0 => 'abs',
00017 1 => '%',
00018 2 => 'itm'
00019 );
00020
00026 protected $_sThisTemplate = null;
00027
00034 protected $_iDefEdit = 0;
00035
00041 protected static $_oNaviTree = null;
00042
00048 protected $_iEditLang = 0;
00049
00055 protected $_sShopTitle = " - ";
00056
00062 protected $_sShopVersion = null;
00063
00069 protected $_sServiceUrl = null;
00070
00076 protected static $_sAuthUserRights = null;
00077
00082 protected $_oEditShop = null;
00083
00087 public function __construct()
00088 {
00089 $myConfig = $this->getConfig();
00090 $myConfig->setConfigParam( 'blAdmin', true );
00091
00092 if ( $oShop = $this->_getEditShop( $myConfig->getShopId() ) ) {
00093
00094 $this->_sShopTitle = $oShop->oxshops__oxname->getRawValue();
00095 $this->_sShopVersion = $oShop->oxshops__oxversion->value;
00096
00097 }
00098 }
00099
00107 protected function _getEditShop( $sShopId )
00108 {
00109 if ( !$this->_oEditShop ) {
00110 $this->_oEditShop = $this->getConfig()->getActiveShop();
00111 if ( $this->_oEditShop->getId() != $sShopId ) {
00112 $oEditShop = oxNew( 'oxshop' );
00113 if ( $oEditShop->load( $sShopId ) ) {
00114 $this->_oEditShop = $oEditShop;
00115 }
00116 }
00117 }
00118 return $this->_oEditShop;
00119 }
00120
00128 public function init()
00129 {
00130 $myConfig = $this->getConfig();
00131
00132
00133 if ( !$this->_authorize() ) {
00134 oxUtils::getInstance()->redirect( 'index.php');
00135 exit;
00136 }
00137
00138 $oLang = oxLang::getInstance();
00139
00140
00141 $this->_iEditLang = $oLang->getEditLanguage();
00142 $oLang->setBaseLanguage();
00143
00144 parent::init();
00145
00146 $this->_aViewData['malladmin'] = oxSession::getVar( 'malladmin' );
00147 }
00148
00157 public function addGlobalParams( $oShop = null)
00158 {
00159 $mySession = $this->getSession();
00160 $myConfig = $this->getConfig();
00161 $oLang = oxLang::getInstance();
00162
00163 $oShop = parent::addGlobalParams( $oShop );
00164
00165
00166 $sURL = $myConfig->getConfigParam( 'sShopURL' ). $myConfig->getConfigParam( 'sAdminDir' );
00167
00168 if ($myConfig->getConfigParam('sAdminSSLURL')) {
00169 $sURL = $myConfig->getConfigParam('sAdminSSLURL');
00170 }
00171
00172 $oViewConf = $this->getViewConfig();
00173 $oViewConf->setViewConfigParam( 'selflink', $mySession->url($sURL.'/index.php') );
00174 $oViewConf->setViewConfigParam( 'ajaxlink', str_replace( '&', '&', $mySession->url( $sURL.'/oxajax.php' ) ) );
00175 $oViewConf->setViewConfigParam( 'sServiceUrl', $this->getServiceUrl() );
00176 $oViewConf->setViewConfigParam( 'blLoadDynContents', $myConfig->getConfigParam( 'blLoadDynContents' ) );
00177 $oViewConf->setViewConfigParam( 'sShopCountry', $myConfig->getConfigParam( 'sShopCountry' ) );
00178
00179 if ( $sURL = $myConfig->getConfigParam( 'sAdminSSLURL') ) {
00180 $oViewConf->setViewConfigParam( 'selflink', $mySession->url($sURL.'/index.php') );
00181 $oViewConf->setViewConfigParam( 'ajaxlink', str_replace( '&', '&', $mySession->url( $sURL.'/oxajax.php' ) ) );
00182 }
00183
00184
00185 $iDynInterfaceLanguage = $myConfig->getConfigParam( 'iDynInterfaceLanguage' );
00186
00187 $this->_aViewData['adminlang'] = isset( $iDynInterfaceLanguage )?$iDynInterfaceLanguage:$oLang->getTplLanguage();
00188 $this->_aViewData['charset'] = $oLang->translateString( 'charset' );
00189
00190 return $oShop;
00191 }
00192
00198 protected function _getServiceProtocol()
00199 {
00200 return $this->getConfig()->isSsl() ? 'https' : 'http';
00201 }
00202
00210 public function getServiceUrl( $sLangAbbr = null )
00211 {
00212 if ( $this->_sServiceUrl === null ) {
00213
00214 $sProtocol = $this->_getServiceProtocol();
00215
00216
00217
00218 $sUrl = $sProtocol . '://admin.oxid-esales.com/CE/';
00219
00220 $sCountry = $this->_getCountryByCode( $this->getConfig()->getConfigParam( 'sShopCountry' ) );
00221
00222 if ( !$sLangAbbr ) {
00223 $oLang = oxLang::getInstance();
00224 $sLangAbbr = $oLang->getLanguageAbbr( $oLang->getTplLanguage() );
00225 }
00226
00227 $this->_sServiceUrl = $sUrl . $this->_getShopVersionNr()."/{$sCountry}/{$sLangAbbr}/";
00228 }
00229
00230 return $this->_sServiceUrl;
00231 }
00232
00238 protected function _getShopVersionNr()
00239 {
00240 $myConfig = $this->getConfig();
00241
00242 if ( $sShopID = $myConfig->getShopId() ) {
00243 $sQ = "select oxversion from oxshops where oxid = '$sShopID' ";
00244 $sVersion = oxDb::getDb()->getOne( $sQ );
00245 }
00246
00247 $sVersion = preg_replace( "/(^[^0-9]+)(.+)$/", "$2", $sVersion );
00248 return trim( $sVersion );
00249 }
00250
00258 protected function _setupNavigation( $sNode )
00259 {
00260
00261 if ( $sNode ) {
00262
00263 $myAdminNavig = $this->getNavigation();
00264
00265
00266 $iActTab = oxConfig::getParameter( 'actedit' );
00267 $iActTab = $iActTab?$iActTab:$this->_iDefEdit;
00268
00269 $sActTab = $iActTab?"&actedit=$iActTab":'';
00270
00271
00272 $this->_addNavigationHistory($sNode);
00273
00274
00275 $this->_aViewData['listurl'] = $myAdminNavig->getListUrl( $sNode ).$sActTab;
00276
00277
00278 $this->_aViewData['editurl'] = $myAdminNavig->getEditUrl( $sNode, $iActTab ).$sActTab;
00279 }
00280 }
00281
00289 protected function _addNavigationHistory( $sNode )
00290 {
00291 $myUtilsServer = oxUtilsServer::getInstance();
00292
00293
00294 $aHistory = explode('|', $myUtilsServer->getOxCookie('oxidadminhistory'));
00295 if (!is_array($aHistory)) {
00296 $aHistory = array();
00297 }
00298
00299 if (!in_array($sNode, $aHistory)) {
00300 $aHistory[] = $sNode;
00301 }
00302
00303 $myUtilsServer->setOxCookie('oxidadminhistory', implode('|', $aHistory));
00304 }
00305
00312 public function render()
00313 {
00314 $sReturn = parent::render();
00315
00316 $myConfig = $this->getConfig();
00317 $oLang = oxLang::getInstance();
00318
00319
00320 $this->_setupNavigation( oxConfig::getParameter( 'cl' ) );
00321
00322
00323 $sOxId = oxConfig::getParameter( 'oxid' );
00324 $this->_aViewData['oxid'] = ( !$sOxId )?-1:$sOxId;
00325
00326 $this->_aViewData['sumtype'] = $this->_aSumType;
00327
00328
00329 $this->_aViewData['actshop'] = $this->_sShopTitle;
00330 $this->_aViewData["shopid"] = $myConfig->getShopId();
00331
00332
00333 if ( $sActShopId = oxSession::getVar( 'actshop' ) ) {
00334
00335 $this->_aViewData['actshopobj'] = $this->_getEditShop( $sActShopId );
00336 }
00337
00338
00339 $this->_aViewData['actlang'] = $iLanguage = $oLang->getBaseLanguage();
00340 $this->_aViewData['editlanguage'] = $this->_iEditLang;
00341 $this->_aViewData['languages'] = $oLang->getLanguageArray( $iLanguage );
00342
00343
00344 list( $this->_aViewData['iMaxUploadFileSize'], $this->_aViewData['sMaxFormattedFileSize']) = $this->_getMaxUploadFileInfo( @ini_get("upload_max_filesize") );
00345
00346
00347 if ( !isset( $this->_aViewData['updatelist'] ) ) {
00348 $this->_aViewData['updatelist'] = oxConfig::getParameter( 'updatelist' );
00349 }
00350
00351 return $sReturn;
00352 }
00353
00362 protected function _getMaxUploadFileInfo( $iMaxFileSize, $blFormatted = false )
00363 {
00364 $iMaxFileSize = $iMaxFileSize?$iMaxFileSize:'2M';
00365
00366
00367 $iMaxFileSize = trim( $iMaxFileSize );
00368 $sParam = strtolower( $iMaxFileSize{ strlen( $iMaxFileSize )-1 } );
00369 switch( $sParam ) {
00370 case 'g':
00371 $iMaxFileSize *= 1024;
00372 case 'm':
00373 $iMaxFileSize *= 1024;
00374 case 'k':
00375 $iMaxFileSize *= 1024;
00376 }
00377
00378
00379 $aMarkers = array ( 'KB', 'MB', 'GB' );
00380 $sFormattedMaxSize = '';
00381
00382 $iSize = floor( $iMaxFileSize / 1024 );
00383 while ( $iSize && current( $aMarkers ) ) {
00384 $sFormattedMaxSize = $iSize . current( $aMarkers );
00385 $iSize = floor( $iSize / 1024 );
00386 next( $aMarkers );
00387 }
00388
00389 return array( $iMaxFileSize, $sFormattedMaxSize );
00390 }
00391
00397 public function save()
00398 {
00399 }
00400
00408 public function resetContentCache( $blForceResete = null )
00409 {
00410 $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam( 'blClearCacheOnLogout' );
00411
00412
00413 if ( !$blDeleteCacheOnLogout || $blForceResete ) {
00414 oxUtils::getInstance()->oxResetFileCache();
00415 }
00416 }
00417
00427 public function resetCounter( $sCounterType, $sValue = null )
00428 {
00429 $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam( 'blClearCacheOnLogout' );
00430 $myUtilsCount = oxUtilsCount::getInstance();
00431
00432 if ( !$blDeleteCacheOnLogout ) {
00433 switch ( $sCounterType ) {
00434 case 'priceCatArticle':
00435 $myUtilsCount->resetPriceCatArticleCount( $sValue );
00436 break;
00437 case 'catArticle':
00438 $myUtilsCount->resetCatArticleCount( $sValue );
00439 break;
00440 case 'vendorArticle':
00441 $myUtilsCount->resetVendorArticleCount( $sValue );
00442 break;
00443 case 'manufacturerArticle':
00444 $myUtilsCount->resetManufacturerArticleCount( $sValue );
00445 break;
00446 }
00447 }
00448 }
00449
00450
00459 protected function _allowAdminEdit( $sUserId )
00460 {
00461
00462
00463 return true;
00464 }
00465
00473 protected function _getCountryByCode( $sCountryCode )
00474 {
00475 $myConfig = $this->getConfig();
00476
00477
00478 $sCountry = 'international';
00479
00480 $aLandIds = oxLang::getInstance()->getLanguageIds();
00481
00482 $iEnglishId = array_search("en", $aLandIds);
00483
00484 $sEnTag = oxLang::getInstance()->getLanguageTag($iEnglishId);
00485
00486 if ( !empty($sCountryCode) ) {
00487 $sQ = "select oxtitle$sEnTag from oxcountry where oxisoalpha2 = " . oxDb::getDb()->quote( $sCountryCode );
00488 $sCountry = oxDb::getDb()->getOne( $sQ );
00489 }
00490
00491 return strtolower( $sCountry );
00492 }
00493
00499 protected function _authorize()
00500 {
00501 return ( bool ) ( $this->getSession()->checkSessionChallenge() && count( oxUtilsServer::getInstance()->getOxCookie() ) && oxUtils::getInstance()->checkAccessRights() );
00502 }
00503
00509 public function getNavigation()
00510 {
00511 if ( self::$_oNaviTree == null ) {
00512 self::$_oNaviTree = oxNew( 'oxnavigationtree' );
00513 }
00514 return self::$_oNaviTree;
00515 }
00516
00522 public function getViewId()
00523 {
00524 $sClassName = strtolower( get_class( $this ) );
00525 return $this->getNavigation()->getClassId( $sClassName );
00526 }
00527
00533 public function chshp()
00534 {
00535 $sActShop = oxConfig::getParameter( 'shp' );
00536 oxSession::setVar( "shp", $sActShop );
00537 oxSession::setVar( 'currentadminshop', $sActShop );
00538 }
00539
00547 public function resetSeoData( $sShopId )
00548 {
00549 $oEncoder = oxSeoEncoder::getInstance();
00550 $oEncoder->markAsExpired( null, $sShopId );
00551
00552
00553 $oTagCloud = oxNew('oxtagcloud');
00554 $oTagCloud->resetTagCache();
00555 }
00556
00564 public function resetArtSeoUrl( $aArtIds )
00565 {
00566 if ( !is_array($aArtIds) ) {
00567 $aArtIds = array($aArtIds);
00568 }
00569 foreach ( $aArtIds as $sArtId ) {
00570 oxSeoEncoder::getInstance()->markAsExpired( $sArtId );
00571 }
00572 }
00573
00579 public function getPreviewId()
00580 {
00581 $sAdminSid = oxUtilsServer::getInstance()->getOxCookie( 'admin_sid' );
00582 $oUser = $this->getUser();
00583 return md5( $sAdminSid . $oUser->getId() . $oUser->oxuser__oxpassword->value . $oUser->oxuser__oxrights->value );
00584 }
00585 }