Files
booking/booking.travel.inc
Nathan Coad 3a25d690f4 more debug
2018-01-14 11:43:58 +11:00

752 lines
31 KiB
PHP

<?php
/**
* 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 "";
}
//verify that this feature is enabled
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)) {
$inputtext = variable_get('booking_travelform_completed_page');
//$output = token_replace(variable_get('booking_travelform_completed_page'), $tokens);
$return_array[] = array(
'paragraph' => array(
'#type' => 'markup',
'#markup' => token_replace($inputtext['value'], $tokens),
)
);
}
//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) {
$inputtext = variable_get('booking_travelform_married_page');
//$output = token_replace(variable_get('booking_travelform_married_page'), $tokens);
} else {
$inputtext = variable_get('booking_travelform_page');
//$output = token_replace(variable_get('booking_travelform_page'), $tokens);
}
//text before form
$return_array[] = array(
'paragraph' => array(
'#type' => 'markup',
'#markup' => token_replace($inputtext['value'], $tokens),
)
);
//actual form
$return_array[] = array(
'form' => drupal_get_form('travel_form', $node, true, $tokens)
);
//text after form
/*
$afterform_text = variable_get('booking_travelform_page_post_text');
$return_array[] = array(
'paragraph' => array(
'#type' => 'markup',
'#markup' => token_replace($afterform_text['value'], $tokens),
)
);
*/
}
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, $node = NULL, $tokens = NULL)
function travel_form($node, &$form_state, $db_node = NULL, $inserting = FALSE, $tokens = NULL)
{
global $event;
date_default_timezone_set(date_default_timezone(FALSE));
$booking_dietary = '';
$booking_medical_conditions = '';
$booking_bf_gf_nid = '';
$booking_partner_id = '';
$booking_roommate = '';
$transport_type_options = array(
'Driving' => 'Driving',
//'Train' => 'Train',
'Flying' => 'Flying',
);
//there's already info in $node so use that
if (!empty($db_node)) {
$data = $db_node;
watchdog('booking_debug', "<pre>Travel form loaded from travel page:\n@info</pre>", array('@info' => print_r( $data, true)));
}
//otherwise rely on the form state from the previous submission
else {
$data = $form_state['node'];
watchdog('booking_debug', "<pre>Travel form loaded directly:\n@info</pre>", array('@info' => print_r( $data, true)));
}
//get info from the database if we don't have it
if (! isset($data->booking_partner_id)) {
watchdog('booking_debug', "<pre>Travel form querying database for missing details</pre>");
$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' => isset($data->booking_person_nid) ? $data->booking_person_nid : $data->nid))->fetchObject();
//check we got results
if ($person) {
watchdog('booking_debug', "<pre>Person info from database:\n@info</pre>", array('@info' => print_r( $person, true)));
$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_partner_id = $person->booking_partner_id == 0 ? '' : $person->booking_partner_id;
$booking_roommate = $person->booking_room_mate1;
}
else {
watchdog('booking_debug', "<pre>Failed to retrieve person from database using nid from data variable:\n@info</pre>", array('@info' => print_r( $data, true)));
}
}
else {
watchdog('booking_debug', "<pre>Travel form not querying database for missing details</pre>");
$booking_dietary = $data->booking_dietary;
$booking_medical_conditions = $data->booking_medical_conditions;
//an empty value is zero in this case
$booking_bf_gf_nid = $data->booking_bf_gf_nid == 0 ? '' : $data->booking_bf_gf_nid;
$booking_partner_id = $data->booking_partner_id == 0 ? '' : $data->booking_partner_id;
$booking_roommate = $data->booking_room_mate1;
}
//form starts here
//store the node id
$form['personid'] = array(
'#type' => 'hidden',
'#value' => $data->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'),
),
),
);
*/
//calculate which fields to show and whether we need to show the fieldset at all
$show_dietary = ((variable_get('booking_enable_dietary', 0) == 1) || ($inserting == FALSE));
$show_medical = ((variable_get('booking_enable_medcond', 0) == 1) || ($inserting == FALSE));
$show_roommate = (variable_get('booking_enable_roommate', 0) == 1 && $booking_partner_id == 0) || $inserting == FALSE;
$show_bf_gf = $booking_partner_id == 0 || $inserting == FALSE;
$show_special_requirements = ($show_dietary || $show_medical || $show_roommate || $show_bf_gf);
if ($show_special_requirements) {
$form['requirements'] = array(
'#type' => 'fieldset',
'#title' => 'Special Requirements'
);
}
//only show the dietary field if we're allowed to
if ($show_dietary) {
$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
);
}
//display the medical conditions question if it is enabled
if ($show_medical) {
$form['requirements']['booking_medical_conditions'] = array(
'#type' => 'textfield',
'#title' => t('Please describe any medical condition we need to know about.'),
'#description' => t('This field contains information you entered when you registered.'),
'#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 and the person isn't married
if ($show_roommate) {
$form['requirements']['booking_room_mate1'] = array(
'#type' => 'textfield',
'#title' => t('I would like to share a room with'),
'#description' => t('This field contains information you entered when you registered. Update if necessary.'),
'#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 ($show_bf_gf) {
$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) {
//add some html just before the submit button
$afterform_text = variable_get('booking_travelform_page_post_text');
$form['post-text'] = array(
'#type' => 'container',
'#children' => token_replace($afterform_text['value'], $tokens),
);
//include the submit button
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
);
}
return $form;
}
function travel_form_validate($form, &$form_state) {
//watchdog('booking_debug', "<pre>Travel form:\n@info</pre>", 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', "<pre>Travel form non-numeric bf/gf\n@info</pre>", 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', "<pre>Travel form bf/gf same as person id\n@info</pre>", 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', "<pre>Travel form unknown bf/gf id\n@info</pre>", 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', "<pre>Travel form missing flight number for arrival flight\n@info</pre>", array(
'@info' => print_r($form_state['values'], true)
));
}
if (!isset($form_state['values']['booking_flight_datetime_inbound'])) {
form_set_error('booking_flight_datetime_inbound', t('Please enter the arrival time associated with your flight.'));
watchdog('booking_debug', "<pre>Travel form missing flight arrival time\n@info</pre>", 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', "<pre>Travel form missing flight number for departing flight\n@info</pre>", array(
'@info' => print_r($form_state['values'], true)
));
}
if (!isset($form_state['values']['booking_flight_datetime_outbound'])) {
form_set_error('booking_flight_datetime_outbound', t('Please enter the departure time associated with your flight.'));
watchdog('booking', "<pre>Travel form missing flight departure time\n@info</pre>", 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', "<pre>Travel form seems to have arrival flight after departure flight\n@info</pre>", array(
'@info' => print_r($form_state['values'], true)
));
}
} //end check for flying
} //end validation
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, booking_medical_conditions " . "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_bf_gf_nid = empty($values['booking_bf_gf_nid']) ? 0 : $values['booking_bf_gf_nid'];
//optional fields
$node->booking_medical_conditions = variable_get('booking_enable_medcond', 0) == 1 ? $values['booking_medical_conditions'] : $person->booking_medical_conditions;
$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', "<pre>Travel data to save:\n@info</pre>", 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)));
// 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)));
// no return necessary since $nodes array members reference objects global to this function
}
function travel_insert($node)
{
watchdog('booking_debug', "<pre>Inserting travel form:\n@info</pre>", array('@info' => print_r($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();
}
}
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');
}
function travel_view($node, $view_mode)
{
global $event;
$header = array('Attribute', 'Value');
$rows = array();
//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 = l(t('!first !last', array('!first' => $query->booking_firstname, '!last' => $query->booking_lastname)),
t('node/!id', array('!id' => $person->booking_bf_gf_nid,
)));
}
else {
$bf_gf = "N/A";
}
$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' => $node->booking_flight_datetime_inbound == 0 ? '' : 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' => $node->booking_flight_datetime_outbound == 0 ? '' : 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;
}