Index: adminrole.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/adminrole/adminrole.info,v
retrieving revision 1.3
diff -u -r1.3 adminrole.info
--- adminrole.info	18 Jun 2007 22:53:28 -0000	1.3
+++ adminrole.info	7 Feb 2008 18:34:05 -0000
@@ -1,3 +1,4 @@
+; $Id$
 name = Admin Role
-description = Create a role to be "admin" and automatically assign all perms to that role.
-package = User Access
\ No newline at end of file
+description = Automatically grant full access to a chosen administrator role.
+core = 6.x
Index: adminrole.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/adminrole/adminrole.module,v
retrieving revision 1.3
diff -u -r1.3 adminrole.module
--- adminrole.module	4 May 2007 17:33:17 -0000	1.3
+++ adminrole.module	7 Feb 2008 18:34:05 -0000
@@ -1,7 +1,8 @@
 <?php
-// $Id: adminrole.module,v 1.3 2007/05/04 17:33:17 jacobsingh Exp $
+// $Id$

-/** @file
+/**
+ * @file
  * adminrole:
  * This module simply gives a designated role all permissions every time the
  * modules page is submitted.
@@ -10,74 +11,114 @@
 /**
  * Implementation of hook_help().
  */
-function adminrole_help($section) {
-  switch ($section) {
-    case 'admin/settings/adminrole':
-      return t('Change which role is a "admin" Role with full perms');
+function adminrole_help($path, $arg) {
+  $output = '';
+  switch ($path) {
+    case 'admin/help#adminrole':
+      $output = '<p>'. t('This module automatically manages the administrator role.') .'</p>';
   }
+  return $output;
 }

 /**
  * Implementation of hook_menu().
  */
-function adminrole_menu($may_cache) {
+function adminrole_menu() {
   $items = array();
+  $items['admin/user/adminrole'] = array(
+    'title' => 'Administrator role',
+    'description' => 'Change which role is the (full access) administrator role.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('adminrole_admin_settings'),
+    'access callback' => 'user_access',
+    'access arguments' => array('administer permissions'),
+    'type' => MENU_NORMAL_ITEM
+  );
+  return $items;
+}

-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/settings/adminrole',
-      'title' => t('adminrole'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('adminrole_admin_settings'),
-      'access' => user_access('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM
-    );
-    $items[] = array(
-      'path' => 'admin/adminrole/update',
-      'title' => t('adminrole'),
-      'callback' => 'adminrole_update_perms',
-      'access' => user_access('administer site configuration'),
-      'type' => MENU_SUGGESTED_ITEM
-    );
+/**
+ * Implementation of hook_enable().
+ */
+function adminrole_enable() {
+  $admin_role = variable_get('adminrole_adminrole', 0);
+  if ($admin_role == 0) {
+    $role = db_fetch_object(db_query("SELECT rid FROM {role} WHERE name = 'admin' OR name = 'administrator'"));
+    if (is_object($role)) {
+      $admin_role = $role->rid;
+    }
+    variable_set('adminrole_adminrole', $admin_role);
   }
-  return $items;
+  adminrole_update_perms();
 }

+/**
+ * Grant full access for administrators.
+ */
 function adminrole_update_perms() {
-  if ($admin_role = variable_get('adminrole_adminrole', 0)) {
-    $perms = array();
-    foreach (module_list(FALSE, FALSE, TRUE) as $module) {
-      if ($permissions = module_invoke($module, 'perm')) {
-        $perms = array_merge($perms, $permissions);
-      }
-    }
-    db_query('DELETE FROM {permission} WHERE rid = %d', $admin_role);
-    if (count($perms)) {
-      db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $admin_role, implode(', ', $perms));
+  $admin_role = variable_get('adminrole_adminrole', 0);
+  if ($admin_role == 0) {
+    return;
+  }
+
+  $perms = array();
+  foreach (module_list(TRUE, FALSE, TRUE) as $module) {
+    if ($permissions = module_invoke($module, 'perm')) {
+      $perms = array_merge($perms, $permissions);
     }
-    drupal_set_message(t('Admin Permissions Set'));
   }
+  db_query('DELETE FROM {permission} WHERE rid = %d', $admin_role);
+  if (count($perms)) {
+    db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $admin_role, implode(', ', $perms));
+  }
+  $user_roles = user_roles();
+  drupal_set_message(t('Granted full access for role: ' .$user_roles[$admin_role]));
 }

+/**
+ * Admin role selection form.
+ */
 function adminrole_admin_settings() {
   $form = array();
+  $user_roles = user_roles();
+  unset($user_roles[DRUPAL_AUTHENTICATED_RID]);
+  unset($user_roles[DRUPAL_ANONYMOUS_RID]);
+  ksort($user_roles);
+
+  $options = array(0 => t('none')) + $user_roles;
   $form['adminrole_adminrole'] = array(
     '#type' => 'select',
-    '#title' => t('Admin Roles'),
     '#default_value' => variable_get('adminrole_adminrole', 0),
-    '#description' => t("Which Role is Admin?"),
-    '#options' => array_merge(array(0 => t('-- Please Select One --')), user_roles()),
+    '#description' => t('Select the administrator role.'),
+    '#options' => $options,
   );
-  return system_settings_form($form);
-}
-
-function adminrole_form_alter($form_id, &$form) {
-  if ($form_id == 'system_modules') {
-    $form['#submit']["adminrole_update_perms"] = array();
-  }
-}

+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+  );

+  return $form;
+}

+/**
+ * Admin role settings submit.
+ */
+function adminrole_admin_settings_submit($form, &$form_state) {
+  $admin_role = $form_state['values']['adminrole_adminrole'];
+  variable_set('adminrole_adminrole', $admin_role);

+  drupal_set_message('Administrator role changed.');
+  adminrole_update_perms();
+}

+/**
+ * Implementation of hook_form_alter().
+ *
+ * Update admin permission when modules are enabled/disabled.
+ */
+function adminrole_form_alter(&$form, $form_state, $form_id) {
+  if ($form_id == 'system_modules') {
+    $form['#submit'][] = 'adminrole_update_perms';
+  }
+}
