$event->eid));
$form['booking_variety_regn_feedback_wrapper'] = array(
'#markup' => '
Please enter your booking number from your lanyard. ' .
'
',
);
$form['booking_nid'] = array(
'#type' => 'textfield',
'#title' => t('Booking ID'),
'#size' => 60,
'#required' => TRUE,
'#default_value' => !empty($data->booking_nid) ? $data->booking_nid : '',
'#ajax' => array(
'event' => 'change',
'wrapper' => 'booking_variety_regn_feedback_wrapper',
'callback' => 'booking_variety_regn_callback',
),
);
//for each entry in the variety timeslot table, create a new form select item
$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();
foreach($result as $timeslot) {
//reset the array
$options = array ();
$options[''] = '';
//query for variety sessions in the timeslot
$session_query = db_query("SELECT * from {booking_variety_options} WHERE booking_variety_timeslot_id = :id AND booking_variety_status = 1",
array(':id' => $timeslot->tid));
//add all the sessions to the select list
foreach($session_query as $session)
{
$options[$session->vid] = $session->booking_variety_descrip;
}
//create the form element for this timeslot
$form['select-variety-' . $timeslot->tid] = array(
'#type' => 'select',
'#title' => t('Variety Session: ' . $timeslot->booking_variety_time_descrip),
'#required' => TRUE,
'#default_value' => '',
'#options' => _booking_get_variety_timeslot_options($timeslot->tid),
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return array (
'form' => $form,
);
}
/**
* Function to calculate available variety sessions for ajax enabled form booking_variety_regn_form()
* @param $timeslot_id - the timeslot ID to query
* @return array containing the variety sessions for specified timeslot that still have capacity
*/
function _booking_get_variety_timeslot_options($timeslot_id) {
$session_options = array();
$session_options[] = "--";
$session_query = db_query("SELECT * FROM {booking_variety_options} WHERE booking_variety_timeslot_id = :tid AND booking_variety_status = 1",
array(':tid' => $timeslot_id));
// Only add sessions that aren't full to the return result
foreach($session_query as $session) {
if ($session->booking_variety_regncount < $session->booking_variety_maxsize) {
$session_options[$session->vid] = $session->booking_variety_descrip;
}
}
watchdog('booking_debug', "Variety Session Options:\n@info
", array('@info' => print_r( $session_options, true)));
return $session_options;
}
/**
* Callback function to verify if barcode was valid
*/
function booking_variety_regn_callback($form, &$form_state) {
global $event;
//$node = $form_state['values']['form_id'];
$data = $form_state['input'];
watchdog('booking', 'booking_variety_regn_callback validation:\n@info
', array('@info' => print_r( $data, true)));
//verify that user-entered data is a number
if (! preg_match('/^[0-9]+$/', $data['booking_nid'])) {
watchdog('booking_debug', "booking_variety_regn_callback non-numerical input
");
return '' .
'You have not entered a valid booking reference number.
';
}
// Perform lookup on barcode to make sure it matches someone attending the current event
$db_and = db_and();
$db_and->condition('p.booking_eventid', $event->eid, '=');
$db_and->condition('p.booking_status', 1, '=');
$db_and->condition('p.nid', $data['booking_nid'], '=');
$query = db_select('booking_person', 'p');
$query->condition($db_and)
->fields('p');
$person = $query->execute()
->fetchObject();
if ($person) {
watchdog('booking_debug', "booking_variety_regn_callback found valid attendee
");
return '' .
'Matched booking reference number.
';
}
else {
watchdog('booking_debug', "booking_variety_regn_callback did not find valid attendee
");
return '' .
'You have not entered a valid booking reference number.
';
}
}