Code formatting fix
This commit is contained in:
@@ -3,13 +3,14 @@
|
||||
/**
|
||||
* Travel form for attendee
|
||||
*/
|
||||
function booking_travel_page() {
|
||||
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))) {
|
||||
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');
|
||||
@@ -25,14 +26,13 @@ function booking_travel_page() {
|
||||
|
||||
//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();
|
||||
$query->condition('p.booking_tempid', arg(1), '=')->fields('p', array(
|
||||
'nid'
|
||||
));
|
||||
$person = $query->execute()->fetchObject();
|
||||
|
||||
//if we found a matching person
|
||||
if ($person)
|
||||
{
|
||||
if ($person) {
|
||||
//load this person's data
|
||||
$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)));
|
||||
|
||||
//check for an existing travel form
|
||||
if (! empty( $node->tid ))
|
||||
{
|
||||
if (!empty($node->tid)) {
|
||||
$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
|
||||
else
|
||||
{
|
||||
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)
|
||||
{
|
||||
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
|
||||
{
|
||||
} 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_array[] = array(
|
||||
'paragraph' => array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => $output
|
||||
)
|
||||
);
|
||||
$return_array[] = array(
|
||||
'form' => drupal_get_form('travel_form', true, $node->nid)
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
if (!empty($node))
|
||||
{
|
||||
if (!empty($node)) {
|
||||
$data = $node;
|
||||
}
|
||||
//otherwise rely on the form state from the previous submission
|
||||
else
|
||||
{
|
||||
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();
|
||||
$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)
|
||||
{
|
||||
if ($person) {
|
||||
$booking_dietary = $person->booking_dietary;
|
||||
$booking_medical_conditions = $person->booking_medical_conditions;
|
||||
//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
|
||||
$form['personid'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#value' => $nid,
|
||||
'#value' => $nid
|
||||
);
|
||||
|
||||
$form['travel'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => 'Travel details',
|
||||
'#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,
|
||||
'#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,
|
||||
'#states' => 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(
|
||||
'#type' => 'date_select',
|
||||
@@ -168,9 +172,11 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
|
||||
'#date_year_range' => '0:0',
|
||||
'#states' => 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(
|
||||
'#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,
|
||||
'#states' => 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(
|
||||
'#type' => 'date_select',
|
||||
@@ -192,32 +200,42 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
|
||||
'#date_year_range' => '0:0',
|
||||
'#states' => 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(
|
||||
'#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'),
|
||||
'#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'),
|
||||
),
|
||||
),
|
||||
':input[name="booking_transport_type"]' => array(
|
||||
'value' => 'Flying'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$form['accommodation'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => 'Accommodation Details',
|
||||
'#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'),
|
||||
'#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(
|
||||
@@ -235,8 +253,11 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
|
||||
$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'),
|
||||
'#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(
|
||||
@@ -253,16 +274,15 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
|
||||
*/
|
||||
$form['requirements'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => 'Special Requirements',
|
||||
'#title' => 'Special Requirements'
|
||||
);
|
||||
//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(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Special dietary requirements?'),
|
||||
'#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(
|
||||
@@ -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.'),
|
||||
'#maxlength' => 180,
|
||||
'#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
|
||||
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
|
||||
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(
|
||||
'#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,
|
||||
'#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))
|
||||
{
|
||||
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.'),
|
||||
@@ -297,154 +314,127 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
|
||||
'#maxlength' => 15,
|
||||
'#size' => 4,
|
||||
'#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) {
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Submit'),
|
||||
'#value' => t('Submit')
|
||||
);
|
||||
}
|
||||
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)));
|
||||
|
||||
//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
|
||||
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)));
|
||||
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
|
||||
{
|
||||
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)));
|
||||
$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_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_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 (
|
||||
$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', "<pre>Travel form missing flight arrival time\n@info</pre>", 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', "<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_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 (
|
||||
$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', "<pre>Travel form missing flight departure time\n@info</pre>", 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', "<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)));
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
function travel_form_submit($form, &$form_state) {
|
||||
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'])) {
|
||||
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();
|
||||
$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->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?
|
||||
@@ -486,11 +476,14 @@ function travel_form_submit($form, &$form_state) {
|
||||
_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');
|
||||
$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)));
|
||||
|
||||
// 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->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('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');
|
||||
$result = $query->execute();
|
||||
|
||||
//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)));
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -523,8 +519,7 @@ function travel_insert($node)
|
||||
{
|
||||
//watchdog('booking', 'Inserting travel form: @info', array('@info' => var_export($node, TRUE)));
|
||||
|
||||
db_insert('booking_travel')
|
||||
->fields(array(
|
||||
db_insert('booking_travel')->fields(array(
|
||||
'tid' => $node->nid,
|
||||
'booking_person_nid' => $node->booking_person_nid,
|
||||
'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_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_reqd' => $node->booking_accom_after_reqd
|
||||
//'booking_accom_after_staying_with' => $node->booking_accom_after_staying_with,
|
||||
))
|
||||
->execute();
|
||||
))->execute();
|
||||
|
||||
//update the booking_person fields
|
||||
db_update('booking_person')
|
||||
->fields(array(
|
||||
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();
|
||||
'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();
|
||||
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(
|
||||
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,
|
||||
@@ -580,91 +568,132 @@ function travel_update($node)
|
||||
'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_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();
|
||||
))->condition('tid', $node->nid)->execute();
|
||||
|
||||
watchdog('booking', 'Updating travel form booking_person table');
|
||||
|
||||
//update the booking_person fields
|
||||
db_update('booking_person')
|
||||
->fields(array(
|
||||
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();
|
||||
'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();
|
||||
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));
|
||||
$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) {
|
||||
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();
|
||||
$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();
|
||||
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
|
||||
} else
|
||||
$bf_gf = "N/A";
|
||||
|
||||
|
||||
$header = array('Attribute', 'Value');
|
||||
$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');
|
||||
$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);
|
||||
$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,
|
||||
'#markup' => theme('table', array(
|
||||
'header' => $header,
|
||||
'rows' => $rows
|
||||
)),
|
||||
'#weight' => 1
|
||||
);
|
||||
return $node;
|
||||
}
|
Reference in New Issue
Block a user