content_main.php

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

Generated on Thu Dec 4 12:04:55 2008 for OXID eShop CE by  doxygen 1.5.5