Update passport validation and date parse routine for data import

This commit is contained in:
2014-11-29 16:49:57 +11:00
parent cefdfd3afc
commit e5b825b837
4 changed files with 193 additions and 177 deletions

View File

@@ -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");
}
/**

View File

@@ -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);

View File

@@ -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();

View File

@@ -367,8 +367,151 @@ function booking_form($node, &$form_state, $inserting = FALSE) {
);
} //end not-inserting check
if (variable_get('booking_enable_passport', 0) == 1)
$form['contact-details'] = array(
'#type' => 'fieldset',
'#title' => 'Contact details',
);
$form['contact-details']['booking_email'] = array(
'#type' => 'textfield',
'#title' => t('E-mail address'),
'#maxlength' => 100,
'#required' => TRUE,
'#default_value' => !empty($data->booking_email) ? $data->booking_email : ''
);
$form['contact-details']['booking_phone'] = array(
'#type' => 'textfield',
'#title' => t('Home Phone Number'),
'#maxlength' => 30,
'#size' => 35,
'#required' => FALSE,
'#default_value' => !empty($data->booking_phone) ? $data->booking_phone : ''
);
$form['contact-details']['booking_mobile'] = array(
'#type' => 'textfield',
'#title' => t('Mobile Phone Number'),
'#size' => 35,
'#maxlength' => 30,
'#required' => FALSE,
'#default_value' => !empty($data->booking_mobile) ? $data->booking_mobile : ''
);
$form['contact-details']['booking_street'] = array(
'#type' => 'textfield',
'#title' => t('Street Address'),
'#maxlength' => 50,
'#required' => TRUE,
'#default_value' => !empty($data->booking_street) ? $data->booking_street : ''
);
$form['contact-details']['booking_suburb'] = array(
'#type' => 'textfield',
'#title' => t('Suburb'),
'#maxlength' => 50,
'#required' => TRUE,
'#default_value' => !empty($data->booking_suburb) ? $data->booking_suburb : ''
);
if ($inserting == TRUE)
{
$form['contact-details']['booking_state'] = array(
'#type' => 'select',
'#title' => t('State'),
'#required' => TRUE,
'#default_value' => !empty($data->booking_state) ? $data->booking_state : BOOKING_DEFAULT_STATE,
'#options' => _booking_state_options(),
);
$form['contact-details']['booking_other_state'] = array(
'#type' => 'textfield',
'#title' => t('Please specify state'),
'#maxlength' => 50,
'#states' => array(
// Only show this field when the 'booking_state' is set to other.
'visible' => array(
':input[name="booking_state"]' => array('value' => 'Other'),
),
),
'#default_value' => '',
);
} else {
//when modifying the node just show the textfield
$form['contact-details']['booking_state'] = array(
'#type' => 'textfield',
'#title' => t('State'),
'#maxlength' => 50,
'#default_value' => !empty($data->booking_state) ? $data->booking_state : '',
);
}
$form['contact-details']['booking_postcode'] = array(
'#type' => 'textfield',
'#title' => t('Postal/Zip code'),
'#maxlength' => 8,
'#size' => 10,
'#required' => TRUE,
'#default_value' => !empty($data->booking_postcode) ? $data->booking_postcode : ''
);
$form['contact-details']['booking_country'] = array(
'#type' => 'select',
'#title' => t('Country'),
'#required' => TRUE,
'#default_value' => variable_get('booking_country', empty($data->booking_country) ? variable_get('booking_default_country') : $data->booking_country),
'#options' => _booking_country_options(),
);
//emergency contact details
$form['emergency'] = array(
'#type' => 'fieldset',
'#title' => 'Emergency Contact Details',
'#description' => 'Please enter contact details for use in case of emergency',
);
$form['emergency']['booking_guardian_name'] = array(
'#type' => 'textfield',
'#title' => t('Parent/Guardian Name'),
'#maxlength' => 100,
'#required' => TRUE,
'#default_value' => empty($data->booking_guardian_name) ? '' : $data->booking_guardian_name
);
$form['emergency']['booking_guardian_type'] = array(
'#type' => 'radios',
'#title' => t('Relation to you'),
'#options' => $emergency_contact_type_options,
'#default_value' => empty($data->booking_guardian_type) ? 'parent' : $data->booking_guardian_type,
'#required' => TRUE
);
$form['emergency']['booking_guardian_phone'] = array(
'#type' => 'textfield',
'#title' => t('Contact Number'),
'#maxlength' => 30,
'#size' => 30,
'#required' => TRUE,
'#default_value' => empty($data->booking_guardian_phone) ? '' : $data->booking_guardian_phone
);
$form['emergency']['booking_guardian_phone_alt'] = array(
'#type' => 'textfield',
'#title' => t('Alternate Contact Number'),
'#maxlength' => 30,
'#size' => 30,
'#required' => FALSE,
'#default_value' => empty($data->booking_guardian_phone_alt) ? '' : $data->booking_guardian_phone_alt
);
if (variable_get('booking_enable_medicare', 1) == 1)
{
$form['emergency']['booking_medicare'] = array(
'#type' => 'textfield',
'#title' => t('Your Medicare Number'),
'#maxlength' => 15,
'#size' => 15,
'#required' => 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',
@@ -534,149 +677,7 @@ function booking_form($node, &$form_state, $inserting = FALSE) {
'#date_year_range' => '0:+1',
);
}
} //end passport only fields
$form['contact-details'] = array(
'#type' => 'fieldset',
'#title' => 'Contact details',
);
$form['contact-details']['booking_email'] = array(
'#type' => 'textfield',
'#title' => t('E-mail address'),
'#maxlength' => 100,
'#required' => TRUE,
'#default_value' => !empty($data->booking_email) ? $data->booking_email : ''
);
$form['contact-details']['booking_phone'] = array(
'#type' => 'textfield',
'#title' => t('Home Phone Number'),
'#maxlength' => 30,
'#size' => 35,
'#required' => FALSE,
'#default_value' => !empty($data->booking_phone) ? $data->booking_phone : ''
);
$form['contact-details']['booking_mobile'] = array(
'#type' => 'textfield',
'#title' => t('Mobile Phone Number'),
'#size' => 35,
'#maxlength' => 30,
'#required' => FALSE,
'#default_value' => !empty($data->booking_mobile) ? $data->booking_mobile : ''
);
$form['contact-details']['booking_street'] = array(
'#type' => 'textfield',
'#title' => t('Street Address'),
'#maxlength' => 50,
'#required' => TRUE,
'#default_value' => !empty($data->booking_street) ? $data->booking_street : ''
);
$form['contact-details']['booking_suburb'] = array(
'#type' => 'textfield',
'#title' => t('Suburb'),
'#maxlength' => 50,
'#required' => TRUE,
'#default_value' => !empty($data->booking_suburb) ? $data->booking_suburb : ''
);
if ($inserting == TRUE)
{
$form['contact-details']['booking_state'] = array(
'#type' => 'select',
'#title' => t('State'),
'#required' => TRUE,
'#default_value' => !empty($data->booking_state) ? $data->booking_state : BOOKING_DEFAULT_STATE,
'#options' => _booking_state_options(),
);
$form['contact-details']['booking_other_state'] = array(
'#type' => 'textfield',
'#title' => t('Please specify state'),
'#maxlength' => 50,
'#states' => array(
// Only show this field when the 'booking_state' is set to other.
'visible' => array(
':input[name="booking_state"]' => array('value' => 'Other'),
),
),
'#default_value' => '',
);
} else {
//when modifying the node just show the textfield
$form['contact-details']['booking_state'] = array(
'#type' => 'textfield',
'#title' => t('State'),
'#maxlength' => 50,
'#default_value' => !empty($data->booking_state) ? $data->booking_state : '',
);
}
$form['contact-details']['booking_postcode'] = array(
'#type' => 'textfield',
'#title' => t('Postal/Zip code'),
'#maxlength' => 8,
'#size' => 10,
'#required' => TRUE,
'#default_value' => !empty($data->booking_postcode) ? $data->booking_postcode : ''
);
$form['contact-details']['booking_country'] = array(
'#type' => 'select',
'#title' => t('Country'),
'#required' => TRUE,
'#default_value' => variable_get('booking_country', empty($data->booking_country) ? variable_get('booking_default_country') : $data->booking_country),
'#options' => _booking_country_options(),
);
//emergency contact details
$form['emergency'] = array(
'#type' => 'fieldset',
'#title' => 'Emergency Contact Details',
'#description' => 'Please enter contact details for use in case of emergency',
);
$form['emergency']['booking_guardian_name'] = array(
'#type' => 'textfield',
'#title' => t('Parent/Guardian Name'),
'#maxlength' => 100,
'#required' => TRUE,
'#default_value' => empty($data->booking_guardian_name) ? '' : $data->booking_guardian_name
);
$form['emergency']['booking_guardian_type'] = array(
'#type' => 'radios',
'#title' => t('Relation to you'),
'#options' => $emergency_contact_type_options,
'#default_value' => empty($data->booking_guardian_type) ? 'parent' : $data->booking_guardian_type,
'#required' => TRUE
);
$form['emergency']['booking_guardian_phone'] = array(
'#type' => 'textfield',
'#title' => t('Contact Number'),
'#maxlength' => 30,
'#size' => 30,
'#required' => TRUE,
'#default_value' => empty($data->booking_guardian_phone) ? '' : $data->booking_guardian_phone
);
$form['emergency']['booking_guardian_phone_alt'] = array(
'#type' => 'textfield',
'#title' => t('Alternate Contact Number'),
'#maxlength' => 30,
'#size' => 30,
'#required' => FALSE,
'#default_value' => empty($data->booking_guardian_phone_alt) ? '' : $data->booking_guardian_phone_alt
);
if (variable_get('booking_enable_medicare', 1) == 1)
{
$form['emergency']['booking_medicare'] = array(
'#type' => 'textfield',
'#title' => t('Your Medicare Number'),
'#maxlength' => 15,
'#size' => 15,
'#required' => FALSE,
'#default_value' => empty($data->booking_medicare) ? '' : $data->booking_medicare
);
}
} //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'))));