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