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