Index: branches/5.2.x/core/kernel/db/cat_tag_processor.php =================================================================== diff -u -N -r15360 -r15761 --- branches/5.2.x/core/kernel/db/cat_tag_processor.php (.../cat_tag_processor.php) (revision 15360) +++ branches/5.2.x/core/kernel/db/cat_tag_processor.php (.../cat_tag_processor.php) (revision 15761) @@ -1,6 +1,6 @@ ItemCount($this->Prefix, $today_only); } - function CategorySelector($params) + /** + * Displays list of allowed categories on "Suggest Link" and similar forms. + * + * @param array $params Tag params. + * + * @return string + * @access protected + */ + protected function CategorySelector($params) { $category_id = isset($params['category_id']) && is_numeric($params['category_id']) ? $params['category_id'] : false; - if ($category_id === false) { + + if ( $category_id === false ) { // if category id not given use module root category $category_id = $this->Application->findModule('Var', $this->Prefix, 'RootCat'); } $id_field = $this->Application->getUnitOption('c', 'IDField'); - $title_field = $this->Application->getUnitOption('c', 'TitleField'); - $table_name = $this->Application->getUnitOption('c', 'TableName'); - $count_helper = $this->Application->recallObject('CountHelper'); - /* @var $count_helper kCountHelper */ - - list ($view_perm, $view_filter) = $count_helper->GetPermissionClause('c', 'perm_cache'); - // get category list (permission based) - $sql = 'SELECT c.'.$title_field.' AS CategoryName, c.'.$id_field.', c.l' . $this->Application->GetVar('m_lang') . '_CachedNavbar AS CachedNavbar - FROM '.$table_name.' c - INNER JOIN '.TABLE_PREFIX.'CategoryPermissionsCache perm_cache ON c.CategoryId = perm_cache.CategoryId - WHERE (ParentId = '.$category_id.') AND ('.$view_filter.') AND (perm_cache.PermId = '.$view_perm.') AND (c.Status = '.STATUS_ACTIVE.') - ORDER BY c.'.$title_field.' ASC'; - $categories = $this->Conn->Query($sql, $id_field); + $categories = $this->Conn->Query($this->getCategorySelectorQuery($category_id), $id_field); $block_params = $this->prepareTagParams($params); $block_params['name'] = $params['render_as']; $block_params['strip_nl'] = 2; $ret = ''; + foreach ($categories as $category_id => $category_data) { // print category $block_params['separator'] = isset($params['category_id']) ? $params['separator'] : ''; // return original separator, remove separator for top level categories @@ -727,13 +725,44 @@ $ret .= $this->Application->ParseBlock($block_params); // print it's children - $block_params['separator'] = '   '.$params['separator']; + $block_params['separator'] = '   ' . $params['separator']; $ret .= $this->CategorySelector($block_params); } return $ret; } + /** + * Returns given category sub-categories, that user have rights to view. + * + * @param int $category_id Category. + * + * @return array + * @access protected + */ + protected function getCategorySelectorQuery($category_id) + { + $id_field = $this->Application->getUnitOption('c', 'IDField'); + $title_field = $this->Application->getUnitOption('c', 'TitleField'); + + $where_clause = Array ( + 'c.ParentId = ' . $category_id, + 'c.Status = ' . STATUS_ACTIVE, + ); + + $sql = 'SELECT c.' . $title_field . ' AS CategoryName, + c.' . $id_field . ', + c.l' . $this->Application->GetVar('m_lang') . '_CachedNavbar AS CachedNavbar + FROM ' . $this->Application->getUnitOption('c', 'TableName') . ' c'; + + $count_helper = $this->Application->recallObject('CountHelper'); + /* @var $count_helper kCountHelper */ + + list ($sql, $where_clause) = $count_helper->attachViewPermissionCheck('c', $sql, $where_clause); + + return $sql . ' WHERE (' . implode(') AND (', $where_clause) . ') ORDER BY c.' . $title_field . ' ASC'; + } + function PrintMoreCategories($params) { $object = $this->getObject($params); Index: branches/5.2.x/core/units/categories/categories_event_handler.php =================================================================== diff -u -N -r15734 -r15761 --- branches/5.2.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 15734) +++ branches/5.2.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 15761) @@ -1,6 +1,6 @@ addFilter('perm_filter', TABLE_PREFIX . 'CategoryPermissionsCache.PermId = 1'); // check for CATEGORY.VIEW permission - if ($this->Application->RecallVar('user_id') != USER_ROOT) { - // apply permission filters to all users except "root" - $view_filters = Array (); - $groups = explode(',',$this->Application->RecallVar('UserGroups')); + $this->applyViewPermissionFilter($object); - foreach ($groups as $group) { - $view_filters[] = 'FIND_IN_SET('.$group.', ' . TABLE_PREFIX . 'CategoryPermissionsCache.ACL)'; - } - - $view_filter = implode(' OR ', $view_filters); - $object->addFilter('perm_filter2', $view_filter); - } - if (!$this->Application->isAdminUser) { // apply status filter only on front $object->addFilter('status_filter', $object->TableName.'.Status = 1'); @@ -555,6 +543,35 @@ } /** + * Adds filter, that uses *.VIEW permissions to determine if an item should be shown to a user. + * + * @param kDBList $object Object. + * + * @return void + * @access protected + */ + protected function applyViewPermissionFilter(kDBList $object) + { + if ( !$this->Application->ConfigValue('CheckViewPermissionsInCatalog') ) { + return; + } + + if ( $this->Application->RecallVar('user_id') == USER_ROOT ) { + // for "root" CATEGORY.VIEW permission is checked for items lists too + $view_perm = 1; + } + else { + $count_helper = $this->Application->recallObject('CountHelper'); + /* @var $count_helper kCountHelper */ + + list ($view_perm, $view_filter) = $count_helper->GetPermissionClause($object->Prefix, 'perm'); + $object->addFilter('perm_filter2', $view_filter); + } + + $object->addFilter('perm_filter', 'perm.PermId = ' . $view_perm); // check for CATEGORY.VIEW permission + } + + /** * Returns current theme id * * @return int @@ -2163,6 +2180,8 @@ if (defined('IS_INSTALL') && IS_INSTALL) { // skip any processing, because Categories table doesn't exists until install is finished + $this->addViewPermissionJoin($event); + return ; } @@ -2224,6 +2243,8 @@ $this->Application->setUnitOption($event->Prefix, 'ListSortings', $list_sortings); } + $this->addViewPermissionJoin($event); + // add grids for advanced view (with primary category column) $grids = $this->Application->getUnitOption($this->Prefix, 'Grids'); $process_grids = Array ('Default', 'Radio'); @@ -2236,6 +2257,35 @@ } /** + * Adds permission table table JOIN clause only, when advanced catalog view permissions enabled. + * + * @param kEvent $event Event. + * + * @return self + * @access protected + */ + protected function addViewPermissionJoin(kEvent $event) + { + if ( $this->Application->ConfigValue('CheckViewPermissionsInCatalog') ) { + $join_clause = 'LEFT JOIN ' . TABLE_PREFIX . 'CategoryPermissionsCache perm ON perm.CategoryId = %1$s.CategoryId'; + } + else { + $join_clause = ''; + } + + $list_sqls = $this->Application->getUnitOption($event->Prefix, 'ListSQLs'); + /* @var $list_sqls array */ + + foreach ($list_sqls as $special => $list_sql) { + $list_sqls[$special] = str_replace('{PERM_JOIN}', $join_clause, $list_sql); + } + + $this->Application->setUnitOption($event->Prefix, 'ListSQLs', $list_sqls); + + return $this; + } + + /** * Returns folders, that can contain design templates * * @return array Index: branches/5.2.x/core/units/helpers/count_helper.php =================================================================== diff -u -N -r15012 -r15761 --- branches/5.2.x/core/units/helpers/count_helper.php (.../count_helper.php) (revision 15012) +++ branches/5.2.x/core/units/helpers/count_helper.php (.../count_helper.php) (revision 15761) @@ -1,6 +1,6 @@ Application->getUnitOption($prefix, 'TableName'); + $table_name = $this->Application->getUnitOption($prefix, 'TableName'); - if (!isset($count_sql)) { - $count_sql = 'COUNT(*)'; - } + if ( !isset($count_sql) ) { + $count_sql = 'COUNT(*)'; + } - $sql = 'SELECT '.$count_sql.' - FROM '.$table_name.' item_table - INNER JOIN '.TABLE_PREFIX.'CategoryItems ci ON ci.ItemResourceId = item_table.ResourceId - INNER JOIN '.TABLE_PREFIX.'Categories c ON c.CategoryId = ci.CategoryId - INNER JOIN '.TABLE_PREFIX.'CategoryPermissionsCache perm_cache ON ci.CategoryId = perm_cache.CategoryId'; - - list ($view_perm, $view_filter) = $this->GetPermissionClause($prefix, 'perm_cache'); - $where_clauses = Array ( - $view_filter, 'perm_cache.PermId = '.$view_perm, 'ci.PrimaryCat = 1', 'c.Status = '.STATUS_ACTIVE, + $where_clause = array( + 'ci.PrimaryCat = 1', + 'c.Status = ' . STATUS_ACTIVE, ); - if ($today) { - $today_date = adodb_mktime(0, 0, 0, adodb_date('m'), adodb_date('d'), adodb_date('Y')); - $where_clauses[] = 'item_table.CreatedOn >= '.$today_date; - } + $sql = 'SELECT ' . $count_sql . ' + FROM ' . $table_name . ' item_table + INNER JOIN ' . TABLE_PREFIX . 'CategoryItems ci ON ci.ItemResourceId = item_table.ResourceId + INNER JOIN ' . TABLE_PREFIX . 'Categories c ON c.CategoryId = ci.CategoryId'; - $sql .= ' WHERE ('.implode(') AND (', $where_clauses).')'; + list ($sql, $where_clause) = $this->attachViewPermissionCheck($prefix, $sql, $where_clause, 'ci.CategoryId'); + if ( $today ) { + $today_date = adodb_mktime(0, 0, 0, adodb_date('m'), adodb_date('d'), adodb_date('Y')); + $where_clause[] = 'item_table.CreatedOn >= ' . $today_date; + } + + $sql .= ' WHERE (' . implode(') AND (', $where_clause) . ')'; + return (int)$this->Conn->GetOne($sql); } @@ -214,45 +217,69 @@ */ function CategoryCount($today = false) { - $cache_key = 'category_count[%CSerial%]'; + $cache_key = 'category_count[%CSerial%]'; - if ($today) { - $today_date = adodb_mktime(0, 0, 0, adodb_date('m'), adodb_date('d'), adodb_date('Y')); - $cache_key .= ':date=' . $today_date; - } + if ( $today ) { + $today_date = adodb_mktime(0, 0, 0, adodb_date('m'), adodb_date('d'), adodb_date('Y')); + $cache_key .= ':date=' . $today_date; + } - $count = $this->Application->getCache($cache_key); + $count = $this->Application->getCache($cache_key); - if ($count === false) { + if ( $count === false ) { + $where_clause = Array( + 'c.Status = ' . STATUS_ACTIVE, + ); + $sql = 'SELECT COUNT(*) - FROM ' . $this->Application->getUnitOption('c', 'TableName') . ' c - INNER JOIN ' . TABLE_PREFIX . 'CategoryPermissionsCache perm_cache ON c.CategoryId = perm_cache.CategoryId'; + FROM ' . $this->Application->getUnitOption('c', 'TableName') . ' c'; - list ($view_perm, $view_filter) = $this->GetPermissionClause('c', 'perm_cache'); + list ($sql, $where_clause) = $this->attachViewPermissionCheck('c', $sql, $where_clause); - $where_clauses = Array ( - $view_filter, - 'perm_cache.PermId = ' . $view_perm, - 'c.Status = ' . STATUS_ACTIVE, - ); + if ( $today ) { + $where_clause[] = 'c.CreatedOn >= ' . $today_date; + } - if ($today) { - $where_clauses[] = 'c.CreatedOn >= ' . $today_date; - } + $sql .= ' WHERE (' . implode(') AND (', $where_clause) . ')'; - $sql .= ' WHERE ('.implode(') AND (', $where_clauses).')'; - $count = $this->Conn->GetOne($sql); - if ($count !== false) { + if ( $count !== false ) { $this->Application->setCache($cache_key, $count); } - } + } - return $count; + return $count; } /** + * Updates given data to make SQL use view permission check. + * + * @param string $prefix Unit config prefix. + * @param string $sql Sql. + * @param array $where_clause Where clause. + * @param string $category_field Field, where to get Category ID. + * + * @return array + * @access public + */ + public function attachViewPermissionCheck($prefix, $sql, $where_clause, $category_field = 'c.CategoryId') + { + if ( !$this->Application->ConfigValue('CheckViewPermissionsInCatalog') ) { + return array($sql, $where_clause); + } + + list ($view_perm, $view_filter) = $this->GetPermissionClause($prefix, 'perm_cache'); + + $where_clause[] = $view_filter; + $where_clause[] = 'perm_cache.PermId = ' . $view_perm; + + $sql .= ' INNER JOIN ' . TABLE_PREFIX . 'CategoryPermissionsCache perm_cache ON ' . $category_field . ' = perm_cache.CategoryId'; + + return array($sql, $where_clause); + } + + /** * Returns permission limitation clause for category item lists * * @param string $prefix Index: branches/5.2.x/core/install/install_data.sql =================================================================== diff -u -N -r15747 -r15761 --- branches/5.2.x/core/install/install_data.sql (.../install_data.sql) (revision 15747) +++ branches/5.2.x/core/install/install_data.sql (.../install_data.sql) (revision 15761) @@ -11,11 +11,12 @@ INSERT INTO SystemSettings VALUES(DEFAULT, 'AllowDeleteRootCats', '1', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_AllowDeleteRootCats', 'checkbox', NULL, NULL, 10.08, 0, 0, NULL); INSERT INTO SystemSettings VALUES(DEFAULT, 'Catalog_PreselectModuleTab', '1', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_CatalogPreselectModuleTab', 'checkbox', NULL, NULL, 10.09, 0, 0, NULL); INSERT INTO SystemSettings VALUES(DEFAULT, 'RecycleBinFolder', '', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_RecycleBinFolder', 'text', NULL, NULL, 10.10, 0, 0, NULL); -INSERT INTO SystemSettings VALUES(DEFAULT, 'CategoryPermissionRebuildMode', '3', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_CategoryPermissionRebuildMode', 'select', NULL, '1=la_opt_Manual||2=la_opt_Silent||3=la_opt_Automatic', 10.11, 0, 0, 'hint:la_config_CategoryPermissionRebuildMode'); -INSERT INTO SystemSettings VALUES(DEFAULT, 'FilenameSpecialCharReplacement', '-', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_FilenameSpecialCharReplacement', 'select', NULL, '_=+_||-=+-', 10.12, 0, 0, NULL); -INSERT INTO SystemSettings VALUES(DEFAULT, 'Search_MinKeyword_Length', '3', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_Search_MinKeyword_Length', 'text', NULL, NULL, 10.13, 0, 0, NULL); -INSERT INTO SystemSettings VALUES(DEFAULT, 'ExcludeTemplateSectionsFromSearch', '0', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_ExcludeTemplateSectionsFromSearch', 'checkbox', '', '', 10.14, 0, 0, NULL); -INSERT INTO SystemSettings VALUES(DEFAULT, 'UpdateCountersOnFilterChange', '1', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_UpdateCountersOnFilterChange', 'checkbox', '', '', 10.15, 0, 0, NULL); +INSERT INTO SystemSettings VALUES(DEFAULT, 'CheckViewPermissionsInCatalog', '0', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_CheckViewPermissionsInCatalog', 'radio', NULL, '1=la_Yes||0=la_No', 10.11, 0, 1, 'hint:la_config_CheckViewPermissionsInCatalog'); +INSERT INTO SystemSettings VALUES(DEFAULT, 'CategoryPermissionRebuildMode', '3', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_CategoryPermissionRebuildMode', 'select', NULL, '1=la_opt_Manual||2=la_opt_Silent||3=la_opt_Automatic', 10.12, 0, 0, 'hint:la_config_CategoryPermissionRebuildMode'); +INSERT INTO SystemSettings VALUES(DEFAULT, 'FilenameSpecialCharReplacement', '-', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_FilenameSpecialCharReplacement', 'select', NULL, '_=+_||-=+-', 10.13, 0, 0, NULL); +INSERT INTO SystemSettings VALUES(DEFAULT, 'Search_MinKeyword_Length', '3', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_Search_MinKeyword_Length', 'text', NULL, NULL, 10.14, 0, 0, NULL); +INSERT INTO SystemSettings VALUES(DEFAULT, 'ExcludeTemplateSectionsFromSearch', '0', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_ExcludeTemplateSectionsFromSearch', 'checkbox', '', '', 10.15, 0, 0, NULL); +INSERT INTO SystemSettings VALUES(DEFAULT, 'UpdateCountersOnFilterChange', '1', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_UpdateCountersOnFilterChange', 'checkbox', '', '', 10.16, 0, 0, NULL); INSERT INTO SystemSettings VALUES(DEFAULT, 'Category_MetaKey', '', 'In-Portal', 'in-portal:configure_categories', 'la_Text_MetaInfo', 'la_category_metakey', 'textarea', '', '', 20.01, 0, 1, NULL); INSERT INTO SystemSettings VALUES(DEFAULT, 'Category_MetaDesc', '', 'In-Portal', 'in-portal:configure_categories', 'la_Text_MetaInfo', 'la_category_metadesc', 'textarea', '', '', 20.02, 0, 1, NULL); Index: branches/5.2.x/core/units/structure/structure_config.php =================================================================== diff -u -N -r15563 -r15761 --- branches/5.2.x/core/units/structure/structure_config.php (.../structure_config.php) (revision 15563) +++ branches/5.2.x/core/units/structure/structure_config.php (.../structure_config.php) (revision 15761) @@ -1,6 +1,6 @@ Array ( '' => ' SELECT %1$s.* %2$s FROM %1$s - LEFT JOIN '.TABLE_PREFIX.'CategoryPermissionsCache ON '.TABLE_PREFIX.'CategoryPermissionsCache.CategoryId = %1$s.CategoryId', + {PERM_JOIN}', '-virtual' => 'SELECT %1$s.* %2$s FROM %1$s', ), Index: branches/5.2.x/core/kernel/db/cat_event_handler.php =================================================================== diff -u -N -r15608 -r15761 --- branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 15608) +++ branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 15761) @@ -1,6 +1,6 @@ getObject(); - /* @var $object kDBList */ + /* @var $object kCatDBList */ // add category filter if needed if ($event->Special != 'showall' && $event->Special != 'user') { @@ -648,22 +648,8 @@ $object->addFilter('owner_filter', '%1$s.'.$this->getOwnerField($event->Prefix).' = '.$editable_user); } - // add permission filter - if ($this->Application->RecallVar('user_id') == USER_ROOT) { - // for "root" CATEGORY.VIEW permission is checked for items lists too - $view_perm = 1; - } - else { - // for any real user itemlist view permission is checked instead of CATEGORY.VIEW - $count_helper = $this->Application->recallObject('CountHelper'); - /* @var $count_helper kCountHelper */ + $this->applyViewPermissionFilter($object); - list ($view_perm, $view_filter) = $count_helper->GetPermissionClause($event->Prefix, 'perm'); - $object->addFilter('perm_filter2', $view_filter); - } - - $object->addFilter('perm_filter', 'perm.PermId = '.$view_perm); - $types = $event->getEventParam('types'); $this->applyItemStatusFilter($object, $types); @@ -677,6 +663,36 @@ } /** + * Adds filter, that uses *.VIEW permissions to determine if an item should be shown to a user. + * + * @param kCatDBList $object Object. + * + * @return void + * @access protected + */ + protected function applyViewPermissionFilter(kCatDBList $object) + { + if ( !$this->Application->ConfigValue('CheckViewPermissionsInCatalog') ) { + return; + } + + if ( $this->Application->RecallVar('user_id') == USER_ROOT ) { + // for "root" CATEGORY.VIEW permission is checked for items lists too + $view_perm = 1; + } + else { + // for any real user item list view permission is checked instead of CATEGORY.VIEW + $count_helper = $this->Application->recallObject('CountHelper'); + /* @var $count_helper kCountHelper */ + + list ($view_perm, $view_filter) = $count_helper->GetPermissionClause($object->Prefix, 'perm'); + $object->addFilter('perm_filter2', $view_filter); + } + + $object->addFilter('perm_filter', 'perm.PermId = ' . $view_perm); + } + + /** * Adds filter that filters out items with non-required statuses * * @param kDBList $object @@ -2810,6 +2826,8 @@ parent::OnAfterConfigRead($event); if (defined('IS_INSTALL') && IS_INSTALL) { + $this->addViewPermissionJoin($event); + return ; } @@ -2821,7 +2839,7 @@ $file_helper->createItemFiles($event->Prefix, false); // create file fields } - $this->changeSortings($event); + $this->changeSortings($event)->addViewPermissionJoin($event); // add grids for advanced view (with primary category column) $grids = $this->Application->getUnitOption($this->Prefix, 'Grids'); @@ -2845,7 +2863,15 @@ $this->Application->setUnitOption($event->Prefix, 'VirtualFields', $virtual_fields); } - function changeSortings($event) + /** + * Changes default sorting according to system settings. + * + * @param kEvent $event Event. + * + * @return self + * @access protected + */ + protected function changeSortings(kEvent $event) { $remove_sortings = Array (); @@ -2863,7 +2889,7 @@ } if ( !$remove_sortings ) { - return; + return $this; } $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings', Array ()); @@ -2876,9 +2902,40 @@ } $this->Application->setUnitOption($event->Prefix, 'ListSortings', $list_sortings); + + return $this; } /** + * Adds permission table table JOIN clause only, when advanced catalog view permissions enabled. + * + * @param kEvent $event Event. + * + * @return self + * @access protected + */ + protected function addViewPermissionJoin(kEvent $event) + { + if ( $this->Application->ConfigValue('CheckViewPermissionsInCatalog') ) { + $join_clause = 'LEFT JOIN ' . TABLE_PREFIX . 'CategoryPermissionsCache perm ON perm.CategoryId = ' . TABLE_PREFIX . '%3$sCategoryItems.CategoryId'; + } + else { + $join_clause = ''; + } + + $list_sqls = $this->Application->getUnitOption($event->Prefix, 'ListSQLs'); + /* @var $list_sqls array */ + + foreach ($list_sqls as $special => $list_sql) { + $list_sqls[$special] = str_replace('{PERM_JOIN}', $join_clause, $list_sql); + } + + $this->Application->setUnitOption($event->Prefix, 'ListSQLs', $list_sqls); + + return $this; + } + + /** * Returns file contents associated with item * * @param kEvent $event Index: branches/5.2.x/core/install/upgrades.sql =================================================================== diff -u -N -r15747 -r15761 --- branches/5.2.x/core/install/upgrades.sql (.../upgrades.sql) (revision 15747) +++ branches/5.2.x/core/install/upgrades.sql (.../upgrades.sql) (revision 15761) @@ -2884,3 +2884,9 @@ UPDATE Modules SET ClassNamespace = 'Intechnic\\InPortal\\Core' WHERE `Name` IN ('Core', 'In-Portal'); + +UPDATE SystemSettings +SET DisplayOrder = DisplayOrder + 0.01 +WHERE ModuleOwner = 'In-Portal' AND Section = 'in-portal:configure_categories' AND DisplayOrder > 10.10 AND DisplayOrder < 20; + +INSERT INTO SystemSettings VALUES(DEFAULT, 'CheckViewPermissionsInCatalog', '1', 'In-Portal', 'in-portal:configure_categories', 'la_title_General', 'la_config_CheckViewPermissionsInCatalog', 'radio', NULL, '1=la_Yes||0=la_No', 10.11, 0, 1, 'hint:la_config_CheckViewPermissionsInCatalog'); Index: branches/5.2.x/core/units/categories/categories_config.php =================================================================== diff -u -N -r15563 -r15761 --- branches/5.2.x/core/units/categories/categories_config.php (.../categories_config.php) (revision 15563) +++ branches/5.2.x/core/units/categories/categories_config.php (.../categories_config.php) (revision 15761) @@ -1,6 +1,6 @@ ' SELECT %1$s.* %2$s FROM %1$s LEFT JOIN '.TABLE_PREFIX.'%3$sCatalogImages img ON img.ResourceId = %1$s.ResourceId AND img.DefaultImg = 1 - LEFT JOIN '.TABLE_PREFIX.'CategoryPermissionsCache ON '.TABLE_PREFIX.'CategoryPermissionsCache.CategoryId = %1$s.CategoryId + {PERM_JOIN} LEFT JOIN '.TABLE_PREFIX.'%3$sCategoryCustomData cust ON %1$s.ResourceId = cust.ResourceId', '-virtual' => 'SELECT %1$s.* %2$s FROM %1$s', ), Index: branches/5.2.x/core/units/helpers/permissions_helper.php =================================================================== diff -u -N -r15137 -r15761 --- branches/5.2.x/core/units/helpers/permissions_helper.php (.../permissions_helper.php) (revision 15137) +++ branches/5.2.x/core/units/helpers/permissions_helper.php (.../permissions_helper.php) (revision 15761) @@ -1,6 +1,6 @@ Application->ConfigValue('CheckViewPermissionsInCatalog') ) { + if ( strpos($cat_id, '|') !== false ) { + $category_path = explode('|', substr($cat_id, 1, -1)); + $cat_id = end($category_path); + } - $sql = 'SELECT PermissionConfigId - FROM ' . TABLE_PREFIX . 'CategoryPermissionsConfig - WHERE PermissionName = ' . $this->Conn->qstr($name); - $perm_id = $this->Conn->GetOne($sql); + $sql = 'SELECT PermissionConfigId + FROM ' . TABLE_PREFIX . 'CategoryPermissionsConfig + WHERE PermissionName = ' . $this->Conn->qstr($name); + $perm_id = $this->Conn->GetOne($sql); - $sql = 'SELECT PermId - FROM ' . TABLE_PREFIX . 'CategoryPermissionsCache - WHERE (PermId = ' . $perm_id . ') AND (CategoryId = ' . (int)$cat_id . ')'; + $sql = 'SELECT PermId + FROM ' . TABLE_PREFIX . 'CategoryPermissionsCache + WHERE (PermId = ' . $perm_id . ') AND (CategoryId = ' . (int)$cat_id . ')'; - $view_filters = Array (); - foreach ($groups as $group) { - $view_filters[] = 'FIND_IN_SET(' . $group . ', ACL)'; + $view_filters = Array (); + foreach ($groups as $group) { + $view_filters[] = 'FIND_IN_SET(' . $group . ', ACL)'; + } + $sql .= ' AND (' . implode(' OR ', $view_filters) . ')'; + $perm_value = $this->Conn->GetOne($sql) ? 1 : 0; } - $sql .= ' AND (' . implode(' OR ', $view_filters) . ')'; - $perm_value = $this->Conn->GetOne($sql) ? 1 : 0; + else { + $perm_value = 1; + } $this->Application->setCache('permissions[%CPermSerial%]:' . $cache_key, $perm_value); return $perm_value; Index: branches/5.2.x/core/install/english.lang =================================================================== diff -u -N -r15739 -r15761 --- branches/5.2.x/core/install/english.lang (.../english.lang) (revision 15739) +++ branches/5.2.x/core/install/english.lang (.../english.lang) (revision 15761) @@ -151,6 +151,7 @@ U3dpdGNoIENhdGFsb2cgdGFicyBiYXNlZCBvbiBNb2R1bGU= U2VjdGlvbiBQZXJtaXNzaW9uIFJlYnVpbGQgTW9kZQ== Q2hlY2sgU3RvcCBXb3Jkcw== + RW5hYmxlICJWaWV3IFBlcm1pc3Npb25zIiBDaGVjayBpbiBDYXRhbG9n Q0tGaW5kZXIgTGljZW5zZSBLZXk= Q0tGaW5kZXIgTGljZW5zZSBOYW1l RGVmYXVsdCBDU1YgRXhwb3J0IERlbGltaXRlcg==