? invite_role.patch
Index: invite.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/invite.install,v
retrieving revision 1.13.2.2
diff -u -p -r1.13.2.2 invite.install
--- invite.install	6 Oct 2008 13:03:08 -0000	1.13.2.2
+++ invite.install	25 Jul 2009 01:19:45 -0000
@@ -362,3 +362,24 @@ function invite_update_202() {
   return $ret;
 }
 
+/**
+ * Change Invitation limit settings from strings to the role ID.
+ */
+function invite_update_203() {
+  $ret = array();
+  foreach (user_roles(0, 'send invitations') as $rid => $role) {
+    $role_no_space = str_replace(' ', '_', $role);
+
+    // variables changed from 'invite_maxnum_'. $role_no_space to 'invite_maxnum_'. $rid
+    $limit = variable_get('invite_maxnum_'. $role_no_space, -2);
+    if ($limit != -2) {
+      variable_set('invite_maxnum_'. $rid, $limit);
+      variable_del('invite_maxnum_'. $role_no_space);
+    }
+  }
+  $ret[] = array(
+    'query' => 'Invitation limit settings have been successfully updated.',
+    'success' => TRUE
+  );
+  return $ret;
+}
Index: invite.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/invite.module,v
retrieving revision 1.25.2.6
diff -u -p -r1.25.2.6 invite.module
--- invite.module	27 Apr 2009 17:24:44 -0000	1.25.2.6
+++ invite.module	25 Jul 2009 01:19:45 -0000
@@ -471,7 +471,7 @@ function _invite_accept($invite, $accoun
  */
 function _invite_escalate_role($account) {
   // Default target role.
-  $roles = array('default');
+  $roles = array('default' => 'default');
 
   // Add roles of inviter.
   $inviter_uid = db_result(db_query("SELECT uid FROM {invite} WHERE invitee = %d", $account->uid));
@@ -481,9 +481,8 @@ function _invite_escalate_role($account)
 
   // Map to configured target roles.
   $targets = array();
-  foreach ($roles as $role) {
-    $role_no_space = str_replace(' ', '_', $role);
-    $target = variable_get('invite_target_role_'. $role_no_space, DRUPAL_AUTHENTICATED_RID);
+  foreach ($roles as $rid => $role) {
+    $target = variable_get('invite_target_role_'. $rid, DRUPAL_AUTHENTICATED_RID);
     if ($target != DRUPAL_AUTHENTICATED_RID) {
       $targets[$target] = $target;
     }
@@ -658,10 +657,9 @@ function invite_get_role_limit($account)
   }
 
   $role_limit = 0;
-  foreach (user_roles(0, 'send invitations') as $role) {
-    $role_no_space = str_replace(' ', '_', $role);
-    if (in_array($role, $account->roles)) {
-      $role_max = variable_get('invite_maxnum_'. $role_no_space, INVITE_UNLIMITED);
+  foreach (user_roles(0, 'send invitations') as $rid => $role) {
+    if (array_key_exists($rid, $account->roles)) {
+      $role_max = variable_get('invite_maxnum_'. $rid, INVITE_UNLIMITED);
       if ($role_max == INVITE_UNLIMITED) {
         return INVITE_UNLIMITED;
       }
Index: invite_admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/invite_admin.inc,v
retrieving revision 1.3.2.2
diff -u -p -r1.3.2.2 invite_admin.inc
--- invite_admin.inc	19 Apr 2009 21:26:01 -0000	1.3.2.2
+++ invite_admin.inc	25 Jul 2009 01:19:45 -0000
@@ -50,26 +50,25 @@ function invite_settings() {
     '#collapsed' => TRUE,
   );
 
-  foreach ($roles as $role) {
-    $role_no_space = str_replace(' ', '_', $role);
-    $form['role'][$role_no_space] = array(
+  foreach ($roles as $rid => $role) {
+    $form['role'][$rid] = array(
       '#type' => 'fieldset',
       '#title' => t('@role settings', array('@role' => drupal_ucfirst($role))),
       '#collapsible' => TRUE,
       '#collapsed' => TRUE,
     );
-    $form['role'][$role_no_space]['invite_target_role_'. $role_no_space] = array(
+    $form['role'][$rid]['invite_target_role_'. $rid] = array(
       '#type' => 'select',
       '#title' => t('Target role'),
-      '#default_value' => variable_get('invite_target_role_'. $role_no_space, DRUPAL_AUTHENTICATED_RID),
+      '#default_value' => variable_get('invite_target_role_'. $rid, DRUPAL_AUTHENTICATED_RID),
       '#options' => $target_roles,
       '#description' => t('You may choose to add invited users to another role (in addition to the default role set in the general section) when they have been invited by a member of %role.', array('%role' => $role)),
       '#required' => TRUE,
     );
-    $form['role'][$role_no_space]['invite_maxnum_'. $role_no_space] = array(
+    $form['role'][$rid]['invite_maxnum_'. $rid] = array(
       '#type' => 'select',
       '#title' => t('Invitation limit'),
-      '#default_value' => variable_get('invite_maxnum_'. $role_no_space, INVITE_UNLIMITED),
+      '#default_value' => variable_get('invite_maxnum_'. $rid, INVITE_UNLIMITED),
       '#options' => array(5 => 5, 10 => 10, 20 => 20, 50 => 50, 100 => 100, 500 => 500, 1000 => 1000, INVITE_UNLIMITED => t('unlimited')),
       '#description' => t('Allows to limit the total number of invitations members of %role can send.', array('%role' => $role)),
       '#multiple' => FALSE,
