From ae79dbbc5177021074b1fa04cafbf3e7d5d6c0d3 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Fri, 3 Jun 2016 11:44:45 +1000 Subject: [PATCH] fix bug --- booking.emails_admin.inc | 1102 +++++++++++++++++++------------------- 1 file changed, 550 insertions(+), 552 deletions(-) diff --git a/booking.emails_admin.inc b/booking.emails_admin.inc index a8af89f..df7dcca 100644 --- a/booking.emails_admin.inc +++ b/booking.emails_admin.inc @@ -1,260 +1,260 @@ 'token_tree', - '#token_types' => array('booking'), - ); + $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), - ); + /*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_initial_email_subject'] = array ( - '#type' => 'textfield', - '#title' => t('Initial Travel Form Required Subject'), - '#description' => t('Subject line for first email requesting attendee to complete the travel form'), - '#size' => 150, - '#maxlength' => 300, - '#default_value' => variable_get('booking_email_travel_initial_email_subject','[booking:eventname] Travel Details Required'), - ); - $form['emails']['booking_email_travel_initial_email_text'] = array( - '#title' => t('Initial Travel Form Required Text'), - '#description' => t('Text for first email 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_initial_email_text', ''), - ); - $form['emails']['booking_email_travel_reminder_email_subject'] = array ( - '#type' => 'textfield', - '#title' => t('Reminder Travel Form Required Subject'), - '#description' => t('Subject line for reminder email requesting attendee to complete the travel form'), - '#size' => 150, - '#maxlength' => 300, - '#default_value' => variable_get('booking_email_travel_reminder_email_subject','[booking:eventname] Travel Details Required'), - ); - $form['emails']['booking_email_travel_reminder_email_text'] = array( - '#title' => t('Reminder Travel Form Required Text'), - '#description' => t('Text for reminder email 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_reminder_email_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', ''), - ); + $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_initial_email_subject'] = array ( + '#type' => 'textfield', + '#title' => t('Initial Travel Form Required Subject'), + '#description' => t('Subject line for first email requesting attendee to complete the travel form'), + '#size' => 150, + '#maxlength' => 300, + '#default_value' => variable_get('booking_email_travel_initial_email_subject','[booking:eventname] Travel Details Required'), + ); + $form['emails']['booking_email_travel_initial_email_text'] = array( + '#title' => t('Initial Travel Form Required Text'), + '#description' => t('Text for first email 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_initial_email_text', ''), + ); + $form['emails']['booking_email_travel_reminder_email_subject'] = array ( + '#type' => 'textfield', + '#title' => t('Reminder Travel Form Required Subject'), + '#description' => t('Subject line for reminder email requesting attendee to complete the travel form'), + '#size' => 150, + '#maxlength' => 300, + '#default_value' => variable_get('booking_email_travel_reminder_email_subject','[booking:eventname] Travel Details Required'), + ); + $form['emails']['booking_email_travel_reminder_email_text'] = array( + '#title' => t('Reminder Travel Form Required Text'), + '#description' => t('Text for reminder email 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_reminder_email_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, ''), - ); - } + /*Text for emails*/ + $form['custom-emails'] = array( + '#type' => 'fieldset', + '#title' => 'Custom Email Text Definitions', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); - /*Text for logistics emails*/ - $form['custom-logistics-emails'] = array( - '#type' => 'fieldset', - '#title' => 'Custom Logistics Email Text Definitions', - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ); - - //add a bunch of custom emails + //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, ''), + ); + } + + /*Text for logistics emails*/ + $form['custom-logistics-emails'] = array( + '#type' => 'fieldset', + '#title' => 'Custom Logistics Email Text Definitions', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + + //add a bunch of custom emails //@todo add an admin variable for this - for ($i = 1; $i <= 5; $i++) { - $subject_fieldname = 'booking_email_subject_customlogistics' . $i; - $body_fieldname = 'booking_email_customlogistics' . $i; - $form['custom-logistics-emails'][$subject_fieldname] = array ( - '#type' => 'textfield', - '#title' => t('Subject line for Logistics Custom Email ' . $i), - '#size' => 150, - '#maxlength' => 300, - '#default_value' => variable_get($subject_fieldname,'[booking:eventname] Logistics'), - ); - $form['custom-logistics-emails'][$body_fieldname] = array( - '#title' => t('Email text for Logistics Custom Email ' . $i), - '#type' => 'textarea', - '#description' => t(''), - '#default_value' => variable_get($body_fieldname, ''), - ); - } + for ($i = 1; $i <= 5; $i++) { + $subject_fieldname = 'booking_email_subject_customlogistics' . $i; + $body_fieldname = 'booking_email_customlogistics' . $i; + $form['custom-logistics-emails'][$subject_fieldname] = array ( + '#type' => 'textfield', + '#title' => t('Subject line for Logistics Custom Email ' . $i), + '#size' => 150, + '#maxlength' => 300, + '#default_value' => variable_get($subject_fieldname,'[booking:eventname] Logistics'), + ); + $form['custom-logistics-emails'][$body_fieldname] = array( + '#title' => t('Email text for Logistics 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); + //let the builtin hook do all the hard work + return system_settings_form($form, FALSE); } /** @@ -265,206 +265,204 @@ function booking_emails_admin() { */ 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(); - $preselection_options = array(); - $values = array(); - $group_text = ""; - $prefix = t("

Send a manual email to people registered for this event.

"); - $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['initialtravelrequired'] = 'Initial Travel Form Required Email'; - $email_options_array['remindertravelrequired'] = 'Reminder Travel Form Required Email'; - $email_options_array['travelcomplete'] = 'Travel Form Complete Email'; - $preselection_options['---'] = "---"; - $preselection_options['bookedin'] = 'Status of Booked In'; - $preselection_options['test'] = 'Testing'; - - //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); - } + global $event; + //see http://www.jaypan.com/blog/themeing-drupal-7-forms-tables-checkboxes-or-radios + $form = array(); + $options = array(); + $preselection_options = array(); + $values = array(); + $group_text = ""; + $prefix = t("

Send a manual email to people registered for this event.

"); + $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['initialtravelrequired'] = 'Initial Travel Form Required Email'; + $email_options_array['remindertravelrequired'] = 'Reminder Travel Form Required Email'; + $email_options_array['travelcomplete'] = 'Travel Form Complete Email'; + $preselection_options['---'] = "---"; + $preselection_options['bookedin'] = 'Status of Booked In'; + $preselection_options['test'] = 'Testing'; + + //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); + } //add in the custom email types from logistics - for ($i = 1; $i <= 5; $i++) - { - $email_options_array['customlogistics' . $i] = variable_get('booking_email_subject_customlogistics' . $i, $event->booking_eventname . ' logistics custom ' . $i); - } - //add some indication of which people have been pre-selected, if any - if ($input_option == 'unpaid') { - $prefix .= t("

Pre-selecting people with outstanding payments.

"); - } - elseif ($input_option == 'bookedin') { - $prefix .= t("

Pre-selecting only people with a status of booked-in.

"); - } - //attach css so we can customise colours for some people - $form['#attached']['css'] = array( - drupal_get_path('module', 'booking') . '/booking.css', - ); - //attach js for dynamically setting checkboxes - $form['#attached']['js'][] = drupal_get_path("module", "booking")."/booking.js"; - - //@todo add booking prefix - $form['email-type'] = array( - '#type' => 'select', - '#title' => t('Email Type'), - '#required' => TRUE, - '#default_value' => 'NULL', - '#options' => $email_options_array, - ); - - //@todo - /* - create hidden form element that we will populate with JSON data via ajax - create select element defining the pre-selections available - create submit button that calls ajax to update hidden form element, then calls ajax to check the checkboxes based on the hidden form element - - info on turning JSON data back to array - http://stackoverflow.com/questions/29076219/javascript-storing-array-of-objects-in-hidden-field - - ajax references: - http://www.maged.me/blog/drupal-7-execute-javascript-code-after-ajax-call - https://www.drupal.org/node/1028410 - https://www.drupal.org/node/2046693 - - jquery to check the checkboxes: - http://jsfiddle.net/nanoquantumtech/dnhwz/ - */ - - $form['booking-email-default-ids'] = array ( - '#type' => 'hidden', - '#value' => "[]", - '#prefix' => '
', - '#suffix' => '
', - '#attributes' => array('id' => 'booking_email_default_ids'), - ); - - $form['booking-email-preselection'] = array( - '#type' => 'select', - '#title' => t('Preselect Attendees'), - '#options' => $preselection_options, - '#default_value' => '---', - '#ajax' => array( - 'event' => 'change', - 'callback' => '_booking_email_get_default_selection_callback', - 'wrapper' => 'booking_email_default_ids_wrapper', - ), - ); - - $form['submit'] = array ( - '#type' => 'submit', - '#value' => t('Send Email'), - ); + for ($i = 1; $i <= 5; $i++) + { + $email_options_array['customlogistics' . $i] = variable_get('booking_email_subject_customlogistics' . $i, $event->booking_eventname . ' logistics custom ' . $i); + } + //add some indication of which people have been pre-selected, if any + if ($input_option == 'unpaid') { + $prefix .= t("

Pre-selecting people with outstanding payments.

"); + } + elseif ($input_option == 'bookedin') { + $prefix .= t("

Pre-selecting only people with a status of booked-in.

"); + } + //attach css so we can customise colours for some people + $form['#attached']['css'] = array( + drupal_get_path('module', 'booking') . '/booking.css', + ); + //attach js for dynamically setting checkboxes + $form['#attached']['js'][] = drupal_get_path("module", "booking")."/booking.js"; + + //@todo add booking prefix + $form['email-type'] = array( + '#type' => 'select', + '#title' => t('Email Type'), + '#required' => TRUE, + '#default_value' => 'NULL', + '#options' => $email_options_array, + ); + + //@todo + /* + create hidden form element that we will populate with JSON data via ajax + create select element defining the pre-selections available + create submit button that calls ajax to update hidden form element, then calls ajax to check the checkboxes based on the hidden form element + + info on turning JSON data back to array + http://stackoverflow.com/questions/29076219/javascript-storing-array-of-objects-in-hidden-field + + ajax references: + http://www.maged.me/blog/drupal-7-execute-javascript-code-after-ajax-call + https://www.drupal.org/node/1028410 + https://www.drupal.org/node/2046693 + + jquery to check the checkboxes: + http://jsfiddle.net/nanoquantumtech/dnhwz/ + */ + + $form['booking-email-default-ids'] = array ( + '#type' => 'hidden', + '#value' => "[]", + '#prefix' => '
', + '#suffix' => '
', + '#attributes' => array('id' => 'booking_email_default_ids'), + ); + + $form['booking-email-preselection'] = array( + '#type' => 'select', + '#title' => t('Preselect Attendees'), + '#options' => $preselection_options, + '#default_value' => '---', + '#ajax' => array( + 'event' => 'change', + 'callback' => '_booking_email_get_default_selection_callback', + 'wrapper' => 'booking_email_default_ids_wrapper', + ), + ); + + $form['submit'] = array ( + '#type' => 'submit', + '#value' => t('Send Email'), + ); - $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(); + $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 .= "" . $text . " for " . $group->booking_studygroup_descrip . " #" . $group->booking_session_id . "; "; - } - } - $options[$data->nid]['group_roles'] = $group_text; - } - //handle any checkbox pre-selection for this attendee - if ($input_option == 'unpaid') { - $values[$data->nid] = ($data->booking_payment_complete == 'Y' || $data->booking_status != 1) ? FALSE : TRUE; - } - elseif ($input_option == 'bookedin') { - $values[$data->nid] = $data->booking_status == 1 ? TRUE : FALSE; - } - } - - $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' => '
', - '#suffix' => '
', - ); - //watchdog('booking_debug', "
Manual email form default values\n@info
", array('@info' => print_r( $values, true))); - //watchdog('booking_debug', "
Manual email form table\n@info
", array('@info' => print_r( $form['table'], true))); - - $form['submit'] = array ( - '#type' => 'submit', - '#value' => t('Send Email'), - ); + 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 .= "" . $text . " for " . $group->booking_studygroup_descrip . " #" . $group->booking_session_id . "; "; + } + } + $options[$data->nid]['group_roles'] = $group_text; + } + //handle any checkbox pre-selection for this attendee + if ($input_option == 'unpaid') { + $values[$data->nid] = ($data->booking_payment_complete == 'Y' || $data->booking_status != 1) ? FALSE : TRUE; + } + elseif ($input_option == 'bookedin') { + $values[$data->nid] = $data->booking_status == 1 ? TRUE : FALSE; + } + } + + $form['table'] = array ( + '#type' => 'tableselect', + //'#multiple' => TRUE, + '#header' => $header, + '#options' => $options, + '#default_value' => $values, + '#empty' => t('No attendees found.'), + '#attributes' => array('id' => 'sort-table'), + ); + //watchdog('booking_debug', "
Manual email form default values\n@info
", array('@info' => print_r( $values, true))); + //watchdog('booking_debug', "
Manual email form table\n@info
", 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, - ); + return array ( + 'first_para' => array ( + '#type' => 'markup', + '#markup' => $prefix, + ), + 'form' => $form, + ); } /** @@ -476,123 +474,123 @@ function booking_manual_email_form($form, &$form_state, $input_option = "") * Source: http://www.maged.me/blog/drupal-7-execute-javascript-code-after-ajax-call */ function _booking_email_get_default_selection_callback($form, $form_state) { - global $event; - $defaults = array(); - $replacementform_data = array(); - - //get type of selection from $form_state['values']['booking-email-preselection'] - $selection = $form_state['values']['booking-email-preselection']; - //load nodes - $people = booking_load_query(NULL, TRUE); - //populate $defaults based on type of selection - foreach ($people as $person) { - if ($selection == 'bookedin' && $person->booking_status == 1) { - $defaults[] = $person->nid; - } - elseif ($selection == 'test' && $person->booking_lastname == 'Coad') { - $defaults[] = $person->nid; - } - } - //set return value via drupal_json_encode($var) - $replacementform_data['booking-email-default-ids'] = array ( - '#type' => 'hidden', - '#value' => drupal_json_encode($defaults), - '#prefix' => '
', - '#suffix' => '
', - '#attributes' => array('id' => 'booking_email_default_ids'), - ); - $output_html = render($replacementform_data['booking-email-default-ids']); - watchdog('booking_debug', "
Manual Email ajax html\n@info
", array('@info' => print_r( $output_html, true))); - - return array( - '#type' => 'ajax', - '#commands' => array( - ajax_command_replace("#booking_email_default_ids_wrapper", $output_html), - // This will call the command bookingEmailIDs in our custom JS file. - array('command' => 'bookingAjaxCheckboxes', - 'formDataElement' => 'booking_email_default_ids', - 'formName' => 'booking_manual_email_form', - 'checkboxName' => 'table', - ), - ) - ); + global $event; + $defaults = array(); + $replacementform_data = array(); + + //get type of selection from $form_state['values']['booking-email-preselection'] + $selection = $form_state['values']['booking-email-preselection']; + //load nodes + $people = booking_load_query(NULL, TRUE); + //populate $defaults based on type of selection + foreach ($people as $person) { + if ($selection == 'bookedin' && $person->booking_status == 1) { + $defaults[] = $person->nid; + } + elseif ($selection == 'test' && $person->booking_lastname == 'Coad') { + $defaults[] = $person->nid; + } + } + //set return value via drupal_json_encode($var) + $replacementform_data['booking-email-default-ids'] = array ( + '#type' => 'hidden', + '#value' => drupal_json_encode($defaults), + '#prefix' => '
', + '#suffix' => '
', + '#attributes' => array('id' => 'booking_email_default_ids'), + ); + $output_html = render($replacementform_data['booking-email-default-ids']); + watchdog('booking_debug', "
Manual Email ajax html\n@info
", array('@info' => print_r( $output_html, true))); + + return array( + '#type' => 'ajax', + '#commands' => array( + ajax_command_replace("#booking_email_default_ids_wrapper", $output_html), + // This will call the command bookingEmailIDs in our custom JS file. + array('command' => 'bookingAjaxCheckboxes', + 'formDataElement' => 'booking_email_default_ids', //name of the hidden form element that contains the json data + 'formName' => 'booking-manual-email-form', //note the dashes instead of underscores! + 'checkboxName' => 'table', //form element for tableselect + ), + ) + ); } /** * 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))); + $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(); + 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)); - _booking_registration_email($key, false, true); - } - elseif ($form_state['values']['email-type'] == 'initialtravelrequired') { - $message = t('Processing a manual initial travel form request email to id @info', array ('@info' => $key)); - _booking_travelform_initial_request_email($key); - } - elseif ($form_state['values']['email-type'] == 'remindertravelrequired') { - $message = t('Processing a manual reminder travel form request email to id @info', array ('@info' => $key)); - _booking_travelform_reminder_request_email($key); - } - elseif ($form_state['values']['email-type'] == 'balance') { - $message = t('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)); - _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)); - _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)); - _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)); - _booking_missedpayment_email($key); - } - elseif (strpos($form_state['values']['email-type'], 'customlogistics') !== false) { - $message = t('Processing a @custom type email from logistics to id @info', array ('@custom' => $form_state['values']['email-type'], '@info' => $key)); - _booking_custom_email($key, $form_state['values']['email-type'], 'logistics'); - } - 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)); - _booking_custom_email($key, $form_state['values']['email-type'], 'contact'); - } - //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', "
" . $final_message . "\n" . implode("\n", $update_messages) . "
"); - //watchdog('booking', "Sent manual email for $counter people."); + if ($person) + { + if ($form_state['values']['email-type'] == 'registration') { + $message = t('Processing a manual registration email to id @info', array ('@info' => $key)); + _booking_registration_email($key, false, true); + } + elseif ($form_state['values']['email-type'] == 'initialtravelrequired') { + $message = t('Processing a manual initial travel form request email to id @info', array ('@info' => $key)); + _booking_travelform_initial_request_email($key); + } + elseif ($form_state['values']['email-type'] == 'remindertravelrequired') { + $message = t('Processing a manual reminder travel form request email to id @info', array ('@info' => $key)); + _booking_travelform_reminder_request_email($key); + } + elseif ($form_state['values']['email-type'] == 'balance') { + $message = t('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)); + _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)); + _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)); + _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)); + _booking_missedpayment_email($key); + } + elseif (strpos($form_state['values']['email-type'], 'customlogistics') !== false) { + $message = t('Processing a @custom type email from logistics to id @info', array ('@custom' => $form_state['values']['email-type'], '@info' => $key)); + _booking_custom_email($key, $form_state['values']['email-type'], 'logistics'); + } + 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)); + _booking_custom_email($key, $form_state['values']['email-type'], 'contact'); + } + //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', "
" . $final_message . "\n" . implode("\n", $update_messages) . "
"); + //watchdog('booking', "Sent manual email for $counter people."); }