aboutsummaryrefslogtreecommitdiff
path: root/mod/invitefriends/actions/invite.php
diff options
context:
space:
mode:
Diffstat (limited to 'mod/invitefriends/actions/invite.php')
-rw-r--r--mod/invitefriends/actions/invite.php24
1 files changed, 21 insertions, 3 deletions
diff --git a/mod/invitefriends/actions/invite.php b/mod/invitefriends/actions/invite.php
index abc212bea..9334860a7 100644
--- a/mod/invitefriends/actions/invite.php
+++ b/mod/invitefriends/actions/invite.php
@@ -19,7 +19,7 @@ if (strlen($emails) > 0) {
}
if (!is_array($emails) || count($emails) == 0) {
- register_error(elgg_echo('invitefriends:failure'));
+ register_error(elgg_echo('invitefriends:noemails'));
forward($_SERVER['HTTP_REFERER']);
}
@@ -27,7 +27,9 @@ $current_user = get_loggedin_user();
$error = FALSE;
$bad_emails = array();
-foreach($emails as $email) {
+$already_members = array();
+$sent_total = 0;
+foreach ($emails as $email) {
$email = trim($email);
if (empty($email)) {
@@ -41,6 +43,12 @@ foreach($emails as $email) {
continue;
}
+ if (get_user_by_email($email)) {
+ $error = TRUE;
+ $already_members[] = $email;
+ continue;
+ }
+
$link = $CONFIG->wwwroot . 'pg/register?friend_guid=' . $current_user->guid . '&invitecode=' . generate_invite_code($current_user->username);
$message = sprintf(elgg_echo('invitefriends:email'),
$CONFIG->site->name,
@@ -60,10 +68,20 @@ foreach($emails as $email) {
}
elgg_send_email($from, $email, $subject, $message);
+ $sent_total++;
}
if ($error) {
- register_error(sprintf(elgg_echo('invitefriends:email_error'), implode(', ', $bad_emails)));
+ register_error(sprintf(elgg_echo('invitefriends:invitations_sent'), $sent_total));
+
+ if (count($bad_emails) > 0) {
+ register_error(sprintf(elgg_echo('invitefriends:email_error'), implode(', ', $bad_emails)));
+ }
+
+ if (count($already_members) > 0) {
+ register_error(sprintf(elgg_echo('invitefriends:already_members'), implode(', ', $already_members)));
+ }
+
} else {
system_message(elgg_echo('invitefriends:success'));
}