Loads of changes

This commit is contained in:
2014-02-24 23:53:12 +11:00
parent 66d4c89679
commit b710954bdd
10 changed files with 357 additions and 251 deletions

View File

@@ -114,7 +114,7 @@ function booking_admin() {
$form['misc']['booking_auto_confirm_email'] = array ( $form['misc']['booking_auto_confirm_email'] = array (
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Automatic Registration Email'), '#title' => t('Automatic Registration Email'),
'#description' => t('Automatically send a confirmation email when a user registers for an event? (If No, email will be sent when status manually changed from Not Coming to Paid).'), '#description' => t('Automatically send a confirmation email when a user registers for an event? (If No, email will be sent when status manually changed from Not Coming to Paid). Recommended to set this to Yes if "Show on lists once booked in" is set to No.'),
'#options' => array (0 => t('No'), t('Yes')), '#options' => array (0 => t('No'), t('Yes')),
'#default_value' => variable_get('booking_auto_confirm_email', 0), '#default_value' => variable_get('booking_auto_confirm_email', 0),
); );
@@ -200,7 +200,7 @@ function booking_admin() {
'#default_value' => variable_get('booking_csv_exclude_fields', ''), '#default_value' => variable_get('booking_csv_exclude_fields', ''),
'#description' => 'Separate each field with a semi-colon. Field names as per database schema.', '#description' => 'Separate each field with a semi-colon. Field names as per database schema.',
'#size' => 150, '#size' => 150,
'#maxlength' => 500, '#maxlength' => 2000,
); );
return system_settings_form($form); return system_settings_form($form);
} }
@@ -340,29 +340,13 @@ function booking_manual_email_submit($form, &$form_state) {
elseif (strpos($form_state['values']['email-type'], 'custom') !== false) elseif (strpos($form_state['values']['email-type'], 'custom') !== false)
{ {
watchdog('booking', 'Processing a @custom type email to id @info', array ('@custom' => $form_state['values']['email-type'], '@info' => $key)); watchdog('booking', 'Processing a @custom type email to id @info', array ('@custom' => $form_state['values']['email-type'], '@info' => $key));
_booking_custom_email($key,$form_state['values']['email-type']); _booking_custom_email($key, $form_state['values']['email-type']);
} }
/*
elseif ($form_state['values']['email-type'] == 'custom1')
{
watchdog('booking', 'Processing a custom1 type email to id @info', array ('@info' => $key));
_booking_custom_email($key,$form_state['values']['email-type']);
}
elseif ($form_state['values']['email-type'] == 'custom2')
{
watchdog('booking', 'Processing a custom2 type email to id @info', array ('@info' => $key));
_booking_custom_email($key,$form_state['values']['email-type']);
}
elseif ($form_state['values']['email-type'] == 'custom3')
{
watchdog('booking', 'Processing a custom3 type email to id @info', array ('@info' => $key));
_booking_custom_email($key,$form_state['values']['email-type']);
}
*/
$counter++; $counter++;
} }
} }
} }
drupal_set_message("Sent manual email for $counter people.", 'status', FALSE); drupal_set_message("Sent manual email for $counter people.", 'status', FALSE);
watchdog('booking', "Sent manual email for $counter people."); //watchdog('booking', "Sent manual email for $counter people.");
} }

View File

@@ -175,6 +175,11 @@ function _datetime_array_to_ts($date)
//watchdog('booking', 'Date-time Conversion: @info', array('@info' => var_export($date, TRUE))); //watchdog('booking', 'Date-time Conversion: @info', array('@info' => var_export($date, TRUE)));
date_default_timezone_set(TIMEZONE); date_default_timezone_set(TIMEZONE);
$tz = new DateTimeZone(TIMEZONE); $tz = new DateTimeZone(TIMEZONE);
if (empty($date) || ($date['month'] == '' && $date['day'] == '' && $date['year'] == ''))
return 0;
else
watchdog('booking', "Date array to timestamp: @info", array('@info' => var_export($date, TRUE)));
$gmt_ts = mktime($date['hour'], $date['minute'], 0, $date['month'], $date['day'], $date['year']); $gmt_ts = mktime($date['hour'], $date['minute'], 0, $date['month'], $date['day'], $date['year']);
$ts = new DateTime("@$gmt_ts"); $ts = new DateTime("@$gmt_ts");
@@ -294,6 +299,17 @@ function _booking_avg_age($sum, $count, $reference_ts)
return $difference->y . " years, " . $difference->m . " months, " . $difference->d . " days"; return $difference->y . " years, " . $difference->m . " months, " . $difference->d . " days";
} }
/**
* Helper function to calculate persons age in years at start of event
*/
function _booking_get_age_years($dob_ts)
{
global $event;
$reference_ts = _booking_convert_ts($event->booking_event_start);
$dob = _booking_convert_ts($dob_ts);
return $dob->diff($reference_ts)->y;
}
function _date_range_to_string($date_start, $date_end) { function _date_range_to_string($date_start, $date_end) {
$start = _booking_split_date($date_start); $start = _booking_split_date($date_start);
$end = _booking_split_date($date_end); $end = _booking_split_date($date_end);
@@ -338,6 +354,44 @@ function _date_range_to_string($date_start, $date_end) {
return $final_string; return $final_string;
} }
/**
* Function for calculating statistics of attendees
*/
function _booking_generate_statistics($booking_list)
{
global $event;
$statistics = array(
'males' => 0,
'females' => 0,
'under20' => 0,
'20to25' => 0,
'over25' => 0,
);
foreach ($booking_list as $person)
{
//ignore people that havent paid or are no longer coming
if ($person->booking_status == 0 || $person->booking_status == 3)
continue;
if ($person->booking_gender == 'M')
$statistics['males']++;
else
$statistics['females']++;
$age = _booking_get_age_years($person->booking_dob);
if ($age < 20)
$statistics['under20']++;
elseif($age >= 20 && $age < 25)
$statistics['20to25']++;
else
$statistics['over25']++;
}
return $statistics;
}
//figure out if we're in the right time period for discounted registration rates //figure out if we're in the right time period for discounted registration rates
function _booking_is_earlybird() function _booking_is_earlybird()
@@ -426,7 +480,9 @@ function _booking_amount_paid($nid, $person = NULL)
if ($person->booking_partner_id > 0) if ($person->booking_partner_id > 0)
{ {
//watchdog('booking', "Checking total paid for married person"); //watchdog('booking', "Checking total paid for married person");
//look for payments in the payment transaction table
//if we're combining the payment for married couples //if we're combining the payment for married couples
if (variable_get('booking_enable_combined_pricing', 0) == 1) if (variable_get('booking_enable_combined_pricing', 0) == 1)
{ {
@@ -448,7 +504,7 @@ function _booking_amount_paid($nid, $person = NULL)
//watchdog('booking', "Total amount paid according to paypal payments table is " . $amount_paid); //watchdog('booking', "Total amount paid according to paypal payments table is " . $amount_paid);
//if there were no results, $amount_paid will still be 0 //there were no payment transactions, so rely on what the amount is set to in the individual registration records
if ($amount_paid == 0) if ($amount_paid == 0)
{ {
//if we're combining the payment for married couples //if we're combining the payment for married couples
@@ -480,6 +536,8 @@ function _booking_amount_paid($nid, $person = NULL)
foreach ($query as $payment) foreach ($query as $payment)
$amount_paid += ($payment->booking_mc_gross - $payment->booking_mc_fee); $amount_paid += ($payment->booking_mc_gross - $payment->booking_mc_fee);
//watchdog('booking', "Total amount paid according to paypal payments table is " . $amount_paid);
//if there were no results, $amount_paid will still be 0 //if there were no results, $amount_paid will still be 0
if ($amount_paid == 0) if ($amount_paid == 0)
$amount_paid = $person->booking_amount_paid; $amount_paid = $person->booking_amount_paid;
@@ -501,16 +559,24 @@ function _booking_amount_owing($nid, $amount_paid = 0)
//fetch details about the person //fetch details about the person
$person = db_query("SELECT price.booking_price, price.booking_late_price, person.booking_payment_id, " . $person = db_query("SELECT price.booking_price, price.booking_late_price, person.booking_payment_id, " .
"person.booking_total_pay_reqd, person.booking_amount_paid, person.booking_partner_id, person.booking_country " . "person.booking_total_pay_reqd, person.booking_amount_paid, person.booking_partner_id, person.booking_country, person.booking_welfare_required " .
"FROM {booking_person} person, {booking_price} price " . "FROM {booking_person} person, {booking_price} price " .
"WHERE person.nid = :nid " . "WHERE person.nid = :nid " .
"AND person.booking_payment_id = price.pid", "AND person.booking_payment_id = price.pid",
array(':nid' => $nid)) array(':nid' => $nid))
->fetchObject(); ->fetchObject();
//check for early bird rate or full rate //determine what rate this person needs to pay
if (_booking_is_earlybird() == TRUE) if ($person->booking_welfare_required == 'Y')
{
//cater for any manual adjustment
//watchdog('booking', "This registration is eligible for welfare rates");
$total_due = $person->booking_total_pay_reqd; $total_due = $person->booking_total_pay_reqd;
}
//the early bird rate will be defined by default for the registration
elseif (_booking_is_earlybird() == TRUE)
$total_due = $person->booking_total_pay_reqd;
//finally we must be in the late-fee period
else else
$total_due = $person->booking_late_price; $total_due = $person->booking_late_price;
@@ -519,80 +585,9 @@ function _booking_amount_owing($nid, $amount_paid = 0)
//if we didn't get the amount paid as a command line parameter, check it now //if we didn't get the amount paid as a command line parameter, check it now
if ($amount_paid == 0) if ($amount_paid == 0)
{ {
//watchdog('booking', "Checking total amount already paid by " . $nid);
$amount_paid = _booking_amount_paid($nid, $person); $amount_paid = _booking_amount_paid($nid, $person);
} }
//check if there is anything outstanding
/*
//check for a spouse
if ($person->booking_partner_id > 0)
{
watchdog('booking', "Checking outstanding balance for married person");
//if we're combining the payment for married couples
if (variable_get('booking_enable_combined_pricing', 0) == 1)
{
//check for payments in the paypal transaction table from either spouse
$query = db_query("SELECT booking_mc_gross FROM booking_payment " .
"WHERE booking_person_nid = :nid OR booking_person_nid = :spousenid",
array(':nid' => $nid, 'spousenid' => $person->booking_partner_id));
}
else {
//check for payments in the paypal transaction table from just this person
$query = db_query("SELECT booking_mc_gross FROM booking_payment " .
"WHERE booking_person_nid = :nid",
array(':nid' => $nid));
}
//add up all the payments
foreach ($query as $payment)
$amount_paid += $payment->booking_mc_gross;
watchdog('booking', "Total amount paid according to paypal payments table is " . $amount_paid);
//if there were no results, $amount_paid will still be 0
if ($amount_paid == 0)
{
//if we're combining the payment for married couples
if (variable_get('booking_enable_combined_pricing', 0) == 1)
{
$spouse = db_query("SELECT person.booking_amount_paid " .
"FROM {booking_person} person " .
"WHERE person.nid = :nid ",
array(':nid' => $person->booking_partner_id))
->fetchObject();
$amount_paid = $person->booking_amount_paid + $spouse->booking_amount_paid;
watchdog('booking', "Total combined payments for couple based on totals in booking_person table is " . $amount_paid);
}
else
{
$amount_paid = $person->booking_amount_paid;
watchdog('booking', "Total amount paid for individual based on totals in booking_person table is " . $amount_paid);
}
}
}
else
{
//Check if there are payment records in the paypal transaction table for this unmarried person
//if so, base their payments on the gross amount in there rather than what the person booking_person database says
$query = db_query("SELECT booking_mc_gross FROM booking_payment " .
"WHERE booking_person_nid = :nid",
array(':nid' => $nid));
foreach ($query as $payment)
$amount_paid += $payment->booking_mc_gross;
//if there were no results, $amount_paid will still be 0
if ($amount_paid == 0)
$amount_paid = $person->booking_amount_paid;
//in case there has been some manual adjustment
elseif ($amount_paid < $person->booking_amount_paid)
$amount_paid = $person->booking_amount_paid;
}
watchdog('booking', "Total amount already paid for this registration " . $nid . " is " . $amount_paid);
*/
if ($amount_paid >= $total_due) if ($amount_paid >= $total_due)
{ {
//watchdog('booking', "This person doesn't owe any money: @info", array('@info' => var_export($person, TRUE))); //watchdog('booking', "This person doesn't owe any money: @info", array('@info' => var_export($person, TRUE)));
@@ -609,13 +604,55 @@ function _booking_amount_owing($nid, $amount_paid = 0)
$amount_owing = $amount_owing / (1 - 0.024); $amount_owing = $amount_owing / (1 - 0.024);
//paypal charges 3.4 percent if they're doing a currency conversion //paypal charges 3.4 percent if they're doing a currency conversion
else else
{
$amount_owing = $amount_owing / (1 - 0.034); $amount_owing = $amount_owing / (1 - 0.034);
watchdog('booking', "This is an international registration.");
}
} }
else else
$amount_owing = $total_due - $amount_paid; $amount_owing = $total_due - $amount_paid;
return number_format($amount_owing, 2, '.', ''); return number_format($amount_owing, 2, '.', '');
} }
/**
* Helper function to cycle through a list without getting in an endless loop
* Used for calculating study groups and maybe readings groups
*
* Each iteration through the list the maximum permitted size for a given entry will be increased by one
* until we find an available entry or we run out of cycle counts
*/
function _booking_loop_carefully(&$list, $field, &$i, $maximum, $list_size, $max_cycle_count)
{
$cycle = 0;
while ($list[$i][$field] >= $maximum)
{
drupal_set_message(t("Field !field is !value for entry !index, which larger than maximum allowed size, !max. Moving to next entry in list.",
array('!field' => $field, '!value' => $list[$i][$field], '!max' => $maximum, '!index' => $i)));
$i++;
//reset the counter if we go past the end
if ($i > $list_size)
{
$i = 1;
//make sure we don't get stuck in an infinite loop - only go past the end once
if ($cycle >= $max_cycle_count)
{
drupal_set_message(t("Reached the end of !field list. Unable to find satisfactory entry after !num cycles.",
array('!field' => $field, '!num' => $cycle)));
return;
}
elseif ($cycle > 0)
{
//temporarily increase the maximum size of our groups by one
$maximum++;
}
//always increment the cycle counter if we've reached the end
$cycle++;;
}
}
}
/** /**
* Helper function to generate paypal form for payments * Helper function to generate paypal form for payments
*/ */
@@ -628,6 +665,8 @@ function _booking_paypal_form($person, $invoiceid, $amount_owing, $button_text)
*/ */
function _booking_paypal_form_builder($node, &$form_state, $person, $invoiceid, $amount_owing, $button_text) { function _booking_paypal_form_builder($node, &$form_state, $person, $invoiceid, $amount_owing, $button_text) {
global $event; global $event;
//get our current path so we can send the user back here if they cancel
$path = isset($_GET['q']) ? $_GET['q'] : '<front>'; $path = isset($_GET['q']) ? $_GET['q'] : '<front>';
//paypal specific settings //paypal specific settings
@@ -653,7 +692,7 @@ function _booking_paypal_form_builder($node, &$form_state, $person, $invoiceid,
$form['#action'] = url(variable_get('booking_paypal_sandbox', 0) ? BOOKING_PAYPAL_SUBMIT_URL_SANDBOX : BOOKING_PAYPAL_SUBMIT_URL, array('absolute' => TRUE)); $form['#action'] = url(variable_get('booking_paypal_sandbox', 0) ? BOOKING_PAYPAL_SUBMIT_URL_SANDBOX : BOOKING_PAYPAL_SUBMIT_URL, array('absolute' => TRUE));
//turn the array into a form
foreach($vars as $name => $value) { foreach($vars as $name => $value) {
$form[$name] = array( $form[$name] = array(
'#type' => 'hidden', '#type' => 'hidden',

View File

@@ -63,6 +63,7 @@ function booking_import_data_admin_submit($form, &$form_state)
$error = false; $error = false;
$update_counter = 0; $update_counter = 0;
$delimiter = ","; $delimiter = ",";
$result_array = array();
//get the file name from temporary storage field //get the file name from temporary storage field
$file = $form_state['storage']['file']; $file = $form_state['storage']['file'];
@@ -120,6 +121,14 @@ function booking_import_data_admin_submit($form, &$form_state)
} }
} }
$result_array[] = t('Setting payment for id !nid to $!price of total required $!total and status to !status',
array('!nid' => $record['nid'],
'!price' => $record['booking_amount_paid'],
'!total' => $record['booking_total_pay_reqd'],
'!status' => _booking_status_lookup($record['booking_status'])
)
);
//TODO: output this from $result_array
drupal_set_message(t('Setting payment for id !nid to $!price of total required $!total and status to !status', drupal_set_message(t('Setting payment for id !nid to $!price of total required $!total and status to !status',
array('!nid' => $record['nid'], array('!nid' => $record['nid'],
'!price' => $record['booking_amount_paid'], '!price' => $record['booking_amount_paid'],
@@ -127,8 +136,8 @@ function booking_import_data_admin_submit($form, &$form_state)
'!status' => _booking_status_lookup($record['booking_status'])) '!status' => _booking_status_lookup($record['booking_status']))
)); ));
watchdog('booking', 'Setting payment for regn id !nid to $!price and status to !status', // watchdog('booking', 'Setting payment for regn id !nid to $!price and status to !status',
array('!nid' => $record['nid'], '!price' => $record['booking_amount_paid'], '!status' => _booking_status_lookup($record['booking_status']))); // array('!nid' => $record['nid'], '!price' => $record['booking_amount_paid'], '!status' => _booking_status_lookup($record['booking_status'])));
db_update('booking_person') db_update('booking_person')
->fields(array( ->fields(array(
@@ -139,7 +148,10 @@ function booking_import_data_admin_submit($form, &$form_state)
->condition('nid', $record['nid']) ->condition('nid', $record['nid'])
->execute(); ->execute();
} } //end processing input data
//output our results to watchdog
watchdog('booking', '<pre>@print_r</pre>', array('@print_r', print_r( $result_array, TRUE)));
//delete the uploaded file //delete the uploaded file
file_delete($file); file_delete($file);

View File

@@ -247,9 +247,9 @@ function booking_menu() {
'type' => MENU_NORMAL_ITEM, 'type' => MENU_NORMAL_ITEM,
); );
$items['admin/booking/paypal'] = array( $items['admin/booking/payments'] = array(
'title' => 'Booking Paypal Summary', 'title' => 'Booking Payment Summary',
'description' => 'List paypal payments', 'description' => 'List all payments',
'page callback' => 'booking_report_paypal_payments', 'page callback' => 'booking_report_paypal_payments',
'access arguments' => array('access reports'), 'access arguments' => array('access reports'),
'type' => MENU_NORMAL_ITEM, 'type' => MENU_NORMAL_ITEM,
@@ -528,15 +528,6 @@ function booking_node_access($node, $op, $account) {
array('!account' => $account->uid, '!op' => $op, '!type' => $type, '@info' => var_export($account, TRUE))); array('!account' => $account->uid, '!op' => $op, '!type' => $type, '@info' => var_export($account, TRUE)));
} }
*/ */
/*
if ($op == 'view')
return user_access('view all bookings', $account);
if ($op == 'create')
return user_access('create bookings', $account);
if ($op == 'update' || $op == 'delete')
return user_access('edit bookings', $account);
*/
} }

View File

@@ -89,6 +89,7 @@ function booking_paypal_ipn() {
function _booking_process_payment($data) { function _booking_process_payment($data) {
global $event; global $event;
$balance_payment = false; $balance_payment = false;
$amount_owing = 0;
//TODO: verify $data['receiver_email'] matches variable_get('booking_paypal_account', '') //TODO: verify $data['receiver_email'] matches variable_get('booking_paypal_account', '')
@@ -118,7 +119,7 @@ function _booking_process_payment($data) {
if ($duplicate_check) if ($duplicate_check)
{ {
watchdog('booking', 'Detected duplicate paypal notifications for transaction id !id, registration id !nid', array('!id' => $data['ipn_track_id'], '!nid' => $nid), WATCHDOG_ERROR); watchdog('booking', 'Detected duplicate paypal notifications for transaction id !id, registration id !nid', array('!id' => $data['ipn_track_id'], '!nid' => $nid), WATCHDOG_ERROR);
//return; return;
} }
watchdog('booking', 'Adding payment for user with node id: !id; event id: !eid', array('!id' => $nid, '!eid' => $eid)); watchdog('booking', 'Adding payment for user with node id: !id; event id: !eid', array('!id' => $nid, '!eid' => $eid));
@@ -155,6 +156,7 @@ function _booking_process_payment($data) {
->execute() ->execute()
->fetchObject(); ->fetchObject();
//check if we found a person matching this payment
if ($payment) if ($payment)
{ {
watchdog('booking', 'Found matching user with node id: !id; event id: !eid; existing payment !payment', array('!id' => $nid, '!eid' => $eid, watchdog('booking', 'Found matching user with node id: !id; event id: !eid; existing payment !payment', array('!id' => $nid, '!eid' => $eid,
@@ -198,12 +200,11 @@ function _booking_process_payment($data) {
)) ))
->condition('nid', $nid) ->condition('nid', $nid)
->execute(); ->execute();
//send a notification email
//If there is no outstanding balance, send a payment complete email //If there is no outstanding balance, send a payment complete email
$amount_owing = _booking_amount_owing($nid);
//if ($total >= $payment->booking_total_pay_reqd) //if ($total >= $payment->booking_total_pay_reqd)
if (_booking_amount_owing($nid) == 0) if ($amount_owing == 0)
{ {
//this should always be a balance payment type email, since that tells the user that their payment is completed //this should always be a balance payment type email, since that tells the user that their payment is completed
_booking_registration_email($nid, TRUE); _booking_registration_email($nid, TRUE);
@@ -237,16 +238,23 @@ function _booking_process_payment($data) {
->condition('nid', $payment->booking_partner_id) ->condition('nid', $payment->booking_partner_id)
->execute(); ->execute();
//send an email //send an email to the spouse
_booking_registration_email($payment->booking_partner_id, $balance_payment); _booking_registration_email($payment->booking_partner_id, TRUE);
} }
elseif (variable_get('booking_enable_combined_pricing', 0) == 1) elseif (variable_get('booking_enable_combined_pricing', 0) == 1)
{ {
watchdog('booking', 'Combined pricing is enabled, but this person has a partner id of !id.', array('!id' => $payment->booking_partner_id)); watchdog('booking', 'Combined pricing is enabled, but this person has a partner id of !id.', array('!id' => $payment->booking_partner_id));
} //end spouse check } //end spouse check
} }
//if this was an initial payment we need to send a notification
elseif ($balance_payment == FALSE)
{
_booking_registration_email($nid, FALSE);
}
else //this person still has an outstanding balance so just send a confirmation email else //this person still has an outstanding balance so just send a confirmation email
{ {
watchdog('booking', 'This balance payment of !payment was insufficient for !id to completely pay the total outstanding of !outstanding.',
array('!id' => $nid, '!payment' => $data['mc_gross'], '!outstanding' => $amount_owing));
//TODO: create an email specifically for partial-balance payments //TODO: create an email specifically for partial-balance payments
//_booking_registration_email($nid, $balance_payment); //_booking_registration_email($nid, $balance_payment);
} }

View File

@@ -277,9 +277,7 @@ function booking_form($node, &$form_state, $inserting = FALSE) {
), ),
), ),
*/ */
'#title' => t('I have read and agree to the following aims and expectations.', '#title' => token_replace(variable_get('booking_registration_aims_rules_checkbox'), booking_define_tokens()),
array('!event' => $event->booking_eventname)
),
'#description' => token_replace(variable_get('booking_registration_aims_rules_text'), booking_define_tokens()) '#description' => token_replace(variable_get('booking_registration_aims_rules_text'), booking_define_tokens())
); );
} }
@@ -899,25 +897,16 @@ function booking_form_submit($form, &$form_state) {
$node->booking_passport_num = empty($values['booking_passport_num']) ? '' : $values['booking_passport_num']; $node->booking_passport_num = empty($values['booking_passport_num']) ? '' : $values['booking_passport_num'];
$node->booking_passport_issue_location = empty($values['booking_passport_issue_location']) ? '' : $values['booking_passport_issue_location']; $node->booking_passport_issue_location = empty($values['booking_passport_issue_location']) ? '' : $values['booking_passport_issue_location'];
$node->booking_passport_issue_name = empty($values['booking_passport_issue_name']) ? '' : $values['booking_passport_issue_name']; $node->booking_passport_issue_name = empty($values['booking_passport_issue_name']) ? '' : $values['booking_passport_issue_name'];
$node->booking_passport_expiry_date = empty($values['booking_passport_expiry_date']) ? '0' : _datearray_to_ts($values['booking_passport_expiry_date']); $node->booking_passport_expiry_date = empty($values['booking_passport_expiry_date']) ? '0' : _datearray_to_ts($values['booking_passport_expiry_date']);
//calculate booking_payment_id based on form choice of student or worker //payment details
//$worker_type = db_result(db_query("SELECT pid FROM {booking_price} where booking_eventid = %d AND booking_price_descrip='%s'",
// EVENTID, $values['booking_worker_type'] ));
$node->booking_payment_id = $values['booking_payment_id']; $node->booking_payment_id = $values['booking_payment_id'];
//contact details
$node->booking_street = ucwords($values['booking_street']); $node->booking_street = ucwords($values['booking_street']);
$node->booking_suburb = ucwords($values['booking_suburb']); $node->booking_suburb = ucwords($values['booking_suburb']);
$node->booking_postcode = $values['booking_postcode']; $node->booking_postcode = $values['booking_postcode'];
$node->booking_country = $values['booking_country']; $node->booking_country = $values['booking_country'];
//allow for user-entered value if the state is not already listed
if ($values['booking_state'] == 'Other') {
$node->booking_state = $values['booking_other_state'];
} else {
$node->booking_state = ucwords($values['booking_state']);
}
$node->booking_phone = $values['booking_phone']; $node->booking_phone = $values['booking_phone'];
$node->booking_mobile = $values['booking_mobile']; $node->booking_mobile = $values['booking_mobile'];
$node->booking_email = strtolower($values['booking_email']); $node->booking_email = strtolower($values['booking_email']);
@@ -926,7 +915,13 @@ function booking_form_submit($form, &$form_state) {
$node->booking_married = ($values['booking_married'] == 1 ? 'Y' : 'N'); $node->booking_married = ($values['booking_married'] == 1 ? 'Y' : 'N');
$node->booking_partner_name = ucwords($values['booking_partner_name']); $node->booking_partner_name = ucwords($values['booking_partner_name']);
$node->booking_partner_id = empty($values['booking_partner_id']) ? 0 : $values['booking_partner_id']; $node->booking_partner_id = empty($values['booking_partner_id']) ? 0 : $values['booking_partner_id'];
//allow for user-entered value if the state is not already listed
if ($values['booking_state'] == 'Other') {
$node->booking_state = $values['booking_other_state'];
} else {
$node->booking_state = ucwords($values['booking_state']);
}
//emergency contact info //emergency contact info
$node->booking_guardian_name = $values['booking_guardian_name']; $node->booking_guardian_name = $values['booking_guardian_name'];
$node->booking_guardian_type = $values['booking_guardian_type']; $node->booking_guardian_type = $values['booking_guardian_type'];
@@ -959,7 +954,6 @@ function booking_form_submit($form, &$form_state) {
$node->booking_skills_other = empty($values['booking_skills_other']) ? 'N' : ($values['booking_skills_other'] == 1 ? 'Y' : 'N'); $node->booking_skills_other = empty($values['booking_skills_other']) ? 'N' : ($values['booking_skills_other'] == 1 ? 'Y' : 'N');
$node->booking_skills_other_details = empty($values['booking_skills_other_details']) ? 'N/A' : $values['booking_skills_other_details']; $node->booking_skills_other_details = empty($values['booking_skills_other_details']) ? 'N/A' : $values['booking_skills_other_details'];
//potential fields for future //potential fields for future
//$node->booking_payment_method = $payment_method; //$node->booking_payment_method = $payment_method;
$node->booking_room_mate1 = empty($values['booking_room_mate1']) ? '' : $values['booking_room_mate1']; $node->booking_room_mate1 = empty($values['booking_room_mate1']) ? '' : $values['booking_room_mate1'];

View File

@@ -12,6 +12,7 @@ function booking_report_summary() {
$bookedin_counter = 0; $bookedin_counter = 0;
$notpaid_counter = 0; $notpaid_counter = 0;
$waiting_counter = 0; $waiting_counter = 0;
$notcoming_counter = 0;
$male_count = 0; $male_count = 0;
$female_count = 0; $female_count = 0;
$baptised_count = 0; $baptised_count = 0;
@@ -32,12 +33,12 @@ function booking_report_summary() {
//as per http://www.drup-all.com/blog/table-sort-pagination-drupal-7 //as per http://www.drup-all.com/blog/table-sort-pagination-drupal-7
$header = array( $header = array(
array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'), array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'),
array('data' => t('Edit Link')), array('data' => t('Name'), 'field' => 'booking_lastname'),
array('data' => t('Name'), 'field' => 'booking_lastname', 'sort' => 'asc'), array('data' => t('Email'), 'field' => 'booking_email'),
array('data' => t('Email'), 'field' => 'booking_email', 'sort' => 'asc'), array('data' => t('Payment To Date'), 'field' => 'booking_amount_paid'),
array('data' => t('Payment To Date'), 'field' => 'booking_amount_paid', 'sort' => 'asc'), array('data' => t('Total Payment Required'), 'field' => 'booking_total_pay_reqd'),
array('data' => t('Total Payment Required'), 'field' => 'booking_total_pay_reqd', 'sort' => 'asc'), array('data' => t('Fully paid?')),
array('data' => t('Welfare Required?'), 'field' => 'booking_welfare_required', 'sort' => 'asc'), array('data' => t('Welfare Required?'), 'field' => 'booking_welfare_required'),
); );
$rows = array(); $rows = array();
@@ -80,21 +81,27 @@ function booking_report_summary() {
} }
//more detailed summary //more detailed summary
//allow user-selectable sorting of columns as per http://www.drup-all.com/blog/table-sort-pagination-drupal-7 //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 = db_select('booking_person', 'p')
->fields('p') ->fields('p')
->condition('p.booking_event_id', $event->eid, '='); ->fields('pr', array('booking_price', 'booking_late_price'))
->condition('p.booking_event_id', $event->eid, '=');
$query->join('booking_price', 'pr', 'pr.pid = p.booking_payment_id');
$table_sort = $query->extend('TableSort')->orderbyHeader($header); $table_sort = $query->extend('TableSort')->orderbyHeader($header);
$result = $table_sort->execute(); $result = $table_sort->execute();
foreach ($result as $person) { foreach ($result as $person) {
$rows[] = array( $rows[] = array(
l(t('!id', array('!id' => $person->nid)), t('node/!id', array('!id' => $person->nid))), l(t('!id', array('!id' => $person->nid)), t('node/!id', array('!id' => $person->nid))),
l(t('!id', array('!id' => $person->nid)), t('node/!id/edit', array('!id' => $person->nid))), //l(t('!id', array('!id' => $person->nid)), t('node/!id/edit', array('!id' => $person->nid))),
t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))), l(t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))),
t('!email', array('!email' => $person->booking_email)), t('node/!id/edit', array('!id' => $person->nid))
),
t('!email', array('!email' => $person->booking_email)),
t('!payment', array('!payment' => $person->booking_amount_paid)), t('!payment', array('!payment' => $person->booking_amount_paid)),
t('!payment', array('!payment' => $person->booking_total_pay_reqd)), t('!payment', array('!payment' => $person->booking_total_pay_reqd)),
_booking_amount_paid($person->nid, $person) >= $person->booking_total_pay_reqd ? 'Yes' : 'No',
t($person->booking_welfare_required == 'Y' ? 'Yes' : 'No'), t($person->booking_welfare_required == 'Y' ? 'Yes' : 'No'),
); );
$total_paid += $person->booking_amount_paid; $total_paid += $person->booking_amount_paid;
@@ -106,6 +113,8 @@ function booking_report_summary() {
$bookedin_counter++; $bookedin_counter++;
elseif ($person->booking_status == 2) elseif ($person->booking_status == 2)
$waiting_counter++; $waiting_counter++;
else
$notcoming_counter++;
//welfare //welfare
if ($person->booking_welfare_required == 'Y') if ($person->booking_welfare_required == 'Y')
@@ -154,8 +163,9 @@ function booking_report_summary() {
array('!average' => _booking_avg_age($dob_total, $person_count, $event->booking_event_start), '!maleaverage' => _booking_avg_age($male_dob_total, $male_count, $event->booking_event_start), array('!average' => _booking_avg_age($dob_total, $person_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) '!femaleaverage' => _booking_avg_age($female_dob_total, $female_count, $event->booking_event_start)
)); ));
$output .= t("There are !bookedin registrations currently booked in, !waiting on waiting list, and !notpaid haven't paid, which comes to a total of !total people who have filled in the registration form.</p>", $output .= t("There are !bookedin registrations currently booked in, !waiting on waiting list, !notpaid haven't paid, and !notcoming are no longer coming, which comes to a total of !total people who have filled in the registration form.</p>",
array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter, '!total' => $person_count)); array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter, '!total' => $person_count,
'!notcoming' => $notcoming_counter));
$output .= t("<p>There are !welfare people with special financial consideration approved. !fullypaid people have completed their payments.<br />", $output .= t("<p>There are !welfare people with special financial consideration approved. !fullypaid people have completed their payments.<br />",
array('!welfare' => $welfare_count, '!fullypaid' => $fullypaid_count array('!welfare' => $welfare_count, '!fullypaid' => $fullypaid_count
)); ));
@@ -420,7 +430,8 @@ function booking_csv_report() {
*/ */
//pivot table based on http://anothermysqldba.blogspot.de/2013/06/pivot-tables-example-in-mysql.html //pivot table based on http://anothermysqldba.blogspot.de/2013/06/pivot-tables-example-in-mysql.html
$query = db_query("select distinct p.*, s1.booking_session_id as session1, s1.booking_is_leader as session1_leader, s1.booking_is_reserveleader as session1_reserveleader, s1.booking_is_helper as session1_helper, s2.booking_session_id as session2, s2.booking_is_leader as session2_leader, s2.booking_is_reserveleader as session2_reserveleader, s2.booking_is_helper as session2_helper, s3.booking_session_id as session3, s3.booking_is_leader as session3_leader, s3.booking_is_reserveleader as session3_reserveleader, s3.booking_is_helper as session3_helper, s4.booking_session_id as session4, s4.booking_is_leader as session4_leader, s4.booking_is_reserveleader as session4_reserveleader, s4.booking_is_helper as session4_helper, s5.booking_session_id as session5, s5.booking_is_leader as session5_leader, s5.booking_is_reserveleader as session5_reserveleader, s5.booking_is_helper as session5_helper, s6.booking_session_id as session6, s6.booking_is_leader as session6_leader, s6.booking_is_reserveleader as session6_reserveleader, s6.booking_is_helper as session6_helper from {booking_person} p $query = db_query("select distinct p.*, s1.booking_session_id as session1, s1.booking_is_leader as session1_leader, s1.booking_is_reserveleader as session1_reserveleader, s1.booking_is_helper as session1_helper, s2.booking_session_id as session2, s2.booking_is_leader as session2_leader, s2.booking_is_reserveleader as session2_reserveleader, s2.booking_is_helper as session2_helper, s3.booking_session_id as session3, s3.booking_is_leader as session3_leader, s3.booking_is_reserveleader as session3_reserveleader, s3.booking_is_helper as session3_helper, s4.booking_session_id as session4, s4.booking_is_leader as session4_leader, s4.booking_is_reserveleader as session4_reserveleader, s4.booking_is_helper as session4_helper, s5.booking_session_id as session5, s5.booking_is_leader as session5_leader, s5.booking_is_reserveleader as session5_reserveleader, s5.booking_is_helper as session5_helper, s6.booking_session_id as session6, s6.booking_is_leader as session6_leader, s6.booking_is_reserveleader as session6_reserveleader, s6.booking_is_helper as session6_helper, pr.booking_price, pr.booking_price_descrip from {booking_person} p
inner join {booking_price} pr on p.booking_payment_id = pr.pid
left outer join {booking_studygroup_mapping} s1 on p.nid = s1.booking_node_id and s1.booking_studygroup_id = 1 left outer join {booking_studygroup_mapping} s1 on p.nid = s1.booking_node_id and s1.booking_studygroup_id = 1
left outer join {booking_studygroup_mapping} s2 on p.nid = s2.booking_node_id and s2.booking_studygroup_id = 2 left outer join {booking_studygroup_mapping} s2 on p.nid = s2.booking_node_id and s2.booking_studygroup_id = 2
left outer join {booking_studygroup_mapping} s3 on p.nid = s3.booking_node_id and s3.booking_studygroup_id = 3 left outer join {booking_studygroup_mapping} s3 on p.nid = s3.booking_node_id and s3.booking_studygroup_id = 3

View File

@@ -354,7 +354,7 @@ function booking_available_leadhelp_select_form_submit($form, &$form_state) {
* Function to correctly clone an associative array storing objects * Function to correctly clone an associative array storing objects
* Taken from http://stackoverflow.com/questions/1532618/is-there-a-function-to-make-a-copy-of-a-php-array-to-another * Taken from http://stackoverflow.com/questions/1532618/is-there-a-function-to-make-a-copy-of-a-php-array-to-another
*/ */
function clone_array($copied_array) { function booking_clone_array($copied_array) {
return array_map(function($element) { return array_map(function($element) {
return ( return (
((is_array($element)) ((is_array($element))
@@ -368,8 +368,12 @@ function clone_array($copied_array) {
}, $copied_array); }, $copied_array);
} }
//taken from http://stackoverflow.com/questions/4102777/php-random-shuffle-array-maintaining-key-value
function shuffle_assoc($list) { /**
* Function to randomise the ordering of an array
* taken from http://stackoverflow.com/questions/4102777/php-random-shuffle-array-maintaining-key-value
*/
function booking_shuffle_assoc($list) {
if (!is_array($list)) return $list; if (!is_array($list)) return $list;
$keys = array_keys($list); $keys = array_keys($list);
@@ -381,6 +385,31 @@ function shuffle_assoc($list) {
return $random; return $random;
} }
/**
* Function to mark an attendee as processed for group calculations
* @param $input string containing passport number to be verified
*/
function booking_assign_attendee_group($nid, $session_id, $gender, $age, &$attendee_list, &$session_count)
{
//mark this person as processed in the working list
$attendee_list[$nid]->processed = 1;
$attendee_list[$nid]->session = $session_id;
//record the category of person
$session_count[$session_id][$gender]++;
$session_count[$session_id]['total']++;
//record the age bracket
//$age = _booking_get_age_years($attendee_list[$nid]->booking_dob);
if ($age < 20)
$session_count[$session_id]['under20']++;
elseif($age >= 20 && $age < 25)
$session_count[$session_id]['20to25']++;
else
$session_count[$session_id]['over25']++;
}
/** /**
* Function for calculating who belongs to which study group * Function for calculating who belongs to which study group
*/ */
@@ -406,18 +435,31 @@ function booking_studygroups_calculate() {
//calculate the max number of attendees in a group //calculate the max number of attendees in a group
$firstgroup = reset($studygroups); $firstgroup = reset($studygroups);
$limit = variable_get('booking_regn_limit','500'); $limit = variable_get('booking_regn_limit','500');
//add an extra two to the maximum size, to cater for some larger groups when the number of people doesn't divide evenly //add an extra one to the maximum size, to cater for some larger groups when the number of people doesn't divide evenly
$max_people = (int) ($limit / $firstgroup->booking_num_group_sessions) + 2; $max_people = (int) ($limit / $firstgroup->booking_num_group_sessions) + 1;
//select all the attendees booked in //select all the attendees booked in
/*
$query = db_query("SELECT p.nid, p.booking_partner_id, p.booking_event_id, p.booking_status, l.booking_total_lead, l.booking_available_lead, l.booking_total_help, l.booking_available_help FROM {booking_person} p left outer join {booking_leadhelp_list} l on p.nid = l.booking_node_id WHERE p.booking_event_id = :eid AND p.booking_status = 1",
array(':eid' => $event->eid));
*/
$query = db_query("SELECT * FROM {booking_person} WHERE booking_event_id = :eid", $query = db_query("SELECT * FROM {booking_person} WHERE booking_event_id = :eid",
array(':eid' => $event->eid)); array(':eid' => $event->eid));
$attendees = $query->fetchAllAssoc('nid'); $attendees = $query->fetchAllAssoc('nid');
//calculate the ratios of males to females, and various age groups
$statistics = _booking_generate_statistics($attendees);
$gender_ratio = ($statistics['males'] / $statistics['females']) * ($max_people / 2);
//store them in a nice easy to access array
$maximums = array(
'male' => ceil($gender_ratio),
'female' => ceil($max_people - $gender_ratio),
'under20' => floor(($statistics['under20'] / $limit) * ($max_people - 2)),
'20to25' => floor(($statistics['20to25'] / $limit) * ($max_people - 2)),
'over25' => floor(($statistics['over25'] / $limit) * ($max_people - 2)),
);
drupal_set_message(t('Aiming for !males males, !females females in group. Made up of !20s under 20, !low20s between 20 and 25, and !high20s over 25. Total count in group is !max.',
array('!20s' => $maximums['under20'], '!low20s' => $maximums['20to25'], '!high20s' => $maximums['over25'],
'!males' => $maximums['male'], '!females' => $maximums['female'], '!max' => $max_people)
));
//select any entries already in the mapping table //select any entries already in the mapping table
$group_mapping_query = db_query("SELECT * FROM {booking_studygroup_mapping} WHERE booking_eventid = :eid", array(':eid' => $event->eid)); $group_mapping_query = db_query("SELECT * FROM {booking_studygroup_mapping} WHERE booking_eventid = :eid", array(':eid' => $event->eid));
$group_mapping = $group_mapping_query->fetchAllAssoc('sid'); $group_mapping = $group_mapping_query->fetchAllAssoc('sid');
@@ -436,11 +478,12 @@ function booking_studygroups_calculate() {
$person->session = 0; $person->session = 0;
$person->is_leader = 'N'; $person->is_leader = 'N';
$person->is_helper = 'N'; $person->is_helper = 'N';
$person->is_reserveleader = 'N';
} }
//watchdog('booking', "Attendee list: @info", array('@info' => var_export($attendees, TRUE))); //watchdog('booking', "Attendee list: @info", array('@info' => var_export($attendees, TRUE)));
//iterate over each study group (eg Monday Tuesday Wednesday etc) //process each study group (eg Monday Tuesday Wednesday etc)
foreach ($studygroups as $group) foreach ($studygroups as $group)
{ {
drupal_set_message(t('Processing study group !group with !sessions sessions.', drupal_set_message(t('Processing study group !group with !sessions sessions.',
@@ -448,43 +491,61 @@ function booking_studygroups_calculate() {
//create a temporary copy of the attendee list to work with for this study group //create a temporary copy of the attendee list to work with for this study group
$working_list = array(); $working_list = array();
$working_list = shuffle_assoc(clone_array($attendees)); $working_list = booking_shuffle_assoc(booking_clone_array($attendees));
//set up the iterator //set up the iterator
$obj = new ArrayObject( $working_list ); $obj = new ArrayObject( $working_list );
$it = $obj->getIterator(); $it = $obj->getIterator();
//clear the array keeping track of the number of people in each session for this group //clear the array keeping track of the number of people in each session for this group
for ($i = 1; $i <= $group->booking_num_group_sessions; $i++) for ($i = 1; $i <= $group->booking_num_group_sessions; $i++)
$session_count[$i] = 0; {
$session_count[$i] = array(
'total' => 0,
'male' => 0,
'female' => 0,
'under20' => 0,
'20to25' => 0,
'over25' => 0,
);
}
// $session_count[$i] = 0;
//search for the leaders and helpers for this study group //search for the leaders and helpers for this study group
foreach ($group_mapping as $person) foreach ($group_mapping as $person)
{ {
if ($person->booking_studygroup_id == $group->sid && ($person->booking_is_leader == 'Y' || $person->booking_is_helper == 'Y' || $person->booking_is_reserveleader == 'Y')) if ($person->booking_studygroup_id == $group->sid && ($person->booking_is_leader == 'Y' || $person->booking_is_helper == 'Y' ||
$person->booking_is_reserveleader == 'Y'))
{ {
drupal_set_message(t('Leader/helper with id !id assigned to session !session (currently with !num people).',
array('!id' => $person->booking_node_id, '!session' => $person->booking_session_id,
'!num' => $session_count[$person->booking_session_id]['total'])
));
drupal_set_message(t('Leader/helper with id !id assigned to session !session (currently with !num people).', array('!id' => $person->booking_node_id, '!session' => $person->booking_session_id, '!num' => $session_count[$person->booking_session_id]))); //mark this position as being used
//mark a position in this session as being used $age = _booking_get_age_years($working_list[$person->booking_node_id]->booking_dob);
$session_count[$person->booking_session_id]++; booking_assign_attendee_group($person->booking_node_id, $person->booking_session_id, 'male', $age, $working_list, $session_count);
//mark this person as processed in the working list
$working_list[$person->booking_node_id]->processed = 1;
//search for a spouse //get any potential spouse info
$spouse_id = $working_list[$person->booking_node_id]->booking_partner_id; $spouse_id = $working_list[$person->booking_node_id]->booking_partner_id;
if ($spouse_id > 0) if ($spouse_id > 0)
{ {
drupal_set_message(t('Spouse with id !id assigned to session !session (currently with !num people).', array('!id' => $spouse_id, '!session' => $person->booking_session_id, '!num' => $session_count[$person->booking_session_id]))); drupal_set_message(t('Spouse with id !id assigned to session !session (currently with !num people).',
//allocate the spouse to the same session array('!id' => $spouse_id, '!session' => $person->booking_session_id,
$working_list[$spouse_id]->session = $person->booking_session_id; '!num' => $session_count[$person->booking_session_id]['total'])
$working_list[$spouse_id]->processed = 1; ));
$session_count[$person->booking_session_id]++; //allocate the spouse to the same session
$age = _booking_get_age_years($working_list[$spouse_id]->booking_dob);
booking_assign_attendee_group($spouse_id, $person->booking_session_id, 'female', $age, $working_list, $session_count);
} }
//TODO: search for a boyfriend/girlfriend
} }
} }
//watchdog('booking', "Attendee list working copy after leader/helper spouse processing: @info", array('@info' => var_export($working_list, TRUE))); //watchdog('booking', "Attendee list working copy after leader/helper spouse processing: @info", array('@info' => var_export($working_list, TRUE)));
//watchdog('booking', "Attendee list session count after leader/helper spouse processing: @info", array('@info' => var_export($session_count, TRUE))); //watchdog('booking', "Attendee list session count after leader/helper spouse processing: @info", array('@info' => var_export($session_count, TRUE)));
//return;
//reset the iterator to starting position //reset the iterator to starting position
$it->rewind(); $it->rewind();
@@ -521,49 +582,48 @@ function booking_studygroups_calculate() {
//cycle the session counter if we already reached the end //cycle the session counter if we already reached the end
if ($i > $group->booking_num_group_sessions) if ($i > $group->booking_num_group_sessions)
$i = 1; $i = 1;
//check this session has room in it //get the current attendee element and their stats
$break_condition = false; $current = $it->current();
while ($session_count[$i] >= $max_people) $gender = $current->booking_gender == 'M' ? 'male' : 'female';
{ $age = _booking_get_age_years($current->booking_dob);
drupal_set_message(t("Session ID !id is full, moving to next session for user id !nid", array('!id' => $i, '!nid' => $it->key())));
$i++;
//reset the counter if we go past the end
if ($i > $group->booking_num_group_sessions)
{
$i = 1;
//make sure we don't get stuck in an infinite loop - only go past the end once
if ($break_condition == true)
{
drupal_set_message(t("Ran out of sessions that aren't full to place attendees into for '!id' group.", array('!id' => $group->booking_studygroup_descrip)), 'error', FALSE);
break;
}
$break_condition = true;
}
}
//get the current attendee element
$current = $it->current();
if ($age < 20)
$age_type = 'under20';
elseif($age >= 20 && $age < 25)
$age_type = '20to25';
else
$age_type = 'over25';
//make sure this person is going to fit in with our calculated gender ratios
_booking_loop_carefully($session_count, $gender, $i, $maximums[$gender], $group->booking_num_group_sessions, 2);
//make sure this person is going to fit in with our calculated age ratios
_booking_loop_carefully($session_count, $age_type, $i, $maximums[$age_type], $group->booking_num_group_sessions, 2);
//check for maximum group size
_booking_loop_carefully($session_count, 'total', $i, $max_people, $group->booking_num_group_sessions, 2);
//assign this attendee to this session if unprocessed so far //assign this attendee to this session if unprocessed so far
if ($current->processed == 0) if ($current->processed == 0)
{ {
drupal_set_message(t('Assigning person with id !id to session !session (currently with !num people).', array('!id' => $it->key(), '!session' => $i, '!num' => $session_count[$i]))); drupal_set_message(t('Assigning person with id !id with gender !gender and age group !age to session !session (currently with !num people).',
$current->session = $i; array('!id' => $it->key(), '!session' => $i, '!num' => $session_count[$i]['total'], '!gender' => $gender, '!age' => $age_type )
$current->processed = 1; ));
$partner_id = $current->booking_partner_id;
$session_count[$i]++;
booking_assign_attendee_group($it->key(), $i, $gender, $age, $working_list, $session_count);
$partner_id = $current->booking_partner_id;
//check if the attendee was married //check if the attendee was married
if ($partner_id > 0) if ($partner_id > 0)
{ {
//add the spouse to the same session and mark as processed in the temporary attendee list //add the spouse to the same session and mark as processed in the temporary attendee list
drupal_set_message(t('Assigning spouse (id !spouse) of id !id to session !session (currently with !num people).', drupal_set_message(t('Assigning spouse (id !spouse) of id !id to session !session (currently with !num people).',
array('!id' => $it->key(), '!session' => $i, '!spouse' => $current->booking_partner_id, '!num' => $session_count[$i]))); array('!id' => $it->key(), '!session' => $i, '!spouse' => $current->booking_partner_id, '!num' => $session_count[$i]['total'])));
booking_assign_attendee_group($partner_id, $i, $gender, $age, $working_list, $session_count);
$working_list[$partner_id]->session = $i;
$working_list[$partner_id]->processed = 1;
$session_count[$i]++;
} }
} }
@@ -630,22 +690,20 @@ function booking_studygroups_calculate() {
'booking_session_id' => $person->session, 'booking_session_id' => $person->session,
'booking_is_leader' => $person->is_leader, 'booking_is_leader' => $person->is_leader,
'booking_is_helper' => $person->is_helper, 'booking_is_helper' => $person->is_helper,
'booking_is_reserveleader' => $person->is_reserveleader,
); );
$insert_query->values($record); $insert_query->values($record);
} }
} }
$insert_query->execute(); //$insert_query->execute();
watchdog('booking', "<pre>Attendee list:\n@info</pre>", array('@info' => print_r( $session_count, true)));
//watchdog('booking', "Attendee list: @info", array('@info' => var_export($session_count, TRUE)));
//clear the arrays we've been using for this iteration //clear the arrays we've been using for this iteration
unset($session_count); unset($session_count);
unset($working_list); unset($working_list);
//
} //finished processing study groups } //finished processing study groups
//watchdog('booking', "Attendee list final version: @info", array('@info' => var_export($attendees, TRUE))); //watchdog('booking', "Attendee list final version: @info", array('@info' => var_export($attendees, TRUE)));

View File

@@ -20,6 +20,7 @@ function booking_tokens_admin() {
"<li>No alcohol or illicit drugs are allowed at [booking:eventname]. Not only do these do serious harm to you but can endanger others who attend. Only bring things that better yourself and others</li>\n" . "<li>No alcohol or illicit drugs are allowed at [booking:eventname]. Not only do these do serious harm to you but can endanger others who attend. Only bring things that better yourself and others</li>\n" .
"<li>With regards to clothing, we ask that you wear modest clothing to all activities. There is a variety of activities during [booking:eventname], we would like you to be comfortable at all times. In light of this, pants may be worn throughout for all attendees - when packing, please keep in mind that modesty and moderate dress will be insisted upon</li>\n" . "<li>With regards to clothing, we ask that you wear modest clothing to all activities. There is a variety of activities during [booking:eventname], we would like you to be comfortable at all times. In light of this, pants may be worn throughout for all attendees - when packing, please keep in mind that modesty and moderate dress will be insisted upon</li>\n" .
"<li>In keeping with the spirit of [booking:eventname], please respect the facilities and equipment. We ask that you also respect the instruction of the Hosts and the Committee. Attendees must not leave the premises without the prior permission of the Secretary or Hosts.</li></ul>"; "<li>In keeping with the spirit of [booking:eventname], please respect the facilities and equipment. We ask that you also respect the instruction of the Hosts and the Committee. Attendees must not leave the premises without the prior permission of the Secretary or Hosts.</li></ul>";
$default_aims_and_rules_checkbox = "I regularly attend CYC type activities/events, and I agree at all times to be an example of Christ and that my actions and words will be a light to those we meet.";
$default_into_regn_not_opened_text = t("<p><br />Hi. Welcome to the booking page for [booking:eventname], God willing.</p>\n" . $default_into_regn_not_opened_text = t("<p><br />Hi. Welcome to the booking page for [booking:eventname], God willing.</p>\n" .
"<p>Bookings are not yet open. Please try again later.</p>" . "<p>Bookings are not yet open. Please try again later.</p>" .
"<p>If you have any questions, please use the !contact form.</p>", "<p>If you have any questions, please use the !contact form.</p>",
@@ -154,6 +155,12 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text
'#type' => 'textarea', '#type' => 'textarea',
'#default_value' => variable_get('default_into_regn_closed_text', $default_into_regn_closed_text), '#default_value' => variable_get('default_into_regn_closed_text', $default_into_regn_closed_text),
); );
$form['registration']['booking_registration_aims_rules_checkbox'] = array(
'#title' => t('The text next to the aims and rules checkbox'),
'#type' => 'textarea',
'#description' => t(''),
'#default_value' => variable_get('booking_registration_aims_rules_checkbox', $default_aims_and_rules_checkbox),
);
$form['registration']['booking_registration_aims_rules_text'] = array( $form['registration']['booking_registration_aims_rules_text'] = array(
'#title' => t('The aims and rules attendees must agree to'), '#title' => t('The aims and rules attendees must agree to'),
'#type' => 'textarea', '#type' => 'textarea',
@@ -335,6 +342,12 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text
'#description' => t(''), '#description' => t(''),
'#default_value' => variable_get('booking_email_waitinglist_text', $booking_email_waitinglist_text), '#default_value' => variable_get('booking_email_waitinglist_text', $booking_email_waitinglist_text),
); );
$form['emails']['booking_email_travel_complete_text'] = array(
'#title' => t('Email text to indicate a person has completed the travel form.'),
'#type' => 'textarea',
'#description' => t(''),
'#default_value' => variable_get('booking_email_travel_complete_text', ''),
);
$form['emails']['booking_email_paymentoutstanding_text'] = array( $form['emails']['booking_email_paymentoutstanding_text'] = array(
'#title' => t('Email text to send a person reminding them of how much they owe'), '#title' => t('Email text to send a person reminding them of how much they owe'),
'#type' => 'textarea', '#type' => 'textarea',

View File

@@ -43,11 +43,6 @@ function booking_travel_page() {
if ($travelform) if ($travelform)
{ {
/*
$output .= t("<p><br />Hi !firstname !lastname. Our records indicate you or your spouse have already completed the travel details form for !event. " .
"Please contact us if you need change any of your travel details.</p>",
array('!firstname' => $person->booking_firstname, '!lastname' => $person->booking_lastname, '!event' => $event->booking_eventname));
*/
$output = token_replace(variable_get('booking_travelform_completed_page'), $tokens); $output = token_replace(variable_get('booking_travelform_completed_page'), $tokens);
$return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output)); $return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output));
} }
@@ -93,7 +88,7 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
{ {
$data = $form_state['input']; $data = $form_state['input'];
//check for existing booking_person data to use in the form //check for existing booking_person data to use in the form
$person = db_query("SELECT booking_dietary, booking_medical_conditions, booking_bf_gf " . $person = db_query("SELECT booking_dietary, booking_medical_conditions, booking_bf_gf, booking_partner_id " .
"FROM {booking_person} " . "FROM {booking_person} " .
"WHERE nid = :nid ", "WHERE nid = :nid ",
array(':nid' => $nid)) array(':nid' => $nid))
@@ -128,8 +123,8 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Transport Type'), '#title' => t('Transport Type'),
'#options' => $transport_type_options, '#options' => $transport_type_options,
'#default_value' => !empty($data->booking_transport_type) ? $data->booking_transport_type : '', '#default_value' => !empty($data->booking_transport_type) ? $data->booking_transport_type : '0',
'#required' => TRUE, //'#required' => TRUE,
); );
/* /*
@@ -264,13 +259,18 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
'#required' => FALSE, '#required' => FALSE,
'#default_value' => !empty($data->booking_medical_conditions) ? $data->booking_medical_conditions : $booking_medical_conditions, '#default_value' => !empty($data->booking_medical_conditions) ? $data->booking_medical_conditions : $booking_medical_conditions,
); );
$form['requirements']['booking_bf_gf'] = array( //only show this field if this person isn't married
'#type' => 'textfield', //TODO: Get their registration ID instead of their name
'#title' => t('Boyfriend/Girlfriend that you want to be in the same discussion groups as you.'), if ((variable_get('booking_enable_combined_pricing', 0) == 1) && $person->booking_partner_id == 0)
'#maxlength' => 180, {
'#required' => FALSE, $form['requirements']['booking_bf_gf'] = array(
'#default_value' => !empty($data->booking_bf_gf) ? $data->booking_bf_gf : $booking_bf_gf, '#type' => 'textfield',
); '#title' => t('Boyfriend/Girlfriend that you want to be in the same discussion groups as you.'),
'#maxlength' => 180,
'#required' => FALSE,
'#default_value' => !empty($data->booking_bf_gf) ? $data->booking_bf_gf : $booking_bf_gf,
);
}
if ($inserting == TRUE) { if ($inserting == TRUE) {
$form['submit'] = array( $form['submit'] = array(
@@ -282,6 +282,13 @@ function travel_form($node, &$form_state, $inserting = FALSE, $nid = 0)
} }
function travel_form_validate($form, &$form_state) { function travel_form_validate($form, &$form_state) {
watchdog('booking', 'Travel form: @info', array('@info' => var_export($form_state, TRUE)));
//check that a transport choice has been made
if (isset($form_state['booking_transport_type']) && $form_state['booking_transport_type'] == 0)
{
form_set_error('booking_transport_type', t('You must select a transport type.'));
}
} }
function travel_form_submit($form, &$form_state) { function travel_form_submit($form, &$form_state) {
@@ -333,26 +340,15 @@ function travel_form_submit($form, &$form_state) {
//booking_person related fields //booking_person related fields
$node->booking_dietary = $values['booking_dietary']; $node->booking_dietary = $values['booking_dietary'];
$node->booking_medical_conditions = $values['booking_medical_conditions']; $node->booking_medical_conditions = $values['booking_medical_conditions'];
$node->booking_bf_gf = $values['booking_bf_gf']; $node->booking_bf_gf = empty($values['booking_bf_gf']) ? 'N/A' : $values['booking_bf_gf'];
//store the node //store the node
$foo = node_submit(&$node); $foo = node_submit(&$node);
$blah = node_save($foo); $blah = node_save($foo);
//send a confirmation email //send a confirmation email
_booking_travelform_confirmation_email($node); _booking_travelform_confirmation_email($node);
//TODO: Put this back in after testing
/*
//clear the temp id
db_update('booking_person')
->fields(array(
'booking_tempid' => '',
))
->condition('nid', $values['personid'])
->execute();
*/
drupal_set_message("Thanks for submitting your travel details. You should receive a confirmation email shortly.", $type = 'status'); drupal_set_message("Thanks for submitting your travel details. You should receive a confirmation email shortly.", $type = 'status');
$form_state['redirect'] = array('content/travel'); $form_state['redirect'] = array('content/travel');
@@ -470,11 +466,11 @@ function travel_view($node, $view_mode) {
global $event; global $event;
//fetch details about the person //fetch details about the person
$person = db_query("SELECT booking_firstname, booking_lastname " . $person = db_query("SELECT p.*, t.* from {booking_person} p " .
"FROM {booking_person} " . "left outer join {booking_travel} t on p.nid = t.booking_person_nid " .
"WHERE nid = :nid ", "where p.nid = :nid",
array(':nid' => $node->booking_person_nid)) array(':nid' => $node->booking_person_nid))
->fetchObject(); ->fetchObject();
$header = array('Attribute', 'Value'); $header = array('Attribute', 'Value');
$rows = array(); $rows = array();