Index: og_mandatory_group.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og_mandatory_group/og_mandatory_group.module,v
retrieving revision 1.9
diff -u -F^f -r1.9 og_mandatory_group.module
--- og_mandatory_group.module	28 Oct 2006 01:55:59 -0000	1.9
+++ og_mandatory_group.module	28 Apr 2007 22:48:09 -0000
@@ -73,17 +73,30 @@ function og_mandatory_group_user($op, &$
     case 'insert':
       if (($group = variable_get('og_mandatory_group', 0)) != 0) {
         og_save_subscription($group, $account->uid, array('is_active' => 1));
-        // mail the admins
-        $node = node_load($group);
-        $subj = t("'@name' joined @site and was assigned to group '@group'.", array('@group' => $node->title, '@name' => $account->name, '@site' => variable_get('site_name', 'drupal')));
-        $from = variable_get('site_mail', ini_get('sendmail_from'));
-
-        $groups = '';
-        if ($edit['og_register']) {
-          $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, o.* FROM {node} n INNER JOIN {og} o ON n.nid = o.nid WHERE n.type IN ('. str_pad('', count(variable_get('og_node_types', array('og'))) * 5 - 1, "'%s',") .') AND n.status = 1 AND o.register = 1'), variable_get('og_node_types', array('og')));
-          while ($row = db_fetch_object($result)) {
-            if ($edit['og_register'][$row->nid]) {
-              switch ($row->selective) {
+        // Notify admins by email if requested
+        if (variable_get('og_mandatory_group_mail', 1)) {
+          og_mandatory_group_mail($group, $edit, $account);
+        }
+      }
+      break;
+  }
+}
+
+/**
+ * Notify admins by email if a new user being assigned to groups
+ * 
+ */
+function og_mandatory_group_mail($group, $edit, $account) {
+  $node = node_load($group);
+  $subj = t("'@name' joined @site and was assigned to group '@group'.", array('@group' => $node->title, '@name' => $account->name, '@site' => variable_get('site_name', 'drupal')));
+  $from = variable_get('site_mail', ini_get('sendmail_from'));
+
+  $groups = '';
+  if ($edit['og_register']) {
+    $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, o.* FROM {node} n INNER JOIN {og} o ON n.nid = o.nid WHERE n.type IN ('. str_pad('', count(variable_get('og_node_types', array('og'))) * 5 - 1, "'%s',") .') AND n.status = 1 AND o.register = 1'), variable_get('og_node_types', array('og')));
+    while ($row = db_fetch_object($result)) {
+      if ($edit['og_register'][$row->nid]) {
+        switch ($row->selective) {
           case OG_OPEN:
             $groups .= check_plain($row->title) .' '. t('(open group)');
             break;
@@ -96,30 +109,28 @@ function og_mandatory_group_user($op, &$
           case OG_CLOSED:
             $groups .= check_plain($row->title) .' '. t('(closed group)');
             break;
-              }
-              $groups .= "\n\t". url("node/$row->nid", NULL, NULL, TRUE) ."\n\n";
-            }
-          }
-        }
-        $sql = og_list_users_sql(1, 1);
-        $result = db_query($sql, $group);
-        while ($row = db_fetch_object($result)) {
-          if ($row->mail) {
-            $body = t('You may manage subscribers at @url', array('@url' => url("og/users/$node->nid", NULL, NULL, TRUE)));
-            if (strlen($groups)) {
-              $body .= "\n". t('The user also subscribed to the following groups:') ."\n\n". $groups;
-            }
-            if (user_access('administer users', user_load(array('uid' => $row->uid)))) {
-              $body .= "\n". t('You may manage this user at @url', array('@url' => url("user/$account->uid/edit", NULL, NULL, TRUE)));
-            }
-            drupal_mail('og_mandatory_group_register', $row->mail, $subj, $body, $from);
-          }
         }
+
+        $groups .= "\n\t". url("node/$row->nid", NULL, NULL, TRUE) ."\n\n";
       }
-      break;
+    }
   }
-}
 
+  $sql = og_list_users_sql(1, 1);
+  $result = db_query($sql, $group);
+  while ($row = db_fetch_object($result)) {
+    if ($row->mail) {
+      $body = t('You may manage subscribers at @url', array('@url' => url("og/users/$node->nid", NULL, NULL, TRUE)));
+      if (strlen($groups)) {
+        $body .= "\n". t('The user also subscribed to the following groups:') ."\n\n". $groups;
+      }
+      if (user_access('administer users', user_load(array('uid' => $row->uid)))) {
+        $body .= "\n". t('You may manage this user at @url', array('@url' => url("user/$account->uid/edit", NULL, NULL, TRUE)));
+      }
+      drupal_mail('og_mandatory_group_register', $row->mail, $subj, $body, $from);
+    }
+  }
+}
 
 /**
  * Implementation of hook_menu
@@ -175,6 +186,14 @@ function og_mandatory_group_settings() {
       '#title' => t('Require new users to join at least one group in addition to any mandatory group'),
       '#default_value' => variable_get('og_mandatory_additional_group', FALSE),
   );
+
+  $form['og_mandatory_group_mail'] = array(
+      '#title' => t('Email mandatory group managers'),
+      '#type' => 'checkbox',
+      '#default_value' => variable_get('og_mandatory_group_mail', 1),
+      '#description' => t("Should email be sent to the mandatory group's managers when a new user joins the site?"),
+  );
+  
   $form['#validate'] = array('og_mandatory_group_settings_validate' => array());
   return system_settings_form($form);
 }
