Index: trunk/core/units/permissions/permissions_tag_processor.php =================================================================== diff -u -N -r5304 -r5319 --- trunk/core/units/permissions/permissions_tag_processor.php (.../permissions_tag_processor.php) (revision 5304) +++ trunk/core/units/permissions/permissions_tag_processor.php (.../permissions_tag_processor.php) (revision 5319) @@ -59,13 +59,57 @@ function PrintPermissions($params) { + $category =& $this->Application->recallObject('c'); + $group_id = $this->Application->GetVar('group_id'); $prefix = $this->Application->GetVar('item_prefix'); - $module = $this->Application->findModule('Var', $prefix, 'Name'); - $sql = 'SELECT * - FROM '.TABLE_PREFIX.'PermissionConfig + $perm_live_table = $this->Application->getUnitOption('c-perm', 'TableName'); + $perm_temp_table = $this->Application->GetTempName($perm_live_table); + + $categories = explode('|', substr($category->GetDBField('ParentPath'), 1, -1)); + + // get permission name + category position in parent path that has value set for that permission + $case = 'MAX(CASE c.CategoryId'; + foreach ($categories as $pos => $cat_id) { + $case .= ' WHEN '.$cat_id.' THEN '.$pos; + } + $case .= ' END) AS InheritedPosition'; + $sql = 'SELECT '.$case.', IF(tmp_p.Permission IS NOT NULL, tmp_p.Permission, p.Permission) AS Perm + FROM '.TABLE_PREFIX.'Category c + LEFT JOIN '.$perm_live_table.' p ON p.CatId = c.CategoryId + LEFT JOIN '.TABLE_PREFIX.'PermissionConfig pc ON pc.PermissionName = p.Permission + LEFT JOIN '.$perm_temp_table.' tmp_p ON tmp_p.CatId = c.CategoryId + WHERE + CategoryId IN ('.implode(',', $categories).') AND + ModuleId = "'.$module.'" AND + ( + (p.GroupId = '.$group_id.' AND p.Type = 0) + OR + (tmp_p.GroupId = '.$group_id.' AND tmp_p.Type = 0) + ) + GROUP BY Perm'; + $perm_positions = $this->Conn->GetCol($sql, 'Perm'); + + $pos_sql = ''; + foreach ($perm_positions as $perm_name => $category_pos) { + $pos_sql .= '(#TABLE_PREFIX#.Permission = "'.$perm_name.'" AND #TABLE_PREFIX#.CatId = '.$categories[$category_pos].') OR '; + } + $pos_sql = preg_replace('/(.*) OR $/', '\\1', $pos_sql); + + // get all permissions list with iheritence status, inherited category id and permission value + $sql = 'SELECT pc.PermissionName, + pc.Description, + IF (tmp_p.PermissionValue IS NULL AND p.PermissionValue IS NULL, + 0, + IF (tmp_p.PermissionValue IS NOT NULL, tmp_p.PermissionValue, p.PermissionValue) + ) AS Value, + IF (tmp_p.CatId IS NOT NULL, tmp_p.CatId, IF(p.CatId IS NOT NULL, p.CatId, 0) ) AS InheritedFrom, + IF(tmp_p.CatId = '.$category->GetID().', 0, 1) AS Inherited + FROM '.TABLE_PREFIX.'PermissionConfig pc + LEFT JOIN '.$perm_live_table.' p ON (p.Permission = pc.PermissionName) AND ('.str_replace('#TABLE_PREFIX#', 'p', $pos_sql).') AND (p.GroupId = '.$group_id.') + LEFT JOIN '.$perm_temp_table.' tmp_p ON (tmp_p.Permission = pc.PermissionName) AND ('.str_replace('#TABLE_PREFIX#', 'tmp_p', $pos_sql).') AND (tmp_p.GroupId = '.$group_id.') WHERE ModuleId = "'.$module.'"'; $permissions = $this->Conn->Query($sql);