split up some of the email functions for easier management
This commit is contained in:
402
booking.emails_admin.inc
Normal file
402
booking.emails_admin.inc
Normal file
@@ -0,0 +1,402 @@
|
||||
<?php
|
||||
|
||||
function booking_emails_admin() {
|
||||
global $event;
|
||||
$form = array();
|
||||
|
||||
//include the token definitions
|
||||
$form['tokens'] = array(
|
||||
'#theme' => 'token_tree',
|
||||
'#token_types' => array('booking'),
|
||||
);
|
||||
|
||||
/*Text for emails*/
|
||||
$form['emails'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => 'Built-In Workflow Email Definitions',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$form['emails']['booking_email_notification_text'] = array(
|
||||
'#title' => t('Notification Email'),
|
||||
'#type' => 'textarea',
|
||||
//'#format' => 'full_html',
|
||||
'#description' => t('Email to send to the notification email address (defined in general configuration) when a person has registered'),
|
||||
'#default_value' => variable_get('booking_email_notification_text', '[booking:regn-summary]'),
|
||||
);
|
||||
$form['emails']['booking_email_bookedin_text'] = array(
|
||||
'#title' => t('Registration Successful Email'),
|
||||
'#type' => 'textarea',
|
||||
//'#format' => 'full_html',
|
||||
'#description' => t('Text to use in an email indicating the person has booked in, paid their deposit and is not on the waiting list'),
|
||||
'#default_value' => variable_get('booking_email_bookedin_text', $default_email_text),
|
||||
);
|
||||
$form['emails']['booking_email_regn_complete_text'] = array(
|
||||
'#title' => t('Payment Complete Email'),
|
||||
'#type' => 'textarea',
|
||||
//'#format' => 'full_html',
|
||||
'#description' => t('Email text to indicate a person has booked in, fully paid and is not on the waiting list. ' .
|
||||
'This will be sent either at initial registration if the full amount is paid, or when the balance is paid.'),
|
||||
'#default_value' => variable_get('booking_email_regn_complete_text', $booking_email_regn_complete_text),
|
||||
);
|
||||
$form['emails']['booking_email_waitinglist_text'] = array(
|
||||
'#title' => t('Registration on Waiting List Email'),
|
||||
'#description' => t('Email text to indicate a person has registered but is on the waiting list. ' .
|
||||
'This will be sent instead of the Registration Successful or Registration Complete emails if the person is on the waiting list.'),
|
||||
'#type' => 'textarea',
|
||||
//'#format' => 'full_html',
|
||||
'#default_value' => variable_get('booking_email_waitinglist_text', $booking_email_waitinglist_text),
|
||||
);
|
||||
$form['emails']['booking_email_partialpayment_received_text'] = array(
|
||||
'#title' => t('Email text to send a person thanking them for their partial payment'),
|
||||
'#type' => 'textarea',
|
||||
//'#format' => 'full_html',
|
||||
'#description' => t(''),
|
||||
'#default_value' => variable_get('booking_email_partialpayment_received_text', ''),
|
||||
);
|
||||
$form['emails']['booking_email_paymentoutstanding_subject'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Balance Outstanding Email Subject'),
|
||||
'#description' => t('Subject line for email advising attendee they missed the payment deadline'),
|
||||
'#size' => 150,
|
||||
'#maxlength' => 300,
|
||||
'#default_value' => variable_get('booking_email_paymentoutstanding_subject','[booking:eventname] payment required'),
|
||||
);
|
||||
$form['emails']['booking_email_paymentoutstanding_text'] = array(
|
||||
'#description' => t('Email text to send a person reminding them of how much they owe'),
|
||||
'#type' => 'textarea',
|
||||
//'#format' => 'full_html',
|
||||
'#title' => t('Balance Outstanding Email Text'),
|
||||
'#default_value' => variable_get('booking_email_paymentoutstanding_text', $booking_email_paymentoutstanding_text),
|
||||
);
|
||||
|
||||
$form['emails']['booking_email_paymentoutstanding_married_text'] = array(
|
||||
'#title' => t('Email text to send a married couple reminding them of how much they both owe (only applies when combined pricing enabled)'),
|
||||
'#type' => 'textarea',
|
||||
//'#format' => 'full_html',
|
||||
'#description' => t(''),
|
||||
'#default_value' => variable_get('booking_email_paymentoutstanding_married_text', $booking_email_paymentoutstanding_married_text),
|
||||
);
|
||||
$form['emails']['booking_email_waitinglistpromotion'] = array(
|
||||
'#title' => t('Email text to send a person on the waiting list when a spot opens up for them'),
|
||||
'#type' => 'textarea',
|
||||
'#description' => t(''),
|
||||
'#default_value' => variable_get('booking_email_waitinglistpromotion', $booking_email_waitinglistpromotion),
|
||||
);
|
||||
$form['emails']['booking_email_notcoming_demotion_subject'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Withdrawal Processed Email'),
|
||||
'#description' => t('Subject line for email advising attendee their withdrawal has been processed'),
|
||||
'#size' => 150,
|
||||
'#maxlength' => 300,
|
||||
'#default_value' => variable_get('booking_email_notcoming_demotion_subject','[booking:eventname] withdrawal processed'),
|
||||
);
|
||||
$form['emails']['booking_email_notcoming_demotion'] = array(
|
||||
'#title' => t('Email text to send a person who withdraws their registration'),
|
||||
'#type' => 'textarea',
|
||||
'#description' => t(''),
|
||||
'#default_value' => variable_get('booking_email_notcoming_demotion', $booking_email_notcoming_demotion),
|
||||
);
|
||||
$form['emails']['booking_email_missedpayment_subject'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Missed Payment Email Subject'),
|
||||
'#description' => t('Subject line for email advising attendee they missed the payment deadline'),
|
||||
'#size' => 150,
|
||||
'#maxlength' => 300,
|
||||
'#default_value' => variable_get('booking_email_missedpayment_subject','[booking:eventname] payment deadline missed'),
|
||||
);
|
||||
$form['emails']['booking_email_missedpayment'] = array(
|
||||
'#title' => t('Missed Payment Email Text'),
|
||||
'#type' => 'textarea',
|
||||
'#description' => t('Email text to send a person who missed the payment deadline'),
|
||||
'#default_value' => variable_get('booking_email_missedpayment', ''),
|
||||
);
|
||||
$form['emails']['booking_email_travel_required_subject'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Travel Form Required Subject'),
|
||||
'#description' => t('Subject line for email requesting attendee to complete the travel form'),
|
||||
'#size' => 150,
|
||||
'#maxlength' => 300,
|
||||
'#default_value' => variable_get('booking_email_travel_required_subject','[booking:eventname] Travel Details Required'),
|
||||
);
|
||||
$form['emails']['booking_email_travel_required_text'] = array(
|
||||
'#title' => t('Travel Form Required Text'),
|
||||
'#description' => t('Email text requesting attendee to complete the travel form. This email will be sent from the !email email address', array('!email' => variable_get('booking_logistics_email'))),
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => variable_get('booking_email_travel_required_text', ''),
|
||||
);
|
||||
$form['emails']['booking_email_travel_complete_subject'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Travel Form Complete Subject'),
|
||||
'#description' => t('Subject line for email indicating a person has completed the travel form'),
|
||||
'#size' => 150,
|
||||
'#maxlength' => 300,
|
||||
'#default_value' => variable_get('booking_email_travel_complete_subject','[booking:eventname] Travel Details Received'),
|
||||
);
|
||||
$form['emails']['booking_email_travel_complete_text'] = array(
|
||||
'#title' => t('Travel Form Complete Text'),
|
||||
'#description' => t('Email text to indicate a person has completed the travel form. This email will be sent from the !email email address', array('!email' => variable_get('booking_logistics_email'))),
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => variable_get('booking_email_travel_complete_text', ''),
|
||||
);
|
||||
|
||||
/*Text for emails*/
|
||||
$form['custom-emails'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => 'Custom Email Text Definitions',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
|
||||
//add a bunch of custom emails
|
||||
for ($i = 1; $i <= variable_get('booking_custom_email_count','5'); $i++) {
|
||||
$subject_fieldname = 'booking_email_subject_custom' . $i;
|
||||
$body_fieldname = 'booking_email_custom' . $i;
|
||||
$form['custom-emails'][$subject_fieldname] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Subject line for Custom Email ' . $i),
|
||||
'#size' => 150,
|
||||
'#maxlength' => 300,
|
||||
'#default_value' => variable_get($subject_fieldname,'[booking:eventname]'),
|
||||
);
|
||||
$form['custom-emails'][$body_fieldname] = array(
|
||||
'#title' => t('Email text for custom email ' . $i),
|
||||
'#type' => 'textarea',
|
||||
'#description' => t(''),
|
||||
'#default_value' => variable_get($body_fieldname, ''),
|
||||
);
|
||||
}
|
||||
|
||||
//let the builtin hook do all the hard work
|
||||
return system_settings_form($form, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to allow admin user to manually generate and send a workflow or custom email
|
||||
*
|
||||
* @param $input_option - A pre-defined string that selects the checkboxes for a corresponding class of people
|
||||
* @return form render array
|
||||
*/
|
||||
function booking_manual_email_form($form, &$form_state, $input_option = "")
|
||||
{
|
||||
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,
|
||||
);
|
||||
|
||||
$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 ($input_option == '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' => array("1814" => TRUE),
|
||||
'#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 default values\n@info</pre>", array('@info' => print_r( $values, true)));
|
||||
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 to handle sending the manual emails
|
||||
*/
|
||||
function booking_manual_email_form_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.");
|
||||
}
|
Reference in New Issue
Block a user