From e02d8638330c3a993fe615b5a21d4c3438aade3c Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Wed, 25 May 2016 11:20:35 +1000 Subject: [PATCH] Code formatting fix --- booking.travel.inc | 1305 ++++++++++++++++++++++---------------------- 1 file changed, 667 insertions(+), 638 deletions(-) diff --git a/booking.travel.inc b/booking.travel.inc index 84b8969..8cac6eb 100644 --- a/booking.travel.inc +++ b/booking.travel.inc @@ -3,668 +3,697 @@ /** * Travel form for attendee */ -function booking_travel_page() { - global $event; - $output = ""; - $return_array = array(); - - //verify that arg(1) is a uuid - if (! preg_match('/^[0-9A-Fa-f\-]+$/', arg(1))) { - //parameter from url is not what we were expecting - drupal_set_message("Error: Invalid session ID supplied. Please use the contact us form to let us know.", 'error', FALSE); - drupal_goto('content/travel'); - return ""; - } - - if (variable_get('booking_enable_travelform', 0) == 0) { - drupal_set_message("Error: The travel form is not enabled. Please use the contact us form to inform the site owner of this error.", 'error', FALSE); - drupal_goto('content/travel'); - return ""; - } - - - //work out the node id from the session id - $query = db_select('booking_person', 'p'); - $query->condition('p.booking_tempid', arg(1), '=') - ->fields('p', array('nid')); - $person = $query->execute() - ->fetchObject(); - - //if we found a matching person - if ($person) - { - //load this person's data - $node = node_load($person->nid); - - $tokens = booking_define_personspecific_tokens($node); - - //watchdog('booking', 'Checking for existing travel form for: @info', array('@info' => var_export($person, TRUE))); - - //check for an existing travel form - if (! empty( $node->tid )) - { - $output = token_replace(variable_get('booking_travelform_completed_page'), $tokens); - $return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output)); - } - //they haven't submitted a travel form yet - else - { - //Output different text if this is for a married couple - if ((variable_get('booking_enable_combined_pricing', 0) == 1) && $node->booking_partner_id > 0) - { - $output = token_replace(variable_get('booking_travelform_married_page'), $tokens); - } - else - { - $output = token_replace(variable_get('booking_travelform_page'), $tokens); - } - - $return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output)); - $return_array[] = array('form' => drupal_get_form('travel_form', true, $node->nid)); - } - - return $return_array; - //there was no person matching this session id - } else { - drupal_set_message("Unable to find matching session ID " . arg(1), 'error', FALSE); - return ""; - } - +function booking_travel_page() +{ + global $event; + $output = ""; + $return_array = array(); + + //verify that arg(1) is a uuid + if (!preg_match('/^[0-9A-Fa-f\-]+$/', arg(1))) { + //parameter from url is not what we were expecting + drupal_set_message("Error: Invalid session ID supplied. Please use the contact us form to let us know.", 'error', FALSE); + drupal_goto('content/travel'); + return ""; + } + + if (variable_get('booking_enable_travelform', 0) == 0) { + drupal_set_message("Error: The travel form is not enabled. Please use the contact us form to inform the site owner of this error.", 'error', FALSE); + drupal_goto('content/travel'); + return ""; + } + + + //work out the node id from the session id + $query = db_select('booking_person', 'p'); + $query->condition('p.booking_tempid', arg(1), '=')->fields('p', array( + 'nid' + )); + $person = $query->execute()->fetchObject(); + + //if we found a matching person + if ($person) { + //load this person's data + $node = node_load($person->nid); + + $tokens = booking_define_personspecific_tokens($node); + + //watchdog('booking', 'Checking for existing travel form for: @info', array('@info' => var_export($person, TRUE))); + + //check for an existing travel form + if (!empty($node->tid)) { + $output = token_replace(variable_get('booking_travelform_completed_page'), $tokens); + $return_array[] = array( + 'paragraph' => array( + '#type' => 'markup', + '#markup' => $output + ) + ); + } + //they haven't submitted a travel form yet + else { + //Output different text if this is for a married couple + if ((variable_get('booking_enable_combined_pricing', 0) == 1) && $node->booking_partner_id > 0) { + $output = token_replace(variable_get('booking_travelform_married_page'), $tokens); + } else { + $output = token_replace(variable_get('booking_travelform_page'), $tokens); + } + + $return_array[] = array( + 'paragraph' => array( + '#type' => 'markup', + '#markup' => $output + ) + ); + $return_array[] = array( + 'form' => drupal_get_form('travel_form', true, $node->nid) + ); + } + + return $return_array; + //there was no person matching this session id + } else { + drupal_set_message("Unable to find matching session ID " . arg(1), 'error', FALSE); + return ""; + } + } function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0) { - global $event; - date_default_timezone_set(date_default_timezone(FALSE)); - - $booking_dietary = ''; - $booking_medical_conditions = ''; - $booking_bf_gf_nid = ''; - $booking_roommate = ''; - - $transport_type_options = array( - 'Driving' => 'Driving', - //'Train' => 'Train', - 'Flying' => 'Flying' - ); - - //there's already info in $node so use that - if (!empty($node)) - { - $data = $node; - } - //otherwise rely on the form state from the previous submission - else - { - $data = $form_state['input']; - } - - //get info about this person from the relevant node id - $person = db_query("SELECT booking_dietary, booking_medical_conditions, booking_bf_gf_nid, booking_partner_id, booking_room_mate1 " . - "FROM {booking_person} " . - "WHERE nid = :nid ", - array(':nid' => $nid <> 0 ? $nid : $data->booking_person_nid)) - ->fetchObject(); - - if ($person) - { - $booking_dietary = $person->booking_dietary; - $booking_medical_conditions = $person->booking_medical_conditions; - //an empty value is zero in this case - $booking_bf_gf_nid = $person->booking_bf_gf_nid == 0 ? '' : $person->booking_bf_gf_nid; - $booking_roommate = $person->booking_room_mate1; - } - + global $event; + date_default_timezone_set(date_default_timezone(FALSE)); + + $booking_dietary = ''; + $booking_medical_conditions = ''; + $booking_bf_gf_nid = ''; + $booking_roommate = ''; + + $transport_type_options = array( + 'Driving' => 'Driving', + //'Train' => 'Train', + 'Flying' => 'Flying' + ); + + //there's already info in $node so use that + if (!empty($node)) { + $data = $node; + } + //otherwise rely on the form state from the previous submission + else { + $data = $form_state['input']; + } + + //get info about this person from the relevant node id + $person = db_query("SELECT booking_dietary, booking_medical_conditions, booking_bf_gf_nid, booking_partner_id, booking_room_mate1 " . "FROM {booking_person} " . "WHERE nid = :nid ", array( + ':nid' => $nid <> 0 ? $nid : $data->booking_person_nid + ))->fetchObject(); + + if ($person) { + $booking_dietary = $person->booking_dietary; + $booking_medical_conditions = $person->booking_medical_conditions; + //an empty value is zero in this case + $booking_bf_gf_nid = $person->booking_bf_gf_nid == 0 ? '' : $person->booking_bf_gf_nid; + $booking_roommate = $person->booking_room_mate1; + } + //form starts here - //store the node id - $form['personid'] = array( - '#type' => 'hidden', - '#value' => $nid, - ); - - $form['travel'] = array( - '#type' => 'fieldset', - '#title' => 'Travel details', - ); - $form['travel']['booking_transport_type'] = array( - '#type' => 'radios', - '#title' => t('Transport Type'), - '#options' => $transport_type_options, - '#default_value' => !empty($data->booking_transport_type) ? $data->booking_transport_type : NULL, - '#required' => TRUE, - ); - - /* - $form['travel']['booking_transport_to_morriset_reqd'] = array( - '#type' => 'radios', - '#title' => t('Do you require transport from Study Week to Morriset Station?'), - '#options' => array('Yes' => 'Yes', 'No' => 'No - I have arranged my own Transport'), - '#default_value' => (! isset($data->booking_transport_to_morriset_reqd)) ? '' : ($data->booking_transport_to_morriset_reqd == 1 ? 'Yes' : 'No'), - '#states' => array( - 'visible' => array( - ':input[name="booking_transport_type"]' => array('value' => 'Train'), - ), - ), - ); - */ - //Flying Options - $form['travel']['booking_flightnum_inbound'] = array( - '#type' => 'textfield', - '#title' => t('Flight Number arriving into Sydney'), - '#maxlength' => 50, - '#default_value' => empty($data->booking_flightnum_inbound) ? '' : $data->booking_flightnum_inbound, - '#states' => array( - 'visible' => array( - ':input[name="booking_transport_type"]' => array('value' => 'Flying'), - ), - ), - ); - $form['travel']['booking_flight_datetime_inbound'] = array( - '#type' => 'date_select', - '#title' => t('Date and Time of flight arrival into Sydney Airport'), - '#description' => t('Note: 24 hour time - 12:00 is midday'), - '#default_value' => empty($data->booking_flight_datetime_inbound) ? '' : date("Y-m-d H:i:s", $data->booking_flight_datetime_inbound), - '#date_format' => 'd/m/Y H:i', - '#date_year_range' => '0:0', - '#states' => array( - 'visible' => array( - ':input[name="booking_transport_type"]' => array('value' => 'Flying'), - ), - ), - ); - $form['travel']['booking_flightnum_outbound'] = array( - '#type' => 'textfield', - '#title' => t('Flight Number departing from Sydney'), - '#maxlength' => 50, - '#default_value' => empty($data->booking_flightnum_outbound) ? '' : $data->booking_flightnum_outbound, - '#states' => array( - 'visible' => array( - ':input[name="booking_transport_type"]' => array('value' => 'Flying'), - ), - ), - ); - $form['travel']['booking_flight_datetime_outbound'] = array( - '#type' => 'date_select', - '#title' => t('Date and Time of flight departure from Sydney Airport'), - '#description' => t('Note: 24 hour time - 12:00 is midday'), - '#default_value' => empty($data->booking_flight_datetime_outbound) ? '' : date("Y-m-d H:i:s", $data->booking_flight_datetime_outbound), - '#date_format' => 'd/m/Y H:i', - '#date_year_range' => '0:0', - '#states' => array( - 'visible' => array( - ':input[name="booking_transport_type"]' => array('value' => 'Flying'), - ), - ), - ); - - $form['travel']['booking_transport_from_morriset_reqd'] = array( - '#type' => 'radios', - '#title' => t('Will you be catching the train to Study Week?'), - '#options' => array('Yes' => 'Yes I will be catching the train', 'No' => 'No - I have arranged my own Transport'), - '#default_value' => (! isset($data->booking_transport_from_morriset_reqd)) ? 'No' : ($data->booking_transport_from_morriset_reqd == 1 ? 'Yes' : 'No'), - '#states' => array( - 'visible' => array( - ':input[name="booking_transport_type"]' => array('value' => 'Flying'), - ), - ), - ); - - $form['accommodation'] = array( - '#type' => 'fieldset', - '#title' => 'Accommodation Details', - ); - $form['accommodation']['booking_accom_before_reqd'] = array( - '#type' => 'radios', - '#title' => t('Do you need us to organise accommodation before Study Week?'), - '#options' => array('Yes' => 'Yes', 'No' => "No - I have arranged my own accommodation or I'm not arriving early"), - '#default_value' => (! isset($data->booking_accom_before_reqd)) ? 'No' : ($data->booking_accom_before_reqd == 1 ? 'Yes' : 'No'), - ); - /* - $form['accommodation']['booking_accom_before_staying_with'] = array( - '#type' => 'textfield', - '#title' => t('Who are you staying with in Sydney before Study Week?'), - '#maxlength' => 100, - '#default_value' => empty($data->booking_accom_before_staying_with) ? '' : $data->booking_accom_before_staying_with, - '#states' => array( - 'visible' => array( - ':input[name="booking_accom_before_reqd"]' => array('value' => 'No'), - ), - ), - ); - */ - $form['accommodation']['booking_accom_after_reqd'] = array( - '#type' => 'radios', - '#title' => t('Do you need us to organise accommodation after Study Week?'), - '#options' => array('Yes' => 'Yes', 'No' => "No - I have arranged my own accommodation or I'm not staying in Sydney afterwards"), - '#default_value' => (! isset($data->booking_accom_after_reqd)) ? 'No' : ($data->booking_accom_after_reqd == 1 ? 'Yes' : 'No'), - ); - /* - $form['accommodation']['booking_accom_after_staying_with'] = array( - '#type' => 'textfield', - '#title' => t('Who are you staying with in Sydney after Study Week?'), - '#maxlength' => 100, - '#default_value' => empty($data->booking_accom_after_staying_with) ? '' : $data->booking_accom_after_staying_with, - '#states' => array( - 'visible' => array( - ':input[name="booking_accom_after_reqd"]' => array('value' => 'No'), - ), - ), - ); - */ - $form['requirements'] = array( - '#type' => 'fieldset', - '#title' => 'Special Requirements', - ); - //only show the dietary field if we're allowed to - if (variable_get('booking_enable_dietary', 0) == 1 || $inserting == FALSE) - { - $form['requirements']['booking_dietary'] = array( - '#type' => 'textfield', - '#title' => t('Special dietary requirements?'), - '#maxlength' => 180, - '#default_value' => !empty($data->booking_dietary) ? $data->booking_dietary : $booking_dietary, - ); - } - $form['requirements']['booking_medical_conditions'] = array( - '#type' => 'textfield', - '#title' => t('Please describe any medical condition we need to know about.'), - '#maxlength' => 180, - '#required' => FALSE, - '#default_value' => !empty($data->booking_medical_conditions) ? $data->booking_medical_conditions : $booking_medical_conditions, - ); - //only show the room mate field if we're allowed to - if (variable_get('booking_enable_roommate', 0) == 1 || $inserting == FALSE) - { - //married people won't need to select a room mate - if ((variable_get('booking_enable_combined_pricing', 0) == 1) && $person->booking_partner_id == 0) - { - $form['requirements']['booking_room_mate1'] = array( - '#type' => 'textfield', - '#title' => t('I would like to share a room with'), - '#maxlength' => 200, - '#required' => FALSE, - '#default_value' => !empty($data->booking_room_mate1) ? $data->booking_room_mate1 : $booking_roommate, - ); - } - } - //only show this field if this person isn't married - if (((variable_get('booking_enable_combined_pricing', 0) == 1) && $person->booking_partner_id == 0) || (variable_get('booking_enable_combined_pricing', 0) == 0)) - { - $form['requirements']['booking_bf_gf_nid'] = array( - '#type' => 'textfield', - '#title' => t('Registration ID of Boyfriend/Girlfriend to be placed in the same discussion groups as you.'), - '#description' => t('If you\'re not sure what this number is, ask your Significant Other to look at the confirmation email they received when they registered.'), - '#maxlength' => 15, - '#size' => 4, - '#required' => FALSE, - '#default_value' => !empty($data->booking_bf_gf_nid) ? $data->booking_bf_gf_nid : $booking_bf_gf_nid, - ); - } - - if ($inserting == TRUE) { - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit'), - ); - } - return $form; + //store the node id + $form['personid'] = array( + '#type' => 'hidden', + '#value' => $nid + ); + + $form['travel'] = array( + '#type' => 'fieldset', + '#title' => 'Travel details' + ); + $form['travel']['booking_transport_type'] = array( + '#type' => 'radios', + '#title' => t('Transport Type'), + '#options' => $transport_type_options, + '#default_value' => !empty($data->booking_transport_type) ? $data->booking_transport_type : NULL, + '#required' => TRUE + ); + + /* + $form['travel']['booking_transport_to_morriset_reqd'] = array( + '#type' => 'radios', + '#title' => t('Do you require transport from Study Week to Morriset Station?'), + '#options' => array('Yes' => 'Yes', 'No' => 'No - I have arranged my own Transport'), + '#default_value' => (! isset($data->booking_transport_to_morriset_reqd)) ? '' : ($data->booking_transport_to_morriset_reqd == 1 ? 'Yes' : 'No'), + '#states' => array( + 'visible' => array( + ':input[name="booking_transport_type"]' => array('value' => 'Train'), + ), + ), + ); + */ + //Flying Options + $form['travel']['booking_flightnum_inbound'] = array( + '#type' => 'textfield', + '#title' => t('Flight Number arriving into Sydney'), + '#maxlength' => 50, + '#default_value' => empty($data->booking_flightnum_inbound) ? '' : $data->booking_flightnum_inbound, + '#states' => array( + 'visible' => array( + ':input[name="booking_transport_type"]' => array( + 'value' => 'Flying' + ) + ) + ) + ); + $form['travel']['booking_flight_datetime_inbound'] = array( + '#type' => 'date_select', + '#title' => t('Date and Time of flight arrival into Sydney Airport'), + '#description' => t('Note: 24 hour time - 12:00 is midday'), + '#default_value' => empty($data->booking_flight_datetime_inbound) ? '' : date("Y-m-d H:i:s", $data->booking_flight_datetime_inbound), + '#date_format' => 'd/m/Y H:i', + '#date_year_range' => '0:0', + '#states' => array( + 'visible' => array( + ':input[name="booking_transport_type"]' => array( + 'value' => 'Flying' + ) + ) + ) + ); + $form['travel']['booking_flightnum_outbound'] = array( + '#type' => 'textfield', + '#title' => t('Flight Number departing from Sydney'), + '#maxlength' => 50, + '#default_value' => empty($data->booking_flightnum_outbound) ? '' : $data->booking_flightnum_outbound, + '#states' => array( + 'visible' => array( + ':input[name="booking_transport_type"]' => array( + 'value' => 'Flying' + ) + ) + ) + ); + $form['travel']['booking_flight_datetime_outbound'] = array( + '#type' => 'date_select', + '#title' => t('Date and Time of flight departure from Sydney Airport'), + '#description' => t('Note: 24 hour time - 12:00 is midday'), + '#default_value' => empty($data->booking_flight_datetime_outbound) ? '' : date("Y-m-d H:i:s", $data->booking_flight_datetime_outbound), + '#date_format' => 'd/m/Y H:i', + '#date_year_range' => '0:0', + '#states' => array( + 'visible' => array( + ':input[name="booking_transport_type"]' => array( + 'value' => 'Flying' + ) + ) + ) + ); + + $form['travel']['booking_transport_from_morriset_reqd'] = array( + '#type' => 'radios', + '#title' => t('Will you be catching the train to Study Week?'), + '#options' => array( + 'Yes' => 'Yes I will be catching the train', + 'No' => 'No - I have arranged my own Transport' + ), + '#default_value' => (!isset($data->booking_transport_from_morriset_reqd)) ? 'No' : ($data->booking_transport_from_morriset_reqd == 1 ? 'Yes' : 'No'), + '#states' => array( + 'visible' => array( + ':input[name="booking_transport_type"]' => array( + 'value' => 'Flying' + ) + ) + ) + ); + + $form['accommodation'] = array( + '#type' => 'fieldset', + '#title' => 'Accommodation Details' + ); + $form['accommodation']['booking_accom_before_reqd'] = array( + '#type' => 'radios', + '#title' => t('Do you need us to organise accommodation before Study Week?'), + '#options' => array( + 'Yes' => 'Yes', + 'No' => "No - I have arranged my own accommodation or I'm not arriving early" + ), + '#default_value' => (!isset($data->booking_accom_before_reqd)) ? 'No' : ($data->booking_accom_before_reqd == 1 ? 'Yes' : 'No') + ); + /* + $form['accommodation']['booking_accom_before_staying_with'] = array( + '#type' => 'textfield', + '#title' => t('Who are you staying with in Sydney before Study Week?'), + '#maxlength' => 100, + '#default_value' => empty($data->booking_accom_before_staying_with) ? '' : $data->booking_accom_before_staying_with, + '#states' => array( + 'visible' => array( + ':input[name="booking_accom_before_reqd"]' => array('value' => 'No'), + ), + ), + ); + */ + $form['accommodation']['booking_accom_after_reqd'] = array( + '#type' => 'radios', + '#title' => t('Do you need us to organise accommodation after Study Week?'), + '#options' => array( + 'Yes' => 'Yes', + 'No' => "No - I have arranged my own accommodation or I'm not staying in Sydney afterwards" + ), + '#default_value' => (!isset($data->booking_accom_after_reqd)) ? 'No' : ($data->booking_accom_after_reqd == 1 ? 'Yes' : 'No') + ); + /* + $form['accommodation']['booking_accom_after_staying_with'] = array( + '#type' => 'textfield', + '#title' => t('Who are you staying with in Sydney after Study Week?'), + '#maxlength' => 100, + '#default_value' => empty($data->booking_accom_after_staying_with) ? '' : $data->booking_accom_after_staying_with, + '#states' => array( + 'visible' => array( + ':input[name="booking_accom_after_reqd"]' => array('value' => 'No'), + ), + ), + ); + */ + $form['requirements'] = array( + '#type' => 'fieldset', + '#title' => 'Special Requirements' + ); + //only show the dietary field if we're allowed to + if (variable_get('booking_enable_dietary', 0) == 1 || $inserting == FALSE) { + $form['requirements']['booking_dietary'] = array( + '#type' => 'textfield', + '#title' => t('Special dietary requirements?'), + '#maxlength' => 180, + '#default_value' => !empty($data->booking_dietary) ? $data->booking_dietary : $booking_dietary + ); + } + $form['requirements']['booking_medical_conditions'] = array( + '#type' => 'textfield', + '#title' => t('Please describe any medical condition we need to know about.'), + '#maxlength' => 180, + '#required' => FALSE, + '#default_value' => !empty($data->booking_medical_conditions) ? $data->booking_medical_conditions : $booking_medical_conditions + ); + //only show the room mate field if we're allowed to + if (variable_get('booking_enable_roommate', 0) == 1 || $inserting == FALSE) { + //married people won't need to select a room mate + if ((variable_get('booking_enable_combined_pricing', 0) == 1) && $person->booking_partner_id == 0) { + $form['requirements']['booking_room_mate1'] = array( + '#type' => 'textfield', + '#title' => t('I would like to share a room with'), + '#maxlength' => 200, + '#required' => FALSE, + '#default_value' => !empty($data->booking_room_mate1) ? $data->booking_room_mate1 : $booking_roommate + ); + } + } + //only show this field if this person isn't married + if (((variable_get('booking_enable_combined_pricing', 0) == 1) && $person->booking_partner_id == 0) || (variable_get('booking_enable_combined_pricing', 0) == 0)) { + $form['requirements']['booking_bf_gf_nid'] = array( + '#type' => 'textfield', + '#title' => t('Registration ID of Boyfriend/Girlfriend to be placed in the same discussion groups as you.'), + '#description' => t('If you\'re not sure what this number is, ask your Significant Other to look at the confirmation email they received when they registered.'), + '#maxlength' => 15, + '#size' => 4, + '#required' => FALSE, + '#default_value' => !empty($data->booking_bf_gf_nid) ? $data->booking_bf_gf_nid : $booking_bf_gf_nid + ); + } + + if ($inserting == TRUE) { + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + } + return $form; } -function travel_form_validate($form, &$form_state) { - //watchdog('booking', "
Travel form:\n@info
", array('@info' => print_r( $form_state, true))); - - //verify boyfriend/girlfriend id is in the correct format - if (isset($form_state['values']['booking_bf_gf_nid']) && $form_state['values']['booking_bf_gf_nid'] != '') - { - //make sure this is a node id not something else - if (! is_numeric($form_state['values']['booking_bf_gf_nid'] )) - { - form_set_error('booking_bf_gf_nid', - t('You have entered an invalid registration id for your boyfriend/girlfriend. ' . - 'Please ensure you are using only the registration reference number your boyfriend/girlfriend received via email. For example, your registration ID is !id. ' . - 'If you believe this to be incorrect, please !contact using the details provided.', - array('!id' => $form_state['values']['personid'], '!contact' => l('contact us', 'contact'))) - ); - watchdog('booking', "
Travel form non-numeric bf/gf\n@info
", array('@info' => print_r( $form_state['values'], true))); - } - //don't allow them to specify their own node id - elseif ($form_state['values']['personid'] == $form_state['values']['booking_bf_gf_nid']) - { - form_set_error('booking_bf_gf_nid', - t('You have entered your own registration id.' . - 'Please ensure you enter only the registration reference number your boyfriend/girlfriend received via email when registering, not your own registration id.') - ); - watchdog('booking', "
Travel form bf/gf same as person id\n@info
", array('@info' => print_r( $form_state['values'], true))); - } - else - { - //check that the partner exists - $partner = db_query("SELECT person.nid " . - "FROM {booking_person} person " . - "WHERE nid = :nid", - array(':nid' => $form_state['values']['booking_bf_gf_nid'])) - ->fetchObject(); - if (! $partner) - { - form_set_error('booking_bf_gf_nid', - t('We cannot find a matching registration id for your boyfriend/girlfriend. ' . - 'Please ensure you are using only the number that relates to their registration. For example, your registration ID is !id. ' . - 'If you believe this to be incorrect, please !contact using the details provided.', - array('!id' => $form_state['values']['personid'], '!contact' => l('contact us', 'contact'))) - ); - watchdog('booking', "
Travel form unknown bf/gf id\n@info
", array('@info' => print_r( $form_state['values'], true))); - } //end missing partner handling - } //end bf/gf validation - } //end bf/gf checking - - //check to make sure flight info is entered if it is selected - if (isset($form_state['values']['booking_transport_type']) && $form_state['values']['booking_transport_type'] == 'Flying') - { - - if ( (! isset($form_state['values']['booking_flightnum_inbound'])) || ($form_state['values']['booking_flightnum_inbound'] == '') ) - { - form_set_error('booking_flightnum_inbound', - t('Please enter the flight number associated with your arrival flight.') - ); - watchdog('booking', "
Travel form missing flight number for arrival flight\n@info
", - array('@info' => print_r( $form_state['values'], true))); - } - - if ( - $form_state['values']['booking_flight_datetime_inbound']['day'] == '' || - $form_state['values']['booking_flight_datetime_inbound']['month'] == '' || - $form_state['values']['booking_flight_datetime_inbound']['year'] == '' || - $form_state['values']['booking_flight_datetime_inbound']['hour'] == '' || - $form_state['values']['booking_flight_datetime_inbound']['minute'] == '' - ) - { - form_set_error('booking_flight_datetime_inbound', - t('Please enter the arrival time associated with your flight.') - ); - watchdog('booking', "
Travel form missing flight arrival time\n@info
", array('@info' => print_r( $form_state['values'], true))); - } - - if ( (! isset($form_state['values']['booking_flightnum_outbound'])) || ($form_state['values']['booking_flightnum_outbound'] == '') ) - { - form_set_error('booking_flightnum_outbound', - t('Please enter the flight number associated with your departing flight.') - ); - watchdog('booking', "
Travel form missing flight number for departing flight\n@info
", - array('@info' => print_r( $form_state['values'], true))); - } - - if ( - $form_state['values']['booking_flight_datetime_outbound']['day'] == '' || - $form_state['values']['booking_flight_datetime_outbound']['month'] == '' || - $form_state['values']['booking_flight_datetime_outbound']['year'] == '' || - $form_state['values']['booking_flight_datetime_outbound']['hour'] == '' || - $form_state['values']['booking_flight_datetime_outbound']['minute'] == '' - ) - { - form_set_error('booking_flight_datetime_outbound', - t('Please enter the departure time associated with your flight.') - ); - watchdog('booking', "
Travel form missing flight departure time\n@info
", array('@info' => print_r( $form_state['values'], true))); - } - - //check for arrival time after departure time - if (_datetime_to_ts($form_state['values']['booking_flight_datetime_inbound']) > _datetime_to_ts($form_state['values']['booking_flight_datetime_outbound'])) - { - form_set_error('booking_flight_datetime_inbound', - t('You have entered an arrival flight time that is after your departure flight time.') - ); - watchdog('booking', "
Travel form seems to have arrival flight after departure flight\n@info
", array('@info' => print_r( $form_state['values'], true))); - } - - } //end check for flying - +function travel_form_validate($form, &$form_state) +{ + //watchdog('booking', "
Travel form:\n@info
", array('@info' => print_r( $form_state, true))); + + //verify boyfriend/girlfriend id is in the correct format + if (isset($form_state['values']['booking_bf_gf_nid']) && $form_state['values']['booking_bf_gf_nid'] != '') { + //make sure this is a node id not something else + if (!is_numeric($form_state['values']['booking_bf_gf_nid'])) { + form_set_error('booking_bf_gf_nid', t('You have entered an invalid registration id for your boyfriend/girlfriend. ' . 'Please ensure you are using only the registration reference number your boyfriend/girlfriend received via email. For example, your registration ID is !id. ' . 'If you believe this to be incorrect, please !contact using the details provided.', array( + '!id' => $form_state['values']['personid'], + '!contact' => l('contact us', 'contact') + ))); + watchdog('booking', "
Travel form non-numeric bf/gf\n@info
", array( + '@info' => print_r($form_state['values'], true) + )); + } + //don't allow them to specify their own node id + elseif ($form_state['values']['personid'] == $form_state['values']['booking_bf_gf_nid']) { + form_set_error('booking_bf_gf_nid', t('You have entered your own registration id.' . 'Please ensure you enter only the registration reference number your boyfriend/girlfriend received via email when registering, not your own registration id.')); + watchdog('booking', "
Travel form bf/gf same as person id\n@info
", array( + '@info' => print_r($form_state['values'], true) + )); + } else { + //check that the partner exists + $partner = db_query("SELECT person.nid " . "FROM {booking_person} person " . "WHERE nid = :nid", array( + ':nid' => $form_state['values']['booking_bf_gf_nid'] + ))->fetchObject(); + if (!$partner) { + form_set_error('booking_bf_gf_nid', t('We cannot find a matching registration id for your boyfriend/girlfriend. ' . 'Please ensure you are using only the number that relates to their registration. For example, your registration ID is !id. ' . 'If you believe this to be incorrect, please !contact using the details provided.', array( + '!id' => $form_state['values']['personid'], + '!contact' => l('contact us', 'contact') + ))); + watchdog('booking', "
Travel form unknown bf/gf id\n@info
", array( + '@info' => print_r($form_state['values'], true) + )); + } //end missing partner handling + } //end bf/gf validation + } //end bf/gf checking + + //check to make sure flight info is entered if it is selected + if (isset($form_state['values']['booking_transport_type']) && $form_state['values']['booking_transport_type'] == 'Flying') { + + if ((!isset($form_state['values']['booking_flightnum_inbound'])) || ($form_state['values']['booking_flightnum_inbound'] == '')) { + form_set_error('booking_flightnum_inbound', t('Please enter the flight number associated with your arrival flight.')); + watchdog('booking', "
Travel form missing flight number for arrival flight\n@info
", array( + '@info' => print_r($form_state['values'], true) + )); + } + + if ($form_state['values']['booking_flight_datetime_inbound']['day'] == '' || $form_state['values']['booking_flight_datetime_inbound']['month'] == '' || $form_state['values']['booking_flight_datetime_inbound']['year'] == '' || $form_state['values']['booking_flight_datetime_inbound']['hour'] == '' || $form_state['values']['booking_flight_datetime_inbound']['minute'] == '') { + form_set_error('booking_flight_datetime_inbound', t('Please enter the arrival time associated with your flight.')); + watchdog('booking', "
Travel form missing flight arrival time\n@info
", array( + '@info' => print_r($form_state['values'], true) + )); + } + + if ((!isset($form_state['values']['booking_flightnum_outbound'])) || ($form_state['values']['booking_flightnum_outbound'] == '')) { + form_set_error('booking_flightnum_outbound', t('Please enter the flight number associated with your departing flight.')); + watchdog('booking', "
Travel form missing flight number for departing flight\n@info
", array( + '@info' => print_r($form_state['values'], true) + )); + } + + if ($form_state['values']['booking_flight_datetime_outbound']['day'] == '' || $form_state['values']['booking_flight_datetime_outbound']['month'] == '' || $form_state['values']['booking_flight_datetime_outbound']['year'] == '' || $form_state['values']['booking_flight_datetime_outbound']['hour'] == '' || $form_state['values']['booking_flight_datetime_outbound']['minute'] == '') { + form_set_error('booking_flight_datetime_outbound', t('Please enter the departure time associated with your flight.')); + watchdog('booking', "
Travel form missing flight departure time\n@info
", array( + '@info' => print_r($form_state['values'], true) + )); + } + + //check for arrival time after departure time + if (_datetime_to_ts($form_state['values']['booking_flight_datetime_inbound']) > _datetime_to_ts($form_state['values']['booking_flight_datetime_outbound'])) { + form_set_error('booking_flight_datetime_inbound', t('You have entered an arrival flight time that is after your departure flight time.')); + watchdog('booking', "
Travel form seems to have arrival flight after departure flight\n@info
", array( + '@info' => print_r($form_state['values'], true) + )); + } + + } //end check for flying + } -function travel_form_submit($form, &$form_state) { - global $event; - $values = $form_state['input']; - - //watchdog('booking', 'Submitting travel form: @info', array('@info' => var_export($values, TRUE))); - - //check that $values['personid'] is a number - if (! preg_match('/^[0-9]+$/', $values['personid'])) { - //parameter from url is not what we were expecting - drupal_set_message("Error: Invalid form data supplied. Please use the contact us form to let us know.", 'error', FALSE); - return ""; - } - - //fetch details about the person - $person = db_query("SELECT nid as personid, booking_tempid, booking_firstname, booking_lastname, booking_partner_id, booking_dietary, booking_room_mate1 " . - "FROM {booking_person} " . - "WHERE nid = :nid ", - array(':nid' => $values['personid'])) - ->fetchObject(); - - //create the new node structure - $node = new stdClass(); - $node = node_type_set_defaults(); - $node->title = t('!event travel form: !name', - array('!event' => $event->booking_eventname, '!name' => $person->booking_firstname . ' ' . $person->booking_lastname)); - $node->type = 'travel'; - $node->status = 1; // Published? - $node->promote = 0; // Display on front page? - $node->language = LANGUAGE_NONE; - $node->created = time(); - $node->changed = time(); - //populate the data - $node->booking_person_nid = $values['personid']; - $node->booking_transport_type = $values['booking_transport_type']; - $node->booking_transport_from_morriset_reqd = $values['booking_transport_from_morriset_reqd'] == 'Yes' ? 1 : 0; - //$node->booking_transport_to_morriset_reqd = $values['booking_transport_to_morriset_reqd'] == 'Yes' ? 1 : 0; - $node->booking_flightnum_inbound = $values['booking_flightnum_inbound']; - //todo: ternary operator to handle 0 as the date time - $node->booking_flight_datetime_inbound = _datetime_array_to_ts($values['booking_flight_datetime_inbound']); - $node->booking_flightnum_outbound = $values['booking_flightnum_outbound']; - $node->booking_flight_datetime_outbound = _datetime_array_to_ts($values['booking_flight_datetime_outbound']); - $node->booking_accom_before_reqd = $values['booking_accom_before_reqd'] == 'Yes' ? 1 : 0; - //$node->booking_accom_before_staying_with = $values['booking_accom_before_staying_with']; - $node->booking_accom_after_reqd = $values['booking_accom_after_reqd'] == 'Yes' ? 1 : 0; - //$node->booking_accom_after_staying_with = $values['booking_accom_after_staying_with']; - - //booking_person related fields - $node->booking_medical_conditions = $values['booking_medical_conditions']; - $node->booking_bf_gf_nid = empty($values['booking_bf_gf_nid']) ? 0 : $values['booking_bf_gf_nid']; - - //optional fields - $node->booking_dietary = variable_get('booking_enable_dietary', 0) == 1 ? $values['booking_dietary'] : $person->booking_dietary; - //room mate field might be enabled but not displayed for a married couple so calculate whether the field is empty or not first - $room_mate = empty($values['booking_room_mate1']) ? $person->booking_room_mate1 : $values['booking_room_mate1']; - $node->booking_room_mate1 = variable_get('booking_enable_roommate', 0) == 1 ? $room_mate : $person->booking_room_mate1; - - //watchdog('booking', "
Travel data to save:\n@info
", array('@info' => print_r( $node, true))); - - //store the node - $foo = node_submit($node); - $blah = node_save($foo); - - //send a confirmation email - _booking_travelform_confirmation_email($values['personid']); - - drupal_set_message("Thanks for submitting your travel details. You should receive a confirmation email shortly.", $type = 'status'); - $form_state['redirect'] = array('content/travel'); - +function travel_form_submit($form, &$form_state) +{ + global $event; + $values = $form_state['input']; + + //watchdog('booking', 'Submitting travel form: @info', array('@info' => var_export($values, TRUE))); + + //check that $values['personid'] is a number + if (!preg_match('/^[0-9]+$/', $values['personid'])) { + //parameter from url is not what we were expecting + drupal_set_message("Error: Invalid form data supplied. Please use the contact us form to let us know.", 'error', FALSE); + return ""; + } + + //fetch details about the person + $person = db_query("SELECT nid as personid, booking_tempid, booking_firstname, booking_lastname, booking_partner_id, booking_dietary, booking_room_mate1 " . "FROM {booking_person} " . "WHERE nid = :nid ", array( + ':nid' => $values['personid'] + ))->fetchObject(); + + //create the new node structure + $node = new stdClass(); + $node = node_type_set_defaults(); + $node->title = t('!event travel form: !name', array( + '!event' => $event->booking_eventname, + '!name' => $person->booking_firstname . ' ' . $person->booking_lastname + )); + $node->type = 'travel'; + $node->status = 1; // Published? + $node->promote = 0; // Display on front page? + $node->language = LANGUAGE_NONE; + $node->created = time(); + $node->changed = time(); + //populate the data + $node->booking_person_nid = $values['personid']; + $node->booking_transport_type = $values['booking_transport_type']; + $node->booking_transport_from_morriset_reqd = $values['booking_transport_from_morriset_reqd'] == 'Yes' ? 1 : 0; + //$node->booking_transport_to_morriset_reqd = $values['booking_transport_to_morriset_reqd'] == 'Yes' ? 1 : 0; + $node->booking_flightnum_inbound = $values['booking_flightnum_inbound']; + //todo: ternary operator to handle 0 as the date time + $node->booking_flight_datetime_inbound = _datetime_array_to_ts($values['booking_flight_datetime_inbound']); + $node->booking_flightnum_outbound = $values['booking_flightnum_outbound']; + $node->booking_flight_datetime_outbound = _datetime_array_to_ts($values['booking_flight_datetime_outbound']); + $node->booking_accom_before_reqd = $values['booking_accom_before_reqd'] == 'Yes' ? 1 : 0; + //$node->booking_accom_before_staying_with = $values['booking_accom_before_staying_with']; + $node->booking_accom_after_reqd = $values['booking_accom_after_reqd'] == 'Yes' ? 1 : 0; + //$node->booking_accom_after_staying_with = $values['booking_accom_after_staying_with']; + + //booking_person related fields + $node->booking_medical_conditions = $values['booking_medical_conditions']; + $node->booking_bf_gf_nid = empty($values['booking_bf_gf_nid']) ? 0 : $values['booking_bf_gf_nid']; + + //optional fields + $node->booking_dietary = variable_get('booking_enable_dietary', 0) == 1 ? $values['booking_dietary'] : $person->booking_dietary; + //room mate field might be enabled but not displayed for a married couple so calculate whether the field is empty or not first + $room_mate = empty($values['booking_room_mate1']) ? $person->booking_room_mate1 : $values['booking_room_mate1']; + $node->booking_room_mate1 = variable_get('booking_enable_roommate', 0) == 1 ? $room_mate : $person->booking_room_mate1; + + //watchdog('booking', "
Travel data to save:\n@info
", array('@info' => print_r( $node, true))); + + //store the node + $foo = node_submit($node); + $blah = node_save($foo); + + //send a confirmation email + _booking_travelform_confirmation_email($values['personid']); + + drupal_set_message("Thanks for submitting your travel details. You should receive a confirmation email shortly.", $type = 'status'); + $form_state['redirect'] = array( + 'content/travel' + ); + } -function travel_load($nodes) { - //watchdog('booking', 'Loading node with params: @info', array('@info' => var_export($nodes, TRUE))); - +function travel_load($nodes) +{ + //watchdog('booking', 'Loading node with params: @info', array('@info' => var_export($nodes, TRUE))); + // note that $nodes is an array of object references, keyed by nid // grab the data from our module tables - - $query = db_select('booking_travel', 't'); - $query->distinct(); - $query->join('booking_person','p','p.nid = t.booking_person_nid'); - $query->fields('t'); - $query->fields('p', array('booking_dietary','booking_medical_conditions','booking_bf_gf_nid', 'booking_room_mate1')); - $query->condition('tid', array_keys($nodes), 'IN'); - $result = $query->execute(); - - //add that data to the array of node references - foreach ($result as $record) - { - //watchdog('booking', 'This node looks like: @info', array('@info' => var_export($record, TRUE))); - // run through each result row and add in the needed attributes - foreach ($record as $key => $value) - { - $nodes[$record->tid]->$key = $value; - } - } - - //watchdog('booking', 'Final loaded travel form node: @info', array('@info' => var_export($nodes, TRUE))); + + $query = db_select('booking_travel', 't'); + $query->distinct(); + $query->join('booking_person', 'p', 'p.nid = t.booking_person_nid'); + $query->fields('t'); + $query->fields('p', array( + 'booking_dietary', + 'booking_medical_conditions', + 'booking_bf_gf_nid', + 'booking_room_mate1' + )); + $query->condition('tid', array_keys($nodes), 'IN'); + $result = $query->execute(); + + //add that data to the array of node references + foreach ($result as $record) { + //watchdog('booking', 'This node looks like: @info', array('@info' => var_export($record, TRUE))); + // run through each result row and add in the needed attributes + foreach ($record as $key => $value) { + $nodes[$record->tid]->$key = $value; + } + } + + //watchdog('booking', 'Final loaded travel form node: @info', array('@info' => var_export($nodes, TRUE))); // no return necessary since $nodes array members reference objects global to this function } -function travel_insert($node) +function travel_insert($node) { - //watchdog('booking', 'Inserting travel form: @info', array('@info' => var_export($node, TRUE))); - - db_insert('booking_travel') - ->fields(array( - 'tid' => $node->nid, - 'booking_person_nid' => $node->booking_person_nid, - 'booking_transport_type' => $node->booking_transport_type, - 'booking_transport_from_morriset_reqd' => $node->booking_transport_from_morriset_reqd, - //'booking_transport_to_morriset_reqd' => $node->booking_transport_to_morriset_reqd, - 'booking_flightnum_inbound' => $node->booking_flightnum_inbound, - 'booking_flight_datetime_inbound' => $node->booking_flight_datetime_inbound, - 'booking_flightnum_outbound' => $node->booking_flightnum_outbound, - 'booking_flight_datetime_outbound' => $node->booking_flight_datetime_outbound, - 'booking_accom_before_reqd' => $node->booking_accom_before_reqd, - //'booking_accom_before_staying_with' => $node->booking_accom_before_staying_with, - 'booking_accom_after_reqd' => $node->booking_accom_after_reqd, - //'booking_accom_after_staying_with' => $node->booking_accom_after_staying_with, - )) - ->execute(); - - //update the booking_person fields - db_update('booking_person') - ->fields(array( - 'booking_dietary' => $node->booking_dietary, - 'booking_medical_conditions' => $node->booking_medical_conditions, - 'booking_bf_gf_nid' => $node->booking_bf_gf_nid, - 'booking_room_mate1' => $node->booking_room_mate1, - )) - ->condition('nid', $node->booking_person_nid) - ->execute(); - - //set the boyfriend/girlfriend to point to this person - if ($node->booking_bf_gf_nid <> 0) - { - db_update('booking_person') - ->fields(array( - 'booking_bf_gf_nid' => $node->booking_person_nid, - )) - ->condition('nid', $node->booking_bf_gf_nid) - ->execute(); - } + //watchdog('booking', 'Inserting travel form: @info', array('@info' => var_export($node, TRUE))); + + db_insert('booking_travel')->fields(array( + 'tid' => $node->nid, + 'booking_person_nid' => $node->booking_person_nid, + 'booking_transport_type' => $node->booking_transport_type, + 'booking_transport_from_morriset_reqd' => $node->booking_transport_from_morriset_reqd, + //'booking_transport_to_morriset_reqd' => $node->booking_transport_to_morriset_reqd, + 'booking_flightnum_inbound' => $node->booking_flightnum_inbound, + 'booking_flight_datetime_inbound' => $node->booking_flight_datetime_inbound, + 'booking_flightnum_outbound' => $node->booking_flightnum_outbound, + 'booking_flight_datetime_outbound' => $node->booking_flight_datetime_outbound, + 'booking_accom_before_reqd' => $node->booking_accom_before_reqd, + //'booking_accom_before_staying_with' => $node->booking_accom_before_staying_with, + 'booking_accom_after_reqd' => $node->booking_accom_after_reqd + //'booking_accom_after_staying_with' => $node->booking_accom_after_staying_with, + ))->execute(); + + //update the booking_person fields + db_update('booking_person')->fields(array( + 'booking_dietary' => $node->booking_dietary, + 'booking_medical_conditions' => $node->booking_medical_conditions, + 'booking_bf_gf_nid' => $node->booking_bf_gf_nid, + 'booking_room_mate1' => $node->booking_room_mate1 + ))->condition('nid', $node->booking_person_nid)->execute(); + + //set the boyfriend/girlfriend to point to this person + if ($node->booking_bf_gf_nid <> 0) { + db_update('booking_person')->fields(array( + 'booking_bf_gf_nid' => $node->booking_person_nid + ))->condition('nid', $node->booking_bf_gf_nid)->execute(); + } } function travel_update($node) { - watchdog('booking', 'Updating travel form booking_travel table: @info', array('@info' => var_export($node, TRUE))); - db_update('booking_travel') - ->fields(array( - 'tid' => $node->nid, - 'booking_person_nid' => $node->booking_person_nid, - 'booking_transport_type' => $node->booking_transport_type, - 'booking_transport_from_morriset_reqd' => $node->booking_transport_from_morriset_reqd == 'Yes' ? 1 : 0, - //'booking_transport_to_morriset_reqd' => $node->booking_transport_to_morriset_reqd, - 'booking_flightnum_inbound' => $node->booking_flightnum_inbound, - 'booking_flight_datetime_inbound' => _datetime_to_ts($node->booking_flight_datetime_inbound), - 'booking_flightnum_outbound' => $node->booking_flightnum_outbound, - 'booking_flight_datetime_outbound' => _datetime_to_ts($node->booking_flight_datetime_outbound), - 'booking_accom_before_reqd' => $node->booking_accom_before_reqd == 'Yes' ? 1 : 0, - //'booking_accom_before_staying_with' => $node->booking_accom_before_staying_with, - 'booking_accom_after_reqd' => $node->booking_accom_after_reqd == 'Yes' ? 1 : 0, - //'booking_accom_after_staying_with' => $node->booking_accom_after_staying_with, - )) - ->condition('tid', $node->nid) - ->execute(); - - watchdog('booking', 'Updating travel form booking_person table'); - - //update the booking_person fields - db_update('booking_person') - ->fields(array( - 'booking_dietary' => $node->booking_dietary, - 'booking_medical_conditions' => $node->booking_medical_conditions, - 'booking_bf_gf_nid' => $node->booking_bf_gf_nid == '' ? 0 : $node->booking_bf_gf_nid, - 'booking_room_mate1' => $node->booking_room_mate1, - )) - ->condition('nid', $node->booking_person_nid) - ->execute(); - - //set the boyfriend/girlfriend to point to this person - if ($node->booking_bf_gf_nid <> 0) - { - db_update('booking_person') - ->fields(array( - 'booking_bf_gf_nid' => $node->booking_person_nid, - )) - ->condition('nid', $node->booking_bf_gf_nid) - ->execute(); - } + watchdog('booking', 'Updating travel form booking_travel table: @info', array( + '@info' => var_export($node, TRUE) + )); + db_update('booking_travel')->fields(array( + 'tid' => $node->nid, + 'booking_person_nid' => $node->booking_person_nid, + 'booking_transport_type' => $node->booking_transport_type, + 'booking_transport_from_morriset_reqd' => $node->booking_transport_from_morriset_reqd == 'Yes' ? 1 : 0, + //'booking_transport_to_morriset_reqd' => $node->booking_transport_to_morriset_reqd, + 'booking_flightnum_inbound' => $node->booking_flightnum_inbound, + 'booking_flight_datetime_inbound' => _datetime_to_ts($node->booking_flight_datetime_inbound), + 'booking_flightnum_outbound' => $node->booking_flightnum_outbound, + 'booking_flight_datetime_outbound' => _datetime_to_ts($node->booking_flight_datetime_outbound), + 'booking_accom_before_reqd' => $node->booking_accom_before_reqd == 'Yes' ? 1 : 0, + //'booking_accom_before_staying_with' => $node->booking_accom_before_staying_with, + 'booking_accom_after_reqd' => $node->booking_accom_after_reqd == 'Yes' ? 1 : 0 + //'booking_accom_after_staying_with' => $node->booking_accom_after_staying_with, + ))->condition('tid', $node->nid)->execute(); + + watchdog('booking', 'Updating travel form booking_person table'); + + //update the booking_person fields + db_update('booking_person')->fields(array( + 'booking_dietary' => $node->booking_dietary, + 'booking_medical_conditions' => $node->booking_medical_conditions, + 'booking_bf_gf_nid' => $node->booking_bf_gf_nid == '' ? 0 : $node->booking_bf_gf_nid, + 'booking_room_mate1' => $node->booking_room_mate1 + ))->condition('nid', $node->booking_person_nid)->execute(); + + //set the boyfriend/girlfriend to point to this person + if ($node->booking_bf_gf_nid <> 0) { + db_update('booking_person')->fields(array( + 'booking_bf_gf_nid' => $node->booking_person_nid + ))->condition('nid', $node->booking_bf_gf_nid)->execute(); + } } -function travel_delete($node) +function travel_delete($node) { - $person_id = $node->booking_person_nid; - $num_deleted = db_delete('booking_travel') - ->condition('tid', $node->nid) - ->execute(); - $message = t("Successfully deleted !num row(s) from the booking_travel table, corresponding to person ID !id", - array('!num' => $num_deleted, '!id' => $person_id)); - drupal_set_message($message, $type = 'status'); + $person_id = $node->booking_person_nid; + $num_deleted = db_delete('booking_travel')->condition('tid', $node->nid)->execute(); + $message = t("Successfully deleted !num row(s) from the booking_travel table, corresponding to person ID !id", array( + '!num' => $num_deleted, + '!id' => $person_id + )); + drupal_set_message($message, $type = 'status'); } -function travel_view($node, $view_mode) { - global $event; - - //fetch details about the person - $person = db_query("SELECT p.*, t.* from {booking_person} p " . - "left outer join {booking_travel} t on p.nid = t.booking_person_nid " . - "where p.nid = :nid", - array(':nid' => $node->booking_person_nid)) - ->fetchObject(); - //and their boyfriend/girlfriend if it is defined - if ($person->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 - $bf_gf = "N/A"; - - - $header = array('Attribute', 'Value'); - $rows = array(); - - $rows[] = array(t('Name:'), l(t('!first !last', array('!first' => $person->booking_firstname, '!last' => $person->booking_lastname)), - t('node/!id', array('!id' => $node->booking_person_nid))),); - $rows[] = array(t('Transport Type:'), $node->booking_transport_type); - $rows[] = array(t('Catching the train to Study Week:'), $node->booking_transport_from_morriset_reqd == 1 ? 'Yes' : 'No'); - $rows[] = array(t('Inbound Flight Number:'), $node->booking_flightnum_inbound); - $rows[] = array(t('Flight Arrival:'), t('!date', array('!date' => format_date($node->booking_flight_datetime_inbound, 'custom', 'd/m/Y H:i')))); - $rows[] = array(t('Outbound Flight Number:'), $node->booking_flightnum_outbound); - $rows[] = array(t('Flight Departure:'), t('!date', array('!date' => format_date($node->booking_flight_datetime_outbound, 'custom', 'd/m/Y H:i')))); - $rows[] = array(t('Accommodation before Study Week Required:'), $node->booking_accom_before_reqd == 1 ? 'Yes' : 'No'); - $rows[] = array(t('Accommodation after Study Week Required:'), $node->booking_accom_after_reqd == 1 ? 'Yes' : 'No'); - //fields from booking_person - $rows[] = array(t('Special Dietary Requirements:'), $node->booking_dietary); - $rows[] = array(t('Special Medical Conditions:'), $node->booking_medical_conditions); - $rows[] = array(t('Boyfriend/Girlfriend:'), $bf_gf); - $rows[] = array(t('Requested Room mate(s):'), $node->booking_room_mate1); - $node->content['details'] = array( - '#markup' => theme('table', array('header' => $header, 'rows' => $rows)), - '#weight' => 1, - ); - return $node; -} +function travel_view($node, $view_mode) +{ + global $event; + + //fetch details about the person + $person = db_query("SELECT p.*, t.* from {booking_person} p " . "left outer join {booking_travel} t on p.nid = t.booking_person_nid " . "where p.nid = :nid", array( + ':nid' => $node->booking_person_nid + ))->fetchObject(); + //and their boyfriend/girlfriend if it is defined + if ($person->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 + $bf_gf = "N/A"; + + + $header = array( + 'Attribute', + 'Value' + ); + $rows = array(); + + $rows[] = array( + t('Name:'), + l(t('!first !last', array( + '!first' => $person->booking_firstname, + '!last' => $person->booking_lastname + )), t('node/!id', array( + '!id' => $node->booking_person_nid + ))) + ); + $rows[] = array( + t('Transport Type:'), + $node->booking_transport_type + ); + $rows[] = array( + t('Catching the train to Study Week:'), + $node->booking_transport_from_morriset_reqd == 1 ? 'Yes' : 'No' + ); + $rows[] = array( + t('Inbound Flight Number:'), + $node->booking_flightnum_inbound + ); + $rows[] = array( + t('Flight Arrival:'), + t('!date', array( + '!date' => format_date($node->booking_flight_datetime_inbound, 'custom', 'd/m/Y H:i') + )) + ); + $rows[] = array( + t('Outbound Flight Number:'), + $node->booking_flightnum_outbound + ); + $rows[] = array( + t('Flight Departure:'), + t('!date', array( + '!date' => format_date($node->booking_flight_datetime_outbound, 'custom', 'd/m/Y H:i') + )) + ); + $rows[] = array( + t('Accommodation before Study Week Required:'), + $node->booking_accom_before_reqd == 1 ? 'Yes' : 'No' + ); + $rows[] = array( + t('Accommodation after Study Week Required:'), + $node->booking_accom_after_reqd == 1 ? 'Yes' : 'No' + ); + //fields from booking_person + $rows[] = array( + t('Special Dietary Requirements:'), + $node->booking_dietary + ); + $rows[] = array( + t('Special Medical Conditions:'), + $node->booking_medical_conditions + ); + $rows[] = array( + t('Boyfriend/Girlfriend:'), + $bf_gf + ); + $rows[] = array( + t('Requested Room mate(s):'), + $node->booking_room_mate1 + ); + $node->content['details'] = array( + '#markup' => theme('table', array( + 'header' => $header, + 'rows' => $rows + )), + '#weight' => 1 + ); + return $node; +} \ No newline at end of file