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 
00089     protected $_sEditObjectId = null;
00090 
00094     public function __construct()
00095     {
00096         $myConfig = $this->getConfig();
00097         $myConfig->setConfigParam( 'blAdmin', true );
00098         $this->setAdminMode( true );
00099 
00100         if ( $oShop = $this->_getEditShop( $myConfig->getShopId() ) ) {
00101             // passing shop info
00102             $this->_sShopTitle   = $oShop->oxshops__oxname->getRawValue();
00103             $this->_sShopVersion = $oShop->oxshops__oxversion->value;
00104 
00105         }
00106     }
00107 
00115     protected function _getEditShop( $sShopId )
00116     {
00117         if ( !$this->_oEditShop ) {
00118             $this->_oEditShop = $this->getConfig()->getActiveShop();
00119             if ( $this->_oEditShop->getId() != $sShopId ) {
00120                 $oEditShop = oxNew( 'oxshop' );
00121                 if ( $oEditShop->load( $sShopId ) ) {
00122                     $this->_oEditShop = $oEditShop;
00123                 }
00124             }
00125         }
00126         return $this->_oEditShop;
00127     }
00128 
00136     public function init()
00137     {
00138         $myConfig = $this->getConfig();
00139 
00140         // authorization check
00141         if ( !$this->_authorize() ) {
00142             oxRegistry::getUtils()->redirect( 'index.php', true, 302 );
00143             exit;
00144         }
00145 
00146         $oLang = oxRegistry::getLang();
00147 
00148         // language handling
00149         $this->_iEditLang = $oLang->getEditLanguage();
00150         $oLang->setBaseLanguage();
00151 
00152         parent::init();
00153 
00154             $this->_aViewData['malladmin'] = oxSession::getVar( 'malladmin' );
00155     }
00156 
00165     public function addGlobalParams( $oShop = null)
00166     {
00167         $mySession = $this->getSession();
00168         $myConfig  = $this->getConfig();
00169         $oLang = oxRegistry::getLang();
00170 
00171         $oShop = parent::addGlobalParams( $oShop );
00172 
00173         // override cause of admin dir
00174         $sURL = $myConfig->getConfigParam( 'sShopURL' ). $myConfig->getConfigParam( 'sAdminDir' ) . "/";
00175 
00176         if ($myConfig->getConfigParam('sAdminSSLURL')) {
00177             $sURL = $myConfig->getConfigParam('sAdminSSLURL');
00178         }
00179 
00180         $oViewConf = $this->getViewConfig();
00181         $oViewConf->setViewConfigParam( 'selflink', oxRegistry::get("oxUtilsUrl")->processUrl($sURL.'index.php?editlanguage='.$this->_iEditLang, false) );
00182         $oViewConf->setViewConfigParam( 'ajaxlink', str_replace( '&amp;', '&', oxRegistry::get("oxUtilsUrl")->processUrl( $sURL.'oxajax.php?editlanguage='.$this->_iEditLang, false ) ) );
00183         $oViewConf->setViewConfigParam( 'sServiceUrl', $this->getServiceUrl() );
00184         $oViewConf->setViewConfigParam( 'blLoadDynContents', $myConfig->getConfigParam( 'blLoadDynContents' ) );
00185         $oViewConf->setViewConfigParam( 'sShopCountry', $myConfig->getConfigParam( 'sShopCountry' ) );
00186 
00187         // set langugae in admin
00188         $iDynInterfaceLanguage = $myConfig->getConfigParam( 'iDynInterfaceLanguage' );
00189         //$this->_aViewData['adminlang'] = isset( $iDynInterfaceLanguage )?$iDynInterfaceLanguage:$myConfig->getConfigParam( 'iAdminLanguage' );
00190         $this->_aViewData['adminlang'] = isset( $iDynInterfaceLanguage )?$iDynInterfaceLanguage:$oLang->getTplLanguage();
00191         $this->_aViewData['charset']   = $this->getCharSet();
00192 
00193         //setting active currency object
00194         $this->_aViewData["oActCur"] = $myConfig->getActShopCurrencyObject();
00195 
00196         return $oShop;
00197     }
00198 
00204     protected function _getServiceProtocol()
00205     {
00206         return $this->getConfig()->isSsl() ? 'https' : 'http';
00207     }
00208 
00216     public function getServiceUrl( $sLangAbbr = null )
00217     {
00218         if ( $this->_sServiceUrl === null ) {
00219 
00220             $sProtocol = $this->_getServiceProtocol();
00221 
00222 
00223 
00224                 $sUrl = $sProtocol . '://admin.oxid-esales.com/CE/';
00225 
00226             $sCountry = $this->_getCountryByCode( $this->getConfig()->getConfigParam( 'sShopCountry' ) );
00227 
00228             if ( !$sLangAbbr ) {
00229                 $oLang = oxRegistry::getLang();
00230                 $sLangAbbr = $oLang->getLanguageAbbr( $oLang->getTplLanguage() );
00231             }
00232 
00233             if ( $sLangAbbr != "de" ) {
00234                 $sLangAbbr = "en";
00235             }
00236 
00237             $this->_sServiceUrl = $sUrl . $this->_getShopVersionNr()."/{$sCountry}/{$sLangAbbr}/";
00238         }
00239 
00240         return $this->_sServiceUrl;
00241     }
00242 
00248     protected function _getShopVersionNr()
00249     {
00250         $myConfig = $this->getConfig();
00251 
00252         if ( $sShopID = $myConfig->getShopId() ) {
00253             $sQ = "select oxversion from oxshops where oxid = '$sShopID' ";
00254             $sVersion = oxDb::getDb()->getOne( $sQ, false, false );
00255         }
00256 
00257         $sVersion = preg_replace( "/(^[^0-9]+)(.+)$/", "$2", $sVersion );
00258         return trim( $sVersion );
00259     }
00260 
00268     protected function _setupNavigation( $sNode )
00269     {
00270         // navigation according to class
00271         if ( $sNode ) {
00272 
00273             $myAdminNavig = $this->getNavigation();
00274 
00275             // active tab
00276             $iActTab = oxConfig::getParameter( 'actedit' );
00277             $iActTab = $iActTab?$iActTab:$this->_iDefEdit;
00278 
00279             $sActTab = $iActTab?"&actedit=$iActTab":'';
00280 
00281             // store navigation history
00282             $this->_addNavigationHistory($sNode);
00283 
00284             // list url
00285             $this->_aViewData['listurl'] = $myAdminNavig->getListUrl( $sNode ).$sActTab;
00286 
00287             // edit url
00288             $this->_aViewData['editurl'] = $myAdminNavig->getEditUrl( $sNode, $iActTab ).$sActTab;
00289         }
00290     }
00291 
00299     protected function _addNavigationHistory( $sNode )
00300     {
00301         $myUtilsServer = oxRegistry::get("oxUtilsServer");
00302 
00303         // store navigation history
00304         $aHistory = explode('|', $myUtilsServer->getOxCookie('oxidadminhistory'));
00305         if (!is_array($aHistory)) {
00306             $aHistory = array();
00307         }
00308 
00309         if (!in_array($sNode, $aHistory)) {
00310             $aHistory[] = $sNode;
00311         }
00312 
00313         $myUtilsServer->setOxCookie('oxidadminhistory', implode('|', $aHistory));
00314     }
00315 
00322     public function render()
00323     {
00324         $sReturn = parent::render();
00325 
00326         $myConfig = $this->getConfig();
00327         $oLang = oxRegistry::getLang();
00328 
00329         // sets up navigation data
00330         $this->_setupNavigation( oxConfig::getParameter( 'cl' ) );
00331 
00332         // active object id
00333         $sOxId = $this->getEditObjectId();
00334         $this->_aViewData['oxid'] = ( !$sOxId )?-1:$sOxId;
00335         // add Sumtype to all templates
00336         $this->_aViewData['sumtype'] = $this->_aSumType;
00337 
00338         // active shop title
00339         $this->_aViewData['actshop'] = $this->_sShopTitle;
00340         $this->_aViewData["shopid"]  = $myConfig->getShopId();
00341 
00342         // loading active shop
00343         if ( $sActShopId = oxSession::getVar( 'actshop' ) ) {
00344             // load object
00345             $this->_aViewData['actshopobj'] =  $this->_getEditShop( $sActShopId );
00346         }
00347 
00348         // add language data to all templates
00349         $this->_aViewData['actlang']      = $iLanguage = $oLang->getBaseLanguage();
00350         $this->_aViewData['editlanguage'] = $this->_iEditLang;
00351         $this->_aViewData['languages'] = $oLang->getLanguageArray( $iLanguage );
00352 
00353         // setting maximum upload size
00354         list( $this->_aViewData['iMaxUploadFileSize'], $this->_aViewData['sMaxFormattedFileSize']) = $this->_getMaxUploadFileInfo( @ini_get("upload_max_filesize") );
00355 
00356         // "save-on-tab"
00357         if ( !isset( $this->_aViewData['updatelist'] ) ) {
00358             $this->_aViewData['updatelist'] = oxConfig::getParameter( 'updatelist' );
00359         }
00360 
00361         return $sReturn;
00362     }
00363 
00372     protected function _getMaxUploadFileInfo( $iMaxFileSize, $blFormatted = false )
00373     {
00374         $iMaxFileSize = $iMaxFileSize?$iMaxFileSize:'2M';
00375 
00376         // processing config
00377         $iMaxFileSize = trim( $iMaxFileSize );
00378         $sParam = strtolower( $iMaxFileSize{ strlen( $iMaxFileSize )-1 } );
00379         switch( $sParam ) {
00380             case 'g':
00381                 $iMaxFileSize *= 1024;
00382             case 'm':
00383                 $iMaxFileSize *= 1024;
00384             case 'k':
00385                 $iMaxFileSize *= 1024;
00386         }
00387 
00388         // formatting
00389         $aMarkers = array ( 'KB', 'MB', 'GB' );
00390         $sFormattedMaxSize = '';
00391 
00392         $iSize = floor( $iMaxFileSize / 1024 );
00393         while ( $iSize && current( $aMarkers ) ) {
00394             $sFormattedMaxSize = $iSize . " " . current( $aMarkers );
00395             $iSize = floor( $iSize / 1024 );
00396             next( $aMarkers );
00397         }
00398 
00399         return array( $iMaxFileSize, $sFormattedMaxSize );
00400     }
00401 
00407     public function save()
00408     {
00409     }
00410 
00418     public function resetContentCache( $blForceReset = null )
00419     {
00420         $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam( 'blClearCacheOnLogout' );
00421 
00422         if ( !$blDeleteCacheOnLogout || $blForceReset ) {
00423 
00424 
00425                 oxRegistry::getUtils()->oxResetFileCache();
00426 
00427         }
00428     }
00429 
00439     public function resetCounter( $sCounterType, $sValue = null )
00440     {
00441         $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam( 'blClearCacheOnLogout' );
00442         $myUtilsCount = oxRegistry::get("oxUtilsCount");
00443 
00444         if ( !$blDeleteCacheOnLogout ) {
00445             switch ( $sCounterType ) {
00446                 case 'priceCatArticle':
00447                     $myUtilsCount->resetPriceCatArticleCount( $sValue );
00448                     break;
00449                 case 'catArticle':
00450                     $myUtilsCount->resetCatArticleCount( $sValue );
00451                     break;
00452                 case 'vendorArticle':
00453                     $myUtilsCount->resetVendorArticleCount( $sValue );
00454                     break;
00455                 case 'manufacturerArticle':
00456                     $myUtilsCount->resetManufacturerArticleCount( $sValue );
00457                     break;
00458             }
00459         }
00460     }
00461 
00462 
00471     protected function _allowAdminEdit( $sUserId )
00472     {
00473 
00474         //otherwise return true
00475         return true;
00476     }
00477 
00485     protected function _getCountryByCode( $sCountryCode )
00486     {
00487         $myConfig = $this->getConfig();
00488 
00489         //default country
00490         $sCountry = 'international';
00491 
00492         if ( !empty( $sCountryCode ) ) {
00493             $aLangIds = oxRegistry::getLang()->getLanguageIds();
00494             $iEnglishId = array_search("en", $aLangIds);
00495             if ( false !== $iEnglishId ) {
00496                 $sViewName = getViewName( "oxcountry", $iEnglishId );
00497                 $sQ = "select oxtitle from {$sViewName} where oxisoalpha2 = " . oxDb::getDb()->quote( $sCountryCode );
00498                 $sCountryName = oxDb::getDb()->getOne( $sQ, false, false );
00499                 if ( $sCountryName ) {
00500                     $sCountry = $sCountryName;
00501                 }
00502             } else {
00503                 // handling when english language is deleted
00504                 switch ( $sCountryCode ) {
00505                     case 'de':
00506                         return 'germany';
00507                     default:
00508                         return 'international';
00509                 }
00510             }
00511         }
00512         return strtolower( $sCountry );
00513     }
00514 
00520     protected function _authorize()
00521     {
00522         return ( bool ) (
00523                 $this->getSession()->checkSessionChallenge()
00524                 && count( oxRegistry::get("oxUtilsServer")->getOxCookie() )
00525                 && oxRegistry::getUtils()->checkAccessRights()
00526             );
00527     }
00528 
00534     public function getNavigation()
00535     {
00536         if ( self::$_oNaviTree == null ) {
00537             self::$_oNaviTree = oxNew( 'oxnavigationtree' );
00538         }
00539         return self::$_oNaviTree;
00540     }
00541 
00547     public function getViewId()
00548     {
00549         $sClassName = strtolower( get_class( $this ) );
00550         return $this->getNavigation()->getClassId( $sClassName );
00551     }
00552 
00558     public function chshp()
00559     {
00560         $sActShop = oxConfig::getParameter( 'shp' );
00561         oxSession::setVar( "shp", $sActShop );
00562         oxSession::setVar( 'currentadminshop', $sActShop );
00563     }
00564 
00572     public function resetSeoData( $sShopId )
00573     {
00574         $aTypes = array( 'oxarticle', 'oxcategory', 'oxvendor', 'oxcontent', 'dynamic', 'oxmanufacturer' );
00575         $oEncoder = oxRegistry::get("oxSeoEncoder");
00576         foreach ( $aTypes as $sType ) {
00577             $oEncoder->markAsExpired( null, $sShopId, 1, null, "oxtype = '{$sType}'" );
00578         }
00579 
00580         // resetting tag cache
00581         $oTagCloud = oxNew('oxtagcloud');
00582         $oTagCloud->resetCache();
00583     }
00584 
00590     public function getPreviewId()
00591     {
00592         return oxRegistry::getUtils()->getPreviewId();
00593     }
00594 
00600     public function getEditObjectId()
00601     {
00602         if ( null === ( $sId = $this->_sEditObjectId ) ) {
00603             if ( null === ( $sId = oxConfig::getParameter( "oxid" ) ) ) {
00604                 $sId = oxSession::getVar( "saved_oxid" );
00605             }
00606         }
00607         return $sId;
00608     }
00609 
00617     public function setEditObjectId( $sId )
00618     {
00619         $this->_sEditObjectId = $sId;
00620         $this->_aViewData["updatelist"] = 1;
00621     }
00622 }