Index: og_mandatory_group.module
===================================================================
--- og_mandatory_group.module	(revision 5489)
+++ og_mandatory_group.module	(working copy)
@@ -77,48 +77,50 @@
       // Sloppy modules may try to register an account with uid == 0.
       if (($group = variable_get('og_mandatory_group', 0)) != 0 && $account->uid) {
         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'));
+        // mail the admins only if the administration has not over-ridden and said no
+        if (variable_get('og_mandatory_group_mail', 1)) {
+          $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 (!empty($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.og_register = 1'), variable_get('og_node_types', array('og')));
-          while ($row = db_fetch_object($result)) {
-            if ($edit['og_register'][$row->nid]) {
-              switch ($row->og_selective) {
-                case OG_OPEN:
-                  $groups .= check_plain($row->title) .' '. t('(open group)');
-                  break;
-                case OG_MODERATED:
-                  $groups .= check_plain($row->title) .' '. t('(moderated group)');
-                  break;
-                case OG_INVITE_ONLY:
-                  $groups .= check_plain($row->title) .' '. t('(invite only group)');
-                  break;
-                case OG_CLOSED:
-                  $groups .= check_plain($row->title) .' '. t('(closed group)');
-                  break;
+          $groups = '';
+          if (!empty($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.og_register = 1'), variable_get('og_node_types', array('og')));
+            while ($row = db_fetch_object($result)) {
+              if ($edit['og_register'][$row->nid]) {
+                switch ($row->og_selective) {
+                  case OG_OPEN:
+                    $groups .= check_plain($row->title) .' '. t('(open group)');
+                    break;
+                  case OG_MODERATED:
+                    $groups .= check_plain($row->title) .' '. t('(moderated group)');
+                    break;
+                  case OG_INVITE_ONLY:
+                    $groups .= check_plain($row->title) .' '. t('(invite only group)');
+                    break;
+                  case OG_CLOSED:
+                    $groups .= check_plain($row->title) .' '. t('(closed group)');
+                    break;
+                }
+                $groups .= "\n\t". url("node/$row->nid", array('absolute' => TRUE)) ."\n\n";
               }
-              $groups .= "\n\t". url("node/$row->nid", array('absolute' => 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", array('absolute' => TRUE))));
-            if (strlen($groups)) {
-              $body .= "\n". t('The user also subscribed to the following groups:') ."\n\n". $groups;
+          $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", array('absolute' => 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", array('absolute' => TRUE))));
+              }
+              // array of params with the context so the message will be sent properly
+              $params = array('context' => array('subject' => $subj, 'body' => $body));
+              drupal_mail('og_mandatory_group', 'notify', $row->mail, language_default(), $params, $from);
             }
-            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", array('absolute' => TRUE))));
-            }
-            // array of params with the context so the message will be sent properly
-            $params = array('context' => array('subject' => $subj, 'body' => $body));
-            drupal_mail('og_mandatory_group', 'notify', $row->mail, language_default(), $params, $from);
           }
         }
       }
@@ -178,11 +180,18 @@
     '#default_value' => variable_get('og_mandatory_group', 0),
   );
 
-  $form['og_mandatory_additional_group'] = array(
+  $form['groups']['og_mandatory_additional_group'] = array(
       '#type' => 'checkbox',
       '#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['settings']['og_mandatory_group_mail'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Email administrator when new user joins the site'),
+    '#default_value' => variable_get('og_mandatory_group_mail', 1),
+    '#description' => t('If checked emails will be sent out to the administrator, if not checked emails will not be sent out'),
+  );
   $form['#validate'][] = 'og_mandatory_group_settings_validate';
   return system_settings_form($form);
 }
