Index: /modules/quota_by_role/quota_by_role.module
===================================================================
--- /modules/quota_by_role/quota_by_role.module (revision 39)
+++ /modules/quota_by_role/quota_by_role.module (revision 40)
@@ -13,5 +13,5 @@
                        <strong>Notes:</strong><ul>
                                <li>When a new role is added, there will be no quota set up for it. You need to come to this settings form to add a new quota.</li>
-                               <li>Quotas are determined based on the weight. Processing starts at the lowest weight and is stopped at the first match. It is a good idea to have groups that admins are in at the lowest weight.</li>
+                               <li>Quotas are determined based on the weight. Processing starts at the lowest weight and is stopped at the group first match. It is a good idea to have groups that admins are in at the lowest weight.</li>
                                <li>User 1 will not be included in quota checks.</li>
 ") .'</p><br />';
@@ -235,22 +235,24 @@
 function _quota_by_role_check_post($user, $table) {
   $overquota = FALSE;
-
-  // Retrieve list of all the roles this user belongs to
-  $user_roles = $user->roles;
+  $breakout = FALSE;
 
   // Retrieve list of all the quota_by_role
   $sql_result_object = db_query("SELECT q.*, r.name FROM {quota_by_role_rules q, role r} WHERE q.rid = r.rid ORDER BY q.weight ASC");
   while($r = db_fetch_object($sql_result_object)) {
-   
-    // Now we need to do a node create count for every role in the quota_by_role array
-    $sql_result_object_2 = _quota_by_role_fetch_count('node', $r->per, $user->uid);
-    $r_2[] = db_fetch_array($sql_result_object_2);  // Count of nodes created
-    $sql_result_object_3 = _quota_by_role_fetch_count('comments', $r->per, $user->uid);
-    $r_3[] = db_fetch_array($sql_result_object_3);  // Count of comments created
-    $total_count = $r_2[0]['cnt'] + $r_3[0]['cnt']; // Add them together
+    
+    // is this user even in the role given?
+    if (in_array($r->name, $user->roles)) {
+      
+      // stop after the first group match.
+      $breakout = TRUE;
+
+      // Now we need to do a node create count for every role in the quota_by_role array
+      $nodes_posted = _quota_by_role_fetch_count('node', $r->per, $user->uid); // Count of nodes created
+      $comments_posted = _quota_by_role_fetch_count('comments', $r->per, $user->uid); // Count of comments created
+      $total_count = $nodes_posted + $comments_posted; // Add them together
        
       // Compare the count of the above query with quota limit
       // If quota exceeded, then print error message and dissallow the post
-      if ($total_count >= $r->limit_to && _quota_by_role_value_in_array($user_roles, $r->name)) { 
+      if ($total_count >= $r->limit_to) { 
 
         switch($r->per) {
@@ -266,5 +268,5 @@
           $message = t('Sorry, but you posting quota has been exceeded. You are unable to create any new content.');
         else
-          $message = t('Sorry, but your posting quota has been exceeded. Please try again in 1 $per.');
+          $message = t('Sorry, but your posting quota has been exceeded. Please try again in 1 @per.', array('@per' => $per));
 
         form_set_error('', $message);
@@ -273,11 +275,9 @@
         $overquota = TRUE;
       }
-      else {
-        // Otherwise the post is allowed
-        // drupal_set_message(t("You are still free to post."));
-      }
- 
+    
+    }
+    
     // No need to continue if we have found a quota limiting this user
-    if ($overquota)
+    if ($breakout)
       break;
   }  
@@ -289,18 +289,7 @@
 function _quota_by_role_fetch_count($table, $per, $uid) {
   switch ($table) {
-    case 'node' : return db_query("SELECT COUNT(*) AS cnt FROM {node t} WHERE t.created >= %d AND t.uid = %d", time() - $per, $uid); break;
-    case 'comments' : return db_query("SELECT COUNT(*) AS cnt FROM {comments t} WHERE t.timestamp >= %d AND t.uid = %d", time() - $per, $uid); break;
-  }
-} 
-
-// This function checks whether $to_check exists in $array
-function _quota_by_role_value_in_array($array, $to_check) {
-
-  foreach ($array as $key => $value) {
-    if ($value == $to_check)
-      return true;
-  }
-
-  return false;
+    case 'node' : return db_result(db_query("SELECT COUNT(*) AS cnt FROM {node t} WHERE t.created >= %d AND t.uid = %d", time() - $per, $uid)); break;
+    case 'comments' : return db_result(db_query("SELECT COUNT(*) AS cnt FROM {comments t} WHERE t.timestamp >= %d AND t.uid = %d", time() - $per, $uid)); break;
+  }
 }
 
