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         $sChosenArtCat = oxConfig::getParameter( "artcat");
00025         $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
00026         if ( $soxId != "-1" && isset( $soxId)) {
00027 
00028             // generating category tree for select list
00029             $sChosenArtCat = $this->_getCategoryTree( "artcattree", $sChosenArtCat, $soxId );
00030 
00031             // load object
00032             $oCategory->loadInLang( $this->_iEditLang, $soxId );
00033 
00034 
00035             $oOtherLang = $oCategory->getAvailableInLangs();
00036             if (!isset($oOtherLang[$this->_iEditLang])) {
00037                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00038                 $oCategory->loadInLang( key($oOtherLang), $soxId );
00039             }
00040 
00041             // remove already created languages
00042             $aLang = array_diff ( oxLang::getInstance()->getLanguageNames(), $oOtherLang );
00043             if ( count( $aLang))
00044                 $this->_aViewData["posslang"] = $aLang;
00045 
00046             foreach ( $oOtherLang as $id => $language) {
00047                 $oLang = new oxStdClass();
00048                 $oLang->sLangDesc = $language;
00049                 $oLang->selected = ($id == $this->_iEditLang);
00050                 $this->_aViewData["otherlang"][$id] =  clone $oLang;
00051             }
00052 
00053             if ( $oCategory->oxcategories__oxparentid->value == 'oxrootid')
00054                 $oCategory->oxcategories__oxparentid->setValue('');
00055 
00056             $this->_getCategoryTree( "cattree", $oCategory->oxcategories__oxparentid->value, $oCategory->oxcategories__oxid->value, true, $oCategory->oxcategories__oxshopid->value);
00057 
00058             $this->_aViewData["defsort"] = $oCategory->oxcategories__oxdefsort->value;
00059         } else
00060             $this->_getCategoryTree( "cattree", "", "", true, $myConfig->getShopId());
00061 
00062         $this->_aViewData["sortableFields"] = $this->getSortableFields();
00063 
00064         if ( oxConfig::getParameter("aoc") ) {
00065 
00066             $aColumns = array();
00067             include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00068             $this->_aViewData['oxajax'] = $aColumns;
00069 
00070             return "popups/category_main.tpl";
00071         }
00072         //print_r($this);
00073         return "category_main.tpl";
00074     }
00075 
00081     public function getSortableFields()
00082     {
00083         $aSkipFields = array( "OXID", "OXSHOPID", "OXSHOPINCL", "OXSHOPEXCL", "OXPARENTID", "OXACTIVE", "OXACTIVEFROM"
00084             , "OXACTIVETO", "OXSHORTDESC"
00085             , "OXUNITNAME", "OXUNITQUANTITY", "OXEXTURL", "OXURLDESC", "OXURLIMG", "OXVAT"
00086             , "OXTHUMB", "OXPICSGENERATED", "OXPIC1", "OXPIC2", "OXPIC3", "OXPIC4", "OXPIC5"
00087             , "OXPIC6", "OXPIC7", "OXPIC8", "OXPIC9", "OXPIC10", "OXPIC11", "OXPIC12", "OXSTOCKFLAG"
00088             , "OXSTOCKTEXT", "OXNOSTOCKTEXT", "OXDELIVERY", "OXFILE", "OXSEARCHKEYS", "OXTEMPLATE"
00089             , "OXQUESTIONEMAIL", "OXISSEARCH", "OXISCONFIGURABLE", "OXBUNDLEID", "OXFOLDER", "OXSUBCLASS"
00090             , "OXREMINDACTIVE", "OXREMINDAMOUNT", "OXVENDORID", "OXMANUFACTURERID", "OXSKIPDISCOUNTS"
00091             , "OXBLFIXEDPRICE", "OXICON", "OXVARSELECT", "OXAMITEMID", "OXAMTASKID", "OXPIXIEXPORT", "OXPIXIEXPORTED", "OXSORT"
00092             , "OXUPDATEPRICE", "OXUPDATEPRICEA", "OXUPDATEPRICEB", "OXUPDATEPRICEC", "OXUPDATEPRICETIME", "OXISDOWNLOADABLE"
00093         );
00094         $aSkipFields = array_merge($aSkipFields, oxShopMetaData::getInstance()->getShopFields());
00095 
00096         $oDbHandler = oxNew( "oxDbMetaDataHandler" );
00097         $aFields = array_merge( $oDbHandler->getMultilangFields( 'oxarticles' ), $oDbHandler->getSinglelangFields( 'oxarticles', 0 ) );
00098         $aFields = array_diff( $aFields, $aSkipFields );
00099         $aFields = array_unique( $aFields );
00100 
00101         return $aFields;
00102     }
00103 
00109     public function save()
00110     {
00111         parent::save();
00112 
00113         $myConfig  = $this->getConfig();
00114 
00115         $soxId = $this->getEditObjectId();
00116         $aParams = oxConfig::getParameter( "editval");
00117 
00118         // checkbox handling
00119         if ( !isset( $aParams['oxcategories__oxactive']))
00120             $aParams['oxcategories__oxactive'] = 0;
00121         if ( !isset( $aParams['oxcategories__oxhidden']))
00122             $aParams['oxcategories__oxhidden'] = 0;
00123         if ( !isset( $aParams['oxcategories__oxdefsortmode']))
00124             $aParams['oxcategories__oxdefsortmode'] = 0;
00125 
00126         // null values
00127         if ($aParams['oxcategories__oxvat'] === '')
00128             $aParams['oxcategories__oxvat'] = null;
00129 
00130             // shopid
00131             $aParams['oxcategories__oxshopid'] = oxSession::getVar( "actshop" );
00132 
00133         $oCategory = oxNew( "oxcategory" );
00134 
00135         if ( $soxId != "-1") {
00136             $this->resetCounter( "catArticle", $soxId );
00137             $oCategory->load( $soxId);
00138             $oCategory->loadInLang( $this->_iEditLang, $soxId );
00139 
00140             $myUtilsPic = oxUtilsPic::getInstance();
00141             // #1173M - not all pic are deleted, after article is removed
00142             $myUtilsPic->overwritePic( $oCategory, 'oxcategories', 'oxthumb', 'TC', '0', $aParams, $myConfig->getPictureDir(false) );
00143             $myUtilsPic->overwritePic( $oCategory, 'oxcategories', 'oxicon', 'CICO', 'icon', $aParams, $myConfig->getPictureDir(false) );
00144             $myUtilsPic->overwritePic( $oCategory, 'oxcategories', 'oxpromoicon', 'PICO', 'icon', $aParams, $myConfig->getPictureDir(false) );
00145 
00146         } else {
00147             //#550A - if new category is made then is must be default activ
00148             //#4051: Impossible to create inactive category
00149             //$aParams['oxcategories__oxactive'] = 1;
00150             $aParams['oxcategories__oxid'] = null;
00151         }
00152 
00153 
00154         $oCategory->setLanguage(0);
00155         if ( isset( $aParams["oxcategories__oxlongdesc"] ) ) {
00156             $aParams["oxcategories__oxlongdesc"] = $this->_processLongDesc( $aParams["oxcategories__oxlongdesc"] );
00157         }
00158 
00159 
00160         $oCategory->assign( $aParams );
00161         $oCategory->setLanguage($this->_iEditLang);
00162 
00163         $oCategory = oxUtilsFile::getInstance()->processFiles( $oCategory );
00164         $oCategory->save();
00165             
00166         $this->setEditObjectId( $oCategory->getId() );        
00167     }
00168 
00176     protected function _processLongDesc( $sValue )
00177     {
00178         // workaround for firefox showing &lang= as &9001;= entity, mantis#0001272
00179         return str_replace( '&lang=', '&amp;lang=', $sValue );
00180     }
00181 
00187     public function saveinnlang()
00188     {
00189         $this->save();
00190     }
00191 
00197     public function deletePicture()
00198     {
00199         $myConfig = $this->getConfig();
00200 
00201         if ( $myConfig->isDemoShop() ) {
00202             // disabling uploading pictures if this is demo shop
00203             $oEx = new oxExceptionToDisplay();
00204             $oEx->setMessage( 'CATEGORY_PICTURES_UPLOADISDISABLED' );
00205             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false );
00206 
00207             return;
00208         }
00209 
00210         $sOxId = $this->getEditObjectId();
00211         $sField = oxConfig::getParameter('masterPicField');
00212         if (empty($sField)) {
00213             return;
00214         }
00215 
00216         $oItem = oxNew('oxCategory');
00217         $oItem->load($sOxId);
00218         $this->_deleteCatPicture($oItem, $sField);
00219     }
00220 
00229     protected function _deleteCatPicture(oxCategory $oItem, $sField)
00230     {
00231         $myConfig = $this->getConfig();
00232         $sItemKey = 'oxcategories__'.$sField;
00233 
00234 
00235         switch ($sField) {
00236             case 'oxthumb':
00237                 $sImgType = 'TC';
00238                 break;
00239 
00240             case 'oxicon':
00241                 $sImgType = 'CICO';
00242                 break;
00243 
00244             case 'oxpromoicon':
00245                 $sImgType = 'PICO';
00246                 break;
00247 
00248             default:
00249                 $sImgType = false;
00250         }
00251 
00252         if ($sImgType !== false) {
00253             $myUtilsPic = oxUtilsPic::getInstance();
00254             $sDir = $myConfig->getPictureDir(false);
00255             $myUtilsPic->safePictureDelete($oItem->$sItemKey->value, $sDir . oxUtilsFile::getInstance()->getImageDirByType($sImgType), 'oxcategories', $sField);
00256 
00257             $oItem->$sItemKey = new oxField();
00258             $oItem->save();
00259         }
00260     }
00261 }