? invite-role_ids.patch
? 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 02:40:36 -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 02:40:36 -0000
@@ -470,20 +470,19 @@ function _invite_accept($invite, $accoun
  *   The user object of the invitee.
  */
 function _invite_escalate_role($account) {
-  // Default target role.
-  $roles = array('default');
+  // Add a dummy entry to retrieve the default target role setting.
+  $roles = array('default' => 'default');
 
   // Add roles of inviter.
   $inviter_uid = db_result(db_query("SELECT uid FROM {invite} WHERE invitee = %d", $account->uid));
   if ($inviter_uid && $inviter = user_load(array('uid' => $inviter_uid))) {
-    $roles = array_merge($roles, array_intersect($inviter->roles, user_roles(0, 'send invitations')));
+    $roles = array_merge($roles, array_intersect($inviter->roles, user_roles(FALSE, 'send invitations')));
   }
 
   // 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;
     }
@@ -629,7 +628,6 @@ function invite_get_remaining_invites($a
   }
   else {
     $remaining = invite_get_role_limit($account);
-
     if ($remaining > 0) {
       // Legacy support.
       $sent = db_result(db_query("SELECT COUNT(*) FROM {invite} WHERE uid = %d", $account->uid));
@@ -658,10 +656,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(FALSE, '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 02:40:37 -0000
@@ -10,11 +10,11 @@
  * Menu callback; display invite settings form.
  */
 function invite_settings() {
-  $roles = user_roles(0, 'send invitations');
+  $roles = user_roles(FALSE, 'send invitations');
   if (count($roles) == 0) {
     drupal_set_message(t('Please enable the <em>send invitations</em> permission for at least one role. This can be done on the <a href="!permissions-url">Permissions page</a>.', array('!permissions-url' => url('admin/user/permissions'))));
   }
-  $target_roles = user_roles(1);
+  $target_roles = user_roles(TRUE);
 
   // General settings.
   $form['general'] = array(
@@ -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,
