diff --git a/booking.admin.inc b/booking.admin.inc index b1d2f8f..52f62d6 100644 --- a/booking.admin.inc +++ b/booking.admin.inc @@ -194,7 +194,14 @@ function booking_admin() { '#default_value' => variable_get('booking_dietary_text_definition', ''), '#description' => 'Text to use if attendee may not specify dietary requirements (as above).', ); - + $form['misc']['booking_csv_exclude_fields'] = array ( + '#type' => 'textfield', + '#title' => t('Fields to exclude from CSV report'), + '#default_value' => variable_get('booking_csv_exclude_fields', ''), + '#description' => 'Separate each field with a semi-colon. Field names as per database schema.', + '#size' => 150, + '#maxlength' => 500, + ); return system_settings_form($form); } diff --git a/booking.emails.inc b/booking.emails.inc index 3224af5..461cc83 100644 --- a/booking.emails.inc +++ b/booking.emails.inc @@ -39,8 +39,9 @@ $params['subject'] = $subject; $params['body'] = $body; + $params['headers']['Bcc'] = "it@coadcorp.com, " . variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from'))); drupal_mail('booking', 'registration_mail', $to, $language, $params, $from); - drupal_mail('booking', 'registration_mail', 'it@coadcorp.com', $language, $params, $from); + //drupal_mail('booking', 'registration_mail', 'it@coadcorp.com', $language, $params, $from); //send a notification email if we didn't automatically send one earlier if (variable_get('booking_auto_confirm_email', 0) == 1) @@ -142,6 +143,7 @@ function _booking_balance_payment_email($nid) $to = $node->booking_email; $subject = t('!event Payment Required', 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 for a married couple only if we're combining pricing for couples if (variable_get('booking_enable_combined_pricing', 0) == 1 && $node->booking_partner_id > 0) @@ -157,9 +159,10 @@ function _booking_balance_payment_email($nid) //send the email drupal_mail('booking', 'registration_mail_bal_outstanding', $to, $language, $params, $from); - 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"; + //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); } /** @@ -190,15 +193,18 @@ function _booking_custom_email($nid, $email_type) $to = $node->booking_email; $subject = token_replace(variable_get($email_subject_variable, t('!event', array('!event' => $event->booking_eventname))), $tokens); $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($email_body_variable), $tokens); - //send the email + //send the email to the person 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); + //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); } @@ -226,15 +232,16 @@ function _booking_promoted_from_waitinglist_email($nid) $to = $node->booking_email; $subject = t('!event Position Available', 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_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', 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); } @@ -263,15 +270,16 @@ function _booking_demoted_to_notcoming_email($nid) $subject = token_replace(variable_get('booking_email_notcoming_demotion_subject', t('!event', array('!event' => $event->booking_eventname))), $tokens); //$subject = t('!event withdrawal confirmation', 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_notcoming_demotion'), $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', 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); } diff --git a/booking.helper.inc b/booking.helper.inc index ffcdb57..de662fa 100644 --- a/booking.helper.inc +++ b/booking.helper.inc @@ -425,7 +425,7 @@ function _booking_amount_paid($nid, $person = NULL) //check for a spouse if ($person->booking_partner_id > 0) { - watchdog('booking', "Checking total paid for married person"); + //watchdog('booking', "Checking total paid for married person"); //if we're combining the payment for married couples if (variable_get('booking_enable_combined_pricing', 0) == 1) @@ -446,7 +446,7 @@ function _booking_amount_paid($nid, $person = NULL) foreach ($query as $payment) $amount_paid += ($payment->booking_mc_gross - $payment->booking_mc_fee); - watchdog('booking', "Total amount paid according to paypal payments table is " . $amount_paid); + //watchdog('booking', "Total amount paid according to paypal payments table is " . $amount_paid); //if there were no results, $amount_paid will still be 0 if ($amount_paid == 0) @@ -460,12 +460,12 @@ function _booking_amount_paid($nid, $person = NULL) array(':nid' => $person->booking_partner_id)) ->fetchObject(); $amount_paid = $person->booking_amount_paid + $spouse->booking_amount_paid; - watchdog('booking', "Total combined payments for couple based on totals in booking_person table is " . $amount_paid); + //watchdog('booking', "Total combined payments for couple based on totals in booking_person table is " . $amount_paid); } else { $amount_paid = $person->booking_amount_paid; - watchdog('booking', "Total amount paid for individual based on totals in booking_person table is " . $amount_paid); + //watchdog('booking', "Total amount paid for individual based on totals in booking_person table is " . $amount_paid); } } @@ -488,7 +488,7 @@ function _booking_amount_paid($nid, $person = NULL) // $amount_paid = $person->booking_amount_paid; } - watchdog('booking', "Total amount already paid for this registration " . $nid . " is " . $amount_paid); + //watchdog('booking', "Total amount already paid for this registration " . $nid . " is " . $amount_paid); return $amount_paid; } @@ -501,7 +501,7 @@ function _booking_amount_owing($nid, $amount_paid = 0) //fetch details about the person $person = db_query("SELECT price.booking_price, price.booking_late_price, person.booking_payment_id, " . - "person.booking_total_pay_reqd, person.booking_amount_paid, person.booking_partner_id " . + "person.booking_total_pay_reqd, person.booking_amount_paid, person.booking_partner_id, person.booking_country " . "FROM {booking_person} person, {booking_price} price " . "WHERE person.nid = :nid " . "AND person.booking_payment_id = price.pid", @@ -514,12 +514,12 @@ function _booking_amount_owing($nid, $amount_paid = 0) else $total_due = $person->booking_late_price; - watchdog('booking', "Total amount due for this registration " . $nid . " is " . $total_due); + //watchdog('booking', "Total amount due for this registration " . $nid . " is " . $total_due); //if we didn't get the amount paid as a command line parameter, check it now if ($amount_paid == 0) { - watchdog('booking', "Checking total amount already paid by " . $nid); + //watchdog('booking', "Checking total amount already paid by " . $nid); $amount_paid = _booking_amount_paid($nid, $person); } @@ -595,7 +595,7 @@ function _booking_amount_owing($nid, $amount_paid = 0) if ($amount_paid >= $total_due) { - watchdog('booking', "This person doesn't owe any money: @info", array('@info' => var_export($person, TRUE))); + //watchdog('booking', "This person doesn't owe any money: @info", array('@info' => var_export($person, TRUE))); return 0; } @@ -605,7 +605,11 @@ function _booking_amount_owing($nid, $amount_paid = 0) //add the 30 cent fixed cost $amount_owing = $total_due - $amount_paid + 0.3; //and the 2.4 percent transaction fee - $amount_owing = $amount_owing / (1 - 0.024); + if ($person->booking_country === "Australia") + $amount_owing = $amount_owing / (1 - 0.024); + //paypal charges 3.4 percent if they're doing a currency conversion + else + $amount_owing = $amount_owing / (1 - 0.034); } else $amount_owing = $total_due - $amount_paid; diff --git a/booking.module b/booking.module index 19a1482..6bfecac 100644 --- a/booking.module +++ b/booking.module @@ -103,7 +103,16 @@ function booking_permission() { ), 'edit study groups' => array( 'title' => t('Edit study groups'), - ), + ), + 'create_travel_forms' => array( + 'title' => t('Create a new travel form entry'), + ), + 'view_travel_forms' => array( + 'title' => t('View all travel forms'), + ), + 'edit_travel_forms' => array( + 'title' => t('Edit all travel forms'), + ), ); } @@ -188,6 +197,7 @@ function booking_menu() { //'type' => MENU_LOCAL_TASK, ); + //pages for attendees to fill out information $items['booking'] = array( 'title' => $bookingTitle . ' Booking Form', 'page callback' => 'booking_register_page', @@ -201,7 +211,6 @@ function booking_menu() { 'access arguments' => array('access booking form'), 'type' => MENU_CALLBACK, ); - $items['balance/%'] = array( 'title' => 'Registration Final Payment', @@ -210,6 +219,15 @@ function booking_menu() { 'access arguments' => array('access booking form'), 'type' => MENU_CALLBACK, ); + + $items['travel/%'] = array( + 'title' => 'Travel Details Page', + 'page callback' => 'booking_travel_page', + 'page arguments' => array(3), //include the temporary id + 'access arguments' => array('access booking form'), + 'type' => MENU_SUGGESTED_ITEM, + ); + $items['variety'] = array( 'title' => $bookingTitle . ' Variety Sessions', 'page callback' => 'drupal_get_form', @@ -424,8 +442,13 @@ function booking_node_info() { 'booking' => array( 'name' => t('Registration'), 'base' => 'booking', - 'description' => t('This node represents a booking into an event.'), - ) + 'description' => t('This node represents a registration for an event.'), + ), + 'travel' => array( + 'name' => t('Travel Form'), + 'base' => 'travel', + 'description' => t('This node represents a travel details form for an event registration.'), + ) ); } @@ -435,7 +458,8 @@ function booking_node_info() { */ function booking_node_access($node, $op, $account) { $type = is_string($node) ? $node : $node->type; - + + //check access levels for a booking node if ($type == 'booking' && in_array($type, node_permissions_get_configured_types())) { //watchdog('booking', "Booking node_access processing user id '!account' performing operation !op for node type !type. @info", // array('!account' => $account->uid, '!op' => $op, '!type' => $type, '@info' => var_export($account, TRUE))); @@ -469,6 +493,32 @@ function booking_node_access($node, $op, $account) { array('!account' => $account->uid, '!op' => $op, '!type' => $type, '@info' => var_export($account, TRUE))); return NODE_ACCESS_DENY; } + //Check access levels for travel form node + elseif ($type == 'travel' && in_array($type, node_permissions_get_configured_types())) + { + if ($op == 'view') + { + if (user_access('view_travel_forms', $account)) + return NODE_ACCESS_ALLOW; + } + elseif ($op == 'create') + { + if (user_access('create_travel_forms', $account)) + return NODE_ACCESS_ALLOW; + } + elseif ($op == 'update' || $op == 'delete') + { + if (user_access('edit_travel_forms', $account)) + return NODE_ACCESS_ALLOW; + } + + //no permission to view this information + //watchdog('booking', "Booking node_access denying uid !account performing operation !op. @info", + // array('!account' => $account->uid, '!op' => $op, '@info' => var_export($account, TRUE))); + //watchdog('booking', "Booking node_access denying user id '!account' performing operation !op for node type !type. @info", + // array('!account' => $account->uid, '!op' => $op, '!type' => $type, '@info' => var_export($account, TRUE))); + return NODE_ACCESS_DENY; + } /* else { @@ -505,6 +555,12 @@ function booking_theme() { function booking_mail($key, &$message, $params) { $message['subject'] = $params['subject']; $message['body'][] = $params['body']; + + //reference https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_mail/7 + if (isset($params['headers']) && is_array($params['headers'])) { + $message['headers'] += $params['headers']; + } + } /** diff --git a/booking.reports.inc b/booking.reports.inc index baddf37..0c082be 100644 --- a/booking.reports.inc +++ b/booking.reports.inc @@ -399,7 +399,15 @@ function booking_csv_report() { $delimiter_esc = preg_quote($delimiter, '/'); $enclosure_esc = preg_quote($enclosure, '/'); - $fields_to_skip = array('booking_payment_id', 'booking_event_id', 'booking_tempid'); + /* + $fields_to_skip = array('booking_payment_id', 'booking_event_id', 'booking_skills_childminding', 'booking_passport_issue_date', + 'booking_passport_expiry_date', 'booking_passport_num', 'booking_passport_num', 'booking_mission_experience_details', + 'booking_passport_issue_location', 'booking_passport_issue_name', 'booking_skills_builder', 'booking_skills_cooking', + 'booking_skills_language', 'booking_skills_language_details', 'booking_skills_other', 'booking_skills_other_details'); + */ + $builtin_fields_to_skip = array('booking_event_id'); + $custom_fields_to_skip = explode(";", variable_get('booking_csv_exclude_fields', '')); + $fields_to_skip = array_merge($builtin_fields_to_skip, $custom_fields_to_skip); //query the db /* @@ -438,6 +446,9 @@ function booking_csv_report() { //add in a special column for a processed version of the date of birth if (strcmp($key,"booking_dob") == 0) $header_array[] = "booking_dob_processed"; + //add in a calculated field for amount owing + if (strcmp($key, "nid") == 0) + $header_array[] = "booking_amount_owing"; } $header = implode( $delimiter, $header_array ); @@ -488,6 +499,14 @@ function booking_csv_report() { continue; } + //add in the amount owing using the nid as the key + if ($key == 'nid') + { + $output[] = $value; + $output[] = _booking_amount_owing($value); + continue; + } + // Enclose fields containing $delimiter, $enclosure or whitespace if ( $encloseAll || preg_match( "/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $value ) ) { $output[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $value) . $enclosure; @@ -496,6 +515,8 @@ function booking_csv_report() { $output[] = $field; } } + + $row = implode($delimiter, $output) . "\n"; diff --git a/booking.tokens.inc b/booking.tokens.inc index be582e5..5a7cb77 100644 --- a/booking.tokens.inc +++ b/booking.tokens.inc @@ -280,7 +280,27 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text '#description' => t(''), '#default_value' => variable_get('booking_waitingpage_post_text', $booking_waitingpage_post_text), ); - + + /*Text for the Travel Form page*/ + $form['travel'] = array( + '#type' => 'fieldset', + '#title' => 'Travel Form Text Definitions', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['travel']['booking_travelform_page'] = array( + '#title' => t('Text to use at the start of the travel form.'), + '#type' => 'textarea', + '#description' => t(''), + '#default_value' => variable_get('booking_travelform_page', ''), + ); + $form['travel']['booking_travelform_completed_page'] = array( + '#title' => t('Text to use on the travel form if the form has already been submitted.'), + '#type' => 'textarea', + '#description' => t(''), + '#default_value' => variable_get('booking_travelform_completed_page', ''), + ); + /*Text for emails*/ $form['emails'] = array( '#type' => 'fieldset', diff --git a/booking.travel.inc b/booking.travel.inc new file mode 100644 index 0000000..9cc5c5d --- /dev/null +++ b/booking.travel.inc @@ -0,0 +1,495 @@ + arg(1))) + ->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 .= t("


Hi !firstname !lastname. Our records indicate you or your spouse have already completed the travel details form for !event. " . + "Please contact us if you need change any of your travel details.

", + array('!firstname' => $person->booking_firstname, '!lastname' => $person->booking_lastname, '!event' => $event->booking_eventname)); + $return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output)); + } + //they haven't submitted a travel form yet + else + { + $output = token_replace(variable_get('booking_travelform_page'), $tokens); + + + //check for married couple + //if ($person->booking_partner_id > 0) { + // $output .= t("


Hi Mr and Mrs !lastname. Please enter your travel details for !event below.

", + // array('!lastname' => $person->booking_lastname, '!event' => $event->booking_eventname)); + //} + //else { + // $output .= t("


Hi !firstname !lastname. Please enter your travel details for !event below.

", + // array('!firstname' => $person->booking_firstname, '!lastname' => $person->booking_lastname, '!event' => $event->booking_eventname)); + //} + + $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 = ''; + + if (!empty($node)) + { + $data = $node; + watchdog('booking', 'Travel form loading data from saved node: @info', array('@info' => var_export($node, TRUE))); + } + 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 " . + "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; + } + //watchdog('booking', 'Booking registration form loading data from form submission: @info', array('@info' => var_export($form_state, TRUE))); + } + + $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 : '', + '#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, + ); + $form['requirements']['booking_bf_gf'] = 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, + ); + + if ($inserting == TRUE) { + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + } + return $form; +} + +function travel_form_validate($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'])) { + //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 = $values['booking_bf_gf']; + + //store the node + $foo = node_submit(&$node); + $blah = node_save($foo); + + //send a confirmation email + _booking_travelform_confirmation_email($node); + + //TODO: Put this back in after testing +/* + //clear the temp id + db_update('booking_person') + ->fields(array( + 'booking_tempid' => '', + )) + ->condition('nid', $values['personid']) + ->execute(); + +*/ + 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')); + $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(); + + //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, + )) + ->condition('nid', $node->booking_person_nid) + ->execute(); +} + +function travel_update($node) +{ + watchdog('booking', 'Updating travel form booking_travel table: @info', array('@info' => var_export($node, TRUE))); + db_update('booking_travel') + ->fields(array( + 'tid' => $node->nid, + 'booking_person_nid' => $node->booking_person_nid, + 'booking_transport_type' => $node->booking_transport_type, + 'booking_transport_from_morriset_reqd' => $node->booking_transport_from_morriset_reqd == 'Yes' ? 1 : 0, + //'booking_transport_to_morriset_reqd' => $node->booking_transport_to_morriset_reqd, + 'booking_flightnum_inbound' => $node->booking_flightnum_inbound, + 'booking_flight_datetime_inbound' => _datetime_to_ts($node->booking_flight_datetime_inbound), + 'booking_flightnum_outbound' => $node->booking_flightnum_outbound, + 'booking_flight_datetime_outbound' => _datetime_to_ts($node->booking_flight_datetime_outbound), + 'booking_accom_before_reqd' => $node->booking_accom_before_reqd == 'Yes' ? 1 : 0, + //'booking_accom_before_staying_with' => $node->booking_accom_before_staying_with, + 'booking_accom_after_reqd' => $node->booking_accom_after_reqd == 'Yes' ? 1 : 0, + //'booking_accom_after_staying_with' => $node->booking_accom_after_staying_with, + )) + ->condition('tid', $node->nid) + ->execute(); + + watchdog('booking', 'Updating travel form booking_person table'); + + //update the booking_person fields + db_update('booking_person') + ->fields(array( + 'booking_dietary' => $node->booking_dietary, + 'booking_medical_conditions' => $node->booking_medical_conditions, + 'booking_bf_gf' => $node->booking_bf_gf, + )) + ->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 booking_firstname, booking_lastname " . + "FROM {booking_person} " . + "WHERE nid = :nid ", + array(':nid' => $node->booking_person_nid)) + ->fetchObject(); + + $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:'), $node->booking_bf_gf); + + $node->content['details'] = array( + '#markup' => theme('table', array('header' => $header, 'rows' => $rows)), + '#weight' => 1, + ); + return $node; +} \ No newline at end of file