/[drupal]/contributions/modules/role_theme_switcher/role_theme_switcher.module
ViewVC logotype

Contents of /contributions/modules/role_theme_switcher/role_theme_switcher.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Wed Feb 18 16:56:40 2009 UTC (9 months ago) by tiutiun
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, HEAD
Branch point for: DRUPAL-6--1
Changes since 1.5: +29 -21 lines
File MIME type: text/x-php
Drupal 6.x release
- Thanks to nextpulse (Robert Yau) for the proposed patch
1 <?php
2 // $Id: role_theme_switcher.module,v 1.1 2009/01/21 10:34:35 moduledeveloper Exp $
3
4 /**
5 * Implementation of hook_init().
6 */
7 function role_theme_switcher_init()
8 {
9 global $user, $custom_theme;
10
11 foreach ($user->roles as $key => $value)
12 {
13 $role_name = str_replace(' ', '_', $value);
14 $role_theme = variable_get(strtolower($role_name) .'_theme', '');
15
16 // Change active theme in user object
17 $user->theme = $role_theme;
18
19 // Also change the active theme globally
20 $custom_theme = $role_theme;
21 drupal_clear_css_cache();
22 }
23 }
24
25 /**
26 * Implementation of hook_menu().
27 */
28 function role_theme_switcher_menu()
29 {
30 $items['admin/user/themes'] = array(
31 'type' => MENU_NORMAL_ITEM,
32 'title' => t('Role theme switcher'),
33 'description' => t('Settings for role theme switcher.'),
34 'page callback' => 'drupal_get_form',
35 'page arguments' => array('role_theme_switcher_admin_settings'),
36 'access arguments'=> array('administer site configuration'),
37 );
38
39 return $items;
40 }
41
42 /**
43 * Implemntation of hook_settings().
44 */
45 function role_theme_switcher_admin_settings()
46 {
47 $roles = user_roles();
48 // Get all enabled themes
49 $themes = list_themes();
50 $list = array_merge(array(t('Default')), array_keys($themes));
51
52 foreach ($roles as $id => $role)
53 {
54 $role_name = str_replace(' ', '_', $role);
55 $form[strtolower($role_name) .'_theme'] = array(
56 '#type' => 'select',
57 '#title' => ucfirst(strtolower($role)),
58 '#options' => drupal_map_assoc($list),
59 '#default_value' => variable_get(strtolower($role_name) .'_theme', '')
60 );
61 }
62
63 return system_settings_form($form);
64 }

  ViewVC Help
Powered by ViewVC 1.1.2