? 933470-admin_theme_multirole.patch
Index: admin_theme.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/admin_theme/admin_theme.install,v
retrieving revision 1.1.2.5
diff -u -p -r1.1.2.5 admin_theme.install
--- admin_theme.install	20 Oct 2009 18:24:29 -0000	1.1.2.5
+++ admin_theme.install	3 Dec 2010 17:01:52 -0000
@@ -40,4 +40,21 @@ function admin_theme_uninstall() {
     $var = admin_theme_variable_name($info['module'], $info['option']);
     variable_del($var);
   }
-}
\ No newline at end of file
+}
+
+/**
+ * Implements hook_update_N().
+ *
+ * Change the variable structure of admin_theme.
+ */
+function admin_theme_update_6001() {
+  if (variable_get('admin_theme', 0)) {
+    // Fetch all roles that can access the admin theme.
+    $roles = user_roles(TRUE, 'access admin theme');
+    foreach ($roles as $rid) {
+      $options[$rid] = 1;
+    }
+    variable_set('admin_theme', $options);
+  }
+}
+
Index: admin_theme.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/admin_theme/admin_theme.module,v
retrieving revision 1.1.2.19
diff -u -p -r1.1.2.19 admin_theme.module
--- admin_theme.module	16 Apr 2010 13:38:02 -0000	1.1.2.19
+++ admin_theme.module	3 Dec 2010 17:01:53 -0000
@@ -7,6 +7,11 @@
  */
 
 /**
+ * @define superuser as a pseudo "role"
+ */
+define('SUPERUSER', 'user_1');
+
+/**
  * Implementation of hook_perm().
  */
 function admin_theme_perm() {
@@ -54,20 +59,32 @@ function admin_theme_list() {
 function admin_theme_form_system_admin_theme_settings_alter(&$form, $form_state) {
   // we want our checkboxes before the submit button
   $form['buttons']['#weight'] = 10;
-  
-  // define a fieldset for the theme
-  $form['theme'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Theme'),
-    '#collapsible' => TRUE,
-  );
+
   $form['theme']['#description'] = $form['admin_theme']['#description'];
   unset($form['admin_theme']['#description']);
   
   // add the core administration theme select field to this fieldset
-  $form['theme']['admin_theme'] = $form['admin_theme'];
+  $admin_theme = $form['admin_theme'];
   unset($form['admin_theme']);
-  
+
+  // Load all the roles that have the permission to use the admin theme.
+  $roles = user_roles(TRUE, 'access admin theme');
+  // Add user 1
+  $roles[SUPERUSER] = t('User 1');
+  // define a fieldset for the theme
+  $form['admin_theme'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Used theme'),
+    '#collapsible' => TRUE,
+    '#tree' => TRUE,
+  );
+  $defaults = variable_get('admin_theme', array());
+  foreach ($roles as $rid => $role) {
+    $form['admin_theme'][$rid] = $admin_theme;
+    $form['admin_theme'][$rid]['#title'] = t('For %role', array('%role' => $role));
+    $form['admin_theme'][$rid]['#default_value'] = isset($defaults[$rid]) ? $defaults[$rid] : 0;
+  }
+
   // define a fieldset for the page selection
   $form['pages'] = array(
     '#type' => 'fieldset',
@@ -83,6 +100,7 @@ function admin_theme_form_system_admin_t
 
   // add all options as checkboxes to the admin theme settings form
   $list = admin_theme_list();
+
   foreach ($list as $info) {
     $var = admin_theme_variable_name($info['module'], $info['option']);
     $form['pages'][$var] = array(
@@ -161,15 +179,45 @@ function admin_theme_init() {
     }
   }
 
+  // Repeat the core check.
+  if (arg(0) == 'admin' || (variable_get('node_admin_theme', '0') && arg(0) == 'node' && (arg(1) == 'add' || arg(2) == 'edit'))) {
+    $admin_theme = TRUE;
+  }
   // Use the admin theme for the current request (if global admin theme setting is checked).
   if ($admin_theme) {
     global $custom_theme;
-    $custom_theme = variable_get('admin_theme', '0');
+    $custom_theme = admin_theme_get_custom_theme();
     drupal_add_css(drupal_get_path('module', 'system') .'/admin.css', 'module');
   }
 }
 
 /**
+ * Load the correct admin theme from the variables table dependent on the current user.
+ */
+function admin_theme_get_custom_theme() {
+  global $user;
+  // User 1 is an exception.
+  $settings = variable_get('admin_theme', array());
+  if ($user->uid == 1 && isset($settings[SUPERUSER])) {
+    return $settings[SUPERUSER];
+  }
+  else {
+    // There is no API function to see if a permission is allowed for a given role.
+    // Roles that have the permission
+    $roles = user_roles(TRUE, 'access admin theme');
+    $users_roles = $user->roles;
+    $match = array_intersect($users_roles, $roles);
+    if (!empty($match)) {
+      $rid = key($match);
+      if (isset($settings[$rid])) {
+        return $settings[$rid];
+      }
+    }
+  }
+  return 0;
+}
+
+/**
  * Implementation of hook_admin_theme().
  */
 function admin_theme_admin_theme_options($op = 'info', $option = NULL) {
