Index: trunk/kernel/units/categories/categories_event_handler.php =================================================================== diff -u -N --- trunk/kernel/units/categories/categories_event_handler.php (revision 0) +++ trunk/kernel/units/categories/categories_event_handler.php (revision 1566) @@ -0,0 +1,91 @@ +Application->getUnitOption($event->Prefix,'TableName'); + $current_cat = $this->Application->GetVar('m_cat_id'); + + if($current_cat) + { + $sql = 'SELECT ParentId FROM '.$category_table.' WHERE CategoryId = '.$current_cat; + $cat_to_go = $this->Conn->GetOne($sql); + } + else + { + $cat_to_go = 0; + } + + $event->redirect_params = Array('m_cat_id' => $cat_to_go); + } + + /** + * Goes to home category + * + * @param kEvent $event + */ + function OnGoHome(&$event) + { + $cat_to_go = 0; + $event->redirect_params = Array('m_cat_id' => $cat_to_go); + } + + /** + * Apply system filter to categories list + * + * @param kEvent $event + */ + function SetCustomQuery(&$event) + { + $object =& $event->getObject(); + + if ( $event->getEventParam('parent_cat_id') ) { + $parent_cat_id = $event->getEventParam('parent_cat_id'); + } + else { + $parent_cat_id = $this->Application->GetVar('c_id'); + if (!$parent_cat_id) { + $parent_cat_id = $this->Application->GetVar('m_cat_id'); + } + if (!$parent_cat_id) { + $parent_cat_id = 0; + } + } + + if ($parent_cat_id != 'any') { + if ($event->getEventParam('recursive')) { + $current_path = $this->Conn->GetOne('SELECT ParentPath FROM '.TABLE_PREFIX.'Category WHERE CategoryId='.$parent_cat_id); + $subcats = $this->Conn->GetCol('SELECT CategoryId FROM '.TABLE_PREFIX.'Category WHERE ParentPath LIKE "'.$current_path.'%" '); + $object->addFilter('parent_filter', 'ParentId IN ('.implode(', ', $subcats).')'); + } + else { + $object->addFilter('parent_filter', 'ParentId = '.$parent_cat_id); + } + } + + $object->addFilter('parent_filter', 'ParentId = '.$parent_cat_id); + + $view_perm = 1; + $object->addFilter('perm_filter', 'PermId = '.$view_perm); + if (!defined('ADMIN')) { + $groups = explode(',',$this->Application->RecallVar('UserGroups')); + foreach ($groups as $group) { + $view_filters[] = 'FIND_IN_SET('.$group.', acl) || ((NOT FIND_IN_SET('.$group.',dacl)) AND acl=\'\')'; + } + $view_filter = implode(' OR ', $view_filters); + $object->addFilter('perm_filter2', $view_filter); + } + + if (!defined('ADMIN')) { + $object->addFilter('status_filter', $object->TableName.'.Status = 1'); + } + } +} + +?> \ No newline at end of file