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("
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("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.
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("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("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.
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("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("View 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("View 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("!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'] = '
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)); }