? .svn
? og_mandatory_group_email.patch
Index: og_mandatory_group.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og_mandatory_group/og_mandatory_group.module,v
retrieving revision 1.4.2.3
diff -u -p -r1.4.2.3 og_mandatory_group.module
--- og_mandatory_group.module	24 Oct 2006 00:39:49 -0000	1.4.2.3
+++ og_mandatory_group.module	16 Mar 2007 12:41:01 -0000
@@ -78,18 +78,32 @@ 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' => check_plain($node->title), '%name' => check_plain($account->name), '%site' => variable_get('site_name', 'drupal')));
-        $from = variable_get('site_mail', ini_get('sendmail_from'));
-        $headers = "From: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $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' => check_plain($node->title), '%name' => check_plain($account->name), '%site' => variable_get('site_name', 'drupal')));
+  $from = variable_get('site_mail', ini_get('sendmail_from'));
+  $headers = "From: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $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;
@@ -102,27 +116,24 @@ 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)));
-            }
-            user_mail($row->mail, $subj, $body, $headers);
-          }
         }
+        $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)));
+      }
+      user_mail($row->mail, $subj, $body, $headers);
+    }
   }
 }
 
@@ -159,6 +170,13 @@ 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_email'] = array(
+      '#title' => t('Send an email to administrators when a new user joins the site'),
+      '#type' => 'checkbox',
+      '#default_value' => variable_get('og_mandatory_group_email', 1),
+  );
+
   $form['#validate'] = array('og_mandatory_group_settings_validate' => array());
   return $form;
 }
