Files
booking/booking.variety_form.inc
Nathan Coad 7f4f8455ee cleanup
2018-05-02 16:33:18 +10:00

103 lines
3.1 KiB
PHP

<?php
/**
* @file
* User facing page for booking into a variety session
* NOTE: This feature is not complete
*/
function booking_variety_regn_form($node, &$form_state)
{
global $event;
$form = array ();
$data = $node;
// Query the variety timeslot table
$timeslot_query = db_select('booking_variety_times', 'v');
$timeslot_query->condition('v.booking_eventid', $event->eid, '=')
->fields('v')
->orderBy('v.booking_variety_start');
$result = $timeslot_query->execute();
$form['#prefix'] = '<div id="booking_variety_session_form_wrapper">';
$form['#suffix'] = '</div>';
$form['identity'] = array(
'#type' => 'fieldset',
'#title' => 'Select Person',
);
$form['identity']['booking_nid'] = array(
'#type' => 'textfield',
'#title' => t('Booking Number'),
'#description' => t('Please enter your booking number from your lanyard.'),
'#size' => 60,
'#required' => TRUE,
'#default_value' => !empty($data->booking_nid) ? $data->booking_nid : '',
'#ajax' => array(
'event' => 'change',
'wrapper' => 'booking_variety_session_fieldset_wrapper',
'callback' => 'booking_variety_session_form_callback',
),
);
$form['variety-sessions'] = array(
'#type' => 'fieldset',
'#title' => 'Select Variety Sessions',
'#prefix' => '<div id="booking_variety_session_fieldset_wrapper">',
'#suffix' => '</div>'
);
//for each entry in the variety timeslot table, create a new form select item
foreach($result as $timeslot) {
$fieldname = 'select-variety-' . $timeslot->tid;
// Make sure we get rid of any stale data
/*
if (isset($form_state['input']['variety-sessions'][$fieldname])) {
watchdog('booking_debug', 'Unsetting stale @name data, was: <pre>@info</pre>',
array('@name' => $fieldname, '@info' => print_r($form_state['input'], true)));
unset($form_state['input']['variety-sessions'][$fieldname]);
}
*/
//create the form element for this timeslot
$form['variety-sessions'][$fieldname] = array(
'#type' => 'select',
'#title' => t('Variety Session: ' . $timeslot->booking_variety_time_descrip),
'#required' => TRUE,
'#default_value' => isset($form_state['values'][$fieldname]) ? $form_state['values'][$fieldname] : 0,
'#options' => _booking_get_variety_timeslot_options($timeslot->tid),
'#prefix' => '<div id="booking_variety_session_' . $timeslot->tid . '_wrapper">',
'#suffix' => '</div>',
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return array (
'form' => $form,
);
}
/**
* Callback function to rebuild the variety session fieldset
*/
function booking_variety_session_form_callback($form, &$form_state) {
$form_state['rebuild'] = TRUE;
return $form['form']['variety-sessions'];
}
/**
* Process the submission
*/
function booking_variety_regn_form_submit($form, &$form_state) {
global $event;
$values = $form_state['input'];
watchdog('booking_debug', 'booking_variety_regn_form_submit: <pre>@info</pre>', array('@info' => print_r( $form_state, true)));
}