From 65463ecb76a9e69b2111222c579b5426924617d1 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Tue, 22 May 2018 10:19:29 +1000 Subject: [PATCH] work on better custom email definition form --- booking.constants.inc | 29 +++++++++++ booking.emails_admin.inc | 102 ++++++++++++++++++++++++++++++++++++++ booking.module | 13 ++++- booking.variety_admin.inc | 4 +- 4 files changed, 145 insertions(+), 3 deletions(-) diff --git a/booking.constants.inc b/booking.constants.inc index 14b3d67..7ecc3cc 100644 --- a/booking.constants.inc +++ b/booking.constants.inc @@ -1,5 +1,34 @@ 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) . " **Logistics**"; + } + + return $email_options_array; +} + /** * Helper function to provide a list of options for the state field of the registration form */ diff --git a/booking.emails_admin.inc b/booking.emails_admin.inc index d04a2bd..f0804b2 100644 --- a/booking.emails_admin.inc +++ b/booking.emails_admin.inc @@ -248,6 +248,108 @@ function booking_emails_workflow_admin() { return system_settings_form($form, FALSE); } +// TODO : Use ajax to select email definition instead of drawing so many WYSIWYG text editors which take ages to load +/** + * Hook form() to use ajax to allow admin user to define custom emails that can be sent by Bookings module + * + * @param + * @return form render array + */ +function booking_emails_custom_ajax_form($node, &$form_state) { + global $event; + $form = array(); + $data = $node; + + //$email_options_array = _booking_custom_email_types(); + //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) . " **Logistics**"; + } + + if(variable_get('booking_enable_html_mail', 0) == 1) { + $form_type = 'text_format'; + $form_format = 'full_html'; + } + else { + $form_type = 'textarea'; + $form_format = NULL; + } + + $form['email-type'] = array( + '#type' => 'select', + '#title' => t('Email Type'), + '#required' => TRUE, + '#default_value' => 'NULL', + '#options' => $email_options_array, + '#ajax' => array( + 'event' => 'change', + 'callback' => 'booking_emails_custom_ajax_form_callback', + 'wrapper' => 'booking_emails_custom_fieldset_wrapper', + ), + ); + + $form['email-definition'] = array( + '#type' => 'fieldset', + '#title' => 'Email Definition', + '#prefix' => '
', + '#suffix' => '
' + ); + + $form['email-definition']['booking_email_subjectline_custom'] = array ( + '#type' => 'textfield', + '#title' => t('Subject line for Custom Email'), + '#size' => 150, + '#maxlength' => 300, + '#default_value' => isset($form_state['values']['booking_email_subjectline_custom']) ? $form_state['values']['booking_email_subjectline_custom'] : '', + ); + $form['email-definition']['booking_email_body_custom'] = array( + '#title' => t('Email text for custom email'), + '#description' => t(''), + '#default_value' => isset($form_state['values']['booking_email_body_custom']) ? $form_state['values']['booking_email_body_custom'] : '', + '#type' => $form_type, + '#format' => $form_format, + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + + return array ( + 'form' => $form, + ); +} + +/** + * Callback function to display the custom email definition for form booking_emails_custom_ajax_form + */ +function booking_emails_custom_ajax_form_callback($form, &$form_state) { + global $event; + $text = ""; + $data = $form_state['input']; + + //check the selected email type + //configure the input text field and textarea based on select field + $emailtype = $form_state['input']['email-type']; + if (strpos($emailtype, 'custom') !== false) { + $subject = variable_get('booking_email_subject_' . $emailtype, ''); + $form['form']['email-definition']['booking_email_subjectline_custom']['#default_value'] = $subject; + + $text = variable_get('booking_email_' . $emailtype, ''); + $text = isset($text['format']) ? $text['value'] : $text; + $form['form']['email-definition']['booking_email_body_custom']['#default_value'] = $text; + } + + // Rebuild the form + $form_state['rebuild'] = TRUE; + return $form['form']; +} + /** * Function to allow admin user to define custom emails that can be sent by Bookings module * diff --git a/booking.module b/booking.module index 1fcfea7..df4611b 100644 --- a/booking.module +++ b/booking.module @@ -206,6 +206,17 @@ function booking_menu() { 'weight' => -98, //'type' => MENU_LOCAL_TASK, ); + + $items['admin/config/booking/emails/definitions'] = array( + 'title' => 'Booking module ajax custom email definitions', + 'description' => 'Configure custom emails used by the Booking module via AJAX', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('booking_emails_custom_ajax_form'), + 'access arguments' => array('access administration pages'), + 'file' => 'booking.emails_admin.inc', + 'type' => MENU_LOCAL_ACTION, + ); + $items['admin/config/booking/emails/custom'] = array( 'title' => 'Booking module custom email definitions', 'description' => 'Configure custom emails used by the Booking module', @@ -346,7 +357,7 @@ function booking_menu() { //'page arguments' => array('booking_manual_email'), 'access arguments' => array('access administration pages'), 'type' => MENU_NORMAL_ITEM, - ); + ); $items['admin/booking/manual-payments'] = array( 'title' => 'Manual Payment Processing', diff --git a/booking.variety_admin.inc b/booking.variety_admin.inc index e92abf4..5039e62 100644 --- a/booking.variety_admin.inc +++ b/booking.variety_admin.inc @@ -553,12 +553,12 @@ function booking_varietysessions_csv_report($timeslot_id) { array(':eid' => $event->eid)); $session_members = $session_members_query->fetchAll(); - watchdog('booking_debug', 'booking_varietysessions_csv_report session members:
@info
', array('@info' => print_r( $session_members, true))); + //watchdog('booking_debug', 'booking_varietysessions_csv_report session members:
@info
', array('@info' => print_r( $session_members, true))); //generate the row data foreach ($session_members as $member) { $session_ids = drupal_json_decode($member->booking_variety_ids); - watchdog('booking_debug', 'booking_varietysessions_csv_report person session ids:
@info
', array('@info' => print_r( $session_ids, true))); + //watchdog('booking_debug', 'booking_varietysessions_csv_report person session ids:
@info
', array('@info' => print_r( $session_ids, true))); //get the session id that matches our timeslot $sid = $session_ids[$timeslot_id];