--- og.pages.inc Thu May 28 21:00:21 2009 +++ og.pages.inc Sat May 30 11:44:00 2009 @@ -189,6 +189,10 @@ '#title' => t('Email addresses or usernames'), '#description' => t('Enter up to %max email addresses or usernames. Separate multiple addresses by commas or new lines. Each person will receive an invitation message from you.', array('%max' => $max)) ); + if (og_is_group_admin($node)) { + $form['mails']['#description'] .= t('
Existing users will be added silently, the rest will receive an invitation message from you and be added once they create an account.'); + } + $form['pmessage'] = array( '#type' => 'textarea', '#title' => t('Personal message'), @@ -214,6 +218,10 @@ elseif (in_array($user->mail, $emails)) { form_set_error('mails', t('You may not invite yourself - @self.', array('@self' => $user->mail))); } + elseif (in_array($user->name, $emails)) { + form_set_error('mails', t('You may not invite yourself - @self.', array('@self' => $user->name))); + } + else { $valid_emails = array(); $bad = array(); @@ -253,18 +261,46 @@ '@group' => $node->title, '@description' => $node->og_description, '@site' => variable_get('site_name', 'drupal'), - '!group_url' => url("og/subscribe/$node->nid", array('absolute' => TRUE)), '@body' => $form_state['values']['pmessage'], ); global $user; $from = $user->mail; + $sentmails = 0; foreach ($emails as $mail) { + $variables['!group_url'] = url("og/subscribe/$node->nid", array('absolute' => TRUE)); + if (og_is_group_admin($node)) { + $account = user_load(array('mail' => $mail)); + if ($account && $account->mail) { + og_save_subscription($node->nid, $account->uid, array('is_active' => 1)); + drupal_set_message(t('@name was added to the group and no invitation was sent to them.', array('@name' => $account->name))); + } + else { + $sql = "SELECT COUNT(*) FROM {og_invite} WHERE mail = '%s' AND group_nid = %d"; + $cnt = db_result(db_query($sql, $mail, $node->nid)); + if ($cnt) { + drupal_set_message(t('@email was already on the invitation list for this group, but will be re-invited.', array('@email' => $mail))); + } + else { + $record = array('mail' => $mail, 'group_nid' => $node->nid); + $result = drupal_write_record('og_invite', $record); + } + $variables['!group_url'] = url('user/register', array('absolute' => TRUE)); + drupal_mail('og', 'invite_user', $mail, $GLOBALS['language'], $variables, $from); + $sentmails ++; + } + } + else { drupal_mail('og', 'invite_user', $mail, $GLOBALS['language'], $variables, $from); + $sentmails ++; + } + } + if ($sentmails) { + drupal_set_message(format_plural($sentmails, '1 invitation sent.', '@count invitations sent.')); } - drupal_set_message(format_plural(count($emails), '1 invitation sent.', '@count invitations sent.')); } + function og_subscribe($node, $uid = NULL) { global $user; if (is_null($uid)) { @@ -384,6 +420,7 @@ '#description' => t('Add one or more usernames in order to associate users with this group. Multiple usernames should be separated by a comma.'), '#element_validate' => array('og_add_users_og_names_validate'), ); + $form['og_names']['#description'] .= '
' . t('If you wish to use emails in addition to usernames, invite will accept a mix of both.', array( '@url' => url('og/invite/'. $group_node->nid))); $form['op'] = array('#type' => 'submit', '#value' => t('Add users')); $form['gid'] = array('#type' => 'value', '#value' => $group_node->nid); return $form; --- og.module Tue Jun 09 07:42:46 2009 +++ og.module Tue Jun 09 11:41:47 2009 @@ -1829,6 +1829,7 @@ ); return $form; } + break; case 'insert': if (isset($edit['og_register'])) { foreach (array_keys(array_filter($edit['og_register'])) as $gid) { @@ -1838,6 +1839,16 @@ } } } + $sql = "SELECT group_nid FROM {og_invite} WHERE mail = '%s'"; + $result = db_query($sql, $account->mail); + while ($group = db_fetch_array($result)) { + $gid = $group['group_nid']; + $groupnode = node_load($gid); + og_save_subscription($gid, $account->uid, array('is_active' => 1)); + drupal_set_message(t('You are now a member of the %group.', array('%group' => $groupnode->title))); + } + $sql = "DELETE FROM {og_invite} WHERE mail = '%s'"; + $result = db_query($sql, $account->mail); break; case 'delete': $sql = 'DELETE FROM {og_uid} WHERE uid=%d'; @@ -2083,7 +2094,7 @@ if ($subscription == 'active' || user_access('administer nodes')) { $links = module_invoke_all('og_create_links', $node); // We want to open this up for OG_INVITE_ONLY but we need to handle invitation workflow much better. See http://drupal.org/node/170332 - if ($node->og_selective < OG_INVITE_ONLY) { + if ($node->og_selective < OG_INVITE_ONLY || og_is_group_admin($node)) { $links['invite'] = l(t('Invite friend'), "og/invite/$node->nid"); } $links['subscribers'] = $txt; --- og.install Fri May 15 13:28:02 2009 +++ og.install Sat May 30 11:24:58 2009 @@ -143,6 +143,24 @@ ), 'primary key' => array('nid', 'group_nid'), ); + $schema['og_invite'] = array( + 'description' => 'Pending OG Invitations', + 'fields' => array( + 'mail' => array( + 'type' => 'varchar', + 'length' => 64, + 'not null' => TRUE, + 'description' => "Invited email address.", + ), + 'group_nid' => array( + 'description' => "The group's {node}.nid.", + 'type' => 'int', + 'size' => 'normal', + 'not null' => TRUE, + ), + ), + 'primary key' => array('mail', 'group_nid'), + ); return $schema; } @@ -429,6 +447,31 @@ og_ancestry_dedupe($ret); } + return $ret; +} + +// Add og_invite table to store emails for inviting non-users to groups. +function og_update_6204() { + $ret = array(); + $schema['og_invite'] = array( + 'description' => 'Pending OG Invitations', + 'fields' => array( + 'mail' => array( + 'type' => 'varchar', + 'length' => 64, + 'not null' => TRUE, + 'description' => "Invited email address.", + ), + 'group_nid' => array( + 'description' => "The group's {node}.nid.", + 'type' => 'int', + 'size' => 'normal', + 'not null' => TRUE, + ), + ), + 'primary key' => array('mail', 'group_nid'), + ); + db_create_table($ret, 'og_invite', $schema['og_invite']); return $ret; }