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
00029 $sChosenArtCat = $this->_getCategoryTree( "artcattree", $sChosenArtCat, $soxId );
00030
00031
00032 $oCategory->loadInLang( $this->_iEditLang, $soxId );
00033
00034
00035 $oOtherLang = $oCategory->getAvailableInLangs();
00036 if (!isset($oOtherLang[$this->_iEditLang])) {
00037
00038 $oCategory->loadInLang( key($oOtherLang), $soxId );
00039 }
00040
00041
00042 $aLang = array_diff ( oxRegistry::getLang()->getLanguageNames(), $oOtherLang );
00043 if ( count( $aLang))
00044 $this->_aViewData["posslang"] = $aLang;
00045
00046 foreach ( $oOtherLang as $id => $language) {
00047 $oLang = new stdClass();
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 $oCategoryMainAjax = oxNew( 'category_main_ajax' );
00066 $this->_aViewData['oxajax'] = $oCategoryMainAjax->getColumns();
00067
00068 return "popups/category_main.tpl";
00069 }
00070
00071 return "category_main.tpl";
00072 }
00073
00079 public function getSortableFields()
00080 {
00081 $aSkipFields = array( "OXID", "OXSHOPID", "OXSHOPINCL", "OXSHOPEXCL", "OXPARENTID", "OXACTIVE", "OXACTIVEFROM"
00082 , "OXACTIVETO", "OXSHORTDESC"
00083 , "OXUNITNAME", "OXUNITQUANTITY", "OXEXTURL", "OXURLDESC", "OXURLIMG", "OXVAT"
00084 , "OXTHUMB", "OXPICSGENERATED", "OXPIC1", "OXPIC2", "OXPIC3", "OXPIC4", "OXPIC5"
00085 , "OXPIC6", "OXPIC7", "OXPIC8", "OXPIC9", "OXPIC10", "OXPIC11", "OXPIC12", "OXSTOCKFLAG"
00086 , "OXSTOCKTEXT", "OXNOSTOCKTEXT", "OXDELIVERY", "OXFILE", "OXSEARCHKEYS", "OXTEMPLATE"
00087 , "OXQUESTIONEMAIL", "OXISSEARCH", "OXISCONFIGURABLE", "OXBUNDLEID", "OXFOLDER", "OXSUBCLASS"
00088 , "OXREMINDACTIVE", "OXREMINDAMOUNT", "OXVENDORID", "OXMANUFACTURERID", "OXSKIPDISCOUNTS"
00089 , "OXBLFIXEDPRICE", "OXICON", "OXVARSELECT", "OXAMITEMID", "OXAMTASKID", "OXPIXIEXPORT", "OXPIXIEXPORTED", "OXSORT"
00090 , "OXUPDATEPRICE", "OXUPDATEPRICEA", "OXUPDATEPRICEB", "OXUPDATEPRICEC", "OXUPDATEPRICETIME", "OXISDOWNLOADABLE"
00091 , "OXVARMAXPRICE"
00092 );
00093 $aSkipFields = array_merge($aSkipFields, oxRegistry::get("oxShopMetaData")->getShopFields());
00094
00095 $oDbHandler = oxNew( "oxDbMetaDataHandler" );
00096 $aFields = array_merge( $oDbHandler->getMultilangFields( 'oxarticles' ), $oDbHandler->getSinglelangFields( 'oxarticles', 0 ) );
00097 $aFields = array_diff( $aFields, $aSkipFields );
00098 $aFields = array_unique( $aFields );
00099
00100 return $aFields;
00101 }
00102
00108 public function save()
00109 {
00110 parent::save();
00111
00112 $myConfig = $this->getConfig();
00113
00114 $soxId = $this->getEditObjectId();
00115 $aParams = oxConfig::getParameter( "editval");
00116
00117
00118 if ( !isset( $aParams['oxcategories__oxactive']))
00119 $aParams['oxcategories__oxactive'] = 0;
00120 if ( !isset( $aParams['oxcategories__oxhidden']))
00121 $aParams['oxcategories__oxhidden'] = 0;
00122 if ( !isset( $aParams['oxcategories__oxdefsortmode']))
00123 $aParams['oxcategories__oxdefsortmode'] = 0;
00124
00125
00126 if ($aParams['oxcategories__oxvat'] === '')
00127 $aParams['oxcategories__oxvat'] = null;
00128
00129
00130 $aParams['oxcategories__oxshopid'] = oxSession::getVar( "actshop" );
00131
00132 $oCategory = oxNew( "oxcategory" );
00133
00134 if ( $soxId != "-1") {
00135 $this->resetCounter( "catArticle", $soxId );
00136 $oCategory->load( $soxId);
00137 $oCategory->loadInLang( $this->_iEditLang, $soxId );
00138
00139 $myUtilsPic = oxRegistry::get("oxUtilsPic");
00140
00141 $myUtilsPic->overwritePic( $oCategory, 'oxcategories', 'oxthumb', 'TC', '0', $aParams, $myConfig->getPictureDir(false) );
00142 $myUtilsPic->overwritePic( $oCategory, 'oxcategories', 'oxicon', 'CICO', 'icon', $aParams, $myConfig->getPictureDir(false) );
00143 $myUtilsPic->overwritePic( $oCategory, 'oxcategories', 'oxpromoicon', 'PICO', 'icon', $aParams, $myConfig->getPictureDir(false) );
00144
00145 } else {
00146
00147
00148
00149 $aParams['oxcategories__oxid'] = null;
00150 }
00151
00152
00153 $oCategory->setLanguage(0);
00154 if ( isset( $aParams["oxcategories__oxlongdesc"] ) ) {
00155 $aParams["oxcategories__oxlongdesc"] = $this->_processLongDesc( $aParams["oxcategories__oxlongdesc"] );
00156 }
00157
00158
00159 if ( empty($aParams['oxcategories__oxpricefrom']) ) {
00160 $aParams['oxcategories__oxpricefrom'] = 0;
00161 }
00162 if ( empty($aParams['oxcategories__oxpriceto']) ) {
00163 $aParams['oxcategories__oxpriceto'] = 0;
00164 }
00165
00166 $oCategory->assign( $aParams );
00167 $oCategory->setLanguage($this->_iEditLang);
00168
00169 $oCategory = oxRegistry::get("oxUtilsFile")->processFiles( $oCategory );
00170 $oCategory->save();
00171
00172 $this->setEditObjectId( $oCategory->getId() );
00173 }
00174
00182 protected function _processLongDesc( $sValue )
00183 {
00184
00185 return str_replace( '&lang=', '&lang=', $sValue );
00186 }
00187
00193 public function saveinnlang()
00194 {
00195 $this->save();
00196 }
00197
00203 public function deletePicture()
00204 {
00205 $myConfig = $this->getConfig();
00206
00207 if ( $myConfig->isDemoShop() ) {
00208
00209 $oEx = new oxExceptionToDisplay();
00210 $oEx->setMessage( 'CATEGORY_PICTURES_UPLOADISDISABLED' );
00211 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false );
00212
00213 return;
00214 }
00215
00216 $sOxId = $this->getEditObjectId();
00217 $sField = oxConfig::getParameter('masterPicField');
00218 if (empty($sField)) {
00219 return;
00220 }
00221
00222 $oItem = oxNew('oxCategory');
00223 $oItem->load($sOxId);
00224 $this->_deleteCatPicture($oItem, $sField);
00225 }
00226
00235 protected function _deleteCatPicture(oxCategory $oItem, $sField)
00236 {
00237 $myConfig = $this->getConfig();
00238 $sItemKey = 'oxcategories__'.$sField;
00239
00240
00241 switch ($sField) {
00242 case 'oxthumb':
00243 $sImgType = 'TC';
00244 break;
00245
00246 case 'oxicon':
00247 $sImgType = 'CICO';
00248 break;
00249
00250 case 'oxpromoicon':
00251 $sImgType = 'PICO';
00252 break;
00253
00254 default:
00255 $sImgType = false;
00256 }
00257
00258 if ($sImgType !== false) {
00259 $myUtilsPic = oxRegistry::get("oxUtilsPic");
00260 $sDir = $myConfig->getPictureDir(false);
00261 $myUtilsPic->safePictureDelete($oItem->$sItemKey->value, $sDir . oxRegistry::get("oxUtilsFile")->getImageDirByType($sImgType), 'oxcategories', $sField);
00262
00263 $oItem->$sItemKey = new oxField();
00264 $oItem->save();
00265 }
00266 }
00267 }