diff options
| author | lsces <lester@lsces.co.uk> | 2012-08-06 18:43:04 +0100 |
|---|---|---|
| committer | lsces <lester@lsces.co.uk> | 2012-08-06 18:43:04 +0100 |
| commit | 8326991cd2bb943d371ee07726cedebad91a085b (patch) | |
| tree | 25f9bd668bc5ae4b015ac03d04d9e89c4919b6b2 | |
| parent | e9e19c996ef22c3535bf34822fde69c3e094c5b0 (diff) | |
| download | themes-8326991cd2bb943d371ee07726cedebad91a085b.tar.gz themes-8326991cd2bb943d371ee07726cedebad91a085b.tar.bz2 themes-8326991cd2bb943d371ee07726cedebad91a085b.zip | |
Complete role model support in theme management
| -rw-r--r-- | BitThemes.php | 79 | ||||
| -rw-r--r-- | templates/admin_layout.tpl | 60 | ||||
| -rw-r--r-- | templates/admin_layout_overview.tpl | 6 |
3 files changed, 123 insertions, 22 deletions
diff --git a/BitThemes.php b/BitThemes.php index 5d3f0ea..285ca03 100644 --- a/BitThemes.php +++ b/BitThemes.php @@ -501,6 +501,35 @@ class BitThemes extends BitSingleton { break; } + if ( defined ('ROLE_MODEL') ) { + // transform roles to managable array + if( empty( $row["roles"] )) { + // default is that module is visible at all times + $row["visible"] = TRUE; + $row["module_roles"] = array(); + } else { + $row['module_roles'] = $this->parseRoles( $row['roles'] ); + + if( $gBitUser->isAdmin() ) { + if ( $gBitSystem->isFeatureActive('site_mods_req_admn_grp') ) { + if( in_array(1, $row['module_roles']) ) { + $row['visible'] = TRUE; + } + } + else { + $row["visible"] = TRUE; + } + } else { + // Check for the right roles + foreach( $row["module_roles"] as $modRoleId ) { + if( $gBitUser->isInRole( $modRoleId )) { + $row["visible"] = TRUE; + break; // no need to continue looping + } + } + } + } + } else { // transform groups to managable array if( empty( $row["groups"] )) { // default is that module is visible at all times @@ -528,6 +557,7 @@ class BitThemes extends BitSingleton { } } } + } if( empty( $ret[$row['layout_area']] )) { $ret[$row['layout_area']] = array(); @@ -621,7 +651,11 @@ class BitThemes extends BitSingleton { $layouts = array(); $modules = $this->mDb->getAll( "SELECT tl.* FROM `".BIT_DB_PREFIX."themes_layouts` tl ORDER BY ".$this->mDb->convertSortmode( "pos_asc" )); foreach( $modules as $module ) { - $module['module_groups'] = $this->parseGroups( $module['groups'] ); + if( defined ( 'ROLE_MODEL') ) { + $module['module_roles'] = $this->parseRoles( $module['roles'] ); + } else { + $module['module_groups'] = $this->parseGroups( $module['groups'] ); + } $layouts[$module['layout']][$module['layout_area']][] = $module; } ksort( $layouts ); @@ -648,8 +682,9 @@ class BitThemes extends BitSingleton { // nuke existing layout $this->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."themes_layouts` WHERE `layout`=?", array( $pToLayout )); // get requested layout + $team = defined('ROLE_MODEL') ? 'roles' : 'groups'; $layout = $this->mDb->getAll( " - SELECT `title`, `layout_area`, `module_rows`, `module_rsrc`, `params`, `cache_time`, `groups`, `pos` + SELECT `title`, `layout_area`, `module_rows`, `module_rsrc`, `params`, `cache_time`, `$team`, `pos` FROM `".BIT_DB_PREFIX."themes_layouts` WHERE `layout`=?", array( $pFromLayout )); foreach( $layout as $module ) { $module['layout'] = $pToLayout; @@ -708,6 +743,39 @@ class BitThemes extends BitSingleton { return $ret; } + /** + * transform roles string to handy array + * + * @param array $pParseString either space separated list of roles or serialised array + * @access public + * @return array of roles + */ + function parseRoles( $pParseString ) { + $ret = array(); + // convert role string to hash + if( preg_match( '/[A-Za-z]/', $pParseString )) { + // old style serialized role names + if( $grps = @unserialize( $pParseString )) { + foreach( $grps as $grp ) { + global $gBitUser; + if( !( $roleId = array_search( $grp, $gBitUser->mRoles ))) { + if( $gBitUser->isAdmin() ) { + $ret[] = $gBitUser->rollExists( $grp, '*' ); + } + } + + if( @$this->verifyId( $roleId )) { + $ret[] = $roleId; + } + } + } + } else { + // new imploded style + $ret = explode( ' ', $pParseString ); + } + return $ret; + } + // }}} // {{{ =================== Modules ==================== @@ -736,13 +804,18 @@ class BitThemes extends BitSingleton { } $pHash['store']['title'] = ( !empty( $pHash['title'] ) ? $pHash['title'] : NULL ); + $pHash['store']['params'] = ( !empty( $pHash['params'] ) ? $pHash['params'] : NULL ); $pHash['store']['layout'] = ( !empty( $pHash['layout'] ) ? $pHash['layout'] : DEFAULT_PACKAGE ); $pHash['store']['module_rows'] = ( @is_numeric( $pHash['module_rows'] ) ? $pHash['module_rows'] : NULL ); $pHash['store']['cache_time'] = ( @is_numeric( $pHash['cache_time'] ) ? $pHash['cache_time'] : NULL ); $pHash['store']['pos'] = ( @is_numeric( $pHash['pos'] ) ? $pHash['pos'] : 1 ); - if( !empty( $pHash['groups'] ) && is_array( $pHash['groups'] )) { + if( !empty( $pHash['roles'] ) && is_array( $pHash['roles'] )) { + $pHash['store']['roles'] = implode( ' ', $pHash['roles'] ); + } elseif( !empty( $pHash['groups'] ) && is_array( $pHash['groups'] )) { $pHash['store']['groups'] = implode( ' ', $pHash['groups'] ); + } elseif (defined('ROLE_MODEL') ) { + $pHash['store']['roles'] = NULL; } else { $pHash['store']['groups'] = NULL; } diff --git a/templates/admin_layout.tpl b/templates/admin_layout.tpl index 484b2b4..9ad0682 100644 --- a/templates/admin_layout.tpl +++ b/templates/admin_layout.tpl @@ -206,15 +206,27 @@ </div> <div class="row"> - {formlabel label="Groups" for="groups"} - {forminput} - <select multiple="multiple" size="5" name="groups[]" id="groups"> - {foreach from=$groups key=groupId item=group} - <option value="{$groupId}" {if $group.selected eq 'y'}selected="selected"{/if}>{$group.group_name}</option> - {/foreach} - </select> - {formhelp note="Select the groups of users who can see this module. If you select no group, the module will be visible to all users."} - {/forminput} + {if $roles } + {formlabel label="Roles" for="roles"} + {forminput} + <select multiple="multiple" size="5" name="roles[]" id="roles"> + {foreach from=$roles key=roleId item=role} + <option value="{$roleId}" {if $role.selected eq 'y'}selected="selected"{/if}>{$role.role_name}</option> + {/foreach} + </select> + {formhelp note="Select the roles of users who can see this module. If you select no role, the module will be visible to all users."} + {/forminput} + {else} + {formlabel label="Groups" for="groups"} + {forminput} + <select multiple="multiple" size="5" name="groups[]" id="groups"> + {foreach from=$groups key=groupId item=group} + <option value="{$groupId}" {if $group.selected eq 'y'}selected="selected"{/if}>{$group.group_name}</option> + {/foreach} + </select> + {formhelp note="Select the groups of users who can see this module. If you select no group, the module will be visible to all users."} + {/forminput} + {/if} </div> <div class="row"> @@ -310,15 +322,27 @@ </div> <div class="row"> - {formlabel label="Groups" for="c_groups"} - {forminput} - <select multiple="multiple" size="5" name="groups[]" id="c_groups"> - {foreach from=$groups key=groupId item=group} - <option value="{$groupId}" {if $group.selected eq 'y'}selected="selected"{/if}>{$group.group_name}</option> - {/foreach} - </select> - {formhelp note="Select the groups of users who can see this module. If you select no group, the module will be visible to all users."} - {/forminput} + {if $roles } + {formlabel label="Roles" for="c_roles"} + {forminput} + <select multiple="multiple" size="5" name="roles[]" id="c_roles"> + {foreach from=$roles key=roleId item=role} + <option value="{$roleId}" {if $role.selected eq 'y'}selected="selected"{/if}>{$role.role_name}</option> + {/foreach} + </select> + {formhelp note="Select the roles of users who can see this module. If you select no role, the module will be visible to all users."} + {/forminput} + {else} + {formlabel label="Groups" for="c_groups"} + {forminput} + <select multiple="multiple" size="5" name="groups[]" id="c_groups"> + {foreach from=$groups key=groupId item=group} + <option value="{$groupId}" {if $group.selected eq 'y'}selected="selected"{/if}>{$group.group_name}</option> + {/foreach} + </select> + {formhelp note="Select the groups of users who can see this module. If you select no group, the module will be visible to all users."} + {/forminput} + {/if} </div> <div class="row submit"> diff --git a/templates/admin_layout_overview.tpl b/templates/admin_layout_overview.tpl index 90d18e9..a0682e4 100644 --- a/templates/admin_layout_overview.tpl +++ b/templates/admin_layout_overview.tpl @@ -66,7 +66,11 @@ {section name=ix loop=$layout.$area} <tr> <td> - {include file="bitpackage:themes/module_config_inc.tpl" modInfo=$layout.$area[ix]} + {if $roles } + {include file="bitpackage:themes/module_config_role_inc.tpl" modInfo=$layout.$area[ix]} + {else} + {include file="bitpackage:themes/module_config_inc.tpl" modInfo=$layout.$area[ix]} + {/if} </td> </tr> {sectionelse} |
