Index: branches/unlabeled/unlabeled-1.27.2/core/units/categories/categories_event_handler.php =================================================================== diff -u -r7755 -r7926 --- branches/unlabeled/unlabeled-1.27.2/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 7755) +++ branches/unlabeled/unlabeled-1.27.2/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 7926) @@ -81,6 +81,19 @@ } /** + * Set's mark, that root category is edited + * + * @param kEvent $event + */ + function OnEdit(&$event) + { + $category_id = $this->Application->GetVar($event->getPrefixSpecial().'_id'); + $this->Application->StoreVar('IsRootCategory_'.$this->Application->GetVar('m_wid'), $category_id === '0'); + + parent::OnEdit($event); + } + + /** * Apply system filter to categories list * * @param kEvent $event @@ -383,6 +396,18 @@ } /** + * Reset root-category flag when new category is created + * + * @param kEvent $event + */ + function OnPreCreate(&$event) + { + $this->Application->RemoveVar('IsRootCategory_'.$this->Application->GetVar('m_wid')); + + parent::OnPreCreate($event); + } + + /** * Checks cache update mark and redirect to cache if needed * * @param kEvent $event @@ -392,14 +417,16 @@ $object =& $event->getObject(); if ($object->IsRoot()) { $event->setEventParam('master_ids', Array(0)); + $this->RemoveRequiredFields($object); } parent::OnSave($event); if ($event->status == erSUCCESS && $this->Application->RecallVar('PermCache_UpdateRequired')) { // "catalog" should be in opener stack by now $wid = $this->Application->GetVar('m_wid'); $stack_name = rtrim('opener_stack_'.$wid, '_'); - + $this->Application->RemoveVar('IsRootCategory_'.$wid); + $opener_stack = unserialize($this->Application->RecallVar($stack_name)); $opener_stack[0] = str_replace('catalog', 'categories/cache_updater', $opener_stack[0]); $this->Application->StoreVar($stack_name, serialize($opener_stack)); @@ -408,6 +435,25 @@ } /** + * Creates a new item in temp table and + * stores item id in App vars and Session on succsess + * + * @param kEvent $event + */ + function OnPreSaveCreated(&$event) + { + $object =& $event->getObject( Array('skip_autoload' => true) ); + /* @var $object CategoriesItem */ + + if ($object->IsRoot()) { + // don't create root category while saving permissions + return ; + } + + parent::OnPreSaveCreated($event); + } + + /** * Deletes all selected items. * Automatically recurse into sub-items using temp handler, and deletes sub-items * by calling its Delete method if sub-item has AutoDelete set to true in its config file