Extra flight fields, improved data import function
This commit is contained in:
@@ -242,6 +242,37 @@ function _datetime_to_ts($date) {
|
||||
//return mktime($date_split[5], $date_split[6], 0, $date_split[2], $date_split[3], $date_split[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to turn a loosely formatted date into a timestamp
|
||||
*
|
||||
* @param $date in format DD/MM/YYYY HH:mm
|
||||
* @return unix timestamp formatted for current time zone
|
||||
*/
|
||||
function _datetime_to_ts_nonstrict($date) {
|
||||
$pattern = '/^(\d{1,2})\/(\d{1,2})\/(\d{4})(\s+(\d{1,2})\:(\d{1,2}))?/';
|
||||
|
||||
//check for a match
|
||||
if (preg_match($pattern, $date, $matches))
|
||||
{
|
||||
$date_split = $matches;
|
||||
}
|
||||
//return zero now if no matches
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
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]);
|
||||
$ts = new DateTime("@$gmt_ts");
|
||||
$ts->setTimezone($tz);
|
||||
|
||||
return $ts->format("U");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to split date into array
|
||||
*
|
||||
|
@@ -66,6 +66,8 @@ function booking_import_data_admin_submit($form, &$form_state)
|
||||
$update_counter = 0;
|
||||
$delimiter = ",";
|
||||
$result_array = array();
|
||||
$datetime_fields = array('booking_outflight_origin_ts', 'booking_outflight_destination_ts', 'booking_rtrnflight_origin_ts',
|
||||
'booking_rtrnflight_destination_ts');
|
||||
|
||||
$builtin_fields_to_import = array('nid', 'booking_status');
|
||||
$custom_fields_to_import = explode(";", variable_get('booking_import_include_fields', ''));
|
||||
@@ -79,8 +81,11 @@ function booking_import_data_admin_submit($form, &$form_state)
|
||||
drupal_set_message(t('Input file uploaded successfully, filename: "@filename"', array('@filename' => $file->filename)));
|
||||
$filename = drupal_realpath($file->uri);
|
||||
|
||||
//as per http://stackoverflow.com/questions/4541749/fgetcsv-fails-to-read-line-ending-in-mac-formatted-csv-file-any-better-solution
|
||||
ini_set("auto_detect_line_endings", "1");
|
||||
|
||||
//convert csv to associative array
|
||||
//based on http://stackoverflow.com/questions/4801895/csv-to-associative-array
|
||||
//based on http://stackoverflow.com/questions/4801895/csv-to-associative-array
|
||||
if( ($handle = fopen( $filename, "r")) !== FALSE) {
|
||||
$rowCounter = 0;
|
||||
while (($rowData = fgetcsv($handle, 0, $delimiter)) !== FALSE) {
|
||||
@@ -132,6 +137,12 @@ function booking_import_data_admin_submit($form, &$form_state)
|
||||
$update_text .= " set booking status to '" . $record[$field] . "'; ";
|
||||
$update_array[$field] = _booking_status_lookup($record[$field]);
|
||||
}
|
||||
//check for fields that need to be converted to a timestamp from text
|
||||
elseif (in_array($field, $datetime_fields))
|
||||
{
|
||||
$update_array[$field] = _datetime_to_ts_nonstrict($record[$field]);
|
||||
$update_text .= " set '" . $field . "' to '" . $update_array[$field] . "'; ";
|
||||
}
|
||||
elseif ( (! isset($record[$field])) || $record[$field] == '' )
|
||||
{
|
||||
//drupal_set_message("Error: Unable to locate expected field '$field' in input file for record number $update_counter.", 'error', FALSE);
|
||||
|
@@ -429,6 +429,34 @@ function booking_update_7223() {
|
||||
db_add_field('booking_person', 'booking_internal_flight_inbound', $spec);
|
||||
}
|
||||
|
||||
/**
|
||||
* More fields for flight details
|
||||
*/
|
||||
function booking_update_7224() {
|
||||
db_drop_field('booking_person', 'booking_internal_flight_outbound');
|
||||
db_drop_field('booking_person', 'booking_internal_flight_inbound');
|
||||
|
||||
$text_spec = array('type' => 'varchar', 'length' => '200', 'not null' => FALSE);
|
||||
$date_spec = array('type' => 'int', 'not null' => FALSE, 'disp-width' => '11');
|
||||
|
||||
db_add_field('booking_person', 'booking_outflight_bookingnum', $text_spec);
|
||||
db_add_field('booking_person', 'booking_outflight_flightnum', $text_spec);
|
||||
db_add_field('booking_person', 'booking_outflight_origin', $text_spec);
|
||||
db_add_field('booking_person', 'booking_outflight_origin_ts', $date_spec);
|
||||
db_add_field('booking_person', 'booking_outflight_connecting_flightnum', $text_spec);
|
||||
db_add_field('booking_person', 'booking_outflight_destination', $text_spec);
|
||||
db_add_field('booking_person', 'booking_outflight_destination_ts', $date_spec);
|
||||
|
||||
db_add_field('booking_person', 'booking_rtrnflight_bookingnum', $text_spec);
|
||||
db_add_field('booking_person', 'booking_rtrnflight_flightnum', $text_spec);
|
||||
db_add_field('booking_person', 'booking_rtrnflight_origin', $text_spec);
|
||||
db_add_field('booking_person', 'booking_rtrnflight_origin_ts', $date_spec);
|
||||
db_add_field('booking_person', 'booking_rtrnflight_connecting_flightnum', $text_spec);
|
||||
db_add_field('booking_person', 'booking_rtrnflight_destination', $text_spec);
|
||||
db_add_field('booking_person', 'booking_rtrnflight_destination_ts', $date_spec);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of hook_install().
|
||||
*/
|
||||
|
@@ -1671,9 +1671,26 @@ function booking_view($node, $view_mode) {
|
||||
$rows[] = array(t('Passport Exact Issued Name:'), $node->booking_passport_issue_name);
|
||||
$rows[] = array(t('Passport Issue Location:'), $node->booking_passport_issue_location);
|
||||
$rows[] = array(t('Destination Country:'), $node->booking_destination_country);
|
||||
$rows[] = array(t('Travel Insurance details:'), $node->booking_travel_insurance);
|
||||
$rows[] = array(t('Internal Flight Outbound:'), $node->booking_internal_flight_outbound);
|
||||
$rows[] = array(t('Internal Flight Returning:'), $node->booking_internal_flight_inbound);
|
||||
$rows[] = array(t('Travel Insurance details:'), $node->booking_travel_insurance);
|
||||
|
||||
$flight_rows[] = array(t('Internal Flight Booking Reference:'), $node->booking_outflight_bookingnum);
|
||||
$flight_rows[] = array(t('Internal Flight Number:'), $node->booking_outflight_flightnum);
|
||||
$flight_rows[] = array(t('Internal Flight Origin to Destination:'), $node->booking_outflight_origin);
|
||||
$flight_rows[] = array(t('Internal Flight Departure Time:'), format_date($node->booking_outflight_origin_ts, 'custom', 'd/m/Y H:i') );
|
||||
$flight_rows[] = array(t('Connecting Flight Number:'), $node->booking_outflight_connecting_flightnum);
|
||||
$flight_rows[] = array(t('Connecting Flight Origin to Destination:'), $node->booking_outflight_destination);
|
||||
$flight_rows[] = array(t('Internal Flight Arrival Time:'), format_date($node->booking_outflight_destination_ts, 'custom', 'd/m/Y H:i') );
|
||||
|
||||
//add the flight info to a new section
|
||||
$flight_heading = t("<h2>Internal Flight Details</h2>");
|
||||
$node->content['flight-heading'] = array(
|
||||
'#markup' => $flight_heading,
|
||||
'#weight' => 2,
|
||||
);
|
||||
$node->content['flight-details'] = array(
|
||||
'#markup' => theme('table', array('header' => $header, 'rows' => $flight_rows)),
|
||||
'#weight' =>2,
|
||||
);
|
||||
}
|
||||
|
||||
$rows[] = array(t('Payment Type Selected:'), t('!amount_paid', array('!amount_paid' => $payment_type)));
|
||||
|
@@ -35,22 +35,30 @@ function booking_report_summary() {
|
||||
|
||||
//define sorting information with the header
|
||||
//as per http://www.drup-all.com/blog/table-sort-pagination-drupal-7
|
||||
$header = array(
|
||||
array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'),
|
||||
array('data' => t('Name'), 'field' => 'booking_lastname'),
|
||||
array('data' => t('Booking Status'), 'field' => 'booking_status'),
|
||||
array('data' => t('Studygroups')),
|
||||
array('data' => t('Room')),
|
||||
array('data' => t('Travel')),
|
||||
array('data' => t('Email'), 'field' => 'booking_email'),
|
||||
array('data' => t('Payment To Date'), 'field' => 'booking_amount_paid'),
|
||||
array('data' => t('Total Payment Required')),
|
||||
array('data' => t('Fully paid?')),
|
||||
array('data' => t('Refund Processed?'), 'field' => 'booking_refund_processed'),
|
||||
array('data' => t('Refund Due'), 'field' => 'booking_refund_due'),
|
||||
array('data' => t('Welfare Required?'), 'field' => 'booking_welfare_required'),
|
||||
array('data' => t('Committee?'), 'field' => 'booking_committee_member'),
|
||||
);
|
||||
$header = array();
|
||||
$header[] = array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc');
|
||||
$header[] = array('data' => t('Name'), 'field' => 'booking_lastname');
|
||||
$header[] = array('data' => t('Booking Status'), 'field' => 'booking_status');
|
||||
|
||||
if (variable_get('booking_enable_studygroups', 0) == 1)
|
||||
{
|
||||
$header[] = array('data' => t('Studygroups'));
|
||||
}
|
||||
if (variable_get('booking_enable_roomallocations', 0) == 1)
|
||||
{
|
||||
$header[] = array('data' => t('Room'));
|
||||
}
|
||||
|
||||
$header[] = array('data' => t('Travel'));
|
||||
$header[] = array('data' => t('Email'), 'field' => 'booking_email');
|
||||
$header[] = array('data' => t('Payment To Date'), 'field' => 'booking_amount_paid');
|
||||
$header[] = array('data' => t('Total Payment Required'));
|
||||
$header[] = array('data' => t('Fully paid?'));
|
||||
$header[] = array('data' => t('Refund Processed?'), 'field' => 'booking_refund_processed');
|
||||
$header[] = array('data' => t('Refund Due'), 'field' => 'booking_refund_due');
|
||||
$header[] = array('data' => t('Welfare Required?'), 'field' => 'booking_welfare_required');
|
||||
$header[] = array('data' => t('Committee?'), 'field' => 'booking_committee_member');
|
||||
|
||||
|
||||
$rows = array();
|
||||
$state_header = array('State', 'Count');
|
||||
@@ -106,6 +114,7 @@ function booking_report_summary() {
|
||||
|
||||
foreach ($result as $person)
|
||||
{
|
||||
$this_row = array();
|
||||
//$amount_owing = _booking_amount_owing($person->nid, 0, FALSE);
|
||||
$amount_owing = _booking_amount_owing($person, 0, FALSE);
|
||||
|
||||
@@ -120,24 +129,32 @@ function booking_report_summary() {
|
||||
}
|
||||
|
||||
//define the row for this person
|
||||
$rows[] = array(
|
||||
l(t('View !id', array('!id' => $person->nid)), t('node/!id', array('!id' => $person->nid))),
|
||||
l(t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))),
|
||||
t('node/!id/edit', array('!id' => $person->nid))
|
||||
),
|
||||
_booking_status_generate($person->booking_status),
|
||||
l(t('Groups'), t('admin/booking/!id/edit-studygroup', array('!id' => $person->nid))),
|
||||
l(t('Room'), t('admin/booking/!id/edit-room', array('!id' => $person->nid))),
|
||||
$travel_link,
|
||||
t('!email', array('!email' => $person->booking_email)),
|
||||
t('!payment', array('!payment' => $person->booking_amount_paid)),
|
||||
t('!payment', array('!payment' => $amount_owing == 0 ? $person->booking_total_pay_reqd : _booking_total_due($person))),
|
||||
t('!fullypaid', array('!fullypaid' => $amount_owing == 0 ? 'Yes' : 'No')),
|
||||
t('!reqd', array('!reqd' => $person->booking_refund_processed == 'Y' ? 'Yes' : 'No')),
|
||||
t('!payment', array('!payment' => $person->booking_refund_due)),
|
||||
t($person->booking_welfare_required == 'Y' ? 'Yes' : 'No'),
|
||||
t($person->booking_committee_member == 'Y' ? 'Yes' : 'No'),
|
||||
);
|
||||
$this_row[] = l(t('View !id', array('!id' => $person->nid)), t('node/!id', array('!id' => $person->nid)));
|
||||
$this_row[] = l(t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))),
|
||||
t('node/!id/edit', array('!id' => $person->nid))
|
||||
);
|
||||
$this_row[] = _booking_status_generate($person->booking_status);
|
||||
|
||||
if (variable_get('booking_enable_studygroups', 0) == 1)
|
||||
{
|
||||
$this_row[] = l(t('Groups'), t('admin/booking/!id/edit-studygroup', array('!id' => $person->nid)));
|
||||
}
|
||||
if (variable_get('booking_enable_roomallocations', 0) == 1)
|
||||
{
|
||||
$this_row[] =l(t('Room'), t('admin/booking/!id/edit-room', array('!id' => $person->nid)));
|
||||
}
|
||||
|
||||
$this_row[] = $travel_link;
|
||||
$this_row[] = t('!email', array('!email' => $person->booking_email));
|
||||
$this_row[] = t('!payment', array('!payment' => $person->booking_amount_paid));
|
||||
$this_row[] = t('!payment', array('!payment' => $amount_owing == 0 ? $person->booking_total_pay_reqd : _booking_total_due($person)));
|
||||
$this_row[] = t('!fullypaid', array('!fullypaid' => $amount_owing == 0 ? 'Yes' : 'No'));
|
||||
$this_row[] = t('!reqd', array('!reqd' => $person->booking_refund_processed == 'Y' ? 'Yes' : 'No'));
|
||||
$this_row[] = t('!payment', array('!payment' => $person->booking_refund_due));
|
||||
$this_row[] = t($person->booking_welfare_required == 'Y' ? 'Yes' : 'No');
|
||||
$this_row[] = t($person->booking_committee_member == 'Y' ? 'Yes' : 'No');
|
||||
$rows[] = $this_row;
|
||||
|
||||
//add up the total paid
|
||||
$total_paid += $person->booking_amount_paid;
|
||||
|
||||
@@ -508,6 +525,9 @@ function booking_csv_report() {
|
||||
$custom_fields_to_skip = explode(";", variable_get('booking_csv_exclude_fields', ''));
|
||||
$fields_to_skip = array_merge($builtin_fields_to_skip, $custom_fields_to_skip);
|
||||
|
||||
$datetime_fields = array('booking_outflight_origin_ts', 'booking_outflight_destination_ts', 'booking_rtrnflight_origin_ts',
|
||||
'booking_rtrnflight_destination_ts', 'booking_timestamp', 'booking_flight_datetime_inbound', 'booking_flight_datetime_outbound');
|
||||
|
||||
//query the db
|
||||
/*
|
||||
$query = db_select('booking_person', 'p');
|
||||
@@ -596,8 +616,8 @@ function booking_csv_report() {
|
||||
}
|
||||
|
||||
//handle more exact dates
|
||||
if ($key == 'booking_timestamp' || $key == 'booking_flight_datetime_inbound' || $key == 'booking_flight_datetime_outbound') {
|
||||
$output[] = format_date($value, 'custom', 'd/m/Y H:i');
|
||||
if (in_array($key, $datetime_fields)) {
|
||||
$output[] = $value == 0 ? '0' : format_date($value, 'custom', 'd/m/Y H:i');
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user