content_main.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Content_Main extends oxAdminDetails
00009 {
00016     public function render()
00017     {
00018         $myConfig = $this->getConfig();
00019 
00020         parent::render();
00021 
00022         $soxId = oxConfig::getParameter( "oxid");
00023         // check if we right now saved a new entry
00024         $sSavedID = oxConfig::getParameter( "saved_oxid");
00025         if ( ($soxId == "-1" || !isset( $soxId)) && isset( $sSavedID) ) {
00026             $soxId = $sSavedID;
00027             oxSession::deleteVar( "saved_oxid");
00028             $this->_aViewData["oxid"] =  $soxId;
00029             // for reloading upper frame
00030             $this->_aViewData["updatelist"] =  "1";
00031         }
00032 
00033         // categorie tree
00034         $oCatTree = oxNew( "oxCategoryList" );
00035         $oCatTree->buildList($myConfig->getConfigParam( 'bl_perfLoadCatTree' ));
00036 
00037         $oContent = oxNew( "oxcontent" );
00038         if ( $soxId != "-1" && isset( $soxId)) {
00039             // load object
00040             $oContent->loadInLang( $this->_iEditLang, $soxId );
00041 
00042             $oOtherLang = $oContent->getAvailableInLangs();
00043             if (!isset($oOtherLang[$this->_iEditLang])) {
00044                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00045                 $oContent->loadInLang( key($oOtherLang), $soxId );
00046             }
00047 
00048             // remove already created languages
00049             $aLang = array_diff ( oxLang::getInstance()->getLanguageNames(), $oOtherLang );
00050             if ( count( $aLang))
00051                 $this->_aViewData["posslang"] = $aLang;
00052             foreach ( $oOtherLang as $id => $language) {
00053                 $oLang= new oxStdClass();
00054                 $oLang->sLangDesc = $language;
00055                 $oLang->selected = ($id == $this->_iEditLang);
00056                 $this->_aViewData["otherlang"][$id] =  clone $oLang;
00057             }
00058             // mark selected
00059             if (  $oContent->oxcontents__oxcatid->value && isset( $oCatTree[$oContent->oxcontents__oxcatid->value] ) ) {
00060                 $oCatTree[$oContent->oxcontents__oxcatid->value]->selected = 1;
00061             }
00062 
00063         } else {
00064                 // create ident to make life easier
00065                 $sUId = oxUtilsObject::getInstance()->generateUId();
00066                 $oContent->oxcontents__oxloadid = new oxField( $sUId );
00067         }
00068 
00069         $this->_aViewData["edit"] = $oContent;
00070         $this->_aViewData["link"] = "[{ oxgetseourl ident=&quot;".$oContent->oxcontents__oxloadid->value."&quot; type=&quot;oxcontent&quot; }]";
00071         $this->_aViewData["cattree"] = $oCatTree;
00072 
00073         // generate editor
00074         $sCSS = "content.tpl.css";
00075         if ( $oContent->oxcontents__oxsnippet->value == '1') {
00076             $sCSS = null;
00077         }
00078 
00079         $this->_aViewData["editor"]  = $this->_generateTextEditor( "100%", 300, $oContent, "oxcontents__oxcontent", $sCSS);
00080         $this->_aViewData["afolder"] = $myConfig->getConfigParam( 'aCMSfolder' );
00081 
00082         return "content_main.tpl";
00083     }
00084 
00090     public function save()
00091     {
00092         $myConfig = $this->getConfig();
00093 
00094 
00095         $soxId      = oxConfig::getParameter( "oxid");
00096         $aParams    = oxConfig::getParameter( "editval");
00097 
00098         if ( isset( $aParams['oxcontents__oxloadid'] ) ) {
00099             $aParams['oxcontents__oxloadid'] = $this->_prepareIdent( $aParams['oxcontents__oxloadid'] );
00100         }
00101 
00102         // check if loadid is unique
00103         if ( $this->_checkIdent( $aParams['oxcontents__oxloadid'], $soxId ) ) {
00104             // loadid already used, display error message
00105             $this->_aViewData["blLoadError"] = true;
00106 
00107             $oContent = oxNew( "oxcontent" );
00108             if ( $soxId != '-1') {
00109                 $oContent->load( $soxId );
00110             }
00111             $oContent->assign( $aParams );
00112             $this->_aViewData["edit"] = $oContent;
00113             return;
00114         }
00115 
00116         // checkbox handling
00117         if ( !isset( $aParams['oxcontents__oxactive']))
00118             $aParams['oxcontents__oxactive'] = 0;
00119 
00120         // special treatment
00121         if ( $aParams['oxcontents__oxtype'] == 0)
00122             $aParams['oxcontents__oxsnippet'] = 1;
00123         else
00124             $aParams['oxcontents__oxsnippet'] = 0;
00125 
00126         //Updates object folder parameters
00127         if ( $aParams['oxcontents__oxfolder'] == 'CMSFOLDER_NONE' ) {
00128             $aParams['oxcontents__oxfolder'] = '';
00129         }
00130 
00131             // shopid
00132             $sShopID = oxSession::getVar( "actshop");
00133             $aParams['oxcontents__oxshopid'] = $sShopID;
00134         $oContent = oxNew( "oxcontent" );
00135 
00136         if ( $soxId != "-1")
00137             $oContent->loadInLang( $this->_iEditLang, $soxId );
00138         else
00139             $aParams['oxcontents__oxid'] = null;
00140 
00141         //$aParams = $oContent->ConvertNameArray2Idx( $aParams);
00142 
00143         $oContent->setLanguage(0);
00144         $oContent->assign( $aParams);
00145         $oContent->setLanguage($this->_iEditLang);
00146         $oContent->save();
00147         $this->_aViewData["updatelist"] = "1";
00148 
00149         // set oxid if inserted
00150         if( $soxId == "-1")
00151             oxSession::setVar( "saved_oxid", $oContent->oxcontents__oxid->value);
00152     }
00153 
00159     public function saveinnlang()
00160     {
00161         $myConfig  = $this->getConfig();
00162 
00163 
00164         $soxId      = oxConfig::getParameter( "oxid");
00165         $aParams    = oxConfig::getParameter( "editval");
00166 
00167         if ( isset( $aParams['oxcontents__oxloadid'] ) ) {
00168             $aParams['oxcontents__oxloadid'] = $this->_prepareIdent( $aParams['oxcontents__oxloadid'] );
00169         }
00170 
00171         // checkbox handling
00172         if ( !isset( $aParams['oxcontents__oxactive']))
00173             $aParams['oxcontents__oxactive'] = 0;
00174 
00175             // shopid
00176             $sShopID = oxSession::getVar( "actshop");
00177             $aParams['oxcontents__oxshopid'] = $sShopID;
00178 
00179         $oContent = oxNew( "oxcontent" );
00180 
00181         if ( $soxId != "-1")
00182             $oContent->loadInLang( $this->_iEditLang, $soxId );
00183         else
00184             $aParams['oxcontents__oxid'] = null;
00185 
00186         $oContent->setLanguage(0);
00187         $oContent->assign( $aParams);
00188 
00189         // apply new language
00190         $sNewLanguage = oxConfig::getParameter( "new_lang");
00191         $oContent->setLanguage( $sNewLanguage);
00192         $oContent->save();
00193         $this->_aViewData["updatelist"] = "1";
00194 
00195         // set for reload
00196         oxSession::setVar( "new_lang", $sNewLanguage);
00197 
00198         // set oxid if inserted
00199         if ( $soxId == "-1")
00200             oxSession::setVar( "saved_oxid", $oContent->oxcontents__oxid->value);
00201     }
00202 
00210     protected function _prepareIdent( $sIdent )
00211     {
00212         if ( $sIdent ) {
00213             return getStr()->preg_replace( "/[^a-zA-Z0-9_]*/", "", $sIdent );
00214         }
00215     }
00216 
00224     protected function _checkIdent( $sIdent, $sOxId )
00225     {
00226         $blAllow = false;
00227         // null not allowed
00228         if ( !strlen( $sIdent ) ) {
00229             $blAllow = true;
00230         } elseif ( oxDb::getDb()->GetOne( "select oxid from oxcontents where oxloadid = '{$sIdent}' and oxid != '{$sOxId}' and oxshopid = '".$this->getConfig()->getShopId()."'" ) ) {
00231             $blAllow = true;
00232         }
00233         return $blAllow;
00234     }
00235 }

Generated on Wed Jun 17 12:09:01 2009 for OXID eShop CE by  doxygen 1.5.5