Index: trunk/core/admin_templates/categories/categories_edit_permissions.tpl =================================================================== diff -u -N -r5319 -r5322 --- trunk/core/admin_templates/categories/categories_edit_permissions.tpl (.../categories_edit_permissions.tpl) (revision 5319) +++ trunk/core/admin_templates/categories/categories_edit_permissions.tpl (.../categories_edit_permissions.tpl) (revision 5322) @@ -70,7 +70,7 @@ if (isset($t)) set_hidden_field('t', $t); var $tab_id = this.queryTabRegistry('prefix', this.ActivePrefix, 'tab_id'); - this.submit_kernel_form($tab_id); + this.submit_kernel_form(); } var $PermManager = new Catalog('', 'permmanager_'); @@ -98,11 +98,6 @@ function edit(){ } - - function ReflectPermissions($prefix, $group_id) { - // process only this prefix & group checkboxes - } - a_toolbar.Render(); @@ -177,6 +172,24 @@ } Grids['g'].RadioMode = true; + + function update_light(perm_name, value) + { + var $img_base = img_path.replace('#MODULE#', 'kernel'); + document.getElementById('light_'+perm_name).src = $img_base + 'perm_' + (value ? 'green' : 'red') + '.gif'; + } + + function inherited_click(perm_name, inherited_value, state, access_cb_id) + { + if (state) { + update_light(perm_name, inherited_value); + document.getElementById(access_cb_id).disabled = true; + } + else { + update_light(perm_name, document.getElementById(access_cb_id).checked) + document.getElementById(access_cb_id).disabled = false; + } + } \ No newline at end of file Index: trunk/core/admin_templates/js/catalog.js =================================================================== diff -u -N -r5296 -r5322 --- trunk/core/admin_templates/js/catalog.js (.../catalog.js) (revision 5296) +++ trunk/core/admin_templates/js/catalog.js (.../catalog.js) (revision 5322) @@ -43,14 +43,22 @@ } Catalog.prototype.submit_kernel_form = function($tab_id) { - var $prefix = this.queryTabRegistry('tab_id', $tab_id, 'prefix'); + var $prefix = 'dummy'; + var $result_div = ''; + + if (isset($tab_id)) { + // responce result + progress are required + $prefix = this.queryTabRegistry('tab_id', $tab_id, 'prefix'); + $result_div = $tab_id + '_div'; + } + var $kf = document.getElementById($form_name); Request.params = Request.serializeForm($kf); Request.method = $kf.method.toUpperCase(); this.BusyRequest[$prefix] = false; - Request.makeRequest($kf.action, this.BusyRequest[$prefix], $tab_id + '_div', this.successCallback, this.errorCallback, $tab_id + '_div', this); + Request.makeRequest($kf.action, this.BusyRequest[$prefix], $result_div, this.successCallback, this.errorCallback, $result_div, this); $form_name = 'kernel_form'; // restore back to main form with current category id of catalog }; @@ -62,17 +70,19 @@ window.location.href = RegExp.$1; return false; } - + $params = $params.split(','); - var $js_end = $text.indexOf($object.Separator); - if ($js_end != -1) { - document.getElementById($params[0]).innerHTML = $text.substring($js_end + $object.Separator.length); - eval($text.substring(0, $js_end)); + if ($params[0].length) { + var $js_end = $text.indexOf($object.Separator); + if ($js_end != -1) { + document.getElementById($params[0]).innerHTML = $text.substring($js_end + $object.Separator.length); + eval($text.substring(0, $js_end)); + } + else { + document.getElementById($params[0]).innerHTML = $text; + } } - else { - document.getElementById($params[0]).innerHTML = $text; - } - + if (typeof($Debugger) != 'undefined') { $Debugger.Clear(); } Index: trunk/kernel/units/permissions/permissions_tag_processor.php =================================================================== diff -u -N -r5319 -r5322 --- trunk/kernel/units/permissions/permissions_tag_processor.php (.../permissions_tag_processor.php) (revision 5319) +++ trunk/kernel/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 Index: trunk/kernel/admin_templates/categories/categories_edit_permissions.tpl =================================================================== diff -u -N -r5319 -r5322 --- trunk/kernel/admin_templates/categories/categories_edit_permissions.tpl (.../categories_edit_permissions.tpl) (revision 5319) +++ trunk/kernel/admin_templates/categories/categories_edit_permissions.tpl (.../categories_edit_permissions.tpl) (revision 5322) @@ -70,7 +70,7 @@ if (isset($t)) set_hidden_field('t', $t); var $tab_id = this.queryTabRegistry('prefix', this.ActivePrefix, 'tab_id'); - this.submit_kernel_form($tab_id); + this.submit_kernel_form(); } var $PermManager = new Catalog('', 'permmanager_'); @@ -98,11 +98,6 @@ function edit(){ } - - function ReflectPermissions($prefix, $group_id) { - // process only this prefix & group checkboxes - } - a_toolbar.Render(); @@ -177,6 +172,24 @@ } Grids['g'].RadioMode = true; + + function update_light(perm_name, value) + { + var $img_base = img_path.replace('#MODULE#', 'kernel'); + document.getElementById('light_'+perm_name).src = $img_base + 'perm_' + (value ? 'green' : 'red') + '.gif'; + } + + function inherited_click(perm_name, inherited_value, state, access_cb_id) + { + if (state) { + update_light(perm_name, inherited_value); + document.getElementById(access_cb_id).disabled = true; + } + else { + update_light(perm_name, document.getElementById(access_cb_id).checked) + document.getElementById(access_cb_id).disabled = false; + } + } \ No newline at end of file Index: trunk/kernel/admin_templates/incs/catalog.js =================================================================== diff -u -N -r5296 -r5322 --- trunk/kernel/admin_templates/incs/catalog.js (.../catalog.js) (revision 5296) +++ trunk/kernel/admin_templates/incs/catalog.js (.../catalog.js) (revision 5322) @@ -43,14 +43,22 @@ } Catalog.prototype.submit_kernel_form = function($tab_id) { - var $prefix = this.queryTabRegistry('tab_id', $tab_id, 'prefix'); + var $prefix = 'dummy'; + var $result_div = ''; + + if (isset($tab_id)) { + // responce result + progress are required + $prefix = this.queryTabRegistry('tab_id', $tab_id, 'prefix'); + $result_div = $tab_id + '_div'; + } + var $kf = document.getElementById($form_name); Request.params = Request.serializeForm($kf); Request.method = $kf.method.toUpperCase(); this.BusyRequest[$prefix] = false; - Request.makeRequest($kf.action, this.BusyRequest[$prefix], $tab_id + '_div', this.successCallback, this.errorCallback, $tab_id + '_div', this); + Request.makeRequest($kf.action, this.BusyRequest[$prefix], $result_div, this.successCallback, this.errorCallback, $result_div, this); $form_name = 'kernel_form'; // restore back to main form with current category id of catalog }; @@ -62,17 +70,19 @@ window.location.href = RegExp.$1; return false; } - + $params = $params.split(','); - var $js_end = $text.indexOf($object.Separator); - if ($js_end != -1) { - document.getElementById($params[0]).innerHTML = $text.substring($js_end + $object.Separator.length); - eval($text.substring(0, $js_end)); + if ($params[0].length) { + var $js_end = $text.indexOf($object.Separator); + if ($js_end != -1) { + document.getElementById($params[0]).innerHTML = $text.substring($js_end + $object.Separator.length); + eval($text.substring(0, $js_end)); + } + else { + document.getElementById($params[0]).innerHTML = $text; + } } - else { - document.getElementById($params[0]).innerHTML = $text; - } - + if (typeof($Debugger) != 'undefined') { $Debugger.Clear(); } 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 Index: trunk/kernel/admin_templates/img/perm_red.gif =================================================================== diff -u -N Binary files differ Index: trunk/kernel/admin_templates/img/perm_green.gif =================================================================== diff -u -N Binary files differ Index: trunk/core/admin_templates/categories/permissions_tab.tpl =================================================================== diff -u -N -r5304 -r5322 --- trunk/core/admin_templates/categories/permissions_tab.tpl (.../permissions_tab.tpl) (revision 5304) +++ trunk/core/admin_templates/categories/permissions_tab.tpl (.../permissions_tab.tpl) (revision 5322) @@ -3,9 +3,7 @@ document.getElementById('_div').setAttribute('group_id', ); - ReflectPermissions('', ); #separator# - "> @@ -14,30 +12,34 @@ - [][][inherit]" /> + ', , this.checked, '')" type="checkbox" name="" value="1" checked/> + + + + + - [][][value]" /> + ', this.checked)" type="checkbox" disabled="disabled" name="" id="" value="1" checked/> - inherit category name + + " src="/img/perm_greenred.gif"/> - - + + - +
- - from ajax [prefix: ]; [group_id: ]
\ No newline at end of file Index: trunk/kernel/admin_templates/categories/permissions_tab.tpl =================================================================== diff -u -N -r5304 -r5322 --- trunk/kernel/admin_templates/categories/permissions_tab.tpl (.../permissions_tab.tpl) (revision 5304) +++ trunk/kernel/admin_templates/categories/permissions_tab.tpl (.../permissions_tab.tpl) (revision 5322) @@ -3,9 +3,7 @@ document.getElementById('_div').setAttribute('group_id', ); - ReflectPermissions('', ); #separator# - "> @@ -14,30 +12,34 @@ - [][][inherit]" /> + ', , this.checked, '')" type="checkbox" name="" value="1" checked/> + + + + + - [][][value]" /> + ', this.checked)" type="checkbox" disabled="disabled" name="" id="" value="1" checked/> - inherit category name + + " src="/img/perm_greenred.gif"/> - - + + - +
- - from ajax [prefix: ]; [group_id: ]
\ No newline at end of file