diff --git a/booking.admin.inc b/booking.admin.inc index fd4b744..c4f9111 100644 --- a/booking.admin.inc +++ b/booking.admin.inc @@ -74,12 +74,22 @@ function booking_admin() { $form['attendee']['booking_max_dob'] = array ( '#type' => 'date_select', '#title' => t('Maximum Date of Birth'), - '#description' => t("The most recent date of birth you wish to allow into the event."), + '#description' => t("The youngest date of birth you wish to allow into the event."), '#default_value' => variable_get('booking_max_dob','1995-04-15 00:00:00'), '#date_format' => 'd/m/Y', '#date_label_position' => 'within', '#date_year_range' => '-60:-10' ); + + $form['attendee']['booking_min_dob'] = array ( + '#type' => 'date_select', + '#title' => t('Minimum Date of Birth'), + '#description' => t("The oldest date of birth you wish to allow into the event."), + '#default_value' => variable_get('booking_min_dob','1995-04-15 00:00:00'), + '#date_format' => 'd/m/Y', + '#date_label_position' => 'within', + '#date_year_range' => '-60:-10' + ); $form['attendee']['booking_regn_limit'] = array ( '#type' => 'textfield', diff --git a/booking.helper.inc b/booking.helper.inc index f8506ce..1929046 100644 --- a/booking.helper.inc +++ b/booking.helper.inc @@ -336,6 +336,43 @@ function _booking_max_dob_ts() return mktime(12, 0, 0, $max_dob_matches[2], $max_dob_matches[3], $max_dob_matches[1]); } +/** + * Helper function to calculate the year offset between the start of event and a + * + * @param $datetime Date to compare from date_select field + * @return integer containing difference in years + */ +function _booking_year_offset($datetime) +{ + global $event; + + //set the time zone + date_default_timezone_set(date_default_timezone(FALSE)); + $tz = new DateTimeZone(date_default_timezone(FALSE)); + + //try to load the date + try { + //$date = new DateTime(variable_get('booking_min_dob','1970-01-01 00:00:00')); + $date = new DateTime($datetime); + } catch (Exception $e) { + $date = new DateTime('1970-01-01 00:00:00'); + } + + //set the timezone for the date + $date->setTimezone($tz); + + //watchdog('booking', '
DateTime of minimum DOB:\n @info 
', array('@info' => print_r( $date, true))); + + $reference_date = _booking_convert_ts($event->booking_event_start); + $difference = $date->diff($reference_date); + + //watchdog('booking', '
DateTime of difference in minimum DOB to start of event:\n @info 
', array('@info' => print_r( $difference, true))); + + return $difference->y; + +} + + /** * Helper function to calculate the average age in days, months and years at the start of the event */ @@ -369,6 +406,9 @@ function _booking_get_age_years($dob_ts) return $dob->diff($reference_ts)->y; } +/** + * Helper function to create a string describing a date range + */ function _date_range_to_string($date_start, $date_end) { $start = _booking_split_date($date_start); $end = _booking_split_date($date_end); diff --git a/booking.regn_form.inc b/booking.regn_form.inc index e7be80f..b91195d 100644 --- a/booking.regn_form.inc +++ b/booking.regn_form.inc @@ -49,26 +49,6 @@ function booking_register_page() { return $return_array; } -/** - * Landing page after returning from paypal - */ -function booking_payment_completed_page() { - //get some configuration information - global $event; - $output = ""; - $return_array = array(); - - //set the page title - $bookingTitle = !empty($event->booking_eventname) ? $event->booking_eventname : 'Event'; - drupal_set_title($bookingTitle . ' Registration Completed'); - - $output = token_replace(variable_get('booking_regn_completed_page'), booking_define_tokens()); - $return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output)); - - return $return_array; -} - - function booking_form($node, &$form_state, $inserting = FALSE) { global $event; @@ -77,6 +57,12 @@ function booking_form($node, &$form_state, $inserting = FALSE) { $partner_options = array(); date_default_timezone_set(date_default_timezone(FALSE)); + //calculate what years to show in the date of birth field + $min_dob_years = _booking_year_offset(variable_get('booking_min_dob','1970-01-01 00:00:00')); + $max_dob_years = _booking_year_offset(variable_get('booking_max_dob','1970-01-01 00:00:00')); + $date_year_range = "-" . $min_dob_years . ':-' . $max_dob_years; + + //determine whether loading saved node or form submission if (!empty($node)) { $data = $node; @@ -93,11 +79,13 @@ function booking_form($node, &$form_state, $inserting = FALSE) { 'legal_guardian' => 'Legal Guardian', 'relative' => 'Close Relative'); + /* $status_options[0] = t('Not Paid'); $status_options[1] = t('Booked In'); $status_options[2] = t('Waiting List'); $status_options[3] = t('No Longer Coming'); - +*/ + //figure out if we're in the earlybird rate section $early = db_query("SELECT booking_earlybird_close FROM {booking_event} where eid = :eid", array( ':eid' => $event->eid)) @@ -158,8 +146,14 @@ function booking_form($node, &$form_state, $inserting = FALSE) { '#date_format' => 'd/m/Y', '#date_label_position' => 'within', '#date_year_range' => '-50:-13' + //'#date_year_range' => $date_year_range, ); + //override our generous date year range if this is a new form submission + if ($inserting == TRUE) { + $form['your-details']['booking_dob']['#date_year_range'] = $date_year_range; + } + $form['your-details']['booking_payment_id'] = array( '#type' => 'select', '#title' => t('Choose your payment type'), @@ -1265,3 +1259,24 @@ function _booking_form_submit_post_triggers($node) { } } + + +/** + * Landing page after returning from paypal + */ +function booking_payment_completed_page() { + //get some configuration information + global $event; + $output = ""; + $return_array = array(); + + //set the page title + $bookingTitle = !empty($event->booking_eventname) ? $event->booking_eventname : 'Event'; + drupal_set_title($bookingTitle . ' Registration Completed'); + + $output = token_replace(variable_get('booking_regn_completed_page'), booking_define_tokens()); + $return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output)); + + return $return_array; +} + diff --git a/booking.regn_node.inc b/booking.regn_node.inc index 7b2e0ad..5f87050 100644 --- a/booking.regn_node.inc +++ b/booking.regn_node.inc @@ -114,7 +114,7 @@ function booking_load($nodes) { } } - //watchdog('booking', 'Final loaded node: @info', array('@info' => var_export($nodes, TRUE))); + watchdog('booking', 'Final loaded node: @info', array('@info' => var_export($nodes, TRUE))); // no return necessary since $nodes array members reference objects global to this function }