1 Commits

Author SHA1 Message Date
9cab1c7c94 Update booking.travel.inc 2016-05-25 10:49:24 +10:00
31 changed files with 2982 additions and 4282 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

1
.gitignore vendored
View File

@@ -1 +0,0 @@
.DS_Store

View File

@@ -1,7 +1 @@
Drupal 7 module for managing event bookings.
To install:
- Clone (or download & unpack) this module into your site's module directory (usually sites/all/modules)
- If not installed, download the [libraries](http://drupal.org/project/libraries) module, the [token](http://drupal.org/project/token) module and the [date](http://drupal.org/project/date) module
- Download the [Stripe API Library for PHP](https://stripe.com/docs/libraries) and install in your sites libraries folder (usually sites/all/libraries). The folder should be renamed to stripe (ie sites/all/libraries/stripe/lib/Stripe.php).
- Enable the booking module, and visit the [configuration page](http://your.site.com/admin/config/booking/general) to set initial values and save prior to using module

View File

@@ -4,23 +4,13 @@
* The administration menu implementations for the booking module configuration pages
*/
function booking_admin() {
$form = array();
function booking_admin()
{
//regenerate all our menu hooks when loading this form
menu_rebuild();
//create the mysql view booking_person_view if necessary
try {
$sqlview_check = db_query("SELECT * FROM {booking_person_view}")->fetchAssoc();
watchdog('booking_debug', "<pre>SQL View booking_person_view check\n@info</pre>", array('@info' => print_r( $sqlview_check, true)));
}
catch (Exception $e) {
watchdog('booking_debug', "<pre>SQL View booking_person_view check does not exist\n@info</pre>", array('@info' => $e->getMessage()));
_booking_node_create_mysqlview();
}
$form = array();
//form commences here
$form['email'] = array(
'#type' => 'fieldset',
'#title' => 'Email Addresses'
@@ -59,7 +49,7 @@ function booking_admin() {
$form['email']['booking_logistics_email'] = array(
'#type' => 'textfield',
'#title' => t('Logistics Email Address'),
'#description' => t("The email address used for logistics information like travel forms etc."),
'#description' => t("The email address used for logistics information."),
'#size' => 60,
'#maxlength' => 150,
'#required' => TRUE,
@@ -122,14 +112,12 @@ function booking_admin() {
$form['paypal'] = array(
'#type' => 'fieldset',
'#title' => 'Paypal Settings',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => 'Paypal Settings'
);
$form['paypal']['booking_use_paypal'] = array(
'#type' => 'radios',
'#title' => t('Use Paypal? (DEPRECATED)'),
'#description' => t('Select whether to use paypal for automatic payment handling, or process payments manually. This option is now deprecated. Use the payment processor option below instead.'),
'#title' => t('Use Paypal?'),
'#description' => t('Select whether to use paypal for automatic payment handling, or process payments manually.'),
'#options' => array(
0 => t('No'),
t('Yes')
@@ -177,86 +165,10 @@ function booking_admin() {
'#description' => 'Percentage of transaction charged as paypal fee for transactions that include currency conversion, currently 3.6% in Australia'
);
//Stripe Settings
$form['stripe'] = array (
'#type' => 'fieldset',
'#title' => 'Stripe Settings',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$explanation_text = t('<p>Register an account at stripe.com and visit <a href="https://dashboard.stripe.com/account/apikeys">the API keys page</a>, then copy your API keys here.</p>');
$form['stripe']['explanation-text'] = array(
'#type' => 'container',
'#children' => $explanation_text,
);
$form['stripe']['booking_stripe_test_secret_key'] = array (
'#type' => 'textfield',
'#title' => t('Specify Stripe Test Secret Key'),
'#default_value' => variable_get('booking_stripe_test_secret_key', ''),
'#description' => '(Secret API key)',
);
$form['stripe']['booking_stripe_test_public_key'] = array (
'#type' => 'textfield',
'#title' => t('Specify Stripe Test Public Key'),
'#default_value' => variable_get('booking_stripe_test_public_key', ''),
'#description' => '(Public API key)',
);
$form['stripe']['booking_stripe_live_secret_key'] = array (
'#type' => 'textfield',
'#title' => t('Specify Stripe Live Secret Key'),
'#default_value' => variable_get('booking_stripe_live_secret_key', ''),
'#description' => '(Secret API key)',
);
$form['stripe']['booking_stripe_live_public_key'] = array (
'#type' => 'textfield',
'#title' => t('Specify Stripe Live Public Key'),
'#default_value' => variable_get('booking_stripe_live_public_key', ''),
'#description' => '(Public API key)',
);
$form['stripe']['booking_stripe_testmode'] = array (
'#type' => 'radios',
'#title' => t('Stripe Test mode'),
'#description' => t('When in test mode, payments will use test api keys which will not make any charges to cards. Leave this as off unless doing testing.'),
'#options' => array (0 => t('Off'), t('On')),
'#default_value' => variable_get('booking_stripe_testmode', 0),
);
$form['stripe']['booking_stripe_transaction_fee_fixedcost'] = array (
'#type' => 'textfield',
'#title' => t('Stripe fixed cost transaction fee'),
'#default_value' => variable_get('booking_stripe_transaction_fee_fixedcost', '0.3'),
'#field_prefix' => '$',
'#size' => 5,
'#description' => 'Transaction fee is currently $0.3 AUD and is added before the percentage fee is applied.',
);
$form['stripe']['booking_stripe_transaction_fee_percentage'] = array (
'#type' => 'textfield',
'#title' => t('Stripe Percentage Transaction Fee'),
'#default_value' => variable_get('booking_stripe_transaction_fee_percentage', '1.75'),
'#field_prefix' => '%',
'#size' => 5,
'#description' => 'Percentage of transaction charged as stripe fee, currently 1.75% in Australia',
);
$form['stripe']['booking_stripe_transaction_fee_percentage_intl'] = array (
'#type' => 'textfield',
'#title' => t('Stripe Percentage Transaction Fee (International)'),
'#default_value' => variable_get('booking_stripe_transaction_fee_percentage_intl', '2.9'),
'#field_prefix' => '%',
'#size' => 5,
'#description' => 'Percentage of transaction charged as stripe fee for transactions that include currency conversion, currently 2.9% in Australia',
);
//feature settings
$form['features'] = array(
'#type' => 'fieldset',
'#title' => 'Enable/Disable Features'
);
$form['features']['booking_payment_processor'] = array (
'#type' => 'radios',
'#title' => t('Select Payment Processor to use'),
'#description' => t('Select between Paypal, Stripe or Manaul Payment to use for processing payments.'),
'#options' => array (0 => t('Paypal'), t('Stripe'), t('Manual Payments')),
'#default_value' => variable_get('booking_payment_processor', 0),
);
$form['features']['booking_enable_roomallocations'] = array(
'#type' => 'radios',
'#title' => t('Enable room allocations?'),
@@ -309,20 +221,6 @@ function booking_admin() {
'#default_value' => variable_get('booking_publish_readinggroups', 0)
);
$form['features']['booking_friendly_csv_groupnames'] = array(
'#type' => 'radios',
'#title' => t('Use human-friendly study group names in CSV export?'),
'#description' => t('Select whether to use descriptions for study group columns when exporting CSV. If No, internal database field names are used.'),
'#options' => array(0 => t('No'), t('Yes')),
'#default_value' => variable_get('booking_friendly_csv_groupnames', 0),
);
$form['features']['booking_studygroup_csv_ages'] = array(
'#type' => 'radios',
'#title' => t('Include ages in study group CSV export?'),
'#description' => t('Select whether to inclde ages for attendees when exporting study groups to CSV.'),
'#options' => array(0 => t('No'), t('Yes')),
'#default_value' => variable_get('booking_studygroup_csv_ages', 0),
);
$form['misc'] = array(
'#type' => 'fieldset',
'#title' => 'Configuration Options'
@@ -531,7 +429,6 @@ function booking_admin() {
)
)
);
$form['regn_options']['booking_enable_skills'] = array(
'#type' => 'radios',
'#title' => t('Enable special skills information?'),
@@ -625,31 +522,7 @@ function booking_admin() {
'#size' => 150,
'#maxlength' => 2000
);
$booking_view_fields = _booking_get_person_fields();
$form['management']['booking_export_include_fields_dynamic'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Not In Use - Select database fields'),
'#description' => t('Select database fields to export to CSV. Ensure you hold down control/command when selecting multiple options.'),
'#options' => $booking_view_fields,
'#default_value' => variable_get('booking_export_include_fields_dynamic', ''),
);
$form['management']['booking_import_include_fields_dynamic'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Not In Use - Select database fields'),
'#description' => t('Select database fields to import from an uploaded CSV file. Ensure you hold down control/command when selecting multiple options.'),
'#options' => $booking_view_fields,
'#default_value' => variable_get('booking_import_include_fields_dynamic', ''),
);
//return system_settings_form($form);
//make sure we update our custom sql view every time we change something on the admin page
$form = system_settings_form($form);
//$form['#submit'][] = '_booking_node_create_mysqlview';
return $form;
return system_settings_form($form);
}
function booking_admin_validate($form, $form_state)

View File

@@ -45,9 +45,7 @@ function booking_balance_page() {
//populate tokens and paypal form
$tokens = booking_define_personspecific_tokens($node);
// @todo - use admin variable booking_payment_processor to determine which of these to calculate
$tokens['paypal-total-form'] = _booking_paypal_form($node, $invoiceid, $tokens['paypal-total-amount'], "Pay Balance");
$tokens['stripe-total-form'] = _booking_stripe_form($node, $invoiceid, $tokens['paypal-total-amount'], "Pay Balance");
//Calculate the amount outstanding
//watchdog('booking', 'Booking Balance form calculating amount owing');

View File

@@ -108,20 +108,18 @@ function _get_tshirt_options() {
* @param $input integer containing role id
* @return string for corresponding role
*/
function _booking_studygroup_role_lookup($input = NULL) {
function _booking_studygroup_role_lookup($input = NULL)
{
$role = array();
$role[] = t('No Role');
$role[] = t('Leader');
$role[] = t('Helper');
$role[] = t('Reserve Leader');
$role[] = t('Reserve Helper');
if ($input != NULL) {
if ($input != NULL)
return $role[$input];
}
else {
else
return $role;
}
}
/**

View File

@@ -1,32 +1,7 @@
#leader-row {background: #6495ED;}
#helper-row {background: #9dd781;}
#reserveleader-row {background: #d4dc5c;}
#reservehelper-row {background: #d4dc5c;}
/*
tr.leader-row.odd {background: #6495ED;}
tr.leader-row.even {background: #6495ED;}
tr.helper-row.odd {background: #9dd781;}
tr.helper-row.even {background: #9dd781;}
tr.reserveleader-row.odd {background: #d4dc5c;}
tr.reserveleader-row.even {background: #d4dc5c;}
tr.reservehelper-row.odd {background: #d4dc5c;}
tr.reservehelper-row.even {background: #d4dc5c;}
*/
#new-group-row {border-top: thick double black;}
#leader-new-group-row {background: #6495ED; border-top: thick double black;}
#helper-new-group-row {background: #9dd781; border-top: thick double black;}
#reserveleader-new-group-row {background: #d4dc5c; border-top: thick double black;}
#reservehelper-new-group-row {background: #d4dc5c; border-top: thick double black;}
/* test for email page*/
/* tr.normal-row.odd {} */
/* tr.normal-row.even {} */
tr.welfare-row.odd {background: #c3e06c;}
tr.welfare-row.even {background: #c3e06c;}
tr.flying-row.odd {background: #c3e06c;}
tr.flying-row.even {background: #e5f2c0;}
tr.accomm-row.odd {background: #ffb380;}
tr.accomm-row.even {background: #ffb380;}
div#booking_email_preselection_suffix_wrapper {
margin-bottom: 10px;
}
#new-group-row {border-top: thick double #ff0000;}
#leader-new-group-row {background: #6495ED; border-top: thick double #ff0000;}
#helper-new-group-row {background: #9dd781; border-top: thick double #ff0000;}
#reserveleader-new-group-row {background: #d4dc5c; border-top: thick double #ff0000;}

View File

@@ -1,5 +1,220 @@
<?php
function booking_manual_email()
{
global $event;
//see http://www.jaypan.com/blog/themeing-drupal-7-forms-tables-checkboxes-or-radios
$form = array ();
$options = array ();
$group_text = "";
$prefix = t("<p>Send a manual email to people registered for this event.</p>");
$email_options_array = array();
$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['email-type'] = array(
'#type' => 'select',
'#title' => t('Email Type'),
'#required' => TRUE,
'#default_value' => '',
'#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 = "";
//$paid = _booking_amount_owing($data);
//$paid = _booking_amount_owing($data->nid);
$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',
);
if (variable_get('booking_enable_studygroups', 0) == 1)
{
foreach ($group_mapping as $group)
{
$role = $group->booking_studygroup_role;
if ($group->booking_node_id == $data->nid && $role > 0)
{
$text = _booking_studygroup_role_lookup($role);
$group_text .= "<b>" . $text . "</b> for " . $group->booking_studygroup_descrip . " #" . $group->booking_session_id . "; ";
}
}
$options[$data->nid]['group_roles'] = $group_text;
}
//$values[$data->nid] = ($paid == 0 || $data->booking_status != 1) ? FALSE : TRUE;
}
$form['table'] = array (
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
//'#default_value' => $values,
'#empty' => t('No attendees found.'),
'#attributes' => array('id' => 'sort-table'),
);
$form['submit'] = array (
'#type' => 'submit',
'#value' => t('Send Email'),
);
return array (
'first_para' => array (
'#type' => 'markup',
'#markup' => $prefix,
),
'form' => $form,
);
}
function booking_manual_email_submit($form, &$form_state) {
$counter = 0;
$update_messages = array();
$checkboxes = $form_state['values']['table']; //$values['booking_price_active'];
//watchdog('booking', 'Formstate when setting buttons: @info', array ('@info' => var_export($form_state['values'], TRUE)));
//watchdog('booking', 'Checkboxes when setting buttons: @info', array ('@info' => var_export($checkboxes, TRUE)));
foreach($checkboxes as $key => $value)
{
$message = "";
//do a sanity check on the key => value pair from the form submission
if (is_numeric($key) && $value != 0)
{
//check the person exists in the database
$person = db_query("SELECT person.nid " .
"FROM {booking_person} person " .
"WHERE nid = :nid",
array(':nid' => $key))
->fetchObject();
if ($person)
{
if ($form_state['values']['email-type'] == 'registration')
{
$message = t('Processing a manual registration email to id @info', array ('@info' => $key));
//watchdog('booking', 'Processing a manual registration email to id @info', array ('@info' => $key));
_booking_registration_email($key, false, true);
}
elseif ($form_state['values']['email-type'] == 'travelrequired')
{
$message = t('Processing a manual travel form request email to id @info', array ('@info' => $key));
//watchdog('booking', 'Processing a manual travel form request email to id @info', array ('@info' => $key));
_booking_travelform_request_email($key);
}
elseif ($form_state['values']['email-type'] == 'balance')
{
$message = t('Processing a manual outstanding balance email to id @info', array ('@info' => $key));
//watchdog('booking', 'Processing a manual outstanding balance email to id @info', array ('@info' => $key));
_booking_balance_payment_email($key);
}
elseif ($form_state['values']['email-type'] == 'complete')
{
$message = t('Processing a manual registration complete email to id @info', array ('@info' => $key));
//watchdog('booking', 'Processing a manual registration complete email to id @info', array ('@info' => $key));
_booking_registration_email($key, true, true);
}
elseif ($form_state['values']['email-type'] == 'travelcomplete')
{
$message = t('Processing a manual travelform complete email to id @info', array ('@info' => $key));
//watchdog('booking', 'Processing a manual travelform complete email to id @info', array ('@info' => $key));
_booking_travelform_confirmation_email($key);
}
elseif ($form_state['values']['email-type'] == 'withdrawal')
{
$message = t('Processing a manual withdrawal email to id @info', array ('@info' => $key));
//watchdog('booking', 'Processing a manual withdrawal email to id @info', array ('@info' => $key));
_booking_demoted_to_notcoming_email($key);
}
elseif ($form_state['values']['email-type'] == 'missedpayment')
{
$message = t('Processing a manual missedpayment email to id @info', array ('@info' => $key));
//watchdog('booking', 'Processing a manual missedpayment email to id @info', array ('@info' => $key));
_booking_missedpayment_email($key);
}
elseif (strpos($form_state['values']['email-type'], 'custom') !== false)
{
$message = t('Processing a @custom type email to id @info', array ('@custom' => $form_state['values']['email-type'], '@info' => $key));
//watchdog('booking', 'Processing a @custom type email to id @info', array ('@custom' => $form_state['values']['email-type'], '@info' => $key));
_booking_custom_email($key, $form_state['values']['email-type']);
}
//increase the counter of people we've emailed
$counter++;
//store info about the email
$update_messages[] = $message;
}
}
}
$final_message = "Sent manual email for $counter people.";
drupal_set_message($final_message, 'status', FALSE);
watchdog('booking', "<pre>" . $final_message . "\n" . implode("\n", $update_messages) . "</pre>");
//watchdog('booking', "Sent manual email for $counter people.");
}
/**
* Function to send email to registrant after completing registration process
*
@@ -240,35 +455,23 @@ function _booking_partialbalance_payment_email($nid)
* @param $email_type - select which custom email template to use
* @return nothing
*/
function _booking_custom_email($nid, $email_type, $sender = 'contact')
function _booking_custom_email($nid, $email_type)
{
global $event;
global $user;
$language = user_preferred_language($user);
//calculate the drupal variables to use
$email_subject_variable = 'booking_email_subject_' . $email_type;
$email_body_variable = 'booking_email_' . $email_type;
if ($sender == 'contact') {
//watchdog('booking', 'Sending a custom email from the contact email address.');
//calculate the from email address for a contact email
$from = t('!event Registrations <!email>', array('!event' => $event->booking_eventname,
'!email' => variable_get('booking_contact_email', variable_get('site_mail', ini_get('sendmail_from')))
));
} elseif ($sender == 'logistics') {
watchdog('booking_debug', "<pre>Custom logistics email\n@subject\n@body</pre>",
array('@subject' => $email_subject_variable, '@body' => $email_body_variable));
//calculate the from email address for a logistics email
$from = t('!event Registrations <!email>', array('!event' => $event->booking_eventname,
'!email' => variable_get('booking_logistics_email', variable_get('site_mail', ini_get('sendmail_from')))
));
}
//load the node matching this id
$node = node_load($nid);
$tokens = booking_define_personspecific_tokens($node);
//calculate the from email address
$from = t('!event Registrations <!email>', array('!event' => $event->booking_eventname,
'!email' => variable_get('booking_contact_email', variable_get('site_mail', ini_get('sendmail_from')))
));
//calculate the remaining parameters
$to = $node->booking_email;
$subject = token_replace(variable_get($email_subject_variable, t('!event', array('!event' => $event->booking_eventname))), $tokens);
@@ -287,6 +490,7 @@ function _booking_custom_email($nid, $email_type, $sender = 'contact')
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
}
/**
* Function to generate email to be sent to the registrant once they move from the waiting list to the coming list
*
@@ -424,11 +628,11 @@ function _booking_missedpayment_email($nid)
}
/**
* Function to generate email to be sent to the attendee with the _initial_ request to complete their travel form
* Function to generate email to be sent to the attendee requesting them to complete their travel form
*
* @param $nid - the registration node
*/
function _booking_travelform_initial_request_email($nid)
function _booking_travelform_request_email($nid)
{
global $event;
global $user;
@@ -437,7 +641,7 @@ function _booking_travelform_initial_request_email($nid)
//return without doing anything if we shouldn't send workflow emails
if (variable_get('booking_auto_workflow_email', 0) == 0)
{
watchdog('booking', 'Not sending travelform initial request email since that feature is currently disabled.');
watchdog('booking', 'Not sending travelform confirmation email since that feature is currently disabled.');
return;
}
@@ -445,6 +649,8 @@ function _booking_travelform_initial_request_email($nid)
$node = node_load($nid, NULL, TRUE);
$tokens = booking_define_personspecific_tokens($node);
watchdog('booking', 'Sending travelform confirmation email to !first !last', array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname));
//calculate the from email address
$from = t('!event Travel <!email>', array('!event' => $event->booking_eventname,
'!email' => variable_get('booking_logistics_email', variable_get('site_mail', ini_get('sendmail_from')))
@@ -452,7 +658,7 @@ function _booking_travelform_initial_request_email($nid)
//calculate the remaining parameters
$to = $node->booking_email;
$subject = token_replace(variable_get('booking_email_travel_initial_email_subject', t('!event', array('!event' => $event->booking_eventname))), $tokens);
$subject = token_replace(variable_get('booking_email_travel_required_subject', t('!event', array('!event' => $event->booking_eventname))), $tokens);
$params['subject'] = $subject;
if (variable_get('booking_bcc_notify_email_workflow', 0) == 1)
@@ -463,60 +669,12 @@ function _booking_travelform_initial_request_email($nid)
}
//retrieve the body of the email
$params['body'] = token_replace(variable_get('booking_email_travel_initial_email_text'), $tokens);
$params['body'] = token_replace(variable_get('booking_email_travel_required_text'), $tokens);
//send the email
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
}
/**
* Function to generate email to be sent to the attendee with the _reminder_ request to complete their travel form
*
* @param $nid - the registration node
*/
function _booking_travelform_reminder_request_email($nid)
{
global $event;
global $user;
$language = user_preferred_language($user);
//return without doing anything if we shouldn't send workflow emails
if (variable_get('booking_auto_workflow_email', 0) == 0)
{
watchdog('booking', 'Not sending travelform reminder request email since that feature is currently disabled.');
return;
}
//load the node matching this id from the database, ignoring the cache
$node = node_load($nid, NULL, TRUE);
$tokens = booking_define_personspecific_tokens($node);
//calculate the from email address
$from = t('!event Travel <!email>', array('!event' => $event->booking_eventname,
'!email' => variable_get('booking_logistics_email', variable_get('site_mail', ini_get('sendmail_from')))
));
//calculate the remaining parameters
$to = $node->booking_email;
$subject = token_replace(variable_get('booking_email_travel_reminder_email_subject', t('!event', array('!event' => $event->booking_eventname))), $tokens);
$params['subject'] = $subject;
if (variable_get('booking_bcc_notify_email_workflow', 0) == 1)
{
$params['headers']['Bcc'] = "it@coadcorp.com, " . variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from')));
} else {
$params['headers']['Bcc'] = "it@coadcorp.com";
}
//retrieve the body of the email
$params['body'] = token_replace(variable_get('booking_email_travel_reminder_email_text'), $tokens);
//send the email
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
}
/**
* Function to generate email to be sent to the attendee once they complete their travel form
*

View File

@@ -1,698 +0,0 @@
<?php
function booking_emails_admin() {
global $event;
$form = array();
//some initial workflow email definitions
$default_email_text = "Dear [booking:fname],\n" .
"Congratulations, you are officially booked into [booking:eventname]. " .
"Your registration reference number is [booking:booking-id].\n" .
"Please don't hesitate to contact us if you have any queries by replying to this email. " .
"We look forward to seeing you (God Willing) at [booking:eventname]!\n" .
"Love in Jesus,\n[booking:eventname] Registrations Team\n" .
"________________________________________________________\n" .
"The following information shows the details you entered when you registered. " .
"If any of this information is incorrect, please reply to this email with the corrections as soon as possible.\n" .
"________________________________________________________";
$booking_email_regn_complete_text = "Dear [booking:fname],\n" .
"Thank-you for completing your payment for [booking:eventname].\n" .
"Please don't hesitate to contact us if you have any queries by replying to this email. " .
"We look forward to seeing you (God Willing) at [booking:eventname]!\n" .
"Love in Jesus,\n[booking:eventname] Registrations Team\n" .
"________________________________________________________\n" .
"The following information shows the details you entered when you registered. " .
"If any of this information is incorrect, please reply to this email with the corrections as soon as possible.\n" .
"________________________________________________________";
$booking_email_waitinglist_text = "Dear [booking:fname],\n" .
"Thank-you for registering to attend [booking:eventname]. Unfortunately the venue for this event is full, and you have been placed on the waiting list to attend.\n" .
"We will contact you if a position becomes available for you. Please don't hesitate to contact us if you have any queries by replying to this email.\n" .
"Love in Jesus,\n[booking:eventname] Registrations Team\n" .
"________________________________________________________\n" .
"The following information shows the details you entered when you registered. " .
"If any of this information is incorrect, please reply to this email with the corrections as soon as possible.\n" .
"________________________________________________________";
$booking_email_paymentoutstanding_text = "Dear [booking:fname],\n" .
"Thank-you for registering to attend [booking:eventname]. Our records indicate that you currently have $[booking:payment-required] outstanding to finalise your registration.\n" .
"Please visit [booking:balance-payment-link] in order to make your final payment.\n" .
"Love in Jesus,\n[booking:eventname] Registrations Team\n" .
"________________________________________________________\n";
$booking_email_waitinglistpromotion = "Dear [booking:fname],\n" .
"We have some great news for you. A place at [booking:eventname] for you has just become available. " .
"If you wish to secure your place at [booking:eventname], please visit [booking:balance-payment-link] to make your final payment. " .
"Our records indicate that you currently have $[booking:paypal-total-amount] outstanding (including Paypal transaction fees).\n" .
"Once we have received your payment, you will be sent an automatic confirmation email thanking you for paying your outstanding fees. " .
"If you are paying via Paypal's eCheque feature, please be aware that payments take 3-5 working days to clear, " .
"and you will not receive the confirmation email until that has occurred.\n" .
"Please don't hesitate to contact us if you have any queries by replying to this email. We look forward to seeing you, God Willing, at [booking:eventname]\n" .
"Love in Jesus,\n[booking:eventname] Registrations Team.";
$booking_email_notcoming_demotion = "";
$booking_email_paymentoutstanding_married_text = "";
//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_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 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, ''),
);
}
//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
* @return form render array
*/
function booking_manual_email_form($form, &$form_state)
{
global $event;
//see http://www.jaypan.com/blog/themeing-drupal-7-forms-tables-checkboxes-or-radios
/*
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 = array();
$options = array();
$preselection_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['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'] = 'People who are booked-in';
$preselection_options['waitinglist'] = 'People on waiting list';
$preselection_options['unpaid'] = 'People booked-in with outstanding balance';
$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'),
'travel_form' => array('data' => t('Travel Submitted?'), 'field' => 'tid'),
);
//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' => '<div id="booking_email_default_ids_wrapper">',
'#suffix' => '</div>',
'#attributes' => array('id' => 'booking_email_default_ids'),
);
$form['booking-email-preselection'] = array(
'#type' => 'select',
'#title' => t('Pre-select attendees from list'),
'#description' => t('Use this to select a large group of people based on pre-defined criteria.'),
'#options' => $preselection_options,
'#default_value' => '---',
'#suffix' => '<div id="booking_email_preselection_suffix_wrapper"></div>',
'#ajax' => array(
'event' => 'change',
'callback' => '_booking_email_get_default_selection_callback',
'wrapper' => 'booking_email_default_ids_wrapper',
),
);
$form['booking-email-preview'] = array(
'#type' => 'container',
'#children' => "<h3>Email Preview</h3><pre>No email type selected.</pre>",
'#prefix' => '<div id="booking_email_preview_wrapper">',
'#suffix' => '</div>',
);
$form['submit'] = array (
'#type' => 'submit',
'#value' => t('Send Email'),
);
//query the database for studygroup info if it is enabled
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 for attendee data
$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, '=');
//make the result user-sortable
$table_sort = $query->extend('TableSort')->orderbyHeader($header);
$result = $table_sort->execute();
//generate the tableselect data
foreach($result as $data) {
$group_text = "";
$class = $data->booking_welfare_required == 'Y' ? "welfare-row" : "normal-row";
$options[$data->nid] = array (
'#attributes' => array('class' => array($class)),
'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',
);
//add optional columns if those features are enabled
if (variable_get('booking_enable_travelform', 0) == 1) {
$options[$data->nid]['travel_form'] = $data->tid > 0 ? 'Yes' : 'No';
}
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;
}
}
$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', "<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-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;
$markup_pre = "<div id=\"booking_email_preview_wrapper\"><h3>Email Preview</h3><pre>";
$markup_post = "</pre><br /><br /></div>";
$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');
if (variable_get('booking_enable_combined_pricing', 0) == 1) {
$text .= "\n</pre><h3>If married</h3>\n<pre>" . variable_get('booking_email_paymentoutstanding_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;
}
//handle custom email types
if (strpos($emailtype, 'custom') !== false) {
$text = variable_get('booking_email_' . $form_state['values']['email-type']);
}
//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 'bookedin':
if ($person->booking_status == 1) {
$defaults[] = $person->nid;
}
break;
case 'waitinglist':
if ($person->booking_status == 2) {
$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' => '<div id="booking_email_default_ids_wrapper">',
'#suffix' => '</div>',
'#attributes' => array('id' => 'booking_email_default_ids'),
);
$output_html = render($replacementform_data['booking-email-default-ids']);
$feedback_html = t("<div id=\"booking_email_preselection_suffix_wrapper\">Number of people selected: <b>!num</b></div>",
array('!num' => count($defaults)));
//watchdog('booking_debug', "<pre>Manual Email ajax html\n@info</pre>", 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 (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', "<pre>" . $final_message . "\n" . implode("\n", $update_messages) . "</pre>");
//watchdog('booking', "Sent manual email for $counter people.");
}

View File

@@ -1,4 +1,5 @@
<?php
// $Id: booking.events.inc,v 0.1 2012/02/28
/**
* @file

View File

@@ -144,7 +144,8 @@ function _booking_get_waitinglist_top()
LIMIT 1',
array(':eid' => $event->eid));
foreach ($result as $person) {
foreach ($result as $person)
{
watchdog('booking', "First person on the waiting list: @info", array('@info' => var_export($person, TRUE)));
return $person->nid;
}
@@ -157,7 +158,8 @@ function _booking_get_waitinglist_top()
LIMIT 1',
array(':eid' => $event->eid));
foreach ($result as $person) {
foreach ($result as $person)
{
watchdog('booking', "First person on the missed-payment-deadline list: @info", array('@info' => var_export($person, TRUE)));
return $person->nid;
}
@@ -790,27 +792,27 @@ function _booking_generate_statistics($booking_list)
}
//figure out if we're in the right time period for discounted registration rates
function _booking_is_earlybird() {
function _booking_is_earlybird()
{
global $event;
if ($event->booking_earlybird_close > time()) {
if ($event->booking_earlybird_close > time())
return TRUE;
}
else {
else
{
return FALSE;
}
}
function _booking_datepaid_ts($nid) {
function _booking_datepaid_ts($nid)
{
$query = db_query("SELECT * FROM {booking_payment} where booking_person_nid = :nid", array(':nid' => $nid))
->fetchObject();
if ($query) {
if ($query)
return $query->booking_payment_date;
}
else {
else
return 0;
}
}
/**
@@ -839,29 +841,6 @@ function _booking_add_paypal_fees($amount, $country)
return $result;
}
/**
* Helper function to calculate stripe transaction fees
*/
function _booking_add_stripe_fees($amount, $country) {
//add the 30 cent fixed cost
$result = '0.00';
$result = (float) ($amount + (float) variable_get('booking_stripe_transaction_fee_fixedcost', '0.3'));
//and the 2.6 percent transaction fee for australian transaction with no currency conversion
if ($country == variable_get('booking_default_country', 'Australia')) {
$percentage = (float) variable_get('booking_stripe_transaction_fee_percentage', '1.75');
} else {
$percentage = (float) variable_get('booking_stripe_transaction_fee_percentage_intl', '2.9');
}
//apply the percentage
$percentage = (float) $percentage / 100;
$result = $result / (1 - $percentage);
//return result
return $result;
}
/**
* Helper function to return the amount for a booking deposit, if there is one
*/
@@ -875,17 +854,10 @@ function _booking_deposit_amount($person, $include_fees = TRUE)
->fetchObject();
if ($deposit) {
//if we're using paypal or stripe, add the transaction fee
$payment_processor_type = variable_get('booking_payment_processor', 0);
if ($include_fees == TRUE) {
if ($payment_processor_type == 0) {
$amount_owing = _booking_add_paypal_fees($deposit->booking_price, $person->booking_country);
}
elseif ($payment_processor_type == 1) {
$amount_owing = _booking_add_stripe_fees($deposit->booking_price, $person->booking_country);
}
//if we're using paypal, add the transaction fee
if (variable_get('booking_use_paypal', 0) == 1 && $include_fees == TRUE) {
$amount_owing = _booking_add_paypal_fees($deposit->booking_price, $person->booking_country);
}
//otherwise we're using manual payment processing so don't add any fees
else {
$amount_owing = $deposit->booking_price;
}
@@ -901,11 +873,13 @@ function _booking_deposit_amount($person, $include_fees = TRUE)
/**
* Calculate exactly how much a person has already paid
*/
function _booking_amount_paid($nid, $person = NULL) {
function _booking_amount_paid($nid, $person = NULL)
{
$amount_paid = 0;
//fetch details about the person if we don't already have them
if ($person == NULL) {
if ($person == NULL)
{
$person = db_query("SELECT price.booking_price, price.booking_late_price, person.booking_payment_id, " .
"person.booking_total_pay_reqd, person.booking_amount_paid, person.booking_partner_id " .
"FROM {booking_person} person, {booking_price} price " .
@@ -916,13 +890,15 @@ function _booking_amount_paid($nid, $person = NULL) {
}
//check for a spouse
if ($person->booking_partner_id > 0) {
if ($person->booking_partner_id > 0)
{
//watchdog('booking', "Checking total paid for married person");
//look for payments in the payment transaction table
//if we're combining the payment for married couples
if (variable_get('booking_enable_combined_pricing', 0) == 1) {
if (variable_get('booking_enable_combined_pricing', 0) == 1)
{
//check for payments in the paypal transaction table from either spouse
$query = db_query("SELECT booking_mc_gross, booking_mc_fee FROM booking_payment " .
"WHERE booking_person_nid = :nid OR booking_person_nid = :spousenid",
@@ -936,16 +912,17 @@ function _booking_amount_paid($nid, $person = NULL) {
}
//add up all the payments
foreach ($query as $payment) {
foreach ($query as $payment)
$amount_paid += ($payment->booking_mc_gross - $payment->booking_mc_fee);
}
//watchdog('booking', "Total amount paid according to paypal payments table is " . $amount_paid);
//there were no payment transactions, so rely on what the amount is set to in the individual registration records
if ($amount_paid == 0) {
//if we're combining the payment for married couples
if (variable_get('booking_enable_combined_pricing', 0) == 1) {
if ($amount_paid == 0)
{
//if we're combining the payment for married couples
if (variable_get('booking_enable_combined_pricing', 0) == 1)
{
$spouse = db_query("SELECT person.booking_amount_paid " .
"FROM {booking_person} person " .
"WHERE person.nid = :nid ",
@@ -954,15 +931,17 @@ function _booking_amount_paid($nid, $person = NULL) {
$amount_paid = $person->booking_amount_paid + $spouse->booking_amount_paid;
//watchdog('booking', "Total combined payments for couple based on totals in booking_person table is " . $amount_paid);
}
else {
$amount_paid = $person->booking_amount_paid;
else
{
$amount_paid = $person->booking_amount_paid;
//watchdog('booking', "Total amount paid for individual based on totals in booking_person table is " . $amount_paid);
}
//end combined payments check
}
}
//no spouse found
else {
else
{
//Check if there are payment records in the paypal transaction table for this unmarried person
//if so, base their payments on the gross amount in there rather than what the person booking_person database says
$query = db_query("SELECT booking_mc_gross, booking_mc_fee FROM booking_payment " .
@@ -974,9 +953,8 @@ function _booking_amount_paid($nid, $person = NULL) {
//watchdog('booking', "Total amount paid according to paypal payments table is " . $amount_paid);
//if there were no results, $amount_paid will still be 0
if ($amount_paid == 0) {
if ($amount_paid == 0)
$amount_paid = $person->booking_amount_paid;
}
//in case there has been some manual adjustment
//elseif ($amount_paid < $person->booking_amount_paid)
// $amount_paid = $person->booking_amount_paid;
@@ -1045,11 +1023,26 @@ function _booking_total_due($person)
*
* @param $person - the object relating to the registration node
* @param $amount_paid - if we have previously calculated the amount paid, this can be passed as a value
* @param $include_fees - boolean to indicate whether we want the net amount or the amount owing including paypal fees
* @param $include_paypal_fees - boolean to indicate whether we want the net amount or the amount owing including paypal fees
* @return amount owing as a decimal value
*/
function _booking_amount_owing($person, $amount_paid = 0, $include_fees = TRUE) {
global $event;
function _booking_amount_owing($person, $amount_paid = 0, $include_paypal_fees = TRUE)
{
//$amount_paid = 0;
//$total_due = 0;
//fetch details about the person
/*
$person = db_query("SELECT price.booking_price, price.booking_late_price, person.booking_payment_id, " .
"person.booking_total_pay_reqd, person.booking_amount_paid, person.booking_partner_id, person.booking_country, person.booking_welfare_required, person.booking_committee_member " .
"FROM {booking_person} person, {booking_price} price " .
"WHERE person.nid = :nid " .
"AND person.booking_payment_id = price.pid",
array(':nid' => $nid))
->fetchObject();
//$person = node_load($nid);
*/
//quick sanity check
if (! $person->nid) {
watchdog('booking', "Unable to find matching person relating to registration id. Details were '" . var_export($person, TRUE) . "' .");
@@ -1059,85 +1052,43 @@ function _booking_amount_owing($person, $amount_paid = 0, $include_fees = TRUE)
$total_due = _booking_total_due($person);
//if we didn't get the amount paid as a command line parameter, check it now
if ($amount_paid == 0) {
if ($amount_paid == 0)
{
$amount_paid = _booking_amount_paid($person->nid, $person);
}
//check if there is anything outstanding
//use the original total amount required rather than the late-rate, to cater for people that paid before the late rate
if ($amount_paid >= $person->booking_total_pay_reqd) {
if ($amount_paid >= $person->booking_total_pay_reqd)
{
//watchdog('booking', "This person doesn't owe any money: @info", array('@info' => var_export($person, TRUE)));
return 0;
}
//if we're using paypal or stripe, add the transaction fee
$payment_processor_type = variable_get('booking_payment_processor', 0);
if ($include_fees == TRUE) {
if ($payment_processor_type == 0) {
$amount_owing = _booking_add_paypal_fees($total_due - $amount_paid, $person->booking_country);
}
elseif ($payment_processor_type == 1) {
$amount_owing = _booking_add_stripe_fees($total_due - $amount_paid, $person->booking_country);
//if we're using paypal, add the transaction fee
if (variable_get('booking_use_paypal', 0) == 1 && $include_paypal_fees == TRUE)
{
$amount_owing = _booking_add_paypal_fees($total_due - $amount_paid, $person->booking_country);
/*
//add the 30 cent fixed cost
$amount_owing = $total_due - $amount_paid + 0.3;
//and the 2.4 percent transaction fee
if ($person->booking_country === "Australia")
$amount_owing = $amount_owing / (1 - 0.026);
//paypal charges 3.4 percent if they're doing a currency conversion
//assume that everyone not based in Australia will be doing a currency conversion
else
{
$amount_owing = $amount_owing / (1 - 0.036);
//watchdog('booking', "This is an international registration.");
}
*/
}
//otherwise we're using manual payment processing so don't add any fees
else {
else
$amount_owing = $total_due - $amount_paid;
}
return number_format($amount_owing, 2, '.', '');
}
/**
* Function to update the person object when a payment has been made
* payment details should be inserted into booking_payment prior to calling this function
*
* @param $person - the populated node object representing this person including related price information
* @param $payment_amount - the gross payment amount that is being processed
* @param $balance_payment - boolean to indicate if this transaction was to complete a payment
* @return nothing
*/
function _booking_process_person_payment($person, $payment_amount, $balance_payment) {
global $event;
//calculate their total payment amount
$total = $person->booking_amount_paid + $payment_amount;
//only recalculate their booking status if this is the initial payment, not a payment of the outstanding balance
if ($balance_payment == FALSE) {
watchdog('booking', 'Processing an initial payment. Booking status is currently ' . $person->booking_status);
if ($person->booking_status == 1) {
watchdog('booking', 'This registration has been manually assigned to the booked-in list.');
$status = 1;
}
elseif (_booking_check_bookings_full() == True || $person->booking_status == 2) {
watchdog('booking', 'This registration belongs on the waiting list.');
$status = 2;
}
else {
watchdog('booking', 'This registration made it to the booked-in list.');
$status = 1;
}
}
else {
//this is a balance payment
watchdog('booking', 'Processing a balance payment.');
//if this is a payment of outstanding balance, keep the booking_status the same
$status = $person->booking_status;
}
//update the database for this person
db_update('booking_person')
->fields(array(
'booking_amount_paid' => $total,
'booking_status' => $status,
))
->condition('nid', $person->nid)
->execute();
//handle workflow emails and spouse payment updates
_booking_postpayment_trigger($person->nid, $person, $balance_payment);
}
/**
* Function to handle any post-payment notification emails for either paypal or manual payment
* still a WIP
@@ -1154,7 +1105,8 @@ function _booking_postpayment_trigger($nid, $person, $balance_payment)
//If there is no outstanding balance, send a payment complete email
$amount_owing = _booking_amount_owing($person);
//if ($total >= $person->booking_total_pay_reqd)
if ($amount_owing == 0) {
if ($amount_owing == 0)
{
//set the payment complete flag
db_update('booking_person')
->fields(array(
@@ -1246,7 +1198,8 @@ function _booking_process_refund($person)
$refund = $paid - _booking_deposit_amount($person, FALSE);
//if there is a spouse, subtract their deposit too
if (variable_get('booking_enable_combined_pricing', 0) == 1 && $person->booking_partner_id > 0) {
if (variable_get('booking_enable_combined_pricing', 0) == 1 && $person->booking_partner_id > 0)
{
$refund = $refund - _booking_deposit_amount($person, FALSE);
}
@@ -1304,24 +1257,65 @@ function _booking_process_refund($person)
return $refund;
}
/**
* Helper function to provide a list of columns in the booking_person table
* This will be used to select which fields to import/export to/from a CSV
*/
function _booking_get_person_fields() {
$list_of_columns = array();
$query = db_query('SHOW COLUMNS FROM {booking_person_view}');
$result = $query->fetchAll();
foreach ($result as $column) {
$field = $column->Field;
$list_of_columns[$field] = $field;
/**
* Helper function to generate paypal form for payments
*/
function _booking_paypal_form($person, $invoiceid, $amount_owing, $button_text) {
$form = drupal_get_form('_booking_paypal_form_builder', $person, $invoiceid, $amount_owing, $button_text);
return drupal_render($form);
}
/**
* Helper function to generate form elements for paypal form
*/
function _booking_paypal_form_builder($node, &$form_state, $person, $invoiceid, $amount_owing, $button_text) {
global $event;
//get our current path so we can send the user back here if they cancel
$path = isset($_GET['q']) ? $_GET['q'] : '<front>';
//paypal specific settings
$vars = array(
'module' => 'Booking System',
'type' => $event->booking_eventname,
//'custom' => $data,
'item_name' => $event->booking_eventname . ' ' . $person->booking_price_descrip,
'invoice' => $invoiceid,
'no_shipping' => TRUE,
'no_note' => TRUE,
'currency_code' => 'AUD',
'return' => url('bookingfinal', array('absolute' => TRUE)),
'cancel_return' => url($path, array('absolute' => TRUE)),
'rm' => '2',
'amount' => $amount_owing,
'last_name' => $person->booking_lastname,
'first_name' => $person->booking_firstname,
'cmd' => '_xclick',
'notify_url' => url(BOOKING_PAYPAL_IPN_PATH, array('absolute' => TRUE)),
'business' => variable_get('booking_paypal_account', '')
);
$form['#action'] = url(variable_get('booking_paypal_sandbox', 0) ? BOOKING_PAYPAL_SUBMIT_URL_SANDBOX : BOOKING_PAYPAL_SUBMIT_URL, array('absolute' => TRUE));
//turn the array into a form
foreach($vars as $name => $value) {
$form[$name] = array(
'#type' => 'hidden',
'#value' => $value,
);
}
//watchdog('booking_debug', "<pre>Database columns for booking_person\n@info</pre>", array('@info' => print_r( $list_of_columns, true)));
return $list_of_columns;
$form['submit'] = array(
'#type' => 'button',
'#value' => t($button_text),
);
//watchdog('booking', 'Booking Balance payment: @info', array ('@info' => var_export($form, TRUE)));
return $form;
}
/**
* Helper function to format registrations details for summary in the confirmation email
*/
@@ -1342,14 +1336,14 @@ function _booking_details_email_summary($node) {
$rows[] = t('Name: !first !last', array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname));
$rows[] = t('Gender: !gender', array('!gender' => $node->booking_gender == 'M' ? 'Male' : 'Female'));
$rows[] = t('Date of birth: !dob', array('!dob' => _booking_convert_ts($node->booking_dob)->format('d/m/Y')));
/*
if (variable_get('booking_enable_passport', 1) == 1) {
$rows[] = t('Passport Number: !value', array('!value' => $node->booking_passport_num));
$rows[] = t('Passport Expiry: !timestamp', array('!timestamp' => _booking_convert_ts($node->booking_passport_expiry_date)->format('d/m/Y')));
$rows[] = t('Passport Exact Issued Name: !value', array('!value' => $node->booking_passport_issue_name));
$rows[] = t('Passport Issue Location: !value', array('!value' => $node->booking_passport_issue_location));
}
*/
$rows[] = t('Email address: !email', array('!email' => $node->booking_email));
$rows[] = t('Home Phone Number: !home', array('!home' => $node->booking_phone));
$rows[] = t('Mobile Phone Number: !mob', array('!mob' => $node->booking_mobile));
@@ -1480,7 +1474,7 @@ function _booking_travelform_email_summary($node) {
foreach ($rows as $key => $value)
$rows[$key] = wordwrap($value);
}
//watchdog('booking_debug', "<pre>Travel form summary\n@info</pre>", array('@info' => print_r( $rows, true)));
return implode("\n", $rows);
}
@@ -1529,35 +1523,58 @@ function _booking_leader_helper_email_summary($node) {
$found = FALSE;
//display study session data if enabled
if (variable_get('booking_enable_studygroups', 0) == 1) {
if (variable_get('booking_enable_studygroups', 0) == 1)
{
//look up the titles of the study groups
$studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid",
array(':eid' => $event->eid));
$studygroups = $studygroups_query->fetchAllAssoc('sid');
foreach ($studygroups as $studygroup) {
//for ($i = 1; $i <= variable_get('booking_studygroup_count','0'); $i++)
//for ($i = 1; $i <= count($studygroups); $i++)
foreach ($studygroups as $studygroup)
{
//don't print info about the readings groups
if ($studygroup->booking_is_readinggroup == 'Y') {
//if ($i == variable_get('booking_readinggroup_id','7'))
// continue;
//if ($studygroups[$i]->booking_is_readinggroup == 'Y')
// continue;
if ($studygroup->booking_is_readinggroup == 'Y')
continue;
}
//calculate the session references
//$sessionid = "session" . $i;
$sessionid = "session" . $studygroup->sid;
$roleid = $sessionid . "_role";
$otherperson_name = "TBA";
$otherperson_email = "";
$otherperson_phone = "";
//check that this study group session has been defined for this attendee and that they have a role to perform
if (!empty($node->$sessionid) && $node->$roleid > 0) {
//check that this study group session has been defined for this attendee and that they
if (!empty($node->$sessionid) && $node->$roleid > 0)
{
/*
//make sure we only add this prefix text once, as soon as we've found a matching role
if ($found == FALSE)
{
$found = TRUE;
$rows[] = t("You have been assigned to perform the following roles for study groups:");
}
*/
//TODO: use a function for this.
//if they're a leader or reserver leader, then the matching person is the helper
if ($node->$roleid == 1 || $node->$roleid == 3) {
if ($node->$roleid == 1 || $node->$roleid == 3)
{
$role = "Leader";
$otherrole = "Helper";
$otherrole_id = 2;
}
//otherwise the matching person is the leader
else {
else
{
$role = "Helper";
$otherrole = "Leader";
$otherrole_id = 1;
@@ -1575,25 +1592,25 @@ function _booking_leader_helper_email_summary($node) {
//watchdog('booking', "<pre>Other person for studygroup !group and role !role result:\n@info</pre>",
// array('!group' => $studygroup->sid, '!role' => $otherrole_id, '@info' => print_r( $otherperson, true)));
//create the text for the token
foreach ($otherperson as $other) {
foreach ($otherperson as $other)
{
$otherperson_name = $other->booking_firstname . ' ' . $other->booking_lastname;
$otherperson_email = $other->booking_email;
$otherperson_phone = $other->booking_mobile;
}
$rows[] = t('!role for !descrip. Your !otherrole is !other. You can contact them on !phone or !email.',
$rows[] = t('!role for !descrip (section !id). Your !otherrole is !other. You can contact them on !phone or !email.',
array('!role' => $role, '!id' => $studygroup->sid, '!descrip' => $studygroup->booking_studygroup_descrip,
'!otherrole' => $otherrole, '!other' => $otherperson_name, '!phone' => $otherperson_phone, '!email' => $otherperson_email,
));
}
}
}
//format the output to be used in an email
foreach ($rows as $key => $value) {
foreach ($rows as $key => $value)
$rows[$key] = wordwrap($value);
}
return implode("\n", $rows);
}
@@ -1625,43 +1642,6 @@ function _booking_room_email_summary($node) {
return implode("\n", $rows);
}
/**
* Helper function to create the mean, median, mode or average of an array
* @see http://www.phpsnips.com/45/Mean,-Median,-Mode,-Range-Of-An-Array
*/
function _booking_mmmr($array, $output = 'mean'){
if(!is_array($array)) {
return FALSE;
}
else {
switch($output){
case 'mean':
$count = count($array);
$sum = array_sum($array);
$total = $sum / $count;
break;
case 'median':
rsort($array);
$middle = round(count($array) / 2);
$total = $array[$middle-1];
break;
case 'mode':
$v = array_count_values($array);
arsort($v);
foreach($v as $k => $v){$total = $k; break;}
break;
case 'range':
sort($array);
$sml = $array[0];
rsort($array);
$lrg = $array[0];
$total = $lrg - $sml;
break;
}
return $total;
}
}
/**
* @brief Generates a Universally Unique IDentifier, version 4.
*

View File

@@ -1,9 +1,9 @@
; $Id$
name = Booking System
description = "A module which provides a booking system for event registration."
package = Booking System
dependencies[] = date
dependencies[] = token
dependencies[] = libraries
version = 0.2
configure = admin/config/booking/general
configure = admin/config/booking
core = 7.x

View File

@@ -531,119 +531,34 @@ function booking_update_7232() {
db_change_field('booking_person', 'booking_event_id', 'booking_eventid', $spec);
}
/**
* Ensure SQL View booking_person_view is created
*/
function booking_update_7233() {
_booking_node_create_mysqlview();
}
/**
* Remove deprecated passport and flight details
*/
function booking_update_7234() {
$fields = array(
'booking_passport_expiry_date', 'booking_passport_num', 'booking_passport_issue_location',
'booking_passport_issue_name', 'booking_destination_country', 'booking_travel_insurance',
'booking_outflight_bookingnum', 'booking_outflight_flightnum', 'booking_outflight_origin',
'booking_outflight_origin_ts', 'booking_outflight_connecting_flightnum', 'booking_outflight_destination',
'booking_outflight_destination_ts', 'booking_rtrnflight_bookingnum', 'booking_rtrnflight_flightnum',
'booking_rtrnflight_origin', 'booking_rtrnflight_origin_ts', 'booking_rtrnflight_connecting_flightnum',
'booking_rtrnflight_destination', 'booking_rtrnflight_destination_ts'
);
foreach ($fields as $field) {
db_drop_field('booking_person', $field);
}
//update the view to match the new table definition
_booking_node_create_mysqlview();
}
/**
* Add email address for guardian contact info
*/
function booking_update_7235() {
$spec = array('type' => 'varchar', 'length' => '250', 'not null' => FALSE);
db_add_field('booking_person', 'booking_guardian_email', $spec);
//update the view to match the new table definition
_booking_node_create_mysqlview();
}
/**
* Add flag to indicate a studygroup session has been manually assigned
*/
function booking_update_7236() {
$spec = array('type' => 'varchar', 'length' => '1', 'not null' => FALSE, 'default' => 'N');
db_add_field('booking_studygroup_mapping', 'booking_session_manually_allocated', $spec);
//update the view to match the new table definition
_booking_node_create_mysqlview();
}
/**
* Add flag to indicate an attendee that should be kept separate for automated group calculations
*/
function booking_update_7237() {
$spec = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0);
db_add_field('booking_person', 'booking_keepseparate_id', $spec);
//update the view to match the new table definition
_booking_node_create_mysqlview();
}
/**
* Add description field to room definitions
*/
function booking_update_7238() {
$spec = array('type' => 'varchar', 'length' => '200', 'not null' => FALSE);
db_add_field('booking_room_definition', 'booking_room_description', $spec);
//update the view to match the new table definition
_booking_node_create_mysqlview();
}
/**
* Change room number field in room definitions to integer
*/
function booking_update_7239() {
$spec = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0);
db_change_field('booking_room_definition', 'booking_room_number', 'booking_room_number', $spec);
//update the view to match the new table definition
_booking_node_create_mysqlview();
}
/**
* Add stripe token field to booking_payments table
*/
function booking_update_7240() {
$spec = array('type' => 'varchar', 'length' => '200', 'not null' => FALSE);
db_add_field('booking_payment', 'booking_stripe_token', $spec);
//update the view to match the new table definition
_booking_node_create_mysqlview();
}
/**
* Implementation of hook_install().
*/
function booking_install() {
// Create some sample data
// TODO: Set default values for the config pages too
$result = db_insert('booking_price')
->fields(array(
'booking_eventid' => 1,
'booking_price' => '50.00',
'booking_price_descrip' => 'Deposit',
'booking_buttonid' => '',
'booking_price_active' => 1,
'booking_depositonly' => 1,
))
->execute();
//earlybird close is 31st Jan 2012 at 13:59:59 UTC
$result = db_insert('booking_event')
->fields(array(
'booking_eventname' => 'Sample Event',
'booking_event_active' => 1,
'booking_register_open' => 1312207199,
'booking_register_close' => 1340459999,
'booking_earlybird_close' => 1328018399,
))
->execute();
$result = db_insert('booking_price')
->fields(array(
'booking_eventid' => 1,
'booking_price' => '50.00',
'booking_price_descrip' => 'Deposit',
'booking_buttonid' => '',
'booking_price_active' => 1,
'booking_depositonly' => 1,
))
->execute();
//create the sql view booking_person_view when first installing this module
_booking_node_create_mysqlview();
$result = db_insert('booking_event')
->fields(array(
'booking_eventname' => 'Sample Event',
'booking_event_active' => 1,
'booking_register_open' => 1312207199,
'booking_register_close' => 1340459999,
'booking_earlybird_close' => 1328018399,
))
->execute();
//earlybird close is 31st Jan 2012 at 13:59:59 UTC
}
/**
@@ -700,7 +615,6 @@ function booking_schema() {
'booking_dependant_children' => array('type' => 'varchar', 'length' => '1', 'not null' => TRUE, 'default' => 'N'),
'booking_bf_gf' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
'booking_bf_gf_nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10'),
'booking_keepseparate_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0),
'booking_room_mate1' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
'booking_room_mate2' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
//payment info
@@ -715,7 +629,6 @@ function booking_schema() {
//emergency contact info
'booking_guardian_name' => array('type' => 'varchar', 'length' => '100', 'not null' => TRUE),
'booking_guardian_type' => array('type' => 'varchar', 'length' => '100', 'not null' => TRUE),
'booking_guardian_email' => array('type' => 'varchar', 'length' => '250', 'not null' => FALSE),
'booking_guardian_phone' => array('type' => 'varchar', 'length' => '50', 'not null' => FALSE),
'booking_guardian_phone_alt' => array('type' => 'varchar', 'length' => '50', 'not null' => FALSE),
'booking_medicare' => array('type' => 'varchar', 'length' => '50', 'not null' => FALSE),
@@ -763,7 +676,6 @@ function booking_schema() {
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
*/
/*
//passport info
'booking_passport_expiry_date' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_passport_num' => array('type' => 'varchar', 'length' => '50', 'not null' => FALSE),
@@ -787,7 +699,6 @@ function booking_schema() {
'booking_rtrnflight_connecting_flightnum' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
'booking_rtrnflight_destination' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
'booking_rtrnflight_destination_ts' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
*/
/*
),
'foreign keys' => array(
@@ -803,55 +714,55 @@ function booking_schema() {
'primary key' => array('nid'),
);
$schema['booking_event'] = array(
'fields' => array(
'eid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventname' => array('type' => 'varchar', 'length' => '200', 'not null' => TRUE),
'booking_event_active' => array('type' => 'varchar', 'length' => '1', 'default' => 0, 'not null' => TRUE),
'booking_register_open' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_register_close' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_earlybird_close' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_event_start' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_event_end' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'eid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventname' => array('type' => 'varchar', 'length' => '200', 'not null' => TRUE),
'booking_event_active' => array('type' => 'varchar', 'length' => '1', 'default' => 0, 'not null' => TRUE),
'booking_register_open' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_register_close' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_earlybird_close' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_event_start' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_event_end' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
),
'primary key' => array('eid'),
);
$schema['booking_price'] = array(
'fields' => array(
'pid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_price' => array('type' => 'numeric', 'not null' => FALSE, 'default' => 0, 'precision' => '7', 'scale' => '2'),
'booking_late_price' => array('type' => 'numeric', 'not null' => FALSE, 'default' => 0, 'precision' => '7', 'scale' => '2'),
'booking_price_descrip' => array('type' => 'varchar', 'length' => '100', 'not null' => TRUE),
'booking_buttonid' => array('type' => 'varchar', 'length' => '50', 'not null' => FALSE),
'booking_late_buttonid' => array('type' => 'varchar', 'length' => '50', 'not null' => FALSE),
'booking_price_active' => array('type' => 'varchar', 'length' => '1', 'default' => 0, 'not null' => TRUE),
'booking_earlybird_rate' => array('type' => 'varchar', 'length' => '1', 'default' => 0, 'not null' => TRUE),
'booking_depositonly' => array('type' => 'varchar', 'length' => '1', 'default' => 0, 'not null' => TRUE),
'pid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_price' => array('type' => 'numeric', 'not null' => FALSE, 'default' => 0, 'precision' => '7', 'scale' => '2'),
'booking_late_price' => array('type' => 'numeric', 'not null' => FALSE, 'default' => 0, 'precision' => '7', 'scale' => '2'),
'booking_price_descrip' => array('type' => 'varchar', 'length' => '100', 'not null' => TRUE),
'booking_buttonid' => array('type' => 'varchar', 'length' => '50', 'not null' => FALSE),
'booking_late_buttonid' => array('type' => 'varchar', 'length' => '50', 'not null' => FALSE),
'booking_price_active' => array('type' => 'varchar', 'length' => '1', 'default' => 0, 'not null' => TRUE),
'booking_earlybird_rate' => array('type' => 'varchar', 'length' => '1', 'default' => 0, 'not null' => TRUE),
'booking_depositonly' => array('type' => 'varchar', 'length' => '1', 'default' => 0, 'not null' => TRUE),
),
'primary key' => array('pid'),
);
$schema['booking_payment'] = array(
'fields' => array(
'payid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_person_nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_mc_gross' => array('type' => 'numeric', 'not null' => FALSE, 'default' => 0, 'precision' => '7', 'scale' => '2'),
'booking_mc_currency' => array('type' => 'varchar', 'length' => '10', 'not null' => FALSE),
'booking_mc_fee' => array('type' => 'numeric', 'not null' => FALSE, 'default' => 0, 'precision' => '7', 'scale' => '2'),
'booking_quantity' => array('type' => 'int', 'length' => 11, 'not null' => FALSE, 'default' => 0),
'booking_invoice' => array('type' => 'varchar', 'length' => '150', 'not null' => FALSE),
'booking_payer_id' => array('type' => 'varchar', 'length' => '150', 'not null' => FALSE),
'booking_payment_date' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_payment_status' => array('type' => 'varchar', 'length' => '50', 'not null' => FALSE),
'booking_first_name' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
'booking_last_name' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
'booking_buyer_email' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
'booking_payer_status' => array('type' => 'varchar', 'length' => '50', 'not null' => FALSE),
'booking_item_name' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
'booking_ipn_track_id' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
'booking_stripe_token' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
),
'payid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_person_nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_mc_gross' => array('type' => 'numeric', 'not null' => FALSE, 'default' => 0, 'precision' => '7', 'scale' => '2'),
'booking_mc_currency' => array('type' => 'varchar', 'length' => '10', 'not null' => FALSE),
'booking_mc_fee' => array('type' => 'numeric', 'not null' => FALSE, 'default' => 0, 'precision' => '7', 'scale' => '2'),
'booking_quantity' => array('type' => 'int', 'length' => 11, 'not null' => FALSE, 'default' => 0),
'booking_invoice' => array('type' => 'varchar', 'length' => '150', 'not null' => FALSE),
'booking_payer_id' => array('type' => 'varchar', 'length' => '150', 'not null' => FALSE),
'booking_payment_date' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_payment_status' => array('type' => 'varchar', 'length' => '50', 'not null' => FALSE),
'booking_first_name' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
'booking_last_name' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
'booking_buyer_email' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
'booking_payer_status' => array('type' => 'varchar', 'length' => '50', 'not null' => FALSE),
'booking_item_name' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
'booking_ipn_track_id' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE)),
'primary key' => array('payid'),
);
@@ -891,20 +802,20 @@ function booking_schema() {
$schema['booking_travel'] = array(
'fields' => array(
'tid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_person_nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_transport_type' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
'booking_transport_from_morriset_reqd' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
'booking_transport_to_morriset_reqd' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
'booking_flightnum_inbound' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
'booking_flight_datetime_inbound' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_flightnum_outbound' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
'booking_flight_datetime_outbound' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_accom_before_reqd' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
'booking_accom_before_staying_with' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
'booking_accom_after_reqd' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
'booking_accom_after_staying_with' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
),
'tid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_person_nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_transport_type' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
'booking_transport_from_morriset_reqd' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
'booking_transport_to_morriset_reqd' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
'booking_flightnum_inbound' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
'booking_flight_datetime_inbound' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_flightnum_outbound' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
'booking_flight_datetime_outbound' => array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11'),
'booking_accom_before_reqd' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
'booking_accom_before_staying_with' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
'booking_accom_after_reqd' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
'booking_accom_after_staying_with' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
),
'primary key' => array('tid'),
);
@@ -928,13 +839,13 @@ function booking_schema() {
'booking_node_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_studygroup_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_session_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10', 'default' => 0),
'booking_session_manually_allocated' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE, 'default' => 'N'),
//'booking_is_leader' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
//'booking_is_helper' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
'booking_studygroup_role' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE, 'default' => 0),
),
'primary key' => array('sid'),
);
//this table isn't currently in use
$schema['booking_readinggroup_definition'] = array(
'fields' => array(
'rid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
@@ -948,12 +859,11 @@ function booking_schema() {
'fields' => array(
'rid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_room_location_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0),
'booking_room_number' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0),
'booking_room_number' => array('type' => 'varchar', 'length' => '500', 'not null' => FALSE),
'booking_room_singlebeds' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0),
'booking_room_doublebeds' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0),
'booking_room_queenbeds' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0),
'booking_room_ensuite' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE, 'default' => 'N'),
'booking_room_description' => array('type' => 'varchar', 'length' => '200', 'not null' => TRUE),
),
'primary key' => array('rid'),
);

View File

@@ -1,18 +0,0 @@
/**
* Drupal AJAX framework command.
*/
Drupal.ajax.prototype.commands.bookingAjaxCheckboxes = function(ajax, response, status) {
jQuery(function($) {
var arr = $.parseJSON($('input#' + response.formDataElement).val())
$('#' + response.formName).find(':checkbox[name^="' + response.checkboxName + '"]').each(function () {
//.prop() doesn't exist in Drupal's old version of jQuery so use .attr() instead
if ($.inArray($(this).val(), arr) != -1) {
$(this).attr("checked", true);
$(this).closest('tr').addClass("selected");
} else {
$(this).attr("checked", false);
$(this).closest('tr').removeClass("selected");
}
});
});
}

View File

@@ -16,7 +16,6 @@
define('BOOKING_PAYPAL_SUBMIT_URL', 'https://www.paypal.com/cgi-bin/webscr');
define('BOOKING_PAYPAL_SUBMIT_URL_SANDBOX', 'https://www.sandbox.paypal.com/cgi-bin/webscr');
//@todo should really change this to system/booking/paypal
define('BOOKING_PAYPAL_IPN_PATH', 'system/booking_paypal/ipn');
// Load the include for various constants
@@ -49,7 +48,6 @@ module_load_include('inc', 'booking', 'booking.helper');
module_load_include('inc', 'booking', 'booking.paypal');
// Load the include for email functions
module_load_include('inc', 'booking', 'booking.emails');
module_load_include('inc', 'booking', 'booking.emails_admin');
// Load the include for bulk data import
module_load_include('inc', 'booking', 'booking.import_data');
// Load the include for variety session configuration
@@ -68,14 +66,12 @@ module_load_include('inc', 'booking', 'booking.rooms');
module_load_include('inc', 'booking', 'booking.rooms_allocate');
// Load the include for room layout definitions
module_load_include('inc', 'booking', 'booking.rooms_admin');
// Load the include for stripe payments
module_load_include('inc', 'booking', 'booking.stripe');
function booking_init() {
date_default_timezone_set(date_default_timezone(FALSE));
global $event;
//@see http://www.devdaily.com/drupal/drupal-7-sql-cheat-sheet-function-examples
//reference - http://www.devdaily.com/drupal/drupal-7-sql-cheat-sheet-function-examples
$event = db_query("SELECT * from {booking_event} where booking_event_active=1")
->fetchObject();
@@ -85,6 +81,7 @@ function booking_init() {
/**
* Implementation of hook_permission().
* D7 done.
*/
function booking_permission() {
return array(
@@ -151,17 +148,28 @@ function booking_menu() {
$items = array();
$items['admin/config/booking'] = array(
'title' => 'Booking module configuration',
'description' => 'Configure the Booking module',
'position' => 'left',
'weight' => -100,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
/*
'title' => 'Booking module configuration',
'description' => 'Configure the Booking module',
'page callback' => 'drupal_get_form',
'page arguments' => array('booking_admin'),
'access arguments' => array('access administration pages'),
*/
'title' => 'Booking module configuration',
'description' => 'Configure the Booking module',
'position' => 'left',
'weight' => -100,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
//'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/config/booking/general'] = array(
'title' => 'Booking module general configuration',
'description' => 'Configure general settings for Booking module',
'page callback' => 'drupal_get_form',
@@ -169,48 +177,39 @@ function booking_menu() {
'access arguments' => array('administer site configuration'),
//'type' => MENU_DEFAULT_LOCAL_TASK,
//'position' => 'left',
'weight' => -100,
'weight' => -100,
);
//http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form/
$items['admin/config/booking/text'] = array(
'title' => 'Booking module text definitions',
'description' => 'Configure text used in the Booking module',
'description' => 'Configure text used in the Event Booking module',
'page callback' => 'drupal_get_form',
'page arguments' => array('booking_tokens_admin'),
'access arguments' => array('administer site configuration'),
'weight' => -99,
//'type' => MENU_LOCAL_TASK,
);
$items['admin/config/booking/emails'] = array(
'title' => 'Booking module email definitions',
'description' => 'Configure built-in workflow and custom emails used by the Booking module',
'page callback' => 'drupal_get_form',
'page arguments' => array('booking_emails_admin'),
'access arguments' => array('administer site configuration'),
'weight' => -98,
//'type' => MENU_LOCAL_TASK,
);
$items['admin/config/booking/events'] = array(
'title' => 'Booking module event settings',
'description' => 'Configure events for the Booking module',
'page callback' => 'drupal_get_form',
'page arguments' => array('booking_event_admin'),
'access arguments' => array('administer site configuration'),
'weight' => -97,
//'type' => MENU_LOCAL_TASK,
);
$items['admin/config/booking/prices'] = array(
'title' => 'Booking module price settings',
'description' => 'Configure prices for the Booking module',
'description' => 'Configure prices for the Event Booking module',
'page callback' => 'drupal_get_form',
'page arguments' => array('booking_price_admin'),
'access arguments' => array('administer site configuration'),
'weight' => -96,
//'type' => MENU_LOCAL_TASK,
);
$items['admin/config/booking/events'] = array(
'title' => 'Booking module event settings',
'description' => 'Configure events for the Event Booking module',
'page callback' => 'drupal_get_form',
'page arguments' => array('booking_event_admin'),
'access arguments' => array('administer site configuration'),
//'type' => MENU_LOCAL_TASK,
);
$items['admin/config/booking/variety'] = array(
'title' => 'Booking module variety sessions',
'description' => 'Configure variety sessions for the Booking module',
'description' => 'Configure variety sessions for the Event Booking module',
'page callback' => 'drupal_get_form',
'page arguments' => array('booking_variety_admin'),
'access arguments' => array('administer site configuration'),
@@ -226,18 +225,6 @@ function booking_menu() {
'type' => MENU_CALLBACK,
);
/*
$items['admin/booking/createview'] = array(
'title' => 'Booking Test mysql view creation',
'description' => 'Booking Test mysql view creation',
'page callback' => '_booking_node_create_mysqlview',
//'access arguments' => array('edit bookings'),
//always allow access to this page - security risk!
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
*/
//pages for attendees to fill out information
$items['booking'] = array(
'title' => $bookingTitle . ' Booking Form',
@@ -245,16 +232,6 @@ function booking_menu() {
'access arguments' => array('access booking form'),
'type' => MENU_NORMAL_ITEM,
);
// @todo remove this after testing
/*
$items['stripetest'] = array(
'title' => $bookingTitle . ' Stripe Test',
'page callback' => 'drupal_get_form',
'page arguments' => array('booking_stripeform_form'),
'access arguments' => array('access booking form'),
'type' => MENU_NORMAL_ITEM,
);
*/
$items['bookingfinal'] = array(
'title' => $bookingTitle . ' Registration Completed',
'page callback' => 'booking_payment_completed_page',
@@ -293,20 +270,6 @@ function booking_menu() {
'type' => MENU_SUGGESTED_ITEM,
);
$items['coming'] = array(
'title' => "Who's Coming?",
'page callback' => 'booking_coming_page',
'access arguments' => array("access coming list"),
'type' => MENU_NORMAL_ITEM,
);
$items['waitinglist'] = array(
'title' => "Who's on the waiting list?",
'page callback' => 'booking_waitinglist_page',
'access arguments' => array("access waiting list"),
'type' => MENU_NORMAL_ITEM,
);
//Various reports
$items['admin/booking/summary'] = array(
'title' => 'Booking Summary',
@@ -324,21 +287,11 @@ function booking_menu() {
'type' => MENU_NORMAL_ITEM,
);
$items['admin/booking/travel'] = array(
'title' => 'Booking Travel Summary',
'description' => "List people's travel details",
'page callback' => 'booking_report_travel',
'access arguments' => array('access reports'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/booking/manual-email'] = array(
'title' => 'Manually Email People',
'description' => 'Send manual email to registered people',
'page callback' => 'drupal_get_form',
'page arguments' => array('booking_manual_email_form'),
//'page callback' => 'drupal_get_form',
//'page arguments' => array('booking_manual_email'),
'page callback' => 'drupal_get_form',
'page arguments' => array('booking_manual_email'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
@@ -369,6 +322,21 @@ function booking_menu() {
'type' => MENU_NORMAL_ITEM,
);
$items['coming'] = array(
'title' => "Who's Coming?",
'page callback' => 'booking_coming_page',
'access arguments' => array("access coming list"),
'type' => MENU_NORMAL_ITEM,
);
$items['waitinglist'] = array(
'title' => "Who's on the waiting list?",
'page callback' => 'booking_waitinglist_page',
'access arguments' => array("access waiting list"),
'type' => MENU_NORMAL_ITEM,
);
//show flight info report only if we have passport info enabled
if (variable_get('booking_enable_passport', 0) == 1)
{
@@ -439,10 +407,11 @@ function booking_menu() {
}
//configure study groups
if (variable_get('booking_enable_studygroups', 0) == 1) {
if (variable_get('booking_enable_studygroups', 0) == 1)
{
//the config pages for study groups
$items['admin/config/booking/studygroups'] = array(
'title' => 'Booking module Study Group configuration',
'title' => 'Booking Module Study Group Configuration',
'description' => 'Define and configure Study Groups for the Booking module',
'page callback' => 'booking_studygroups_admin',
'access arguments' => array('administer site configuration'),
@@ -485,16 +454,6 @@ function booking_menu() {
'type' => MENU_NORMAL_ITEM,
);
//@todo a nice report with everyone's studygroup membership
$items['admin/booking/studygroups/report/leadershelpers'] = array(
'title' => 'View Studygroup Leaders and Helpers',
'description' => 'View Studygroup Leaders and Helpers',
'page callback' => 'booking_studygroups_leadhelp_view_summary',
'access arguments' => array("view study groups"),
'type' => MENU_LOCAL_ACTION,
);
$items['admin/booking/studygroups/calculateleaders'] = array(
'title' => 'Calculate Study Group Leaders',
'description' => 'Calculate Study Group Leaders and Helpers',
@@ -538,23 +497,16 @@ function booking_menu() {
'access arguments' => array('edit study groups'),
//'type' => MENU_LOCAL_ACTION,
);
$items['admin/booking/studygroups/%/editleaders'] = array(
'title' => 'Edit Study Group Leaders',
'description' => 'Edit Study Group Leaders and Helpers',
/*
$items['admin/booking/studygroups/calculate'] = array(
'title' => 'Calculate Study Groups',
'description' => 'Calculate Study Group memberships',
'page callback' => 'drupal_get_form',
'page arguments' => array('booking_studygroup_leadhelp_edit_form', 3),
'page arguments' => array('booking_studygroups_calculate'),
'access arguments' => array('edit study groups'),
//'type' => MENU_LOCAL_ACTION,
'type' => MENU_LOCAL_ACTION,
);
//callback for autocomplete lookup
$items['booking/studygroups/autocomplete'] = array(
'title' => 'Autocomplete for studygroup allocations',
'page callback' => '_booking_studygroups_name_autocomplete',
'access arguments' => array('edit study groups'),
'type' => MENU_CALLBACK
);
*/
$items['admin/booking/studygroups/%/update'] = array(
'title' => 'Update Study Groups',
'description' => 'Calculate updated Study Group memberships',
@@ -581,7 +533,7 @@ function booking_menu() {
//config pages
$items['admin/config/booking/rooms'] = array(
'title' => 'Booking module room definitions',
'description' => 'View and configure Room Definitions for the Booking module',
'description' => 'View and Configure room definitions for the Event Booking module',
'page callback' => 'drupal_get_form',
'page arguments' => array('booking_rooms_view_definitions'),
'access arguments' => array('administer site configuration'),
@@ -725,24 +677,19 @@ function booking_menu() {
);
//the paypal IPN
$items[BOOKING_PAYPAL_IPN_PATH] = array(
'type' => MENU_CALLBACK,
'access callback' => TRUE,
'page callback' => 'booking_paypal_ipn',
);
//stripe webhook
$items['system/booking/stripe/webhook'] = array(
'type' => MENU_CALLBACK,
'access callback' => TRUE,
'page callback' => 'booking_stripe_webhook',
$items[BOOKING_PAYPAL_IPN_PATH] = array(
'type' => MENU_CALLBACK,
'page callback' => 'booking_paypal_ipn',
'access callback' => TRUE
);
return $items;
}
/**
* Describe the nodes we are going to define to model content specific to the booking module
* D7 done
*/
function booking_node_info() {
return array(
@@ -759,63 +706,6 @@ function booking_node_info() {
);
}
/**
* Implements hook_library().
*/
function booking_library() {
$module_path = drupal_get_path('module', 'booking');
$items['booking-stripe'] = array(
'title' => t('Stripe'),
'version' => '1.0',
'js' => array(
'https://js.stripe.com/v1/' => array(),
'https://checkout.stripe.com/checkout.js' => array(),
$module_path . '/booking.stripe.js' => array(),
),
);
return $items;
}
/**
* Implements hook_libraries_info().
* @todo does this even do anything useful?
*/
function booking_libraries_info() {
$libraries['stripe'] = array(
'name' => 'Stripe Payment API PHP Library',
'vendor url' => 'https://github.com/stripe/stripe-php',
'download url' => 'https://github.com/stripe/stripe-php/archive/master.zip',
'version arguments' => array(
'file' => 'VERSION',
'pattern' => '/([0-9a-zA-Z\.-]+)/',
'lines' => 1,
),
'files' => array('php' => array('init.php')),
'callbacks' => array('post-load' => array('booking_libraries_postload_callback')),
);
return $libraries;
}
/**
* Post-load callback for the Stripe PHP Library.
*
* @param array $library
* An array of library information.
* @param string $version
* If the $library array belongs to a certain version, a string containing the
* version.
* @param string $variant
* If the $library array belongs to a certain variant, a string containing the
* variant name.
*/
function booking_libraries_postload_callback($library, $version = NULL, $variant = NULL) {
if (!empty($library['loaded'])) {
\Stripe\Stripe::setApiKey(_booking_get_stripe_private_key());
}
}
/**
* Implementation of access related hooks for booking_registration node type.
@@ -930,46 +820,10 @@ function booking_mail($key, &$message, $params) {
}
}
/**
* Implements hook_requirements().
*/
function booking_requirements($phase) {
$requirements = array();
$t = get_t();
//do a runtime verification that the stripe library is installed
if ($phase == 'runtime') {
//check that the stripe library is present
if (($library = libraries_detect('stripe')) && !empty($library['installed'])) {
// The library is installed. Awesome!
$info = libraries_info('stripe');
//watchdog('booking_debug', "<pre>Stripe library check\n@info</pre>", array('@info' => print_r($info, true)));
$requirements['booking_stripe_library'] = array(
'title' => $t('Booking Module Libraries'),
'description' => $t('Stripe library is installed.'),
'value' => $t('Version !version installed.', array('!version' => $info['version'])),
'severity' => REQUIREMENT_OK,
);
}
else {
// Stripe library is not installed or something else is wrong with it
$error_message = $library['error message'];
$requirements['booking_stripe_library'] = array(
'title' => $t('Booking Module Libraries'),
'description' => $t('Stripe payment processor library not installed correctly. Download https://github.com/stripe/stripe-php/archive/master.zip and extract contents into sites/all/libraries/stripe'),
'value' => $error_message,
'severity' => REQUIREMENT_ERROR,
);
}
}
return $requirements;
}
/**
* Function for generating the "lucky number" to be used on the lanyard
* @todo move this into a better place. It doesn't belong here
*/
function booking_generate_luckynumbers() {
global $event;
@@ -982,7 +836,7 @@ function booking_generate_luckynumbers() {
$attendees = $attendee_query->fetchAll();
//assuming there's less than 900 people, generate numbers within that range and shuffle the order
$numbers = range(100,750);
$numbers = range(100,650);
shuffle($numbers);
foreach ($attendees as $attendee)
@@ -1005,6 +859,7 @@ function booking_generate_luckynumbers() {
drupal_set_message(t('Finished.'));
return t("<h3>Generate Lucky Numbers</h3>");
}
/*
function booking_form_user_profile_form_alter(&$form, &$form_state) {

View File

@@ -91,7 +91,7 @@ function booking_paypal_ipn() {
}
*/
//@todo Handle refund and payment dispute IPNs
//TODO: Handle refund and payment dispute IPNs
if (empty($ipn['payment_status']) || ($ipn['payment_status'] != 'Completed' && variable_get('booking_paypal_sandbox', 0) == 0))
return;
@@ -104,18 +104,19 @@ function booking_paypal_ipn() {
}
//Insert record into database and remove temporary booking id field from user
_booking_store_paypal_payment($ipn);
_booking_process_payment($ipn);
}
function _booking_store_paypal_payment($data) {
function _booking_process_payment($data) {
global $event;
$balance_payment = false;
$amount_owing = 0;
//extract the person node id from the invoice
$pos = strpos($data['invoice'], "_");
if (($pos === false) || ($pos == 0)) {
if (($pos === false) || ($pos == 0))
{
watchdog('booking', 'Unable to process payment with invalid invoice information: !id', array('!id' => $data['invoice']), WATCHDOG_ERROR);
return;
}
@@ -124,16 +125,20 @@ function _booking_store_paypal_payment($data) {
//get the data between the first and second underscore
$eid = substr($data['invoice'], $pos + 1, strrpos($data['invoice'], "_") - $pos - 1);
if (substr($eid,0,3) == "bal") {
if (substr($eid,0,3) == "bal")
{
$balance_payment = true;
watchdog('booking', 'Balance payment for user with node id: !id', array('!id' => $nid));
}
//verify paypal hasn't already sent through a notification for this payment
$duplicate_check = db_query("SELECT payid, booking_person_nid FROM {booking_payment} where booking_ipn_track_id = :ipn_id ",
array(':ipn_id' => $data['ipn_track_id']))->fetchObject();
if ($duplicate_check) {
watchdog('booking', 'Detected duplicate paypal notifications for transaction id !id, registration id !nid', array('!id' => $data['ipn_track_id'], '!nid' => $nid), WATCHDOG_ERROR);
array(':ipn_id' => $data['ipn_track_id']))
->fetchObject();
if ($duplicate_check)
{
watchdog('booking', 'Detected duplicate paypal notifications for transaction id !id, registration id !nid', array('!id' => $data['ipn_track_id'], '!nid' => $nid), WATCHDOG_ERROR);
return;
}
@@ -160,117 +165,135 @@ function _booking_store_paypal_payment($data) {
))
->execute();
//Get the person's info so we can update their total amount paid and booking status
//Get the person's info
$person = node_load($nid);
//check if we found a person matching this payment
if ($person) {
watchdog('booking', 'Found matching user with node id: !id; event id: !eid; existing payment !payment',
array('!id' => $nid, '!eid' => $eid, '!payment' => $person->booking_amount_paid));
_booking_process_person_payment($person, $data['mc_gross'], $balance_payment);
if ($person)
{
watchdog('booking', 'Found matching user with node id: !id; event id: !eid; existing payment !payment', array('!id' => $nid, '!eid' => $eid,
'!payment' => $person->booking_amount_paid));
//if successful, update their total payment amount
$total = $person->booking_amount_paid + $data['mc_gross'];
//only recalculate their booking status if this is the initial payment, not a payment of the outstanding balance
if ($balance_payment == FALSE)
{
watchdog('booking', 'Processing an initial payment. Booking status is currently ' . $person->booking_status);
if ($person->booking_status == 1)
{
watchdog('booking', 'This registration has been manually assigned to the booked-in list.');
$status = 1;
}
elseif (_booking_check_bookings_full() == True || $person->booking_status == 2)
{
watchdog('booking', 'This registration belongs on the waiting list.');
$status = 2;
}
else
{
watchdog('booking', 'This registration made it to the booked-in list.');
$status = 1;
}
}
else //this is a balance payment
{
watchdog('booking', 'Processing a balance payment.');
//if this is a payment of outstanding balance, keep the booking_status the same
$status = $person->booking_status;
//$status = $person->booking_status == 2 ? 2 : 1;
}
//update the database for this person
db_update('booking_person')
->fields(array(
'booking_amount_paid' => $total,
'booking_status' => $status,
))
->condition('nid', $nid)
->execute();
//replace the code below with a call to the helper function
_booking_postpayment_trigger($nid, $person, $balance_payment);
/*
//If there is no outstanding balance, send a payment complete email
$amount_owing = _booking_amount_owing($person);
//if ($total >= $person->booking_total_pay_reqd)
if ($amount_owing == 0)
{
//set the payment complete flag
db_update('booking_person')
->fields(array(
'booking_payment_complete' => 'Y',
))
->condition('nid', $nid)
->execute();
//this should always be a balance payment type email, since that tells the user that their payment is completed
_booking_registration_email($nid, TRUE);
//if we are combining payments, and this person has a linked spouse
if ((variable_get('booking_enable_combined_pricing', 0) == 1) && ($person->booking_partner_id > 0))
{
//check spouse booking_status and payment info
$spouse = db_select('booking_person', 'p')
->condition('p.nid', $person->booking_partner_id,'=')
->fields('p', array('booking_amount_paid', 'booking_status', 'booking_total_pay_reqd'))
->execute()
->fetchObject();
//update the spouse's status from "not paid" if required
$spouse_status = $spouse->booking_status == 0 ? 1 : $spouse->booking_status;
watchdog('booking', 'Setting status for spouse id !id to !new from !status', array('!id' => $person->booking_partner_id,
'!new' => $spouse_status, '!status' => $spouse->booking_status));
//set the spouse's payment required to be zero or equal to their previous payment total
$spouse_new_amount_reqd = $spouse->booking_amount_paid > 0 ? $spouse->booking_amount_paid : 0;
watchdog('booking', 'Setting amount owing for spouse id !id to !new from !old.', array('!id' => $person->booking_partner_id,
'!new' => $spouse_new_amount_reqd, '!old' => $spouse->booking_total_pay_reqd));
//update the database for this person
db_update('booking_person')
->fields(array(
'booking_total_pay_reqd' => $spouse_new_amount_reqd,
'booking_status' => $spouse_status,
'booking_payment_complete' => 'Y',
))
->condition('nid', $person->booking_partner_id)
->execute();
//send an email to the spouse
_booking_registration_email($person->booking_partner_id, TRUE);
}
}
//if this was an initial payment we might need to send a notification
elseif ($balance_payment == FALSE)
{
//send a notification email if we didn't automatically send one earlier
if (variable_get('booking_auto_confirm_email', 0) == 0)
{
_booking_registration_email($nid, FALSE);
}
}
else //this person still has an outstanding balance so just send a confirmation email
{
watchdog('booking', 'This balance payment of !payment was insufficient for !id to completely pay the total outstanding of !outstanding.',
array('!id' => $nid, '!payment' => $data['mc_gross'], '!outstanding' => $amount_owing));
//send the person an email thanking them for their partial payment
_booking_partialbalance_payment_email($nid);
//TODO: create an email specifically for partial-balance payments
//_booking_registration_email($nid, $balance_payment);
}
*/
}
else {
//couldn't find a matching nid for this invoice
else //couldn't find a matching nid for this invoice
{
watchdog('booking', "Unable to process payment for user with node id: '!id'", array('!id' => $nid), WATCHDOG_ERROR);
//db_query("UPDATE {booking_person} SET booking_tempid='' WHERE nid = %d", $nid);
}
}
/**
* Landing page after returning from paypal
*/
function booking_payment_completed_page() {
//get some configuration information
global $event;
$output = "";
$return_array = array();
/*
$parameters = drupal_get_query_parameters();
//check if we got a transaction token from paypal
if (isset($parameters['token'])) {
//check to make sure the value is something we're expecting
$paypal_token = $parameters['token'];
if (! preg_match('/^[0-9A-Fa-f\-]+$/', $paypal_token)) {
//parameter from url is not what we were expecting so ignore it and just use the site-wide tokens for this page
$tokens = booking_define_tokens();
}
else {
//query the payments table to find the attendee that this paypal token belongs to
}
}
*/
//set the page title
$bookingTitle = !empty($event->booking_eventname) ? $event->booking_eventname : 'Event';
drupal_set_title($bookingTitle . ' Registration Completed');
$input = variable_get('booking_regn_completed_page');
//watchdog('booking_debug', "<pre>Paypal landing page token:\n@info</pre>", array('@info' => print_r($input['value'] , true)));
$output = token_replace($input['value'], booking_define_tokens());
$return_array[] = array(
'paragraph' => array(
'#type' => 'markup',
'#markup' => $output
)
);
return $return_array;
}
/**
* Helper function to generate paypal form for payments
*/
function _booking_paypal_form($person, $invoiceid, $amount_owing, $button_text) {
$form = drupal_get_form('_booking_paypal_form_builder', $person, $invoiceid, $amount_owing, $button_text);
return drupal_render($form);
}
/**
* Helper function to generate form elements for paypal form
*/
function _booking_paypal_form_builder($node, &$form_state, $person, $invoiceid, $amount_owing, $button_text) {
global $event;
//get our current path so we can send the user back here if they cancel
$path = isset($_GET['q']) ? $_GET['q'] : '<front>';
//paypal specific settings
$vars = array(
'module' => 'Booking System',
'type' => $event->booking_eventname,
//'custom' => $data,
'item_name' => $event->booking_eventname . ' ' . $person->booking_price_descrip,
'invoice' => $invoiceid,
'no_shipping' => TRUE,
'no_note' => TRUE,
'currency_code' => 'AUD',
'return' => url('bookingfinal', array('absolute' => TRUE)),
'cancel_return' => url($path, array('absolute' => TRUE)),
'rm' => '2',
'amount' => $amount_owing,
'last_name' => $person->booking_lastname,
'first_name' => $person->booking_firstname,
'cmd' => '_xclick',
'notify_url' => url(BOOKING_PAYPAL_IPN_PATH, array('absolute' => TRUE)),
'business' => variable_get('booking_paypal_account', '')
);
$form['#action'] = url(variable_get('booking_paypal_sandbox', 0) ? BOOKING_PAYPAL_SUBMIT_URL_SANDBOX : BOOKING_PAYPAL_SUBMIT_URL, array('absolute' => TRUE));
//turn the array into a form
foreach($vars as $name => $value) {
$form[$name] = array(
'#type' => 'hidden',
'#value' => $value,
);
}
$form['submit'] = array(
'#type' => 'button',
'#value' => t($button_text),
);
//watchdog('booking', 'Booking Balance payment: @info', array ('@info' => var_export($form, TRUE)));
return $form;
}

View File

@@ -122,14 +122,6 @@ function booking_form($node, &$form_state, $inserting = FALSE)
'#title' => 'Personal details'
);
//add a fieldset for data only admins can see
if ($inserting == FALSE) {
$form['internal-details'] = array(
'#type' => 'fieldset',
'#title' => 'Internal Details'
);
}
$form['your-details']['booking_firstname'] = array(
'#type' => 'textfield',
'#title' => t('First Name'),
@@ -179,7 +171,8 @@ function booking_form($node, &$form_state, $inserting = FALSE)
// The status field should not be visible unless this registration is being updated...i.e. not at actual registration time...
if ($inserting != TRUE) {
$form['internal-details']['booking_comment_field'] = array(
$form['your-details']['booking_comment_field'] = array(
'#type' => 'textarea',
'#title' => t('Comments relating to this registration. Internal only.'),
'#cols' => 60,
@@ -192,28 +185,28 @@ function booking_form($node, &$form_state, $inserting = FALSE)
'#default_value' => !empty($data->booking_comment_field) ? $data->booking_comment_field : ''
);
$form['internal-details']['booking_status'] = array(
$form['your-details']['booking_status'] = array(
'#type' => 'select',
'#title' => t('Registration Status'),
'#options' => _booking_status_generate(),
'#default_value' => !empty($data->booking_status) ? $data->booking_status : ''
);
$form['internal-details']['booking_welfare_required'] = array(
$form['your-details']['booking_welfare_required'] = array(
'#type' => 'checkbox',
'#title' => t('Welfare Required?'),
'#description' => t('Select to mark this attendee as requiring special financial consideration'),
'#default_value' => (!empty($data->booking_welfare_required) && $data->booking_welfare_required == 'Y') ? 1 : 0
);
$form['internal-details']['booking_committee_member'] = array(
$form['your-details']['booking_committee_member'] = array(
'#type' => 'checkbox',
'#title' => t('Committee Member?'),
'#description' => t('Select to identify this attendee as being on the committee'),
'#default_value' => (!empty($data->booking_committee_member) && $data->booking_committee_member == 'Y') ? 1 : 0
);
$form['internal-details']['booking_amount_paid'] = array(
$form['your-details']['booking_amount_paid'] = array(
'#type' => 'textfield',
'#title' => t('Amount Paid'),
'#maxlength' => 10,
@@ -221,27 +214,27 @@ function booking_form($node, &$form_state, $inserting = FALSE)
'#default_value' => !empty($data->booking_amount_paid) ? $data->booking_amount_paid : ''
);
$form['internal-details']['booking_total_pay_reqd'] = array(
$form['your-details']['booking_total_pay_reqd'] = array(
'#type' => 'textfield',
'#title' => t('Total Amount Due'),
'#maxlength' => 10,
'#required' => FALSE,
'#default_value' => !empty($data->booking_total_pay_reqd) ? $data->booking_total_pay_reqd : '0.00'
);
$form['internal-details']['booking_payment_complete'] = array(
$form['your-details']['booking_payment_complete'] = array(
'#type' => 'checkbox',
'#title' => t('Payment Completed?'),
'#description' => t('Select to mark this attendee as having fully paid'),
'#default_value' => (!empty($data->booking_payment_complete) && $data->booking_payment_complete == 'Y') ? 1 : 0
);
//refund info
$form['internal-details']['booking_refund_processed'] = array(
$form['your-details']['booking_refund_processed'] = array(
'#type' => 'checkbox',
'#title' => t('Refund Processed?'),
'#description' => t('Select to mark the processing of any applicable refund as complete'),
'#default_value' => (!empty($data->booking_refund_processed) && $data->booking_refund_processed == 'Y') ? 1 : 0
);
$form['internal-details']['booking_refund_due'] = array(
$form['your-details']['booking_refund_due'] = array(
'#type' => 'textfield',
'#title' => t('Refund Amount Due'),
'#maxlength' => 10,
@@ -362,11 +355,10 @@ function booking_form($node, &$form_state, $inserting = FALSE)
));
//convert that into an array
foreach ($partners as $row) {
foreach ($partners as $row)
$partner_options[$row->nid] = $row->booking_firstname . ' ' . $row->booking_lastname;
}
//create a select field
$form['internal-details']['booking_partner_id'] = array(
$form['your-details']['booking_partner_id'] = array(
'#type' => 'select',
'#title' => t('Choose Spouse'),
'#default_value' => $data->booking_partner_id,
@@ -374,7 +366,7 @@ function booking_form($node, &$form_state, $inserting = FALSE)
);
//add the boyfriend/girlfriend field in here too
$form['internal-details']['booking_bf_gf_nid'] = array(
$form['your-details']['booking_bf_gf_nid'] = array(
'#type' => 'textfield',
'#title' => t('Registration ID of Boyfriend/Girlfriend to be placed in the same discussion groups as you.'),
'#maxlength' => 15,
@@ -382,16 +374,6 @@ function booking_form($node, &$form_state, $inserting = FALSE)
'#required' => FALSE,
'#default_value' => !empty($data->booking_bf_gf_nid) ? $data->booking_bf_gf_nid : ''
);
$form['internal-details']['booking_keepseparate_id'] = array(
'#type' => 'textfield',
'#title' => t('Registration ID of a person to keep separate when calculating discussion groups. Only a site administrator may set this.'),
'#maxlength' => 15,
'#size' => 4,
'#required' => FALSE,
'#default_value' => !empty($data->booking_keepseparate_id) ? $data->booking_keepseparate_id : ''
);
}
} //end allow couples check
@@ -431,7 +413,7 @@ function booking_form($node, &$form_state, $inserting = FALSE)
'#value' => 1
);
$form['internal-details']['booking_barcode'] = array(
$form['your-details']['booking_barcode'] = array(
'#type' => 'textfield',
'#title' => t('Barcode'),
'#maxlength' => 30,
@@ -440,7 +422,7 @@ function booking_form($node, &$form_state, $inserting = FALSE)
'#default_value' => !empty($data->booking_barcode) ? $data->booking_barcode : ''
);
$form['internal-details']['booking_luckynum'] = array(
$form['your-details']['booking_luckynum'] = array(
'#type' => 'textfield',
'#title' => t('Lucky Number'),
'#maxlength' => 30,
@@ -449,7 +431,7 @@ function booking_form($node, &$form_state, $inserting = FALSE)
'#default_value' => !empty($data->booking_luckynum) ? $data->booking_luckynum : ''
);
$form['internal-details']['booking_readinggroup'] = array(
$form['your-details']['booking_readinggroup'] = array(
'#type' => 'textfield',
'#title' => t('Reading Group Allocation'),
'#maxlength' => 100,
@@ -569,22 +551,9 @@ function booking_form($node, &$form_state, $inserting = FALSE)
'#title' => 'Emergency Contact Details',
'#description' => 'Please enter contact details for use in case of emergency'
);
if (variable_get('booking_enable_medicare', 1) == 1) {
$medicare_required_check = (variable_get('booking_enforce_medicare_verification', 1) == 1) && $inserting;
$form['emergency']['booking_medicare'] = array(
'#type' => 'textfield',
'#title' => t('Your Medicare Number'),
'#maxlength' => 15,
'#size' => 15,
'#required' => FALSE,
//'#required' => $medicare_required_check,
'#default_value' => empty($data->booking_medicare) ? '' : $data->booking_medicare
);
}
$form['emergency']['booking_guardian_name'] = array(
'#type' => 'textfield',
'#title' => t('Emergency Contact Name'),
'#title' => t('Parent/Guardian Name'),
'#maxlength' => 100,
'#required' => TRUE,
'#default_value' => empty($data->booking_guardian_name) ? '' : $data->booking_guardian_name
@@ -596,38 +565,9 @@ function booking_form($node, &$form_state, $inserting = FALSE)
'#default_value' => empty($data->booking_guardian_type) ? 'parent' : $data->booking_guardian_type,
'#required' => TRUE
);
//confirm the guardians email address if the user is entering details
//this isn't saved to the database
if ($inserting == TRUE) {
$form['emergency']['booking_guardian_email'] = array(
'#type' => 'textfield',
'#title' => t('Emergency Contact Email Address'),
'#size' => 30,
'#required' => TRUE,
'#default_value' => empty($data->booking_guardian_email) ? '' : $data->booking_guardian_email,
);
$form['emergency']['booking_guardian_email_confirm'] = array(
'#type' => 'textfield',
'#title' => t('Confirm Emergency Contact Email Address'),
'#size' => 30,
'#required' => TRUE,
'#default_value' => empty($data->booking_guardian_email_confirm) ? '' : $data->booking_guardian_email_confirm,
);
}
//don't require an admin to enter this field
else {
$form['emergency']['booking_guardian_email'] = array(
'#type' => 'textfield',
'#title' => t('Emergency Contact Email Address'),
'#size' => 30,
'#required' => FALSE,
'#default_value' => empty($data->booking_guardian_email) ? '' : $data->booking_guardian_email,
);
}
$form['emergency']['booking_guardian_phone'] = array(
'#type' => 'textfield',
'#title' => t('Emergency Contact Mobile Phone Number'),
'#title' => t('Contact Number'),
'#maxlength' => 30,
'#size' => 30,
'#required' => TRUE,
@@ -635,13 +575,192 @@ function booking_form($node, &$form_state, $inserting = FALSE)
);
$form['emergency']['booking_guardian_phone_alt'] = array(
'#type' => 'textfield',
'#title' => t('Emergency Contact Alternate Contact Number'),
'#title' => t('Alternate Contact Number'),
'#maxlength' => 30,
'#size' => 30,
'#required' => FALSE,
'#default_value' => empty($data->booking_guardian_phone_alt) ? '' : $data->booking_guardian_phone_alt
);
if (variable_get('booking_enable_medicare', 1) == 1) {
$form['emergency']['booking_medicare'] = array(
'#type' => 'textfield',
'#title' => t('Your Medicare Number'),
'#maxlength' => 15,
'#size' => 15,
'#required' => FALSE,
//'#required' => variable_get('booking_enforce_medicare_verification', 1) == 1 ? TRUE : FALSE,
'#default_value' => empty($data->booking_medicare) ? '' : $data->booking_medicare
);
}
if (variable_get('booking_enable_passport', 0) == 1) {
$form['passport-details'] = array(
'#type' => 'fieldset',
'#title' => 'Passport Details'
);
$form['passport-details']['booking_passport_num'] = array(
'#type' => 'textfield',
'#title' => t('Passport Number'),
'#maxlength' => 45,
'#required' => FALSE,
'#default_value' => !empty($data->booking_passport_num) ? $data->booking_passport_num : ''
);
$form['passport-details']['booking_passport_issue_location'] = array(
'#type' => 'textfield',
'#title' => t('City of Issue (eg Sydney)'),
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => !empty($data->booking_passport_issue_location) ? $data->booking_passport_issue_location : ''
);
$form['passport-details']['booking_passport_issue_name'] = array(
'#type' => 'textfield',
'#title' => t('Exact name as listed on passport'),
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => !empty($data->booking_passport_issue_name) ? $data->booking_passport_issue_name : ''
);
$form['passport-details']['booking_passport_expiry_date'] = array(
'#type' => 'date_select',
'#title' => t('Passport expiry date'),
'#default_value' => empty($data->booking_passport_expiry_date) ? '' : date("Y-m-d H:i:s", $data->booking_passport_expiry_date),
'#required' => FALSE,
'#date_format' => 'd/m/Y',
//'#date_label_position' => 'within',
'#date_year_range' => '+0:+13'
);
$form['passport-details']['booking_travel_insurance'] = array(
'#type' => 'textfield',
'#title' => t('Travel insurance policy details'),
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => !empty($data->booking_travel_insurance) ? $data->booking_travel_insurance : ''
);
if ($inserting == FALSE) {
$form['passport-details']['booking_destination_country'] = array(
'#type' => 'textfield',
'#title' => t('Which country is this person going to?'),
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => !empty($data->booking_destination_country) ? $data->booking_destination_country : ''
);
//flights from the conference week to the destination country
$form['outbound-flight-details'] = array(
'#type' => 'fieldset',
'#title' => 'Flight Details (Conference To Destination Country)'
);
$form['outbound-flight-details']['booking_outflight_bookingnum'] = array(
'#type' => 'textfield',
'#title' => t('Internal Flight Booking Reference (departing conference week)'),
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => !empty($data->booking_outflight_bookingnum) ? $data->booking_outflight_bookingnum : ''
);
$form['outbound-flight-details']['booking_outflight_flightnum'] = array(
'#type' => 'textfield',
'#title' => t('Internal Flight Number (departing conference week)'),
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => !empty($data->booking_outflight_flightnum) ? $data->booking_outflight_flightnum : ''
);
$form['outbound-flight-details']['booking_outflight_origin'] = array(
'#type' => 'textfield',
'#title' => t('Internal Flight Origin to Destination (departing conference week)'),
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => !empty($data->booking_outflight_origin) ? $data->booking_outflight_origin : ''
);
$form['outbound-flight-details']['booking_outflight_origin_ts'] = array(
'#type' => 'date_select',
'#title' => t('Internal flight departure time (local timezone)'),
'#description' => t('Note: 24 hour time - 12:00 is midday'),
'#default_value' => empty($data->booking_outflight_origin_ts) ? '' : date("Y-m-d H:i:s", $data->booking_outflight_origin_ts),
'#date_format' => 'd/m/Y H:i',
'#date_year_range' => '0:+1'
);
$form['outbound-flight-details']['booking_outflight_connecting_flightnum'] = array(
'#type' => 'textfield',
'#title' => t('Connecting Flight Number (if applicable)'),
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => !empty($data->booking_outflight_connecting_flightnum) ? $data->booking_outflight_connecting_flightnum : ''
);
$form['outbound-flight-details']['booking_outflight_destination'] = array(
'#type' => 'textfield',
'#title' => t('Connecting Flight Origin to Destination'),
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => !empty($data->booking_outflight_destination) ? $data->booking_outflight_destination : ''
);
$form['outbound-flight-details']['booking_outflight_destination_ts'] = array(
'#type' => 'date_select',
'#title' => t('Internal flight arrival time (local timezone)'),
'#description' => t('Note: 24 hour time - 12:00 is midday'),
'#default_value' => empty($data->booking_outflight_destination_ts) ? '' : date("Y-m-d H:i:s", $data->booking_outflight_destination_ts),
'#date_format' => 'd/m/Y H:i',
'#date_year_range' => '0:+1'
);
//flights from the destination country back to conference
$form['inbound-flight-details'] = array(
'#type' => 'fieldset',
'#title' => 'Flight Details (Destination Country Back To Conference)'
);
$form['inbound-flight-details']['booking_rtrnflight_bookingnum'] = array(
'#type' => 'textfield',
'#title' => t('Internal Flight Booking Reference (returning to conference)'),
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => !empty($data->booking_rtrnflight_bookingnum) ? $data->booking_rtrnflight_bookingnum : ''
);
$form['inbound-flight-details']['booking_rtrnflight_flightnum'] = array(
'#type' => 'textfield',
'#title' => t('Internal Flight Number (returning to conference)'),
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => !empty($data->booking_rtrnflight_flightnum) ? $data->booking_rtrnflight_flightnum : ''
);
$form['inbound-flight-details']['booking_rtrnflight_origin'] = array(
'#type' => 'textfield',
'#title' => t('Internal Flight Origin to Destination (returning to conference)'),
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => !empty($data->booking_rtrnflight_origin) ? $data->booking_rtrnflight_origin : ''
);
$form['inbound-flight-details']['booking_rtrnflight_origin_ts'] = array(
'#type' => 'date_select',
'#title' => t('Internal flight departure time (local timezone)'),
'#description' => t('Note: 24 hour time - 12:00 is midday'),
'#default_value' => empty($data->booking_rtrnflight_origin_ts) ? '' : date("Y-m-d H:i:s", $data->booking_rtrnflight_origin_ts),
'#date_format' => 'd/m/Y H:i',
'#date_year_range' => '0:+1'
);
$form['inbound-flight-details']['booking_rtrnflight_connecting_flightnum'] = array(
'#type' => 'textfield',
'#title' => t('Connecting Flight Number (if applicable)'),
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => !empty($data->booking_rtrnflight_connecting_flightnum) ? $data->booking_rtrnflight_connecting_flightnum : ''
);
$form['inbound-flight-details']['booking_rtrnflight_destination'] = array(
'#type' => 'textfield',
'#title' => t('Connecting Flight Origin to Destination'),
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => !empty($data->booking_rtrnflight_destination) ? $data->booking_rtrnflight_destination : ''
);
$form['inbound-flight-details']['booking_rtrnflight_destination_ts'] = array(
'#type' => 'date_select',
'#title' => t('Internal flight arrival time (local timezone)'),
'#description' => t('Note: 24 hour time - 12:00 is midday'),
'#default_value' => empty($data->booking_rtrnflight_destination_ts) ? '' : date("Y-m-d H:i:s", $data->booking_rtrnflight_destination_ts),
'#date_format' => 'd/m/Y H:i',
'#date_year_range' => '0:+1'
);
}
} //end passport only fields
if (variable_get('booking_enable_helpareas', 1) == 1) {
$form['help-areas'] = array(
'#type' => 'fieldset',
@@ -699,6 +818,47 @@ function booking_form($node, &$form_state, $inserting = FALSE)
$form['help-areas'][$key] = $value;
}
}
/*
$form['help-areas']['booking_help_music'] = array(
'#type' => 'textfield',
'#title' => t('I can help with music by playing the following musical instrument(s)'),
'#maxlength' => 200,
'#required' => FALSE,
'#default_value' => !empty($data->booking_help_music) ? $data->booking_help_music : ''
);
$form['help-areas']['booking_help_reading'] = array(
'#type' => 'checkbox',
'#title' => t('I can help with reading'),
'#default_value' => (!empty($data->booking_help_reading) && $data->booking_help_reading == 'Y') ? 1 : 0
);
$form['help-areas']['booking_help_chairing'] = array(
'#type' => 'checkbox',
'#title' => t('I can help with chairing'),
'#default_value' => (!empty($data->booking_help_chairing) && $data->booking_help_chairing == 'Y') ? 1 : 0
);
$form['help-areas']['booking_help_praying'] = array(
'#type' => 'checkbox',
'#title' => t('I can help with praying'),
'#default_value' => (!empty($data->booking_help_praying) && $data->booking_help_praying == 'Y') ? 1 : 0
);
$form['help-areas']['booking_help_meditations'] = array(
'#type' => 'checkbox',
'#title' => t('I can help with evening meditations'),
'#default_value' => (!empty($data->booking_help_meditations) && $data->booking_help_meditations == 'Y') ? 1 : 0
);
$form['help-areas']['booking_firstaid'] = array(
'#type' => 'checkbox',
'#title' => t('I am a qualified First Aid Officer'),
'#default_value' => (!empty($data->booking_firstaid) && $data->booking_firstaid == 'Y') ? 1 : 0
);
$form['help-areas']['booking_nurse'] = array(
'#type' => 'checkbox',
'#title' => t('I am a qualified Nurse'),
'#default_value' => (!empty($data->booking_nurse) && $data->booking_nurse == 'Y') ? 1 : 0
);
*/
}
if (variable_get('booking_enable_skills', 1) == 1) {
@@ -925,23 +1085,29 @@ function booking_form($node, &$form_state, $inserting = FALSE)
return $form;
}
function booking_form_validate($form, &$form_state) {
function booking_form_validate($form, &$form_state)
{
return _booking_validate($form_state['values']['form_id'], $form_state['input']);
}
function _booking_validate($node, &$form_state)
{
global $event;
$node = $form_state['values']['form_id'];
$data = $form_state['input'];
//watchdog('booking', '<pre>Booking registration form validation:\n@info</pre>', array('@info' => print_r( $data, true)));
//watchdog('booking', '<pre>Booking registration form validation:\n@info</pre>', array('@info' => print_r( $form_state, true)));
//in case the date of birth field hasn't been filled out
watchdog('booking', 'Blank date of birth checking: @info', array(
'@info' => var_export($data['booking_dob'], TRUE)
'@info' => var_export($form_state['booking_dob'], TRUE)
));
$dob_check = $data['booking_dob']['day'] != '' && $data['booking_dob']['month'] != '' && $data['booking_dob']['year'] != '' ? _datearray_to_ts($data['booking_dob']) : 0;
$dob_check = $form_state['booking_dob']['day'] != '' && $form_state['booking_dob']['month'] != '' && $form_state['booking_dob']['year'] != '' ? _datearray_to_ts($form_state['booking_dob']) : 0;
//Verify this is not a duplicate registration
//try and find the person in the database for this event
$person = db_query("SELECT person.nid, person.booking_tempid " . "FROM {booking_person} person " . "WHERE booking_firstname = :first AND booking_lastname = :last AND booking_dob = :dob AND booking_eventid = :eid", array(
':first' => $data['booking_firstname'],
':last' => $data['booking_lastname'],
':first' => $form_state['booking_firstname'],
':last' => $form_state['booking_lastname'],
':dob' => $dob_check,
':eid' => $event->eid
))->fetchObject();
@@ -961,9 +1127,9 @@ function booking_form_validate($form, &$form_state) {
}
//verify partner id is in the correct format
if (isset($data['booking_partner_id']) && $data['booking_partner_id'] != '') {
if (isset($form_state['booking_partner_id']) && $form_state['booking_partner_id'] != '') {
if (!is_numeric($data['booking_partner_id'])) {
if (!is_numeric($form_state['booking_partner_id'])) {
form_set_error('booking_partner_id', t('You have entered an invalid partner registration id. Please ensure you are using only the registration reference number your partner received via email. If you believe this to be incorrect, please !contact using the details provided.', array(
'!contact' => l('contact us', 'contact')
)));
@@ -971,7 +1137,7 @@ function booking_form_validate($form, &$form_state) {
//check that the partner exists
$partner = db_query("SELECT person.nid, person.booking_married " . "FROM {booking_person} person " . "WHERE nid = :nid AND person.booking_married = 'Y'", array(
':nid' => $data['booking_partner_id']
':nid' => $form_state['booking_partner_id']
))->fetchObject();
//watchdog('booking', 'Checking for partner via query: @info', array('@info' => $partner->__toString()));
@@ -983,39 +1149,25 @@ function booking_form_validate($form, &$form_state) {
}
}
//watchdog('booking', 'Form validate data: @info', array('@info' => var_export($data, TRUE)));
//validate attendee's email address
$email = (isset($data['booking_email']) ? $data['booking_email'] : $node->booking_email);
if (strlen(trim($email)) > 0 && !_valid_email_address($email)) {
//watchdog('booking', 'Form validate data: @info', array('@info' => var_export($form_state, TRUE)));
$email = (isset($form_state['booking_email']) ? $form_state['booking_email'] : $node->booking_email);
if (strlen(trim($email)) > 0 && !_valid_email_address($email))
form_set_error('booking_email', t('You must enter a valid e-mail address. Please ensure you typed your email address correctly.'));
}
//make sure that the email confirmation field matches the first email address entry
$email_confirm = (isset($data['booking_email_confirm']) ? $data['booking_email_confirm'] : $node->booking_email);
$email_confirm = (isset($form_state['booking_email_confirm']) ? $form_state['booking_email_confirm'] : $node->booking_email);
$email = preg_replace('/\s+/', '', $email);
$email_confirm = preg_replace('/\s+/', '', $email_confirm);
if (strcasecmp($email, $email_confirm) !== 0) {
form_set_error('booking_email', t('Your email addresses do not match. Please ensure you typed your email address correctly.'));
}
//validate emergency contact's email address
$guardian_email = (isset($data['booking_guardian_email']) ? $data['booking_guardian_email'] : $node->booking_guardian_email);
if (strlen(trim($guardian_email)) > 0 && !_valid_email_address($guardian_email)) {
form_set_error('booking_guardian_email', t('You must enter a valid e-mail address. Please ensure you typed your emergency contact\'s email address correctly.'));
}
$guardian_email_confirm = (isset($data['booking_guardian_email_confirm']) ? $data['booking_guardian_email_confirm'] : $node->booking_guardian_email);
$guardian_email = preg_replace('/\s+/', '', $guardian_email);
$guardian_email_confirm = preg_replace('/\s+/', '', $guardian_email_confirm);
if (strcasecmp($guardian_email_confirm, $guardian_email_confirm) !== 0) {
form_set_error('booking_guardian_email', t('Your emergency contact\'s email addresses do not match. Please ensure you typed your emergency contact\'s email address correctly.'));
form_set_error('booking_email', t('Your email address does not match. Please ensure you typed your email address correctly.'));
}
//if DOB on form is more recent than DOB limit, display validation error
if ($dob_check > _booking_max_dob_ts()) {
watchdog('booking', "Attempt to register from !first !last, who is too young (!info) to attend event.", array(
'!first' => $data['booking_firstname'],
'!last' => $data['booking_lastname'],
'!info' => var_export($data['booking_dob'], TRUE)
'!first' => $form_state['booking_firstname'],
'!last' => $form_state['booking_lastname'],
'!info' => var_export($form_state['booking_dob'], TRUE)
));
form_set_error('booking_dob', t('Unfortunately you are too young to attend !event.', array(
'!event' => variable_get('booking_event_name', 'this event')
@@ -1023,13 +1175,13 @@ function booking_form_validate($form, &$form_state) {
}
//check the medicare number for people in Australia
if (variable_get('booking_enable_medicare', 1) == 1 && $data['booking_country'] == 'Australia') {
if (variable_get('booking_enable_medicare', 1) == 1 && $form_state['booking_country'] == 'Australia') {
//proper validation routine at http://dyball.wordpress.com/2007/12/05/validation-of-medicare-numbers/
if ((variable_get('booking_enforce_medicare_verification', 1) == 1) && (!_valid_medicare_number($data['booking_medicare']))) {
if ((variable_get('booking_enforce_medicare_verification', 1) == 1) && (!_valid_medicare_number($form_state['booking_medicare']))) {
form_set_error('booking_medicare', t('You have entered an invalid medicare number. Please check your medicare card and re-enter the number. If you believe this to be incorrect, please !contact.', array(
'!contact' => l('send us an email', 'mailto:' . variable_get('booking_contact_email') . '?subject=Invalid Medicare Number')
)));
} elseif ((variable_get('booking_enforce_medicare_verification', 1) == 0) && (!_valid_medicare_number($data['booking_medicare']))) {
} elseif ((variable_get('booking_enforce_medicare_verification', 1) == 0) && (!_valid_medicare_number($form_state['booking_medicare']))) {
drupal_set_message(t('You have entered an invalid medicare number. Please ensure you check your medicare card and send us the correct information via !contact.', array(
'!contact' => l('email', 'mailto:' . variable_get('booking_contact_email') . '?subject=Invalid Medicare Number')
)), 'error', FALSE);
@@ -1039,24 +1191,24 @@ function booking_form_validate($form, &$form_state) {
//verify state information with the new few checks
//make sure state field is not blank
if ($data['booking_state'] == '_blank_') {
if ($form_state['booking_state'] == '_blank_') {
form_set_error('booking_state', t('You must enter your State in the address section of the Contact details. ' . 'Please choose a state of Other and specify N/A if your country does not have states, or choose NZ if you reside in New Zealand.'));
}
//verify international address has updated the state field
if ((strcasecmp($data['booking_country'], 'New Zealand') == 0) && (strcasecmp($data['booking_state'], 'NZ') !== 0)) {
if ((strcasecmp($form_state['booking_country'], 'New Zealand') == 0) && (strcasecmp($form_state['booking_state'], 'NZ') !== 0)) {
form_set_error('booking_state', t('You have indicated you reside in New Zealand. Please select NZ as your state.'));
} elseif ((strcasecmp($data['booking_country'], 'Australia') !== 0) && (strcasecmp($data['booking_state'], 'Other') !== 0) && (strcasecmp($data['booking_state'], 'NZ') !== 0)) {
} elseif ((strcasecmp($form_state['booking_country'], 'Australia') !== 0) && (strcasecmp($form_state['booking_state'], 'Other') !== 0) && (strcasecmp($form_state['booking_state'], 'NZ') !== 0)) {
form_set_error('booking_state', t('You must enter your State in the address section of the Contact details. Please choose a state of Other and specify N/A if your country does not have states.'));
}
//verify that a state has been entered if "Other" was selected
if (($data['booking_state'] == 'Other') && ($data['booking_other_state'] == ''))
if (($form_state['booking_state'] == 'Other') && ($form_state['booking_other_state'] == ''))
form_set_error('booking_other_state', t('You must enter your State in the address section of the Contact details. Please put N/A if your country does not have states.'));
//verify passport number
if (variable_get('booking_enable_passport', 0) == 1 && $data['booking_country'] == 'Australia') {
if (($data['booking_passport_num'] != '') && (!_valid_passport_number($data['booking_passport_num']))) {
if (variable_get('booking_enable_passport', 0) == 1 && $form_state['booking_country'] == 'Australia') {
if (($form_state['booking_passport_num'] != '') && (!_valid_passport_number($form_state['booking_passport_num']))) {
form_set_error('booking_passport_num', t('You have entered an invalid passport number. Please check your passport and re-enter the number. ' . 'If you believe this to be incorrect, please !contact.', array(
'!contact' => l('send us an email', 'mailto:' . variable_get('booking_contact_email') . '?subject=Invalid Passport Number')
)));
@@ -1064,40 +1216,29 @@ function booking_form_validate($form, &$form_state) {
}
//check at least one phone number has been entered
if (($data['booking_phone'] == '') && ($data['booking_mobile'] == ''))
if (($form_state['booking_phone'] == '') && ($form_state['booking_mobile'] == ''))
form_set_error('booking_mobile', t('You must enter at least one phone number, either a mobile phone or a home phone number.'));
if (($data['booking_phone'] != '') && (!_valid_phone_number($data['booking_phone'])))
if (($form_state['booking_phone'] != '') && (!_valid_phone_number($form_state['booking_phone'])))
form_set_error('booking_phone', t('You have entered an invalid home phone number.'));
if (($data['booking_mobile'] != '') && (!_valid_phone_number($data['booking_mobile'])))
if (($form_state['booking_mobile'] != '') && (!_valid_phone_number($form_state['booking_mobile'])))
form_set_error('booking_mobile', t('You have entered an invalid mobile phone number.'));
//verify an australian mobile number is entered correctly if applicable
if (($data['booking_mobile'] != '') && ($data['booking_country'] == 'Australia') && (!_valid_australian_mobile_number($data['booking_mobile'])))
if (($form_state['booking_mobile'] != '') && ($form_state['booking_country'] == 'Australia') && (!_valid_australian_mobile_number($form_state['booking_mobile'])))
form_set_error('booking_mobile', t('You have entered an invalid mobile phone number.'));
//validate guardian phone number
if ($data['booking_country'] == 'Australia') {
if (!_valid_australian_mobile_number($data['booking_guardian_phone'])) {
form_set_error('booking_guardian_phone', t('You have entered an invalid contact phone number for your emergency contact.'));
}
} else {
if (!_valid_phone_number($data['booking_guardian_phone'])) {
form_set_error('booking_guardian_phone', t('You have entered an invalid contact phone number for your emergency contact.'));
}
}
//verify alternate guardian phone number
if (($data['booking_guardian_phone_alt'] != '') && (!_valid_phone_number($data['booking_guardian_phone_alt'])))
form_set_error('booking_guardian_phone_alt', t('You have entered an invalid alternate contact phone number for your emergency contact.'));
//verify guardian phone number(s)
if (($form_state['booking_guardian_phone'] != '') && (!_valid_phone_number($form_state['booking_guardian_phone'])))
form_set_error('booking_guardian_phone', t('You have entered an contact phone number for your emergency contact.'));
//check the terms and conditions have been agreed to. Do this one last so it stands out more
if ($data['booking_agreement'] == 0)
if ($form_state['booking_agreement'] == 0)
form_set_error('booking_agreement', t('You must read and agree with the aims and expectations prior to submitting this form.'));
//if there are any errors then log the data the user entered so we can check it later
if (form_get_errors()) {
watchdog('booking', "<pre>Detected validation error(s):\n@errors\n\n User data:\n@info</pre>", array(
'@info' => print_r($data, true),
'@info' => print_r($form_state, true),
'@errors' => print_r(form_get_errors(), true)
));
}
@@ -1139,7 +1280,6 @@ function booking_form_submit($form, &$form_state)
$node->booking_status = 0; //zero means not yet coming. Only change to 1 when a payment is made
//passport details
/*
$node->booking_passport_num = empty($values['booking_passport_num']) ? '' : $values['booking_passport_num'];
$node->booking_passport_issue_location = empty($values['booking_passport_issue_location']) ? '' : $values['booking_passport_issue_location'];
$node->booking_passport_issue_name = empty($values['booking_passport_issue_name']) ? '' : $values['booking_passport_issue_name'];
@@ -1163,7 +1303,7 @@ function booking_form_submit($form, &$form_state)
$node->booking_rtrnflight_connecting_flightnum = empty($values['booking_rtrnflight_connecting_flightnum']) ? '' : $values['booking_rtrnflight_connecting_flightnum'];
$node->booking_rtrnflight_destination = empty($values['booking_rtrnflight_destination']) ? '' : $values['booking_rtrnflight_destination'];
$node->booking_rtrnflight_destination_ts = empty($values['booking_rtrnflight_destination_ts']) ? '0' : _datetime_array_to_ts($values['booking_rtrnflight_destination_ts']);
*/
//payment details
$node->booking_payment_id = $values['booking_payment_id'];
@@ -1181,7 +1321,6 @@ function booking_form_submit($form, &$form_state)
$node->booking_partner_name = empty($values['booking_partner_name']) ? '' : ucwords($values['booking_partner_name']);
$node->booking_partner_id = empty($values['booking_partner_id']) ? 0 : $values['booking_partner_id'];
$node->booking_bf_gf_nid = empty($values['booking_bf_gf_nid']) ? 0 : $values['booking_bf_gf_nid'];
$node->booking_keepseparate_id = empty($values['booking_keepseparate_id']) ? 0 : $values['booking_keepseparate_id'];
//allow for user-entered value if the state is not already listed
if ($values['booking_state'] == 'Other') {
@@ -1193,7 +1332,6 @@ function booking_form_submit($form, &$form_state)
//emergency contact info
$node->booking_guardian_name = $values['booking_guardian_name'];
$node->booking_guardian_type = $values['booking_guardian_type'];
$node->booking_guardian_email = $values['booking_guardian_email'];
$node->booking_guardian_phone = $values['booking_guardian_phone'];
$node->booking_guardian_phone_alt = $values['booking_guardian_phone_alt'];
$node->booking_medicare = empty($values['booking_medicare']) ? 0 : $values['booking_medicare'];
@@ -1275,8 +1413,6 @@ function _booking_form_submit_post_triggers($node)
{
global $event;
//do these triggers really do anything? The partner id and bf/gf id won't be set in initial submit
//if booking_partner_id is set, make sure the nid it refers to has this node as its booking_partner_id
if ($node->booking_partner_id != 0) {
$partner = db_query("Select booking_partner_id from {booking_person} where nid = :nid", array(
@@ -1294,23 +1430,6 @@ function _booking_form_submit_post_triggers($node)
}
}
//repeat the process above for bf/gf
if ($node->booking_bf_gf_nid != 0) {
$partner = db_query("Select booking_bf_gf_nid from {booking_person} where nid = :nid", array(
':nid' => $node->booking_bf_gf_nid
))->fetchObject();
if ($partner->booking_bf_gf_nid == 0) {
watchdog('booking', 'Updating bf/gf node !partner to refer to this node !nid', array(
'!partner' => $node->booking_bf_gf_nid,
'!nid' => $node->nid
));
//update the partner id of the partner to refer to this node
db_update('booking_person')->fields(array(
'booking_bf_gf_nid' => $node->nid
))->condition('nid', $node->booking_bf_gf_nid)->execute();
}
}
//check whether we should send an automatic email even though they haven't paid yet
if (variable_get('booking_auto_confirm_email', 0) == 1) {
//send the person an email
@@ -1319,4 +1438,33 @@ function _booking_form_submit_post_triggers($node)
//just send a notification email
_booking_regn_notifyonly_email($node, FALSE);
}
}
/**
* Landing page after returning from paypal
*/
function booking_payment_completed_page()
{
//get some configuration information
global $event;
$output = "";
$return_array = array();
//set the page title
$bookingTitle = !empty($event->booking_eventname) ? $event->booking_eventname : 'Event';
drupal_set_title($bookingTitle . ' Registration Completed');
$input = variable_get('booking_regn_completed_page');
watchdog('booking_debug', "<pre>Paypal landing page token:\n@info</pre>", array('@info' => print_r($input['value'] , true)));
$output = token_replace($input['value'], booking_define_tokens());
$return_array[] = array(
'paragraph' => array(
'#type' => 'markup',
'#markup' => $output
)
);
return $return_array;
}

View File

@@ -12,105 +12,6 @@ function booking_node_presave($node) {
}
}
/**
* Function to create a mysql view of all information relating to an attendee
*
* @param
* @return
*/
function _booking_node_create_mysqlview()
{
global $event;
$studygroups = array();
//sometimes we will execute when hook_init hasn't been called
//for example at install or upgrade time
//so query the database directly for the event currently active
if ($event == NULL) {
watchdog('booking_debug', "Calling _booking_node_create_mysqlview() when hook_init not yet run.");
$event = db_query("SELECT * from {booking_event} where booking_event_active=1")->fetchObject();
}
$query = db_select('booking_person', 'p');
//add price info
$query->join('booking_price', 'pr', 'p.booking_payment_id = pr.pid');
//add travel form info if it exists
$query->leftJoin('booking_travel', 't', 'p.nid = t.booking_person_nid');
//add the joins for room allocation info if enabled
if (variable_get('booking_enable_roomallocations', 0) == 1) {
$query->leftJoin('booking_room_mapping', 'rm', 'p.nid = rm.booking_nodeid');
$query->leftJoin('booking_room_definition', 'r', 'rm.booking_roomid = r.rid');
$query->leftJoin('booking_room_locations', 'l', 'l.lid = r.booking_room_location_id');
}
//add the joins to flatten out study groups into columns
if (variable_get('booking_enable_studygroups', 0) == 1) {
//get details of the study groups defined for this event
//but when this function gets called we don't have the global $event variable populated, so do the join here ourselves
$studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} l INNER JOIN {booking_event} e ON l.booking_eventid = e.eid WHERE e.booking_event_active=1");
$studygroups = $studygroups_query->fetchAllAssoc('sid');
foreach ($studygroups as $studygroup) {
$id = $studygroup->sid;
$query->leftJoin('booking_studygroup_mapping', 's' . $id, 'p.nid = s' . $id . '.booking_node_id and s' . $id . '.booking_studygroup_id = ' . $id);
}
}
//filter the results either by current active event
// @todo is this filter really necessary?
$query->condition('p.booking_eventid', $event->eid, '=');
//add the database fields we always want to retrieve
$query->fields('p')
->fields('t')
->fields('pr', array('booking_price', 'booking_price_descrip','booking_late_price'));
if (variable_get('booking_enable_roomallocations', 0) == 1) {
$query->fields('rm', array('booking_room_bedtype'))
->fields('r', array('rid', 'booking_room_location_id', 'booking_room_number'))
->fields('l');
}
//now add the study group fields if applicable
if (variable_get('booking_enable_studygroups', 0) == 1) {
foreach ($studygroups as $studygroup)
{
$id = $studygroup->sid;
$query->addField('s' . $id, 'booking_session_id', 'session' . $id);
$query->addField('s' . $id, 'booking_studygroup_role', 'session' . $id . '_role');
}
}
//now that we have built the query as a SelectObject, turn it into a string we can use to create a view
$querystring=$query->__toString();
$querystring=str_replace("{",'',$querystring);
$querystring=str_replace("}",'',$querystring);
foreach($query->getArguments() as $key=> $item) {
if(!$item) {
$item = 'NULL';
}
$querystring=str_replace($key.')',$item.')',$querystring);
}
$querystring = "CREATE OR REPLACE VIEW booking_person_view AS " . $querystring;
watchdog('booking_debug', "<pre>Booking Person View creation query string:\n@info</pre>", array('@info' => print_r($querystring, true)));
$viewquery = db_query($querystring)->execute();
//$result = $viewquery->fetchObject();
watchdog('booking_debug', "<pre>Booking Person View creation result:\n@info</pre>", array('@info' => print_r($viewquery, true)));
}
/**
* Function to add single quote marks around a string
* @see booking_load_query
*
* @param $input - string to add quote marks around
* @return quoted string
*/
function _booking_quote_string($input) {
return sprintf("'%s'", $input);
}
/**
* Function to query the database for the complete object representing a registration
*
@@ -119,29 +20,7 @@ function _booking_quote_string($input) {
*/
function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE)
{
//filter the results either by specific nodes if passed as a parameter or by all nodes matching the event id
if (! is_null($node_ids)) {
$nid_string = implode(',', array_map('_booking_quote_string', $node_ids));
$query_string = "SELECT * FROM {booking_person_view} WHERE nid IN ( " . $nid_string . " )";
//watchdog('booking_debug', "<pre>Loading node query:\n@info</pre>", array('@info' => print_r($query_string, true)));
$result = db_query($query_string)->fetchAllAssoc('nid');
}
else {
$result = db_query("SELECT * FROM {booking_person_view}")->fetchAllAssoc('nid');
}
//watchdog('booking', "<pre>Loading node query output:\n@info</pre>", array('@info' => print_r( $result, true)));
return $result;
}
/**
* Function to query the database for the complete object representing a registration
*
* @param $node_ids - a list of node IDs to query for
* @return list of objects
*/
function booking_load_query_old($node_ids = NULL, $fetchAssoc = FALSE)
{
global $event;
//$studygroup_count = variable_get('booking_studygroup_count','0');
$studygroups = array();
@@ -229,7 +108,6 @@ function booking_load_query_old($node_ids = NULL, $fetchAssoc = FALSE)
}
*/
}
watchdog('booking_debug', "<pre>Loading node query:\n@info</pre>", array('@info' => print_r( (string)$query, true)));
//get the query result as either an associative array
if ($fetchAssoc == TRUE)
@@ -245,13 +123,6 @@ function booking_load_query_old($node_ids = NULL, $fetchAssoc = FALSE)
return $result;
}
/**
* Function implementing hook_load for the node-type booking
* @see booking_load_query
*
* @param $nodes - An array of the nodes being loaded, keyed by nid
* @return nothing
*/
function booking_load($nodes) {
global $event;
@@ -273,7 +144,8 @@ function booking_load($nodes) {
}
function booking_insert($node) {
watchdog('booking_debug', "<pre>Inserting node:\n@info</pre>", array('@info' => print_r($node, TRUE)));
watchdog('booking', 'Inserting node: @info', array('@info' => var_export($node, TRUE)));
//TODO: Generalise this by using the keys from $node instead of hard coding everything
db_insert('booking_person')
@@ -285,6 +157,27 @@ function booking_insert($node) {
'booking_dob' => $node->booking_dob,
'booking_barcode' => $node->booking_barcode,
'booking_luckynum' => $node->booking_luckynum,
'booking_passport_num' => $node->booking_passport_num,
'booking_passport_issue_location' => $node->booking_passport_issue_location,
'booking_passport_issue_name' => $node->booking_passport_issue_name,
'booking_passport_expiry_date' => $node->booking_passport_expiry_date,
'booking_destination_country' => $node->booking_destination_country,
'booking_travel_insurance' => $node->booking_travel_insurance,
'booking_outflight_bookingnum' => $node->booking_outflight_bookingnum,
'booking_outflight_flightnum' => $node->booking_outflight_flightnum,
'booking_outflight_bookingnum' => $node->booking_outflight_bookingnum,
'booking_outflight_origin' => $node->booking_outflight_origin,
'booking_outflight_origin_ts' => $node->booking_outflight_origin_ts,
'booking_outflight_connecting_flightnum' => $node->booking_outflight_connecting_flightnum,
'booking_outflight_destination' => $node->booking_outflight_destination,
'booking_outflight_destination_ts' => $node->booking_outflight_destination_ts,
'booking_rtrnflight_bookingnum' => $node->booking_rtrnflight_bookingnum,
'booking_rtrnflight_flightnum' => $node->booking_rtrnflight_flightnum,
'booking_rtrnflight_origin' => $node->booking_rtrnflight_origin,
'booking_rtrnflight_origin_ts' => $node->booking_rtrnflight_origin_ts,
'booking_rtrnflight_connecting_flightnum' => $node->booking_rtrnflight_connecting_flightnum,
'booking_rtrnflight_destination' => $node->booking_rtrnflight_destination,
'booking_rtrnflight_destination_ts' => $node->booking_rtrnflight_destination_ts,
'booking_gender' => $node->booking_gender,
'booking_street' => $node->booking_street,
'booking_suburb' => $node->booking_suburb,
@@ -319,7 +212,6 @@ function booking_insert($node) {
'booking_total_pay_reqd' => $node->booking_total_pay_reqd,
'booking_guardian_name' => $node->booking_guardian_name,
'booking_guardian_type' => $node->booking_guardian_type,
'booking_guardian_email' => $node->booking_guardian_email,
'booking_guardian_phone' => $node->booking_guardian_phone,
'booking_guardian_phone_alt' => $node->booking_guardian_phone_alt,
'booking_medicare' => empty($node->booking_medicare) ? '' : $node->booking_medicare,
@@ -372,6 +264,27 @@ function booking_update($node) {
'booking_dob' => _date_to_ts($node->booking_dob),
'booking_barcode' => $node->booking_barcode,
'booking_luckynum' => $node->booking_luckynum == '' ? 0 : $node->booking_luckynum,
'booking_passport_num' => $node->booking_passport_num,
'booking_passport_issue_location' => $node->booking_passport_issue_location,
'booking_passport_issue_name' => $node->booking_passport_issue_name,
'booking_passport_expiry_date' => _date_to_ts($node->booking_passport_expiry_date),
'booking_destination_country' => $node->booking_destination_country,
'booking_travel_insurance' => $node->booking_travel_insurance,
'booking_outflight_bookingnum' => $node->booking_outflight_bookingnum,
'booking_outflight_flightnum' => $node->booking_outflight_flightnum,
'booking_outflight_bookingnum' => $node->booking_outflight_bookingnum,
'booking_outflight_origin' => $node->booking_outflight_origin,
'booking_outflight_origin_ts' => _datetime_to_ts($node->booking_outflight_origin_ts),
'booking_outflight_connecting_flightnum' => $node->booking_outflight_connecting_flightnum,
'booking_outflight_destination' => $node->booking_outflight_destination,
'booking_outflight_destination_ts' => _datetime_to_ts($node->booking_outflight_destination_ts),
'booking_rtrnflight_bookingnum' => $node->booking_rtrnflight_bookingnum,
'booking_rtrnflight_flightnum' => $node->booking_rtrnflight_flightnum,
'booking_rtrnflight_origin' => $node->booking_rtrnflight_origin,
'booking_rtrnflight_origin_ts' => _datetime_to_ts($node->booking_rtrnflight_origin_ts),
'booking_rtrnflight_connecting_flightnum' => $node->booking_rtrnflight_connecting_flightnum,
'booking_rtrnflight_destination' => $node->booking_rtrnflight_destination,
'booking_rtrnflight_destination_ts' => _datetime_to_ts($node->booking_rtrnflight_destination_ts),
'booking_gender' => $node->booking_gender,
'booking_street' => $node->booking_street,
'booking_suburb' => $node->booking_suburb,
@@ -389,7 +302,6 @@ function booking_update($node) {
'booking_partner_id' => $node->booking_partner_id,
'booking_dependant_children' => $node->booking_dependant_children,
'booking_bf_gf_nid' => $node->booking_bf_gf_nid == '' ? 0 : $node->booking_bf_gf_nid,
'booking_keepseparate_id' => $node->booking_keepseparate_id == '' ? 0 : $node->booking_keepseparate_id,
'booking_room_mate1' => $node->booking_room_mate1,
'booking_room_mate2' => $node->booking_room_mate2,
'booking_random_facts' => $node->booking_random_facts,
@@ -409,7 +321,6 @@ function booking_update($node) {
'booking_refund_due' => $node->booking_refund_due == '' ? 0 : $node->booking_refund_due,
'booking_guardian_name' => $node->booking_guardian_name,
'booking_guardian_type' => $node->booking_guardian_type,
'booking_guardian_email' => $node->booking_guardian_email,
'booking_guardian_phone' => $node->booking_guardian_phone,
'booking_guardian_phone_alt' => $node->booking_guardian_phone_alt,
'booking_medicare' => $node->booking_medicare,
@@ -442,11 +353,13 @@ function booking_update($node) {
//***now process some post-update triggers***
//if booking_partner_id is set, make sure the nid it refers to has this node as its booking_partner_id
if ($node->booking_partner_id != 0) {
if ($node->booking_partner_id != 0)
{
$partner = db_query("Select booking_partner_id from {booking_person} where nid = :nid",
array(':nid' => $node->booking_partner_id))
->fetchObject();
if ($partner->booking_partner_id == 0) {
if ($partner->booking_partner_id == 0)
{
watchdog('booking', 'Updating partner node !partner to refer to this node !nid',
array('!partner' => $node->booking_partner_id, '!nid' => $node->nid));
//update the partner id of the partner to refer to this node
@@ -459,24 +372,6 @@ function booking_update($node) {
}
}
//repeat the process for bf/gf
if ($node->booking_bf_gf_nid != 0) {
$partner = db_query("Select booking_bf_gf_nid from {booking_person} where nid = :nid",
array(':nid' => $node->booking_bf_gf_nid))
->fetchObject();
if ($partner->booking_bf_gf_nid == 0) {
watchdog('booking', 'Updating bf/gf node !partner to refer to this node !nid',
array('!partner' => $node->booking_bf_gf_nid, '!nid' => $node->nid));
//update the partner id of the partner to refer to this node
db_update('booking_person')
->fields(array(
'booking_bf_gf_nid' => $node->nid,
))
->condition('nid', $node->booking_bf_gf_nid)
->execute();
}
}
//status change triggers start here
//check if someone has moved to not-coming list from the booked-in list
@@ -499,25 +394,27 @@ function booking_update($node) {
_booking_person_rooms_cleanup($node->nid);
//check if there is room on the booked-in list
if (_booking_check_bookings_full() == False) {
if (_booking_check_bookings_full() == False)
{
watchdog('booking', 'Looks like there was room on the booked in list, so lets tell the next person');
//find the first person on the waiting list
$temp_nid = _booking_get_waitinglist_top();
//-1 means there was no one on the waiting list
if ($temp_nid != -1) {
if ($temp_nid != -1) //-1 means there was no one on the waiting list
{
//update their registration status
_booking_change_status($temp_nid,1);
//send them an email
_booking_promoted_from_waitinglist_email($temp_nid);
}
}
else {
else
watchdog('booking', 'Still no room on the booked in list though.');
}
}
//check if someone has moved to booked-in list from waiting-list
elseif ($previous_status->booking_status == 2 && $node->booking_status == 1) {
elseif ($previous_status->booking_status == 2 && $node->booking_status == 1)
{
watchdog('booking', 'Detected person moving from Waiting list to Booked In');
//send them an email
@@ -542,7 +439,8 @@ function booking_update($node) {
}
//check if someone has been demoted to the "missed payment deadline" status from being booked-in
elseif ($previous_status->booking_status == 1 && $node->booking_status == 4) {
elseif ($previous_status->booking_status == 1 && $node->booking_status == 4)
{
watchdog('booking', 'Detected person moving from Booked In list to Missed Payment Deadline list.');
//let this person know they're no longer "booked in"
@@ -555,25 +453,29 @@ function booking_update($node) {
_booking_person_rooms_cleanup($node->nid);
//check if there is room on the booked-in list
if (_booking_check_bookings_full() == False) {
if (_booking_check_bookings_full() == False)
{
watchdog('booking', 'Position available, so lets tell the next person');
//find the first person on the waiting list
$temp_nid = _booking_get_waitinglist_top();
//-1 means there was no one on the waiting list
if ($temp_nid != -1) {
if ($temp_nid != -1) //-1 means there was no one on the waiting list
{
//update their registration status
_booking_change_status($temp_nid,1);
//send them an email
_booking_promoted_from_waitinglist_email($temp_nid);
}
}
else {
else
{
watchdog('booking', 'Still no room on the booked in list.');
}
}
//if someone is moving to the not-coming list from the waiting list
elseif ($previous_status->booking_status == 2 && $node->booking_status == 3) {
elseif ($previous_status->booking_status == 2 && $node->booking_status == 3)
{
watchdog('booking', 'Detected person moving from waiting list to No Longer Coming');
//let this person know their request has been processed
_booking_demoted_to_notcoming_email($node->nid);
@@ -588,7 +490,8 @@ function booking_update($node) {
}
//if we're not automatically sending emails on registration
//and someone moved from not-paid to booked-in (ie, manual payment process)
elseif (variable_get('booking_auto_confirm_email', 0) == 0 && $previous_status->booking_status == 0 && $node->booking_status == 1) {
elseif (variable_get('booking_auto_confirm_email', 0) == 0 && $previous_status->booking_status == 0 && $node->booking_status == 1)
{
watchdog('booking', 'Detected person moving from Not Paid list to Booked In list');
//make sure the booked in list isn't full
@@ -601,9 +504,11 @@ function booking_update($node) {
}
}
//if someone moved from the not-paid list to waiting list by manual update
elseif ($previous_status->booking_status == 0 && $node->booking_status == 2) {
elseif ($previous_status->booking_status == 0 && $node->booking_status == 2)
{
watchdog('booking', 'Detected person moving from Not Paid list to Waiting List');
//create a manual payment entry of zero dollars
//so things like the waiting list report work
$result = db_insert('booking_payment')
@@ -632,7 +537,8 @@ function booking_update($node) {
}
//if the payment ID has changed then update the total pay required
if ($previous_status->booking_payment_id != $node->booking_payment_id) {
if ($previous_status->booking_payment_id != $node->booking_payment_id)
{
$total_due = 0;
watchdog('booking', 'Detected payment type change for attendee');
@@ -694,35 +600,36 @@ function booking_view($node, $view_mode) {
//calculate the price owed by this person
//if (_booking_is_earlybird() == true || _booking_amount_owing($node->nid) == 0)
if (_booking_is_earlybird() == true || _booking_amount_owing($node) == 0 || $node->booking_committee_member == 'Y' || $node->booking_welfare_required == 'Y') {
if (_booking_is_earlybird() == true || _booking_amount_owing($node) == 0 || $node->booking_committee_member == 'Y' || $node->booking_welfare_required == 'Y')
{
$price = $node->booking_price;
}
else {
else
$price = $node->booking_late_price;
}
//include the price description to display with this view
$payment_type = $node->booking_price_descrip . ' ($' . $price . ')';
//look up the actual name for a linked partner
if ($node->booking_partner_id != 0) {
if ($node->booking_partner_id != 0)
{
$query = db_query("Select booking_firstname, booking_lastname from {booking_person} where nid = :nid",
array(':nid' => $node->booking_partner_id))
->fetchObject();
$partner_name = $query->booking_firstname . " " . $query->booking_lastname;
}
else {
else
$partner_name = "N/A";
}
//also look up the actual name if a boyfriend/girlfriend is defined
if ($node->booking_bf_gf_nid != 0) {
if ($node->booking_bf_gf_nid != 0)
{
$query = db_query("Select booking_firstname, booking_lastname from {booking_person} where nid = :nid",
array(':nid' => $node->booking_bf_gf_nid))
->fetchObject();
$bf_gf = $query->booking_firstname . " " . $query->booking_lastname;
}
else {
else
$bf_gf = "N/A";
}
//define column widths along with the header
$header = array(
@@ -739,30 +646,65 @@ function booking_view($node, $view_mode) {
$rows[] = array(t('Committee Member:'), t('!ans', array('!ans' => ($node->booking_committee_member == 'Y' ? '<b>Yes</b>' : 'No'))));
$rows[] = array(t('Welfare Required:'), $node->booking_welfare_required == 'Y' ? 'Yes' : 'No');
$rows[] = array(t('Barcode:'), t('!id', array('!id' => $node->booking_barcode)));
$rows[] = array(t('Lanyard lucky number:'), $node->booking_luckynum);
$rows[] = array(t('Reading Group:'), t('!group', array('!group' => $node->booking_readinggroup)));
$rows[] = array(t('Date of birth:'), t('!dob', array('!dob' => format_date($node->booking_dob, 'custom', 'd/m/Y'))));
$rows[] = array(t('Email address:'), t('!email', array('!email' => $node->booking_email)));
if (variable_get('booking_enable_passport', 1) == 1)
{
$rows[] = array(t('Passport Number:'), $node->booking_passport_num);
$rows[] = array(t('Passport Expiry:'), t('!timestamp', array('!timestamp' => _booking_convert_ts($node->booking_passport_expiry_date)->format('d/m/Y'))));
$rows[] = array(t('Passport Exact Issued Name:'), $node->booking_passport_issue_name);
$rows[] = array(t('Passport Issue Location:'), $node->booking_passport_issue_location);
$rows[] = array(t('Destination Country:'), $node->booking_destination_country);
$rows[] = array(t('Travel Insurance details:'), $node->booking_travel_insurance);
//outbound flight
$flight_rows[] = array(t('Internal Flight Booking Reference:'), $node->booking_outflight_bookingnum);
$flight_rows[] = array(t('Internal Flight Number:'), $node->booking_outflight_flightnum);
$flight_rows[] = array(t('Internal Flight Origin to Destination:'), $node->booking_outflight_origin);
$flight_rows[] = array(t('Internal Flight Departure Time:'),
$node->booking_outflight_origin_ts == 0 ? '' : format_date($node->booking_outflight_origin_ts, 'custom', 'd/m/Y H:i') );
$flight_rows[] = array(t('Connecting Flight Number:'), $node->booking_outflight_connecting_flightnum);
$flight_rows[] = array(t('Connecting Flight Origin to Destination:'), $node->booking_outflight_destination);
$flight_rows[] = array(t('Internal Flight Arrival Time:'),
$node->booking_outflight_destination_ts == 0 ? '' : format_date($node->booking_outflight_destination_ts, 'custom', 'd/m/Y H:i') );
//return flight
$flight_rows[] = array(t('Return Internal Flight Booking Reference:'), $node->booking_rtrnflight_bookingnum);
$flight_rows[] = array(t('Return Internal Flight Number:'), $node->booking_rtrnflight_flightnum);
$flight_rows[] = array(t('Return Internal Flight Origin to Destination:'), $node->booking_rtrnflight_origin);
$flight_rows[] = array(t('Return Internal Flight Departure Time:'),
$node->booking_rtrnflight_origin_ts == 0 ? '' : format_date($node->booking_rtrnflight_origin_ts, 'custom', 'd/m/Y H:i') );
$flight_rows[] = array(t('Connecting Flight Number:'), $node->booking_rtrnflight_connecting_flightnum);
$flight_rows[] = array(t('Connecting Flight Origin to Destination:'), $node->booking_rtrnflight_destination);
$flight_rows[] = array(t('Return Internal Flight Arrival Time:'),
$node->booking_rtrnflight_destination_ts == 0 ? '' : format_date($node->booking_rtrnflight_destination_ts, 'custom', 'd/m/Y H:i') );
//add the flight info to a new section
$flight_heading = t("<h2>Internal Flight Details</h2>");
$node->content['flight-heading'] = array(
'#markup' => $flight_heading,
'#weight' => 2,
);
$node->content['flight-details'] = array(
'#markup' => theme('table', array('header' => $header, 'rows' => $flight_rows)),
'#weight' => 3,
);
}
$rows[] = array(t('Payment Type Selected:'), t('!amount_paid', array('!amount_paid' => $payment_type)));
$rows[] = array(t('Amount Paid:'), t('!amount_paid', array('!amount_paid' => $node->booking_amount_paid)));
$rows[] = array(t('Payment Complete Flag:'), t('!ans', array('!ans' => $node->booking_payment_complete == 'Y' ? 'Yes' : 'No')));
$rows[] = array(t('Total Amount Due:'), t('!amount_paid', array('!amount_paid' => $node->booking_total_pay_reqd)));
$rows[] = array(t('Refund Due:'), t('!amount_due', array('!amount_due' => $node->booking_refund_due)));
$rows[] = array(t('Refund Processed:'), t('!ans', array('!ans' => ($node->booking_refund_processed == 'Y' ? 'Yes' : 'No'))));
$rows[] = array(t('Reading Group:'), t('!group', array('!group' => $node->booking_readinggroup)));
$rows[] = array(t('Random Facts:'), t('!facts', array('!facts' => $node->booking_random_facts)));
if (variable_get('booking_enable_tshirts', 0) == 1) {
if (variable_get('booking_enable_tshirts', 0) == 1)
{
$rows[] = array(t('Hoodie Size:'), $node->booking_shirt_size);
}
$rows[] = array(t('Ecclesia:'), t('!ecclesia', array('!ecclesia' => $node->booking_ecclesia)));
$rows[] = array(t('Baptised:'), t('!ans', array('!ans' => ($node->booking_baptised == 'Y' ? 'Yes' : 'No'))));
$rows[] = array(t('Married:'), t('!ans', array('!ans' => ($node->booking_married == 'Y' ? 'Yes' : 'No'))));
if (variable_get('booking_ask_dependant_children', 0) == 1) {
$rows[] = array(t('Bringing dependant children:'), t('!ans', array('!ans' => ($node->booking_dependant_children == 'Y' ? 'Yes' : 'No'))));
}
$rows[] = array(t('Linked Partner:'), t($partner_name));
$rows[] = array(t('Linked Boyfriend/Girlfriend:'), t($bf_gf));
$rows[] = array(t('Node ID to keep separate:'), $node->booking_keepseparate_id == 0 ? 'N/A' : $node->booking_keepseparate_id);
$rows[] = array(t('Home Phone Number:'), t('!home', array('!home' => $node->booking_phone)));
$rows[] = array(t('Mobile Phone Number:'), t('!mob', array('!mob' => $node->booking_mobile)));
$rows[] = array(t('Postal Address:'), t('!street<br />!suburb !state !code<br />!country',
@@ -770,24 +712,34 @@ function booking_view($node, $view_mode) {
'!state' => ($node->booking_state == 'N/A' ? '' : $node->booking_state),
'!code' => $node->booking_postcode,
'!country' => $node->booking_country)));
$rows[] = array(t('Ecclesia:'), t('!ecclesia', array('!ecclesia' => $node->booking_ecclesia)));
$rows[] = array(t('Baptised:'), t('!ans', array('!ans' => ($node->booking_baptised == 'Y' ? 'Yes' : 'No'))));
$rows[] = array(t('Married:'), t('!ans', array('!ans' => ($node->booking_married == 'Y' ? 'Yes' : 'No'))));
if (variable_get('booking_ask_dependant_children', 0) == 1)
{
$rows[] = array(t('Bringing dependant children:'), t('!ans', array('!ans' => ($node->booking_dependant_children == 'Y' ? 'Yes' : 'No'))));
}
$rows[] = array(t('Linked Partner:'), t($partner_name));
$rows[] = array(t('Linked Boyfriend/Girlfriend:'), t($bf_gf));
$rows[] = array(t('Emergency Contact Name:'), $node->booking_guardian_name);
$rows[] = array(t('Emergency Contact Relationship:'), $node->booking_guardian_type);
$rows[] = array(t('Emergency Contact Email Address:'), $node->booking_guardian_email);
$rows[] = array(t('Emergency Contact Phone:'), $node->booking_guardian_phone);
$rows[] = array(t('Emergency Contact Alternate Phone:'), $node->booking_guardian_phone_alt);
if (variable_get('booking_enable_medicare', 1) == 1) {
if (variable_get('booking_enable_medicare', 1) == 1)
$rows[] = array(t('Medicare Number:'), $node->booking_medicare);
}
$rows[] = array(t('Special Dietary Requirements:'), $node->booking_dietary);
$rows[] = array(t('Special Medical Conditions:'), $node->booking_medical_conditions);
if (variable_get('booking_enable_roommate', 0) == 1) {
if (variable_get('booking_enable_roommate', 0) == 1)
{
$rows[] = array(t('Preferred room-mates:'), t('!room', array('!room' => $node->booking_room_mate1 . ' ' . $node->booking_room_mate2)));
}
if (variable_get('booking_enable_helpareas', 1) == 1) {
if (variable_get('booking_enable_helpareas', 1) == 1)
{
$rows[] = array(t('Qualified Life Saver:'), $node->booking_lifesaver == 'Y' ? 'Yes' : 'No');
$rows[] = array(t('Qualified First Aider:'), $node->booking_firstaid == 'Y' ? 'Yes' : 'No');
$rows[] = array(t('Qualified Nurse:'), $node->booking_nurse == 'Y' ? 'Yes' : 'No');
@@ -811,7 +763,8 @@ function booking_view($node, $view_mode) {
$rows[] = array(t('Help areas:'), t('!help', array('!help' => $help_areas)));
}
if (variable_get('booking_enable_skills', 1) == 1) {
if (variable_get('booking_enable_skills', 1) == 1)
{
$skill_areas = '';
if ($node->booking_skills_builder == 'Y')
$skill_areas .= 'builder, ';
@@ -827,9 +780,11 @@ function booking_view($node, $view_mode) {
$rows[] = array(t('Previous Mission Experience:'), $node->booking_mission_experience_details);
}
$rows[] = array(t('Temporary UUID:'), $node->booking_tempid);
$rows[] = array(t('Lanyard lucky number:'), $node->booking_luckynum);
//display room allocation data if enabled
if (variable_get('booking_enable_roomallocations', 0) == 1) {
if (variable_get('booking_enable_roomallocations', 0) == 1)
{
$room_heading = t("<h2>Room Allocation</h2><p>!link</p>",
array('!link' => l(t('Edit Room Allocation'), t('admin/booking/!id/edit-room', array('!id' => $node->nid)), array('query' => drupal_get_destination()) )
));
@@ -851,7 +806,8 @@ function booking_view($node, $view_mode) {
}
//add the travel info if it has been defined for this attendee
if (! empty($node->tid)) {
if (! empty($node->tid))
{
$travel_heading = t("<h2>Travel Details</h2><p>!link</p>",
array('!link' => l(t('Edit Travel Details'), t('node/!id/edit', array('!id' => $node->tid)))
));
@@ -893,7 +849,8 @@ function booking_view($node, $view_mode) {
//watchdog('booking', "<pre>Displaying node studygroups query output:\n@info</pre>", array('@info' => print_r( $studygroups, true)));
foreach ($studygroups as $studygroup) {
foreach ($studygroups as $studygroup)
{
//calculate the session references
$sessionid = "session" . $studygroup->sid;
$roleid = $sessionid . "_role";
@@ -902,8 +859,21 @@ function booking_view($node, $view_mode) {
$group_rows[] = array(t('Role'), _booking_studygroup_role_lookup($node->$roleid));
}
/*
for ($i = 1; $i <= variable_get('booking_studygroup_count','0'); $i++)
{
//calculate the session references
$sessionid = "session" . $i;
$roleid = $sessionid . "_role";
$group_rows[] = array(t('<b>' . $studygroups[$i]->booking_studygroup_descrip . '</b> group number'), $node->$sessionid);
$group_rows[] = array(t('Role'), _booking_studygroup_role_lookup($node->$roleid));
}
*/
//only add to the render array if there were some study groups found
if (count($group_rows) > 0) {
if (count($group_rows) > 0)
{
$node->content['group-heading'] = array(
'#markup' => $studygroup_heading,
'#weight' => 8,
@@ -914,6 +884,7 @@ function booking_view($node, $view_mode) {
'#weight' => 9,
);
}
}
$node->content['details'] = array(

View File

@@ -79,7 +79,7 @@ function booking_report_summary() {
$query->orderBy('state_count', 'DESC');
$state_stats = $query->execute();
//add some age info to an array so we can calculate age info and generate the actual rows after the more detailed summary loop
//TODO: add some info to a hash so we can calculate age info and generate the actual rows after the more detailed summary loop
//include count of guys, girls, minimum, maximum and average ages
foreach ($state_stats as $state) {
if (strcmp($state->booking_country,'Australia') == 0 ) {
@@ -279,8 +279,7 @@ function booking_report_summary() {
));
$output .= t("<h3>Ages</h3>");
$output .= t("<p>The combined average age at the start of the week will be !average.<br />The male average age will be !maleaverage.<br />The female average age will be !femaleaverage.</p>",
array('!average' => _booking_avg_age($dob_total, $male_count + $female_count, $event->booking_event_start),
'!maleaverage' => _booking_avg_age($male_dob_total, $male_count, $event->booking_event_start),
array('!average' => _booking_avg_age($dob_total, $male_count + $female_count, $event->booking_event_start), '!maleaverage' => _booking_avg_age($male_dob_total, $male_count, $event->booking_event_start),
'!femaleaverage' => _booking_avg_age($female_dob_total, $female_count, $event->booking_event_start)
));
$output .= t("<h3>Finances</h3>");
@@ -428,107 +427,6 @@ function booking_report_flight_details() {
return $result;
}
/**
* List everyone's travel info
*/
function booking_report_travel() {
global $event;
//$form = array();
$prefix = t("<h2>Travel Details</h2>");
//define sorting information with the header
//as per http://www.drup-all.com/blog/table-sort-pagination-drupal-7
$header = array();
$header[] = array('data' => t('Name'), 'field' => 'booking_lastname');
//$header[] = array('data' => t('Edit'), 'field' => 'nid', 'sort' => 'asc');
$header[] = array('data' => t('State'), 'field' => 'booking_state');
$header[] = array('data' => t('Transport Type'), 'field' => 'booking_transport_type');
$header[] = array('data' => t('Catching train from airport?'), 'field' => 'booking_transport_from_morriset_reqd');
$header[] = array('data' => t('Inbound Flight'), 'field' => 'booking_flightnum_inbound');
$header[] = array('data' => t('Inbound Time'), 'field' => 'booking_flight_datetime_inbound');
$header[] = array('data' => t('Outbound Flight'), 'field' => 'booking_flightnum_outbound');
$header[] = array('data' => t('Outbound Time'), 'field' => 'booking_flight_datetime_outbound');
$header[] = array('data' => t('Accommodation Before?'), 'field' => 'booking_accom_before_reqd');
$header[] = array('data' => t('Accommodation After?'), 'field' => 'booking_accom_after_reqd');
//get travel info from database
$query = db_select('booking_person', 'p');
$query->leftJoin('booking_travel', 't', 'p.nid = t.booking_person_nid');
//include people either booked in or on the waiting list or hosts, that belong to the current event id
$db_or = db_or();
$db_or->condition('p.booking_status', 1, '=');
$db_or->condition('p.booking_status', 2, '=');
$db_or->condition('p.booking_status', 5, '=');
$db_and = db_and()->condition('p.booking_eventid', $event->eid, '=')->condition($db_or);
$query->condition($db_and);
$query->fields('p')->fields('t');
//allow user to sort columns
$table_sort = $query->extend('TableSort')->orderbyHeader($header);
$result = $table_sort->execute();
foreach ($result as $person) {
$this_row = array();
//define the row for this person
//$this_row[] = $travel_link = l(t('Travel'), t('node/!id', array('!id' => $person->tid)));
//$this_row[] = l(t('Edit !id', array('!id' => $person->nid)), t('node/!id/edit', array('!id' => $person->nid)));
$this_row[] = l(t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))),
t('node/!id', array('!id' => $person->tid))
);
$this_row[] = t('!state', array('!state' => $person->booking_state));
//$this_row[] = _booking_status_generate($person->booking_status);
$class = $person->booking_transport_type == 'Flying' ? "flying-row" : "normal-row";
//calculate the travel link
if ($person->tid > 0) {
//$travel_link = l(t('Travel'), t('node/!id/edit', array('!id' => $person->tid)));
$this_row[] = t('!transport', array('!transport' => $person->booking_transport_type));
$this_row[] = t('!train', array('!train' => $person->booking_transport_from_morriset_reqd == 1 ? 'Yes' : 'No'));
$this_row[] = t('!inflightnum', array('!inflightnum' => $person->booking_flightnum_inbound));
$this_row[] = t('!inflighttime', array('!inflighttime' =>
$person->booking_flight_datetime_inbound == 0 ? '' : format_date($person->booking_flight_datetime_inbound, 'custom', 'd/m/Y H:i')));
$this_row[] = t('!outflightnum', array('!outflightnum' => $person->booking_flightnum_outbound));
$this_row[] = t('!outflighttime', array('!outflighttime' =>
$person->booking_flight_datetime_outbound == 0 ? '' : format_date($person->booking_flight_datetime_outbound, 'custom', 'd/m/Y H:i')));
$this_row[] = t('!beforeaccom', array('!beforeaccom' => $person->booking_accom_before_reqd == 1 ? 'Yes' : 'No'));
$this_row[] = t('!afteraccom', array('!afteraccom' => $person->booking_accom_after_reqd == 1 ? 'Yes' : 'No'));
//mark people requiring accommodation in a different colour so they stand out more
if ($person->booking_accom_before_reqd == 1 || $person->booking_accom_after_reqd == 1) {
$class = "accomm-row";
}
}
else {
$this_row[] = "N/A";
//put in empty fields to fill up the table columns
for ($i = 0; $i < 7; $i++) {
$this_row[] = "";
}
}
$rows[] = array('data' => $this_row, 'class' => array($class));
}
$result = array (
'#attached' => array (
'css' => array(drupal_get_path('module', 'booking') . '/booking.css')
),
'first_para' => array (
'#type' => 'markup',
'#markup' => $prefix,
),
'table' => array (
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => array('id' => 'sort-table'),
//'#sticky' => FALSE,
)
);
return $result;
}
function booking_coming_page() {
global $event;
@@ -539,17 +437,21 @@ function booking_coming_page() {
$rows = array();
//work out whether to include the team colour in this page
if (variable_get('booking_publish_readinggroups', 0) == 1) {
if (variable_get('booking_publish_readinggroups', 0) == 1)
{
$header = array('Name', 'Team Colour', 'State');
}
else {
else
{
$header = array('Name', 'State');
}
//if configuration is set to show on lists even when no payment has been made, then include booking status of 0 (unpaid) or 1 (booked in)
//also ensure any committee members always show
if (variable_get('booking_auto_show_on_lists', 1) == 1) {
if (variable_get('booking_auto_show_on_lists', 1) == 1)
{
$or = db_or()->condition('p.booking_status', 0)->condition('p.booking_status', 1)>condition('p.booking_committee_member', 'Y');
$result = db_select('booking_person', 'p')
->fields('p', array('booking_firstname', 'booking_lastname', 'booking_state', 'booking_readinggroup', 'booking_country'))
->condition($or)
@@ -559,10 +461,13 @@ function booking_coming_page() {
->orderBy('booking_lastname')
->orderBy('booking_firstname')
->execute();
}
else {
else
{
//payment must be made before someone will show up as booked in, but also include any committee member that might not have paid
$or = db_or()->condition('p.booking_status', 1)->condition('p.booking_committee_member', 'Y');
$result = db_select('booking_person', 'p')
->fields('p', array('booking_firstname', 'booking_lastname', 'booking_state', 'booking_readinggroup', 'booking_country'))
->condition($or)
@@ -574,11 +479,13 @@ function booking_coming_page() {
->execute();
}
foreach ($result as $person) {
foreach ($result as $person)
{
$state = $person->booking_country === variable_get('booking_default_country') ? $person->booking_state : $person->booking_country;
//if we're allowed to publish reading groups, specify them in the array element
if (variable_get('booking_publish_readinggroups', 0) == 1) {
if (variable_get('booking_publish_readinggroups', 0) == 1)
{
$rows[] = array(
t('!first !last', array('!first' => ucwords($person->booking_firstname),
'!last' => ucwords($person->booking_lastname))),
@@ -587,7 +494,8 @@ function booking_coming_page() {
);
}
//don't publish reading group information
else {
else
{
$rows[] = array(
t('!first !last', array('!first' => ucwords($person->booking_firstname),
'!last' => ucwords($person->booking_lastname))),
@@ -600,12 +508,15 @@ function booking_coming_page() {
//output the results
//check there were some bookings
if (count($rows) > 0) {
if (count($rows) >= $booking_limit) {
if (count($rows) > 0)
{
if (count($rows) >= $booking_limit)
{
//there is a waiting list
$output .= token_replace(variable_get('booking_whoscoming_pre_waitlist_text'), booking_define_tokens());
}
else {
else
{
//there's no waiting list
$output .= token_replace(variable_get('booking_whoscoming_pre_text'), booking_define_tokens());
}
@@ -613,7 +524,8 @@ function booking_coming_page() {
//theme the table of registrations
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes));
}
else {
else
{
//no bookings
$output .= token_replace(variable_get('booking_whoscoming_pre_noregistrations_text'), booking_define_tokens());
}
@@ -729,7 +641,13 @@ function booking_csv_report() {
//keep a list of any fields that we need to handle as dates
$datetime_fields = array('booking_outflight_origin_ts', 'booking_outflight_destination_ts', 'booking_rtrnflight_origin_ts',
'booking_rtrnflight_destination_ts', 'booking_timestamp', 'booking_flight_datetime_inbound', 'booking_flight_datetime_outbound');
$number_only_fields = array('booking_postcode', 'booking_mobile', 'booking_phone', 'booking_guardian_phone', 'booking_guardian_phone_alt');
$number_only_fields = array('booking_postcode', 'booking_mobile', 'booking_phone');
//this isn't required since we already have the info directly as a field
//so there is no need to rewrite the ID field with a user-friendly description
//look up room location descriptions for presenting a friendly name rather than an ID
//$room_query = db_query("SELECT * FROM {booking_room_locations} WHERE booking_roomlocation_active = 'Y'");
//$room_locations = $room_query->fetchAllAssoc('lid');
//look up the titles of the study groups and add to array for updating in the header
$studygroup_descriptions = array();
@@ -737,7 +655,7 @@ function booking_csv_report() {
array(':eid' => $event->eid));
$studygroups = $studygroups_query->fetchAllAssoc('sid');
//update array for turning study group session IDs into the name for that group
//update array for turning study group session IDs into the name for that group
foreach ($studygroups as $studygroup) {
//calculate the session references
$sessionid = "session" . $studygroup->sid;
@@ -759,23 +677,23 @@ function booking_csv_report() {
//write the header based on the first result
$header_array = array();
foreach (reset($result) as $key => $value) {
if (in_array($key, $fields_to_skip)) {
foreach (reset($result) as $key => $value)
{
if (in_array($key, $fields_to_skip))
continue;
}
/*
//Replace headings for study group sessions and roles with the name of the study group rather than just sessionN and sessionN_role etc
if (variable_get('booking_friendly_csv_groupnames','0') == 1 && array_key_exists($key, $studygroup_descriptions)) {
if (array_key_exists($key, $studygroup_descriptions))
{
$header_array[] = $studygroup_descriptions[$key];
continue;
}
*/
$header_array[] = $key;
//add in a special column for a processed version of the date of birth
if (strcmp($key,"booking_dob") == 0) {
if (strcmp($key,"booking_dob") == 0)
$header_array[] = "booking_dob_processed";
}
//add in a calculated field for amount owing
if (strcmp($key, "nid") == 0) {
$header_array[] = "booking_amount_owing_gross";

View File

@@ -420,15 +420,15 @@ function booking_rooms_view_form($node, &$form_state, $location_id) {
return "";
}
//@todo reduce the number of queries by using some joins
$location_description = db_query("SELECT booking_roomlocation_descrip FROM {booking_room_locations} where lid = :id",
array(':id' => $location_id))
->fetchObject();
//use the query result to include a human friendly group name
array(':id' => $location_id))
->fetchObject();
//$prefix = t("<h2>Room Allocations for !room</h2>", array('!room' => _booking_room_location_lookup($location_id)));
$prefix = t("<h2>Room Allocations for !room</h2>", array('!room' => $location_description->booking_roomlocation_descrip));
//query for room definitions
$room_query = db_query("SELECT * FROM {booking_room_definition} WHERE booking_room_location_id = :lid ORDER BY booking_room_number",
$room_query = db_query("SELECT * FROM {booking_room_definition} WHERE booking_room_location_id = :lid",
array(':lid' => $location_id));
//query for existing room allocations
@@ -444,10 +444,8 @@ function booking_rooms_view_form($node, &$form_state, $location_id) {
array(':eid' => $event->eid))->fetchAllAssoc('nid');
//define the header
$header = array(
$header = array (
'booking_room_number' => array('data' => t('Room Number')),
'booking_room_description' => array('data' => t('Room Label')),
'booking_room_ensuite' => array('data' => t('Ensuite?')),
'booking_room_singlebed' => array('data' => t('Single Bed')),
'booking_room_doublebed_p1' => array('data' => t('Double Bed Person 1')),
'booking_room_doublebed_p2' => array('data' => t('Double Bed Person 2')),
@@ -455,87 +453,101 @@ function booking_rooms_view_form($node, &$form_state, $location_id) {
'booking_room_queenbed_p2' => array('data' => t('Queen Bed Person 2')),
);
//define the default fields in a table row
$default_row = array();
$default_row['booking_room_number'] = "";
$default_row['booking_room_description'] = "";
$default_row['booking_room_ensuite'] = "";
$default_row['booking_room_singlebed'] = "";
$default_row['booking_room_doublebed_p1'] = "";
$default_row['booking_room_doublebed_p2'] = "";
$default_row['booking_room_queenbed_p1'] = "";
$default_row['booking_room_queenbed_p2'] = "";
foreach ($room_query as $data) {
//create a row that contains just the room location and number and the custom css id for a separating line between the rooms
$new_row = _booking_clone_array($default_row);
$new_row['booking_room_number'] = $data->booking_room_number;
$new_row['booking_room_description'] = $data->booking_room_description;
$new_row['booking_room_ensuite'] = $data->booking_room_ensuite == 'Y' ? "Yes" : "No";
$rows[] = array(
'data' => $new_row,
'id' => array("new-group-row"),
);
foreach ($room_query as $data)
{
//load the existing bed mappings for this room
$existing_beds = array();
for ($i = 1; $i <= 3; $i++) {
foreach ($room_mapping as $mapping) {
for ($i = 1; $i <= 3; $i++)
{
foreach ($room_mapping as $mapping)
{
//check that the room id in the mapping table matches the room that we're currently adding to the table
//and also the bed type matches the first dimension in the array
if ($mapping->booking_roomid == $data->rid && $mapping->booking_room_bedtype == $i) {
if ($mapping->booking_roomid == $data->rid && $mapping->booking_room_bedtype == $i)
{
$existing_beds[$i][] = $mapping->booking_nodeid;
}
}
} //end creating existing room mappings for this room
}
//create a row that contains just the room location and number
$rows[] = array (
'data' => array(
$data->booking_room_number,
"",
"",
"",
"",
"",
),
'id' => array("new-group-row"),
);
//create an additional row for each single bed
for ($i = 0; $i < $data->booking_room_singlebeds; $i++) {
for ($i = 0; $i < $data->booking_room_singlebeds; $i++)
{
//retrieve the default value if one exists
$nid = (!empty($existing_beds[1][$i])) ? $existing_beds[1][$i] : 0;
$new_row = _booking_clone_array($default_row);
$new_row['booking_room_singlebed'] = _booking_rooms_view_formatperson($attendees, $nid);
$rows[] = array(
'data' => $new_row,
$rows[] = array (
'data' => array(
"",
_booking_rooms_view_formatperson($attendees, $nid),
"",
"",
"",
"",
),
);
}
//create an additional row for each double bed
//$j is our counter that increments twice as fast as $i to cater for both beds
$j = 0;
for ($i = 0; $i < $data->booking_room_doublebeds; $i++) {
$new_row = _booking_clone_array($default_row);
$new_row['booking_room_doublebed_p1'] = _booking_rooms_view_formatperson($attendees, (!empty($existing_beds[2][$j])) ? $existing_beds[2][$j++] : 0);
$new_row['booking_room_doublebed_p2'] = _booking_rooms_view_formatperson($attendees, (!empty($existing_beds[2][$j])) ? $existing_beds[2][$j++] : 0);
$rows[] = array(
'data' => $new_row,
for ($i = 0; $i < $data->booking_room_doublebeds; $i++)
{
$rows[] = array (
'data' => array(
"",
"",
_booking_rooms_view_formatperson($attendees, (!empty($existing_beds[2][$j])) ? $existing_beds[2][$j++] : 0),
_booking_rooms_view_formatperson($attendees, (!empty($existing_beds[2][$j])) ? $existing_beds[2][$j++] : 0),
"",
"",
),
);
}
//create an additional row for each queen bed
//$j is our counter that increments twice as fast as $i to cater for both beds
$j = 0;
for ($i = 1; $i <= $data->booking_room_queenbeds; $i++) {
$new_row = _booking_clone_array($default_row);
$new_row['booking_room_queenbed_p1'] = _booking_rooms_view_formatperson($attendees, (!empty($existing_beds[3][$j])) ? $existing_beds[3][$j++] : 0);
$new_row['booking_room_queenbed_p2'] = _booking_rooms_view_formatperson($attendees, (!empty($existing_beds[3][$j])) ? $existing_beds[3][$j++] : 0);
$rows[] = array(
'data' => $new_row,
for ($i = 1; $i <= $data->booking_room_queenbeds; $i++)
{
$rows[] = array (
'data' => array(
"",
"",
"",
"",
_booking_rooms_view_formatperson($attendees, (!empty($existing_beds[3][$j])) ? $existing_beds[3][$j++] : 0),
_booking_rooms_view_formatperson($attendees, (!empty($existing_beds[3][$j])) ? $existing_beds[3][$j++] : 0),
),
);
}
} //end room iteration loop
}
//watchdog('booking', "<pre>Room assignment report rows:\n@info</pre>", array('@info' => print_r( $rows, true)));
$result = array(
'#attached' => array(
$result = array (
'#attached' => array (
'css' => array(drupal_get_path('module', 'booking') . '/booking.css')
),
'first_para' => array(
'first_para' => array (
'#type' => 'markup',
'#markup' => $prefix,
),
'table' => array(
'table' => array (
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
@@ -558,7 +570,8 @@ function _booking_rooms_view_formatperson(&$attendees, $nid) {
$output = "Empty";
if ($nid > 0 && !empty($attendees[$nid])) {
if ($nid > 0 && !empty($attendees[$nid]))
{
$output = $attendees[$nid]->booking_firstname . " " . $attendees[$nid]->booking_lastname;
}

View File

@@ -225,20 +225,18 @@ function booking_rooms_view_definitions() {
$definition_query->join('booking_room_locations', 'l', 'l.lid = r.booking_room_location_id');
$definition_query->condition('l.booking_roomlocation_active', 'Y', '=')
->fields('r')
->fields('l')
->orderBy('lid')->orderBy('booking_room_number');
->fields('l');
$definition_result = $definition_query->execute();
$location_header = array (
'booking_roomlocation_descrip' => t('Location Description'),
'booking_roomlocation_active' => t('Location Active?'),
'booking_roomlocation_descrip' => t('Location Description'),
'booking_roomlocation_active' => t('Location Active?'),
'booking_location_edit' => t('Edit Location'),
);
$definition_header = array (
'booking_room_location_description' => t('Room Location'),
'booking_room_number' => t('Room Number'),
'booking_room_description' => t('Room Description'),
'booking_room_location_description' => t('Room Location'),
'booking_room_number' => t('Room Number'),
'booking_room_singlebeds' => t('Number Single Beds'),
'booking_room_doublebeds' => t('Number Double Beds'),
'booking_room_queenbeds' => t('Number Queen Beds'),
@@ -246,7 +244,8 @@ function booking_rooms_view_definitions() {
'booking_room_edit' => t('Edit Room'),
);
foreach($location_result as $data) {
foreach($location_result as $data)
{
$location_rows[] = array (
$data->booking_roomlocation_descrip,
$data->booking_roomlocation_active == 'Y' ? 'Yes' : 'No',
@@ -254,12 +253,12 @@ function booking_rooms_view_definitions() {
);
}
foreach($definition_result as $data) {
foreach($definition_result as $data)
{
$definition_rows[] = array (
//_booking_room_location_lookup($data->booking_room_location_id),
//_booking_room_location_lookup($data->booking_room_location_id),
$data->booking_roomlocation_descrip,
$data->booking_room_number,
$data->booking_room_description,
$data->booking_room_number,
$data->booking_room_singlebeds,
$data->booking_room_doublebeds,
$data->booking_room_queenbeds,
@@ -310,30 +309,33 @@ function booking_rooms_definition_form($node, &$form_state, $create, $room_id =
$query = db_query("SELECT * FROM {booking_room_locations} where booking_roomlocation_active='Y'");
foreach($query as $row) {
foreach($query as $row)
{
$location_options[$row->lid] = $row->booking_roomlocation_descrip;
}
if ($create == true) {
if ($create == true)
{
$data = $node;
$prefix = t("<p>Create new room defintion.</p>");
//watchdog('booking', 'Creating new room definition: @info', array ('@info' => var_export($node, TRUE)));
}
else {
else
{
//verify that $editid is a number
if (! preg_match('/^[0-9]+$/', $room_id)) {
drupal_set_message("Error: Invalid room ID supplied. Unable to update room definition.", 'error', FALSE);
drupal_goto('admin/config/booking/rooms');
return "";
}
$prefix = t("<p>Update the room defintions.</p>");
//$data = $form_state['input'];
$data = db_query("SELECT * FROM {booking_room_definition} WHERE rid = :id", array(':id' => $room_id))
$data = db_query("SELECT * FROM {booking_room_definition} WHERE rid = :id",
array(':id' => $room_id))
->fetchObject();
$prefix = t("<p>Update the room defintions.</p>");
//add this to the form in a hidden field so we can update the right price
$form['booking_rid'] = array(
$form['booking_rid'] = array (
'#type' => 'hidden',
'#value' => $room_id,
);
@@ -341,14 +343,15 @@ function booking_rooms_definition_form($node, &$form_state, $create, $room_id =
}
//create the options array for bed counts
for ($i = 0; $i <= 15; $i++) {
for ($i = 0; $i <= 15; $i++)
$bedcount_options[$i] = $i;
}
//define the form for adding to the room definitions
if(!isset($form_state['storage']['confirm'])) {
$form[] = array (
'first_heading' => array(
'first_heading' => array (
'#type' => 'markup',
'#markup' => $prefix,
),
@@ -360,33 +363,26 @@ function booking_rooms_definition_form($node, &$form_state, $create, $room_id =
'#options' => $location_options,
'#default_value' => !empty($data->booking_room_location_id) ? $data->booking_room_location_id : ''
);
$form['booking_room_number'] = array(
$form['booking_room_number'] = array (
'#type' => 'textfield',
'#title' => t('Specify room number'),
'#size' => 5,
'#maxlength' => 10,
'#default_value' => !empty($data->booking_room_number) ? $data->booking_room_number : '',
);
$form['booking_room_description'] = array(
'#type' => 'textfield',
'#title' => t('Specify room label (not mandatory)'),
'#size' => 50,
'#maxlength' => 100,
'#default_value' => !empty($data->booking_room_description) ? $data->booking_room_description : '',
);
$form['booking_room_singlebeds'] = array(
$form['booking_room_singlebeds'] = array (
'#type' => 'select',
'#title' => t('Specify number of single beds'),
'#options' => $bedcount_options,
'#default_value' => !empty($data->booking_room_singlebeds) ? $data->booking_room_singlebeds : '',
);
$form['booking_room_doublebeds'] = array(
$form['booking_room_doublebeds'] = array (
'#type' => 'select',
'#title' => t('Specify number of double beds'),
'#options' => $bedcount_options,
'#default_value' => !empty($data->booking_room_doublebeds) ? $data->booking_room_doublebeds : '',
);
$form['booking_room_queenbeds'] = array(
$form['booking_room_queenbeds'] = array (
'#type' => 'select',
'#title' => t('Specify number of queen beds'),
'#options' => $bedcount_options,
@@ -398,18 +394,21 @@ function booking_rooms_definition_form($node, &$form_state, $create, $room_id =
'#default_value' => (!empty($data->booking_room_ensuite) && $data->booking_room_ensuite == 'Y') ? 1 : 0,
);
if ($create == true) {
$form['submit'] = array(
if ($create == true)
{
$form['submit'] = array
(
'#type' => 'submit',
'#value' => t('Add Room'),
);
}
else {
$form['Update'] = array(
} else {
$form['Update'] = array
(
'#type' => 'submit',
'#value' => t('Update Room'),
);
$form['Delete'] = array(
$form['Delete'] = array
(
'#type' => 'submit',
'#value' => t('Delete Room'),
);
@@ -419,22 +418,12 @@ function booking_rooms_definition_form($node, &$form_state, $create, $room_id =
'form' => $form,
);
}
else {
else
{
return confirm_form($form, "Are you sure you wish to delete room definition with id " . $room_id . "?",
current_path(), NULL, "Delete Room");
}
}
/**
* Validate the form for adding room definitions
*/
function booking_rooms_definition_form_validate($form, $form_state) {
//make sure room number is numerical
$values = $form_state['input'];
if (! is_numeric($values['booking_room_number'])) {
form_set_error('booking_room_number', t('Room number must be numeric. If you need to use a more descriptive label, please use the room label field.'));
}
}
/**
@@ -448,12 +437,14 @@ function booking_rooms_definition_form_submit($form, &$form_state) {
//watchdog('booking', "<pre>Room definition submission:\n@info</pre>", array('@info' => print_r( $form_state, true)));
//if we're deleting, add the confirmation to the form if it hasn't been defined yet
if($form_state['values']['op'] == 'Delete Room' && (!isset($form_state['storage']['confirm']))) {
if($form_state['values']['op'] == 'Delete Room' && (!isset($form_state['storage']['confirm'])))
{
//watchdog('booking', "<pre>Room deletion confirmation being set:\n@info</pre>", array('@info' => print_r( $form_state, true)));
$form_state['storage']['confirm'] = TRUE;
$form_state['rebuild'] = TRUE;
}
elseif ($form_state['values']['op'] == 'Delete Room') {
}
elseif ($form_state['values']['op'] == 'Delete Room')
{
//delete the room
watchdog('booking', "Deleting room ID !rid", array('!rid' => $values['booking_rid']));
@@ -464,12 +455,12 @@ function booking_rooms_definition_form_submit($form, &$form_state) {
drupal_set_message('Deleted room id ' . $values['booking_rid'] );
$form_state['redirect'] = $redirect_path;
}
elseif ($form_state['values']['op'] == 'Update Room') {
elseif ($form_state['values']['op'] == 'Update Room')
{
$result = db_update('booking_room_definition')
->fields(array(
'booking_room_location_id' => $values['booking_room_location_id'],
'booking_room_number' => $values['booking_room_number'],
'booking_room_description' => $values['booking_room_description'],
'booking_room_location_id' => $values['booking_room_location_id'],
'booking_room_number' => $values['booking_room_number'],
'booking_room_singlebeds' => $values['booking_room_singlebeds'],
'booking_room_doublebeds' => $values['booking_room_doublebeds'],
'booking_room_queenbeds' => $values['booking_room_queenbeds'],
@@ -484,9 +475,8 @@ function booking_rooms_definition_form_submit($form, &$form_state) {
{
db_insert('booking_room_definition')
->fields(array(
'booking_room_location_id' => $values['booking_room_location_id'],
'booking_room_number' => $values['booking_room_number'],
'booking_room_description' => $values['booking_room_description'],
'booking_room_location_id' => $values['booking_room_location_id'],
'booking_room_number' => $values['booking_room_number'],
'booking_room_singlebeds' => $values['booking_room_singlebeds'],
'booking_room_doublebeds' => $values['booking_room_doublebeds'],
'booking_room_queenbeds' => $values['booking_room_queenbeds'],

View File

@@ -11,10 +11,7 @@ function _booking_rooms_name_autocomplete($string) {
$query = db_select('booking_person', 'p')
->fields('p', array('nid', 'booking_firstname', 'booking_lastname'));
$db_or = db_or()
->condition('p.booking_lastname', '%' . db_like($string) . '%', 'LIKE')
->condition('p.booking_firstname', '%' . db_like($string) . '%', 'LIKE')
->condition('p.nid', $string, "=");
$db_or = db_or()->condition('p.booking_lastname', '%' . db_like($string) . '%', 'LIKE')->condition('p.booking_firstname', '%' . db_like($string) . '%', 'LIKE');
$db_and = db_and()->condition($db_or)->condition('p.booking_eventid', $event->eid, '=');
$result = $query->condition($db_and)
->execute();
@@ -71,8 +68,6 @@ function booking_rooms_allocate_form($node, &$form_state, $location_id) {
$header = array (
'booking_room_location' => array('data' => t('Room Location'), 'field' => 'booking_room_location_id'),
'booking_room_number' => array('data' => t('Room Number')),
'booking_room_description' => array('data' => t('Room Label')),
'booking_room_ensuite' => array('data' => t('Ensuite?')),
'booking_room_singlebed' => array('data' => t('Single Bed')),
'booking_room_doublebed_p1' => array('data' => t('Double Bed Person 1')),
'booking_room_doublebed_p2' => array('data' => t('Double Bed Person 2')),
@@ -99,22 +94,24 @@ function booking_rooms_allocate_form($node, &$form_state, $location_id) {
$default_row = array();
$default_row['booking_room_location'] = "";
$default_row['booking_room_number'] = "";
$default_row['booking_room_description'] = "";
$default_row['booking_room_ensuite'] = "";
$default_row['booking_room_singlebed'] = "";
$default_row['booking_room_doublebed_p1'] = "";
$default_row['booking_room_doublebed_p2'] = "";
$default_row['booking_room_queenbed_p1'] = "";
$default_row['booking_room_queenbed_p2'] = "";
foreach ($room_query as $data) {
foreach ($room_query as $data)
{
//create an array representing the existing bed mappings for this room
$existing_beds = array();
for ($i = 1; $i <= 3; $i++) {
foreach ($room_mapping as $mapping) {
for ($i = 1; $i <= 3; $i++)
{
foreach ($room_mapping as $mapping)
{
//check that the room id in the mapping table matches the room that we're currently adding to the table
//and also the bed type matches the first dimension in the array
if ($mapping->booking_roomid == $data->rid && $mapping->booking_room_bedtype == $i) {
if ($mapping->booking_roomid == $data->rid && $mapping->booking_room_bedtype == $i)
{
$existing_beds[$i][] = $mapping->booking_lastname . ', ' . $mapping->booking_firstname . ' [' . $mapping->booking_nodeid . ']';
}
}
@@ -125,8 +122,6 @@ function booking_rooms_allocate_form($node, &$form_state, $location_id) {
//$new_row['booking_room_location'] = _booking_room_location_lookup($data->booking_room_location_id);
$new_row['booking_room_location'] = $data->booking_roomlocation_descrip;
$new_row['booking_room_number'] = $data->booking_room_number;
$new_row['booking_room_description'] = $data->booking_room_description;
$new_row['booking_room_ensuite'] = $data->booking_room_ensuite == 'Y' ? "Yes" : "No";
$form['rooms']['#rows'][$counter++] = array(
'data' => $new_row,
'id' => array("new-group-row"),

View File

@@ -1,65 +0,0 @@
(function($) {
$(function() {
Stripe.setPublishableKey(Drupal.settings.booking_stripeform.pubkey);
});
Drupal.behaviors.booking_stripeform = {
attach: function(context, settings) {
$("#" + settings.booking_stripeform.form_selector, context).submit(function(e) {
e.preventDefault();
var $form = $(this);
var $obj;
var $submitBtn = $("#edit-submit", context);
settings.booking_stripeform.submitBtnText = $submitBtn.val();
try {
var $ccnum = $(':input[data-stripe="number"]', $form);
var $exp_month = $(':input[data-stripe="exp-month"]', $form);
var $exp_year = $(':input[data-stripe="exp-year"]', $form);
var $cvc = $(':input[data-stripe="cvc"]', $form);
if(!Stripe.card.validateCardNumber($(':input[data-stripe="number"]', $form).val())) {
$obj = $ccnum;
throw "Invalid credit card number";
}
if(!Stripe.card.validateExpiry($exp_month.val(), $exp_year.val())) {
$obj = $exp_month;
throw "Invalid expiration month/year";
}
if(!Stripe.card.validateCVC($cvc.val())) {
$obj = $cvc;
throw "Invalid CVC";
}
} catch(err) {
$.each([$ccnum, $exp_month, $exp_year, $cvc], function(i, e) {
e.addClass('error');
});
$obj.parents('div.control-group').toggleClass('error');
reportError(err, $obj);
return false;
}
$submitBtn.val('Please wait...').attr('disabled', true);
Stripe.createToken($form, stripeResponseHandler);
return false;
});
}
}
var stripeResponseHandler = function(status, response) {
var $form = $("#" + Drupal.settings.booking_stripeform.form_selector);
if (response.error) {
alert(response.error.message);
} else {
// token contains id, last4, and card type
var token = response.id;
// Insert the token into the form so it gets submitted to the server
$('input[name=stripeToken]', $form).val(token);
// and submit
$form.get(0).submit();
}
};
/**
* Uses Bootstrap's popover to alert the user.
*/
function reportError(msg, $el) {
console.log([$el, msg]);
}
}(jQuery));

View File

@@ -1,309 +0,0 @@
<?php
/**
* @file
* Functions for stripe payment integration
* @see https://github.com/ericthelast/drupal-stripe-form and https://www.webomelette.com/drupal-stripe-integration
* Australian test number is 4000000360000006
*/
/**
* Get the current stripe api public key
*/
function _booking_get_stripe_public_key() {
if (variable_get('booking_stripe_testmode', 0) == 1) {
return variable_get('booking_stripe_test_public_key', '');
}
else {
return variable_get('booking_stripe_live_public_key', '');
}
}
/**
* Get the current stripe api private key
*/
function _booking_get_stripe_private_key() {
if (variable_get('booking_stripe_testmode', 0) == 1) {
return variable_get('booking_stripe_test_secret_key', '');
}
else {
return variable_get('booking_stripe_live_secret_key', '');
}
}
/**
* Helper function to generate paypal form for payments
*/
function _booking_stripe_form($person, $invoiceid, $amount_owing, $button_text) {
$payment_form = drupal_get_form('booking_stripe_form', $person, $invoiceid, $amount_owing, $button_text);
return drupal_render($payment_form);
}
function booking_stripe_form($node, &$form_state, $person, $invoiceid, $amount_owing, $button_text) {
global $event;
$settings = array();
$form = array();
//set some values for our internal stripe library to help process the form
//these will be used by the attached js from booking-strip library to identify which parts of the form to process
// @todo set name and image in the admin page
$setting['booking_stripe'] = array(
'pubkey' => _booking_get_stripe_public_key(),
'form_selector' => str_replace('_', '-', __FUNCTION__),
'name' => 'Study Week',
'image' => '',
);
//attach settings and javascript to the form
$form['#attached'] = array(
'js' => array(
array('data' => $setting, 'type' => 'setting'),
),
'library' => array(
array('booking', 'booking-stripe'),
),
);
//paypal specific settings
$vars = array(
'module' => 'Booking System',
'type' => $event->booking_eventname,
'nid' => $person->nid,
'email' => $person->booking_email,
'description' => $event->booking_eventname . ' ' . $person->booking_price_descrip,
'invoice' => $invoiceid,
'amount' => $amount_owing,
'last_name' => $person->booking_lastname,
'first_name' => $person->booking_firstname,
'uuid' => $person->booking_tempid,
'token_id' => '',
'token_email' => ''
);
/*
$form['#id'] = 'booking_stripe_form';
$form['#attached']['js'] = array(
array(
'data' => 'https://checkout.stripe.com/checkout.js',
'type' => 'external',
),
array(
'data' => drupal_get_path('module', 'booking') . '/booking.stripe.js',
'type' => 'file',
),
);
*/
//turn the array into a form
foreach($vars as $name => $value) {
$form[$name] = array(
'#type' => 'hidden',
'#value' => $value,
);
};
$form['submit'] = array(
'#id' => 'stripe-submit',
'#type' => 'button',
'#value' => t($button_text),
);
$form['#after_build'][] = 'booking_stripe_add_final_validation';
//watchdog('booking', 'Booking Balance payment: @info', array ('@info' => var_export($form, TRUE)));
return $form;
}
/**
* Tries to add final validation after all else has been added through alters.
*/
function booking_stripe_add_final_validation($form) {
$form['#validate'][] = 'booking_stripe_validate_form_payment';
return $form;
}
/**
* Form validation callback.
*/
function booking_stripe_checkout_form_validate($form, &$form_state) {
// Validate normal form elements as needed.
}
/**
* Processes the stripe payment.
*
* We do this here so that if the payment fails,
* we're still in a validation stage and can return
* early. If success, we'll pass the charge on
* to the submission callback.
*/
function booking_stripe_validate_form_payment($form, &$form_state) {
global $event;
if($errors = form_get_errors()) {
return;
}
$path = libraries_get_path('stripe');
require_once($path . '/init.php');
\Stripe\Stripe::setApiKey(_booking_get_stripe_private_key());
//$token = $form_state['values']['stripeToken'];
//$amount = $form_state['values']['amount'] * 100;
//get values from original form
$token = (isset($form_state['input']['token_id']) ? $form_state['input']['token_id'] : '');
$amount = (isset($form_state['input']['amount']) ? $form_state['input']['amount'] : '');
$invoice = (isset($form_state['input']['invoice']) ? $form_state['input']['invoice'] : '');
$nid = (isset($form_state['input']['nid']) ? $form_state['input']['nid'] : '');
$tempid= (isset($form_state['input']['uuid']) ? $form_state['input']['uuid'] : '');
$last_name = (isset($form_state['input']['last_name']) ? $form_state['input']['last_name'] : '');
$first_name = (isset($form_state['input']['first_name']) ? $form_state['input']['first_name'] : '');
watchdog('booking_debug', "<pre>Stripe token:\n@info</pre>", array('@info' => print_r( $token, true)));
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = \Stripe\Charge::create(array(
"amount" => $amount * 100,
"currency" => "aud",
"card" => $token,
"statement_descriptor" => substr($event->booking_eventname, 0, 21), //this field is limited to 22 characters
"expand" => array('balance_transaction'),
"description" => $form_state['input']['description'],
"receipt_email" => $form_state['input']['email'],
"metadata" => array(
"invoice" => $invoice,
"nid" => $nid,
"last_name" => $last_name,
"first_name" => $first_name,
),
));
watchdog('booking_debug', "<pre>Stripe payment charge results:\n@info</pre>", array('@info' => print_r( $charge, true)));
if ($charge && $charge->paid) {
watchdog('booking', 'Charge created successfully');
_booking_process_stripe_payment($charge, $token);
//$form_state['stripeform_charge'] = $charge;
// @todo call _booking_process_stripe_payment to store payment
drupal_goto('bookingfinal/' . $tempid);
}
else {
watchdog('booking', 'Charge was not created successfully');
drupal_set_message('Card does not seem to have been charged successfully. Please try again', 'error');
}
}
catch(\Stripe\Error\Card $e) {
$e_json = $e->getJsonBody();
$error = $e_json['error'];
watchdog('booking', $e->getMessage());
drupal_set_message($error['message'], 'error');
}
catch (\Stripe\Error\ApiConnection $e) {
watchdog('booking', $e->getMessage());
drupal_set_message($error['message'], 'error');
}
catch (\Stripe\Error\Api $e) {
watchdog('booking', $e->getMessage());
drupal_set_message($error['message'], 'error');
}
}
/**
* Form submission handler.
*/
function booking_stripeform_form_submit($form, &$form_state) {
drupal_set_message('Charge successful!');
}
/**
* FAPI #pre_render callback.
*
* Removes the name field form a form element.
*/
function booking_stripeform_remove_name($element) {
unset($element['#name']);
return $element;
}
function _booking_process_stripe_payment($charge, $token) {
global $event;
$balance_payment = false;
$amount_owing = 0;
//$invoice = $data->metadata;
//verify the status of the charge
if (empty($charge->status) || ($charge->status != 'succeeded')) {
$successful = FALSE;
}
else {
$successful = TRUE;
}
//extract the person node id from the invoice
$pos = strpos($charge->metadata->invoice, "_");
if (($pos === false) || ($pos == 0)) {
watchdog('booking', 'Unable to process payment with invalid invoice information: !id', array('!id' => $charge->metadata->invoice), WATCHDOG_ERROR);
return;
}
//get the part of the invoice up to the first underscore
$nid = substr($charge->metadata->invoice, 0, $pos);
//get the data between the first and second underscore
$eid = substr($charge->metadata->invoice, $pos + 1, strrpos($charge->metadata->invoice, "_") - $pos - 1);
if (substr($eid,0,3) == "bal") {
$balance_payment = true;
watchdog('booking_debug', 'Balance payment via stripe for user with node id: !id and status !status.',
array('!id' => $nid, '!status' => $charge->status));
}
else {
watchdog('booking_debug', 'Initial payment via stripe for user with node id: !id and status !status.',
array('!id' => $nid, '!status' => $charge->status));
}
//this shouldn't ever happen, since stripe is sending this notification synchronously
//but just in case, check for an existing transaction that matches this one
$duplicate_check = db_query("SELECT payid, booking_person_nid FROM {booking_payment} where booking_ipn_track_id = :ipn_id ",
array(':ipn_id' => $charge->id))->fetchObject();
if ($duplicate_check) {
watchdog('booking', 'Detected duplicate stripe transaction notifications for transaction id !id, registration id !nid',
array('!id' => $charge->id, '!nid' => $nid), WATCHDOG_ERROR);
return;
}
$gross_amount = $charge->amount / 100;
$result = db_insert('booking_payment')
->fields(array(
'booking_person_nid' => $nid,
'booking_eventid' => $event->eid,
'booking_mc_gross' => $gross_amount,
'booking_mc_currency' => $charge->balance_transaction->currency,
'booking_mc_fee' => $charge->balance_transaction->fee / 100,
'booking_invoice' => $charge->metadata->invoice,
'booking_payer_id' => $charge->source->id,
'booking_payment_date' => $charge->created,
'booking_payment_status' => $charge->status,
'booking_first_name' => $charge->metadata->first_name,
'booking_last_name' => $charge->metadata->last_name,
'booking_buyer_email' => $charge->receipt_email,
//'booking_payer_status' => $data['payer_status'],
'booking_item_name' => $charge->description,
'booking_ipn_track_id' => $charge->id,
'booking_stripe_token' => $token,
))
->execute();
//Get the person's info so we can update their total amount paid and booking status
$person = node_load($nid);
//check if we found a person matching this payment
if ($person) {
watchdog('booking', 'Found matching user with node id: !id; event id: !eid; existing payment !payment',
array('!id' => $nid, '!eid' => $eid, '!payment' => $person->booking_amount_paid));
_booking_process_person_payment($person, $gross_amount, $balance_payment);
}
else {
//couldn't find a matching nid for this invoice
watchdog('booking', "Unable to process payment for user with node id: '!id'", array('!id' => $nid), WATCHDOG_ERROR);
//db_query("UPDATE {booking_person} SET booking_tempid='' WHERE nid = %d", $nid);
}
}

View File

@@ -1,52 +0,0 @@
jQuery(document).ready(function($) {
var settings = Drupal.settings.booking_stripe;
var $stripeForm = $("#" + settings.form_selector);
var handler = StripeCheckout.configure({
key: settings.pubkey,
image: settings.image,
locale: 'auto',
token: function(token) {
try {
// Use the token to create the charge with a server-side script.
// You can access the token ID with `token.id`
$(':input[name="token_id"]', $stripeForm).val(token.id);
$(':input[name="token_email"]', $stripeForm).val(token.email);
$stripeForm.get(0).submit();
}
catch(err) {
console.log([err]);
alert(err.message);
}
}
});
$('.form-submit').click(function (e) {
//currentForm = $(this).closest('form');
//if (currentForm === undefined)
// return;
var settings = Drupal.settings.booking_stripe;
var $stripeForm = $("#" + settings.form_selector);
//$description = $(':input[name="description"]', $stripeForm).val();
//console.log([$description]);
//description: currentForm.find('input[name="description"]').val(),
//email: currentForm.find('input[name="email"]').val(),
//amount: currentForm.find('input[name="amount"]').val() * 100,
//alert($(':input[name="description"]', $stripeForm));
handler.open({
name: settings.name,
currency: "aud",
description: $(':input[name="description"]', $stripeForm).val(),
email: $(':input[name="email"]', $stripeForm).val(),
amount: $(':input[name="amount"]', $stripeForm).val() * 100,
zipCode: true,
closed: function() {
//document.getElementById("booking_stripe_form").submit();
}
});
e.preventDefault();
});
// Close Checkout on page navigation
//$(window).on('popstate', function() {
// handler.close();
//});
});

View File

@@ -2,9 +2,11 @@
/**
* @file
* Functions for automatically calculating leaders and helpers for discussion groups
* Functions for calculating leaders and helpers for discussion groups
*/
/**
* Function for calculating and assigning leaders and helpers to active study group sessions
*/
@@ -64,16 +66,20 @@ function _booking_get_next_studygroup($type, $studygroups) {
$count = count($studygroups) - 1;
for ($i = 0; $i < $count; $i++) {
for ($i = 0; $i < $count; $i++)
{
$group = $studygroups[$i];
$leader = $group->leader_nid;
//watchdog('booking_debug', "<pre>Study Group Element at index $i:\n@info</pre>", array('@info' => print_r( $group, true)));
//watchdog('booking_debug', "<pre>Study Group Leader NID at index $i:\n@info</pre>", array('@info' => var_dump($group)));
if ($leader == 0) {
if ($leader == 0)
{
return $i;
}
}
}
/**
@@ -95,7 +101,9 @@ function _booking_studygroups_retrieve_eligible_people() {
$bookedin_result = $query->execute();
//iterate over the attendee associative array and add some fields
foreach ($bookedin_result as $person) {
foreach ($bookedin_result as $person)
{
$person->processed = 0;
$person->leading = array();
$person->helping = array();
@@ -116,7 +124,9 @@ function _booking_studygroups_retrieve_eligible_people() {
array(':eid' => $event->eid));
//iterate over the attendee associative array and add some fields
foreach ($result2 as $person){
foreach ($result2 as $person)
{
$person->processed = 0;
$person->leading = array();
$person->helping = array();
@@ -130,6 +140,8 @@ function _booking_studygroups_retrieve_eligible_people() {
}
/**
* Function for
*/
@@ -146,9 +158,11 @@ function _booking_studygroups_retrieve_groups() {
//assume they all have the same number of sessions
//$num_sessions = $studygroup->booking_num_group_sessions;
foreach ($group_mapping as $group) {
foreach ($group_mapping as $group)
{
//watchdog('booking_debug', "<pre>Study Group Element:\n@info</pre>", array('@info' => print_r( $group, true)));
for ($i = 1; $i <= 16; $i++) {
for ($i = 1; $i <= 16; $i++)
{
$new_group = clone $group;
$new_group->session_id = $i;
@@ -165,336 +179,3 @@ function _booking_studygroups_retrieve_groups() {
return $groups;
}
/**
* autocomplete helper to look up names for room allocations
* based on https://www.drupal.org/node/854216
* $string = string for search
*/
function _booking_studygroups_name_autocomplete($string) {
global $event;
$matches = array();
$query = db_select('booking_person', 'p')
->fields('p', array('nid', 'booking_firstname', 'booking_lastname'));
$db_or = db_or()
->condition('p.booking_lastname', '%' . db_like($string) . '%', 'LIKE')
->condition('p.booking_firstname', '%' . db_like($string) . '%', 'LIKE')
->condition('p.nid', $string, "=");
$db_and = db_and()->condition($db_or)->condition('p.booking_eventid', $event->eid, '=');
$result = $query->condition($db_and)
->execute();
// save the query to matches
foreach ($result as $row) {
$name = $row->booking_lastname . ', ' . $row->booking_firstname . ' [' . $row->nid . ']';
$matches[$name] = $name;
}
// Return the result to the form in json
drupal_json_output($matches);
}
/**
* Function to allow admin to edit leaders and helpers for a study group
*/
function booking_studygroup_leadhelp_edit_form($node, &$form_state, $group_id) {
global $event;
//verify that $group_id is a number
if (! preg_match('/^[0-9]+$/', $group_id)) {
drupal_set_message("Error: Invalid study group ID '" . $group_id . "' supplied. Unable to edit group leaders and helpers.", 'error', FALSE);
drupal_goto('admin/booking/studygroups');
return "";
}
//try to select the study group for this $group_id
$studygroup = db_query("SELECT * FROM {booking_studygroup_list} WHERE sid = :sid", array(':sid' => $group_id))
->fetchObject();
if (! $studygroup) {
drupal_set_message("Error: Could not find matching study group ID. Unable to edit leaders/helpers.", 'error', FALSE);
drupal_goto('admin/booking/studygroups');
return "";
}
//define the table header
$header = array (
'sid' => array('data' => t('Study Group Session ID'), 'field' => 'sid'),
'booking_assign_leader' => array('data' => t('Leader')),
'booking_assign_helper' => array('data' => t('Helper')),
'booking_assign_reserveleader' => array('data' => t('Reserve Leader')),
'booking_assign_reservehelper' => array('data' => t('Reserve Helper')),
);
//attach the custom css
$form['#attached']['css'] = array(
drupal_get_path('module', 'booking') . '/booking.css',
);
$prefix = t("<h2>Edit Leaders/Helpers for Study Group &dash; !descrip</h2>",
array('!descrip' => $studygroup->booking_studygroup_descrip));
$prefix .= "<p>Enter part of a person's name in the text field and wait for the blue spinning circle to autocomplete with the person's details. " .
"Make sure you click on the person from the dropdown list that appears.</p>";
$form['first_para'] = array (
'#type' => 'markup',
'#markup' => $prefix,
);
//add this to the form in a hidden field so we can update the right studygroup
$form['booking_gid'] = array (
'#type' => 'hidden',
'#value' => $group_id,
);
//create the container element for the whole table
$form['studygroups'] = array(
'#prefix' => '<div id="studygroups">',
'#suffix' => '</div>',
'#tree' => TRUE,
'#theme' => 'table',
'#header' => $header,
'#rows' => array(),
);
//get the list of study group session memberships
$session_members_query = db_query("SELECT m.*, p.* FROM {booking_studygroup_mapping} m
inner join {booking_person} p on p.nid = m.booking_node_id
WHERE m.booking_studygroup_id = :gid AND m.booking_studygroup_role > 0",
array(':gid' => $group_id));
$session_members = $session_members_query->fetchAllAssoc('booking_node_id');
//create an array representing the existing leaders/helpers for this group
$existing_leaders = array();
foreach ($session_members as $person) {
$existing_leaders[$person->booking_session_id][$person->booking_studygroup_role] =
$person->booking_lastname . ', ' . $person->booking_firstname . ' [' . $person->booking_node_id . ']';
}
//create the rows for the individual sessions (instances really) of this study group
for ($i = 1; $i <= $studygroup->booking_num_group_sessions; $i++) {
$leader = array (
'#id' => 'booking-studygroup-leader-' . $i,
'#type' => 'textfield',
'#title' => 'Name',
'#title_display' => 'invisible',
'#name' => 'booking_studygroup_leader[' . $i . ']',
'#size' => 100,
'#autocomplete_path' => 'booking/studygroups/autocomplete',
'#value' => (!empty($existing_leaders[$i][1])) ? $existing_leaders[$i][1] : '',
'#attributes' => array('style' => array('width:200px')),
);
$helper = array (
'#id' => 'booking-studygroup-helper-' . $i,
'#type' => 'textfield',
'#title' => 'Name',
'#title_display' => 'invisible',
'#name' => 'booking_studygroup_helper[' . $i . ']',
'#size' => 100,
'#autocomplete_path' => 'booking/studygroups/autocomplete',
'#value' => (!empty($existing_leaders[$i][2])) ? $existing_leaders[$i][2] : '',
'#attributes' => array('style' => array('width:200px')),
);
$reserveleader = array (
'#id' => 'booking-studygroup-reserveleader-' . $i,
'#type' => 'textfield',
'#title' => 'Name',
'#title_display' => 'invisible',
'#name' => 'booking_studygroup_reserveleader[' . $i . ']',
'#size' => 100,
'#autocomplete_path' => 'booking/studygroups/autocomplete',
'#value' => (!empty($existing_leaders[$i][3])) ? $existing_leaders[$i][3] : '',
'#attributes' => array('style' => array('width:200px')),
);
$reservehelper = array (
'#id' => 'booking-studygroup-reservehelper-' . $i,
'#type' => 'textfield',
'#title' => 'Name',
'#title_display' => 'invisible',
'#name' => 'booking_studygroup_reservehelper[' . $i . ']',
'#size' => 100,
'#autocomplete_path' => 'booking/studygroups/autocomplete',
'#value' => (!empty($existing_leaders[$i][4])) ? $existing_leaders[$i][4] : '',
'#attributes' => array('style' => array('width:200px')),
);
$form['studygroups'][$i] = array(
'booking-studygroup-leader' => &$leader,
'booking-studygroup-helper' => &$helper,
'booking-studygroup-reserveleader' => &$reserveleader,
'booking-studygroup-reservehelper' => &$reservehelper,
);
$new_row = array();
//handle readings group differently
if ($studygroup->booking_is_readinggroup == 'Y') {
$new_row['sid'] = _booking_readinggroup_colour_lookup($i);
}
//non readings groups just show the session ID
else {
$new_row['sid'] = $i;
}
$new_row['booking_studygroup_leader'] = array('data' => &$leader);
$new_row['booking_studygroup_helper'] = array('data' => &$helper);
$new_row['booking_studygroup_reserveleader'] = array('data' => &$reserveleader);
$new_row['booking_studygroup_reservehelper'] = array('data' => &$reservehelper);
$form['studygroups']['#rows'][$i] = $new_row;
//clean up references
unset($leader);
unset($helper);
unset($reserveleader);
unset($reservehelper);
}
//record whether this was a reading group, so we can update colours if necessary
$form['booking_readinggroup'] = array (
'#type' => 'hidden',
'#value' => $studygroup->booking_is_readinggroup,
);
//close out the form
$form['submit'] = array (
'#type' => 'submit',
'#value' => t('Submit'),
);
return array (
'form' => $form,
);
}
/**
* Process the submission for leaders/helpers
*/
function booking_studygroup_leadhelp_edit_form_submit($form, &$form_state) {
global $event;
$values = $form_state['input'];
$group_id = $form_state['values']['booking_gid'];
$update_messages = array();
$counter = 0;
//watchdog('booking_debug', "<pre>Studygroup leader/helper test submission form :\n@info</pre>", array('@info' => print_r( $form_state, true)));
$role_types = array(
'booking_studygroup_leader' => 1,
'booking_studygroup_helper' => 2,
'booking_studygroup_reserveleader' => 3,
'booking_studygroup_reservehelper' => 4,
);
//iterate over the different role types
foreach ($role_types as $type => $type_id) {
//iterate over the sessions for that role type
foreach ($values[$type] as $session_id => $person) {
//get the previous value
$previous_value = _booking_studygroup_leadhelp_edit_get_previous_value($form, $type, $type . '[' . $session_id . ']');
//watchdog('booking_debug', "<pre>Studygroup assignment previous value:\n@info\nCurrent value:\n@current</pre>",
// array('@info' => print_r( $previous_value, true), '@current' => print_r( $person, true)));
//compare it against $person
//if $person is now empty, set the person's role to zero
if (empty($person) && $previous_value != 0) {
$update_messages[] = t("Clearing leader/helper role for nid @id and session @session in group @group. Used to have role @role.",
array('@id' => $previous_value, '@group' => $group_id, '@role' => $type_id, '@session' => $session_id));
db_update('booking_studygroup_mapping')
->fields(array(
'booking_studygroup_role' => 0,
))
->condition('booking_studygroup_id', $group_id)
->condition('booking_node_id', $previous_value)
->condition('booking_session_id', $session_id)
->execute();
$counter++;
}
elseif (!empty($person)) {
preg_match('/[\s\w,]+\s\[(\d+)\]/i', $person, $matches);
$person_nid = $matches[1];
//if $person is now different, run an update query
if ($person_nid != $previous_value) {
//check if this person is already a member of this studygroup
$group_query = db_query("SELECT * FROM {booking_studygroup_mapping} " .
"WHERE booking_eventid = :eid AND booking_node_id = :nid AND booking_studygroup_id = :gid",
array(':eid' => $event->eid, ':nid' => $person_nid, ':gid' => $group_id))
->fetchObject();
if (! $group_query) {
//this person doesn't seem to already be in this study group so insert a record
$update_messages[] = t("Adding via insert: role @role to nid @id in group @group and session @session.",
array('@id' => $person_nid, '@group' => $group_id, '@role' => $type_id, '@session' => $session_id));
db_insert('booking_studygroup_mapping')
->fields(array(
'booking_eventid' => $event->eid,
'booking_node_id' => $person_nid,
'booking_studygroup_id' => $group_id,
'booking_session_id' => $session_id,
'booking_studygroup_role' => $type_id,
))
->execute();
}
else {
//update the role for the new person
$update_messages[] = t("Adding via update: role @role to nid @id in group @group and session @session.",
array('@id' => $person_nid, '@group' => $group_id, '@role' => $type_id, '@session' => $session_id));
db_update('booking_studygroup_mapping')
->fields(array(
'booking_studygroup_role' => $type_id,
'booking_session_id' => $session_id,
))
->condition('booking_studygroup_id', $group_id)
->condition('booking_node_id', $person_nid)
->execute();
}
$counter++;
//remove the role from the old person if there was someone else there before
if ($previous_value != 0) {
$update_messages[] = t("Removing role @role from nid @id in group @group and session @session.",
array('@id' => $previous_value, '@group' => $group_id, '@role' => $type_id, '@session' => $session_id));
db_update('booking_studygroup_mapping')
->fields(array(
'booking_studygroup_role' => 0,
))
->condition('booking_studygroup_id', $group_id)
->condition('booking_node_id', $previous_value)
->condition('booking_session_id', $session_id)
->execute();
$counter++;
} //end previous value check
} //end different person check
} //end empty person check
} //iterate session
} //iterate role type
//do we need to update colours for reading group?
if ($form_state['values']['booking_readinggroup'] == 'Y') {
booking_studygroups_process_colours();
}
$final_message = "Made $counter updates leader/helper roles for study group id $group_id. Changing one person to another counts as two updates.";
drupal_set_message($final_message, 'status', FALSE);
watchdog('booking', "<pre>" . $final_message . "\n" . implode("\n", $update_messages) . "</pre>");
}
/**
* look through the previous form data and return the matching element
*/
function _booking_studygroup_leadhelp_edit_get_previous_value(&$form, $type, $name) {
foreach($form['form']['studygroups']['#rows'] as $key => $value) {
//watchdog('booking_debug', "<pre>Studygroup assignment checker for type !type in session !name:\n@info</pre>",
// array('!session' => $name, '!type' => $type, '@info' => print_r( $value, true)));
//return;
if ((!empty($value[$type]['data']['#value'])) && ($value[$type]['data']['#name'] == $name)) {
//found the correct element, extract the node id
$person = $value[$type]['data']['#value'];
if (preg_match('/[\s\w,]+\s\[(\d+)\]/i', $person, $matches)) {
return $matches[1];
}
}
}
//in case there was no matching value, return an empty string
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -38,6 +38,7 @@ function booking_studygroups_admin() {
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes));
return $output;
}
/**
@@ -65,7 +66,7 @@ function booking_studygroups_view_summary() {
$group->booking_is_readinggroup == 'Y' ? 'Yes' : 'No',
l(t('Current Membership', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/view', array('!id' => $group->sid))),
l(t('Compute Membership Update', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/update', array('!id' => $group->sid))),
l(t('Edit Leaders/Helpers', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/editleaders', array('!id' => $group->sid))),
l(t('Edit Leaders/Helpers', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/selectleaders', array('!id' => $group->sid))),
l(t('Download', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/view/csv', array('!id' => $group->sid))),
);
}
@@ -86,12 +87,14 @@ function booking_studygroups_define_form($node, &$form_state, $create, $editid =
$form = array ();
$prefix = "<p>Add a new study group definition</p>";
if ($create == true) {
if ($create == true)
{
drupal_set_title('Add Study Group');
$data = $node;
watchdog('booking_debug', 'Creating new study group: @info', array ('@info' => var_export($form_state, TRUE)));
watchdog('booking', 'Creating new study group: @info', array ('@info' => var_export($node, TRUE)));
}
else {
else
{
drupal_set_title('Edit Study Group');
//verify that $editid is a number
if (! preg_match('/^[0-9]+$/', $editid)) {
@@ -101,17 +104,21 @@ function booking_studygroups_define_form($node, &$form_state, $create, $editid =
}
$data = db_query("SELECT * FROM {booking_studygroup_list} WHERE sid = :id",
array(':id' => $editid))->fetchObject();
array(':id' => $editid))
->fetchObject();
$prefix = t("<p>Update the &quot;!event &quot; study group definition.</p>", array('!event' => $data->booking_studygroup_descrip));
//add this to the form in a hidden field so we can update the right price
$form['booking_sid'] = array (
'#type' => 'hidden',
'#value' => $editid,
);
watchdog('booking_debug', "<pre>Editing study group definition:\n@info</pre>", array ('@info' => print_r($data, TRUE)));
watchdog('booking', 'Editing study group definition: @info',
array ('@info' => var_export($data, TRUE)));
}
if(!isset($form_state['storage']['confirm'])) {
if(!isset($form_state['storage']['confirm']))
{
$form['booking_studygroup_descrip'] = array (
'#type' => 'textfield',
'#title' => t('Description of this study group (eg Monday)'),
@@ -137,15 +144,15 @@ function booking_studygroups_define_form($node, &$form_state, $create, $editid =
'#options' => array (0 => t('No'), t('Yes')),
'#default_value' => !empty($data->booking_is_readinggroup) ? ($data->booking_is_readinggroup == 'Y' ? 1 : 0) : 0,
);
//create the buttons
if ($create == true) {
if ($create == true)
{
$form['submit'] = array
(
'#type' => 'submit',
'#value' => t('Create Study Group'),
);
}
else {
} else {
$form['Update'] = array
(
'#type' => 'submit',
@@ -157,7 +164,7 @@ function booking_studygroups_define_form($node, &$form_state, $create, $editid =
'#value' => t("Delete Study Group Definition"),
);
}
//return the render array
return array (
'first_para' => array (
'#type' => 'markup',
@@ -167,16 +174,15 @@ function booking_studygroups_define_form($node, &$form_state, $create, $editid =
);
}
//confirm delete
else {
else
{
return confirm_form($form, "Are you sure you wish to delete studygroup definition with id " . $editid . "?",
current_path(), NULL, "Delete Study Group Definition");
}
}
/**
* Process addition/update/delete of a studygroup definition
*/
function booking_studygroups_define_form_submit($form, &$form_state) {
global $event;
@@ -189,7 +195,8 @@ function booking_studygroups_define_form_submit($form, &$form_state) {
array(':eid' => $event->eid))->fetchObject();
//watchdog('booking', 'Checkboxes when setting buttons: @info', array ('@info' => var_export($checkboxes, TRUE)));
if ($form_state['values']['op'] == 'Create Study Group') {
if ($form_state['values']['op'] == 'Create Study Group')
{
db_insert('booking_studygroup_list')
->fields(array(
'booking_eventid' => $event->eid,
@@ -202,27 +209,33 @@ function booking_studygroups_define_form_submit($form, &$form_state) {
$new_count = $count->num + 1;
}
//if we're deleting, add the confirmation to the form if it hasn't been defined yet
elseif($form_state['values']['op'] == "Delete Study Group Definition" && (!isset($form_state['storage']['confirm']))) {
elseif($form_state['values']['op'] == "Delete Study Group Definition" && (!isset($form_state['storage']['confirm'])))
{
watchdog('booking', "<pre>Studygroup deletion confirmation being set:\n@info</pre>", array('@info' => print_r( $form_state, true)));
$form_state['storage']['confirm'] = TRUE;
$form_state['rebuild'] = TRUE;
$new_count = $count->num;
}
elseif ($form_state['values']['op'] == 'Delete Study Group Definition') {
}
elseif ($form_state['values']['op'] == 'Delete Study Group Definition')
{
//verify that booking_pid is a number
if (! preg_match('/^[0-9]+$/', $values['booking_sid'])) {
drupal_set_message("Error: Invalid studygroup ID supplied. Unable to delete entry.", 'error', FALSE);
return "";
}
//TODO: Confirmation
//return confirm_form($form, "Really delete price?", 'admin/config/booking/prices');
$num_deleted = db_delete('booking_studygroup_list')
->condition('sid', $values['booking_sid'])
->execute();
$new_count = $count->num - 1;
}
elseif ($form_state['values']['op'] == 'Update Study Group') {
elseif ($form_state['values']['op'] == 'Update Study Group')
{
//verify that booking_sid is a number
if (! preg_match('/^[0-9]+$/', $values['booking_sid'])) {
@@ -246,8 +259,6 @@ function booking_studygroups_define_form_submit($form, &$form_state) {
//update the number of study groups now defined
variable_set('booking_studygroup_count', $new_count);
//call the mysql view update function so that the view matches the new number of study groups
_booking_node_create_mysqlview();
//redirect to the specified path now that the form has been processed
$form_state['redirect'] = $redirect_path;
}

View File

@@ -38,9 +38,9 @@ function booking_studygroups_csv_report($group_id) {
$enclosure_esc = preg_quote($enclosure, '/');
//get the list of study group session memberships
$session_members_query = db_query("SELECT m.*, p.* FROM {booking_studygroup_mapping} m
$session_members_query = db_query("SELECT m.*, p.booking_firstname, p.booking_lastname FROM {booking_studygroup_mapping} m
inner join {booking_person} p on p.nid = m.booking_node_id
WHERE m.booking_studygroup_id = :sid ORDER BY m.booking_session_id, m.booking_studygroup_role DESC, p.booking_lastname",
WHERE m.booking_studygroup_id = :sid ORDER BY m.booking_session_id, m.booking_studygroup_role DESC",
array(':sid' => $group_id));
$session_members = $session_members_query->fetchAll();
@@ -49,21 +49,12 @@ function booking_studygroups_csv_report($group_id) {
if (! isset($data[$member->booking_session_id])) {
$data[$member->booking_session_id] = array();
}
// lookup the name and role for this entry in the study group session and optionally include age
if (variable_get('booking_studygroup_csv_ages', 0) == 1) {
$text = array($member->booking_firstname, $member->booking_lastname, '[' . _booking_get_age_years($member->booking_dob) .']');
}
else {
$text = array($member->booking_firstname, $member->booking_lastname);
}
// lookup the name and role for this entry in the study group session
$text = array($member->booking_firstname, $member->booking_lastname);
//add their role if they're leading/helping etc
if ($member->booking_studygroup_role > 0) {
array_push($text, '(' . _booking_studygroup_role_lookup($member->booking_studygroup_role) . ')');
}
//also tag committee members
if ($member->booking_committee_member == 'Y') {
array_push($text, '(committee)');
}
//add the spaces and put this element in the right array
$data[$member->booking_session_id][] = implode(' ', $text);
@@ -77,12 +68,7 @@ function booking_studygroups_csv_report($group_id) {
foreach ($header_array as $column) {
$maximums[] = count($data[$column]);
//make the column headings a bit more user friendly
if ($group->booking_is_readinggroup == 'Y') {
$column_headings[] = _booking_readinggroup_colour_lookup($column);
}
else {
$column_headings[] = "Session " . $column;
}
$column_headings[] = "Session " . $column;
}
//add the column headings to the CSV
@@ -114,58 +100,3 @@ function booking_studygroups_csv_report($group_id) {
print $csv;
exit(0);
}
/**
* Function to generate table listing all males and groups they're leading/helping
*/
function booking_studygroups_leadhelp_view_summary() {
global $event;
$output = "";
$header = array('First Name', 'Last Name');
$rows = array();
$attributes = array('style' => 'max-width:100%');
//get study group definitions
$query = db_select('booking_studygroup_list', 's')
->fields('s')
->condition('s.booking_eventid', $event->eid, '=')
->orderBy('sid');
$studygroup_list = $query->execute()->fetchAllAssoc('sid');
//add columns for the study groups
foreach ($studygroup_list as $group) {
$header[] = $group->booking_studygroup_descrip;
}
$person_query = db_query("SELECT * FROM {booking_person_view} WHERE booking_gender = 'M' " .
" AND (booking_status = 1 OR booking_status = 2)" .
" ORDER BY booking_lastname, booking_firstname")->fetchAllAssoc('nid');
//loop through each matching person
foreach ($person_query as $person) {
//add the name to an array for this line
$newline = array($person->booking_firstname, $person->booking_lastname);
foreach ($studygroup_list as $group) {
$session = 'session' . $group->sid;
$session_role = 'session' . $group->sid . '_role';
//add details if they have a role for this studygroup
if ($person->$session_role > 0) {
$text = _booking_studygroup_role_lookup($person->$session_role);
$newline[] .= "<b>" . $text . "</b>, session #" . $person->$session;
}
//otherwise put a blank entry for this studygroup
else {
$newline[] = "";
}
} //end iterate studygroup list
//add the line to the array of rows
$rows[] = $newline;
} //end iterate person list
//output everything
$output .= t("<h3>!event Study Group Leaders and Helpers</h3>", array('!event' => $event->booking_eventname));
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes));
return $output;
}

View File

@@ -1,4 +1,5 @@
<?php
// $Id: booking.admin.inc,v 0.1 2011/07/12
/**
* @file
@@ -47,6 +48,49 @@ function booking_tokens_admin() {
$booking_waitingpage_pre_nowaitlist_text = "<p>There's no one on the waiting list yet. If you haven't already done so, go ahead and <a href=\"/booking\">register</a>.</p>\n<br />\n";
$booking_waitingpage_post_text = "<p></p>\n";
$default_email_text = "Dear [booking:fname],\n" .
"Congratulations, you are officially booked into [booking:eventname]. " .
"Your registration reference number is [booking:booking-id].\n" .
"Please don't hesitate to contact us if you have any queries by replying to this email. " .
"We look forward to seeing you (God Willing) at [booking:eventname]!\n" .
"Love in Jesus,\n[booking:eventname] Registrations Team\n" .
"________________________________________________________\n" .
"The following information shows the details you entered when you registered. " .
"If any of this information is incorrect, please reply to this email with the corrections as soon as possible.\n" .
"________________________________________________________";
$booking_email_regn_complete_text = "Dear [booking:fname],\n" .
"Thank-you for completing your payment for [booking:eventname].\n" .
"Please don't hesitate to contact us if you have any queries by replying to this email. " .
"We look forward to seeing you (God Willing) at [booking:eventname]!\n" .
"Love in Jesus,\n[booking:eventname] Registrations Team\n" .
"________________________________________________________\n" .
"The following information shows the details you entered when you registered. " .
"If any of this information is incorrect, please reply to this email with the corrections as soon as possible.\n" .
"________________________________________________________";
$booking_email_waitinglist_text = "Dear [booking:fname],\n" .
"Thank-you for registering to attend [booking:eventname]. Unfortunately the venue for this event is full, and you have been placed on the waiting list to attend.\n" .
"We will contact you if a position becomes available for you. Please don't hesitate to contact us if you have any queries by replying to this email.\n" .
"Love in Jesus,\n[booking:eventname] Registrations Team\n" .
"________________________________________________________\n" .
"The following information shows the details you entered when you registered. " .
"If any of this information is incorrect, please reply to this email with the corrections as soon as possible.\n" .
"________________________________________________________";
$booking_email_paymentoutstanding_text = "Dear [booking:fname],\n" .
"Thank-you for registering to attend [booking:eventname]. Our records indicate that you currently have $[booking:payment-required] outstanding to finalise your registration.\n" .
"Please visit [booking:balance-payment-link] in order to make your final payment.\n" .
"Love in Jesus,\n[booking:eventname] Registrations Team\n" .
"________________________________________________________\n";
$booking_email_waitinglistpromotion = "Dear [booking:fname],\n" .
"We have some great news for you. A place at [booking:eventname] for you has just become available. " .
"If you wish to secure your place at [booking:eventname], please visit [booking:balance-payment-link] to make your final payment. " .
"Our records indicate that you currently have $[booking:paypal-total-amount] outstanding (including Paypal transaction fees).\n" .
"Once we have received your payment, you will be sent an automatic confirmation email thanking you for paying your outstanding fees. " .
"If you are paying via Paypal's eCheque feature, please be aware that payments take 3-5 working days to clear, " .
"and you will not receive the confirmation email until that has occurred.\n" .
"Please don't hesitate to contact us if you have any queries by replying to this email. We look forward to seeing you, God Willing, at [booking:eventname]\n" .
"Love in Jesus,\n[booking:eventname] Registrations Team.";
$booking_email_notcoming_demotion = "";
$booking_email_paymentoutstanding_married_text = "";
$booking_confirmation_text = "<p>Thanks for filling out the registration form.</p>\n" .
"<p>To complete your booking, please make a payment of <strong>$[booking:payment-required]</strong> into the following bank account<br />\n" .
"&nbsp;Account Name: blah<br />\n&nbsp;BSB: blah<br />\n&nbsp;Account Number: blah</p>\n" .
@@ -149,7 +193,17 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text
'#description' => t(''),
'#default_value' => variable_get('booking_regn_confirm_married_text', $booking_regn_confirm_married_text),
);
//$booking_regn_completed_page_default = variable_get('booking_regn_completed_page');
//$booking_regn_completed_page = isset($booking_regn_completed_page_default['value']) ? $booking_regn_completed_page_default['value'] : '';
$form['confirmation']['booking_regn_completed_page'] = array(
'#title' => t('Text to use for landing page on return from paypal website'),
'#type' => 'textarea',
'#description' => t(''),
//'#default_value' => $booking_regn_completed_page,
'#default_value' => isset(variable_get('booking_regn_completed_page')['value']) ? variable_get('booking_regn_completed_page')['value'] : $defaults,
'#type' => 'text_format',
'#format' => 'full_html',
);
/*Text for the balance payment page*/
$form['balance'] = array(
'#type' => 'fieldset',
@@ -257,40 +311,6 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['travel']['booking_travelform_page'] = array(
'#title' => t('Text to use at the start of the travel form for a non-married person.'),
'#type' => 'textarea',
'#description' => t(''),
'#default_value' => isset(variable_get('booking_travelform_page')['value']) ? variable_get('booking_travelform_page')['value'] : $defaults,
'#type' => 'text_format',
'#format' => 'full_html',
);
$form['travel']['booking_travelform_married_page'] = array(
'#title' => t('Text to use at the start of the travel form for a married couple. Only applies if combined pricing is enabled.'),
'#type' => 'textarea',
'#description' => t(''),
'#default_value' => isset(variable_get('booking_travelform_married_page')['value']) ? variable_get('booking_travelform_married_page')['value'] : $defaults,
'#type' => 'text_format',
'#format' => 'full_html',
);
$form['travel']['booking_travelform_page_post_text'] = array(
'#title' => t('Text to use at the end of the travel form. This is not displayed on the "travel form completed" page defined below.'),
'#type' => 'textarea',
'#description' => t(''),
'#default_value' => isset(variable_get('booking_travelform_page_post_text')['value']) ? variable_get('booking_travelform_page_post_text')['value'] : $defaults,
'#type' => 'text_format',
'#format' => 'full_html',
);
$form['travel']['booking_travelform_completed_page'] = array(
'#title' => t('Text to use on the travel form if the form has already been submitted.'),
'#type' => 'textarea',
'#description' => t(''),
'#default_value' => isset(variable_get('booking_travelform_completed_page')['value']) ? variable_get('booking_travelform_completed_page')['value'] : $defaults,
'#type' => 'text_format',
'#format' => 'full_html',
);
/*
$form['travel']['booking_travelform_page'] = array(
'#title' => t('Text to use at the start of the travel form for a non-married person.'),
'#type' => 'textarea',
@@ -309,27 +329,165 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text
'#description' => t(''),
'#default_value' => variable_get('booking_travelform_completed_page', ''),
);
*/
//other pages like paypal landing page
$form['otherpages'] = array(
/*Text for emails*/
$form['emails'] = array(
'#type' => 'fieldset',
'#title' => 'Miscellaneous pages',
'#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,
);
//$booking_regn_completed_page_default = variable_get('booking_regn_completed_page');
//$booking_regn_completed_page = isset($booking_regn_completed_page_default['value']) ? $booking_regn_completed_page_default['value'] : '';
$form['otherpages']['booking_regn_completed_page'] = array(
'#title' => t('Text to use for landing page on return from paypal website'),
'#type' => 'textarea',
'#description' => t(''),
//'#default_value' => $booking_regn_completed_page,
'#default_value' => isset(variable_get('booking_regn_completed_page')['value']) ? variable_get('booking_regn_completed_page')['value'] : $defaults,
'#type' => 'text_format',
'#format' => 'full_html',
);
//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, ''),
);
}
//see http://drupal.org/node/820816#comment-3100356
//and http://drupal.org/node/823362
@@ -381,10 +539,6 @@ function booking_token_info() {
'name' => t('Event Contact Email'),
'description' => t('Contact email address for the current event.')
);
$info['tokens']['booking']['logistics-email'] = array(
'name' => t('Event Logistics Email'),
'description' => t('Logistics email address for the current event.')
);
$info['tokens']['booking']['eventdates'] = array(
'name' => t('Event Dates'),
'description' => t('Dates of the current event.')
@@ -437,14 +591,6 @@ function booking_token_info() {
'name' => t('Paypal Total Form Button'),
'description' => t('The paypal form for the total amount.')
);
$info['tokens']['booking']['stripe-deposit-form'] = array(
'name' => t('Stripe Deposit Form Button'),
'description' => t('The stripe popup form for the deposit amount.')
);
$info['tokens']['booking']['stripe-total-form'] = array(
'name' => t('Stripe Total Form Button'),
'description' => t('The stripe popup form for the total amount.')
);
$info['tokens']['booking']['booking-id'] = array(
'name' => t('Booking ID'),
'description' => t('ID of the user\'s registration.')
@@ -550,7 +696,6 @@ function booking_define_tokens()
date("Y-m-d", $booking_times->booking_event_end));
$tokens['contact-us'] = l('contact us', 'contact-us');
$tokens['contact-email'] = variable_get('booking_contact_email');
$tokens['logistics-email'] = variable_get('booking_logistics_email');
$tokens['regn-count'] = $regncount_query->num_ppl;
$tokens['regn-limit'] = variable_get('booking_regn_limit',0);
return $tokens;
@@ -595,7 +740,6 @@ function booking_define_personspecific_tokens($node)
$tokens = array();
$tokens['eventname'] = $event->booking_eventname;
$tokens['contact-email'] = variable_get('booking_contact_email');
$tokens['logistics-email'] = variable_get('booking_logistics_email');
$tokens['team-colour'] = ucwords($node->booking_readinggroup);
$tokens['fname'] = ucwords(trim($node->booking_firstname));
$tokens['lname'] = ucwords(trim($node->booking_lastname));
@@ -614,9 +758,6 @@ function booking_define_personspecific_tokens($node)
if (variable_get('booking_enable_travelform', 0) == 1) {
$tokens['travel-link'] = url('travel/' . $tempid, array('absolute' => TRUE));
$tokens['travel-summary'] = _booking_travelform_email_summary($node);
} else {
$tokens['travel-link'] = "";
$tokens['travel-summary'] = "";
}
if (variable_get('booking_enable_studygroups', 0) == 1) {
$tokens['studygroup-summary'] = _booking_studygroup_email_summary($node);
@@ -627,6 +768,6 @@ function booking_define_personspecific_tokens($node)
$tokens['room-allocation'] = _booking_room_email_summary($node);
$tokens['bed-type'] = _booking_room_bedtype_lookup(empty($node->booking_room_bedtype) ? '0' : $node->booking_room_bedtype);
}
//watchdog('booking_debug', "<pre>Person specific tokens:\n@info</pre>", array('@info' => print_r( $tokens, true)));
return $tokens;
}

File diff suppressed because it is too large Load Diff