rsvp_set_invites($attendees, $rid)
rsvp/rsvp.module, line 308
$attendees either an array or a string with line delimited email addresses.
<?php
function rsvp_set_invites($attendees, $rid) {
$emails = array();
// convert to array
$attendees = explode("\r\n", $attendees);
// remove duplicates
$attendees = array_unique($attendees);
foreach ($attendees as $key => $value) {
// strip whitespace
$string = trim($value);
// attempt to deal with the string as a drupal username
// we do this before dealing it as an e-mail to handle users like
// foo@somesite.com
$user = user_load(array('name' => $string));
if ($user === FALSE) {
// attempt to find a system user having this string as an e-mail address
$user = user_load(array('mail' => $string));
if ($user === FALSE) {
// no user found: carry on dealing with the string as an e-mail address
if (strlen($string) && valid_email_address($string)) {
if (!_rsvp_attendee_exists($rid, $string)) {
// if this e-mail is not in the attendee list,
// add it
db_query('INSERT INTO {rsvp_invite} (rid, email, hash, timestamp) VALUES (%d, \'%s\', \'%s\', %d)', $rid, $string, md5($rid . $string . time()), time());
}
else {
// the e-mail is already in the attendee list
$emails['existing'][] = $string;
}
}
else {
// the e-mail is invalid
$emails['invalid'][] = $string;
}
}
}
if ($user !== FALSE) {
// a valid drupal user was found, make sure his/her e-mail isn't already
// in the attendees list
if (!_rsvp_attendee_exists($rid, $user->mail)) {
db_query('INSERT INTO {rsvp_invite} (rid, uid, email, hash, timestamp) VALUES (%d, %d, \'%s\', \'%s\', %d)', $rid, $user->uid, $user->mail, md5($rid . $string . time()), time());
}
else {
// the e-mail is already in the attendee list
$emails['existing'][] = $user->name;
}
}
}
return $emails;
}
?>