308 lines
12 KiB
PHP
308 lines
12 KiB
PHP
<?php
|
|
// $Id: booking.emails.inc,v 0.1 2010/07/21
|
|
|
|
/**
|
|
* Function to send email to registrant after completing registration process
|
|
*
|
|
* @param $nid - the node id relating to the registration node
|
|
* @return nothing
|
|
*/
|
|
function _booking_registration_email($nid, $balance_payment, $manual = false) {
|
|
global $event;
|
|
global $user;
|
|
$language = user_preferred_language($user);
|
|
//$account = $user;
|
|
|
|
//flush cache for this node
|
|
entity_get_controller('node')->resetCache(array($nid));
|
|
|
|
//load the node matching this id
|
|
$node = node_load($nid);
|
|
|
|
watchdog('booking', 'Sending registration email to !first !last', array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname));
|
|
|
|
//waiting list has already been calculated, stored in node
|
|
$waiting_list = $node->booking_status == 2 ? TRUE : FALSE;
|
|
|
|
//calculate the from email address
|
|
$from = t('!event Registrations <!email>', array('!event' => $event->booking_eventname,
|
|
'!email' => variable_get('booking_contact_email', variable_get('site_mail', ini_get('sendmail_from')))
|
|
));
|
|
|
|
//send the registering person an email
|
|
$to = $node->booking_email;
|
|
$body = _booking_registration_email_generate($node, $waiting_list, $balance_payment, $manual);
|
|
if ($balance_payment == TRUE)
|
|
$subject = t('!event Payment Complete', array('!event' => $event->booking_eventname));
|
|
else
|
|
$subject = t('!event Registration', array('!event' => $event->booking_eventname));
|
|
|
|
$params['subject'] = $subject;
|
|
$params['body'] = $body;
|
|
drupal_mail('booking', 'registration_mail', $to, $language, $params, $from);
|
|
drupal_mail('booking', 'registration_mail', 'it@coadcorp.com', $language, $params, $from);
|
|
|
|
//send a notification email if we didn't automatically send one earlier
|
|
if (variable_get('booking_auto_confirm_email', 0) == 1)
|
|
{
|
|
_booking_regn_notifyonly_email($node, $balance_payment);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Function to send notification email only, nothing to the end user
|
|
*
|
|
* @param $node - variable representing the booking node
|
|
* @return nothing
|
|
*/
|
|
function _booking_regn_notifyonly_email($node, $balance_payment)
|
|
{
|
|
global $event;
|
|
global $user;
|
|
$language = user_preferred_language($user);
|
|
|
|
//calculate the from email address
|
|
$from = t('!event Registrations <!email>', array('!event' => $event->booking_eventname,
|
|
'!email' => variable_get('booking_contact_email', variable_get('site_mail', ini_get('sendmail_from')))
|
|
));
|
|
|
|
//just put the registration info in this email to notify the appropriate people
|
|
$to = variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from')));
|
|
|
|
if ($balance_payment == TRUE)
|
|
$params['subject'] = t('Registration Fully Paid: !first !last', array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname));
|
|
else
|
|
$params['subject'] = t('New Registration: !first !last', array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname));
|
|
|
|
$params['body'] = _booking_details_email_summary($node);
|
|
drupal_mail('booking', 'registration_mail_notify', $to, $language, $params, $from);
|
|
}
|
|
|
|
/**
|
|
* Function to generate email text to be sent to registrant after completing registration process
|
|
*
|
|
* @param $node - the registration node
|
|
* @param $booking_count - the number of bookings already made for this event id
|
|
* @param $waiting_list - whether this registration is on on the waiting list
|
|
* @return array containing email text
|
|
*/
|
|
function _booking_registration_email_generate($node, $waiting_list, $balance_payment, $manual) {
|
|
|
|
global $event;
|
|
$tokens = booking_define_personspecific_tokens($node);
|
|
|
|
if ($balance_payment == True)
|
|
{
|
|
$contact_message = token_replace(variable_get('booking_email_regn_complete_text'), $tokens);
|
|
}
|
|
elseif ($waiting_list == False)
|
|
{
|
|
$contact_message = token_replace(variable_get('booking_email_bookedin_text'), $tokens);
|
|
}
|
|
else
|
|
{
|
|
//booking is on the waiting list
|
|
$contact_message = token_replace(variable_get('booking_email_waitinglist_text'), $tokens);
|
|
}
|
|
|
|
//$contact_message .= "\n\n" . t("!details", array('!details' => _booking_details_email_summary($node)));
|
|
return $contact_message;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to generate email to be sent to the registrant to remind them of how much they owe, and include a payment link
|
|
*
|
|
* @param $nid - the registration node
|
|
*/
|
|
function _booking_balance_payment_email($nid)
|
|
{
|
|
global $event;
|
|
global $user;
|
|
$language = user_preferred_language($user);
|
|
|
|
//load the node matching this id
|
|
$node = node_load($nid);
|
|
$tokens = booking_define_personspecific_tokens($node);
|
|
|
|
if ($tokens['payment-required'] <= 0)
|
|
{
|
|
watchdog('booking', "Not sending amount owing email, since this person doesn't owe any money: @info", array('@info' => var_export($node, TRUE)));
|
|
return;
|
|
}
|
|
|
|
//calculate the from email address
|
|
$from = t('!event Registrations <!email>', array('!event' => $event->booking_eventname,
|
|
'!email' => variable_get('booking_contact_email', variable_get('site_mail', ini_get('sendmail_from')))
|
|
));
|
|
|
|
//calculate the remaining parameters
|
|
$to = $node->booking_email;
|
|
$subject = t('!event Payment Required', array('!event' => $event->booking_eventname));
|
|
$params['subject'] = $subject;
|
|
|
|
//retrieve the body of the email
|
|
$params['body'] = token_replace(variable_get('booking_email_paymentoutstanding_text'), $tokens) .
|
|
"\n\n" . t("!details", array('!details' => _booking_details_email_summary($node)));
|
|
|
|
//send the email
|
|
drupal_mail('booking', 'registration_mail_bal_outstanding', $to, $language, $params, $from);
|
|
drupal_mail('booking', 'registration_mail_bal_outstanding', variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from'))),
|
|
$language, $params, $from);
|
|
drupal_mail('booking', 'registration_mail_bal_outstanding', 'it@coadcorp.com', $language, $params, $from);
|
|
}
|
|
|
|
/**
|
|
* Function to generate email to be sent to the registrant based on custom email template configured in text tokens page
|
|
*
|
|
* @param $nid - the registration node
|
|
* @param $email_type - select which custom email template to use
|
|
* @return nothing
|
|
*/
|
|
function _booking_custom_email($nid, $email_type)
|
|
{
|
|
global $event;
|
|
global $user;
|
|
$language = user_preferred_language($user);
|
|
$email_subject_variable = 'booking_email_subject_' . $email_type;
|
|
$email_body_variable = 'booking_email_' . $email_type;
|
|
|
|
//load the node matching this id
|
|
$node = node_load($nid);
|
|
$tokens = booking_define_personspecific_tokens($node);
|
|
|
|
//calculate the from email address
|
|
$from = t('!event Registrations <!email>', array('!event' => $event->booking_eventname,
|
|
'!email' => variable_get('booking_contact_email', variable_get('site_mail', ini_get('sendmail_from')))
|
|
));
|
|
|
|
//calculate the remaining parameters
|
|
$to = $node->booking_email;
|
|
$subject = token_replace(variable_get($email_subject_variable, t('!event', array('!event' => $event->booking_eventname))), $tokens);
|
|
$params['subject'] = $subject;
|
|
|
|
//retrieve the body of the email
|
|
$params['body'] = token_replace(variable_get($email_body_variable), $tokens);
|
|
|
|
//send the email
|
|
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
|
|
drupal_mail('booking', 'booking_email_custom', variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from'))),
|
|
$language, $params, $from);
|
|
drupal_mail('booking', 'booking_email_custom', 'it@coadcorp.com', $language, $params, $from);
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to generate email to be sent to the registrant once they move from the waiting list to the coming list
|
|
*
|
|
* @param $nid - the registration node
|
|
*/
|
|
function _booking_promoted_from_waitinglist_email($nid)
|
|
{
|
|
global $event;
|
|
global $user;
|
|
$language = user_preferred_language($user);
|
|
|
|
//load the node matching this id
|
|
$node = node_load($nid);
|
|
$tokens = booking_define_personspecific_tokens($node);
|
|
|
|
//calculate the from email address
|
|
$from = t('!event Registrations <!email>', array('!event' => $event->booking_eventname,
|
|
'!email' => variable_get('booking_contact_email', variable_get('site_mail', ini_get('sendmail_from')))
|
|
));
|
|
|
|
//calculate the remaining parameters
|
|
$to = $node->booking_email;
|
|
$subject = t('!event Position Available', array('!event' => $event->booking_eventname));
|
|
$params['subject'] = $subject;
|
|
|
|
//retrieve the body of the email
|
|
$params['body'] = token_replace(variable_get($booking_email_waitinglistpromotion), $tokens);
|
|
|
|
//send the email
|
|
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
|
|
drupal_mail('booking', 'booking_email_custom', variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from'))),
|
|
$language, $params, $from);
|
|
drupal_mail('booking', 'booking_email_custom', 'it@coadcorp.com', $language, $params, $from);
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
function _booking_promoted_from_waitinglist_email_old($nid)
|
|
{
|
|
global $event;
|
|
global $user;
|
|
$language = user_preferred_language($user);
|
|
//load the node matching this id
|
|
$node = node_load($nid);
|
|
|
|
//figure out if we're in the right time period for discounted registration rates
|
|
$early = db_query("SELECT booking_earlybird_close FROM {booking_event} where eid = :eid", array(
|
|
':eid' => $event->eid))
|
|
->fetchObject();
|
|
if ($early->booking_earlybird_close > time())
|
|
$amount_owing = _booking_amount_owing($node->nid);
|
|
else
|
|
{
|
|
$amount_owing = _booking_amount_owing($node->nid;
|
|
}
|
|
|
|
//calcalate a new temp id to be configured for this user if required
|
|
if ($node->booking_tempid == '')
|
|
{
|
|
$tempid = _booking_uuidSecure();
|
|
//update the user with this tempid
|
|
db_update('booking_person')
|
|
->fields(array(
|
|
'booking_tempid' => $tempid
|
|
))
|
|
->condition('nid', $node->nid)
|
|
->execute();
|
|
}
|
|
else
|
|
{
|
|
$tempid = $node->booking_tempid;
|
|
}
|
|
//calculate the booking balance URL for this user
|
|
$url = url('balance/' . $tempid, array('absolute' => TRUE));
|
|
|
|
//calculate the from email address
|
|
$from = t('!event Registrations <!email>', array('!event' => $event->booking_eventname,
|
|
'!email' => variable_get('booking_contact_email', variable_get('site_mail', ini_get('sendmail_from')))
|
|
));
|
|
|
|
//calculate the body of the email
|
|
$contact_message[] = t("Dear !firstname,", array('!firstname' => ucwords(trim($node->booking_firstname))));
|
|
$contact_message[] = t("We have some great news for you. A place at !event for you has just become available. ",
|
|
array('!event' => $event->booking_eventname));
|
|
$contact_message[] = t("If you wish to secure your place at !event, please visit !link to make your final payment. " .
|
|
"Our records indicate that you currently have $!amount outstanding (including Paypal transaction fees).",
|
|
array('!amount' => number_format($amount_owing, 2, '.', ''), '!link' => $url, '!event' => $event->booking_eventname));
|
|
$contact_message[] = t("Once we have received your payment, you will be sent an automatic confirmation email thanking you for paying your outstanding fees. " .
|
|
"If you are paying via Paypal's eCheque feature, please be aware that payments take 3-5 working days to clear, and you will not receive the confirmation email until that has occurred.");
|
|
$contact_message[] = t("Please don't hesitate to contact us if you have any queries by replying to this email. We look forward to seeing you (God Willing) at !event!!!", array('!event' => $event->booking_eventname));
|
|
$contact_message[] = t("Love in Jesus,\n!event Registrations Team\n", array('!event' => $event->booking_eventname));
|
|
$contact_message[] = t("________________________________________________________");
|
|
$contact_message[] = t("The following information shows the details you entered when you registered. If any of this information is incorrect, please reply to this email with the corrections as soon as possible.\n________________________________________________________");
|
|
$contact_message[] = t("!details", array('!details' => _booking_details_email_summary($node)));
|
|
|
|
//turn the array into the body of the email
|
|
foreach ($contact_message as $key => $value)
|
|
$contact_message[$key] = wordwrap($value);
|
|
|
|
//calculate the remaining parameters
|
|
$to = $node->booking_email;
|
|
$subject = t('!event Position Available', array('!event' => $event->booking_eventname));
|
|
$params['subject'] = $subject;
|
|
$params['body'] = implode("\n\n", $contact_message);
|
|
//send the email
|
|
drupal_mail('booking', 'registration_mail', $to, $language, $params, $from);
|
|
drupal_mail('booking', 'registration_mail', 'it@coadcorp.com', $language, $params, $from);
|
|
}
|
|
*/
|
|
|