Index: trunk/core/units/permissions/permissions_tag_processor.php =================================================================== diff -u -N -r5319 -r5322 --- trunk/core/units/permissions/permissions_tag_processor.php (.../permissions_tag_processor.php) (revision 5319) +++ trunk/core/units/permissions/permissions_tag_processor.php (.../permissions_tag_processor.php) (revision 5322) @@ -69,25 +69,23 @@ $perm_temp_table = $this->Application->GetTempName($perm_live_table); $categories = explode('|', substr($category->GetDBField('ParentPath'), 1, -1)); + $this_cat = array_pop($categories); // 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 + $sql = 'SELECT '.$case.', 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'); @@ -96,7 +94,7 @@ 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); + $pos_sql = $pos_sql ? preg_replace('/(.*) OR $/', '\\1', $pos_sql) : '0'; // get all permissions list with iheritence status, inherited category id and permission value $sql = 'SELECT pc.PermissionName, @@ -106,15 +104,18 @@ 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 + IF(tmp_p.CatId = '.$category->GetID().', 0, 1) AS Inherited, + IF(p.PermissionValue IS NOT NULL, p.PermissionValue, 0) AS InheritedValue 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.') + 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 (tmp_p.CatId = '.$this_cat.') AND (tmp_p.GroupId = '.$group_id.') WHERE ModuleId = "'.$module.'"'; $permissions = $this->Conn->Query($sql); $ret = ''; - $block_params = Array('name' => $params['render_as']); + $block_params = array_merge_recursive2( $this->prepareTagParams($params), Array('name' => $params['render_as'])); foreach ($permissions as $perm_record) { $block_params = array_merge_recursive2($block_params, $perm_record); $ret .= $this->Application->ParseBlock($block_params); @@ -139,6 +140,38 @@ return $ret; } + /** + * Returns category name by ID + * + * @param Array $params + */ + function CategoryPath($params) + { + $category_id = $params['cat_id']; + $category_path = $this->Application->getCache('category_paths', $category_id); + if ($category_path === false) { + // not chached + if ($category_id > 0) { + $id_field = $this->Application->getUnitOption('c', 'IDField'); + $table_name = $this->Application->getUnitOption('c', 'TableName'); + $sql = 'SELECT CachedNavbar + FROM '.$table_name.' + WHERE '.$id_field.' = '.$category_id; + $category_path = trim($this->CategoryPath( Array('cat_id' => 0) ).'>'.$this->Conn->GetOne($sql), '>'); + } + else { + $category_path = $this->Application->Phrase( $this->Application->ConfigValue('Root_Name') ); + } + $this->Application->setCache('category_paths', $category_id, $category_path); + } + return $category_path; + } + + function PermInputName($params) + { + return $this->Prefix.'['.$this->Application->GetVar('group_id').']['.$this->Application->Parser->GetParam('PermissionName').']['.$params['sub_key'].']'; + } + } ?> \ No newline at end of file