00001 <?php
00002
00009 class oxAdminView extends oxView
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
00075 public function __construct()
00076 {
00077 $myConfig = $this->getConfig();
00078 $myConfig->setConfigParam( 'blAdmin', true );
00079
00080 if ( $sShopID = $myConfig->getShopId() ) {
00081 $oShop = oxNew( 'oxshop' );
00082 if ( $oShop->load( $sShopID ) ) {
00083
00084
00085 $this->_sShopTitle = $oShop->oxshops__oxname->getRawValue();
00086 $this->_sShopVersion = $oShop->oxshops__oxversion->value;
00087
00088 }
00089 }
00090 }
00091
00099 public function init()
00100 {
00101 $myConfig = $this->getConfig();
00102
00103
00104 if ( !$this->_authorize() ) {
00105 oxUtils::getInstance()->redirect( 'index.php' );
00106 exit();
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 $this->_iEditLang = oxLang::getInstance()->getEditLanguage();
00119 oxLang::getInstance()->setBaseLanguage();
00120
00121 parent::init();
00122
00123 $this->_aViewData['malladmin'] = oxSession::getVar( 'malladmin' );
00124 }
00125
00134 public function addGlobalParams( $oShop = null)
00135 {
00136 $mySession = $this->getSession();
00137 $myConfig = $this->getConfig();
00138
00139 $oShop = parent::addGlobalParams( $oShop );
00140
00141
00142 $sURL = $myConfig->getConfigParam( 'sShopURL' ). $myConfig->getConfigParam( 'sAdminDir' );
00143
00144 if ($myConfig->getConfigParam('sAdminSSLURL'))
00145 $sURL = $myConfig->getConfigParam('sAdminSSLURL');
00146
00147 $oViewConf = $this->getViewConfig();
00148 $oViewConf->setViewConfigParam( 'selflink', $sURL.'/index.php' );
00149 $oViewConf->setViewConfigParam( 'ajaxlink', str_replace( '&', '&', $mySession->url( $sURL.'/oxajax.php' ) ) );
00150 $oViewConf->setViewConfigParam( 'sServiceUrl', $this->getServiceUrl() );
00151 $oViewConf->setViewConfigParam( 'blLoadDynContents', $myConfig->getConfigParam( 'blLoadDynContents' ) );
00152 $oViewConf->setViewConfigParam( 'sShopCountry', $myConfig->getConfigParam( 'sShopCountry' ) );
00153
00154 if ( $sURL = $myConfig->getConfigParam( 'sAdminSSLURL') ) {
00155 $oViewConf->setViewConfigParam( 'selflink', $sURL.'/index.php' );
00156 $oViewConf->setViewConfigParam( 'ajaxlink', str_replace( '&', '&', $mySession->url( $sURL.'/oxajax.php' ) ) );
00157 }
00158
00159
00160 $iDynInterfaceLanguage = $myConfig->getConfigParam( 'iDynInterfaceLanguage' );
00161
00162 $this->_aViewData['adminlang'] = isset( $iDynInterfaceLanguage )?$iDynInterfaceLanguage:oxLang::getInstance()->getTplLanguage();
00163 $this->_aViewData['charset'] = oxLang::getInstance()->translateString( 'charset' );
00164
00165 return $oShop;
00166 }
00167
00173 public function getServiceUrl( $sLangAbbr=null )
00174 {
00175 if ( !empty($this->_sServiceUrl) )
00176 return $this->_sServiceUrl;
00177
00178 $myConfig = $this->getConfig();
00179
00180
00181
00182 $sUrl = 'http://admin.oxid-esales.com/CE/';
00183
00184 $sShopVersionNr = $this->_getShopVersionNr();
00185 $sCountry = $this->_getCountryByCode( $myConfig->getConfigParam( 'sShopCountry' ) );
00186
00187 if (!$iLang) {
00188 $iLang = oxLang::getInstance()->getTplLanguage();
00189 $aLanguages = oxLang::getInstance()->getLanguageArray();
00190 $sLangAbbr = $aLanguages[$iLang]->abbr;
00191 }
00192
00193 $sUrl .= "{$sShopVersionNr}/{$sCountry}/{$sLangAbbr}/";
00194
00195 $this->_sServiceUrl = $sUrl;
00196
00197 return $this->_sServiceUrl;
00198 }
00199
00205 protected function _getShopVersionNr()
00206 {
00207 $myConfig = $this->getConfig();
00208
00209 if ( $sShopID = $myConfig->getShopId() ) {
00210 $sQ = "select oxversion from oxshops where oxid = '$sShopID' ";
00211 $sVersion = oxDb::getDb()->getOne( $sQ );
00212 }
00213
00214 $sVersion = preg_replace( "/(^[^0-9]+)(.+)$/", "$2", $sVersion );
00215 return trim( $sVersion );
00216 }
00217
00225 protected function _setupNavigation( $sNode )
00226 {
00227
00228 if ( $sNode ) {
00229
00230 $myAdminNavig = $this->getNavigation();
00231
00232
00233 $iActTab = oxConfig::getParameter( 'actedit' );
00234 $iActTab = $iActTab?$iActTab:$this->_iDefEdit;
00235
00236 $sActTab = $iActTab?"&actedit=$iActTab":'';
00237
00238
00239 $this->_addNavigationHistory($sNode);
00240
00241
00242 $this->_aViewData['listurl'] = $myAdminNavig->getListUrl( $sNode ).$sActTab;
00243
00244
00245 $this->_aViewData['editurl'] = $myAdminNavig->getEditUrl( $sNode, $iActTab ).$sActTab;
00246 }
00247 }
00248
00256 protected function _addNavigationHistory( $sNode )
00257 {
00258
00259 $aHistory = explode('|',oxUtilsServer::getInstance()->getOxCookie('oxidadminhistory'));
00260 if(!is_array($aHistory)) {
00261 $aHistory = array();
00262 }
00263
00264 if(!in_array($sNode,$aHistory)) {
00265 $aHistory[] = $sNode;
00266 }
00267
00268 oxUtilsServer::getInstance()->setOxCookie('oxidadminhistory',implode('|',$aHistory));
00269 }
00270
00277 public function render()
00278 {
00279 $sReturn = parent::render();
00280
00281 $myConfig = $this->getConfig();
00282
00283
00284 $this->_setupNavigation( oxConfig::getParameter( 'cl' ) );
00285
00286
00287 $sOxId = oxConfig::getParameter( 'oxid' );
00288 $this->_aViewData['oxid'] = ( !$sOxId )?-1:$sOxId;
00289
00290 $this->_aViewData['sumtype'] = $this->_aSumType;
00291
00292
00293 $this->_aViewData['actshop'] = $this->_sShopTitle;
00294 $this->_aViewData["shopid"] = $myConfig->getShopId();
00295
00296
00297 if ( oxSession::getVar( 'actshop' ) ) {
00298
00299 $oShop = oxNew( 'oxshop' );
00300 $oShop->load( oxSession::getVar( 'actshop' ) );
00301 $this->_aViewData['actshopobj'] = $oShop;
00302 }
00303
00304
00305 $this->_aViewData['actlang'] = $iLanguage = oxLang::getInstance()->getBaseLanguage();
00306 $this->_aViewData['editlanguage'] = $this->_iEditLang;
00307 $this->_aViewData['languages'] = oxLang::getInstance()->getLanguageArray( $iLanguage );
00308
00309
00310 list( $this->_aViewData['iMaxUploadFileSize'], $this->_aViewData['sMaxFormattedFileSize']) = $this->_getMaxUploadFileInfo( @ini_get("upload_max_filesize") );
00311
00312
00313 if ( !isset( $this->_aViewData['updatelist'] ) ) {
00314 $this->_aViewData['updatelist'] = oxConfig::getParameter( 'updatelist' );
00315 }
00316
00317 return $sReturn;
00318 }
00319
00327 protected function _getMaxUploadFileInfo( $iMaxFileSize, $blFormatted = false )
00328 {
00329 $iMaxFileSize = $iMaxFileSize?$iMaxFileSize:'2M';
00330
00331
00332 $iMaxFileSize = trim( $iMaxFileSize );
00333 $sParam = strtolower( $iMaxFileSize{ strlen( $iMaxFileSize )-1 } );
00334 switch( $sParam ) {
00335 case 'g':
00336 $iMaxFileSize *= 1024;
00337 case 'm':
00338 $iMaxFileSize *= 1024;
00339 case 'k':
00340 $iMaxFileSize *= 1024;
00341 }
00342
00343
00344 $aMarkers = array ( 'KB', 'MB', 'GB' );
00345 $sFormattedMaxSize = '';
00346
00347 $iSize = floor( $iMaxFileSize / 1024 );
00348 while ( $iSize && current( $aMarkers ) ) {
00349 $sFormattedMaxSize = $iSize . current( $aMarkers );
00350 $iSize = floor( $iSize / 1024 );
00351 next( $aMarkers );
00352 }
00353
00354 return array( $iMaxFileSize, $sFormattedMaxSize );
00355 }
00356
00362 public function autosave()
00363 {
00364 $aAutosave = oxConfig::getParameter( 'autosave' );
00365
00366
00367 if ( is_array( $aAutosave ) && isset( $aAutosave['oxid'] ) && isset( $aAutosave['cl'] ) ) {
00368
00369 $sReturn = '';
00370 foreach ( $aAutosave as $sVarName => $sVarValue ) {
00371 if ( $sVarValue ) {
00372 if ( $sVarName == 'cl' ) {
00373 $sReturn = "$sVarValue?$sReturn";
00374 } else {
00375 $sReturn .= "&$sVarName=$sVarValue";
00376 }
00377 }
00378 }
00379 return "$sReturn&updatelist=1";
00380 }
00381 }
00382
00388 public function save()
00389 {
00390
00391
00392 return $this->autosave();
00393 }
00394
00395
00404 protected function _allowAdminEdit( $sUserId )
00405 {
00406
00407
00408 return true;
00409 }
00410
00416 protected function _getCountryByCode( $sCountryCode )
00417 {
00418 $myConfig = $this->getConfig();
00419
00420
00421 $sCountry = 'international';
00422
00423 if ( !empty($sCountryCode) ) {
00424 $sQ = "select oxtitle_1 from oxcountry where oxisoalpha2 = '$sCountryCode' ";
00425 $sCountry = oxDb::getDb()->getOne( $sQ );
00426 }
00427
00428 return strtolower( $sCountry );
00429 }
00430
00436 protected function _authorize()
00437 {
00438 return ( bool ) ( count( oxUtilsServer::getInstance()->getOxCookie() ) && oxUtils::getInstance()->checkAccessRights() );
00439 }
00440
00446 public function getNavigation()
00447 {
00448 if ( self::$_oNaviTree == null ) {
00449 self::$_oNaviTree = oxNew( 'oxnavigationtree' );
00450 self::$_oNaviTree->init();
00451 }
00452 return self::$_oNaviTree;
00453 }
00454
00460 public function getViewId()
00461 {
00462 $sClassName = strtolower( get_class( $this ) );
00463 return $this->getNavigation()->getClassId( $sClassName );
00464 }
00465
00471 public function chshp()
00472 {
00473 $sActShop = oxConfig::getParameter( 'actshop' );
00474 $this->getConfig()->setShopId( $sActShop );
00475 oxSession::setVar( "shp", $sActShop);
00476 oxSession::setVar( 'currentadminshop', $sActShop );
00477 }
00478
00484 public function resetSeoData( $sShopId )
00485 {
00486 $oEncoder = oxSeoEncoder::getInstance();
00487 $oEncoder->markAsExpired( null, $sShopId, 2 );
00488
00489
00490 $oTagCloud = oxNew('oxtagcloud');
00491 $oTagCloud->resetTagCache();
00492 }
00493 }