category_main.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Category_Main extends oxAdminDetails
00010 {
00017     public function render()
00018     {
00019         $myConfig  = $this->getConfig();
00020 
00021         parent::render();
00022 
00023         $this->_aViewData["edit"] = $oCategory = oxNew( "oxcategory" );;
00024 
00025 
00026         $soxId = oxConfig::getParameter( "oxid");
00027         $sChosenArtCat = oxConfig::getParameter( "artcat");
00028         // check if we right now saved a new entry
00029         $sSavedID = oxConfig::getParameter( "saved_oxid");
00030         if ( ($soxId == "-1" || !isset( $soxId)) && isset( $sSavedID) ) {
00031             $soxId = $sSavedID;
00032             oxSession::deleteVar( "saved_oxid");
00033             $this->_aViewData["oxid"] =  $soxId;
00034             // for reloading upper frame
00035             $this->_aViewData["updatelist"] =  "1";
00036         }
00037 
00038         if ( $soxId != "-1" && isset( $soxId)) {
00039 
00040             // generating category tree for select list
00041             $sChosenArtCat = $this->_getCategoryTree( "artcattree", $sChosenArtCat, $soxId );
00042 
00043             // load object
00044             $oCategory->loadInLang( $this->_iEditLang, $soxId );
00045 
00046 
00047             $oOtherLang = $oCategory->getAvailableInLangs();
00048             if (!isset($oOtherLang[$this->_iEditLang])) {
00049                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00050                 $oCategory->loadInLang( key($oOtherLang), $soxId );
00051             }
00052 
00053             // remove already created languages
00054             $aLang = array_diff ( oxLang::getInstance()->getLanguageNames(), $oOtherLang );
00055             if ( count( $aLang))
00056                 $this->_aViewData["posslang"] = $aLang;
00057 
00058             foreach ( $oOtherLang as $id => $language) {
00059                 $oLang = new oxStdClass();
00060                 $oLang->sLangDesc = $language;
00061                 $oLang->selected = ($id == $this->_iEditLang);
00062                 $this->_aViewData["otherlang"][$id] =  clone $oLang;
00063             }
00064 
00065             if ( $oCategory->oxcategories__oxparentid->value == 'oxrootid')
00066                 $oCategory->oxcategories__oxparentid->setValue('');
00067 
00068             $this->_getCategoryTree( "cattree", $oCategory->oxcategories__oxparentid->value, $oCategory->oxcategories__oxid->value, true, $oCategory->oxcategories__oxshopid->value);
00069 
00070             $this->_aViewData["defsort"] = $oCategory->oxcategories__oxdefsort->value;
00071         } else
00072             $this->_getCategoryTree( "cattree", "", "", true, $myConfig->getShopId());
00073 
00074         $this->_aViewData["sortableFields"] = $this->getSortableFields();
00075 
00076         if ( oxConfig::getParameter("aoc") ) {
00077 
00078             $aColumns = array();
00079             include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00080             $this->_aViewData['oxajax'] = $aColumns;
00081 
00082             return "popups/category_main.tpl";
00083         }
00084         return "category_main.tpl";
00085     }
00086     
00092     public function getSortableFields()
00093     {
00094         $aSkipFields = array( "OXID", "OXSHOPID", "OXPARENTID", "OXACTIVE", "OXSHORTDESC"
00095             , "OXUNITNAME", "OXUNITQUANTITY", "OXEXTURL", "OXURLDESC", "OXURLIMG", "OXVAT" 
00096             , "OXTHUMB", "OXPICSGENERATED", "OXPIC1", "OXPIC2", "OXPIC3", "OXPIC4", "OXPIC5"
00097             , "OXPIC6", "OXPIC7", "OXPIC8", "OXPIC9", "OXPIC10", "OXPIC11", "OXPIC12", "OXSTOCKFLAG"
00098             , "OXSTOCKTEXT", "OXNOSTOCKTEXT", "OXDELIVERY", "OXFILE", "OXSEARCHKEYS", "OXTEMPLATE"
00099             , "OXQUESTIONEMAIL", "OXISSEARCH", "OXISCONFIGURABLE", "OXBUNDLEID", "OXFOLDER", "OXSUBCLASS"
00100             , "OXSOLDAMOUNT", "OXREMINDACTIVE", "OXREMINDAMOUNT", "OXVENDORID", "OXMANUFACTURERID", "OXSKIPDISCOUNTS"
00101             , "OXBLFIXEDPRICE", "OXICON", "OXVARSELECT", "OXAMITEMID", "OXAMTASKID", "OXPIXIEXPORT", "OXPIXIEXPORTED"        
00102         );
00103      
00104         $oDbHandler = oxNew( "oxDbMetaDataHandler" );
00105         $aFields = array_merge( $oDbHandler->getMultilangFields( 'oxarticles' ), $oDbHandler->getSinglelangFields( 'oxarticles', 0 ) ); 
00106         $aFields = array_diff( $aFields, $aSkipFields );
00107         
00108         return $aFields;
00109     }
00110 
00116     public function save()
00117     {
00118         $myConfig  = $this->getConfig();
00119 
00120 
00121         $soxId      = oxConfig::getParameter( "oxid");
00122         $aParams    = oxConfig::getParameter( "editval");
00123 
00124         // checkbox handling
00125         if ( !isset( $aParams['oxcategories__oxactive']))
00126             $aParams['oxcategories__oxactive'] = 0;
00127         if ( !isset( $aParams['oxcategories__oxhidden']))
00128             $aParams['oxcategories__oxhidden'] = 0;
00129         if ( !isset( $aParams['oxcategories__oxdefsortmode']))
00130             $aParams['oxcategories__oxdefsortmode'] = 0;
00131 
00132         // null values
00133         if ($aParams['oxcategories__oxvat'] === '')
00134             $aParams['oxcategories__oxvat'] = null;
00135 
00136             // shopid
00137             $aParams['oxcategories__oxshopid'] = oxSession::getVar( "actshop" );
00138         $oCategory = oxNew( "oxcategory" );
00139 
00140         if ( $soxId != "-1") {
00141             $this->resetCounter( "catArticle", $soxId );
00142             $oCategory->load( $soxId);
00143             $oCategory->loadInLang( $this->_iEditLang, $soxId );
00144                 $myUtilsPic = oxUtilsPic::getInstance();
00145                 // #1173M - not all pic are deleted, after article is removed
00146                 $myUtilsPic->overwritePic( $oCategory, 'oxcategories', 'oxthumb', 'TC', '0', $aParams, $myConfig->getAbsDynImageDir() );
00147                 $myUtilsPic->overwritePic( $oCategory, 'oxcategories', 'oxicon', 'CICO', 'icon', $aParams, $myConfig->getAbsDynImageDir() );
00148 
00149         } else {
00150             //#550A - if new category is made then is must be default activ
00151             $aParams['oxcategories__oxactive'] = 1;
00152             $aParams['oxcategories__oxid'] = null;
00153         }
00154         //$aParams = $oCategory->ConvertNameArray2Idx( $aParams);
00155 
00156 
00157         $oCategory->setLanguage(0);
00158         $oCategory->assign( $aParams);
00159 
00160         $oCategory->setLanguage($this->_iEditLang);
00161 
00162         $oCategory = oxUtilsFile::getInstance()->processFiles( $oCategory );
00163         $oCategory->save();
00164         $this->_aViewData["updatelist"] = "1";
00165 
00166         // set oxid if inserted
00167         if ( $soxId == "-1")
00168             oxSession::setVar( "saved_oxid", $oCategory->oxcategories__oxid->value);
00169     }
00170 
00176     public function saveinnlang()
00177     {
00178 
00179         $soxId      = oxConfig::getParameter( "oxid");
00180         $aParams    = oxConfig::getParameter( "editval");
00181         // checkbox handling
00182         if ( !isset( $aParams['oxcategories__oxactive']))
00183             $aParams['oxcategories__oxactive'] = 0;
00184         if ( !isset( $aParams['oxcategories__oxdefsortmode']))
00185             $aParams['oxcategories__oxdefsortmode'] = 0;
00186 
00187         // null values
00188         if ($aParams['oxcategories__oxvat'] === '')
00189             $aParams['oxcategories__oxvat'] = null;
00190 
00191             // shopid
00192             $aParams['oxcategories__oxshopid'] = oxSession::getVar( "actshop" );
00193 
00194         $oCategory = oxNew( "oxcategory" );
00195 
00196         if ( $soxId != "-1") {
00197             $oCategory->loadInLang( $this->_iEditLang, $soxId );
00198         } else {
00199             $aParams['oxcategories__oxid'] = null;
00200         }
00201 
00202 
00203         //$aParams = $oCategory->ConvertNameArray2Idx( $aParams);
00204         $oCategory->setLanguage(0);
00205         $oCategory->assign( $aParams);
00206 
00207         // apply new language
00208         $sNewLanguage = oxConfig::getParameter( "new_lang");
00209         $oCategory->setLanguage( $sNewLanguage);
00210         $oCategory->save();
00211         $this->_aViewData["updatelist"] = "1";
00212 
00213         // set for reload
00214         oxSession::setVar( "new_lang", $sNewLanguage);
00215 
00216         // set oxid if inserted
00217         if ( $soxId == "-1") {
00218             oxSession::setVar( "saved_oxid", $oCategory->oxcategories__oxid->value);
00219         }
00220     }
00221 }