develop variety session form
This commit is contained in:
120
booking.variety_form.inc
Normal file
120
booking.variety_form.inc
Normal file
@@ -0,0 +1,120 @@
|
||||
<?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;
|
||||
$timeslot_count = 0;
|
||||
|
||||
$query = db_query("SELECT * FROM {booking_variety_times} WHERE booking_eventid = :eid AND booking_variety_status = 1",
|
||||
array(':eid' => $event->eid));
|
||||
|
||||
|
||||
$form['booking_variety_regn_feedback_wrapper'] = array(
|
||||
'#markup' => '<div id="booking_variety_regn_feedback_wrapper">Please enter your booking number from your lanyard. ' .
|
||||
'</p></div><br />',
|
||||
);
|
||||
$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
|
||||
$result = db_query("SELECT * from {booking_variety_times}");
|
||||
|
||||
foreach($query 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_count] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Variety Session: ' . $timeslot->booking_variety_time_descrip),
|
||||
'#required' => TRUE,
|
||||
'#default_value' => '',
|
||||
'#options' => $options,
|
||||
);
|
||||
|
||||
$timeslot_count++;
|
||||
}
|
||||
|
||||
$form['submit'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Submit'),
|
||||
);
|
||||
|
||||
return array (
|
||||
'form' => $form,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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', '<pre>booking_variety_regn_callback validation:\n@info</pre>', 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', "<pre>booking_variety_regn_callback non-numerical input</pre>");
|
||||
return '<div id="booking_variety_regn_feedback_wrapper"><span style="color:#8c2e0b;font-weight: bold;">' .
|
||||
'You have not entered a valid booking reference number.</span><br /><br /></div>';
|
||||
}
|
||||
|
||||
// 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', "<pre>booking_variety_regn_callback found valid attendee</pre>");
|
||||
return '<div id="booking_variety_regn_feedback_wrapper"><span style="color:#234600;font-weight: bold;">' .
|
||||
'Matched booking reference number.</span><br /><br /></div>';
|
||||
}
|
||||
else {
|
||||
watchdog('booking_debug', "<pre>booking_variety_regn_callback did not find valid attendee</pre>");
|
||||
return '<div id="booking_variety_regn_feedback_wrapper"><span style="color:#8c2e0b;font-weight: bold;">' .
|
||||
'You have not entered a valid booking reference number.</span><br /><br /></div>';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user