'token_tree',
'#token_types' => array('booking'),
);
/*Text for emails*/
$form['emails'] = array(
'#type' => 'fieldset',
'#title' => 'Built-In Workflow Email Definitions',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
//if HTML mail is enabled, allow user to specify footer
if(variable_get('booking_enable_html_mail', 0) == 1) {
$form['emails']['booking_html_mail_footer'] = array(
'#title' => t('Footer text for HTML email'),
'#description' => t('Enter HTML to go in the footer of the email template (above the social media icons).
NOTE: No token subsitutions will be made here.'),
'#default_value' => isset(variable_get('booking_html_mail_footer')['value']) ? variable_get('booking_html_mail_footer')['value'] : variable_get('booking_html_mail_footer', '
'), '#type' => 'text_format', '#format' => 'full_html', ); } $form['emails']['booking_email_notification_text'] = array( '#title' => t('Notification Email'), '#description' => t('Email to send to the notification email address (defined in general configuration) when a person has registered'), '#default_value' => isset(variable_get('booking_email_notification_text')['value']) ? variable_get('booking_email_notification_text')['value'] : variable_get('booking_email_notification_text', '[booking:regn-summary]'), '#type' => $form_type, '#format' => $form_format, ); $form['emails']['booking_email_bookedin_text'] = array( '#title' => t('Registration Successful Email'), '#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' => isset(variable_get('booking_email_bookedin_text')['value']) ? variable_get('booking_email_bookedin_text')['value'] : variable_get('booking_email_bookedin_text', $default_email_text), '#type' => $form_type, '#format' => $form_format, ); $form['emails']['booking_email_regn_complete_text'] = array( '#title' => t('Payment Complete Email'), '#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' => isset(variable_get('booking_email_regn_complete_text')['value']) ? variable_get('booking_email_regn_complete_text')['value'] : variable_get('booking_email_regn_complete_text', $booking_email_regn_complete_text), '#type' => $form_type, '#format' => $form_format, ); $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.'), '#default_value' => isset(variable_get('booking_email_waitinglist_text')['value']) ? variable_get('booking_email_waitinglist_text')['value'] : variable_get('booking_email_waitinglist_text', $booking_email_waitinglist_text), '#type' => $form_type, '#format' => $form_format, ); $form['emails']['booking_email_partialpayment_received_text'] = array( '#title' => t('Email text to send a person thanking them for their partial payment'), '#description' => t(''), '#default_value' => isset(variable_get('booking_email_partialpayment_received_text')['value']) ? variable_get('booking_email_partialpayment_received_text')['value'] : variable_get('booking_email_partialpayment_received_text', ''), '#type' => $form_type, '#format' => $form_format, ); $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'), '#title' => t('Balance Outstanding Email Text'), '#default_value' => isset(variable_get('booking_email_paymentoutstanding_text')['value']) ? variable_get('booking_email_paymentoutstanding_text')['value'] : variable_get('booking_email_paymentoutstanding_text', $booking_email_paymentoutstanding_text), '#type' => $form_type, '#format' => $form_format, ); $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)'), '#description' => t(''), '#default_value' => isset(variable_get('booking_email_paymentoutstanding_married_text')['value']) ? variable_get('booking_email_paymentoutstanding_married_text')['value'] : variable_get('booking_email_paymentoutstanding_married_text', $booking_email_paymentoutstanding_married_text), '#type' => $form_type, '#format' => $form_format, ); $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 but they have an outstanding balance.'), '#description' => t(''), '#default_value' => isset(variable_get('booking_email_waitinglistpromotion')['value']) ? variable_get('booking_email_waitinglistpromotion')['value'] : variable_get('booking_email_waitinglistpromotion', $booking_email_waitinglistpromotion), '#type' => $form_type, '#format' => $form_format, ); $form['emails']['booking_email_waitinglistpromotion_fullypaid'] = array( '#title' => t('Email text to send a person on the waiting list when a spot opens up for them and they have already fully paid.'), '#description' => t(''), '#default_value' => isset(variable_get('booking_email_waitinglistpromotion_fullypaid')['value']) ? variable_get('booking_email_waitinglistpromotion_fullypaid')['value'] : variable_get('booking_email_waitinglistpromotion_fullypaid', $booking_email_waitinglistpromotion_fullypaid), '#type' => $form_type, '#format' => $form_format, ); $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'), '#description' => t(''), '#default_value' => isset(variable_get('booking_email_notcoming_demotion')['value']) ? variable_get('booking_email_notcoming_demotion')['value'] : variable_get('booking_email_notcoming_demotion', $booking_email_notcoming_demotion), '#type' => $form_type, '#format' => $form_format, ); $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'), '#description' => t('Email text to send a person who missed the payment deadline'), '#default_value' => isset(variable_get('booking_email_missedpayment')['value']) ? variable_get('booking_email_missedpayment')['value'] : variable_get('booking_email_missedpayment', ''), '#type' => $form_type, '#format' => $form_format, ); $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'))), '#default_value' => isset(variable_get('booking_email_travel_initial_email_text')['value']) ? variable_get('booking_email_travel_initial_email_text')['value'] : variable_get('booking_email_travel_initial_email_text', ''), '#type' => $form_type, '#format' => $form_format, ); $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'))), '#default_value' => isset(variable_get('booking_email_travel_reminder_email_text')['value']) ? variable_get('booking_email_travel_reminder_email_text')['value'] : variable_get('booking_email_travel_reminder_email_text', ''), '#type' => $form_type, '#format' => $form_format, ); $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'))), '#default_value' => isset(variable_get('booking_email_travel_complete_text')['value']) ? variable_get('booking_email_travel_complete_text')['value'] : variable_get('booking_email_travel_complete_text', ''), '#type' => $form_type, '#format' => $form_format, ); //let the builtin hook do all the hard work 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' => '
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['waitinglistpromotion'] = 'Position Available (Balance outstanding)'; $email_options_array['waitinglistpromotionfullypaid'] = 'Position Available (Fully Paid)'; $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['notpaid'] = 'People who have not yet paid'; $preselection_options['bookedin'] = 'People who are booked-in'; $preselection_options['waitinglist'] = 'People on waiting list'; $preselection_options['unpaid'] = 'People booked-in with outstanding balance'; $preselection_options['refundreqd'] = 'Refund Required'; $preselection_options['notravelform'] = "People booked-in no travel form received"; $preselection_options['notravelforminclwaiting'] = "People booked-in/waiting no travel form received"; $preselection_options['leaderhelper'] = "Leaders/Helpers"; $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'), ); //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**"; } //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"; $form['pretext'] = array( '#type' => 'container', '#children' => $prefix, ); //@todo add booking prefix $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_email_get_preview_callback', 'wrapper' => 'booking_email_preview_wrapper', ), ); $form['booking-email-default-ids'] = array ( '#type' => 'hidden', '#value' => "[]", '#prefix' => 'No email type selected.", '#prefix' => '
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-bottom'] = array ( '#type' => 'submit', '#value' => t('Send Email'), ); return array ( /* 'first_para' => array ( '#type' => 'markup', '#markup' => $prefix, ), */ 'form' => $form, ); } /** * Callback to update preview of email that will be sent * */ function _booking_email_get_preview_callback($form, $form_state) { global $event; $text = ""; $emailtype = $form_state['values']['email-type']; switch ($emailtype) { case "registration": $text = variable_get('booking_email_bookedin_text'); break; case "balance": $text = variable_get('booking_email_paymentoutstanding_text'); // perform the checking of HTML value now since we're pre-pending text to it $text = isset($text['format']) ? $text['value'] : $text; if (variable_get('booking_enable_combined_pricing', 0) == 1) { // no
tags necessary if its a HTML mail if(variable_get('booking_enable_html_mail', 0) == 1) { $text .= "\nIf married
\n"; } else { $text .= "\n
"; } $married_text = variable_get('booking_email_paymentoutstanding_married_text'); // repeat HTML check for rest of preview $text .= isset($married_text['format']) ? $married_text['value'] : $married_text; } break; case "complete": $text = variable_get('booking_email_regn_complete_text'); break; case "withdrawal": $text = variable_get('booking_email_notcoming_demotion'); break; case "missedpayment": $text = variable_get('booking_email_missedpayment'); break; case "initialtravelrequired": $text = variable_get('booking_email_travel_initial_email_text'); break; case "remindertravelrequired": $text = variable_get('booking_email_travel_reminder_email_text'); break; case "travelcomplete": $text = variable_get('booking_email_travel_complete_text'); break; case "waitinglistpromotion": $text = variable_get('booking_email_waitinglistpromotion'); break; case "waitinglistpromotionfullypaid": $text = variable_get('booking_email_waitinglistpromotion_fullypaid'); break; } //handle custom email types if (strpos($emailtype, 'custom') !== false) { $text = variable_get('booking_email_' . $form_state['values']['email-type']); } //use the html value if it is set, otherwise use the plaintext input which is just a string $text = isset($text['format']) ? $text['value'] : $text; //watchdog('booking_debug', "Email generation:\n@info", array('@info' => print_r( $text, true))); if(variable_get('booking_enable_html_mail', 0) == 1) { $markup_pre = ""; } else { $markup_pre = "Email Preview
"; $markup_post = ""; } //generate html that will be used to update div booking_email_preview_wrapper return $markup_pre . $text . $markup_post; } /** * Callback to update hidden form value with default checkbox details * * Callback element needs only select the portion of the form to be updated. * Since #ajax['callback'] return can be HTML or a renderable array (or an * array of commands), we can just return a piece of the form. * 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) { switch ($selection) { case 'notpaid': if ($person->booking_status == 0) { $defaults[] = $person->nid; } break; case 'bookedin': if ($person->booking_status == 1) { $defaults[] = $person->nid; } break; case 'waitinglist': if ($person->booking_status == 2) { $defaults[] = $person->nid; } break; case 'refundreqd': if ($person->booking_status == 3 && $person->booking_refund_processed == 'N') { $defaults[] = $person->nid; } break; case 'unpaid': if ($person->booking_payment_complete == 'N' && $person->booking_status == 1) { $defaults[] = $person->nid; } break; case 'notravelform': if ($person->booking_status == 1 && $person->tid == 0) { $defaults[] = $person->nid; } break; case 'notravelforminclwaiting': if (($person->booking_status == 1 || $person->booking_status == 2) && $person->tid == 0) { $defaults[] = $person->nid; } break; case 'leaderhelper': foreach ($person as $key => $value) { if (preg_match('/^session(\d+)_role/', $key, $matches) && $value > 0) { //don't add the person multiple times if they're leading/helping multiple groups if (! in_array($person->nid, $defaults)) { $defaults[] = $person->nid; } } } break; } //end switch } //loop attendees //create new hidden form element to return $replacementform_data['booking-email-default-ids'] = array ( '#type' => 'hidden', '#value' => drupal_json_encode($defaults), //encode the data as json so we can process it with jQuery '#prefix' => 'Email Preview
"; $markup_post = "', '#suffix' => '', '#attributes' => array('id' => 'booking_email_default_ids'), ); $output_html = render($replacementform_data['booking-email-default-ids']); $feedback_html = t("Number of people selected: !num", array('!num' => count($defaults))); //watchdog('booking_debug', "Manual Email ajax html\n@info", array('@info' => print_r( $output_html, true))); //return a sequence of commands to run return array( '#type' => 'ajax', '#commands' => array( ajax_command_replace("#booking_email_default_ids_wrapper", $output_html), ajax_command_replace("#booking_email_preselection_suffix_wrapper", $feedback_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))); 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 ($form_state['values']['email-type'] == 'waitinglistpromotion') { $message = t('Processing a manual waitinglistpromotion email to id @info', array ('@info' => $key)); _booking_promoted_from_waitinglist_email($key); } elseif ($form_state['values']['email-type'] == 'waitinglistpromotionfullypaid') { $message = t('Processing a manual waitinglistpromotionfullypaid email to id @info', array ('@info' => $key)); _booking_promoted_from_waitinglist_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."); }