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             // passing shop info
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         // authorization check
00133         if ( !$this->_authorize() ) {
00134             oxUtils::getInstance()->redirect( 'index.php');
00135             exit;
00136         }
00137 
00138         $oLang = oxLang::getInstance();
00139 
00140         // language handling
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         // override cause of admin dir
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( '&amp;', '&', $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( '&amp;', '&', $mySession->url( $sURL.'/oxajax.php' ) ) );
00181         }
00182 
00183         // set langugae in admin
00184         $iDynInterfaceLanguage = $myConfig->getConfigParam( 'iDynInterfaceLanguage' );
00185         //$this->_aViewData['adminlang'] = isset( $iDynInterfaceLanguage )?$iDynInterfaceLanguage:$myConfig->getConfigParam( 'iAdminLanguage' );
00186         $this->_aViewData['adminlang'] = isset( $iDynInterfaceLanguage )?$iDynInterfaceLanguage:$oLang->getTplLanguage();
00187         $this->_aViewData['charset']   = $oLang->translateString( 'charset' );
00188 
00189         return $oShop;
00190     }
00191 
00197     protected function _getServiceProtocol()
00198     {
00199         return $this->getConfig()->isSsl() ? 'https' : 'http';
00200     }
00201 
00209     public function getServiceUrl( $sLangAbbr = null )
00210     {
00211         if ( $this->_sServiceUrl === null ) {
00212 
00213             $sProtocol = $this->_getServiceProtocol();
00214 
00215 
00216 
00217                 $sUrl = $sProtocol . '://admin.oxid-esales.com/CE/';
00218 
00219             $sCountry = $this->_getCountryByCode( $this->getConfig()->getConfigParam( 'sShopCountry' ) );
00220 
00221             if ( !$sLangAbbr ) {
00222                 $oLang = oxLang::getInstance();
00223                 $sLangAbbr = $oLang->getLanguageAbbr( $oLang->getTplLanguage() );
00224             }
00225 
00226             $this->_sServiceUrl = $sUrl . $this->_getShopVersionNr()."/{$sCountry}/{$sLangAbbr}/";
00227         }
00228 
00229         return $this->_sServiceUrl;
00230     }
00231 
00237     protected function _getShopVersionNr()
00238     {
00239         $myConfig = $this->getConfig();
00240 
00241         if ( $sShopID = $myConfig->getShopId() ) {
00242             $sQ = "select oxversion from oxshops where oxid = '$sShopID' ";
00243             $sVersion = oxDb::getDb()->getOne( $sQ );
00244         }
00245 
00246         $sVersion = preg_replace( "/(^[^0-9]+)(.+)$/", "$2", $sVersion );
00247         return trim( $sVersion );
00248     }
00249 
00257     protected function _setupNavigation( $sNode )
00258     {
00259         // navigation according to class
00260         if ( $sNode ) {
00261 
00262             $myAdminNavig = $this->getNavigation();
00263 
00264             // active tab
00265             $iActTab = oxConfig::getParameter( 'actedit' );
00266             $iActTab = $iActTab?$iActTab:$this->_iDefEdit;
00267 
00268             $sActTab = $iActTab?"&actedit=$iActTab":'';
00269 
00270             // store navigation history
00271             $this->_addNavigationHistory($sNode);
00272 
00273             // list url
00274             $this->_aViewData['listurl'] = $myAdminNavig->getListUrl( $sNode ).$sActTab;
00275 
00276             // edit url
00277             $this->_aViewData['editurl'] = $myAdminNavig->getEditUrl( $sNode, $iActTab ).$sActTab;
00278         }
00279     }
00280 
00288     protected function _addNavigationHistory( $sNode )
00289     {
00290         $myUtilsServer = oxUtilsServer::getInstance();
00291 
00292         // store navigation history
00293         $aHistory = explode('|',$myUtilsServer->getOxCookie('oxidadminhistory'));
00294         if(!is_array($aHistory)) {
00295             $aHistory = array();
00296         }
00297 
00298         if(!in_array($sNode,$aHistory)) {
00299             $aHistory[] = $sNode;
00300         }
00301 
00302         $myUtilsServer->setOxCookie('oxidadminhistory',implode('|',$aHistory));
00303     }
00304 
00311     public function render()
00312     {
00313         $sReturn = parent::render();
00314 
00315         $myConfig = $this->getConfig();
00316         $oLang = oxLang::getInstance();
00317 
00318         // sets up navigation data
00319         $this->_setupNavigation( oxConfig::getParameter( 'cl' ) );
00320 
00321         // active object id
00322         $sOxId = oxConfig::getParameter( 'oxid' );
00323         $this->_aViewData['oxid'] = ( !$sOxId )?-1:$sOxId;
00324         // add Sumtype to all templates
00325         $this->_aViewData['sumtype'] = $this->_aSumType;
00326 
00327         // active shop title
00328         $this->_aViewData['actshop'] = $this->_sShopTitle;
00329         $this->_aViewData["shopid"]  = $myConfig->getShopId();
00330 
00331         // loading active shop
00332         if ( $sActShopId = oxSession::getVar( 'actshop' ) ) {
00333             // load object
00334             $this->_aViewData['actshopobj'] =  $this->_getEditShop( $sActShopId );
00335         }
00336 
00337         // add language data to all templates
00338         $this->_aViewData['actlang']      = $iLanguage = $oLang->getBaseLanguage();
00339         $this->_aViewData['editlanguage'] = $this->_iEditLang;
00340         $this->_aViewData['languages'] = $oLang->getLanguageArray( $iLanguage );
00341 
00342         // setting maximum upload size
00343         list( $this->_aViewData['iMaxUploadFileSize'], $this->_aViewData['sMaxFormattedFileSize']) = $this->_getMaxUploadFileInfo( @ini_get("upload_max_filesize") );
00344 
00345         // "save-on-tab"
00346         if ( !isset( $this->_aViewData['updatelist'] ) ) {
00347             $this->_aViewData['updatelist'] = oxConfig::getParameter( 'updatelist' );
00348         }
00349 
00350         return $sReturn;
00351     }
00352 
00360     protected function _getMaxUploadFileInfo( $iMaxFileSize, $blFormatted = false )
00361     {
00362         $iMaxFileSize = $iMaxFileSize?$iMaxFileSize:'2M';
00363 
00364         // processing config
00365         $iMaxFileSize = trim( $iMaxFileSize );
00366         $sParam = strtolower( $iMaxFileSize{ strlen( $iMaxFileSize )-1 } );
00367         switch( $sParam ) {
00368             case 'g':
00369                 $iMaxFileSize *= 1024;
00370             case 'm':
00371                 $iMaxFileSize *= 1024;
00372             case 'k':
00373                 $iMaxFileSize *= 1024;
00374         }
00375 
00376         // formatting
00377         $aMarkers = array ( 'KB', 'MB', 'GB' );
00378         $sFormattedMaxSize = '';
00379 
00380         $iSize = floor( $iMaxFileSize / 1024 );
00381         while ( $iSize && current( $aMarkers ) ) {
00382             $sFormattedMaxSize = $iSize . current( $aMarkers );
00383             $iSize = floor( $iSize / 1024 );
00384             next( $aMarkers );
00385         }
00386 
00387         return array( $iMaxFileSize, $sFormattedMaxSize );
00388     }
00389 
00395     public function save()
00396     {
00397     }
00398 
00406     public function resetContentCache( $blForceResete = null )
00407     {
00408         $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam( 'blClearCacheOnLogout' );
00409 
00410 
00411             if ( !$blDeleteCacheOnLogout  || $blForceResete ) {
00412                 oxUtils::getInstance()->oxResetFileCache();
00413             }
00414     }
00415 
00425     public function resetCounter( $sCounterType, $sValue = null )
00426     {
00427         $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam( 'blClearCacheOnLogout' );
00428         $myUtilsCount = oxUtilsCount::getInstance();
00429 
00430         if ( !$blDeleteCacheOnLogout ) {
00431             switch ( $sCounterType ) {
00432                 case 'priceCatArticle':
00433                     $myUtilsCount->resetPriceCatArticleCount( $sValue );
00434                     break;
00435                 case 'catArticle':
00436                     $myUtilsCount->resetCatArticleCount( $sValue );
00437                     break;
00438                 case 'vendorArticle':
00439                     $myUtilsCount->resetVendorArticleCount( $sValue );
00440                     break;
00441                 case 'manufacturerArticle':
00442                     $myUtilsCount->resetManufacturerArticleCount( $sValue );
00443                     break;
00444             }
00445         }
00446     }
00447 
00448 
00457     protected function _allowAdminEdit( $sUserId )
00458     {
00459 
00460         //otherwise return true
00461         return true;
00462     }
00463 
00469     protected function _getCountryByCode( $sCountryCode )
00470     {
00471         $myConfig = $this->getConfig();
00472 
00473         //default country
00474         $sCountry = 'international';
00475 
00476         if ( !empty($sCountryCode) ) {
00477             $sQ = "select oxtitle_1 from oxcountry where oxisoalpha2 = " . oxDb::getDb()->quote( $sCountryCode );
00478             $sCountry = oxDb::getDb()->getOne( $sQ );
00479         }
00480 
00481         return strtolower( $sCountry );
00482     }
00483 
00489     protected function _authorize()
00490     {
00491         return ( bool ) ( count( oxUtilsServer::getInstance()->getOxCookie() ) && oxUtils::getInstance()->checkAccessRights() );
00492     }
00493 
00499     public function getNavigation()
00500     {
00501         if ( self::$_oNaviTree == null ) {
00502             self::$_oNaviTree = oxNew( 'oxnavigationtree' );
00503             self::$_oNaviTree->init();
00504         }
00505         return self::$_oNaviTree;
00506     }
00507 
00513     public function getViewId()
00514     {
00515         $sClassName = strtolower( get_class( $this ) );
00516         return $this->getNavigation()->getClassId( $sClassName );
00517     }
00518 
00524     public function chshp()
00525     {
00526         $sActShop = oxConfig::getParameter( 'actshop' );
00527         $this->getConfig()->setShopId( $sActShop );
00528         oxSession::setVar( "shp", $sActShop);
00529         oxSession::setVar( 'currentadminshop', $sActShop );
00530     }
00531 
00537     public function resetSeoData( $sShopId )
00538     {
00539         $oEncoder = oxSeoEncoder::getInstance();
00540         $oEncoder->markAsExpired( null, $sShopId );
00541 
00542         // resetting tag cache
00543         $oTagCloud = oxNew('oxtagcloud');
00544         $oTagCloud->resetTagCache();
00545     }
00546 
00552     public function getPreviewId()
00553     {
00554         $sAdminSid = oxUtilsServer::getInstance()->getOxCookie( 'admin_sid' );
00555         $oUser = $this->getUser();
00556         return md5( $sAdminSid . $oUser->getId() . $oUser->oxuser__oxpassword->value . $oUser->oxuser__oxrights->value );
00557     }
00558 }

Generated on Mon Oct 26 20:07:16 2009 for OXID eShop CE by  doxygen 1.5.5