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