arg(1))) ->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.booking_event_id = :eid AND p.booking_tempid = :tempid", array(':tempid' => arg(1), ':eid' => $event->eid)) ->fetchObject(); if ($person) { $tokens = booking_define_personspecific_tokens($person); watchdog('booking', 'Checking for existing travel form for: @info', array('@info' => var_export($person, TRUE))); //check for an existing travel form $travelform = db_query("SELECT tid " . "FROM {booking_travel} " . "WHERE booking_person_nid = :nid", array(':nid' => $person->nid)) ->fetchObject(); if ($travelform) { $output = token_replace(variable_get('booking_travelform_completed_page'), $tokens); $return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output)); } //they haven't submitted a travel form yet else { //Output different text if this is for a married couple if ((variable_get('booking_enable_combined_pricing', 0) == 1) && $person->booking_partner_id > 0) { $output = token_replace(variable_get('booking_travelform_married_page'), $tokens); } else { $output = token_replace(variable_get('booking_travelform_page'), $tokens); } $return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output)); $return_array[] = array('form' => drupal_get_form('travel_form', true, $person->nid)); } return $return_array; } else { drupal_set_message("Unable to find matching session ID " . arg(1), 'error', FALSE); return ""; } } function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0) { global $event; date_default_timezone_set(TIMEZONE); $booking_dietary = ''; $booking_medical_conditions = ''; $booking_bf_gf_nid = ''; if (!empty($node)) { $data = $node; //watchdog('booking', 'Travel form loading data from saved node: @info', array('@info' => var_export($node, TRUE))); //check for existing booking_person data to use in the form $person = db_query("SELECT booking_dietary, booking_medical_conditions, booking_bf_gf_nid, booking_partner_id " . "FROM {booking_person} " . "WHERE nid = :nid ", array(':nid' => $data->booking_person_nid)) ->fetchObject(); } else { $data = $form_state['input']; //check for existing booking_person data to use in the form $person = db_query("SELECT booking_dietary, booking_medical_conditions, booking_bf_gf_nid, booking_partner_id " . "FROM {booking_person} " . "WHERE nid = :nid ", array(':nid' => $nid)) ->fetchObject(); //watchdog('booking', 'Booking registration form loading data from form submission: @info', array('@info' => var_export($form_state, TRUE))); } if ($person) { $booking_dietary = $person->booking_dietary; $booking_medical_conditions = $person->booking_medical_conditions; $booking_bf_gf_nid = $person->booking_bf_gf_nid; } $transport_type_options = array( 'Driving' => 'Driving', //'Train' => 'Train', 'Flying' => 'Flying' ); //form starts here //store the node id $form['personid'] = array( '#type' => 'hidden', '#value' => $nid, ); $form['travel'] = array( '#type' => 'fieldset', '#title' => 'Travel details', ); $form['travel']['booking_transport_type'] = array( '#type' => 'radios', '#title' => t('Transport Type'), '#options' => $transport_type_options, '#default_value' => !empty($data->booking_transport_type) ? $data->booking_transport_type : NULL, '#required' => TRUE, ); /* $form['travel']['booking_transport_to_morriset_reqd'] = array( '#type' => 'radios', '#title' => t('Do you require transport from Study Week to Morriset Station?'), '#options' => array('Yes' => 'Yes', 'No' => 'No - I have arranged my own Transport'), '#default_value' => (! isset($data->booking_transport_to_morriset_reqd)) ? '' : ($data->booking_transport_to_morriset_reqd == 1 ? 'Yes' : 'No'), '#states' => array( 'visible' => array( ':input[name="booking_transport_type"]' => array('value' => 'Train'), ), ), ); */ //Flying Options $form['travel']['booking_flightnum_inbound'] = array( '#type' => 'textfield', '#title' => t('Flight Number arriving into Sydney'), '#maxlength' => 50, '#default_value' => empty($data->booking_flightnum_inbound) ? '' : $data->booking_flightnum_inbound, '#states' => array( 'visible' => array( ':input[name="booking_transport_type"]' => array('value' => 'Flying'), ), ), ); $form['travel']['booking_flight_datetime_inbound'] = array( '#type' => 'date_select', '#title' => t('Date and Time of flight arrival into Sydney Airport'), '#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'), '#default_value' => empty($data->booking_flight_datetime_outbound) ? '' : date("Y-m-d H:i:s", $data->booking_flight_datetime_outbound), '#date_format' => 'd/m/Y H:i', '#date_year_range' => '0:0', '#states' => array( 'visible' => array( ':input[name="booking_transport_type"]' => array('value' => 'Flying'), ), ), ); $form['travel']['booking_transport_from_morriset_reqd'] = array( '#type' => 'radios', '#title' => t('Will you be catching the train to Study Week?'), '#options' => array('Yes' => 'Yes I will be catching the train', 'No' => 'No - I have arranged my own Transport'), '#default_value' => (! isset($data->booking_transport_from_morriset_reqd)) ? 'No' : ($data->booking_transport_from_morriset_reqd == 1 ? 'Yes' : 'No'), '#states' => array( 'visible' => array( ':input[name="booking_transport_type"]' => array('value' => 'Flying'), ), ), ); $form['accommodation'] = array( '#type' => 'fieldset', '#title' => 'Accommodation Details', ); $form['accommodation']['booking_accom_before_reqd'] = array( '#type' => 'radios', '#title' => t('Do you need us to organise accommodation before Study Week?'), '#options' => array('Yes' => 'Yes', 'No' => "No - I have arranged my own accommodation or I'm not arriving early"), '#default_value' => (! isset($data->booking_accom_before_reqd)) ? 'No' : ($data->booking_accom_before_reqd == 1 ? 'Yes' : 'No'), ); /* $form['accommodation']['booking_accom_before_staying_with'] = array( '#type' => 'textfield', '#title' => t('Who are you staying with in Sydney before Study Week?'), '#maxlength' => 100, '#default_value' => empty($data->booking_accom_before_staying_with) ? '' : $data->booking_accom_before_staying_with, '#states' => array( 'visible' => array( ':input[name="booking_accom_before_reqd"]' => array('value' => 'No'), ), ), ); */ $form['accommodation']['booking_accom_after_reqd'] = array( '#type' => 'radios', '#title' => t('Do you need us to organise accommodation after Study Week?'), '#options' => array('Yes' => 'Yes', 'No' => "No - I have arranged my own accommodation or I'm not staying in Sydney afterwards"), '#default_value' => (! isset($data->booking_accom_after_reqd)) ? 'No' : ($data->booking_accom_after_reqd == 1 ? 'Yes' : 'No'), ); /* $form['accommodation']['booking_accom_after_staying_with'] = array( '#type' => 'textfield', '#title' => t('Who are you staying with in Sydney after Study Week?'), '#maxlength' => 100, '#default_value' => empty($data->booking_accom_after_staying_with) ? '' : $data->booking_accom_after_staying_with, '#states' => array( 'visible' => array( ':input[name="booking_accom_after_reqd"]' => array('value' => 'No'), ), ), ); */ $form['requirements'] = array( '#type' => 'fieldset', '#title' => 'Special Requirements', ); $form['requirements']['booking_dietary'] = array( '#type' => 'textfield', '#title' => t('Special dietary requirements?'), '#maxlength' => 180, '#default_value' => !empty($data->booking_dietary) ? $data->booking_dietary : $booking_dietary, ); $form['requirements']['booking_medical_conditions'] = array( '#type' => 'textfield', '#title' => t('Please describe any medical condition we need to know about.'), '#maxlength' => 180, '#required' => FALSE, '#default_value' => !empty($data->booking_medical_conditions) ? $data->booking_medical_conditions : $booking_medical_conditions, ); //only show this field if this person isn't married //TODO: Get their registration ID instead of their name if ((variable_get('booking_enable_combined_pricing', 0) == 1) && $person->booking_partner_id == 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.'), '#maxlength' => 15, '#size' => 4, '#required' => FALSE, '#default_value' => !empty($data->booking_bf_gf_nid) ? $data->booking_bf_gf_nid : $booking_bf_gf_nid, ); } if ($inserting == TRUE) { $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); } return $form; } function travel_form_validate($form, &$form_state) { //watchdog('booking', "
Travel form:\n@info", array('@info' => print_r( $form_state, true))); //check that a transport choice has been made /* if ((! isset($form_state['booking_transport_type'])) || $form_state['booking_transport_type'] == NULL) { form_set_error('booking_transport_type', t('You must select a transport type.')); } */ //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 (! 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. If you believe this to be incorrect, please !contact using the details provided.', array('!contact' => l('contact us', 'contact'))) ); } //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. If you believe this to be incorrect, please !contact using the details provided.', array('!contact' => l('contact us', 'contact'))) ); } } } 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 " . "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_dietary = $values['booking_dietary']; $node->booking_medical_conditions = $values['booking_medical_conditions']; $node->booking_bf_gf_nid = empty($values['booking_bf_gf_nid']) ? 0 : $values['booking_bf_gf_nid']; watchdog('booking', "
Travel data to save:\n@info", array('@info' => print_r( $node, true))); //store the node $foo = node_submit(&$node); $blah = node_save($foo); //send a confirmation email _booking_travelform_confirmation_email($values['personid']); drupal_set_message("Thanks for submitting your travel details. You should receive a confirmation email shortly.", $type = 'status'); $form_state['redirect'] = array('content/travel'); } function travel_load($nodes) { //watchdog('booking', 'Loading node with params: @info', array('@info' => var_export($nodes, TRUE))); // 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')); $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', 'Inserting travel form: @info', array('@info' => var_export($node, TRUE))); db_insert('booking_travel') ->fields(array( 'tid' => $node->nid, 'booking_person_nid' => $node->booking_person_nid, 'booking_transport_type' => $node->booking_transport_type, 'booking_transport_from_morriset_reqd' => $node->booking_transport_from_morriset_reqd, //'booking_transport_to_morriset_reqd' => $node->booking_transport_to_morriset_reqd, 'booking_flightnum_inbound' => $node->booking_flightnum_inbound, 'booking_flight_datetime_inbound' => $node->booking_flight_datetime_inbound, 'booking_flightnum_outbound' => $node->booking_flightnum_outbound, 'booking_flight_datetime_outbound' => $node->booking_flight_datetime_outbound, 'booking_accom_before_reqd' => $node->booking_accom_before_reqd, //'booking_accom_before_staying_with' => $node->booking_accom_before_staying_with, 'booking_accom_after_reqd' => $node->booking_accom_after_reqd, //'booking_accom_after_staying_with' => $node->booking_accom_after_staying_with, )) ->execute(); watchdog('booking', 'booking_travel table completed.'); //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, )) ->condition('nid', $node->booking_person_nid) ->execute(); watchdog('booking', 'booking_person table completed.'); } 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, )) ->condition('nid', $node->booking_person_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), corresponding to person ID !id", array('!num' => $num_deleted, '!id' => $person_id)); drupal_set_message($message, $type = 'status'); } function travel_view($node, $view_mode) { global $event; //fetch details about the person $person = db_query("SELECT p.*, t.* from {booking_person} p " . "left outer join {booking_travel} t on p.nid = t.booking_person_nid " . "where p.nid = :nid", array(':nid' => $node->booking_person_nid)) ->fetchObject(); //and their boyfriend/girlfriend if it is defined if ($person->booking_bf_gf_nid != 0) { $query = db_query("Select booking_firstname, booking_lastname from {booking_person} where nid = :nid", array(':nid' => $node->booking_bf_gf_nid)) ->fetchObject(); $bf_gf = $query->booking_firstname . " " . $query->booking_lastname; } else $bf_gf = "N/A"; $header = array('Attribute', 'Value'); $rows = array(); $rows[] = array(t('Name:'), l(t('!first !last', array('!first' => $person->booking_firstname, '!last' => $person->booking_lastname)), t('node/!id', array('!id' => $node->booking_person_nid))),); $rows[] = array(t('Transport Type:'), $node->booking_transport_type); $rows[] = array(t('Catching the train to Study Week:'), $node->booking_transport_from_morriset_reqd == 1 ? 'Yes' : 'No'); $rows[] = array(t('Inbound Flight Number:'), $node->booking_flightnum_inbound); $rows[] = array(t('Flight Arrival:'), t('!date', array('!date' => format_date($node->booking_flight_datetime_inbound, 'custom', 'd/m/Y H:i')))); $rows[] = array(t('Outbound Flight Number:'), $node->booking_flightnum_outbound); $rows[] = array(t('Flight Departure:'), t('!date', array('!date' => format_date($node->booking_flight_datetime_outbound, 'custom', 'd/m/Y H:i')))); $rows[] = array(t('Accommodation before Study Week Required:'), $node->booking_accom_before_reqd == 1 ? 'Yes' : 'No'); $rows[] = array(t('Accommodation after Study Week Required:'), $node->booking_accom_after_reqd == 1 ? 'Yes' : 'No'); //fields from booking_person $rows[] = array(t('Special Dietary Requirements:'), $node->booking_dietary); $rows[] = array(t('Special Medical Conditions:'), $node->booking_medical_conditions); $rows[] = array(t('Boyfriend/Girlfriend:'), $bf_gf); $node->content['details'] = array( '#markup' => theme('table', array('header' => $header, 'rows' => $rows)), '#weight' => 1, ); return $node; }