From 8b133cf160b4dcc550dbf3a390726977479503df Mon Sep 17 00:00:00 2001
From: Nathan Coad
Date: Thu, 3 May 2018 08:09:29 +1000
Subject: [PATCH] tidy up and variety validation work
---
booking.install | 25 +-
booking.module | 10 +-
booking.regn_node.inc | 2 +-
booking.reports.inc | 1635 +++++++++++++++++++------------------
booking.variety_admin.inc | 136 ++-
booking.variety_form.inc | 41 +-
deprecated.php | 4 +-
7 files changed, 1008 insertions(+), 845 deletions(-)
diff --git a/booking.install b/booking.install
index ccb5ff6..f02cf6e 100644
--- a/booking.install
+++ b/booking.install
@@ -93,7 +93,7 @@ function booking_update_7201() {
* Add table for variety sessions
*/
function booking_update_7202() {
- $booking_variety_options = array(
+ $booking_variety_sessions = array(
'fields' => array(
'vid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
@@ -105,7 +105,7 @@ function booking_update_7202() {
),
'primary key' => array('vid'),
);
- $booking_variety_times = array(
+ $booking_variety_timeslots = array(
'fields' => array(
'tid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
@@ -127,8 +127,8 @@ function booking_update_7202() {
);
- db_create_table('booking_variety_options', $booking_variety_options);
- db_create_table('booking_variety_times', $booking_variety_times);
+ db_create_table('booking_variety_sessions', $booking_variety_sessions);
+ db_create_table('booking_variety_timeslots', $booking_variety_timeslots);
db_create_table('booking_variety_regn', $booking_variety_regn);
//TODO: create tables for variety session timeslots and variety session registrations (map user to variety session id)
@@ -781,6 +781,17 @@ function booking_update_7253() {
_booking_node_create_mysqlview();
}
+/**
+* Change booking_variety_regn field type and rename some tables
+*/
+function booking_update_7254() {
+ $spec = array('type' => 'varchar', 'length' => '1000', 'not null' => FALSE);
+ db_change_field('booking_variety_regn', 'booking_variety_id', 'booking_variety_ids', $spec);
+ db_rename_table('booking_variety_times', 'booking_variety_timeslots');
+ db_rename_table('booking_variety_options', 'booking_variety_sessions');
+}
+
+
/**
* Implementation of hook_install().
*/
@@ -1047,7 +1058,7 @@ function booking_schema() {
'primary key' => array('payid'),
);
- $schema['booking_variety_options'] = array(
+ $schema['booking_variety_sessions'] = array(
'fields' => array(
'vid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
@@ -1060,7 +1071,7 @@ function booking_schema() {
'primary key' => array('vid'),
);
- $schema['booking_variety_times'] = array(
+ $schema['booking_variety_timeslots'] = array(
'fields' => array(
'tid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
@@ -1075,7 +1086,7 @@ function booking_schema() {
$schema['booking_variety_regn'] = array(
'fields' => array(
'rid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
- 'booking_variety_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
+ 'booking_variety_ids' => array('type' => 'varchar', 'length' => '1000', 'not null' => TRUE),
'booking_node_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
),
'primary key' => array('rid'),
diff --git a/booking.module b/booking.module
index d7c5b65..4837cdd 100644
--- a/booking.module
+++ b/booking.module
@@ -408,7 +408,7 @@ function booking_menu() {
'type' => MENU_LOCAL_ACTION,
);
- $items['admin/config/booking/variety/%/edit'] = array(
+ $items['admin/config/booking/variety/%/edit'] = array(
'title' => 'Edit Variety Session Timeslot',
'page callback' => 'drupal_get_form',
'page arguments' => array('booking_variety_timeslot_form', false, 4),
@@ -416,6 +416,14 @@ function booking_menu() {
'type' => MENU_CALLBACK,
);
+ $items['admin/config/booking/variety/%/csv'] = array(
+ 'title' => 'Variety Session CSV',
+ 'description' => 'CSV Report of Variety Session Timeslot',
+ 'page callback' => 'booking_varietysessions_csv_report',
+ 'page arguments' => array(4),
+ //'type' => MENU_CALLBACK,
+ );
+
$items['admin/config/booking/variety/%/session/list'] = array(
'title' => 'List Variety Sessions',
'description' => 'List variety sessions for the specified timeslot',
diff --git a/booking.regn_node.inc b/booking.regn_node.inc
index 4e82060..2b5e8c3 100644
--- a/booking.regn_node.inc
+++ b/booking.regn_node.inc
@@ -71,7 +71,7 @@ function _booking_node_create_mysqlview()
$query->leftJoin('booking_studygroup_mapping', 's' . $id, 'p.nid = s' . $id . '.booking_node_id and s' . $id . '.booking_studygroup_id = ' . $id);
}
}
-
+
//filter the results either by current active event
// @todo is this filter really necessary?
$query->condition('p.booking_eventid', $event->eid, '=');
diff --git a/booking.reports.inc b/booking.reports.inc
index 23a19cd..383c0f9 100644
--- a/booking.reports.inc
+++ b/booking.reports.inc
@@ -5,680 +5,680 @@
* List people and how much they have paid
*/
function booking_report_summary() {
- global $event;
- //$text = "";
- $output = "";
- $non_australia_count = 0;
- $bookedin_counter = 0;
- $notpaid_counter = 0;
- $waiting_counter = 0;
- $notcoming_counter = 0;
- $hosts_counter = 0;
- $male_count = 0;
- $female_count = 0;
- $baptised_count = 0;
- $married_count = 0;
- $total_paid = 0;
- $total_refunds = 0;
- $dob_total = 0;
- $male_dob_total = 0;
- $female_dob_total = 0;
- $person_count = 0;
- $welfare_count = 0;
- $fullypaid_count = 0;
- $travelform_count = 0;
- $committee_count = 0;
+ global $event;
+ //$text = "";
+ $output = "";
+ $non_australia_count = 0;
+ $bookedin_counter = 0;
+ $notpaid_counter = 0;
+ $waiting_counter = 0;
+ $notcoming_counter = 0;
+ $hosts_counter = 0;
+ $male_count = 0;
+ $female_count = 0;
+ $baptised_count = 0;
+ $married_count = 0;
+ $total_paid = 0;
+ $total_refunds = 0;
+ $dob_total = 0;
+ $male_dob_total = 0;
+ $female_dob_total = 0;
+ $person_count = 0;
+ $welfare_count = 0;
+ $fullypaid_count = 0;
+ $travelform_count = 0;
+ $committee_count = 0;
- $stats_attributes = array('style' => 'max-width:30%');
+ $stats_attributes = array('style' => 'max-width:30%');
- //define sorting information with the header
- //as per http://www.drup-all.com/blog/table-sort-pagination-drupal-7
- $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?'), 'field' => 'booking_payment_complete');
- $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();
-
- //the state summary table
- $state_header = array('State', 'Count', 'Males', 'Females', 'Baptised', 'Male Average Age', 'Female Average Age', 'Overall Average Age');
- $state_rows = array();
- $state_statistics = array();
- //$state_statistics = new stdClass();
-
- //do some analysis about the people booked in
- //first the summary of states
- $query = db_select('booking_person', 'p')
- ->fields('p', array('booking_state', 'booking_country'));
- //include people either booked in or on the waiting list, that belong to the current event id
- $db_or = db_or();
- $db_or->condition('p.booking_status', 1, '=');
- $db_or->condition('p.booking_status', 2, '=');
- $db_and = db_and()->condition($db_or)->condition('p.booking_eventid', $event->eid, '=');
- $query->condition($db_and);
- $query->groupBy('p.booking_state');
- $query->addExpression('COUNT(p.booking_state)', 'state_count');
- $query->orderBy('state_count', 'DESC');
- $state_stats = $query->execute();
-
- //add some age info to an array so we can calculate age info and generate the actual rows after the more detailed summary loop
- //include count of guys, girls, minimum, maximum and average ages
- foreach ($state_stats as $state) {
- if (strcmp($state->booking_country,'Australia') == 0 ) {
- //$state_rows[] = array($state->booking_state, $state->state_count);
- //store the total count for this state
- if (!isset($state_statistics[$state->booking_state])) {
- $state_statistics[$state->booking_state] = new stdClass();
- }
- $state_statistics[$state->booking_state]->total_count = $state->state_count;
- $state_statistics[$state->booking_state]->male_count = 0;
- $state_statistics[$state->booking_state]->male_avg = 0;
- $state_statistics[$state->booking_state]->female_count = 0;
- $state_statistics[$state->booking_state]->female_avg = 0;
- $state_statistics[$state->booking_state]->total_avg = 0;
- $state_statistics[$state->booking_state]->baptised_count = 0;
- } else {
- $non_australia_count += $state->state_count;
- }
- }
- //non australian states
- //$state_rows[] = array('International', $non_australia_count);
- $state_statistics['International'] = new stdClass();
- $state_statistics['International']->total_count = $non_australia_count;
- $state_statistics['International']->male_count = 0;
- $state_statistics['International']->male_avg = 0;
- $state_statistics['International']->female_count = 0;
- $state_statistics['International']->female_avg = 0;
- $state_statistics['International']->total_avg = 0;
- $state_statistics['International']->baptised_count = 0;
-
- //the ecclesia summary table
- $ecclesia_header = array('State','Ecclesia', 'Count');
- $ecclesia_rows = array();
-
- //bookings by ecclesia
- $query = db_select('booking_person', 'p')
- ->fields('p', array('booking_ecclesia','booking_state'))
- ->condition('p.booking_eventid', $event->eid, '=');
- $query->groupBy('p.booking_ecclesia');
- $query->addExpression('COUNT(p.booking_ecclesia)', 'ecclesia_count');
- $query->orderBy('booking_state')
- ->orderBy('ecclesia_count','DESC');
- $stats = $query->execute();
-
- foreach ($stats as $ecclesia) {
- $ecclesia_rows[] = array($ecclesia->booking_state,$ecclesia->booking_ecclesia, $ecclesia->ecclesia_count);
- }
-
- //more detailed summary
- //allow user-selectable sorting of columns as per http://www.drup-all.com/blog/table-sort-pagination-drupal-7
- $query = db_select('booking_person', 'p');
- $query->join('booking_price', 'pr', 'pr.pid = p.booking_payment_id');
- $query->leftJoin('booking_travel', 't', 'p.nid = t.booking_person_nid');
- $query->condition('p.booking_eventid', $event->eid, '=')
- ->fields('p')
- ->fields('t')
- ->fields('pr', array('booking_price', 'booking_late_price'));
-
- $table_sort = $query->extend('TableSort')->orderbyHeader($header);
- $result = $table_sort->execute();
-
- foreach ($result as $person)
- {
- $this_row = array();
- //$amount_owing = _booking_amount_owing($person->nid, 0, FALSE);
- $amount_owing = _booking_amount_owing($person, 0, FALSE);
-
- //calculate the travel link
- if ($person->tid > 0) {
- $travel_link = l(t('Travel'), t('node/!id/edit', array('!id' => $person->tid)));
- }
- else {
- $travel_link = t('N/A');
- }
-
- //define the row for this person
- $this_row[] = l(t('Edit !id', array('!id' => $person->nid)), t('node/!id/edit', array('!id' => $person->nid)));
- $this_row[] = l(t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))),
- t('node/!id', 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-membership', 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('!fullypaid', array('!fullypaid' => $person->booking_payment_complete == 'Y' ? '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;
-
- //subtract any refund
- if ($person->booking_refund_processed == 'Y' && $person->booking_refund_due > 0)
- {
- $total_refunds += $person->booking_refund_due;
- }
-
- //travel form completed?
- if (! empty($person->tid))
- $travelform_count++;
-
- //booking status
- if ($person->booking_status == 0)
- $notpaid_counter++;
- elseif ($person->booking_status == 1)
- $bookedin_counter++;
- elseif ($person->booking_status == 2)
- $waiting_counter++;
- elseif ($person->booking_status == 5)
- $hosts_counter++;
- else
- $notcoming_counter++;
-
- //welfare
- if ($person->booking_welfare_required == 'Y')
- $welfare_count++;
-
- //committee?
- if ($person->booking_committee_member == 'Y')
- $committee_count++;
-
- //fully paid?
- if ($amount_owing == 0)
- $fullypaid_count++;
+ //define sorting information with the header
+ //as per http://www.drup-all.com/blog/table-sort-pagination-drupal-7
+ $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?'), 'field' => 'booking_payment_complete');
+ $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();
+
+ //the state summary table
+ $state_header = array('State', 'Count', 'Males', 'Females', 'Baptised', 'Male Average Age', 'Female Average Age', 'Overall Average Age');
+ $state_rows = array();
+ $state_statistics = array();
+ //$state_statistics = new stdClass();
+
+ //do some analysis about the people booked in
+ //first the summary of states
+ $query = db_select('booking_person', 'p')
+ ->fields('p', array('booking_state', 'booking_country'));
+ //include people either booked in or on the waiting list, that belong to the current event id
+ $db_or = db_or();
+ $db_or->condition('p.booking_status', 1, '=');
+ $db_or->condition('p.booking_status', 2, '=');
+ $db_and = db_and()->condition($db_or)->condition('p.booking_eventid', $event->eid, '=');
+ $query->condition($db_and);
+ $query->groupBy('p.booking_state');
+ $query->addExpression('COUNT(p.booking_state)', 'state_count');
+ $query->orderBy('state_count', 'DESC');
+ $state_stats = $query->execute();
+
+ //add some age info to an array so we can calculate age info and generate the actual rows after the more detailed summary loop
+ //include count of guys, girls, minimum, maximum and average ages
+ foreach ($state_stats as $state) {
+ if (strcmp($state->booking_country,'Australia') == 0 ) {
+ //$state_rows[] = array($state->booking_state, $state->state_count);
+ //store the total count for this state
+ if (!isset($state_statistics[$state->booking_state])) {
+ $state_statistics[$state->booking_state] = new stdClass();
+ }
+ $state_statistics[$state->booking_state]->total_count = $state->state_count;
+ $state_statistics[$state->booking_state]->male_count = 0;
+ $state_statistics[$state->booking_state]->male_avg = 0;
+ $state_statistics[$state->booking_state]->female_count = 0;
+ $state_statistics[$state->booking_state]->female_avg = 0;
+ $state_statistics[$state->booking_state]->total_avg = 0;
+ $state_statistics[$state->booking_state]->baptised_count = 0;
+ } else {
+ $non_australia_count += $state->state_count;
+ }
+ }
+ //non australian states
+ //$state_rows[] = array('International', $non_australia_count);
+ $state_statistics['International'] = new stdClass();
+ $state_statistics['International']->total_count = $non_australia_count;
+ $state_statistics['International']->male_count = 0;
+ $state_statistics['International']->male_avg = 0;
+ $state_statistics['International']->female_count = 0;
+ $state_statistics['International']->female_avg = 0;
+ $state_statistics['International']->total_avg = 0;
+ $state_statistics['International']->baptised_count = 0;
+
+ //the ecclesia summary table
+ $ecclesia_header = array('State','Ecclesia', 'Count');
+ $ecclesia_rows = array();
+
+ //bookings by ecclesia
+ $query = db_select('booking_person', 'p')
+ ->fields('p', array('booking_ecclesia','booking_state'))
+ ->condition('p.booking_eventid', $event->eid, '=');
+ $query->groupBy('p.booking_ecclesia');
+ $query->addExpression('COUNT(p.booking_ecclesia)', 'ecclesia_count');
+ $query->orderBy('booking_state')
+ ->orderBy('ecclesia_count','DESC');
+ $stats = $query->execute();
+
+ foreach ($stats as $ecclesia) {
+ $ecclesia_rows[] = array($ecclesia->booking_state,$ecclesia->booking_ecclesia, $ecclesia->ecclesia_count);
+ }
+
+ //more detailed summary
+ //allow user-selectable sorting of columns as per http://www.drup-all.com/blog/table-sort-pagination-drupal-7
+ $query = db_select('booking_person', 'p');
+ $query->join('booking_price', 'pr', 'pr.pid = p.booking_payment_id');
+ $query->leftJoin('booking_travel', 't', 'p.nid = t.booking_person_nid');
+ $query->condition('p.booking_eventid', $event->eid, '=')
+ ->fields('p')
+ ->fields('t')
+ ->fields('pr', array('booking_price', 'booking_late_price'));
+
+ $table_sort = $query->extend('TableSort')->orderbyHeader($header);
+ $result = $table_sort->execute();
+
+ foreach ($result as $person)
+ {
+ $this_row = array();
+ //$amount_owing = _booking_amount_owing($person->nid, 0, FALSE);
+ $amount_owing = _booking_amount_owing($person, 0, FALSE);
+
+ //calculate the travel link
+ if ($person->tid > 0) {
+ $travel_link = l(t('Travel'), t('node/!id/edit', array('!id' => $person->tid)));
+ }
+ else {
+ $travel_link = t('N/A');
+ }
+
+ //define the row for this person
+ $this_row[] = l(t('Edit !id', array('!id' => $person->nid)), t('node/!id/edit', array('!id' => $person->nid)));
+ $this_row[] = l(t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))),
+ t('node/!id', 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-membership', 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('!fullypaid', array('!fullypaid' => $person->booking_payment_complete == 'Y' ? '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;
+
+ //subtract any refund
+ if ($person->booking_refund_processed == 'Y' && $person->booking_refund_due > 0)
+ {
+ $total_refunds += $person->booking_refund_due;
+ }
+
+ //travel form completed?
+ if (! empty($person->tid))
+ $travelform_count++;
+
+ //booking status
+ if ($person->booking_status == 0)
+ $notpaid_counter++;
+ elseif ($person->booking_status == 1)
+ $bookedin_counter++;
+ elseif ($person->booking_status == 2)
+ $waiting_counter++;
+ elseif ($person->booking_status == 5)
+ $hosts_counter++;
+ else
+ $notcoming_counter++;
+
+ //welfare
+ if ($person->booking_welfare_required == 'Y')
+ $welfare_count++;
+
+ //committee?
+ if ($person->booking_committee_member == 'Y')
+ $committee_count++;
+
+ //fully paid?
+ if ($amount_owing == 0)
+ $fullypaid_count++;
- $person_count++;
-
- $state = strcmp($person->booking_country,'Australia') == 0 ? $person->booking_state : 'International';
-
- //general stats for booked in people
- if ($person->booking_status == 1) {
- //for overall average age
- $dob_total += $person->booking_dob;
+ $person_count++;
+
+ $state = strcmp($person->booking_country,'Australia') == 0 ? $person->booking_state : 'International';
+
+ //general stats for booked in people
+ if ($person->booking_status == 1) {
+ //for overall average age
+ $dob_total += $person->booking_dob;
- //store data for average ages per gender and state
- if ($person->booking_gender == 'M')
- {
- $male_count++;
- $male_dob_total += $person->booking_dob;
- $state_statistics[$state]->male_avg += $person->booking_dob;
- $state_statistics[$state]->male_count++;
- } else {
- $female_count++;
- $female_dob_total += $person->booking_dob;
- $state_statistics[$state]->female_avg += $person->booking_dob;
- $state_statistics[$state]->female_count++;
- }
-
- if ($person->booking_baptised == 'Y') {
- $baptised_count++;
- $state_statistics[$state]->baptised_count++;
- }
-
- if ($person->booking_married == 'Y')
- $married_count++;
- }
- }
-
- //generate the table for state statistics
- foreach ($state_statistics as $key => $value) {
- //$state_rows[] = array($state, $state->total_count, $state->male_count, $state->female_count, 0);
- $male_average_age = _booking_avg_age($value->male_avg, $value->male_count, $event->booking_event_start);
- $female_average_age = _booking_avg_age($value->female_avg, $value->female_count, $event->booking_event_start);
- $state_average_age = _booking_avg_age($value->female_avg + $value->male_avg, $value->female_count + $value->male_count, $event->booking_event_start);
-
- $data = array($key, $value->total_count, $value->male_count, $value->female_count, $value->baptised_count, $male_average_age, $female_average_age, $state_average_age);
- //watchdog('booking', "State statistics:\n@info
", array('@info' => print_r( $data, true)));
- $state_rows[] = $data;
- }
+ //store data for average ages per gender and state
+ if ($person->booking_gender == 'M')
+ {
+ $male_count++;
+ $male_dob_total += $person->booking_dob;
+ $state_statistics[$state]->male_avg += $person->booking_dob;
+ $state_statistics[$state]->male_count++;
+ } else {
+ $female_count++;
+ $female_dob_total += $person->booking_dob;
+ $state_statistics[$state]->female_avg += $person->booking_dob;
+ $state_statistics[$state]->female_count++;
+ }
+
+ if ($person->booking_baptised == 'Y') {
+ $baptised_count++;
+ $state_statistics[$state]->baptised_count++;
+ }
+
+ if ($person->booking_married == 'Y')
+ $married_count++;
+ }
+ }
+
+ //generate the table for state statistics
+ foreach ($state_statistics as $key => $value) {
+ //$state_rows[] = array($state, $state->total_count, $state->male_count, $state->female_count, 0);
+ $male_average_age = _booking_avg_age($value->male_avg, $value->male_count, $event->booking_event_start);
+ $female_average_age = _booking_avg_age($value->female_avg, $value->female_count, $event->booking_event_start);
+ $state_average_age = _booking_avg_age($value->female_avg + $value->male_avg, $value->female_count + $value->male_count, $event->booking_event_start);
+
+ $data = array($key, $value->total_count, $value->male_count, $value->female_count, $value->baptised_count, $male_average_age, $female_average_age, $state_average_age);
+ //watchdog('booking', "State statistics:\n@info
", array('@info' => print_r( $data, true)));
+ $state_rows[] = $data;
+ }
- //output everything
- $output .= t("General Statistics
");
- $output .= t("Attendees booked in
");
- $output .= t("There are !bookedin registrations currently booked in, !waiting on waiting list, !notpaid haven't paid, !hosts are hosts, " .
- "and !notcoming are no longer coming, which comes to a total of !total people who have filled in the registration form. !travel people have filled in their travel form.
",
- array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter, '!total' => $person_count, '!travel' => $travelform_count,
- '!notcoming' => $notcoming_counter, '!hosts' => $hosts_counter));
- $output .= t("There are !boys males and !girls females currently booked in. Of these, !baptised are baptised and !married are married.
",
- array('!boys' => $male_count, '!girls' => $female_count, '!baptised' => $baptised_count, '!married' => $married_count
- ));
- $output .= t("Ages
");
- $output .= t("The combined average age at the start of the week will be !average.
The male average age will be !maleaverage.
The female average age will be !femaleaverage.
",
- array('!average' => _booking_avg_age($dob_total, $male_count + $female_count, $event->booking_event_start),
- '!maleaverage' => _booking_avg_age($male_dob_total, $male_count, $event->booking_event_start),
- '!femaleaverage' => _booking_avg_age($female_dob_total, $female_count, $event->booking_event_start)
- ));
- $output .= t("Finances
");
- $output .= t("There are !welfare people with special financial consideration approved, and !committee people on the committee. " .
- "!fullypaid people have completed their payments.
",
- array('!welfare' => $welfare_count, '!fullypaid' => $fullypaid_count, '!committee' => $committee_count,
- ));
- $output .= t("Total amount paid: $!paid, minus $!refunds in refunds.
", array('!paid' => $total_paid, '!refunds' => $total_refunds));
- $output .= t("Bookings by state
");
- $output .= theme('table', array('header' => $state_header, 'rows' => $state_rows));
- $output .= t("Bookings by ecclesia
");
- $output .= theme('table', array('header' => $ecclesia_header, 'rows' => $ecclesia_rows, 'attributes' => $stats_attributes));
- $output .= t("Summary of attendees for !event.
", array('!event' => $event->booking_eventname));
- $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'sort-table')));
+ //output everything
+ $output .= t("General Statistics
");
+ $output .= t("Attendees booked in
");
+ $output .= t("There are !bookedin registrations currently booked in, !waiting on waiting list, !notpaid haven't paid, !hosts are hosts, " .
+ "and !notcoming are no longer coming, which comes to a total of !total people who have filled in the registration form. !travel people have filled in their travel form.
",
+ array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter, '!total' => $person_count, '!travel' => $travelform_count,
+ '!notcoming' => $notcoming_counter, '!hosts' => $hosts_counter));
+ $output .= t("There are !boys males and !girls females currently booked in. Of these, !baptised are baptised and !married are married.
",
+ array('!boys' => $male_count, '!girls' => $female_count, '!baptised' => $baptised_count, '!married' => $married_count
+ ));
+ $output .= t("Ages
");
+ $output .= t("The combined average age at the start of the week will be !average.
The male average age will be !maleaverage.
The female average age will be !femaleaverage.
",
+ array('!average' => _booking_avg_age($dob_total, $male_count + $female_count, $event->booking_event_start),
+ '!maleaverage' => _booking_avg_age($male_dob_total, $male_count, $event->booking_event_start),
+ '!femaleaverage' => _booking_avg_age($female_dob_total, $female_count, $event->booking_event_start)
+ ));
+ $output .= t("Finances
");
+ $output .= t("There are !welfare people with special financial consideration approved, and !committee people on the committee. " .
+ "!fullypaid people have completed their payments.
",
+ array('!welfare' => $welfare_count, '!fullypaid' => $fullypaid_count, '!committee' => $committee_count,
+ ));
+ $output .= t("Total amount paid: $!paid, minus $!refunds in refunds.", array('!paid' => $total_paid, '!refunds' => $total_refunds));
+ $output .= t("Bookings by state
");
+ $output .= theme('table', array('header' => $state_header, 'rows' => $state_rows));
+ $output .= t("Bookings by ecclesia
");
+ $output .= theme('table', array('header' => $ecclesia_header, 'rows' => $ecclesia_rows, 'attributes' => $stats_attributes));
+ $output .= t("Summary of attendees for !event.
", array('!event' => $event->booking_eventname));
+ $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'sort-table')));
- return $output;
+ return $output;
}
/**
* List the contents of the payments table
*/
function booking_report_paypal_payments() {
- global $event;
- $text = "";
- $output = "";
- $bookedin_counter = 0;
- $total_paid = 0;
- $total_fees = 0;
-
- $header = array('Node Id', 'Name', 'Email', 'Payment Date', 'Gross Payment', 'Currency',
- 'Paypal Fee', 'Invoice', 'Payment Status', 'Payer ID', 'Item Name', 'IPN track ID', 'Payment Complete');
- $rows = array();
-
- //fetch the payment table
- $query = db_select('booking_payment', 'pa');
- $query->join('booking_person', 'p', 'pa.booking_person_nid = p.nid');
- $query->fields('pa')
- ->fields('p', array('booking_payment_complete'))
- ->condition('pa.booking_eventid', $event->eid,'=');
- $result = $query->execute();
+ global $event;
+ $text = "";
+ $output = "";
+ $bookedin_counter = 0;
+ $total_paid = 0;
+ $total_fees = 0;
+
+ $header = array('Node Id', 'Name', 'Email', 'Payment Date', 'Gross Payment', 'Currency',
+ 'Paypal Fee', 'Invoice', 'Payment Status', 'Payer ID', 'Item Name', 'IPN track ID', 'Payment Complete');
+ $rows = array();
+
+ //fetch the payment table
+ $query = db_select('booking_payment', 'pa');
+ $query->join('booking_person', 'p', 'pa.booking_person_nid = p.nid');
+ $query->fields('pa')
+ ->fields('p', array('booking_payment_complete'))
+ ->condition('pa.booking_eventid', $event->eid,'=');
+ $result = $query->execute();
- //$result = db_query("SELECT * FROM {booking_person} p WHERE p.booking_eventid = :eid",
- // array(':eid' => $event->eid));
-
- foreach ($result as $person) {
- $rows[] = array(
- l(t('!id', array('!id' => $person->booking_person_nid)), t('node/!id', array('!id' => $person->booking_person_nid))),
- t('!first !last', array('!first' => ucwords($person->booking_first_name), '!last' => ucwords($person->booking_last_name))),
- t('!email', array('!email' => $person->booking_buyer_email)),
- t(_booking_convert_ts($person->booking_payment_date)->format('j F, Y H:i')),
- t('!payment', array('!payment' => $person->booking_mc_gross)),
- t('!currency', array('!currency' => $person->booking_mc_currency)),
- t('!fee', array('!fee' => $person->booking_mc_fee)),
- t('!invoice', array('!invoice' => $person->booking_invoice)),
- t($person->booking_payment_status),
- t($person->booking_payer_id),
- t($person->booking_item_name),
- t($person->booking_ipn_track_id),
- t($person->booking_payment_complete),
- );
- $total_paid += $person->booking_mc_gross;
- $total_fees += $person->booking_mc_fee;
- }
+ //$result = db_query("SELECT * FROM {booking_person} p WHERE p.booking_eventid = :eid",
+ // array(':eid' => $event->eid));
+
+ foreach ($result as $person) {
+ $rows[] = array(
+ l(t('!id', array('!id' => $person->booking_person_nid)), t('node/!id', array('!id' => $person->booking_person_nid))),
+ t('!first !last', array('!first' => ucwords($person->booking_first_name), '!last' => ucwords($person->booking_last_name))),
+ t('!email', array('!email' => $person->booking_buyer_email)),
+ t(_booking_convert_ts($person->booking_payment_date)->format('j F, Y H:i')),
+ t('!payment', array('!payment' => $person->booking_mc_gross)),
+ t('!currency', array('!currency' => $person->booking_mc_currency)),
+ t('!fee', array('!fee' => $person->booking_mc_fee)),
+ t('!invoice', array('!invoice' => $person->booking_invoice)),
+ t($person->booking_payment_status),
+ t($person->booking_payer_id),
+ t($person->booking_item_name),
+ t($person->booking_ipn_track_id),
+ t($person->booking_payment_complete),
+ );
+ $total_paid += $person->booking_mc_gross;
+ $total_fees += $person->booking_mc_fee;
+ }
- $output .= t("The following table presents payment entries from paypal and manual payments that have been made for !event.
", array('!event' => $event->booking_eventname));
- $output .= theme('table', array('header' => $header, 'rows' => $rows));
- $output .= t("Gross amount paid: $!paid. Total amount of fees paid: $!fees
", array('!paid' => $total_paid, '!fees' => $total_fees));
- return $output;
+ $output .= t("The following table presents payment entries from paypal and manual payments that have been made for !event.
", array('!event' => $event->booking_eventname));
+ $output .= theme('table', array('header' => $header, 'rows' => $rows));
+ $output .= t("Gross amount paid: $!paid. Total amount of fees paid: $!fees
", array('!paid' => $total_paid, '!fees' => $total_fees));
+ return $output;
}
/**
* List everyone's flight info
*/
function booking_report_flight_details() {
- global $event;
- $form = array();
- $prefix = t("Internal Flight Details
\nView flight information for all attendees with status currently set to booked in.
");
-
- $header = array(
- 'booking_name' => array('data' => t('Name'), 'field' => 'booking_lastname'),
- 'booking_destination_country' => array('data' => t('Country'), 'field' => 'booking_destination_country'),
- 'booking_outflight_bookingnum' => array('data' => t('Reference'), 'field' => 'booking_outflight_bookingnum'),
- 'booking_outflight_flightnum' => array('data' => t('Flight #'), 'field' => 'booking_outflight_flightnum'),
- 'booking_outflight_origin' => array('data' => t('Description'), 'field' => 'booking_outflight_origin'),
- 'booking_outflight_origin_ts' => array('data' => t('Departure Time'), 'field' => 'booking_outflight_origin_ts'),
- 'booking_outflight_connecting_flightnum' => array('data' => t('Connecting Flight'), 'field' => 'booking_outflight_connecting_flightnum'),
- 'booking_outflight_destination' => array('data' => t('Description'), 'field' => 'booking_outflight_destination'),
- 'booking_outflight_destination_ts' => array('data' => t('Time'), 'field' => 'booking_outflight_destination_ts'),
- 'booking_rtrnflight_bookingnum' => array('data' => t('Return Reference'), 'field' => 'booking_rtrnflight_bookingnum'),
- 'booking_rtrnflight_flightnum' => array('data' => t('Flight #'), 'field' => 'booking_rtrnflight_flightnum'),
- 'booking_rtrnflight_origin' => array('data' => t('Description'), 'field' => 'booking_rtrnflight_origin'),
- 'booking_rtrnflight_origin_ts' => array('data' => t('Time'), 'field' => 'booking_rtrnflight_origin_ts'),
- );
+ global $event;
+ $form = array();
+ $prefix = t("Internal Flight Details
\nView flight information for all attendees with status currently set to booked in.
");
+
+ $header = array(
+ 'booking_name' => array('data' => t('Name'), 'field' => 'booking_lastname'),
+ 'booking_destination_country' => array('data' => t('Country'), 'field' => 'booking_destination_country'),
+ 'booking_outflight_bookingnum' => array('data' => t('Reference'), 'field' => 'booking_outflight_bookingnum'),
+ 'booking_outflight_flightnum' => array('data' => t('Flight #'), 'field' => 'booking_outflight_flightnum'),
+ 'booking_outflight_origin' => array('data' => t('Description'), 'field' => 'booking_outflight_origin'),
+ 'booking_outflight_origin_ts' => array('data' => t('Departure Time'), 'field' => 'booking_outflight_origin_ts'),
+ 'booking_outflight_connecting_flightnum' => array('data' => t('Connecting Flight'), 'field' => 'booking_outflight_connecting_flightnum'),
+ 'booking_outflight_destination' => array('data' => t('Description'), 'field' => 'booking_outflight_destination'),
+ 'booking_outflight_destination_ts' => array('data' => t('Time'), 'field' => 'booking_outflight_destination_ts'),
+ 'booking_rtrnflight_bookingnum' => array('data' => t('Return Reference'), 'field' => 'booking_rtrnflight_bookingnum'),
+ 'booking_rtrnflight_flightnum' => array('data' => t('Flight #'), 'field' => 'booking_rtrnflight_flightnum'),
+ 'booking_rtrnflight_origin' => array('data' => t('Description'), 'field' => 'booking_rtrnflight_origin'),
+ 'booking_rtrnflight_origin_ts' => array('data' => t('Time'), 'field' => 'booking_rtrnflight_origin_ts'),
+ );
- $query = db_select('booking_person', 'p');
- $query->fields('p');
-
- $db_and = db_and();
- $db_and->condition('p.booking_eventid', $event->eid, '=');
- $db_and->condition('p.booking_status', 1, '=');
- $query->condition($db_and);
+ $query = db_select('booking_person', 'p');
+ $query->fields('p');
+
+ $db_and = db_and();
+ $db_and->condition('p.booking_eventid', $event->eid, '=');
+ $db_and->condition('p.booking_status', 1, '=');
+ $query->condition($db_and);
- $table_sort = $query->extend('TableSort')->orderbyHeader($header);
- $result = $table_sort->execute();
+ $table_sort = $query->extend('TableSort')->orderbyHeader($header);
+ $result = $table_sort->execute();
- foreach($result as $data)
- {
- $name_link = l(t('!first !last', array('!first' => ucwords($data->booking_firstname), '!last' => ucwords($data->booking_lastname))),
- t('node/!id', array('!id' => $data->nid))
- );
-
- $rows[] = array (
- 'data' => array(
- $name_link,
- $data->booking_destination_country,
- $data->booking_outflight_bookingnum,
- $data->booking_outflight_flightnum,
- $data->booking_outflight_origin,
- $data->booking_outflight_origin_ts == 0 ? '' : format_date($data->booking_outflight_origin_ts, 'custom', 'd/m/Y H:i'),
- $data->booking_outflight_connecting_flightnum,
- $data->booking_outflight_destination,
- $data->booking_outflight_destination_ts == 0 ? '' : format_date($data->booking_outflight_destination_ts, 'custom', 'd/m/Y H:i'),
- $data->booking_rtrnflight_bookingnum,
- $data->booking_rtrnflight_flightnum,
- $data->booking_rtrnflight_origin,
- $data->booking_rtrnflight_origin_ts == 0 ? '' : format_date($data->booking_rtrnflight_origin_ts, 'custom', 'd/m/Y H:i'),
- ),
- );
- }
+ foreach($result as $data)
+ {
+ $name_link = l(t('!first !last', array('!first' => ucwords($data->booking_firstname), '!last' => ucwords($data->booking_lastname))),
+ t('node/!id', array('!id' => $data->nid))
+ );
+
+ $rows[] = array (
+ 'data' => array(
+ $name_link,
+ $data->booking_destination_country,
+ $data->booking_outflight_bookingnum,
+ $data->booking_outflight_flightnum,
+ $data->booking_outflight_origin,
+ $data->booking_outflight_origin_ts == 0 ? '' : format_date($data->booking_outflight_origin_ts, 'custom', 'd/m/Y H:i'),
+ $data->booking_outflight_connecting_flightnum,
+ $data->booking_outflight_destination,
+ $data->booking_outflight_destination_ts == 0 ? '' : format_date($data->booking_outflight_destination_ts, 'custom', 'd/m/Y H:i'),
+ $data->booking_rtrnflight_bookingnum,
+ $data->booking_rtrnflight_flightnum,
+ $data->booking_rtrnflight_origin,
+ $data->booking_rtrnflight_origin_ts == 0 ? '' : format_date($data->booking_rtrnflight_origin_ts, 'custom', 'd/m/Y H:i'),
+ ),
+ );
+ }
- $result = array (
- 'first_para' => array (
- '#type' => 'markup',
- '#markup' => $prefix,
- ),
- 'table' => array (
- '#theme' => 'table',
- '#header' => $header,
- '#rows' => $rows,
- '#attributes' => array('id' => 'sort-table'),
- //'#sticky' => FALSE,
- )
- );
-
- return $result;
+ $result = array (
+ 'first_para' => array (
+ '#type' => 'markup',
+ '#markup' => $prefix,
+ ),
+ 'table' => array (
+ '#theme' => 'table',
+ '#header' => $header,
+ '#rows' => $rows,
+ '#attributes' => array('id' => 'sort-table'),
+ //'#sticky' => FALSE,
+ )
+ );
+
+ return $result;
}
/**
* List everyone's travel info
*/
function booking_report_travel() {
- global $event;
- //$form = array();
- $prefix = t("Travel Details
");
+ global $event;
+ //$form = array();
+ $prefix = t("Travel Details
");
- //define sorting information with the header
- //as per http://www.drup-all.com/blog/table-sort-pagination-drupal-7
- $header = array();
- $header[] = array('data' => t('Name'), 'field' => 'booking_lastname');
- //$header[] = array('data' => t('Edit'), 'field' => 'nid', 'sort' => 'asc');
- $header[] = array('data' => t('State'), 'field' => 'booking_state');
- $header[] = array('data' => t('Transport Type'), 'field' => 'booking_transport_type');
- $header[] = array('data' => t('Catching train from airport?'), 'field' => 'booking_transport_from_morriset_reqd');
- $header[] = array('data' => t('Inbound Flight'), 'field' => 'booking_flightnum_inbound');
- $header[] = array('data' => t('Inbound Time'), 'field' => 'booking_flight_datetime_inbound');
- $header[] = array('data' => t('Outbound Flight'), 'field' => 'booking_flightnum_outbound');
- $header[] = array('data' => t('Outbound Time'), 'field' => 'booking_flight_datetime_outbound');
- $header[] = array('data' => t('Accommodation Before?'), 'field' => 'booking_accom_before_reqd');
- $header[] = array('data' => t('Accommodation After?'), 'field' => 'booking_accom_after_reqd');
+ //define sorting information with the header
+ //as per http://www.drup-all.com/blog/table-sort-pagination-drupal-7
+ $header = array();
+ $header[] = array('data' => t('Name'), 'field' => 'booking_lastname');
+ //$header[] = array('data' => t('Edit'), 'field' => 'nid', 'sort' => 'asc');
+ $header[] = array('data' => t('State'), 'field' => 'booking_state');
+ $header[] = array('data' => t('Transport Type'), 'field' => 'booking_transport_type');
+ $header[] = array('data' => t('Catching train from airport?'), 'field' => 'booking_transport_from_morriset_reqd');
+ $header[] = array('data' => t('Inbound Flight'), 'field' => 'booking_flightnum_inbound');
+ $header[] = array('data' => t('Inbound Time'), 'field' => 'booking_flight_datetime_inbound');
+ $header[] = array('data' => t('Outbound Flight'), 'field' => 'booking_flightnum_outbound');
+ $header[] = array('data' => t('Outbound Time'), 'field' => 'booking_flight_datetime_outbound');
+ $header[] = array('data' => t('Accommodation Before?'), 'field' => 'booking_accom_before_reqd');
+ $header[] = array('data' => t('Accommodation After?'), 'field' => 'booking_accom_after_reqd');
- //get travel info from database
- $query = db_select('booking_person', 'p');
- $query->leftJoin('booking_travel', 't', 'p.nid = t.booking_person_nid');
- //include people either booked in or on the waiting list or hosts, that belong to the current event id
- $db_or = db_or();
- $db_or->condition('p.booking_status', 1, '=');
- $db_or->condition('p.booking_status', 2, '=');
- $db_or->condition('p.booking_status', 5, '=');
- $db_and = db_and()->condition('p.booking_eventid', $event->eid, '=')->condition($db_or);
- $query->condition($db_and);
- $query->fields('p')->fields('t');
- //allow user to sort columns
- $table_sort = $query->extend('TableSort')->orderbyHeader($header);
- $result = $table_sort->execute();
-
- foreach ($result as $person) {
- $this_row = array();
+ //get travel info from database
+ $query = db_select('booking_person', 'p');
+ $query->leftJoin('booking_travel', 't', 'p.nid = t.booking_person_nid');
+ //include people either booked in or on the waiting list or hosts, that belong to the current event id
+ $db_or = db_or();
+ $db_or->condition('p.booking_status', 1, '=');
+ $db_or->condition('p.booking_status', 2, '=');
+ $db_or->condition('p.booking_status', 5, '=');
+ $db_and = db_and()->condition('p.booking_eventid', $event->eid, '=')->condition($db_or);
+ $query->condition($db_and);
+ $query->fields('p')->fields('t');
+ //allow user to sort columns
+ $table_sort = $query->extend('TableSort')->orderbyHeader($header);
+ $result = $table_sort->execute();
+
+ foreach ($result as $person) {
+ $this_row = array();
- //define the row for this person
- //$this_row[] = $travel_link = l(t('Travel'), t('node/!id', array('!id' => $person->tid)));
- //$this_row[] = l(t('Edit !id', array('!id' => $person->nid)), t('node/!id/edit', array('!id' => $person->nid)));
- $this_row[] = l(t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))),
- t('node/!id', array('!id' => $person->tid))
- );
- $this_row[] = t('!state', array('!state' => $person->booking_state));
- //$this_row[] = _booking_status_generate($person->booking_status);
+ //define the row for this person
+ //$this_row[] = $travel_link = l(t('Travel'), t('node/!id', array('!id' => $person->tid)));
+ //$this_row[] = l(t('Edit !id', array('!id' => $person->nid)), t('node/!id/edit', array('!id' => $person->nid)));
+ $this_row[] = l(t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))),
+ t('node/!id', array('!id' => $person->tid))
+ );
+ $this_row[] = t('!state', array('!state' => $person->booking_state));
+ //$this_row[] = _booking_status_generate($person->booking_status);
- $class = $person->booking_transport_type == 'Flying' ? "flying-row" : "normal-row";
+ $class = $person->booking_transport_type == 'Flying' ? "flying-row" : "normal-row";
- //calculate the travel link
- if ($person->tid > 0) {
- //$travel_link = l(t('Travel'), t('node/!id/edit', array('!id' => $person->tid)));
- $this_row[] = t('!transport', array('!transport' => $person->booking_transport_type));
- $this_row[] = t('!train', array('!train' => $person->booking_transport_from_morriset_reqd == 1 ? 'Yes' : 'No'));
- $this_row[] = t('!inflightnum', array('!inflightnum' => $person->booking_flightnum_inbound));
- $this_row[] = t('!inflighttime', array('!inflighttime' =>
- $person->booking_flight_datetime_inbound == 0 ? '' : format_date($person->booking_flight_datetime_inbound, 'custom', 'd/m/Y H:i')));
- $this_row[] = t('!outflightnum', array('!outflightnum' => $person->booking_flightnum_outbound));
- $this_row[] = t('!outflighttime', array('!outflighttime' =>
- $person->booking_flight_datetime_outbound == 0 ? '' : format_date($person->booking_flight_datetime_outbound, 'custom', 'd/m/Y H:i')));
- $this_row[] = t('!beforeaccom', array('!beforeaccom' => $person->booking_accom_before_reqd == 1 ? 'Yes' : 'No'));
- $this_row[] = t('!afteraccom', array('!afteraccom' => $person->booking_accom_after_reqd == 1 ? 'Yes' : 'No'));
+ //calculate the travel link
+ if ($person->tid > 0) {
+ //$travel_link = l(t('Travel'), t('node/!id/edit', array('!id' => $person->tid)));
+ $this_row[] = t('!transport', array('!transport' => $person->booking_transport_type));
+ $this_row[] = t('!train', array('!train' => $person->booking_transport_from_morriset_reqd == 1 ? 'Yes' : 'No'));
+ $this_row[] = t('!inflightnum', array('!inflightnum' => $person->booking_flightnum_inbound));
+ $this_row[] = t('!inflighttime', array('!inflighttime' =>
+ $person->booking_flight_datetime_inbound == 0 ? '' : format_date($person->booking_flight_datetime_inbound, 'custom', 'd/m/Y H:i')));
+ $this_row[] = t('!outflightnum', array('!outflightnum' => $person->booking_flightnum_outbound));
+ $this_row[] = t('!outflighttime', array('!outflighttime' =>
+ $person->booking_flight_datetime_outbound == 0 ? '' : format_date($person->booking_flight_datetime_outbound, 'custom', 'd/m/Y H:i')));
+ $this_row[] = t('!beforeaccom', array('!beforeaccom' => $person->booking_accom_before_reqd == 1 ? 'Yes' : 'No'));
+ $this_row[] = t('!afteraccom', array('!afteraccom' => $person->booking_accom_after_reqd == 1 ? 'Yes' : 'No'));
- //mark people requiring accommodation in a different colour so they stand out more
- if ($person->booking_accom_before_reqd == 1 || $person->booking_accom_after_reqd == 1) {
- $class = "accomm-row";
- }
- }
- else {
- $this_row[] = "N/A";
- //put in empty fields to fill up the table columns
- for ($i = 0; $i < 7; $i++) {
- $this_row[] = "";
- }
- }
- $rows[] = array('data' => $this_row, 'class' => array($class));
- }
+ //mark people requiring accommodation in a different colour so they stand out more
+ if ($person->booking_accom_before_reqd == 1 || $person->booking_accom_after_reqd == 1) {
+ $class = "accomm-row";
+ }
+ }
+ else {
+ $this_row[] = "N/A";
+ //put in empty fields to fill up the table columns
+ for ($i = 0; $i < 7; $i++) {
+ $this_row[] = "";
+ }
+ }
+ $rows[] = array('data' => $this_row, 'class' => array($class));
+ }
- $result = array (
- '#attached' => array (
- 'css' => array(drupal_get_path('module', 'booking') . '/booking.css')
- ),
- 'first_para' => array (
- '#type' => 'markup',
- '#markup' => $prefix,
- ),
- 'table' => array (
- '#theme' => 'table',
- '#header' => $header,
- '#rows' => $rows,
- '#attributes' => array('id' => 'sort-table'),
- //'#sticky' => FALSE,
- )
- );
-
- return $result;
+ $result = array (
+ '#attached' => array (
+ 'css' => array(drupal_get_path('module', 'booking') . '/booking.css')
+ ),
+ 'first_para' => array (
+ '#type' => 'markup',
+ '#markup' => $prefix,
+ ),
+ 'table' => array (
+ '#theme' => 'table',
+ '#header' => $header,
+ '#rows' => $rows,
+ '#attributes' => array('id' => 'sort-table'),
+ //'#sticky' => FALSE,
+ )
+ );
+
+ return $result;
}
function booking_coming_page() {
- global $event;
- $output = "";
- $table = "";
- $attributes = array('style' => 'width:50%;/* margin-left:25%; margin-right:25%;*/');
- $booking_limit = variable_get('booking_regn_limit','350');
- $rows = array();
-
- //work out whether to include the team colour in this page
- if (variable_get('booking_publish_readinggroups', 0) == 1) {
- $header = array('Name', 'Team Colour', 'State');
- }
- else {
- $header = array('Name', 'State');
- }
+ global $event;
+ $output = "";
+ $table = "";
+ $attributes = array('style' => 'width:50%;/* margin-left:25%; margin-right:25%;*/');
+ $booking_limit = variable_get('booking_regn_limit','350');
+ $rows = array();
+
+ //work out whether to include the team colour in this page
+ if (variable_get('booking_publish_readinggroups', 0) == 1) {
+ $header = array('Name', 'Team Colour', 'State');
+ }
+ else {
+ $header = array('Name', 'State');
+ }
- //if configuration is set to show on lists even when no payment has been made, then include booking status of 0 (unpaid) or 1 (booked in)
- //also ensure any committee members always show
- if (variable_get('booking_auto_show_on_lists', 1) == 1) {
- $or = db_or()->condition('p.booking_status', 0)->condition('p.booking_status', 1)>condition('p.booking_committee_member', 'Y');
- $result = db_select('booking_person', 'p')
- ->fields('p', array('booking_firstname', 'booking_lastname', 'booking_state', 'booking_readinggroup', 'booking_country'))
- ->condition($or)
- ->condition('p.booking_eventid', $event->eid, '=')
- ->orderBy('booking_country')
- ->orderBy('booking_state')
- ->orderBy('booking_lastname')
- ->orderBy('booking_firstname')
- ->execute();
- }
- else {
- //payment must be made before someone will show up as booked in, but also include any committee member that might not have paid
- $or = db_or()->condition('p.booking_status', 1)->condition('p.booking_committee_member', 'Y');
- $result = db_select('booking_person', 'p')
- ->fields('p', array('booking_firstname', 'booking_lastname', 'booking_state', 'booking_readinggroup', 'booking_country'))
- ->condition($or)
- ->condition('p.booking_eventid', $event->eid, '=')
- ->orderBy('booking_country')
- ->orderBy('booking_state')
- ->orderBy('booking_lastname')
- ->orderBy('booking_firstname')
- ->execute();
- }
+ //if configuration is set to show on lists even when no payment has been made, then include booking status of 0 (unpaid) or 1 (booked in)
+ //also ensure any committee members always show
+ if (variable_get('booking_auto_show_on_lists', 1) == 1) {
+ $or = db_or()->condition('p.booking_status', 0)->condition('p.booking_status', 1)>condition('p.booking_committee_member', 'Y');
+ $result = db_select('booking_person', 'p')
+ ->fields('p', array('booking_firstname', 'booking_lastname', 'booking_state', 'booking_readinggroup', 'booking_country'))
+ ->condition($or)
+ ->condition('p.booking_eventid', $event->eid, '=')
+ ->orderBy('booking_country')
+ ->orderBy('booking_state')
+ ->orderBy('booking_lastname')
+ ->orderBy('booking_firstname')
+ ->execute();
+ }
+ else {
+ //payment must be made before someone will show up as booked in, but also include any committee member that might not have paid
+ $or = db_or()->condition('p.booking_status', 1)->condition('p.booking_committee_member', 'Y');
+ $result = db_select('booking_person', 'p')
+ ->fields('p', array('booking_firstname', 'booking_lastname', 'booking_state', 'booking_readinggroup', 'booking_country'))
+ ->condition($or)
+ ->condition('p.booking_eventid', $event->eid, '=')
+ ->orderBy('booking_country')
+ ->orderBy('booking_state')
+ ->orderBy('booking_lastname')
+ ->orderBy('booking_firstname')
+ ->execute();
+ }
- foreach ($result as $person) {
- $state = $person->booking_country === variable_get('booking_default_country') ? $person->booking_state : $person->booking_country;
-
- //if we're allowed to publish reading groups, specify them in the array element
- if (variable_get('booking_publish_readinggroups', 0) == 1) {
- $rows[] = array(
- t('!first !last', array('!first' => ucwords($person->booking_firstname),
- '!last' => ucwords($person->booking_lastname))),
- t('!group',array('!group' => $person->booking_readinggroup)),
- t('!state', array('!state' => $state)),
- );
- }
- //don't publish reading group information
- else {
- $rows[] = array(
- t('!first !last', array('!first' => ucwords($person->booking_firstname),
- '!last' => ucwords($person->booking_lastname))),
- t('!state', array('!state' => $state)),
- );
- }
- }
-
- //watchdog('booking', "Who's coming formatted: @info", array('@info' => var_export($rows, TRUE)));
-
- //output the results
- //check there were some bookings
- if (count($rows) > 0) {
- if (count($rows) >= $booking_limit) {
- //there is a waiting list
- $output .= token_replace(variable_get('booking_whoscoming_pre_waitlist_text'), booking_define_tokens());
- }
- else {
- //there's no waiting list
- $output .= token_replace(variable_get('booking_whoscoming_pre_text'), booking_define_tokens());
- }
-
- //theme the table of registrations
- $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes));
- }
- else {
- //no bookings
- $output .= token_replace(variable_get('booking_whoscoming_pre_noregistrations_text'), booking_define_tokens());
- }
-
- //include any post-text
- $output .= token_replace(variable_get('booking_whoscoming_post_text'), booking_define_tokens());
-
- return $output;
+ foreach ($result as $person) {
+ $state = $person->booking_country === variable_get('booking_default_country') ? $person->booking_state : $person->booking_country;
+
+ //if we're allowed to publish reading groups, specify them in the array element
+ if (variable_get('booking_publish_readinggroups', 0) == 1) {
+ $rows[] = array(
+ t('!first !last', array('!first' => ucwords($person->booking_firstname),
+ '!last' => ucwords($person->booking_lastname))),
+ t('!group',array('!group' => $person->booking_readinggroup)),
+ t('!state', array('!state' => $state)),
+ );
+ }
+ //don't publish reading group information
+ else {
+ $rows[] = array(
+ t('!first !last', array('!first' => ucwords($person->booking_firstname),
+ '!last' => ucwords($person->booking_lastname))),
+ t('!state', array('!state' => $state)),
+ );
+ }
+ }
+
+ //watchdog('booking', "Who's coming formatted: @info", array('@info' => var_export($rows, TRUE)));
+
+ //output the results
+ //check there were some bookings
+ if (count($rows) > 0) {
+ if (count($rows) >= $booking_limit) {
+ //there is a waiting list
+ $output .= token_replace(variable_get('booking_whoscoming_pre_waitlist_text'), booking_define_tokens());
+ }
+ else {
+ //there's no waiting list
+ $output .= token_replace(variable_get('booking_whoscoming_pre_text'), booking_define_tokens());
+ }
+
+ //theme the table of registrations
+ $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes));
+ }
+ else {
+ //no bookings
+ $output .= token_replace(variable_get('booking_whoscoming_pre_noregistrations_text'), booking_define_tokens());
+ }
+
+ //include any post-text
+ $output .= token_replace(variable_get('booking_whoscoming_post_text'), booking_define_tokens());
+
+ return $output;
}
function booking_waitinglist_page() {
- global $event;
- $output = "";
- $table = "";
- $count = 1;
- //$header = array('Name', 'Occupation', 'State');
- $header = array('Name', 'State', 'Position');
- $booking_limit = variable_get('booking_regn_limit','350');
- $rows = array();
+ global $event;
+ $output = "";
+ $table = "";
+ $count = 1;
+ //$header = array('Name', 'Occupation', 'State');
+ $header = array('Name', 'State', 'Position');
+ $booking_limit = variable_get('booking_regn_limit','350');
+ $rows = array();
- $result = _booking_get_waitinglist();
- /*
- $result = db_query('SELECT DISTINCT nid, booking_firstname, booking_lastname, booking_state, booking_readinggroup, booking_country, booking_status
- FROM (
- SELECT p.nid, p.booking_firstname, p.booking_lastname, p.booking_state, p.booking_country, p.booking_readinggroup, pay.booking_payment_date, p.booking_status
- FROM {booking_person} p, {booking_payment} pay
- WHERE p.booking_eventid = :eid and p.nid = pay.booking_person_nid and ( p.booking_status = 2 or p.booking_status = 4)
- ) AS booking
- ORDER BY booking_status, booking_payment_date',
- array(':eid' => $event->eid));
- */
-
- //watchdog('booking', "Who's coming query: @info", array('@info' => var_export($result, TRUE)));
-
- foreach ($result as $person) {
- $rows[] = array(
- t('!first !last', array('!first' => ucwords($person->booking_firstname),
- '!last' => ucwords($person->booking_lastname))),
- //only for when we have readings groups
- //t('!group',array('!group' => $person->booking_readinggroup)),
- t('!state', array('!state' => $person->booking_country == 'Australia' ? $person->booking_state : $person->booking_country)),
- t($count++),
- );
- }
- //watchdog('booking', "Who's coming formatted: @info", array('@info' => var_export($rows, TRUE)));
-
-
- //output the results
- //check there were people on the waiting list
- if (count($rows) > 0)
- {
- //include the pre-text
- $output .= token_replace(variable_get('booking_waitingpage_pre_text'), booking_define_tokens());
-
- //theme the table of waiting list people
- $output .= theme('table', array('header' => $header, 'rows' => $rows));
- }
- else
- {
- //no one on the waiting list
- $output .= token_replace(variable_get('booking_waitingpage_pre_nowaitlist_text'), booking_define_tokens());
- }
-
- //include any post-text
- $output .= token_replace(variable_get('booking_waitingpage_post_text'), booking_define_tokens());
-
- return $output;
+ $result = _booking_get_waitinglist();
+ /*
+ $result = db_query('SELECT DISTINCT nid, booking_firstname, booking_lastname, booking_state, booking_readinggroup, booking_country, booking_status
+ FROM (
+ SELECT p.nid, p.booking_firstname, p.booking_lastname, p.booking_state, p.booking_country, p.booking_readinggroup, pay.booking_payment_date, p.booking_status
+ FROM {booking_person} p, {booking_payment} pay
+ WHERE p.booking_eventid = :eid and p.nid = pay.booking_person_nid and ( p.booking_status = 2 or p.booking_status = 4)
+ ) AS booking
+ ORDER BY booking_status, booking_payment_date',
+ array(':eid' => $event->eid));
+ */
+
+ //watchdog('booking', "Who's coming query: @info", array('@info' => var_export($result, TRUE)));
+
+ foreach ($result as $person) {
+ $rows[] = array(
+ t('!first !last', array('!first' => ucwords($person->booking_firstname),
+ '!last' => ucwords($person->booking_lastname))),
+ //only for when we have readings groups
+ //t('!group',array('!group' => $person->booking_readinggroup)),
+ t('!state', array('!state' => $person->booking_country == 'Australia' ? $person->booking_state : $person->booking_country)),
+ t($count++),
+ );
+ }
+ //watchdog('booking', "Who's coming formatted: @info", array('@info' => var_export($rows, TRUE)));
+
+
+ //output the results
+ //check there were people on the waiting list
+ if (count($rows) > 0)
+ {
+ //include the pre-text
+ $output .= token_replace(variable_get('booking_waitingpage_pre_text'), booking_define_tokens());
+
+ //theme the table of waiting list people
+ $output .= theme('table', array('header' => $header, 'rows' => $rows));
+ }
+ else
+ {
+ //no one on the waiting list
+ $output .= token_replace(variable_get('booking_waitingpage_pre_nowaitlist_text'), booking_define_tokens());
+ }
+
+ //include any post-text
+ $output .= token_replace(variable_get('booking_waitingpage_post_text'), booking_define_tokens());
+
+ return $output;
}
function ucname($string) {
@@ -698,208 +698,209 @@ function ucname($string) {
*/
function booking_csv_report() {
- global $event;
- $name = 'bookings-' . format_date(time(), 'custom', 'Y-m-d-His');
- $filename = file_directory_temp() . '/' . $name;
- $csv = '';
- $delimiter = ',';
- $enclosure = '"';
- $encloseAll = true;
- $nullToMysqlNull = true;
+ global $event;
+ $name = 'bookings-' . format_date(time(), 'custom', 'Y-m-d-His');
+ $filename = file_directory_temp() . '/' . $name;
+ $csv = '';
+ $delimiter = ',';
+ $enclosure = '"';
+ $encloseAll = true;
+ $nullToMysqlNull = true;
$delimiter_esc = preg_quote($delimiter, '/');
$enclosure_esc = preg_quote($enclosure, '/');
- $readinggroup_id = "";
-
- //$readinggroup = "session" . variable_get('booking_readinggroup_id','7');
-
- //calculate fields to ignore in the output csv file
- $builtin_fields_to_skip = array('booking_eventid');
- $custom_fields_to_skip = explode(";", variable_get('booking_csv_exclude_fields', ''));
- $fields_to_skip = array_merge($builtin_fields_to_skip, $custom_fields_to_skip);
-
- //keep a list of any fields that we need to handle as dates
- $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');
- $number_only_fields = array('booking_postcode', 'booking_mobile', 'booking_phone', 'booking_guardian_phone', 'booking_guardian_phone_alt');
+ $readinggroup_id = "";
+
+ //$readinggroup = "session" . variable_get('booking_readinggroup_id','7');
+
+ //calculate fields to ignore in the output csv file
+ $builtin_fields_to_skip = array('booking_eventid');
+ $custom_fields_to_skip = explode(";", variable_get('booking_csv_exclude_fields', ''));
+ $fields_to_skip = array_merge($builtin_fields_to_skip, $custom_fields_to_skip);
+
+ //keep a list of any fields that we need to handle as dates
+ $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');
+ $number_only_fields = array('booking_postcode', 'booking_mobile', 'booking_phone', 'booking_guardian_phone', 'booking_guardian_phone_alt');
- //look up the titles of the study groups and add to array for updating in the header
- $studygroup_descriptions = array();
- $studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid",
- array(':eid' => $event->eid));
- $studygroups = $studygroups_query->fetchAllAssoc('sid');
-
+ //look up the titles of the study groups and add to array for updating in the header
+ $studygroup_descriptions = array();
+ $studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid",
+ array(':eid' => $event->eid));
+ $studygroups = $studygroups_query->fetchAllAssoc('sid');
+
//update array for turning study group session IDs into the name for that group
- foreach ($studygroups as $studygroup) {
- //calculate the session references
- $sessionid = "session" . $studygroup->sid;
- $roleid = $sessionid . "_role";
- $description = $studygroup->booking_studygroup_descrip;
-
- $studygroup_descriptions[$sessionid] = $description;
- $studygroup_descriptions[$roleid] = $description . " Role";
-
- if ($studygroup->booking_is_readinggroup == 'Y') {
- $readinggroup_id = $sessionid;
- }
- }
+ foreach ($studygroups as $studygroup) {
+ //calculate the session references
+ $sessionid = "session" . $studygroup->sid;
+ $roleid = $sessionid . "_role";
+ $description = $studygroup->booking_studygroup_descrip;
+
+ $studygroup_descriptions[$sessionid] = $description;
+ $studygroup_descriptions[$roleid] = $description . " Role";
+
+ if ($studygroup->booking_is_readinggroup == 'Y') {
+ $readinggroup_id = $sessionid;
+ }
+ }
- //pivot table based on http://anothermysqldba.blogspot.de/2013/06/pivot-tables-example-in-mysql.html
- $result = booking_load_query(NULL, TRUE);
-
- //watchdog('booking', "CSV raw data: @info", array('@info' => var_export($result, TRUE)));
-
- //write the header based on the first result
- $header_array = array();
- foreach (reset($result) as $key => $value) {
- if (in_array($key, $fields_to_skip)) {
- continue;
- }
-
- //Replace headings for study group sessions and roles with the name of the study group rather than just sessionN and sessionN_role etc
- if (variable_get('booking_friendly_csv_groupnames','0') == 1 && array_key_exists($key, $studygroup_descriptions)) {
- $header_array[] = $studygroup_descriptions[$key];
- continue;
- }
-
- $header_array[] = $key;
- //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_gross";
- $header_array[] = "booking_amount_owing_net";
- }
- }
-
- $header = implode( $delimiter, $header_array );
- //watchdog('booking', "CSV header: @info", array('@info' => var_export($header_array, TRUE)));
- //@fwrite($handle, $header . "\n");
- $csv .= $header . "\n";
- //each record
- foreach ($result as $record) {
-
- //watchdog('booking', "CSV raw data entry: @info", array('@info' => var_export($record, TRUE)));
-
- $output = array();
- //each keypair in the record
- foreach ($record as $key => $value)
- {
- //fields to skip
- if (in_array($key, $fields_to_skip))
- continue;
-
- //check for null
- if ($value === NULL && $nullToMysqlNull) {
- $output[] = 'NULL';
- continue;
- }
-
- //capitalise street name and suburb name
- if ($key == 'booking_street' || $key == 'booking_suburb')
- $value = ucname($value);
-
- //handle dates
- if ($key == 'booking_dob') {
- $output[] = format_date($value, 'custom', 'd/m/Y');
- $output[] = '"' . _booking_avg_age($value, 1, $event->booking_event_start) . '"';
- continue;
- }
- if ($key == 'booking_passport_expiry_date') {
- $output[] = format_date($value, 'custom', 'd/m/Y');
- continue;
- }
-
- //handle more exact dates
- if (in_array($key, $datetime_fields)) {
- $output[] = $value == 0 ? '0' : format_date($value, 'custom', 'd/m/Y H:i');
- continue;
- }
-
- //handle numerical fields
- if (in_array($key, $number_only_fields)) {
- $output[] = $value . "\t";
- continue;
- }
-
- //booking status
- if ($key == 'booking_status') {
- $output[] = _booking_status_generate($value);
- continue;
- }
- //studygroup ygroup session roles
- if (preg_match("/session\d+_role/", $key))
- {
- $output[] = _booking_studygroup_role_lookup($value);
- continue;
- }
-
- /*
- //this is not required since node_load already has the room location description for each attendee
- //room location
- if ($key == 'booking_room_location_id') {
- $output[] = $room_locations[$value]->booking_roomlocation_descrip;
- continue;
- }
- */
-
- //room bed type
- if ($key == 'booking_room_bedtype') {
- $output[] = _booking_room_bedtype_lookup($value);
- continue;
- }
-
- //reading group team colour
- if ($key == $readinggroup_id) {
- $output[] = _booking_readinggroup_colour_lookup($value);
- continue;
- }
-
- //add in the amount owing using the nid as the key
- if ($key == 'nid')
- {
- $output[] = $value;
- //add the amount owing firstly including paypal fees then excluding them
- //bit of a hack since this can never be excluded from the report
- $output[] = _booking_amount_owing($record, 0, TRUE);
- $output[] = _booking_amount_owing($record, 0, FALSE);
- 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;
- }
- else {
- $output[] = $field;
- }
- }
-
- $row = implode($delimiter, $output) . "\n";
-
- //@fwrite($handle, $row);
- $csv .= $row;
- //$index++;
+ //pivot table based on http://anothermysqldba.blogspot.de/2013/06/pivot-tables-example-in-mysql.html
+ $result = booking_load_query(NULL, TRUE);
+
+ //watchdog('booking', "CSV raw data: @info", array('@info' => var_export($result, TRUE)));
+
+ //write the header based on the first result
+ $header_array = array();
+ foreach (reset($result) as $key => $value) {
+ if (in_array($key, $fields_to_skip)) {
+ continue;
+ }
+
+ //Replace headings for study group sessions and roles with the name of the study group rather than just sessionN and sessionN_role etc
+ if (variable_get('booking_friendly_csv_groupnames','0') == 1 && array_key_exists($key, $studygroup_descriptions)) {
+ $header_array[] = $studygroup_descriptions[$key];
+ continue;
}
+ $header_array[] = $key;
+ //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_gross";
+ $header_array[] = "booking_amount_owing_net";
+ }
+ }
+
+ $header = implode( $delimiter, $header_array );
+ //watchdog('booking', "CSV header: @info", array('@info' => var_export($header_array, TRUE)));
+ //@fwrite($handle, $header . "\n");
+ $csv .= $header . "\n";
+ //each record
+ foreach ($result as $record) {
+ //watchdog('booking', "CSV raw data entry: @info", array('@info' => var_export($record, TRUE)));
+
+ $output = array();
+ //each keypair in the record
+ foreach ($record as $key => $value) {
+ //fields to skip
+ if (in_array($key, $fields_to_skip))
+ continue;
+
+ //check for null
+ if ($value === NULL && $nullToMysqlNull) {
+ $output[] = 'NULL';
+ continue;
+ }
+
+ //capitalise street name and suburb name
+ if ($key == 'booking_street' || $key == 'booking_suburb') {
+ $value = ucname($value);
+ }
+
+ //handle dates
+ if ($key == 'booking_dob') {
+ $output[] = format_date($value, 'custom', 'd/m/Y');
+ $output[] = '"' . _booking_avg_age($value, 1, $event->booking_event_start) . '"';
+ continue;
+ }
+
+ if ($key == 'booking_passport_expiry_date') {
+ $output[] = format_date($value, 'custom', 'd/m/Y');
+ continue;
+ }
+
+ //handle more exact dates
+ if (in_array($key, $datetime_fields)) {
+ $output[] = $value == 0 ? '0' : format_date($value, 'custom', 'd/m/Y H:i');
+ continue;
+ }
+
+ //handle numerical fields
+ if (in_array($key, $number_only_fields)) {
+ $output[] = $value . "\t";
+ continue;
+ }
+
+ //booking status
+ if ($key == 'booking_status') {
+ $output[] = _booking_status_generate($value);
+ continue;
+ }
+
+ //studygroup group session roles
+ if (preg_match("/session\d+_role/", $key))
+ {
+ $output[] = _booking_studygroup_role_lookup($value);
+ continue;
+ }
+
+ /*
+ //this is not required since node_load already has the room location description for each attendee
+ //room location
+ if ($key == 'booking_room_location_id') {
+ $output[] = $room_locations[$value]->booking_roomlocation_descrip;
+ continue;
+ }
+ */
+
+ //room bed type
+ if ($key == 'booking_room_bedtype') {
+ $output[] = _booking_room_bedtype_lookup($value);
+ continue;
+ }
+
+ //reading group team colour
+ if ($key == $readinggroup_id) {
+ $output[] = _booking_readinggroup_colour_lookup($value);
+ continue;
+ }
+
+ //add in the amount owing using the nid as the key
+ if ($key == 'nid') {
+ $output[] = $value;
+ //add the amount owing firstly including paypal fees then excluding them
+ //bit of a hack since this can never be excluded from the report
+ $output[] = _booking_amount_owing($record, 0, TRUE);
+ $output[] = _booking_amount_owing($record, 0, FALSE);
+ 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;
+ }
+ else {
+ $output[] = $field;
+ }
+
+ }
+
+ $row = implode($delimiter, $output) . "\n";
+
+ //@fwrite($handle, $row);
+ $csv .= $row;
+ //$index++;
+ }
+
//@fclose($handle);
-
- //see http://stackoverflow.com/questions/4348802/how-can-i-output-a-utf-8-csv-in-php-that-excel-will-read-properly
- // but none of these options seem to work
+
+ //see http://stackoverflow.com/questions/4348802/how-can-i-output-a-utf-8-csv-in-php-that-excel-will-read-properly
+ // but none of these options seem to work
drupal_add_http_header("Content-type", "application/octet-stream; charset=utf-8");
- //drupal_add_http_header("Content-type", "application/octet-stream; charset=UTF-16LE");
- //drupal_add_http_header("Content-Type: application/vnd.ms-excel");
+ //drupal_add_http_header("Content-type", "application/octet-stream; charset=UTF-16LE");
+ //drupal_add_http_header("Content-Type: application/vnd.ms-excel");
drupal_add_http_header("Content-Disposition", "attachment; filename=" . $name . ".csv");
- // @readfile($filename);
- //print chr(255) . chr(254);
- //print 'sep=,' . "\n";
- print $csv;
- //print mb_convert_encoding($csv, 'UTF-16LE', 'UTF-8');
-
+ // @readfile($filename);
+ //print chr(255) . chr(254);
+ //print 'sep=,' . "\n";
+ print $csv;
+ //print mb_convert_encoding($csv, 'UTF-16LE', 'UTF-8');
+
//@unlink($filename);
exit(0);
}
diff --git a/booking.variety_admin.inc b/booking.variety_admin.inc
index 266077c..803f25b 100644
--- a/booking.variety_admin.inc
+++ b/booking.variety_admin.inc
@@ -28,7 +28,7 @@ function booking_variety_admin()
'variety_session_add' => t('Add Session'),
);
- $result = db_query("SELECT * from {booking_variety_times}");
+ $result = db_query("SELECT * from {booking_variety_timeslots}");
foreach($result as $data)
{
@@ -83,7 +83,7 @@ function booking_variety_timeslot_form($node, &$form_state, $create, $editid = 0
return "";
}
- $data = db_select ('booking_variety_times', 'v')
+ $data = db_select ('booking_variety_timeslots', 'v')
->condition('v.tid', $editid, '=')
->fields('v')
->execute()
@@ -165,7 +165,7 @@ function booking_variety_timeslot_form_submit($form, &$form_state) {
if ($form_state['values']['op'] == 'Create')
{
- db_insert('booking_variety_times')
+ db_insert('booking_variety_timeslots')
->fields(array(
'booking_eventid' => $event->eid,
'booking_variety_status' => $values['booking_variety_status'] == 1 ? 1 : 0,
@@ -183,7 +183,7 @@ function booking_variety_timeslot_form_submit($form, &$form_state) {
return "";
}
- $num_deleted = db_delete('booking_variety_times')
+ $num_deleted = db_delete('booking_variety_timeslots')
->condition('tid', $values['tid'])
->execute();
@@ -200,7 +200,7 @@ function booking_variety_timeslot_form_submit($form, &$form_state) {
}
//update the event
- db_update('booking_variety_times')
+ db_update('booking_variety_timeslots')
->fields(array (
'booking_eventid' => $event->eid,
'booking_variety_time_descrip' => $values['booking_variety_time_descrip'],
@@ -230,7 +230,7 @@ function booking_variety_create_session_form($node, &$form_state, $timeslot_id =
}
/*
- $data = db_select ('booking_variety_times', 'v')
+ $data = db_select ('booking_variety_timeslots', 'v')
->condition('v.tid', $editid, '=')
->fields('v')
->execute()
@@ -286,7 +286,7 @@ function booking_variety_create_session_form_submit($form, &$form_state) {
global $event;
$values = $form_state['input'];
- db_insert('booking_variety_options')
+ db_insert('booking_variety_sessions')
->fields(array(
'booking_eventid' => $event->eid,
'booking_variety_timeslot_id' => $values['tid'],
@@ -317,8 +317,8 @@ function booking_variety_list_session_form($node, &$form_state, $timeslot_id = 0
$prefix = t("!link
",
array ('!link' => l('Add New Variety Session', "admin/config/booking/variety/$timeslot_id/session/create")));
- $query = db_select ('booking_variety_options', 'v');
- $query->join('booking_variety_times', 't', 'v.booking_variety_timeslot_id = t.tid');
+ $query = db_select ('booking_variety_sessions', 'v');
+ $query->join('booking_variety_timeslots', 't', 'v.booking_variety_timeslot_id = t.tid');
$query->condition('v.booking_variety_timeslot_id', $timeslot_id, '=')
->fields('v')
->fields('t', array('booking_variety_time_descrip'));
@@ -368,3 +368,121 @@ function booking_variety_edit_session_form()
{
}
+
+
+/**
+ * Function to generate a CSV file listing the session membership for the specified variety session timeslot
+ */
+function booking_varietysessions_csv_report($timeslot_id) {
+ global $event;
+ $data = array();
+
+ //verify that $group_id is a number
+ if (! preg_match('/^[0-9]+$/', $timeslot_id)) {
+ drupal_set_message("Error: Invalid variety session timeslot ID '" . $group_id . "' supplied.", 'error', FALSE);
+ drupal_goto('admin/booking/studygroups');
+ return "";
+ }
+
+ // TODO - UPDATE FROM HERE ON!
+
+ //retrieve the name of the study group for the specified ID
+ $group = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid and sid = :sid",
+ array(':eid' => $event->eid, ':sid' => $group_id))
+ ->fetchObject();
+
+ if (! $group)
+ {
+ drupal_set_message("Error: Could not find matching study group ID. Unable to view group membership.", 'error', FALSE);
+ drupal_goto('admin/booking/studygroups');
+ return "";
+ }
+
+ //set options for the CSV file
+ $name = 'bookings-studygroup-' . $group->booking_studygroup_descrip . '-' . format_date(time(), 'custom', 'Y-m-d-His');
+ $filename = file_directory_temp() . '/' . $name;
+ $csv = '';
+ $delimiter = ',';
+ $enclosure = '"';
+ $encloseAll = true;
+ $nullToMysqlNull = true;
+ $delimiter_esc = preg_quote($delimiter, '/');
+ $enclosure_esc = preg_quote($enclosure, '/');
+
+ //get the list of study group session memberships
+ $session_members_query = db_query("SELECT m.*, p.* FROM {booking_studygroup_mapping} m
+ inner join {booking_person} p on p.nid = m.booking_node_id
+ WHERE m.booking_studygroup_id = :sid ORDER BY m.booking_session_id, m.booking_studygroup_role DESC, p.booking_lastname",
+ array(':sid' => $group_id));
+ $session_members = $session_members_query->fetchAll();
+
+ //generate the row data
+ foreach ($session_members as $member) {
+ if (! isset($data[$member->booking_session_id])) {
+ $data[$member->booking_session_id] = array();
+ }
+ // lookup the name and role for this entry in the study group session and optionally include age
+ if (variable_get('booking_studygroup_csv_ages', 0) == 1) {
+ $text = array($member->booking_firstname, $member->booking_lastname, '[' . _booking_get_age_years($member->booking_dob) .']');
+ }
+ else {
+ $text = array($member->booking_firstname, $member->booking_lastname);
+ }
+ //add their role if they're leading/helping etc
+ if ($member->booking_studygroup_role > 0) {
+ array_push($text, '(' . _booking_studygroup_role_lookup($member->booking_studygroup_role) . ')');
+ }
+ //also tag committee members
+ if ($member->booking_committee_member == 'Y') {
+ array_push($text, '(committee)');
+ }
+ //add the spaces and put this element in the right array
+ $data[$member->booking_session_id][] = implode(' ', $text);
+
+ }
+ //watchdog('booking_debug', "Study Group CSV Report\n@info
", array('@info' => print_r( $data_array, true)));
+
+ //calculate the CSV layout
+ $header_array = array_keys($data);
+ $maximums = array();
+ $column_headings = array();
+ foreach ($header_array as $column) {
+ $maximums[] = count($data[$column]);
+ //make the column headings a bit more user friendly
+ if ($group->booking_is_readinggroup == 'Y') {
+ $column_headings[] = _booking_readinggroup_colour_lookup($column);
+ }
+ else {
+ $column_headings[] = "Session " . $column;
+ }
+ }
+
+ //add the column headings to the CSV
+ $header = implode( $delimiter, $column_headings );
+ $csv .= $header . "\n";
+
+ //generate each row for the CSV
+ for ($i = 0; $i < max($maximums); $i++) {
+ $output = array();
+ foreach ($header_array as $column) {
+ $field = isset($data[$column][$i]) ? $data[$column][$i] : '';
+
+ //enclose $field if necessary
+ if ( $encloseAll || preg_match( "/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field ) ) {
+ $output[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field) . $enclosure;
+ }
+ else {
+ $output[] = $field;
+ }
+ } //loop through columns
+ $row = implode($delimiter, $output) . "\n";
+ $csv .= $row;
+
+ }
+
+ //output the CSV to the browser
+ drupal_add_http_header("Content-type", "application/octet-stream; charset=utf-8");
+ drupal_add_http_header("Content-Disposition", "attachment; filename=" . $name . ".csv");
+ print $csv;
+ exit(0);
+}
\ No newline at end of file
diff --git a/booking.variety_form.inc b/booking.variety_form.inc
index 33821ee..ef564cf 100644
--- a/booking.variety_form.inc
+++ b/booking.variety_form.inc
@@ -14,14 +14,14 @@ function booking_variety_regn_form($node, &$form_state)
$data = $node;
// Query the variety timeslot table
- $timeslot_query = db_select('booking_variety_times', 'v');
+ $timeslot_query = db_select('booking_variety_timeslots', 'v');
$timeslot_query->condition('v.booking_eventid', $event->eid, '=')
->fields('v')
->orderBy('v.booking_variety_start');
$result = $timeslot_query->execute();
- $form['#prefix'] = '';
- $form['#suffix'] = '
';
+ //$form['#prefix'] = '';
+ //$form['#suffix'] = '
';
$form['identity'] = array(
'#type' => 'fieldset',
@@ -93,13 +93,14 @@ function _booking_get_variety_timeslot_options($timeslot_id) {
$session_options = array();
$session_options[] = "--";
- $session_query = db_query("SELECT * FROM {booking_variety_options} WHERE booking_variety_timeslot_id = :tid AND booking_variety_status = 1",
+ $session_query = db_query("SELECT * FROM {booking_variety_sessions} WHERE booking_variety_timeslot_id = :tid AND booking_variety_status = 1",
array(':tid' => $timeslot_id));
// Only add sessions that aren't full to the return result
foreach($session_query as $session) {
- if ($session->booking_variety_regncount < $session->booking_variety_maxsize) {
- $session_options[$session->vid] = $session->booking_variety_descrip;
+ $available_spots = $session->booking_variety_maxsize - $session->booking_variety_regncount;
+ if ($available_spots > 0) {
+ $session_options[$session->vid] = $session->booking_variety_descrip . " [" . $available_spots . " spots]";
}
}
//watchdog('booking_debug', "Variety Session Options:\n@info
", array('@info' => print_r( $session_options, true)));
@@ -124,8 +125,6 @@ function booking_variety_regn_form_validate($form, &$form_state) {
$values = $form_state['input'];
//watchdog('booking_debug', 'booking_variety_regn_form_submit: @info
', array('@info' => print_r( $form_state, true)));
- //TODO : Check that the booking number is valid for this event
-
//verify that user-entered data is a number
if (! preg_match('/^[0-9]+$/', $values['booking_nid'])) {
form_set_error('booking_nid', t('You have entered an invalid booking reference number.'));
@@ -146,6 +145,29 @@ function booking_variety_regn_form_validate($form, &$form_state) {
if (! $person) {
form_set_error('booking_nid', t('You have entered an invalid booking reference number.'));
}
+
+ // --- Check there is still space available in the selected variety sessions ---
+
+ //get a list of timeslot IDs from matching form values
+ $variety_timeslot_ids = preg_filter('/^select-variety-(\d+)/', '$1', array_keys( $values ));
+
+ //query the sessions table
+ $sessions_query = db_query("SELECT * FROM {booking_variety_sessions} WHERE booking_eventid = :eid",
+ array(':eid' => $event->eid));
+ $sessions = $sessions_query->fetchAllAssoc('vid');
+
+ watchdog('booking_debug', 'booking_variety_regn_form_validate sessions query: @info
', array('@info' => print_r( $sessions, true)));
+
+ //check there is still room
+ foreach ($variety_timeslot_ids as $id) {
+ $selected_session_id = $values['select-variety-' . $id];
+
+ if ($sessions[$selected_session_id]->booking_variety_regncount < $sessions[$selected_session_id]->booking_variety_maxsize) {
+ watchdog('booking_debug', 'Still room in session ' . $selected_session_id);
+ }
+ }
+
+
}
/**
@@ -155,4 +177,7 @@ function booking_variety_regn_form_submit($form, &$form_state) {
global $event;
$values = $form_state['input'];
watchdog('booking_debug', 'booking_variety_regn_form_submit: @info
', array('@info' => print_r( $form_state, true)));
+
+ //use an update query for the regncount field
+ //based on update booking_variety_sessions set booking_variety_regncount = booking_variety_regncount+1 where vid = 1;
}
\ No newline at end of file
diff --git a/deprecated.php b/deprecated.php
index 5aa6d06..19799be 100644
--- a/deprecated.php
+++ b/deprecated.php
@@ -48,7 +48,7 @@ function booking_variety_session_callback($form, &$form_state) {
// --- Update the wrapper for available variety sessions ---
// Query the variety timeslot table
- $timeslot_query = db_select('booking_variety_times', 'v');
+ $timeslot_query = db_select('booking_variety_timeslots', 'v');
$timeslot_query->condition('v.booking_eventid', $event->eid, '=')
->fields('v')
->orderBy('v.booking_variety_start');
@@ -81,7 +81,7 @@ function booking_variety_session_callback($form, &$form_state) {
//$form['variety-sessions'][$fieldname]['#title'] = t('Rebuilt Variety Session: ' . $timeslot->booking_variety_time_descrip);
// Tell drupal to update the wrapper for this field
- $commands[] = ajax_command_replace('#booking_variety_session_' . $timeslot->tid . '_wrapper', drupal_render($form['variety-sessions'][$fieldname]));
+ $commands[] = ajax_command_replace('#booking_variety_session_' . $timeslot->tid . '_wrapper', drupal_render($form['form']['variety-sessions'][$fieldname]));
//$commands[] = ajax_command_replace('#booking_variety_session_' . $timeslot->tid . '_wrapper', drupal_render($form));
}