00001 <?php
00002
00009 class Category_Main extends oxAdminDetails
00010 {
00011
00018 public function render()
00019 {
00020 $myConfig = $this->getConfig();
00021
00022 parent::render();
00023
00025 $oCategory = oxNew("oxcategory");
00026
00027 $soxId = $this->getEditObjectId();
00028
00029 $this->_aViewData["edit"] = $oCategory;
00030 $this->_aViewData["oxid"] = $soxId;
00031
00032 if ($soxId != "-1" && isset($soxId)) {
00033
00034
00035 $this->_createCategoryTree("artcattree", $soxId);
00036
00037
00038 $oCategory->loadInLang($this->_iEditLang, $soxId);
00039
00040
00041 $oOtherLang = $oCategory->getAvailableInLangs();
00042 if (!isset($oOtherLang[$this->_iEditLang])) {
00043
00044 $oCategory->loadInLang(key($oOtherLang), $soxId);
00045 }
00046
00047
00048 $aLang = array_diff(oxRegistry::getLang()->getLanguageNames(), $oOtherLang);
00049 if (count($aLang)) {
00050 $this->_aViewData["posslang"] = $aLang;
00051 }
00052
00053 foreach ($oOtherLang as $id => $language) {
00054 $oLang = new stdClass();
00055 $oLang->sLangDesc = $language;
00056 $oLang->selected = ($id == $this->_iEditLang);
00057 $this->_aViewData["otherlang"][$id] = clone $oLang;
00058 }
00059
00060 if ($oCategory->oxcategories__oxparentid->value == 'oxrootid') {
00061 $oCategory->oxcategories__oxparentid->setValue('');
00062 }
00063
00064 $this->_getCategoryTree("cattree", $oCategory->oxcategories__oxparentid->value, $oCategory->oxcategories__oxid->value, true, $oCategory->oxcategories__oxshopid->value);
00065
00066 $this->_aViewData["defsort"] = $oCategory->oxcategories__oxdefsort->value;
00067 } else {
00068 $this->_createCategoryTree("cattree", "", true, $myConfig->getShopId());
00069 }
00070
00071 $this->_aViewData["sortableFields"] = $this->getSortableFields();
00072
00073 if (oxRegistry::getConfig()->getRequestParameter("aoc")) {
00075 $oCategoryMainAjax = oxNew('category_main_ajax');
00076 $this->_aViewData['oxajax'] = $oCategoryMainAjax->getColumns();
00077
00078 return "popups/category_main.tpl";
00079 }
00080
00081 return "category_main.tpl";
00082 }
00083
00089 public function getSortableFields()
00090 {
00091 $aSkipFields = array("OXID", "OXSHOPID", "OXMAPID", "OXPARENTID", "OXACTIVE", "OXACTIVEFROM"
00092 , "OXACTIVETO", "OXSHORTDESC"
00093 , "OXUNITNAME", "OXUNITQUANTITY", "OXEXTURL", "OXURLDESC", "OXURLIMG", "OXVAT"
00094 , "OXTHUMB", "OXPIC1", "OXPIC2", "OXPIC3", "OXPIC4", "OXPIC5"
00095 , "OXPIC6", "OXPIC7", "OXPIC8", "OXPIC9", "OXPIC10", "OXPIC11", "OXPIC12", "OXSTOCKFLAG"
00096 , "OXSTOCKTEXT", "OXNOSTOCKTEXT", "OXDELIVERY", "OXFILE", "OXSEARCHKEYS", "OXTEMPLATE"
00097 , "OXQUESTIONEMAIL", "OXISSEARCH", "OXISCONFIGURABLE", "OXBUNDLEID", "OXFOLDER", "OXSUBCLASS"
00098 , "OXREMINDACTIVE", "OXREMINDAMOUNT", "OXVENDORID", "OXMANUFACTURERID", "OXSKIPDISCOUNTS"
00099 , "OXBLFIXEDPRICE", "OXICON", "OXVARSELECT", "OXAMITEMID", "OXAMTASKID", "OXPIXIEXPORT", "OXPIXIEXPORTED", "OXSORT"
00100 , "OXUPDATEPRICE", "OXUPDATEPRICEA", "OXUPDATEPRICEB", "OXUPDATEPRICEC", "OXUPDATEPRICETIME", "OXISDOWNLOADABLE"
00101 , "OXVARMAXPRICE", "OXSHOWCUSTOMAGREEMENT"
00102 );
00104 $oDbHandler = oxNew("oxDbMetaDataHandler");
00105 $aFields = array_merge($oDbHandler->getMultilangFields('oxarticles'), array_keys($oDbHandler->getSinglelangFields('oxarticles', 0)));
00106 $aFields = array_diff($aFields, $aSkipFields);
00107 $aFields = array_unique($aFields);
00108
00109 return $aFields;
00110 }
00111
00117 public function save()
00118 {
00119 parent::save();
00120
00121 $myConfig = $this->getConfig();
00122
00123 $soxId = $this->getEditObjectId();
00124
00125 $aParams = $this->_parseRequestParametersForSave(
00126 $myConfig->getRequestParameter("editval")
00127 );
00128
00130 $oCategory = oxNew("oxcategory");
00131
00132 if ($soxId != "-1") {
00133 $this->resetCounter("catArticle", $soxId);
00134 $oCategory->load($soxId);
00135 $oCategory->loadInLang($this->_iEditLang, $soxId);
00136
00138 $myUtilsPic = oxRegistry::get("oxUtilsPic");
00139
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
00146
00147 $oCategory->setLanguage(0);
00148
00149
00150 $oCategory->assign($aParams);
00151 $oCategory->setLanguage($this->_iEditLang);
00152
00154 $oUtilsFile = oxRegistry::get("oxUtilsFile");
00155
00156 $oCategory = $oUtilsFile->processFiles($oCategory);
00157 $oCategory->save();
00158
00159 $this->setEditObjectId($oCategory->getId());
00160 }
00161
00169 protected function _processLongDesc($sValue)
00170 {
00171
00172 return str_replace('&lang=', '&lang=', $sValue);
00173 }
00174
00178 public function saveinnlang()
00179 {
00180 $this->save();
00181 }
00182
00188 public function deletePicture()
00189 {
00190 $myConfig = $this->getConfig();
00191
00192 if ($myConfig->isDemoShop()) {
00193
00194 $oEx = new oxExceptionToDisplay();
00195 $oEx->setMessage('CATEGORY_PICTURES_UPLOADISDISABLED');
00196
00198 $oUtilsView = oxRegistry::get("oxUtilsView");
00199
00200 $oUtilsView->addErrorToDisplay($oEx, false);
00201
00202 return;
00203 }
00204
00205 $sOxId = $this->getEditObjectId();
00206 $sField = oxRegistry::getConfig()->getRequestParameter('masterPicField');
00207 if (empty($sField)) {
00208 return;
00209 }
00210
00212 $oItem = oxNew('oxCategory');
00213 $oItem->load($sOxId);
00214 $this->_deleteCatPicture($oItem, $sField);
00215 }
00216
00225 protected function _deleteCatPicture(oxCategory $oItem, $sField)
00226 {
00227 $myConfig = $this->getConfig();
00228 $sItemKey = 'oxcategories__' . $sField;
00229
00230
00231 switch ($sField) {
00232 case 'oxthumb':
00233 $sImgType = 'TC';
00234 break;
00235
00236 case 'oxicon':
00237 $sImgType = 'CICO';
00238 break;
00239
00240 case 'oxpromoicon':
00241 $sImgType = 'PICO';
00242 break;
00243
00244 default:
00245 $sImgType = false;
00246 }
00247
00248 if ($sImgType !== false) {
00250 $myUtilsPic = oxRegistry::get("oxUtilsPic");
00252 $oUtilsFile = oxRegistry::get("oxUtilsFile");
00253
00254 $sDir = $myConfig->getPictureDir(false);
00255 $myUtilsPic->safePictureDelete($oItem->$sItemKey->value, $sDir . $oUtilsFile->getImageDirByType($sImgType), 'oxcategories', $sField);
00256
00257 $oItem->$sItemKey = new oxField();
00258 $oItem->save();
00259 }
00260 }
00261
00269 protected function _parseRequestParametersForSave($aReqParams)
00270 {
00271
00272 if (!isset($aReqParams['oxcategories__oxactive'])) {
00273 $aReqParams['oxcategories__oxactive'] = 0;
00274 }
00275 if (!isset($aReqParams['oxcategories__oxhidden'])) {
00276 $aReqParams['oxcategories__oxhidden'] = 0;
00277 }
00278 if (!isset($aReqParams['oxcategories__oxdefsortmode'])) {
00279 $aReqParams['oxcategories__oxdefsortmode'] = 0;
00280 }
00281
00282
00283 if ($aReqParams['oxcategories__oxvat'] === '') {
00284 $aReqParams['oxcategories__oxvat'] = null;
00285 }
00286
00287
00288 $aReqParams['oxcategories__oxshopid'] = oxRegistry::getSession()->getVariable("actshop");
00289
00290 if ($this->getEditObjectId() == "-1") {
00291
00292
00293
00294 $aReqParams['oxcategories__oxid'] = null;
00295 }
00296
00297 if (isset($aReqParams["oxcategories__oxlongdesc"])) {
00298 $aReqParams["oxcategories__oxlongdesc"] = $this->_processLongDesc($aReqParams["oxcategories__oxlongdesc"]);
00299 }
00300
00301 if (empty($aReqParams['oxcategories__oxpricefrom'])) {
00302 $aReqParams['oxcategories__oxpricefrom'] = 0;
00303 }
00304 if (empty($aReqParams['oxcategories__oxpriceto'])) {
00305 $aReqParams['oxcategories__oxpriceto'] = 0;
00306 }
00307
00308 return $aReqParams;
00309 }
00310 }