Implementation of travel form

This commit is contained in:
2014-02-25 13:44:13 +11:00
parent b710954bdd
commit b833125db8
9 changed files with 219 additions and 164 deletions

View File

@@ -20,7 +20,15 @@ function booking_balance_page() {
//TODO: if the person says they're married, query to see if they're listed partner has already registered and paid
//if they have, then let the new registration person know their partner has already paid, and send them the confirmation email
//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();
/*
//fetch details about the person
$query = db_select('booking_person', 'p');
$query->join('booking_price', 'pr', 'p.booking_payment_id = pr.pid');
@@ -29,18 +37,24 @@ function booking_balance_page() {
->fields('pr', array('booking_price', 'booking_price_descrip'));
$person = $query->execute()
->fetchObject();
*/
if ($person) {
//maximum length for invoice id is 127 characters
$invoiceid = $person->nid . '_bal' . REQUEST_TIME . '_' . $person->booking_lastname . '-' . $person->booking_firstname;
if ($person)
{
//load all the fields
$node = node_load($person->nid);
//calculate the invoice ID
$invoiceid = $person->nid . '_bal' . REQUEST_TIME . '_' . $node->booking_lastname . '-' . $node->booking_firstname;
//maximum length for invoice id in paypal is 127 characters so truncate if necessary
$invoiceid = substr($invoiceid, 0, 126);
} else {
drupal_set_message("Unable to find matching session ID " . arg(1), 'error', FALSE);
return "";
}
$tokens = booking_define_personspecific_tokens($person);
$tokens['paypal-total-form'] = _booking_paypal_form($person, $invoiceid, $tokens['paypal-total-amount'], "Pay Balance");
//populate tokens and paypal form
$tokens = booking_define_personspecific_tokens($node);
$tokens['paypal-total-form'] = _booking_paypal_form($node, $invoiceid, $tokens['paypal-total-amount'], "Pay Balance");
//Calculate the amount outstanding
//watchdog('booking', 'Booking Balance form calculating amount owing');
@@ -55,7 +69,7 @@ function booking_balance_page() {
{
$output = token_replace(variable_get('booking_regn_balance_page'), $tokens);
//optional additional text for married people
if ($person->booking_married == 'Y')
if ($node->booking_married == 'Y')
$output .= token_replace(variable_get('booking_regn_balance_married_text'), $tokens);
}

View File

@@ -23,26 +23,18 @@ function booking_confirm_page() {
//fetch details about the person
$query = db_select('booking_person', 'p');
$query->join('booking_price', 'pr', 'p.booking_payment_id = pr.pid');
$query->condition('p.booking_tempid', arg(1), '=')
->fields('p')
->fields('pr', array('booking_price', 'booking_price_descrip'));
->fields('p', array('nid'));
$person = $query->execute()
->fetchObject();
/*
$person = db_query("SELECT person.nid, person.booking_event_id, person.booking_lastname, person.booking_firstname, price.booking_buttonid, price.booking_price, price.booking_price_descrip, booking_partner_id, " .
" person.booking_married, person.booking_partner_name, person.booking_status " .
"FROM {booking_person} person, {booking_price} price " .
"WHERE booking_tempid = :tempid " .
"AND person.booking_payment_id = price.pid",
array(':tempid' => arg(1)))
->fetchObject();
*/
if ($person) {
if ($person)
{
//load all the fields
$node = node_load($person->nid);
//maximum length for invoice id is 127 characters
$invoiceid = $person->nid . '_' . $person->booking_event_id . '_' . $person->booking_lastname . '-' . $person->booking_firstname;
$invoiceid = $person->nid . '_' . $node->booking_event_id . '_' . $node->booking_lastname . '-' . $node->booking_firstname;
$invoiceid = substr($invoiceid, 0, 126);
} else {
drupal_set_message("Unable to find matching session ID " . arg(1), 'error', FALSE);
@@ -50,27 +42,15 @@ function booking_confirm_page() {
}
//check if this registration will be on the waiting list
if (_booking_check_bookings_full() == True || $person->booking_status == 2)
if (_booking_check_bookings_full() == True || $node->booking_status == 2)
$waiting_list = TRUE;
//Calculate the amount outstanding
//$amount_owing = _booking_amount_owing($person->nid);
//populate tokens
/*
$tokens = array();
$tokens['eventname'] = $event->booking_eventname;
$tokens['fname'] = ucwords(trim($person->booking_firstname));
$tokens['booking-id'] = $person->nid;
$tokens['payment-transaction-desc'] = $person->nid . ' ' . $person->booking_lastname;
$tokens['payment-required'] = $person->booking_price;
$tokens['waitinglist-position'] = "";
*/
$tokens = booking_define_personspecific_tokens($person);
$tokens = booking_define_personspecific_tokens($node);
//TODO: add in the paypal forms as tokens
$tokens['paypal-deposit-form'] = _booking_paypal_form($person, $invoiceid, $tokens['paypal-deposit-amount'], "Pay Deposit");
$tokens['paypal-total-form'] = _booking_paypal_form($person, $invoiceid, $tokens['paypal-total-amount'], "Pay Full Amount");
$tokens['paypal-deposit-form'] = _booking_paypal_form($node, $invoiceid, $tokens['paypal-deposit-amount'], "Pay Deposit");
$tokens['paypal-total-form'] = _booking_paypal_form($node, $invoiceid, $tokens['paypal-total-amount'], "Pay Full Amount");
//watchdog('booking', 'Paypal form "@info"', array ('@info' => var_export($tokens['paypal-total-form'], TRUE)));
@@ -99,7 +79,7 @@ function booking_confirm_page() {
}
//optional additional text for married people
if ($person->booking_married == 'Y')
if ($node->booking_married == 'Y')
{
$output .= token_replace(variable_get('booking_regn_confirm_married_text'), $tokens);
}

View File

@@ -159,10 +159,7 @@ function _booking_balance_payment_email($nid)
//send the email
drupal_mail('booking', 'registration_mail_bal_outstanding', $to, $language, $params, $from);
$params['headers']['Bcc'] = "it@coadcorp.com";
//drupal_mail('booking', 'registration_mail_bal_outstanding', variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from'))),
// $language, $params, $from);
//drupal_mail('booking', 'registration_mail_bal_outstanding', 'it@coadcorp.com', $language, $params, $from);
$params['headers']['Bcc'] = "it@coadcorp.com";
}
/**
@@ -199,12 +196,7 @@ function _booking_custom_email($nid, $email_type)
$params['body'] = token_replace(variable_get($email_body_variable), $tokens);
//send the email to the person
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
//send a copy to the site admins so they know it sent successfully
//$params['headers']['Bcc'] = "it@coadcorp.com";
//drupal_mail('booking', 'booking_email_custom', variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from'))),
// $language, $params, $from);
//drupal_mail('booking', 'booking_email_custom', 'it@coadcorp.com', $language, $params, $from);
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
}
@@ -238,11 +230,7 @@ function _booking_promoted_from_waitinglist_email($nid)
$params['body'] = token_replace(variable_get('booking_email_waitinglistpromotion'), $tokens);
//send the email
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
//drupal_mail('booking', 'booking_email_custom', variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from'))),
// $language, $params, $from);
//drupal_mail('booking', 'booking_email_custom', 'it@coadcorp.com', $language, $params, $from);
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
}
/**
@@ -277,83 +265,41 @@ function _booking_demoted_to_notcoming_email($nid)
//send the email
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
//drupal_mail('booking', 'booking_email_custom', variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from'))),
// $language, $params, $from);
//drupal_mail('booking', 'booking_email_custom', 'it@coadcorp.com', $language, $params, $from);
}
/*
function _booking_promoted_from_waitinglist_email_old($nid)
/**
* Function to generate email to be sent to the attendee once they complete their travel form
*
* @param $nid - the registration node
*/
function _booking_travelform_confirmation_email($nid)
{
global $event;
global $user;
$language = user_preferred_language($user);
//load the node matching this id
$node = node_load($nid);
//figure out if we're in the right time period for discounted registration rates
$early = db_query("SELECT booking_earlybird_close FROM {booking_event} where eid = :eid", array(
':eid' => $event->eid))
->fetchObject();
if ($early->booking_earlybird_close > time())
$amount_owing = _booking_amount_owing($node->nid);
else
{
$amount_owing = _booking_amount_owing($node->nid;
}
//calcalate a new temp id to be configured for this user if required
if ($node->booking_tempid == '')
{
$tempid = _booking_uuidSecure();
//update the user with this tempid
db_update('booking_person')
->fields(array(
'booking_tempid' => $tempid
))
->condition('nid', $node->nid)
->execute();
}
else
{
$tempid = $node->booking_tempid;
}
//calculate the booking balance URL for this user
$url = url('balance/' . $tempid, array('absolute' => TRUE));
$tokens = booking_define_personspecific_tokens($node);
watchdog('booking', 'Sending travelform confirmation email to !first !last', array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname));
//calculate the from email address
$from = t('!event Registrations <!email>', array('!event' => $event->booking_eventname,
'!email' => variable_get('booking_contact_email', variable_get('site_mail', ini_get('sendmail_from')))
));
//calculate the body of the email
$contact_message[] = t("Dear !firstname,", array('!firstname' => ucwords(trim($node->booking_firstname))));
$contact_message[] = t("We have some great news for you. A place at !event for you has just become available. ",
array('!event' => $event->booking_eventname));
$contact_message[] = t("If you wish to secure your place at !event, please visit !link to make your final payment. " .
"Our records indicate that you currently have $!amount outstanding (including Paypal transaction fees).",
array('!amount' => number_format($amount_owing, 2, '.', ''), '!link' => $url, '!event' => $event->booking_eventname));
$contact_message[] = t("Once we have received your payment, you will be sent an automatic confirmation email thanking you for paying your outstanding fees. " .
"If you are paying via Paypal's eCheque feature, please be aware that payments take 3-5 working days to clear, and you will not receive the confirmation email until that has occurred.");
$contact_message[] = t("Please don't hesitate to contact us if you have any queries by replying to this email. We look forward to seeing you (God Willing) at !event!!!", array('!event' => $event->booking_eventname));
$contact_message[] = t("Love in Jesus,\n!event Registrations Team\n", array('!event' => $event->booking_eventname));
$contact_message[] = t("________________________________________________________");
$contact_message[] = t("The following information shows the details you entered when you registered. If any of this information is incorrect, please reply to this email with the corrections as soon as possible.\n________________________________________________________");
$contact_message[] = t("!details", array('!details' => _booking_details_email_summary($node)));
//turn the array into the body of the email
foreach ($contact_message as $key => $value)
$contact_message[$key] = wordwrap($value);
//calculate the remaining parameters
$to = $node->booking_email;
$subject = t('!event Position Available', array('!event' => $event->booking_eventname));
$params['subject'] = $subject;
$params['body'] = implode("\n\n", $contact_message);
//send the email
drupal_mail('booking', 'registration_mail', $to, $language, $params, $from);
drupal_mail('booking', 'registration_mail', 'it@coadcorp.com', $language, $params, $from);
}
*/
$subject = t('!event Travel Details Received', array('!event' => $event->booking_eventname));
$params['subject'] = $subject;
$params['headers']['Bcc'] = "it@coadcorp.com, " . variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from')));
//retrieve the body of the email
$params['body'] = token_replace(variable_get('booking_email_travel_complete_text'), $tokens);
//send the email
drupal_mail('booking', 'booking_email_custom', $to, $language, $params, $from);
}

View File

@@ -813,6 +813,48 @@ function _booking_details_email_summary($node) {
return implode("\n", $rows);
}
/**
* Helper function to format travel form summary
*/
function _booking_travelform_email_summary($node) {
$output = '';
//look up the actual name if a boyfriend/girlfriend is defined
if ($node->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";
$rows = array();
$rows[] = t('Name: !first !last', array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname));
$rows[] = t('Transport Type: !transport', array('!transport' => $node->booking_transport_type));
if ($node->booking_transport_type == 'Flying')
{
$rows[] = t('Catching the train to Study Week: !value', array('!value' => $node->booking_transport_from_morriset_reqd == 1 ? 'Yes' : 'No'));
$rows[] = t('Inbound Flight Number: ' . $node->booking_flightnum_inbound);
$rows[] = t('Flight Arrival: !date', array('!date' => format_date($node->booking_flight_datetime_inbound, 'custom', 'd/m/Y H:i')));
$rows[] = t('Outbound Flight Number: ' . $node->booking_flightnum_outbound);
$rows[] = t('Flight Departure: !date', array('!date' => format_date($node->booking_flight_datetime_outbound, 'custom', 'd/m/Y H:i')));
}
$rows[] = t('Accommodation before Study Week Required: !value', array('!value' => $node->booking_accom_before_reqd == 1 ? 'Yes' : 'No'));
$rows[] = t('Accommodation after Study Week Required: !value', array('!value' => $node->booking_accom_after_reqd == 1 ? 'Yes' : 'No'));
//fields from booking_person
$rows[] = t('Special Dietary Requirements: ' . $node->booking_dietary);
$rows[] = t('Special Medical Conditions: ' . $node->booking_medical_conditions);
$rows[] = t('Boyfriend/Girlfriend: ' . $bf_gf);
foreach ($rows as $key => $value)
$rows[$key] = wordwrap($value);
return implode("\n", $rows);
}
/**
* @brief Generates a Universally Unique IDentifier, version 4.

View File

@@ -164,24 +164,11 @@ function booking_update_7203() {
),
'primary key' => array('sid'),
);
//this defines the number of leader/helper sessions for a particular person
$booking_leadhelp_list = array(
'fields' => array(
'id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_node_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_total_lead' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_total_help' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_available_lead' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_available_help' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
),
'primary key' => array('id'),
);
db_create_table('booking_studygroup_list', $booking_studygroup_list);
db_create_table('booking_studygroup_mapping', $booking_studygroup_mapping);
db_create_table('booking_leadhelp_list', $booking_leadhelp_list);
//db_create_table('booking_leadhelp_list', $booking_leadhelp_list);
}
/**
@@ -286,6 +273,14 @@ function booking_update_7210() {
return "Updated maximum payment successfully.";
}
/**
* Add boyfriend or girlfriend node ID field
*/
function booking_update_7211() {
$spec = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0);
db_add_field( 'booking_person', 'booking_bf_gf_nid', $spec);
}
/**
* Implementation of hook_install().
*/
@@ -414,6 +409,7 @@ function booking_schema() {
'booking_partner_name' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
'booking_partner_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10'),
'booking_bf_gf' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
'booking_bf_gf_nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10'),
'booking_room_mate1' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
'booking_room_mate2' => array('type' => 'varchar', 'length' => '200', 'not null' => FALSE),
//helping areas

View File

@@ -915,6 +915,8 @@ function booking_form_submit($form, &$form_state) {
$node->booking_married = ($values['booking_married'] == 1 ? 'Y' : 'N');
$node->booking_partner_name = ucwords($values['booking_partner_name']);
$node->booking_partner_id = empty($values['booking_partner_id']) ? 0 : $values['booking_partner_id'];
$node->booking_bf_gf_nid = empty($values['booking_bf_gf_nid']) ? 0 : $values['booking_bf_gf_nid'];
//allow for user-entered value if the state is not already listed
if ($values['booking_state'] == 'Other') {
$node->booking_state = $values['booking_other_state'];
@@ -1021,9 +1023,11 @@ function booking_load($nodes) {
$query = db_select('booking_person', 'p');
//perform an inner join
$query->join('booking_price', 'pr', 'p.booking_payment_id = pr.pid');
$query->leftJoin('booking_travel', 't', 'p.nid = t.booking_person_nid');
//filter the results and select the appropriate fields
$query->condition('p.nid', array_keys($nodes), 'IN')
->fields('p')
->fields('t')
->fields('pr', array('booking_price', 'booking_price_descrip'));
//get the query result
$result = $query->execute();
@@ -1033,7 +1037,7 @@ function booking_load($nodes) {
//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)));
//watchdog('booking', "<pre>Loading node:\n@info</pre>", array('@info' => print_r( $record, true)));
// run through each result row and add in the needed attributes
foreach ($record as $key => $value)
{
@@ -1074,6 +1078,7 @@ function _booking_insert($node) {
'booking_married' => $node->booking_married,
'booking_partner_name' => $node->booking_partner_name,
'booking_partner_id' => $node->booking_partner_id,
'booking_bf_gf_nid' => $node->booking_bf_gf_nid,
'booking_room_mate1' => $node->booking_room_mate1,
'booking_room_mate2' => $node->booking_room_mate2,
'booking_shirt_size' => empty($node->booking_shirt_size) ? 'N/A' : $node->booking_shirt_size,
@@ -1154,6 +1159,7 @@ function _booking_update($node) {
'booking_married' => ($node->booking_married == 1 ? 'Y' : 'N'),
'booking_partner_name' => $node->booking_partner_name,
'booking_partner_id' => $node->booking_partner_id,
'booking_bf_gf_nid' => $node->booking_bf_gf_nid,
'booking_room_mate1' => $node->booking_room_mate1,
'booking_room_mate2' => $node->booking_room_mate2,
'booking_shirt_size' => $node->booking_shirt_size,
@@ -1356,15 +1362,27 @@ function booking_view($node, $view_mode) {
$price = _booking_is_earlybird() == true ? $price_lookup->booking_price : $price_lookup->booking_late_price;
$payment_type = $price_lookup->booking_price_descrip . ' ($' . $price . ')';
//look up the actual name for a linked partner
if ($node->booking_partner_id != 0)
{
$partner = db_query("Select booking_firstname, booking_lastname from {booking_person} where nid = :nid",
$query = db_query("Select booking_firstname, booking_lastname from {booking_person} where nid = :nid",
array(':nid' => $node->booking_partner_id))
->fetchObject();
$partner_name = $partner->booking_firstname . " " . $partner->booking_lastname;
$partner_name = $query->booking_firstname . " " . $query->booking_lastname;
}
else
$partner_name = "N/A";
//also look up the actual name if a boyfriend/girlfriend is defined
if ($node->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();
@@ -1406,6 +1424,7 @@ function booking_view($node, $view_mode) {
$rows[] = array(t('Married:'), t('!ans', array('!ans' => ($node->booking_married == 'Y' ? 'Yes' : 'No'))));
//$rows[] = array(t("If married, attending partner's name:"), t('!name', array('!name' => $node->booking_partner_name)));
$rows[] = array(t('Linked Partner:'), t($partner_name));
$rows[] = array(t('Linked Boyfriend/Girlfriend:'), t($bf_gf));
$rows[] = array(t('Emergency Contact Name:'), $node->booking_guardian_name);
$rows[] = array(t('Emergency Contact Relationship:'), $node->booking_guardian_type);
$rows[] = array(t('Emergency Contact Phone:'), $node->booking_guardian_phone);

View File

@@ -604,7 +604,6 @@ function booking_studygroups_calculate() {
//check for maximum group size
_booking_loop_carefully($session_count, 'total', $i, $max_people, $group->booking_num_group_sessions, 2);
//assign this attendee to this session if unprocessed so far
if ($current->processed == 0)
{

View File

@@ -513,7 +513,11 @@ function booking_token_info() {
$info['tokens']['booking']['regn-summary'] = array(
'name' => t('Registration Summary'),
'description' => t('Summary of details from user registration.')
);
);
$info['tokens']['booking']['travel-summary'] = array(
'name' => t('Registration Travel Summary'),
'description' => t('Summary of travel details from user registration.')
);
return $info;
}
@@ -623,6 +627,7 @@ function booking_define_personspecific_tokens($node)
$tokens['confirm-payment-link'] = url('confirm/' . $tempid, array('absolute' => TRUE));
$tokens['paypal-total-amount'] = _booking_amount_owing($node->nid, $amount_paid);
$tokens['paypal-deposit-amount'] = _booking_deposit_amount();
$tokens['regn-summary'] = _booking_details_email_summary($node);
$tokens['regn-summary'] = _booking_details_email_summary($node);
$tokens['travel-summary'] = _booking_travelform_email_summary($node);
return $tokens;
}

View File

@@ -77,31 +77,38 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
$booking_dietary = '';
$booking_medical_conditions = '';
$booking_bf_gf = '';
$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)));
//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, booking_partner_id " .
$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();
if ($person)
{
$booking_dietary = $person->booking_dietary;
$booking_medical_conditions = $person->booking_medical_conditions;
$booking_bf_gf = $person->booking_bf_gf;
}
->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',
@@ -123,8 +130,8 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
'#type' => 'radios',
'#title' => t('Transport Type'),
'#options' => $transport_type_options,
'#default_value' => !empty($data->booking_transport_type) ? $data->booking_transport_type : '0',
//'#required' => TRUE,
'#default_value' => !empty($data->booking_transport_type) ? $data->booking_transport_type : NULL,
'#required' => TRUE,
);
/*
@@ -263,12 +270,13 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
//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'] = array(
$form['requirements']['booking_bf_gf_nid'] = array(
'#type' => 'textfield',
'#title' => t('Boyfriend/Girlfriend that you want to be in the same discussion groups as you.'),
'#maxlength' => 180,
'#required' => FALSE,
'#default_value' => !empty($data->booking_bf_gf) ? $data->booking_bf_gf : $booking_bf_gf,
'#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,
);
}
@@ -282,12 +290,41 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
}
function travel_form_validate($form, &$form_state) {
watchdog('booking', 'Travel form: @info', array('@info' => var_export($form_state, TRUE)));
//watchdog('booking', "<pre>Travel form:\n@info</pre>", 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'] == 0)
/*
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')))
);
}
}
}
@@ -340,14 +377,16 @@ function travel_form_submit($form, &$form_state) {
//booking_person related fields
$node->booking_dietary = $values['booking_dietary'];
$node->booking_medical_conditions = $values['booking_medical_conditions'];
$node->booking_bf_gf = empty($values['booking_bf_gf']) ? 'N/A' : $values['booking_bf_gf'];
$node->booking_bf_gf_nid = empty($values['booking_bf_gf_nid']) ? 0 : $values['booking_bf_gf_nid'];
watchdog('booking', "<pre>Travel data to save:\n@info</pre>", array('@info' => print_r( $node, true)));
//store the node
$foo = node_submit(&$node);
$blah = node_save($foo);
//send a confirmation email
_booking_travelform_confirmation_email($node);
_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');
@@ -364,7 +403,7 @@ function travel_load($nodes) {
$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'));
$query->fields('p', array('booking_dietary','booking_medical_conditions','booking_bf_gf_nid'));
$query->condition('tid', array_keys($nodes), 'IN');
$result = $query->execute();
@@ -404,15 +443,19 @@ function travel_insert($node)
))
->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' => $node->booking_bf_gf,
'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)
@@ -444,7 +487,7 @@ function travel_update($node)
->fields(array(
'booking_dietary' => $node->booking_dietary,
'booking_medical_conditions' => $node->booking_medical_conditions,
'booking_bf_gf' => $node->booking_bf_gf,
'booking_bf_gf_nid' => $node->booking_bf_gf_nid,
))
->condition('nid', $node->booking_person_nid)
->execute();
@@ -470,8 +513,19 @@ function travel_view($node, $view_mode) {
"left outer join {booking_travel} t on p.nid = t.booking_person_nid " .
"where p.nid = :nid",
array(':nid' => $node->booking_person_nid))
->fetchObject();
->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();
@@ -488,7 +542,7 @@ function travel_view($node, $view_mode) {
//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:'), $node->booking_bf_gf);
$rows[] = array(t('Boyfriend/Girlfriend:'), $bf_gf);
$node->content['details'] = array(
'#markup' => theme('table', array('header' => $header, 'rows' => $rows)),