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 $oViewConf = $this->getViewConfig();
00172 $oViewConf->setViewConfigParam( 'selflink', $sURL.'/index.php' );
00173 $oViewConf->setViewConfigParam( 'ajaxlink', str_replace( '&', '&', $mySession->url( $sURL.'/oxajax.php' ) ) );
00174 $oViewConf->setViewConfigParam( 'sServiceUrl', $this->getServiceUrl() );
00175 $oViewConf->setViewConfigParam( 'blLoadDynContents', $myConfig->getConfigParam( 'blLoadDynContents' ) );
00176 $oViewConf->setViewConfigParam( 'sShopCountry', $myConfig->getConfigParam( 'sShopCountry' ) );
00177
00178 if ( $sURL = $myConfig->getConfigParam( 'sAdminSSLURL') ) {
00179 $oViewConf->setViewConfigParam( 'selflink', $sURL.'/index.php' );
00180 $oViewConf->setViewConfigParam( 'ajaxlink', str_replace( '&', '&', $mySession->url( $sURL.'/oxajax.php' ) ) );
00181 }
00182
00183
00184 $iDynInterfaceLanguage = $myConfig->getConfigParam( 'iDynInterfaceLanguage' );
00185
00186 $this->_aViewData['adminlang'] = isset( $iDynInterfaceLanguage )?$iDynInterfaceLanguage:$oLang->getTplLanguage();
00187 $this->_aViewData['charset'] = $oLang->translateString( 'charset' );
00188
00189 return $oShop;
00190 }
00191
00197 public function getServiceUrl( $sLangAbbr=null )
00198 {
00199 if ( !empty($this->_sServiceUrl) )
00200 return $this->_sServiceUrl;
00201
00202 $myConfig = $this->getConfig();
00203
00204
00205
00206 $sUrl = 'http://admin.oxid-esales.com/CE/';
00207
00208 $sShopVersionNr = $this->_getShopVersionNr();
00209 $sCountry = $this->_getCountryByCode( $myConfig->getConfigParam( 'sShopCountry' ) );
00210
00211 if (!$iLang) {
00212 $oLang = oxLang::getInstance();
00213 $iLang = $oLang->getTplLanguage();
00214 $aLanguages = $oLang->getLanguageArray();
00215 $sLangAbbr = $aLanguages[$iLang]->abbr;
00216 }
00217
00218 $sUrl .= "{$sShopVersionNr}/{$sCountry}/{$sLangAbbr}/";
00219
00220 $this->_sServiceUrl = $sUrl;
00221
00222 return $this->_sServiceUrl;
00223 }
00224
00230 protected function _getShopVersionNr()
00231 {
00232 $myConfig = $this->getConfig();
00233
00234 if ( $sShopID = $myConfig->getShopId() ) {
00235 $sQ = "select oxversion from oxshops where oxid = '$sShopID' ";
00236 $sVersion = oxDb::getDb()->getOne( $sQ );
00237 }
00238
00239 $sVersion = preg_replace( "/(^[^0-9]+)(.+)$/", "$2", $sVersion );
00240 return trim( $sVersion );
00241 }
00242
00250 protected function _setupNavigation( $sNode )
00251 {
00252
00253 if ( $sNode ) {
00254
00255 $myAdminNavig = $this->getNavigation();
00256
00257
00258 $iActTab = oxConfig::getParameter( 'actedit' );
00259 $iActTab = $iActTab?$iActTab:$this->_iDefEdit;
00260
00261 $sActTab = $iActTab?"&actedit=$iActTab":'';
00262
00263
00264 $this->_addNavigationHistory($sNode);
00265
00266
00267 $this->_aViewData['listurl'] = $myAdminNavig->getListUrl( $sNode ).$sActTab;
00268
00269
00270 $this->_aViewData['editurl'] = $myAdminNavig->getEditUrl( $sNode, $iActTab ).$sActTab;
00271 }
00272 }
00273
00281 protected function _addNavigationHistory( $sNode )
00282 {
00283 $myUtilsServer = oxUtilsServer::getInstance();
00284
00285
00286 $aHistory = explode('|',$myUtilsServer->getOxCookie('oxidadminhistory'));
00287 if(!is_array($aHistory)) {
00288 $aHistory = array();
00289 }
00290
00291 if(!in_array($sNode,$aHistory)) {
00292 $aHistory[] = $sNode;
00293 }
00294
00295 $myUtilsServer->setOxCookie('oxidadminhistory',implode('|',$aHistory));
00296 }
00297
00304 public function render()
00305 {
00306 $sReturn = parent::render();
00307
00308 $myConfig = $this->getConfig();
00309 $oLang = oxLang::getInstance();
00310
00311
00312 $this->_setupNavigation( oxConfig::getParameter( 'cl' ) );
00313
00314
00315 $sOxId = oxConfig::getParameter( 'oxid' );
00316 $this->_aViewData['oxid'] = ( !$sOxId )?-1:$sOxId;
00317
00318 $this->_aViewData['sumtype'] = $this->_aSumType;
00319
00320
00321 $this->_aViewData['actshop'] = $this->_sShopTitle;
00322 $this->_aViewData["shopid"] = $myConfig->getShopId();
00323
00324
00325 if ( $sActShopId = oxSession::getVar( 'actshop' ) ) {
00326
00327 $this->_aViewData['actshopobj'] = $this->_getEditShop( $sActShopId );
00328 }
00329
00330
00331 $this->_aViewData['actlang'] = $iLanguage = $oLang->getBaseLanguage();
00332 $this->_aViewData['editlanguage'] = $this->_iEditLang;
00333 $this->_aViewData['languages'] = $oLang->getLanguageArray( $iLanguage );
00334
00335
00336 list( $this->_aViewData['iMaxUploadFileSize'], $this->_aViewData['sMaxFormattedFileSize']) = $this->_getMaxUploadFileInfo( @ini_get("upload_max_filesize") );
00337
00338
00339 if ( !isset( $this->_aViewData['updatelist'] ) ) {
00340 $this->_aViewData['updatelist'] = oxConfig::getParameter( 'updatelist' );
00341 }
00342
00343 return $sReturn;
00344 }
00345
00353 protected function _getMaxUploadFileInfo( $iMaxFileSize, $blFormatted = false )
00354 {
00355 $iMaxFileSize = $iMaxFileSize?$iMaxFileSize:'2M';
00356
00357
00358 $iMaxFileSize = trim( $iMaxFileSize );
00359 $sParam = strtolower( $iMaxFileSize{ strlen( $iMaxFileSize )-1 } );
00360 switch( $sParam ) {
00361 case 'g':
00362 $iMaxFileSize *= 1024;
00363 case 'm':
00364 $iMaxFileSize *= 1024;
00365 case 'k':
00366 $iMaxFileSize *= 1024;
00367 }
00368
00369
00370 $aMarkers = array ( 'KB', 'MB', 'GB' );
00371 $sFormattedMaxSize = '';
00372
00373 $iSize = floor( $iMaxFileSize / 1024 );
00374 while ( $iSize && current( $aMarkers ) ) {
00375 $sFormattedMaxSize = $iSize . current( $aMarkers );
00376 $iSize = floor( $iSize / 1024 );
00377 next( $aMarkers );
00378 }
00379
00380 return array( $iMaxFileSize, $sFormattedMaxSize );
00381 }
00382
00388 public function save()
00389 {
00390 }
00391
00399 public function resetContentCache( $blForceResete = null )
00400 {
00401 $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam( 'blClearCacheOnLogout' );
00402
00403
00404 if ( !$blDeleteCacheOnLogout || $blForceResete ) {
00405 oxUtils::getInstance()->oxResetFileCache();
00406 }
00407 }
00408
00418 public function resetCounter( $sCounterType, $sValue = null )
00419 {
00420 $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam( 'blClearCacheOnLogout' );
00421 $myUtilsCount = oxUtilsCount::getInstance();
00422
00423 if ( !$blDeleteCacheOnLogout ) {
00424 switch ( $sCounterType ) {
00425 case 'priceCatArticle':
00426 $myUtilsCount->resetPriceCatArticleCount( $sValue );
00427 break;
00428 case 'catArticle':
00429 $myUtilsCount->resetCatArticleCount( $sValue );
00430 break;
00431 case 'vendorArticle':
00432 $myUtilsCount->resetVendorArticleCount( $sValue );
00433 break;
00434 case 'manufacturerArticle':
00435 $myUtilsCount->resetManufacturerArticleCount( $sValue );
00436 break;
00437 }
00438 }
00439 }
00440
00441
00450 protected function _allowAdminEdit( $sUserId )
00451 {
00452
00453
00454 return true;
00455 }
00456
00462 protected function _getCountryByCode( $sCountryCode )
00463 {
00464 $myConfig = $this->getConfig();
00465
00466
00467 $sCountry = 'international';
00468
00469 if ( !empty($sCountryCode) ) {
00470 $sQ = "select oxtitle_1 from oxcountry where oxisoalpha2 = '$sCountryCode' ";
00471 $sCountry = oxDb::getDb()->getOne( $sQ );
00472 }
00473
00474 return strtolower( $sCountry );
00475 }
00476
00482 protected function _authorize()
00483 {
00484 return ( bool ) ( count( oxUtilsServer::getInstance()->getOxCookie() ) && oxUtils::getInstance()->checkAccessRights() );
00485 }
00486
00492 public function getNavigation()
00493 {
00494 if ( self::$_oNaviTree == null ) {
00495 self::$_oNaviTree = oxNew( 'oxnavigationtree' );
00496 self::$_oNaviTree->init();
00497 }
00498 return self::$_oNaviTree;
00499 }
00500
00506 public function getViewId()
00507 {
00508 $sClassName = strtolower( get_class( $this ) );
00509 return $this->getNavigation()->getClassId( $sClassName );
00510 }
00511
00517 public function chshp()
00518 {
00519 $sActShop = oxConfig::getParameter( 'actshop' );
00520 $this->getConfig()->setShopId( $sActShop );
00521 oxSession::setVar( "shp", $sActShop);
00522 oxSession::setVar( 'currentadminshop', $sActShop );
00523 }
00524
00530 public function resetSeoData( $sShopId )
00531 {
00532 $oEncoder = oxSeoEncoder::getInstance();
00533 $oEncoder->markAsExpired( null, $sShopId, 2 );
00534
00535
00536 $oTagCloud = oxNew('oxtagcloud');
00537 $oTagCloud->resetTagCache();
00538 }
00539
00545 public function getPreviewId()
00546 {
00547 $sAdminSid = oxUtilsServer::getInstance()->getOxCookie( 'admin_sid' );
00548 $oUser = $this->getUser();
00549 return md5( $sAdminSid . $oUser->getId() . $oUser->oxuser__oxpassword->value . $oUser->oxuser__oxrights->value );
00550 }
00551 }