From e5b825b83722de87a9cd5d27dc0d44cdd3aed0f5 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Sat, 29 Nov 2014 16:49:57 +1100 Subject: [PATCH] Update passport validation and date parse routine for data import --- booking.helper.inc | 20 ++- booking.import_data.inc | 3 +- booking.paypal.inc | 9 ++ booking.register.inc | 338 ++++++++++++++++++++-------------------- 4 files changed, 193 insertions(+), 177 deletions(-) diff --git a/booking.helper.inc b/booking.helper.inc index 7de1c35..ca86f03 100644 --- a/booking.helper.inc +++ b/booking.helper.inc @@ -62,7 +62,7 @@ function _valid_passport_number($input) { //strip whitespace $passport = preg_replace( '/\s+/', '', $input ); //check for a match - if (preg_match('/^[a-zA-Z]\d{7}$/', $input, $matches)) { + if (preg_match('/^[a-zA-Z]{1,2}\d{7}$/', $input, $matches)) { watchdog('booking', 'Passport number "!passnum" validates since it passed our regexp', array('!passnum' => $input)); return TRUE; @@ -243,9 +243,9 @@ function _datetime_to_ts($date) { } /** - * Function to turn a loosely formatted date into a timestamp + * Function to turn a loosely formatted date into a timestamp, with optional time * - * @param $date in format DD/MM/YYYY HH:mm + * @param $date in format DD/MM/YYYY HH:mm or just DD/MM/YYYY * @return unix timestamp formatted for current time zone */ function _datetime_to_ts_nonstrict($date) { @@ -254,7 +254,13 @@ function _datetime_to_ts_nonstrict($date) { //check for a match if (preg_match($pattern, $date, $matches)) { - $date_split = $matches; + //$date_split = $matches; + $hour = isset($matches[5]) ? $matches[5] : 0; + $minute = isset($matches[6]) ? $matches[6] : 0; + $second = 0; + $month = $matches[2]; + $day = $matches[1]; + $year = $matches[3]; } //return zero now if no matches else @@ -265,12 +271,12 @@ function _datetime_to_ts_nonstrict($date) { date_default_timezone_set(TIMEZONE); $tz = new DateTimeZone(TIMEZONE); - $gmt_ts = mktime($date_split[5], $date_split[6], 0, $date_split[2], $date_split[1], $date_split[3]); + //$gmt_ts = mktime($date_split[5], $date_split[6], 0, $date_split[2], $date_split[1], $date_split[3]); + $gmt_ts = mktime($hour, $minute, $second, $month, $day, $year); $ts = new DateTime("@$gmt_ts"); $ts->setTimezone($tz); - return $ts->format("U"); - + return $ts->format("U"); } /** diff --git a/booking.import_data.inc b/booking.import_data.inc index a4dd385..b04ba1f 100644 --- a/booking.import_data.inc +++ b/booking.import_data.inc @@ -68,8 +68,7 @@ function booking_import_data_admin_submit($form, &$form_state) $result_array = array(); $update_messages = array(); $datetime_fields = array('booking_outflight_origin_ts', 'booking_outflight_destination_ts', 'booking_rtrnflight_origin_ts', - 'booking_rtrnflight_destination_ts'); - + 'booking_rtrnflight_destination_ts','booking_dob', 'booking_passport_expiry_date'); $builtin_fields_to_import = array('nid', 'booking_status'); $custom_fields_to_import = explode(";", variable_get('booking_import_include_fields', '')); $fields_to_import = array_merge($builtin_fields_to_import, $custom_fields_to_import); diff --git a/booking.paypal.inc b/booking.paypal.inc index 9742688..8793df3 100644 --- a/booking.paypal.inc +++ b/booking.paypal.inc @@ -201,6 +201,14 @@ function _booking_process_payment($data) { //if ($total >= $person->booking_total_pay_reqd) if ($amount_owing == 0) { + //set the payment complete flag + db_update('booking_person') + ->fields(array( + 'booking_payment_complete' => 'Y', + )) + ->condition('nid', $nid) + ->execute(); + //this should always be a balance payment type email, since that tells the user that their payment is completed _booking_registration_email($nid, TRUE); @@ -229,6 +237,7 @@ function _booking_process_payment($data) { ->fields(array( 'booking_total_pay_reqd' => $spouse_new_amount_reqd, 'booking_status' => $spouse_status, + 'booking_payment_complete' => 'Y', )) ->condition('nid', $person->booking_partner_id) ->execute(); diff --git a/booking.register.inc b/booking.register.inc index ef1b2a6..151c8b6 100644 --- a/booking.register.inc +++ b/booking.register.inc @@ -367,174 +367,6 @@ function booking_form($node, &$form_state, $inserting = FALSE) { ); } //end not-inserting check - if (variable_get('booking_enable_passport', 0) == 1) - { - $form['passport-details'] = array( - '#type' => 'fieldset', - '#title' => 'Passport Details', - ); - $form['passport-details']['booking_passport_num'] = array( - '#type' => 'textfield', - '#title' => t('Passport Number'), - '#maxlength' => 45, - '#required' => FALSE, - '#default_value' => !empty($data->booking_passport_num) ? $data->booking_passport_num : '' - ); - $form['passport-details']['booking_passport_issue_location'] = array( - '#type' => 'textfield', - '#title' => t('City of Issue (eg Sydney)'), - '#maxlength' => 120, - '#required' => FALSE, - '#default_value' => !empty($data->booking_passport_issue_location) ? $data->booking_passport_issue_location : '' - ); - $form['passport-details']['booking_passport_issue_name'] = array( - '#type' => 'textfield', - '#title' => t('Exact name as listed on passport'), - '#maxlength' => 120, - '#required' => FALSE, - '#default_value' => !empty($data->booking_passport_issue_name) ? $data->booking_passport_issue_name : '' - ); - $form['passport-details']['booking_passport_expiry_date'] = array( - '#type' => 'date_select', - '#title' => t('Passport expiry date'), - '#default_value' => empty($data->booking_passport_expiry_date) ? '' : date("Y-m-d H:i:s", $data->booking_passport_expiry_date), - '#required' => FALSE, - '#date_format' => 'd/m/Y', - //'#date_label_position' => 'within', - '#date_year_range' => '+0:+13' - ); - $form['passport-details']['booking_travel_insurance'] = array( - '#type' => 'textfield', - '#title' => t('Travel insurance policy details'), - '#maxlength' => 120, - '#required' => FALSE, - '#default_value' => !empty($data->booking_travel_insurance) ? $data->booking_travel_insurance : '' - ); - if ($inserting == FALSE) - { - $form['passport-details']['booking_destination_country'] = array( - '#type' => 'textfield', - '#title' => t('Which country is this person going to?'), - '#maxlength' => 120, - '#required' => FALSE, - '#default_value' => !empty($data->booking_destination_country) ? $data->booking_destination_country : '', - ); - - //flights from the conference week to the destination country - $form['outbound-flight-details'] = array( - '#type' => 'fieldset', - '#title' => 'Flight Details (Conference To Destination Country)', - ); - $form['outbound-flight-details']['booking_outflight_bookingnum'] = array( - '#type' => 'textfield', - '#title' => t('Internal Flight Booking Reference (departing conference week)'), - '#maxlength' => 120, - '#required' => FALSE, - '#default_value' => !empty($data->booking_outflight_bookingnum) ? $data->booking_outflight_bookingnum : '', - ); - $form['outbound-flight-details']['booking_outflight_flightnum'] = array( - '#type' => 'textfield', - '#title' => t('Internal Flight Number (departing conference week)'), - '#maxlength' => 120, - '#required' => FALSE, - '#default_value' => !empty($data->booking_outflight_flightnum) ? $data->booking_outflight_flightnum : '', - ); - $form['outbound-flight-details']['booking_outflight_origin'] = array( - '#type' => 'textfield', - '#title' => t('Internal Flight Origin to Destination (departing conference week)'), - '#maxlength' => 120, - '#required' => FALSE, - '#default_value' => !empty($data->booking_outflight_origin) ? $data->booking_outflight_origin : '', - ); - $form['outbound-flight-details']['booking_outflight_origin_ts'] = array( - '#type' => 'date_select', - '#title' => t('Internal flight departure time (local timezone)'), - '#description' => t('Note: 24 hour time - 12:00 is midday'), - '#default_value' => empty($data->booking_outflight_origin_ts) ? '' : date("Y-m-d H:i:s", $data->booking_outflight_origin_ts), - '#date_format' => 'd/m/Y H:i', - '#date_year_range' => '0:+1', - ); - $form['outbound-flight-details']['booking_outflight_connecting_flightnum'] = array( - '#type' => 'textfield', - '#title' => t('Connecting Flight Number (if applicable)'), - '#maxlength' => 120, - '#required' => FALSE, - '#default_value' => !empty($data->booking_outflight_connecting_flightnum) ? $data->booking_outflight_connecting_flightnum : '', - ); - $form['outbound-flight-details']['booking_outflight_destination'] = array( - '#type' => 'textfield', - '#title' => t('Connecting Flight Origin to Destination'), - '#maxlength' => 120, - '#required' => FALSE, - '#default_value' => !empty($data->booking_outflight_destination) ? $data->booking_outflight_destination : '', - ); - $form['outbound-flight-details']['booking_outflight_destination_ts'] = array( - '#type' => 'date_select', - '#title' => t('Internal flight arrival time (local timezone)'), - '#description' => t('Note: 24 hour time - 12:00 is midday'), - '#default_value' => empty($data->booking_outflight_destination_ts) ? '' : date("Y-m-d H:i:s", $data->booking_outflight_destination_ts), - '#date_format' => 'd/m/Y H:i', - '#date_year_range' => '0:+1', - ); - - //flights from the destination country back to conference - $form['inbound-flight-details'] = array( - '#type' => 'fieldset', - '#title' => 'Flight Details (Destination Country Back To Conference)', - ); - $form['inbound-flight-details']['booking_rtrnflight_bookingnum'] = array( - '#type' => 'textfield', - '#title' => t('Internal Flight Booking Reference (returning to conference)'), - '#maxlength' => 120, - '#required' => FALSE, - '#default_value' => !empty($data->booking_rtrnflight_bookingnum) ? $data->booking_rtrnflight_bookingnum : '', - ); - $form['inbound-flight-details']['booking_rtrnflight_flightnum'] = array( - '#type' => 'textfield', - '#title' => t('Internal Flight Number (returning to conference)'), - '#maxlength' => 120, - '#required' => FALSE, - '#default_value' => !empty($data->booking_rtrnflight_flightnum) ? $data->booking_rtrnflight_flightnum : '', - ); - $form['inbound-flight-details']['booking_rtrnflight_origin'] = array( - '#type' => 'textfield', - '#title' => t('Internal Flight Origin to Destination (returning to conference)'), - '#maxlength' => 120, - '#required' => FALSE, - '#default_value' => !empty($data->booking_rtrnflight_origin) ? $data->booking_rtrnflight_origin : '', - ); - $form['inbound-flight-details']['booking_rtrnflight_origin_ts'] = array( - '#type' => 'date_select', - '#title' => t('Internal flight departure time (local timezone)'), - '#description' => t('Note: 24 hour time - 12:00 is midday'), - '#default_value' => empty($data->booking_rtrnflight_origin_ts) ? '' : date("Y-m-d H:i:s", $data->booking_rtrnflight_origin_ts), - '#date_format' => 'd/m/Y H:i', - '#date_year_range' => '0:+1', - ); - $form['inbound-flight-details']['booking_rtrnflight_connecting_flightnum'] = array( - '#type' => 'textfield', - '#title' => t('Connecting Flight Number (if applicable)'), - '#maxlength' => 120, - '#required' => FALSE, - '#default_value' => !empty($data->booking_rtrnflight_connecting_flightnum) ? $data->booking_rtrnflight_connecting_flightnum : '', - ); - $form['inbound-flight-details']['booking_rtrnflight_destination'] = array( - '#type' => 'textfield', - '#title' => t('Connecting Flight Origin to Destination'), - '#maxlength' => 120, - '#required' => FALSE, - '#default_value' => !empty($data->booking_rtrnflight_destination) ? $data->booking_rtrnflight_destination : '', - ); - $form['inbound-flight-details']['booking_rtrnflight_destination_ts'] = array( - '#type' => 'date_select', - '#title' => t('Internal flight arrival time (local timezone)'), - '#description' => t('Note: 24 hour time - 12:00 is midday'), - '#default_value' => empty($data->booking_rtrnflight_destination_ts) ? '' : date("Y-m-d H:i:s", $data->booking_rtrnflight_destination_ts), - '#date_format' => 'd/m/Y H:i', - '#date_year_range' => '0:+1', - ); - } - } //end passport only fields $form['contact-details'] = array( '#type' => 'fieldset', @@ -677,6 +509,175 @@ function booking_form($node, &$form_state, $inserting = FALSE) { '#default_value' => empty($data->booking_medicare) ? '' : $data->booking_medicare ); } + +if (variable_get('booking_enable_passport', 0) == 1) +{ + $form['passport-details'] = array( + '#type' => 'fieldset', + '#title' => 'Passport Details', + ); + $form['passport-details']['booking_passport_num'] = array( + '#type' => 'textfield', + '#title' => t('Passport Number'), + '#maxlength' => 45, + '#required' => FALSE, + '#default_value' => !empty($data->booking_passport_num) ? $data->booking_passport_num : '' + ); + $form['passport-details']['booking_passport_issue_location'] = array( + '#type' => 'textfield', + '#title' => t('City of Issue (eg Sydney)'), + '#maxlength' => 120, + '#required' => FALSE, + '#default_value' => !empty($data->booking_passport_issue_location) ? $data->booking_passport_issue_location : '' + ); + $form['passport-details']['booking_passport_issue_name'] = array( + '#type' => 'textfield', + '#title' => t('Exact name as listed on passport'), + '#maxlength' => 120, + '#required' => FALSE, + '#default_value' => !empty($data->booking_passport_issue_name) ? $data->booking_passport_issue_name : '' + ); + $form['passport-details']['booking_passport_expiry_date'] = array( + '#type' => 'date_select', + '#title' => t('Passport expiry date'), + '#default_value' => empty($data->booking_passport_expiry_date) ? '' : date("Y-m-d H:i:s", $data->booking_passport_expiry_date), + '#required' => FALSE, + '#date_format' => 'd/m/Y', + //'#date_label_position' => 'within', + '#date_year_range' => '+0:+13' + ); + $form['passport-details']['booking_travel_insurance'] = array( + '#type' => 'textfield', + '#title' => t('Travel insurance policy details'), + '#maxlength' => 120, + '#required' => FALSE, + '#default_value' => !empty($data->booking_travel_insurance) ? $data->booking_travel_insurance : '' + ); + if ($inserting == FALSE) + { + $form['passport-details']['booking_destination_country'] = array( + '#type' => 'textfield', + '#title' => t('Which country is this person going to?'), + '#maxlength' => 120, + '#required' => FALSE, + '#default_value' => !empty($data->booking_destination_country) ? $data->booking_destination_country : '', + ); + + //flights from the conference week to the destination country + $form['outbound-flight-details'] = array( + '#type' => 'fieldset', + '#title' => 'Flight Details (Conference To Destination Country)', + ); + $form['outbound-flight-details']['booking_outflight_bookingnum'] = array( + '#type' => 'textfield', + '#title' => t('Internal Flight Booking Reference (departing conference week)'), + '#maxlength' => 120, + '#required' => FALSE, + '#default_value' => !empty($data->booking_outflight_bookingnum) ? $data->booking_outflight_bookingnum : '', + ); + $form['outbound-flight-details']['booking_outflight_flightnum'] = array( + '#type' => 'textfield', + '#title' => t('Internal Flight Number (departing conference week)'), + '#maxlength' => 120, + '#required' => FALSE, + '#default_value' => !empty($data->booking_outflight_flightnum) ? $data->booking_outflight_flightnum : '', + ); + $form['outbound-flight-details']['booking_outflight_origin'] = array( + '#type' => 'textfield', + '#title' => t('Internal Flight Origin to Destination (departing conference week)'), + '#maxlength' => 120, + '#required' => FALSE, + '#default_value' => !empty($data->booking_outflight_origin) ? $data->booking_outflight_origin : '', + ); + $form['outbound-flight-details']['booking_outflight_origin_ts'] = array( + '#type' => 'date_select', + '#title' => t('Internal flight departure time (local timezone)'), + '#description' => t('Note: 24 hour time - 12:00 is midday'), + '#default_value' => empty($data->booking_outflight_origin_ts) ? '' : date("Y-m-d H:i:s", $data->booking_outflight_origin_ts), + '#date_format' => 'd/m/Y H:i', + '#date_year_range' => '0:+1', + ); + $form['outbound-flight-details']['booking_outflight_connecting_flightnum'] = array( + '#type' => 'textfield', + '#title' => t('Connecting Flight Number (if applicable)'), + '#maxlength' => 120, + '#required' => FALSE, + '#default_value' => !empty($data->booking_outflight_connecting_flightnum) ? $data->booking_outflight_connecting_flightnum : '', + ); + $form['outbound-flight-details']['booking_outflight_destination'] = array( + '#type' => 'textfield', + '#title' => t('Connecting Flight Origin to Destination'), + '#maxlength' => 120, + '#required' => FALSE, + '#default_value' => !empty($data->booking_outflight_destination) ? $data->booking_outflight_destination : '', + ); + $form['outbound-flight-details']['booking_outflight_destination_ts'] = array( + '#type' => 'date_select', + '#title' => t('Internal flight arrival time (local timezone)'), + '#description' => t('Note: 24 hour time - 12:00 is midday'), + '#default_value' => empty($data->booking_outflight_destination_ts) ? '' : date("Y-m-d H:i:s", $data->booking_outflight_destination_ts), + '#date_format' => 'd/m/Y H:i', + '#date_year_range' => '0:+1', + ); + + //flights from the destination country back to conference + $form['inbound-flight-details'] = array( + '#type' => 'fieldset', + '#title' => 'Flight Details (Destination Country Back To Conference)', + ); + $form['inbound-flight-details']['booking_rtrnflight_bookingnum'] = array( + '#type' => 'textfield', + '#title' => t('Internal Flight Booking Reference (returning to conference)'), + '#maxlength' => 120, + '#required' => FALSE, + '#default_value' => !empty($data->booking_rtrnflight_bookingnum) ? $data->booking_rtrnflight_bookingnum : '', + ); + $form['inbound-flight-details']['booking_rtrnflight_flightnum'] = array( + '#type' => 'textfield', + '#title' => t('Internal Flight Number (returning to conference)'), + '#maxlength' => 120, + '#required' => FALSE, + '#default_value' => !empty($data->booking_rtrnflight_flightnum) ? $data->booking_rtrnflight_flightnum : '', + ); + $form['inbound-flight-details']['booking_rtrnflight_origin'] = array( + '#type' => 'textfield', + '#title' => t('Internal Flight Origin to Destination (returning to conference)'), + '#maxlength' => 120, + '#required' => FALSE, + '#default_value' => !empty($data->booking_rtrnflight_origin) ? $data->booking_rtrnflight_origin : '', + ); + $form['inbound-flight-details']['booking_rtrnflight_origin_ts'] = array( + '#type' => 'date_select', + '#title' => t('Internal flight departure time (local timezone)'), + '#description' => t('Note: 24 hour time - 12:00 is midday'), + '#default_value' => empty($data->booking_rtrnflight_origin_ts) ? '' : date("Y-m-d H:i:s", $data->booking_rtrnflight_origin_ts), + '#date_format' => 'd/m/Y H:i', + '#date_year_range' => '0:+1', + ); + $form['inbound-flight-details']['booking_rtrnflight_connecting_flightnum'] = array( + '#type' => 'textfield', + '#title' => t('Connecting Flight Number (if applicable)'), + '#maxlength' => 120, + '#required' => FALSE, + '#default_value' => !empty($data->booking_rtrnflight_connecting_flightnum) ? $data->booking_rtrnflight_connecting_flightnum : '', + ); + $form['inbound-flight-details']['booking_rtrnflight_destination'] = array( + '#type' => 'textfield', + '#title' => t('Connecting Flight Origin to Destination'), + '#maxlength' => 120, + '#required' => FALSE, + '#default_value' => !empty($data->booking_rtrnflight_destination) ? $data->booking_rtrnflight_destination : '', + ); + $form['inbound-flight-details']['booking_rtrnflight_destination_ts'] = array( + '#type' => 'date_select', + '#title' => t('Internal flight arrival time (local timezone)'), + '#description' => t('Note: 24 hour time - 12:00 is midday'), + '#default_value' => empty($data->booking_rtrnflight_destination_ts) ? '' : date("Y-m-d H:i:s", $data->booking_rtrnflight_destination_ts), + '#date_format' => 'd/m/Y H:i', + '#date_year_range' => '0:+1', + ); + } +} //end passport only fields if (variable_get('booking_enable_helpareas', 1) == 1) { @@ -1856,6 +1857,7 @@ function booking_view($node, $view_mode) { $rows[] = array(t('Payment Type Selected:'), t('!amount_paid', array('!amount_paid' => $payment_type))); $rows[] = array(t('Amount Paid:'), t('!amount_paid', array('!amount_paid' => $node->booking_amount_paid))); + $rows[] = array(t('Payment Complete Flag:'), t('!ans', array('!ans' => $node->booking_payment_complete == 'Y' ? 'Yes' : 'No'))); $rows[] = array(t('Total Amount Due:'), t('!amount_paid', array('!amount_paid' => $node->booking_total_pay_reqd))); $rows[] = array(t('Refund Due:'), t('!amount_due', array('!amount_due' => $node->booking_refund_due))); $rows[] = array(t('Refund Processed:'), t('!ans', array('!ans' => ($node->booking_refund_processed == 'Y' ? 'Yes' : 'No'))));