Index: branches/RC/core/units/categories/categories_event_handler.php =================================================================== diff -u -r8929 -r9040 --- branches/RC/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 8929) +++ branches/RC/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 9040) @@ -464,7 +464,51 @@ parent::OnPreSaveCreated($event); } + + + /** + * Exclude root categories from deleting + * + * @param kEvent $event + */ + function customProcessing(&$event, $type) + { + if (!$this->Application->ConfigValue('m_AllowDeleteRootCats')) { + + if ($event->Name == 'OnMassDelete' && $type == 'before') { + $ids = $event->getEventParam('ids'); + + if ($ids) { + + // get module roots and exclude them + foreach ($this->Application->ModuleInfo as $module_name => $module_data) { + if ((int)$module_data['RootCat']) + $ids_exclude[] = (int)$module_data['RootCat']; + } + + if ($ids_exclude && array_intersect($ids, $ids_exclude)) + { + $ids = array_diff($ids, $ids_exclude); + $this->Application->StoreVar('root_delete_error', 1); + } + + /* + $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); + $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); + + $sql = 'SELECT '.$id_field.' + FROM '.$table_name.' + WHERE '.$id_field.' IN ('.implode(',', $ids).').'; + $event->setEventParam('ids', $this->Conn->GetCol($sql)); + */ + + $event->setEventParam('ids', $ids); + } + } + } + } + /** * Deletes all selected items. * Automatically recurse into sub-items using temp handler, and deletes sub-items @@ -477,10 +521,16 @@ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { return; } + // $event->status = erSUCCESS; $ids = $this->StoreSelectedIDs($event); + + $event->setEventParam('ids', $ids); + $this->customProcessing($event, 'before'); + $ids = $event->getEventParam('ids'); + if ($ids) { $recursive_helper =& $this->Application->recallObject('RecursiveHelper'); /* @var $recursive_helper kRecursiveHelper */