Code formatting fix

This commit is contained in:
2016-05-25 11:20:35 +10:00
parent bd665d6110
commit e02d863833

View File

@@ -3,13 +3,14 @@
/** /**
* Travel form for attendee * Travel form for attendee
*/ */
function booking_travel_page() { function booking_travel_page()
{
global $event; global $event;
$output = ""; $output = "";
$return_array = array(); $return_array = array();
//verify that arg(1) is a uuid //verify that arg(1) is a uuid
if (! preg_match('/^[0-9A-Fa-f\-]+$/', arg(1))) { if (!preg_match('/^[0-9A-Fa-f\-]+$/', arg(1))) {
//parameter from url is not what we were expecting //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_set_message("Error: Invalid session ID supplied. Please use the contact us form to let us know.", 'error', FALSE);
drupal_goto('content/travel'); drupal_goto('content/travel');
@@ -25,14 +26,13 @@ function booking_travel_page() {
//work out the node id from the session id //work out the node id from the session id
$query = db_select('booking_person', 'p'); $query = db_select('booking_person', 'p');
$query->condition('p.booking_tempid', arg(1), '=') $query->condition('p.booking_tempid', arg(1), '=')->fields('p', array(
->fields('p', array('nid')); 'nid'
$person = $query->execute() ));
->fetchObject(); $person = $query->execute()->fetchObject();
//if we found a matching person //if we found a matching person
if ($person) if ($person) {
{
//load this person's data //load this person's data
$node = node_load($person->nid); $node = node_load($person->nid);
@@ -41,26 +41,33 @@ function booking_travel_page() {
//watchdog('booking', 'Checking for existing travel form for: @info', array('@info' => var_export($person, TRUE))); //watchdog('booking', 'Checking for existing travel form for: @info', array('@info' => var_export($person, TRUE)));
//check for an existing travel form //check for an existing travel form
if (! empty( $node->tid )) if (!empty($node->tid)) {
{
$output = token_replace(variable_get('booking_travelform_completed_page'), $tokens); $output = token_replace(variable_get('booking_travelform_completed_page'), $tokens);
$return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output)); $return_array[] = array(
'paragraph' => array(
'#type' => 'markup',
'#markup' => $output
)
);
} }
//they haven't submitted a travel form yet //they haven't submitted a travel form yet
else else {
{
//Output different text if this is for a married couple //Output different text if this is for a married couple
if ((variable_get('booking_enable_combined_pricing', 0) == 1) && $node->booking_partner_id > 0) if ((variable_get('booking_enable_combined_pricing', 0) == 1) && $node->booking_partner_id > 0) {
{
$output = token_replace(variable_get('booking_travelform_married_page'), $tokens); $output = token_replace(variable_get('booking_travelform_married_page'), $tokens);
} } else {
else
{
$output = token_replace(variable_get('booking_travelform_page'), $tokens); $output = token_replace(variable_get('booking_travelform_page'), $tokens);
} }
$return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output)); $return_array[] = array(
$return_array[] = array('form' => drupal_get_form('travel_form', true, $node->nid)); 'paragraph' => array(
'#type' => 'markup',
'#markup' => $output
)
);
$return_array[] = array(
'form' => drupal_get_form('travel_form', true, $node->nid)
);
} }
return $return_array; return $return_array;
@@ -89,25 +96,20 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
); );
//there's already info in $node so use that //there's already info in $node so use that
if (!empty($node)) if (!empty($node)) {
{
$data = $node; $data = $node;
} }
//otherwise rely on the form state from the previous submission //otherwise rely on the form state from the previous submission
else else {
{
$data = $form_state['input']; $data = $form_state['input'];
} }
//get info about this person from the relevant node id //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 " . $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(
"FROM {booking_person} " . ':nid' => $nid <> 0 ? $nid : $data->booking_person_nid
"WHERE nid = :nid ", ))->fetchObject();
array(':nid' => $nid <> 0 ? $nid : $data->booking_person_nid))
->fetchObject();
if ($person) if ($person) {
{
$booking_dietary = $person->booking_dietary; $booking_dietary = $person->booking_dietary;
$booking_medical_conditions = $person->booking_medical_conditions; $booking_medical_conditions = $person->booking_medical_conditions;
//an empty value is zero in this case //an empty value is zero in this case
@@ -119,19 +121,19 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
//store the node id //store the node id
$form['personid'] = array( $form['personid'] = array(
'#type' => 'hidden', '#type' => 'hidden',
'#value' => $nid, '#value' => $nid
); );
$form['travel'] = array( $form['travel'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => 'Travel details', '#title' => 'Travel details'
); );
$form['travel']['booking_transport_type'] = array( $form['travel']['booking_transport_type'] = array(
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Transport Type'), '#title' => t('Transport Type'),
'#options' => $transport_type_options, '#options' => $transport_type_options,
'#default_value' => !empty($data->booking_transport_type) ? $data->booking_transport_type : NULL, '#default_value' => !empty($data->booking_transport_type) ? $data->booking_transport_type : NULL,
'#required' => TRUE, '#required' => TRUE
); );
/* /*
@@ -155,9 +157,11 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
'#default_value' => empty($data->booking_flightnum_inbound) ? '' : $data->booking_flightnum_inbound, '#default_value' => empty($data->booking_flightnum_inbound) ? '' : $data->booking_flightnum_inbound,
'#states' => array( '#states' => array(
'visible' => array( 'visible' => array(
':input[name="booking_transport_type"]' => array('value' => 'Flying'), ':input[name="booking_transport_type"]' => array(
), 'value' => 'Flying'
), )
)
)
); );
$form['travel']['booking_flight_datetime_inbound'] = array( $form['travel']['booking_flight_datetime_inbound'] = array(
'#type' => 'date_select', '#type' => 'date_select',
@@ -168,9 +172,11 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
'#date_year_range' => '0:0', '#date_year_range' => '0:0',
'#states' => array( '#states' => array(
'visible' => array( 'visible' => array(
':input[name="booking_transport_type"]' => array('value' => 'Flying'), ':input[name="booking_transport_type"]' => array(
), 'value' => 'Flying'
), )
)
)
); );
$form['travel']['booking_flightnum_outbound'] = array( $form['travel']['booking_flightnum_outbound'] = array(
'#type' => 'textfield', '#type' => 'textfield',
@@ -179,9 +185,11 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
'#default_value' => empty($data->booking_flightnum_outbound) ? '' : $data->booking_flightnum_outbound, '#default_value' => empty($data->booking_flightnum_outbound) ? '' : $data->booking_flightnum_outbound,
'#states' => array( '#states' => array(
'visible' => array( 'visible' => array(
':input[name="booking_transport_type"]' => array('value' => 'Flying'), ':input[name="booking_transport_type"]' => array(
), 'value' => 'Flying'
), )
)
)
); );
$form['travel']['booking_flight_datetime_outbound'] = array( $form['travel']['booking_flight_datetime_outbound'] = array(
'#type' => 'date_select', '#type' => 'date_select',
@@ -192,32 +200,42 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
'#date_year_range' => '0:0', '#date_year_range' => '0:0',
'#states' => array( '#states' => array(
'visible' => array( 'visible' => array(
':input[name="booking_transport_type"]' => array('value' => 'Flying'), ':input[name="booking_transport_type"]' => array(
), 'value' => 'Flying'
), )
)
)
); );
$form['travel']['booking_transport_from_morriset_reqd'] = array( $form['travel']['booking_transport_from_morriset_reqd'] = array(
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Will you be catching the train to Study Week?'), '#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'), '#options' => array(
'#default_value' => (! isset($data->booking_transport_from_morriset_reqd)) ? 'No' : ($data->booking_transport_from_morriset_reqd == 1 ? 'Yes' : 'No'), '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( '#states' => array(
'visible' => array( 'visible' => array(
':input[name="booking_transport_type"]' => array('value' => 'Flying'), ':input[name="booking_transport_type"]' => array(
), 'value' => 'Flying'
), )
)
)
); );
$form['accommodation'] = array( $form['accommodation'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => 'Accommodation Details', '#title' => 'Accommodation Details'
); );
$form['accommodation']['booking_accom_before_reqd'] = array( $form['accommodation']['booking_accom_before_reqd'] = array(
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Do you need us to organise accommodation before Study Week?'), '#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"), '#options' => array(
'#default_value' => (! isset($data->booking_accom_before_reqd)) ? 'No' : ($data->booking_accom_before_reqd == 1 ? 'Yes' : 'No'), '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( $form['accommodation']['booking_accom_before_staying_with'] = array(
@@ -235,8 +253,11 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
$form['accommodation']['booking_accom_after_reqd'] = array( $form['accommodation']['booking_accom_after_reqd'] = array(
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Do you need us to organise accommodation after Study Week?'), '#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"), '#options' => array(
'#default_value' => (! isset($data->booking_accom_after_reqd)) ? 'No' : ($data->booking_accom_after_reqd == 1 ? 'Yes' : 'No'), '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( $form['accommodation']['booking_accom_after_staying_with'] = array(
@@ -253,16 +274,15 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
*/ */
$form['requirements'] = array( $form['requirements'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => 'Special Requirements', '#title' => 'Special Requirements'
); );
//only show the dietary field if we're allowed to //only show the dietary field if we're allowed to
if (variable_get('booking_enable_dietary', 0) == 1 || $inserting == FALSE) if (variable_get('booking_enable_dietary', 0) == 1 || $inserting == FALSE) {
{
$form['requirements']['booking_dietary'] = array( $form['requirements']['booking_dietary'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Special dietary requirements?'), '#title' => t('Special dietary requirements?'),
'#maxlength' => 180, '#maxlength' => 180,
'#default_value' => !empty($data->booking_dietary) ? $data->booking_dietary : $booking_dietary, '#default_value' => !empty($data->booking_dietary) ? $data->booking_dietary : $booking_dietary
); );
} }
$form['requirements']['booking_medical_conditions'] = array( $form['requirements']['booking_medical_conditions'] = array(
@@ -270,26 +290,23 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
'#title' => t('Please describe any medical condition we need to know about.'), '#title' => t('Please describe any medical condition we need to know about.'),
'#maxlength' => 180, '#maxlength' => 180,
'#required' => FALSE, '#required' => FALSE,
'#default_value' => !empty($data->booking_medical_conditions) ? $data->booking_medical_conditions : $booking_medical_conditions, '#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 //only show the room mate field if we're allowed to
if (variable_get('booking_enable_roommate', 0) == 1 || $inserting == FALSE) if (variable_get('booking_enable_roommate', 0) == 1 || $inserting == FALSE) {
{
//married people won't need to select a room mate //married people won't need to select a room mate
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) {
{
$form['requirements']['booking_room_mate1'] = array( $form['requirements']['booking_room_mate1'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('I would like to share a room with'), '#title' => t('I would like to share a room with'),
'#maxlength' => 200, '#maxlength' => 200,
'#required' => FALSE, '#required' => FALSE,
'#default_value' => !empty($data->booking_room_mate1) ? $data->booking_room_mate1 : $booking_roommate, '#default_value' => !empty($data->booking_room_mate1) ? $data->booking_room_mate1 : $booking_roommate
); );
} }
} }
//only show this field if this person isn't married //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)) 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( $form['requirements']['booking_bf_gf_nid'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Registration ID of Boyfriend/Girlfriend to be placed in the same discussion groups as you.'), '#title' => t('Registration ID of Boyfriend/Girlfriend to be placed in the same discussion groups as you.'),
@@ -297,154 +314,127 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
'#maxlength' => 15, '#maxlength' => 15,
'#size' => 4, '#size' => 4,
'#required' => FALSE, '#required' => FALSE,
'#default_value' => !empty($data->booking_bf_gf_nid) ? $data->booking_bf_gf_nid : $booking_bf_gf_nid, '#default_value' => !empty($data->booking_bf_gf_nid) ? $data->booking_bf_gf_nid : $booking_bf_gf_nid
); );
} }
if ($inserting == TRUE) { if ($inserting == TRUE) {
$form['submit'] = array( $form['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Submit'), '#value' => t('Submit')
); );
} }
return $form; return $form;
} }
function travel_form_validate($form, &$form_state) { function travel_form_validate($form, &$form_state)
{
//watchdog('booking', "<pre>Travel form:\n@info</pre>", array('@info' => print_r( $form_state, true))); //watchdog('booking', "<pre>Travel form:\n@info</pre>", array('@info' => print_r( $form_state, true)));
//verify boyfriend/girlfriend id is in the correct format //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'] != '') 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 //make sure this is a node id not something else
if (! is_numeric($form_state['values']['booking_bf_gf_nid'] )) 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(
form_set_error('booking_bf_gf_nid', '!id' => $form_state['values']['personid'],
t('You have entered an invalid registration id for your boyfriend/girlfriend. ' . '!contact' => l('contact us', 'contact')
'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.', watchdog('booking', "<pre>Travel form non-numeric bf/gf\n@info</pre>", array(
array('!id' => $form_state['values']['personid'], '!contact' => l('contact us', 'contact'))) '@info' => print_r($form_state['values'], true)
); ));
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 //don't allow them to specify their own node id
elseif ($form_state['values']['personid'] == $form_state['values']['booking_bf_gf_nid']) 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.'));
form_set_error('booking_bf_gf_nid', watchdog('booking', "<pre>Travel form bf/gf same as person id\n@info</pre>", array(
t('You have entered your own registration id.' . '@info' => print_r($form_state['values'], true)
'Please ensure you enter only the registration reference number your boyfriend/girlfriend received via email when registering, not your own registration id.') ));
); } else {
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 //check that the partner exists
$partner = db_query("SELECT person.nid " . $partner = db_query("SELECT person.nid " . "FROM {booking_person} person " . "WHERE nid = :nid", array(
"FROM {booking_person} person " . ':nid' => $form_state['values']['booking_bf_gf_nid']
"WHERE nid = :nid", ))->fetchObject();
array(':nid' => $form_state['values']['booking_bf_gf_nid'])) if (!$partner) {
->fetchObject(); 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(
if (! $partner) '!id' => $form_state['values']['personid'],
{ '!contact' => l('contact us', 'contact')
form_set_error('booking_bf_gf_nid', )));
t('We cannot find a matching registration id for your boyfriend/girlfriend. ' . watchdog('booking', "<pre>Travel form unknown bf/gf id\n@info</pre>", array(
'Please ensure you are using only the number that relates to their registration. For example, your registration ID is !id. ' . '@info' => print_r($form_state['values'], true)
'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 missing partner handling
} //end bf/gf validation } //end bf/gf validation
} //end bf/gf checking } //end bf/gf checking
//check to make sure flight info is entered if it is selected //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_transport_type']) && $form_state['values']['booking_transport_type'] == 'Flying') {
{
if ( (! isset($form_state['values']['booking_flightnum_inbound'])) || ($form_state['values']['booking_flightnum_inbound'] == '') ) 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.'));
form_set_error('booking_flightnum_inbound', watchdog('booking', "<pre>Travel form missing flight number for arrival flight\n@info</pre>", array(
t('Please enter the flight number associated with your arrival flight.') '@info' => print_r($form_state['values'], true)
); ));
watchdog('booking', "<pre>Travel form missing flight number for arrival flight\n@info</pre>",
array('@info' => print_r( $form_state['values'], true)));
} }
if ( 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_state['values']['booking_flight_datetime_inbound']['day'] == '' || form_set_error('booking_flight_datetime_inbound', t('Please enter the arrival time associated with your flight.'));
$form_state['values']['booking_flight_datetime_inbound']['month'] == '' || watchdog('booking', "<pre>Travel form missing flight arrival time\n@info</pre>", array(
$form_state['values']['booking_flight_datetime_inbound']['year'] == '' || '@info' => print_r($form_state['values'], true)
$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', "<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'] == '') ) 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.'));
form_set_error('booking_flightnum_outbound', watchdog('booking', "<pre>Travel form missing flight number for departing flight\n@info</pre>", array(
t('Please enter the flight number associated with your departing flight.') '@info' => print_r($form_state['values'], true)
); ));
watchdog('booking', "<pre>Travel form missing flight number for departing flight\n@info</pre>",
array('@info' => print_r( $form_state['values'], true)));
} }
if ( 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_state['values']['booking_flight_datetime_outbound']['day'] == '' || form_set_error('booking_flight_datetime_outbound', t('Please enter the departure time associated with your flight.'));
$form_state['values']['booking_flight_datetime_outbound']['month'] == '' || watchdog('booking', "<pre>Travel form missing flight departure time\n@info</pre>", array(
$form_state['values']['booking_flight_datetime_outbound']['year'] == '' || '@info' => print_r($form_state['values'], true)
$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', "<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 //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'])) 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.'));
form_set_error('booking_flight_datetime_inbound', watchdog('booking', "<pre>Travel form seems to have arrival flight after departure flight\n@info</pre>", array(
t('You have entered an arrival flight time that is after your departure flight time.') '@info' => print_r($form_state['values'], true)
); ));
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 check for flying
} }
function travel_form_submit($form, &$form_state) { function travel_form_submit($form, &$form_state)
{
global $event; global $event;
$values = $form_state['input']; $values = $form_state['input'];
//watchdog('booking', 'Submitting travel form: @info', array('@info' => var_export($values, TRUE))); //watchdog('booking', 'Submitting travel form: @info', array('@info' => var_export($values, TRUE)));
//check that $values['personid'] is a number //check that $values['personid'] is a number
if (! preg_match('/^[0-9]+$/', $values['personid'])) { if (!preg_match('/^[0-9]+$/', $values['personid'])) {
//parameter from url is not what we were expecting //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); drupal_set_message("Error: Invalid form data supplied. Please use the contact us form to let us know.", 'error', FALSE);
return ""; return "";
} }
//fetch details about the person //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 " . $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(
"FROM {booking_person} " . ':nid' => $values['personid']
"WHERE nid = :nid ", ))->fetchObject();
array(':nid' => $values['personid']))
->fetchObject();
//create the new node structure //create the new node structure
$node = new stdClass(); $node = new stdClass();
$node = node_type_set_defaults(); $node = node_type_set_defaults();
$node->title = t('!event travel form: !name', $node->title = t('!event travel form: !name', array(
array('!event' => $event->booking_eventname, '!name' => $person->booking_firstname . ' ' . $person->booking_lastname)); '!event' => $event->booking_eventname,
'!name' => $person->booking_firstname . ' ' . $person->booking_lastname
));
$node->type = 'travel'; $node->type = 'travel';
$node->status = 1; // Published? $node->status = 1; // Published?
$node->promote = 0; // Display on front page? $node->promote = 0; // Display on front page?
@@ -486,11 +476,14 @@ function travel_form_submit($form, &$form_state) {
_booking_travelform_confirmation_email($values['personid']); _booking_travelform_confirmation_email($values['personid']);
drupal_set_message("Thanks for submitting your travel details. You should receive a confirmation email shortly.", $type = 'status'); drupal_set_message("Thanks for submitting your travel details. You should receive a confirmation email shortly.", $type = 'status');
$form_state['redirect'] = array('content/travel'); $form_state['redirect'] = array(
'content/travel'
);
} }
function travel_load($nodes) { function travel_load($nodes)
{
//watchdog('booking', 'Loading node with params: @info', array('@info' => var_export($nodes, TRUE))); //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 // note that $nodes is an array of object references, keyed by nid
@@ -498,19 +491,22 @@ function travel_load($nodes) {
$query = db_select('booking_travel', 't'); $query = db_select('booking_travel', 't');
$query->distinct(); $query->distinct();
$query->join('booking_person','p','p.nid = t.booking_person_nid'); $query->join('booking_person', 'p', 'p.nid = t.booking_person_nid');
$query->fields('t'); $query->fields('t');
$query->fields('p', array('booking_dietary','booking_medical_conditions','booking_bf_gf_nid', 'booking_room_mate1')); $query->fields('p', array(
'booking_dietary',
'booking_medical_conditions',
'booking_bf_gf_nid',
'booking_room_mate1'
));
$query->condition('tid', array_keys($nodes), 'IN'); $query->condition('tid', array_keys($nodes), 'IN');
$result = $query->execute(); $result = $query->execute();
//add that data to the array of node references //add that data to the array of node references
foreach ($result as $record) foreach ($result as $record) {
{
//watchdog('booking', 'This node looks like: @info', array('@info' => var_export($record, TRUE))); //watchdog('booking', 'This node looks like: @info', array('@info' => var_export($record, TRUE)));
// run through each result row and add in the needed attributes // run through each result row and add in the needed attributes
foreach ($record as $key => $value) foreach ($record as $key => $value) {
{
$nodes[$record->tid]->$key = $value; $nodes[$record->tid]->$key = $value;
} }
} }
@@ -523,8 +519,7 @@ function travel_insert($node)
{ {
//watchdog('booking', 'Inserting travel form: @info', array('@info' => var_export($node, TRUE))); //watchdog('booking', 'Inserting travel form: @info', array('@info' => var_export($node, TRUE)));
db_insert('booking_travel') db_insert('booking_travel')->fields(array(
->fields(array(
'tid' => $node->nid, 'tid' => $node->nid,
'booking_person_nid' => $node->booking_person_nid, 'booking_person_nid' => $node->booking_person_nid,
'booking_transport_type' => $node->booking_transport_type, 'booking_transport_type' => $node->booking_transport_type,
@@ -536,39 +531,32 @@ function travel_insert($node)
'booking_flight_datetime_outbound' => $node->booking_flight_datetime_outbound, 'booking_flight_datetime_outbound' => $node->booking_flight_datetime_outbound,
'booking_accom_before_reqd' => $node->booking_accom_before_reqd, 'booking_accom_before_reqd' => $node->booking_accom_before_reqd,
//'booking_accom_before_staying_with' => $node->booking_accom_before_staying_with, //'booking_accom_before_staying_with' => $node->booking_accom_before_staying_with,
'booking_accom_after_reqd' => $node->booking_accom_after_reqd, 'booking_accom_after_reqd' => $node->booking_accom_after_reqd
//'booking_accom_after_staying_with' => $node->booking_accom_after_staying_with, //'booking_accom_after_staying_with' => $node->booking_accom_after_staying_with,
)) ))->execute();
->execute();
//update the booking_person fields //update the booking_person fields
db_update('booking_person') db_update('booking_person')->fields(array(
->fields(array(
'booking_dietary' => $node->booking_dietary, 'booking_dietary' => $node->booking_dietary,
'booking_medical_conditions' => $node->booking_medical_conditions, 'booking_medical_conditions' => $node->booking_medical_conditions,
'booking_bf_gf_nid' => $node->booking_bf_gf_nid, 'booking_bf_gf_nid' => $node->booking_bf_gf_nid,
'booking_room_mate1' => $node->booking_room_mate1, 'booking_room_mate1' => $node->booking_room_mate1
)) ))->condition('nid', $node->booking_person_nid)->execute();
->condition('nid', $node->booking_person_nid)
->execute();
//set the boyfriend/girlfriend to point to this person //set the boyfriend/girlfriend to point to this person
if ($node->booking_bf_gf_nid <> 0) if ($node->booking_bf_gf_nid <> 0) {
{ db_update('booking_person')->fields(array(
db_update('booking_person') 'booking_bf_gf_nid' => $node->booking_person_nid
->fields(array( ))->condition('nid', $node->booking_bf_gf_nid)->execute();
'booking_bf_gf_nid' => $node->booking_person_nid,
))
->condition('nid', $node->booking_bf_gf_nid)
->execute();
} }
} }
function travel_update($node) function travel_update($node)
{ {
watchdog('booking', 'Updating travel form booking_travel table: @info', array('@info' => var_export($node, TRUE))); watchdog('booking', 'Updating travel form booking_travel table: @info', array(
db_update('booking_travel') '@info' => var_export($node, TRUE)
->fields(array( ));
db_update('booking_travel')->fields(array(
'tid' => $node->nid, 'tid' => $node->nid,
'booking_person_nid' => $node->booking_person_nid, 'booking_person_nid' => $node->booking_person_nid,
'booking_transport_type' => $node->booking_transport_type, 'booking_transport_type' => $node->booking_transport_type,
@@ -580,91 +568,132 @@ function travel_update($node)
'booking_flight_datetime_outbound' => _datetime_to_ts($node->booking_flight_datetime_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_reqd' => $node->booking_accom_before_reqd == 'Yes' ? 1 : 0,
//'booking_accom_before_staying_with' => $node->booking_accom_before_staying_with, //'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_reqd' => $node->booking_accom_after_reqd == 'Yes' ? 1 : 0
//'booking_accom_after_staying_with' => $node->booking_accom_after_staying_with, //'booking_accom_after_staying_with' => $node->booking_accom_after_staying_with,
)) ))->condition('tid', $node->nid)->execute();
->condition('tid', $node->nid)
->execute();
watchdog('booking', 'Updating travel form booking_person table'); watchdog('booking', 'Updating travel form booking_person table');
//update the booking_person fields //update the booking_person fields
db_update('booking_person') db_update('booking_person')->fields(array(
->fields(array(
'booking_dietary' => $node->booking_dietary, 'booking_dietary' => $node->booking_dietary,
'booking_medical_conditions' => $node->booking_medical_conditions, 'booking_medical_conditions' => $node->booking_medical_conditions,
'booking_bf_gf_nid' => $node->booking_bf_gf_nid == '' ? 0 : $node->booking_bf_gf_nid, 'booking_bf_gf_nid' => $node->booking_bf_gf_nid == '' ? 0 : $node->booking_bf_gf_nid,
'booking_room_mate1' => $node->booking_room_mate1, 'booking_room_mate1' => $node->booking_room_mate1
)) ))->condition('nid', $node->booking_person_nid)->execute();
->condition('nid', $node->booking_person_nid)
->execute();
//set the boyfriend/girlfriend to point to this person //set the boyfriend/girlfriend to point to this person
if ($node->booking_bf_gf_nid <> 0) if ($node->booking_bf_gf_nid <> 0) {
{ db_update('booking_person')->fields(array(
db_update('booking_person') 'booking_bf_gf_nid' => $node->booking_person_nid
->fields(array( ))->condition('nid', $node->booking_bf_gf_nid)->execute();
'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; $person_id = $node->booking_person_nid;
$num_deleted = db_delete('booking_travel') $num_deleted = db_delete('booking_travel')->condition('tid', $node->nid)->execute();
->condition('tid', $node->nid) $message = t("Successfully deleted !num row(s) from the booking_travel table, corresponding to person ID !id", array(
->execute(); '!num' => $num_deleted,
$message = t("Successfully deleted !num row(s) from the booking_travel table, corresponding to person ID !id", '!id' => $person_id
array('!num' => $num_deleted, '!id' => $person_id)); ));
drupal_set_message($message, $type = 'status'); drupal_set_message($message, $type = 'status');
} }
function travel_view($node, $view_mode) { function travel_view($node, $view_mode)
{
global $event; global $event;
//fetch details about the person //fetch details about the person
$person = db_query("SELECT p.*, t.* from {booking_person} p " . $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(
"left outer join {booking_travel} t on p.nid = t.booking_person_nid " . ':nid' => $node->booking_person_nid
"where p.nid = :nid", ))->fetchObject();
array(':nid' => $node->booking_person_nid))
->fetchObject();
//and their boyfriend/girlfriend if it is defined //and their boyfriend/girlfriend if it is defined
if ($person->booking_bf_gf_nid != 0) if ($person->booking_bf_gf_nid != 0) {
{ $query = db_query("Select booking_firstname, booking_lastname from {booking_person} where nid = :nid", array(
$query = db_query("Select booking_firstname, booking_lastname from {booking_person} where nid = :nid", ':nid' => $node->booking_bf_gf_nid
array(':nid' => $node->booking_bf_gf_nid)) ))->fetchObject();
->fetchObject();
$bf_gf = $query->booking_firstname . " " . $query->booking_lastname; $bf_gf = $query->booking_firstname . " " . $query->booking_lastname;
} } else
else
$bf_gf = "N/A"; $bf_gf = "N/A";
$header = array('Attribute', 'Value'); $header = array(
'Attribute',
'Value'
);
$rows = array(); $rows = array();
$rows[] = array(t('Name:'), l(t('!first !last', array('!first' => $person->booking_firstname, '!last' => $person->booking_lastname)), $rows[] = array(
t('node/!id', array('!id' => $node->booking_person_nid))),); t('Name:'),
$rows[] = array(t('Transport Type:'), $node->booking_transport_type); l(t('!first !last', array(
$rows[] = array(t('Catching the train to Study Week:'), $node->booking_transport_from_morriset_reqd == 1 ? 'Yes' : 'No'); '!first' => $person->booking_firstname,
$rows[] = array(t('Inbound Flight Number:'), $node->booking_flightnum_inbound); '!last' => $person->booking_lastname
$rows[] = array(t('Flight Arrival:'), t('!date', array('!date' => format_date($node->booking_flight_datetime_inbound, 'custom', 'd/m/Y H:i')))); )), t('node/!id', array(
$rows[] = array(t('Outbound Flight Number:'), $node->booking_flightnum_outbound); '!id' => $node->booking_person_nid
$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'); $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 //fields from booking_person
$rows[] = array(t('Special Dietary Requirements:'), $node->booking_dietary); $rows[] = array(
$rows[] = array(t('Special Medical Conditions:'), $node->booking_medical_conditions); t('Special Dietary Requirements:'),
$rows[] = array(t('Boyfriend/Girlfriend:'), $bf_gf); $node->booking_dietary
$rows[] = array(t('Requested Room mate(s):'), $node->booking_room_mate1); );
$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( $node->content['details'] = array(
'#markup' => theme('table', array('header' => $header, 'rows' => $rows)), '#markup' => theme('table', array(
'#weight' => 1, 'header' => $header,
'rows' => $rows
)),
'#weight' => 1
); );
return $node; return $node;
} }