--- og_user_roles.module.5.x-2.7.orig	2008-01-11 00:03:46.000000000 -0800
+++ og_user_roles.module	2008-01-11 00:06:19.000000000 -0800
@@ -1,5 +1,5 @@
 <?php
-// $Id: og_user_roles.module,v 1.1.2.11 2008/01/10 20:01:19 somebodysysop Exp $
+// $Id: og_user_roles.module,v 1.1.2.3 2007/07/08 19:50:44 somebodysysop Exp $
 
 /**
  * @file
@@ -123,7 +123,7 @@ function og_user_roles_admin_settings() 
     '#type' => 'checkbox',
     '#title' => t('Set default basic group (group limited) role for users who join groups?'),
     '#default_value' => variable_get('og_user_roles_assign_basicgrouprole', 0),
-    '#description' => t('Do you wish to automatically assign a specific "basic group role" to <b>every new group subscriber</b> at the time he subscribes to the group? The role is limited to the group that he is subscribed to. This role assignment can be be removed by the groups\' admins'),
+    '#description' => t('Do you wish to automatically assign a specific "basic group role" to <b>every new group subscriber</b> at the time he subscribes to the group? The role is limited to the group that he is subscribed to. This role assignment can be removed by the groups\' admins'),
   );
   $form['og_user_roles_basicgrouprole']['og_user_roles_basicgrouprole_value'] = array(
     '#type' => 'select',
@@ -166,6 +166,26 @@ function og_user_roles_admin_settings() 
     '#description' => t('Select the role you wish to use as the "founder" role.'),
   );
 
+  $form['og_user_roles_admingrouprole'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Default Group Role for new group administrator.'),
+    '#description' => t('Allows you to select a group role to automatically assign to users who are elevated to group administrator. The role is specific to the group(s) in which the user is a group administrator.  That is, the user will only have the privileges of the role in the group he is the administrator for.'),
+    '#collapsible' => TRUE,
+  );
+  $form['og_user_roles_admingrouprole']['og_user_roles_assign_admingrouprole'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Set default group (group limited) administrator role for users who are elevated to group administrator?'),
+    '#default_value' => variable_get('og_user_roles_assign_admingrouprole', 0),
+    '#description' => t('Do you wish to automatically assign a specific "administrator group role" to <b>every new group administrator</b> at the time he is elevated to group administrator status? The role is limited to the group that he is the administrator for. This role assignment can only be removed by removing the user as a group administrator.'),
+  );
+  $form['og_user_roles_admingrouprole']['og_user_roles_admingrouprole_value'] = array(
+    '#type' => 'select',
+    '#title' => t('Role to use as group administrator role'),
+    '#options' => $roles,
+    '#default_value' => variable_get('og_user_roles_admingrouprole_value', 0),
+    '#description' => t('Select the role you wish to use as the "group administrator role" for every new group administrator.'),
+  );
+
   $form['og_user_roles_notify'] = array(
     '#type' => 'fieldset',
     '#title' => t('Default Group Admin Notification for new subscribers.'),
@@ -569,6 +589,13 @@ function og_user_roles_role_remove($gid)
 }
 
 /**
+ * Remove this role from this user in this group.
+ */
+function og_user_roles_role_delete($uid, $rid, $gid) {
+  db_query("DELETE FROM {og_users_roles} WHERE uid = %d AND gid = %d AND rid = %d", $uid, $gid, $rid);
+}
+
+/**
  * Remove og_user_roles variables for a group node that has been deleted.
  */
 function og_user_roles_variable_remove($gid) {
@@ -1133,6 +1160,15 @@ function og_user_roles_og($op, $nid, $ui
           og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
         }
       }
+
+      // --- Modification - 2008-01-10 - as per: http://drupal.org/node/197489
+      // Places all new group administrators into default group administrator role.
+      $admin = $args['is_admin'];
+      if (variable_get('og_user_roles_assign_admingrouprole', 0) == 1 && $admin == 1) {
+        $rid = variable_get('og_user_roles_admingrouprole_value', 0);
+        og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
+      }
+
       $user = user_load(array('uid' => $uid));
       $node = node_load($nid);
 
@@ -1160,6 +1196,20 @@ function og_user_roles_og($op, $nid, $ui
       } // end if
       break;
 
+    case 'user update':
+      // --- Modification - 2008-01-10 - as per: http://drupal.org/node/197489
+      // Places all new group administrators into default group administrator role.
+      $admin = $args['is_admin'];
+      if (variable_get('og_user_roles_assign_admingrouprole', 0) == 1 && $admin == 1) {
+        $rid = variable_get('og_user_roles_admingrouprole_value', 0);
+        og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
+      }
+      if (variable_get('og_user_roles_assign_admingrouprole', 0) == 1 && $admin == 0) {
+        $rid = variable_get('og_user_roles_admingrouprole_value', 0);
+        og_user_roles_role_delete($uid, $rid, $nid); // delete this admin role for this user in this group (if it exists)
+      }
+      break;
+
     case 'user delete':
       // Remove all roles for this user in this group if he is being unsubscribed;
       og_user_roles_role_leave($uid, $nid);
