994 lines
40 KiB
PHP
994 lines
40 KiB
PHP
<?php
|
|
|
|
function booking_manual_email($preselected = NULL)
|
|
{
|
|
global $event;
|
|
//see http://www.jaypan.com/blog/themeing-drupal-7-forms-tables-checkboxes-or-radios
|
|
$form = array();
|
|
$options = array();
|
|
$values = array();
|
|
$group_text = "";
|
|
$prefix = t("<p>Send a manual email to people registered for this event.</p>");
|
|
$email_options_array = array();
|
|
$email_options_array['NULL'] = "---";
|
|
$email_options_array['registration'] = 'Registration Successful Email';
|
|
$email_options_array['balance'] = 'Balance Outstanding Email';
|
|
$email_options_array['complete'] = 'Payment Complete Email';
|
|
$email_options_array['withdrawal'] = 'Withdrawal Processed Email';
|
|
$email_options_array['missedpayment'] = 'Missed Payment Email';
|
|
$email_options_array['travelrequired'] = 'Travel Form Required Email';
|
|
$email_options_array['travelcomplete'] = 'Travel Form Complete Email';
|
|
|
|
//add in the custom email types
|
|
for ($i = 1; $i <= variable_get('booking_custom_email_count','5'); $i++)
|
|
{
|
|
$email_options_array['custom' . $i] = variable_get('booking_email_subject_custom' . $i, $event->booking_eventname . ' custom ' . $i);
|
|
}
|
|
|
|
$form['#attached']['css'] = array(
|
|
drupal_get_path('module', 'booking') . '/booking.css',
|
|
);
|
|
|
|
$form['email-type'] = array(
|
|
'#type' => 'select',
|
|
'#title' => t('Email Type'),
|
|
'#required' => TRUE,
|
|
'#default_value' => 'NULL',
|
|
'#options' => $email_options_array,
|
|
);
|
|
|
|
//can't get ajax callback to return a working tableselect
|
|
/*
|
|
$form['select-type'] = array(
|
|
'#type' => 'select',
|
|
'#title' => t('Pre-Select People'),
|
|
'#options' => array("---" => "---", "Unpaid" => "Unpaid", "Waiting List" => "Waiting List"),
|
|
'#default_value' => "---",
|
|
'#ajax' => array(
|
|
'callback' => '_booking_manual_email_selecttype_ajax_callback',
|
|
'wrapper' => 'manual-email-attendees-items',
|
|
'method' => 'replace',
|
|
'event' => 'change',
|
|
),
|
|
);
|
|
*/
|
|
$header = array(
|
|
'booking_nid' => array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'),
|
|
'booking_name' => array('data' => t('Name'), 'field' => 'booking_lastname'),
|
|
'booking_gender' => array('data' => t('Gender'), 'field' => 'booking_gender'),
|
|
'booking_email' => array('data' => t('Email'), 'field' => 'booking_email'),
|
|
'booking_state' => array('data' => t('State'), 'field' => 'booking_state'),
|
|
'booking_status' => array('data' => t('Status'), 'field' => 'booking_status'),
|
|
'amount_paid' => array('data' => t('Payment To Date'), 'field' => 'booking_amount_paid'),
|
|
'amount_reqd' => array('data' => t('Total Payment Required'), 'field' => 'booking_total_pay_reqd'),
|
|
'booking_fully_paid' => array('data' => t('Fully paid?'), 'field' => 'booking_payment_complete'),
|
|
'welfare_required' => array('data' => t('Welfare Required?'), 'field' => 'booking_welfare_required'),
|
|
'travel_form' => array('data' => t('Travel Submitted?'), 'field' => 'tid'),
|
|
);
|
|
|
|
if (variable_get('booking_enable_studygroups', 0) == 1)
|
|
{
|
|
//select entries from the study groups mapping table
|
|
$query = db_select('booking_studygroup_mapping', 'm');
|
|
$query->join('booking_studygroup_list', 's', 's.sid = m.booking_studygroup_id');
|
|
$query->condition('m.booking_eventid', $event->eid, '=');
|
|
$query->fields('m')->fields('s', array('booking_studygroup_descrip'));
|
|
$group_mapping = $query->execute()->fetchAllAssoc('sid');
|
|
//add a column to the table header
|
|
$header['group_roles'] = array('data' => t('Group Role'));
|
|
}
|
|
|
|
$query = db_select('booking_person', 'p');
|
|
$query->join('booking_price', 'pr', 'pr.pid = p.booking_payment_id');
|
|
$query->leftJoin('booking_travel', 't', 'p.nid = t.booking_person_nid');
|
|
|
|
$query->fields('p')
|
|
->fields('pr', array('booking_price', 'booking_late_price'))
|
|
->fields('t')
|
|
->condition('p.booking_eventid', $event->eid, '=');
|
|
|
|
$table_sort = $query->extend('TableSort')->orderbyHeader($header);
|
|
$result = $table_sort->execute();
|
|
|
|
foreach($result as $data)
|
|
{
|
|
$group_text = "";
|
|
$class = $data->booking_welfare_required == 'Y' ? "welfare-row" : "normal-row";
|
|
$options[$data->nid] = array (
|
|
'booking_nid' => l(t('!id', array('!id' => $data->nid)), t('node/!id', array('!id' => $data->nid))),
|
|
'booking_name' => $data->booking_firstname . " " . $data->booking_lastname,
|
|
'booking_gender' => $data->booking_gender == 'M' ? 'Male' : 'Female',
|
|
'booking_email' => $data->booking_email,
|
|
'booking_state' => $data->booking_state,
|
|
'booking_status' => _booking_status_generate($data->booking_status),
|
|
'amount_paid' => $data->booking_amount_paid,
|
|
'amount_reqd' => $data->booking_total_pay_reqd,
|
|
'booking_fully_paid' => $data->booking_payment_complete == 'Y' ? 'Yes' : 'No',
|
|
'welfare_required' => $data->booking_welfare_required == 'Y' ? 'Yes' : 'No',
|
|
'travel_form' => $data->tid > 0 ? 'Yes' : 'No',
|
|
'#attributes' => array('class' => array($class)),
|
|
);
|
|
|
|
if (variable_get('booking_enable_studygroups', 0) == 1) {
|
|
foreach ($group_mapping as $group) {
|
|
$role = $group->booking_studygroup_role;
|
|
if ($group->booking_node_id == $data->nid && $role > 0) {
|
|
$text = _booking_studygroup_role_lookup($role);
|
|
$group_text .= "<b>" . $text . "</b> for " . $group->booking_studygroup_descrip . " #" . $group->booking_session_id . "; ";
|
|
}
|
|
}
|
|
$options[$data->nid]['group_roles'] = $group_text;
|
|
}
|
|
|
|
if ($preselected == 'unpaid') {
|
|
$values[$data->nid] = ($data->booking_payment_complete == 'Y' || $data->booking_status != 1) ? FALSE : TRUE;
|
|
}
|
|
}
|
|
|
|
$form['table'] = array (
|
|
'#type' => 'tableselect',
|
|
//'#multiple' => TRUE,
|
|
'#header' => $header,
|
|
'#options' => $options,
|
|
'#default_value' => $values,
|
|
'#empty' => t('No attendees found.'),
|
|
'#attributes' => array('id' => 'sort-table'),
|
|
'#prefix' => '<div id="manual-email-attendees-items">',
|
|
'#suffix' => '</div>',
|
|
);
|
|
|
|
watchdog('booking_debug', "<pre>Manual email form table\n@info</pre>", array('@info' => print_r( $form['table'], true)));
|
|
|
|
$form['submit'] = array (
|
|
'#type' => 'submit',
|
|
'#value' => t('Send Email'),
|
|
);
|
|
|
|
return array (
|
|
'first_para' => array (
|
|
'#type' => 'markup',
|
|
'#markup' => $prefix,
|
|
),
|
|
'form' => $form,
|
|
);
|
|
}
|
|
|
|
function _booking_manual_email_generate_options() {
|
|
global $event;
|
|
$form = array ();
|
|
$options = array ();
|
|
|
|
if (variable_get('booking_enable_studygroups', 0) == 1)
|
|
{
|
|
//select entries from the study groups mapping table
|
|
$query = db_select('booking_studygroup_mapping', 'm');
|
|
$query->join('booking_studygroup_list', 's', 's.sid = m.booking_studygroup_id');
|
|
$query->condition('m.booking_eventid', $event->eid, '=');
|
|
$query->fields('m')->fields('s', array('booking_studygroup_descrip'));
|
|
$group_mapping = $query->execute()->fetchAllAssoc('sid');
|
|
//add a column to the table header
|
|
$header['group_roles'] = array('data' => t('Group Role'));
|
|
}
|
|
|
|
$query = db_select('booking_person', 'p');
|
|
$query->join('booking_price', 'pr', 'pr.pid = p.booking_payment_id');
|
|
$query->leftJoin('booking_travel', 't', 'p.nid = t.booking_person_nid');
|
|
|
|
$query->fields('p')
|
|
->fields('pr', array('booking_price', 'booking_late_price'))
|
|
->fields('t')
|
|
->condition('p.booking_eventid', $event->eid, '=');
|
|
|
|
$table_sort = $query->extend('TableSort')->orderbyHeader($header);
|
|
$result = $table_sort->execute();
|
|
|
|
foreach($result as $data)
|
|
{
|
|
$group_text = "";
|
|
$class = $data->booking_welfare_required == 'Y' ? "welfare-row" : "normal-row";
|
|
$options[$data->nid] = array (
|
|
'booking_nid' => l(t('!id', array('!id' => $data->nid)), t('node/!id', array('!id' => $data->nid))),
|
|
'booking_name' => $data->booking_firstname . " " . $data->booking_lastname,
|
|
'booking_gender' => $data->booking_gender == 'M' ? 'Male' : 'Female',
|
|
'booking_email' => $data->booking_email,
|
|
'booking_state' => $data->booking_state,
|
|
'booking_status' => _booking_status_generate($data->booking_status),
|
|
'amount_paid' => $data->booking_amount_paid,
|
|
'amount_reqd' => $data->booking_total_pay_reqd,
|
|
'booking_fully_paid' => $data->booking_payment_complete == 'Y' ? 'Yes' : 'No',
|
|
'welfare_required' => $data->booking_welfare_required == 'Y' ? 'Yes' : 'No',
|
|
'travel_form' => $data->tid > 0 ? 'Yes' : 'No',
|
|
'#attributes' => array('class' => array($class)),
|
|
);
|
|
|
|
if (variable_get('booking_enable_studygroups', 0) == 1) {
|
|
foreach ($group_mapping as $group) {
|
|
$role = $group->booking_studygroup_role;
|
|
if ($group->booking_node_id == $data->nid && $role > 0) {
|
|
$text = _booking_studygroup_role_lookup($role);
|
|
$group_text .= "<b>" . $text . "</b> for " . $group->booking_studygroup_descrip . " #" . $group->booking_session_id . "; ";
|
|
}
|
|
}
|
|
$options[$data->nid]['group_roles'] = $group_text;
|
|
}
|
|
|
|
//$values[$data->nid] = ($data->booking_payment_complete == 'Y' || $data->booking_status != 1) ? FALSE : TRUE;
|
|
}
|
|
|
|
return $options;
|
|
/*
|
|
return array (
|
|
'#type' => 'tableselect',
|
|
'#header' => $header,
|
|
'#options' => $options,
|
|
'#default_value' => $values,
|
|
'#empty' => t('No attendees found.'),
|
|
'#attributes' => array('id' => 'sort-table'),
|
|
'#prefix' => '<div id="manual-email-attendees-items">',
|
|
'#suffix' => '</div>',
|
|
);
|
|
*/
|
|
}
|
|
|
|
function _booking_manual_email_selecttype_ajax_callback($form, &$form_state) {
|
|
|
|
|
|
$select_type = $form_state['values']['select-type'];
|
|
$new_default_values = array();
|
|
$options = _booking_manual_email_generate_options();
|
|
$header = array(
|
|
'booking_nid' => array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'),
|
|
'booking_name' => array('data' => t('Name'), 'field' => 'booking_lastname'),
|
|
'booking_gender' => array('data' => t('Gender'), 'field' => 'booking_gender'),
|
|
'booking_email' => array('data' => t('Email'), 'field' => 'booking_email'),
|
|
'booking_state' => array('data' => t('State'), 'field' => 'booking_state'),
|
|
'booking_status' => array('data' => t('Status'), 'field' => 'booking_status'),
|
|
'amount_paid' => array('data' => t('Payment To Date'), 'field' => 'booking_amount_paid'),
|
|
'amount_reqd' => array('data' => t('Total Payment Required'), 'field' => 'booking_total_pay_reqd'),
|
|
'booking_fully_paid' => array('data' => t('Fully paid?'), 'field' => 'booking_payment_complete'),
|
|
'welfare_required' => array('data' => t('Welfare Required?'), 'field' => 'booking_welfare_required'),
|
|
'travel_form' => array('data' => t('Travel Submitted?'), 'field' => 'tid'),
|
|
);
|
|
|
|
// generate new default values
|
|
// @todo use a function for this
|
|
if ($select_type == "Unpaid") {
|
|
$new_default_values = array("1814" => TRUE);
|
|
} else {
|
|
$new_default_values = array("1815" => TRUE);
|
|
}
|
|
|
|
//unset($form['table']);
|
|
|
|
$form['new']['table'] = array (
|
|
'#type' => 'tableselect',
|
|
'#multiple' => TRUE,
|
|
'#header' => $header,
|
|
'#options' => $options,
|
|
'#default_value' => $new_default_values,
|
|
'#empty' => t('No attendees found.'),
|
|
'#attributes' => array('id' => 'sort-table'),
|
|
'#prefix' => '<div id="manual-email-attendees-items">',
|
|
'#suffix' => '</div>',
|
|
'#value' =>$new_default_values,
|
|
);
|
|
|
|
// update cached options for tableselect
|
|
$cached_form = form_get_cache($form['#build_id'], $form_state);
|
|
$cached_form['table'] = $form['new']['table'];
|
|
form_set_cache($form['#build_id'], $cached_form, $form_state);
|
|
/*
|
|
$form['table']['#options'] = $options;
|
|
$form['table']['#header'] = $header;
|
|
$form['table']['#default_value'] = $new_default_values;
|
|
$form['table']['#value'] = $new_default_values;
|
|
*/
|
|
watchdog('booking_debug', "<pre>Manual email new form table\n@info</pre>", array('@info' => print_r( $form['new']['table'], true)));
|
|
return form_process_tableselect($form['new']['table']);
|
|
|
|
$form['table'] = array (
|
|
'#type' => 'tableselect',
|
|
'#multiple' => TRUE,
|
|
'#header' => $header,
|
|
'#options' => $options,
|
|
'#value' => $new_default_values,
|
|
'#default_value' => $new_default_values,
|
|
'#empty' => t('No attendees found.'),
|
|
'#attributes' => array('id' => 'sort-table'),
|
|
'#prefix' => '<div id="manual-email-attendees-items">',
|
|
'#suffix' => '</div>',
|
|
);
|
|
watchdog('booking_debug', "<pre>Manual email new form table before\n@info</pre>", array('@info' => print_r( $form['table'], true)));
|
|
//$form['table']['#default_value'] = $new_default_values;
|
|
$form['table'] = form_process_tableselect($form['table']);
|
|
//$form['table']['#default_value'] = $new_default_values;
|
|
watchdog('booking_debug', "<pre>Manual email new form table after\n@info</pre>", array('@info' => print_r( $form['table'], true)));
|
|
return $form['table'];
|
|
|
|
|
|
//$courseid = $form_state['values']['courseid'];
|
|
//$scheduleid = $form_state['values']['scheduleid'];
|
|
|
|
//$checkboxes = $form_state['values']['table'];
|
|
$select_type = $form_state['values']['select-type'];
|
|
$new_default_values = array();
|
|
|
|
$options = _booking_manual_email_generate_options();
|
|
$header = array(
|
|
'booking_nid' => array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'),
|
|
'booking_name' => array('data' => t('Name'), 'field' => 'booking_lastname'),
|
|
'booking_gender' => array('data' => t('Gender'), 'field' => 'booking_gender'),
|
|
'booking_email' => array('data' => t('Email'), 'field' => 'booking_email'),
|
|
'booking_state' => array('data' => t('State'), 'field' => 'booking_state'),
|
|
'booking_status' => array('data' => t('Status'), 'field' => 'booking_status'),
|
|
'amount_paid' => array('data' => t('Payment To Date'), 'field' => 'booking_amount_paid'),
|
|
'amount_reqd' => array('data' => t('Total Payment Required'), 'field' => 'booking_total_pay_reqd'),
|
|
'booking_fully_paid' => array('data' => t('Fully paid?'), 'field' => 'booking_payment_complete'),
|
|
'welfare_required' => array('data' => t('Welfare Required?'), 'field' => 'booking_welfare_required'),
|
|
'travel_form' => array('data' => t('Travel Submitted?'), 'field' => 'tid'),
|
|
);
|
|
|
|
// generate new default values
|
|
// @todo use a function for this
|
|
if ($select_type == "Unpaid") {
|
|
$new_default_values = array("1814" => TRUE);
|
|
} else {
|
|
$new_default_values = array("1815" => TRUE);
|
|
}
|
|
/*
|
|
// update cached options for tableselect
|
|
$cached_form = form_get_cache($form['#build_id'], $form_state);
|
|
$cached_form['table']['#options'] = $options;
|
|
form_set_cache($form['#build_id'], $cached_form, $form_state);
|
|
|
|
// remove radios from tableselect
|
|
$form['new']['table']['#options'] = $options;
|
|
foreach (element_children($form['table']) as $key) {
|
|
if (is_numeric($key)) {
|
|
unset($form['table'][$key]);
|
|
}
|
|
}
|
|
|
|
// add new radios to tableselect
|
|
form_builder($form['#form_id'], $form['table'], $form_state);
|
|
// remove current value
|
|
unset($form['table']['#default_value']);
|
|
unset($form['table']['#value']);
|
|
watchdog('booking_debug', "<pre>Manual email new form table\n@info</pre>", array('@info' => print_r( $form['table'], true)));
|
|
// update the tableselect
|
|
$commands = array();
|
|
$commands[] = ajax_command_replace('#manual-email-attendees-items', drupal_render($form['table']));
|
|
return array('#type' => 'ajax', '#commands' => $commands);
|
|
*/
|
|
// update cached options for tableselect
|
|
//$cached_form = form_get_cache($form['#build_id'], $form_state);
|
|
//watchdog('booking_debug', "<pre>Manual email cached form for tableselect\n@info</pre>", array('@info' => print_r( $cached_form['table'], true)));
|
|
|
|
//unset old tableselect
|
|
unset($form['table']);
|
|
|
|
// configure new tableselect based on old table select
|
|
$form['table'] = array (
|
|
'#type' => 'tableselect',
|
|
'#header' => $header,
|
|
'#options' => $options,
|
|
//'#default_value' => $new_default_values,
|
|
'#empty' => t('No attendees found.'),
|
|
'#attributes' => array('id' => 'sort-table'),
|
|
'#prefix' => '<div id="manual-email-attendees-items">',
|
|
'#suffix' => '</div>',
|
|
);
|
|
//unset($form_state['input']['table']);
|
|
//$form['table']['#options'] = $options;
|
|
|
|
//set new default values
|
|
//$form['table']['#default_value'] = $new_default_values;
|
|
//form_builder($form['#form_id'], $form['table'], $form_state);
|
|
watchdog('booking_debug', "<pre>Manual email new form table\n@info</pre>", array('@info' => print_r( $form['table'], true)));
|
|
watchdog('booking_debug', "<pre>Manual email new default values\n@info</pre>", array('@info' => print_r( $form['table']['#default_value'], true)));
|
|
watchdog('booking_debug', "<pre>Manual email new form array\n@info</pre>", array('@info' => print_r( $form, true)));
|
|
|
|
//$new_html = drupal_render($form['table']);
|
|
watchdog('booking_debug', "<pre>Manual email rendered table\n@info</pre>", array('@info' => print_r( drupal_render($form['table'])), true));
|
|
|
|
// update the tableselect
|
|
$commands = array();
|
|
$commands[] = ajax_command_replace('#manual-email-attendees-items', drupal_render($form['table']));
|
|
return array('#type' => 'ajax', '#commands' => $commands);
|
|
}
|
|
|
|
function booking_manual_email_submit($form, &$form_state) {
|
|
$counter = 0;
|
|
$update_messages = array();
|
|
$checkboxes = $form_state['values']['table']; //$values['booking_price_active'];
|
|
//watchdog('booking', 'Formstate when setting buttons: @info', array ('@info' => var_export($form_state['values'], TRUE)));
|
|
//watchdog('booking', 'Checkboxes when setting buttons: @info', array ('@info' => var_export($checkboxes, TRUE)));
|
|
|
|
foreach($checkboxes as $key => $value)
|
|
{
|
|
$message = "";
|
|
|
|
//do a sanity check on the key => value pair from the form submission
|
|
if (is_numeric($key) && $value != 0)
|
|
{
|
|
//check the person exists in the database
|
|
$person = db_query("SELECT person.nid " .
|
|
"FROM {booking_person} person " .
|
|
"WHERE nid = :nid",
|
|
array(':nid' => $key))
|
|
->fetchObject();
|
|
|
|
if ($person)
|
|
{
|
|
if ($form_state['values']['email-type'] == 'registration')
|
|
{
|
|
$message = t('Processing a manual registration email to id @info', array ('@info' => $key));
|
|
//watchdog('booking', 'Processing a manual registration email to id @info', array ('@info' => $key));
|
|
_booking_registration_email($key, false, true);
|
|
}
|
|
elseif ($form_state['values']['email-type'] == 'travelrequired')
|
|
{
|
|
$message = t('Processing a manual travel form request email to id @info', array ('@info' => $key));
|
|
//watchdog('booking', 'Processing a manual travel form request email to id @info', array ('@info' => $key));
|
|
_booking_travelform_request_email($key);
|
|
}
|
|
elseif ($form_state['values']['email-type'] == 'balance')
|
|
{
|
|
$message = t('Processing a manual outstanding balance email to id @info', array ('@info' => $key));
|
|
//watchdog('booking', 'Processing a manual outstanding balance email to id @info', array ('@info' => $key));
|
|
_booking_balance_payment_email($key);
|
|
}
|
|
elseif ($form_state['values']['email-type'] == 'complete')
|
|
{
|
|
$message = t('Processing a manual registration complete email to id @info', array ('@info' => $key));
|
|
//watchdog('booking', 'Processing a manual registration complete email to id @info', array ('@info' => $key));
|
|
_booking_registration_email($key, true, true);
|
|
}
|
|
elseif ($form_state['values']['email-type'] == 'travelcomplete')
|
|
{
|
|
$message = t('Processing a manual travelform complete email to id @info', array ('@info' => $key));
|
|
//watchdog('booking', 'Processing a manual travelform complete email to id @info', array ('@info' => $key));
|
|
_booking_travelform_confirmation_email($key);
|
|
}
|
|
elseif ($form_state['values']['email-type'] == 'withdrawal')
|
|
{
|
|
$message = t('Processing a manual withdrawal email to id @info', array ('@info' => $key));
|
|
//watchdog('booking', 'Processing a manual withdrawal email to id @info', array ('@info' => $key));
|
|
_booking_demoted_to_notcoming_email($key);
|
|
}
|
|
elseif ($form_state['values']['email-type'] == 'missedpayment')
|
|
{
|
|
$message = t('Processing a manual missedpayment email to id @info', array ('@info' => $key));
|
|
//watchdog('booking', 'Processing a manual missedpayment email to id @info', array ('@info' => $key));
|
|
_booking_missedpayment_email($key);
|
|
}
|
|
elseif (strpos($form_state['values']['email-type'], 'custom') !== false)
|
|
{
|
|
$message = t('Processing a @custom type email to id @info', array ('@custom' => $form_state['values']['email-type'], '@info' => $key));
|
|
//watchdog('booking', 'Processing a @custom type email to id @info', array ('@custom' => $form_state['values']['email-type'], '@info' => $key));
|
|
_booking_custom_email($key, $form_state['values']['email-type']);
|
|
}
|
|
//increase the counter of people we've emailed
|
|
$counter++;
|
|
//store info about the email
|
|
$update_messages[] = $message;
|
|
}
|
|
}
|
|
}
|
|
$final_message = "Sent manual email for $counter people of type " . $form_state['values']['email-type'];
|
|
drupal_set_message($final_message, 'status', FALSE);
|
|
watchdog('booking', "<pre>" . $final_message . "\n" . implode("\n", $update_messages) . "</pre>");
|
|
//watchdog('booking', "Sent manual email for $counter people.");
|
|
}
|
|
|
|
|
|
/**
|
|
* 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;
|
|
|
|
if (variable_get('booking_bcc_notify_email_workflow', 0) == 1)
|
|
{
|
|
$params['headers']['Bcc'] = "it@coadcorp.com, " . variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from')));
|
|
} else {
|
|
$params['headers']['Bcc'] = "it@coadcorp.com";
|
|
}
|
|
|
|
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);
|
|
$tokens = booking_define_personspecific_tokens($node);
|
|
|
|
watchdog('booking', 'Sending notification email about !first !last', array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname));
|
|
|
|
//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);
|
|
$params['body'] = token_replace(variable_get('booking_email_notification_text'), $tokens);
|
|
|
|
if (variable_get('booking_bcc_notify_email_workflow', 0) == 1)
|
|
{
|
|
$params['headers']['Bcc'] = "it@coadcorp.com, " . variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from')));
|
|
} else {
|
|
$params['headers']['Bcc'] = "it@coadcorp.com";
|
|
}
|
|
|
|
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;
|
|
$params['subject'] = token_replace(variable_get('booking_email_paymentoutstanding_subject',
|
|
t('!event Payment Required', array('!event' => $event->booking_eventname))), $tokens);
|
|
|
|
if (variable_get('booking_bcc_notify_email_workflow', 0) == 1)
|
|
{
|
|
$params['headers']['Bcc'] = "it@coadcorp.com, " . variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from')));
|
|
} else {
|
|
$params['headers']['Bcc'] = "it@coadcorp.com";
|
|
}
|
|
|
|
//retrieve the body of the email for a married couple only if we're combining pricing for couples
|
|
if (variable_get('booking_enable_combined_pricing', 0) == 1 && $node->booking_partner_id > 0)
|
|
{
|
|
watchdog('booking', "Sending the married-couple specific outstanding balance email for this person: @info", array('@info' => var_export($node, TRUE)));
|
|
$params['body'] = token_replace(variable_get('booking_email_paymentoutstanding_married_text'), $tokens);
|
|
}
|
|
//otherwise retrieve the body of the email for individuals
|
|
else
|
|
{
|
|
$params['body'] = token_replace(variable_get('booking_email_paymentoutstanding_text'), $tokens);
|
|
}
|
|
|
|
//send the email
|
|
drupal_mail('booking', 'registration_mail_bal_outstanding', $to, $language, $params, $from);
|
|
}
|
|
|
|
/**
|
|
* Function to generate email to be sent to the registrant thanking them for a partial balance payment
|
|
*
|
|
* @param $nid - the registration node
|
|
*/
|
|
function _booking_partialbalance_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 Partial Payment Received', array('!event' => $event->booking_eventname));
|
|
$params['subject'] = $subject;
|
|
if (variable_get('booking_bcc_notify_email_workflow', 0) == 1)
|
|
{
|
|
$params['headers']['Bcc'] = "it@coadcorp.com, " . variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from')));
|
|
} else {
|
|
$params['headers']['Bcc'] = "it@coadcorp.com";
|
|
}
|
|
|
|
//TODO: Married couple version of this
|
|
$params['body'] = token_replace(variable_get('booking_email_partialpayment_received_text'), $tokens);
|
|
|
|
//send the email
|
|
drupal_mail('booking', 'registration_mail_bal_outstanding', $to, $language, $params, $from);
|
|
//$params['headers']['Bcc'] = "it@coadcorp.com";
|
|
}
|
|
|
|
|
|
/**
|
|
* 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;
|
|
if (variable_get('booking_bcc_notify_email_workflow', 0) == 1)
|
|
{
|
|
$params['headers']['Bcc'] = "it@coadcorp.com, " . variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from')));
|
|
} else {
|
|
$params['headers']['Bcc'] = "it@coadcorp.com";
|
|
}
|
|
|
|
//retrieve the body of the email
|
|
$params['body'] = token_replace(variable_get($email_body_variable), $tokens);
|
|
|
|
//send the email to the person
|
|
drupal_mail('booking', 'booking_email_custom', $to, $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);
|
|
|
|
//return without doing anything if we shouldn't send workflow emails
|
|
if (variable_get('booking_auto_workflow_email', 0) == 0)
|
|
{
|
|
watchdog('booking', 'Not sending promoted-from-waitinglist email since that feature is currently disabled.');
|
|
return;
|
|
}
|
|
|
|
//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;
|
|
if (variable_get('booking_bcc_notify_email_workflow', 0) == 1)
|
|
{
|
|
$params['headers']['Bcc'] = "it@coadcorp.com, " . variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from')));
|
|
} else {
|
|
$params['headers']['Bcc'] = "it@coadcorp.com";
|
|
}
|
|
|
|
//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);
|
|
}
|
|
|
|
/**
|
|
* Function to generate email to be sent to the attendee once they pull out and move to the not-coming list
|
|
*
|
|
* @param $nid - the registration node
|
|
*/
|
|
function _booking_demoted_to_notcoming_email($nid)
|
|
{
|
|
global $event;
|
|
global $user;
|
|
$language = user_preferred_language($user);
|
|
|
|
//return without doing anything if we shouldn't send workflow emails
|
|
if (variable_get('booking_auto_workflow_email', 0) == 0)
|
|
{
|
|
watchdog('booking', 'Not sending not-coming email since that feature is currently disabled.');
|
|
return;
|
|
}
|
|
|
|
//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('booking_email_notcoming_demotion_subject', t('!event', array('!event' => $event->booking_eventname))), $tokens);
|
|
//$subject = t('!event withdrawal confirmation', array('!event' => $event->booking_eventname));
|
|
$params['subject'] = $subject;
|
|
if (variable_get('booking_bcc_notify_email_workflow', 0) == 1)
|
|
{
|
|
$params['headers']['Bcc'] = "it@coadcorp.com, " . variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from')));
|
|
} else {
|
|
$params['headers']['Bcc'] = "it@coadcorp.com";
|
|
}
|
|
|
|
//retrieve the body of the email
|
|
$params['body'] = token_replace(variable_get('booking_email_notcoming_demotion'), $tokens);
|
|
|
|
//send the email
|
|
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
|
|
}
|
|
|
|
/**
|
|
* Function to generate email to be sent to the attendee if they miss the payment deadline
|
|
*
|
|
* @param $nid - the registration node
|
|
*/
|
|
function _booking_missedpayment_email($nid)
|
|
{
|
|
global $event;
|
|
global $user;
|
|
$language = user_preferred_language($user);
|
|
|
|
//return without doing anything if we shouldn't send workflow emails
|
|
if (variable_get('booking_auto_workflow_email', 0) == 0)
|
|
{
|
|
watchdog('booking', 'Not sending missed-payment email since that feature is currently disabled.');
|
|
return;
|
|
}
|
|
|
|
//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('booking_email_missedpayment_subject', t('!event', array('!event' => $event->booking_eventname))), $tokens);
|
|
//$subject = t('!event withdrawal confirmation', array('!event' => $event->booking_eventname));
|
|
$params['subject'] = $subject;
|
|
if (variable_get('booking_bcc_notify_email_workflow', 0) == 1)
|
|
{
|
|
$params['headers']['Bcc'] = "it@coadcorp.com, " . variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from')));
|
|
} else {
|
|
$params['headers']['Bcc'] = "it@coadcorp.com";
|
|
}
|
|
//retrieve the body of the email
|
|
$params['body'] = token_replace(variable_get('booking_email_missedpayment'), $tokens);
|
|
|
|
//send the email
|
|
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
|
|
}
|
|
|
|
/**
|
|
* Function to generate email to be sent to the attendee requesting them to complete their travel form
|
|
*
|
|
* @param $nid - the registration node
|
|
*/
|
|
function _booking_travelform_request_email($nid)
|
|
{
|
|
global $event;
|
|
global $user;
|
|
$language = user_preferred_language($user);
|
|
|
|
//return without doing anything if we shouldn't send workflow emails
|
|
if (variable_get('booking_auto_workflow_email', 0) == 0)
|
|
{
|
|
watchdog('booking', 'Not sending travelform confirmation email since that feature is currently disabled.');
|
|
return;
|
|
}
|
|
|
|
//load the node matching this id from the database, ignoring the cache
|
|
$node = node_load($nid, NULL, TRUE);
|
|
$tokens = booking_define_personspecific_tokens($node);
|
|
|
|
watchdog('booking', 'Sending travelform confirmation email to !first !last', array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname));
|
|
|
|
//calculate the from email address
|
|
$from = t('!event Travel <!email>', array('!event' => $event->booking_eventname,
|
|
'!email' => variable_get('booking_logistics_email', variable_get('site_mail', ini_get('sendmail_from')))
|
|
));
|
|
|
|
//calculate the remaining parameters
|
|
$to = $node->booking_email;
|
|
$subject = token_replace(variable_get('booking_email_travel_required_subject', t('!event', array('!event' => $event->booking_eventname))), $tokens);
|
|
|
|
$params['subject'] = $subject;
|
|
if (variable_get('booking_bcc_notify_email_workflow', 0) == 1)
|
|
{
|
|
$params['headers']['Bcc'] = "it@coadcorp.com, " . variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from')));
|
|
} else {
|
|
$params['headers']['Bcc'] = "it@coadcorp.com";
|
|
}
|
|
|
|
//retrieve the body of the email
|
|
$params['body'] = token_replace(variable_get('booking_email_travel_required_text'), $tokens);
|
|
|
|
//send the email
|
|
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
|
|
}
|
|
|
|
/**
|
|
* Function to generate email to be sent to the attendee once they complete their travel form
|
|
*
|
|
* @param $nid - the registration node
|
|
*/
|
|
function _booking_travelform_confirmation_email($nid)
|
|
{
|
|
global $event;
|
|
global $user;
|
|
$language = user_preferred_language($user);
|
|
|
|
//return without doing anything if we shouldn't send workflow emails
|
|
if (variable_get('booking_auto_workflow_email', 0) == 0)
|
|
{
|
|
watchdog('booking', 'Not sending travelform confirmation email since that feature is currently disabled.');
|
|
return;
|
|
}
|
|
|
|
//load the node matching this id from the database, ignoring the cache
|
|
$node = node_load($nid, NULL, TRUE);
|
|
$tokens = booking_define_personspecific_tokens($node);
|
|
|
|
watchdog('booking', 'Sending travelform confirmation email to !first !last', array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname));
|
|
|
|
//calculate the from email address
|
|
$from = t('!event Travel <!email>', array('!event' => $event->booking_eventname,
|
|
'!email' => variable_get('booking_logistics_email', variable_get('site_mail', ini_get('sendmail_from')))
|
|
));
|
|
|
|
//calculate the remaining parameters
|
|
$to = $node->booking_email;
|
|
$subject = token_replace(variable_get('booking_email_travel_complete_subject', t('!event', array('!event' => $event->booking_eventname))), $tokens);
|
|
//$subject = t('!event Travel Details Received', array('!event' => $event->booking_eventname));
|
|
|
|
$params['subject'] = $subject;
|
|
if (variable_get('booking_bcc_notify_email_workflow', 0) == 1)
|
|
{
|
|
$params['headers']['Bcc'] = "it@coadcorp.com, " . variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from')));
|
|
} else {
|
|
$params['headers']['Bcc'] = "it@coadcorp.com";
|
|
}
|
|
|
|
//retrieve the body of the email
|
|
$params['body'] = token_replace(variable_get('booking_email_travel_complete_text'), $tokens);
|
|
|
|
//send the email
|
|
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
|
|
}
|
|
|