oxadminview.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxAdminView extends oxView
00009 {
00010 
00016     protected $_aSumType = array(
00017         0 => 'abs',
00018         1 => '%',
00019         2 => 'itm'
00020     );
00021 
00027     protected $_sThisTemplate = null;
00028 
00035     protected $_iDefEdit = 0;
00036 
00042     protected static $_oNaviTree = null;
00043 
00049     protected $_iEditLang = 0;
00050 
00056     protected $_sShopTitle = " - ";
00057 
00063     protected $_sShopVersion = null;
00064 
00070     protected $_sServiceUrl = null;
00071 
00077     protected static $_sAuthUserRights = null;
00078 
00084     protected $_oEditShop = null;
00085 
00091     protected $_sEditObjectId = null;
00092 
00096     public function __construct()
00097     {
00098         $myConfig = $this->getConfig();
00099         $myConfig->setConfigParam('blAdmin', true);
00100         $this->setAdminMode(true);
00101 
00102         if ($oShop = $this->_getEditShop($myConfig->getShopId())) {
00103             // passing shop info
00104             $this->_sShopTitle = $oShop->oxshops__oxname->getRawValue();
00105             $this->_sShopVersion = $oShop->oxshops__oxversion->value;
00106 
00107         }
00108     }
00109 
00117     protected function _getEditShop($sShopId)
00118     {
00119         if (!$this->_oEditShop) {
00120             $this->_oEditShop = $this->getConfig()->getActiveShop();
00121             if ($this->_oEditShop->getId() != $sShopId) {
00122                 $oEditShop = oxNew('oxshop');
00123                 if ($oEditShop->load($sShopId)) {
00124                     $this->_oEditShop = $oEditShop;
00125                 }
00126             }
00127         }
00128 
00129         return $this->_oEditShop;
00130     }
00131 
00137     public function init()
00138     {
00139         $myConfig = $this->getConfig();
00140 
00141         // authorization check
00142         if (!$this->_authorize()) {
00143             oxRegistry::getUtils()->redirect('index.php', true, 302);
00144             exit;
00145         }
00146 
00147         $oLang = oxRegistry::getLang();
00148 
00149         // language handling
00150         $this->_iEditLang = $oLang->getEditLanguage();
00151         $oLang->setBaseLanguage();
00152 
00153         parent::init();
00154 
00155         $this->_aViewData['malladmin'] = oxRegistry::getSession()->getVariable('malladmin');
00156     }
00157 
00166     public function addGlobalParams($oShop = null)
00167     {
00168         $mySession = $this->getSession();
00169         $myConfig = $this->getConfig();
00170         $oLang = oxRegistry::getLang();
00171 
00172         $oShop = parent::addGlobalParams($oShop);
00173 
00174         // override cause of admin dir
00175         $sURL = $myConfig->getConfigParam('sShopURL') . $myConfig->getConfigParam('sAdminDir') . "/";
00176 
00177         if ($myConfig->getConfigParam('sAdminSSLURL')) {
00178             $sURL = $myConfig->getConfigParam('sAdminSSLURL');
00179         }
00180 
00181         $oViewConf = $this->getViewConfig();
00182         $oViewConf->setViewConfigParam('selflink', oxRegistry::get("oxUtilsUrl")->processUrl($sURL . 'index.php?editlanguage=' . $this->_iEditLang, false));
00183         $oViewConf->setViewConfigParam('ajaxlink', str_replace('&amp;', '&', oxRegistry::get("oxUtilsUrl")->processUrl($sURL . 'oxajax.php?editlanguage=' . $this->_iEditLang, false)));
00184         $oViewConf->setViewConfigParam('sServiceUrl', $this->getServiceUrl());
00185         $oViewConf->setViewConfigParam('blLoadDynContents', $myConfig->getConfigParam('blLoadDynContents'));
00186         $oViewConf->setViewConfigParam('sShopCountry', $myConfig->getConfigParam('sShopCountry'));
00187 
00188         // set langugae in admin
00189         $iDynInterfaceLanguage = $myConfig->getConfigParam('iDynInterfaceLanguage');
00190         //$this->_aViewData['adminlang'] = isset( $iDynInterfaceLanguage )?$iDynInterfaceLanguage:$myConfig->getConfigParam( 'iAdminLanguage' );
00191         $this->_aViewData['adminlang'] = isset($iDynInterfaceLanguage) ? $iDynInterfaceLanguage : $oLang->getTplLanguage();
00192         $this->_aViewData['charset'] = $this->getCharSet();
00193 
00194         //setting active currency object
00195         $this->_aViewData["oActCur"] = $myConfig->getActShopCurrencyObject();
00196 
00197         return $oShop;
00198     }
00199 
00205     protected function _getServiceProtocol()
00206     {
00207         return $this->getConfig()->isSsl() ? 'https' : 'http';
00208     }
00209 
00217     public function getServiceUrl($sLangAbbr = null)
00218     {
00219         if ($this->_sServiceUrl === null) {
00220 
00221             $sProtocol = $this->_getServiceProtocol();
00222 
00223 
00224 
00225             $sUrl = $sProtocol . '://admin.oxid-esales.com/CE/';
00226 
00227             $sCountry = $this->_getCountryByCode($this->getConfig()->getConfigParam('sShopCountry'));
00228 
00229             if (!$sLangAbbr) {
00230                 $oLang = oxRegistry::getLang();
00231                 $sLangAbbr = $oLang->getLanguageAbbr($oLang->getTplLanguage());
00232             }
00233 
00234             if ($sLangAbbr != "de") {
00235                 $sLangAbbr = "en";
00236             }
00237 
00238             $this->_sServiceUrl = $sUrl . $this->_getShopVersionNr() . "/{$sCountry}/{$sLangAbbr}/";
00239         }
00240 
00241         return $this->_sServiceUrl;
00242     }
00243 
00249     protected function _getShopVersionNr()
00250     {
00251         $myConfig = $this->getConfig();
00252 
00253         if ($sShopID = $myConfig->getShopId()) {
00254             $sQ = "select oxversion from oxshops where oxid = '$sShopID' ";
00255             $sVersion = oxDb::getDb()->getOne($sQ, false, false);
00256         }
00257 
00258         $sVersion = preg_replace("/(^[^0-9]+)(.+)$/", "$2", $sVersion);
00259 
00260         return trim($sVersion);
00261     }
00262 
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 = oxRegistry::getConfig()->getRequestParameter('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 
00297     protected function _addNavigationHistory($sNode)
00298     {
00299         $myUtilsServer = oxRegistry::get("oxUtilsServer");
00300 
00301         // store navigation history
00302         $aHistory = explode('|', $myUtilsServer->getOxCookie('oxidadminhistory'));
00303         if (!is_array($aHistory)) {
00304             $aHistory = array();
00305         }
00306 
00307         if (!in_array($sNode, $aHistory)) {
00308             $aHistory[] = $sNode;
00309         }
00310 
00311         $myUtilsServer->setOxCookie('oxidadminhistory', implode('|', $aHistory));
00312     }
00313 
00320     public function render()
00321     {
00322         $sReturn = parent::render();
00323 
00324         $myConfig = $this->getConfig();
00325         $oLang = oxRegistry::getLang();
00326 
00327         // sets up navigation data
00328         $this->_setupNavigation(oxRegistry::getConfig()->getRequestParameter('cl'));
00329 
00330         // active object id
00331         $sOxId = $this->getEditObjectId();
00332         $this->_aViewData['oxid'] = (!$sOxId) ? -1 : $sOxId;
00333         // add Sumtype to all templates
00334         $this->_aViewData['sumtype'] = $this->_aSumType;
00335 
00336         // active shop title
00337         $this->_aViewData['actshop'] = $this->_sShopTitle;
00338         $this->_aViewData["shopid"] = $myConfig->getShopId();
00339 
00340         // loading active shop
00341         if ($sActShopId = oxRegistry::getSession()->getVariable('actshop')) {
00342             // load object
00343             $this->_aViewData['actshopobj'] = $this->_getEditShop($sActShopId);
00344         }
00345 
00346         // add language data to all templates
00347         $this->_aViewData['actlang'] = $iLanguage = $oLang->getBaseLanguage();
00348         $this->_aViewData['editlanguage'] = $this->_iEditLang;
00349         $this->_aViewData['languages'] = $oLang->getLanguageArray($iLanguage);
00350 
00351         // setting maximum upload size
00352         list($this->_aViewData['iMaxUploadFileSize'], $this->_aViewData['sMaxFormattedFileSize']) = $this->_getMaxUploadFileInfo(@ini_get("upload_max_filesize"));
00353 
00354         // "save-on-tab"
00355         if (!isset($this->_aViewData['updatelist'])) {
00356             $this->_aViewData['updatelist'] = oxRegistry::getConfig()->getRequestParameter('updatelist');
00357         }
00358 
00359         return $sReturn;
00360     }
00361 
00370     protected function _getMaxUploadFileInfo($iMaxFileSize, $blFormatted = false)
00371     {
00372         $iMaxFileSize = $iMaxFileSize ? $iMaxFileSize : '2M';
00373 
00374         // processing config
00375         $iMaxFileSize = trim($iMaxFileSize);
00376         $sParam = strtolower($iMaxFileSize{strlen($iMaxFileSize) - 1});
00377         switch ($sParam) {
00378             case 'g':
00379                 $iMaxFileSize *= 1024;
00380             // no break
00381             case 'm':
00382                 $iMaxFileSize *= 1024;
00383             // no break
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 
00405     public function save()
00406     {
00407         $this->resetContentCache();
00408     }
00409 
00415     public function resetContentCache($blForceReset = null)
00416     {
00417         $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam('blClearCacheOnLogout');
00418 
00419         if (!$blDeleteCacheOnLogout || $blForceReset) {
00420 
00421 
00422             oxRegistry::getUtils()->oxResetFileCache();
00423 
00424         }
00425     }
00426 
00434     public function resetCounter($sCounterType, $sValue = null)
00435     {
00436         $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam('blClearCacheOnLogout');
00437         $myUtilsCount = oxRegistry::get("oxUtilsCount");
00438 
00439         if (!$blDeleteCacheOnLogout) {
00440             switch ($sCounterType) {
00441                 case 'priceCatArticle':
00442                     $myUtilsCount->resetPriceCatArticleCount($sValue);
00443                     break;
00444                 case 'catArticle':
00445                     $myUtilsCount->resetCatArticleCount($sValue);
00446                     break;
00447                 case 'vendorArticle':
00448                     $myUtilsCount->resetVendorArticleCount($sValue);
00449                     break;
00450                 case 'manufacturerArticle':
00451                     $myUtilsCount->resetManufacturerArticleCount($sValue);
00452                     break;
00453             }
00454             $this->_resetContentCache();
00455         }
00456     }
00457 
00461     protected function _resetContentCache()
00462     {
00463     }
00464 
00473     protected function _allowAdminEdit($sUserId)
00474     {
00475 
00476         //otherwise return true
00477         return true;
00478     }
00479 
00487     protected function _getCountryByCode($sCountryCode)
00488     {
00489         $myConfig = $this->getConfig();
00490 
00491         //default country
00492         $sCountry = 'international';
00493 
00494         if (!empty($sCountryCode)) {
00495             $aLangIds = oxRegistry::getLang()->getLanguageIds();
00496             $iEnglishId = array_search("en", $aLangIds);
00497             if (false !== $iEnglishId) {
00498                 $sViewName = getViewName("oxcountry", $iEnglishId);
00499                 $sQ = "select oxtitle from {$sViewName} where oxisoalpha2 = " . oxDb::getDb()->quote($sCountryCode);
00500                 $sCountryName = oxDb::getDb()->getOne($sQ, false, false);
00501                 if ($sCountryName) {
00502                     $sCountry = $sCountryName;
00503                 }
00504             } else {
00505                 // handling when english language is deleted
00506                 switch ($sCountryCode) {
00507                     case 'de':
00508                         return 'germany';
00509                     default:
00510                         return 'international';
00511                 }
00512             }
00513         }
00514 
00515         return strtolower($sCountry);
00516     }
00517 
00523     protected function _authorize()
00524     {
00525         return ( bool ) (
00526             $this->getSession()->checkSessionChallenge()
00527             && count(oxRegistry::get("oxUtilsServer")->getOxCookie())
00528             && oxRegistry::getUtils()->checkAccessRights()
00529         );
00530     }
00531 
00537     public function getNavigation()
00538     {
00539         if (self::$_oNaviTree == null) {
00540             self::$_oNaviTree = oxNew('oxnavigationtree');
00541         }
00542 
00543         return self::$_oNaviTree;
00544     }
00545 
00551     public function getViewId()
00552     {
00553         $sClassName = strtolower(get_class($this));
00554 
00555         return $this->getNavigation()->getClassId($sClassName);
00556     }
00557 
00561     public function chshp()
00562     {
00563         $sActShop = oxRegistry::getConfig()->getRequestParameter('shp');
00564         oxRegistry::getSession()->setVariable("shp", $sActShop);
00565         oxRegistry::getSession()->setVariable('currentadminshop', $sActShop);
00566     }
00567 
00573     public function resetSeoData($sShopId)
00574     {
00575         $aTypes = array('oxarticle', 'oxcategory', 'oxvendor', 'oxcontent', 'dynamic', 'oxmanufacturer');
00576         $oEncoder = oxRegistry::get("oxSeoEncoder");
00577         foreach ($aTypes as $sType) {
00578             $oEncoder->markAsExpired(null, $sShopId, 1, null, "oxtype = '{$sType}'");
00579         }
00580 
00581         // resetting tag cache
00582         $oTagCloud = oxNew('oxtagcloud');
00583         $oTagCloud->resetCache();
00584     }
00585 
00591     public function getPreviewId()
00592     {
00593         return oxRegistry::getUtils()->getPreviewId();
00594     }
00595 
00601     public function getEditObjectId()
00602     {
00603         if (null === ($sId = $this->_sEditObjectId)) {
00604             if (null === ($sId = oxRegistry::getConfig()->getRequestParameter("oxid"))) {
00605                 $sId = oxRegistry::getSession()->getVariable("saved_oxid");
00606             }
00607         }
00608 
00609         return $sId;
00610     }
00611 
00617     public function setEditObjectId($sId)
00618     {
00619         $this->_sEditObjectId = $sId;
00620         $this->_aViewData["updatelist"] = 1;
00621     }
00622 }