cleanup
This commit is contained in:
@@ -12,10 +12,7 @@ function booking_variety_regn_form($node, &$form_state)
|
||||
global $event;
|
||||
$form = array ();
|
||||
$data = $node;
|
||||
|
||||
//$query = db_query("SELECT * FROM {booking_variety_times} WHERE booking_eventid = :eid AND booking_variety_status = 1",
|
||||
// array(':eid' => $event->eid));
|
||||
|
||||
|
||||
// Query the variety timeslot table
|
||||
$timeslot_query = db_select('booking_variety_times', 'v');
|
||||
$timeslot_query->condition('v.booking_eventid', $event->eid, '=')
|
||||
@@ -30,11 +27,7 @@ function booking_variety_regn_form($node, &$form_state)
|
||||
'#type' => 'fieldset',
|
||||
'#title' => 'Select Person',
|
||||
);
|
||||
/*
|
||||
$form['identity']['booking_variety_regn_feedback_wrapper'] = array(
|
||||
'#markup' => '<div id="booking_variety_regn_feedback_wrapper" class="form-item">Please enter your booking number from your lanyard.</div>',
|
||||
);
|
||||
*/
|
||||
|
||||
$form['identity']['booking_nid'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Booking Number'),
|
||||
@@ -44,12 +37,6 @@ function booking_variety_regn_form($node, &$form_state)
|
||||
'#default_value' => !empty($data->booking_nid) ? $data->booking_nid : '',
|
||||
'#ajax' => array(
|
||||
'event' => 'change',
|
||||
//'wrapper' => 'booking_variety_regn_feedback_wrapper',
|
||||
//'callback' => 'booking_variety_regn_callback',
|
||||
|
||||
//'wrapper' => 'booking_variety_session_wrapper',
|
||||
//'callback' => 'booking_variety_session_callback',
|
||||
|
||||
'wrapper' => 'booking_variety_session_fieldset_wrapper',
|
||||
'callback' => 'booking_variety_session_form_callback',
|
||||
),
|
||||
@@ -67,11 +54,13 @@ function booking_variety_regn_form($node, &$form_state)
|
||||
$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(
|
||||
@@ -95,164 +84,11 @@ function booking_variety_regn_form($node, &$form_state)
|
||||
);
|
||||
}
|
||||
|
||||
function booking_variety_session_callback($form, &$form_state) {
|
||||
global $event;
|
||||
$commands = array();
|
||||
//$node = $form_state['values']['form_id'];
|
||||
$data = $form_state['input'];
|
||||
watchdog('booking_debug', 'booking_variety_session_callback:<br /><pre>@info</pre>', array('@info' => print_r( $form, true)));
|
||||
|
||||
// --- Update the wrapper for booking ID validity ---
|
||||
//verify that user-entered data is a number
|
||||
if (! preg_match('/^[0-9]+$/', $data['booking_nid'])) {
|
||||
watchdog('booking_debug', "<pre>booking_variety_session_callback non-numerical input</pre>");
|
||||
$markup = '<div id="booking_variety_regn_feedback_wrapper" class="form-item"><span style="color:#8c2e0b;font-weight: bold;">' .
|
||||
'You have not entered a valid booking reference number.</span></div>';
|
||||
$commands[] = ajax_command_replace('#booking_variety_regn_feedback_wrapper', $markup);
|
||||
}
|
||||
|
||||
// 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_session_callback found valid attendee</pre>");
|
||||
|
||||
$markup = '<div id="booking_variety_regn_feedback_wrapper" class="form-item"><span style="color:#234600;font-weight: bold;">' .
|
||||
'Matched booking reference number.</span></div>';
|
||||
$commands[] = ajax_command_replace('#booking_variety_regn_feedback_wrapper', $markup);
|
||||
}
|
||||
else {
|
||||
watchdog('booking_debug', "<pre>booking_variety_session_callback did not find valid attendee</pre>");
|
||||
|
||||
$markup = '<div id="booking_variety_regn_feedback_wrapper" class="form-item"><span style="color:#8c2e0b;font-weight: bold;">' .
|
||||
'You have not entered a valid booking reference number.</span></div>';
|
||||
$commands[] = ajax_command_replace('#booking_variety_regn_feedback_wrapper', $markup);
|
||||
}
|
||||
|
||||
// --- Update the wrapper for available variety sessions ---
|
||||
// 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();
|
||||
|
||||
//for each entry in the variety timeslot table, create a new form select item
|
||||
foreach($result as $timeslot) {
|
||||
$fieldname = 'select-variety-' . $timeslot->tid;
|
||||
$options = _booking_get_variety_timeslot_options($timeslot->tid);
|
||||
watchdog('booking_debug', 'Timeslot @tid form state value: <pre>@info</pre>',
|
||||
array('@tid' => $timeslot->tid, '@info' => print_r($form_state['values'], true)));
|
||||
watchdog('booking_debug', 'Setting timeslot @tid default value to @value', array(
|
||||
'@tid' => $timeslot->tid,
|
||||
'@value' => isset($form_state['values'][$fieldname]) ? $form_state['values'][$fieldname] : 0)
|
||||
);
|
||||
|
||||
//re-create the form element for this timeslot
|
||||
|
||||
$form['variety-sessions'][$fieldname] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Rebuilt Variety Session: ' . $timeslot->booking_variety_time_descrip),
|
||||
'#required' => TRUE,
|
||||
'#options' => $options,
|
||||
'#prefix' => '<div id="booking_variety_session_' . $timeslot->tid . '_wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
'#default_value' => 1,
|
||||
);
|
||||
|
||||
//$form['variety-sessions'][$fieldname]['#options'] = $options;
|
||||
//$form['variety-sessions'][$fieldname]['#title'] = t('Rebuilt Variety Session: ' . $timeslot->booking_variety_time_descrip);
|
||||
|
||||
// Tell drupal to update the wrapper for this field
|
||||
$commands[] = ajax_command_replace('#booking_variety_session_' . $timeslot->tid . '_wrapper', drupal_render($form['variety-sessions'][$fieldname]));
|
||||
//$commands[] = ajax_command_replace('#booking_variety_session_' . $timeslot->tid . '_wrapper', drupal_render($form));
|
||||
}
|
||||
|
||||
$form_state['rebuild'] = TRUE;
|
||||
return array('#type' => 'ajax', '#commands' => $commands);
|
||||
//$page = array('#type' => 'ajax', '#commands' => $commands);
|
||||
//ajax_deliver($page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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', "<pre>Variety Session Options:\n@info</pre>", 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', '<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" class="form-item"><span style="color:#8c2e0b;font-weight: bold;">' .
|
||||
'You have not entered a valid booking reference number.</span></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" class="form-item"><span style="color:#234600;font-weight: bold;">' .
|
||||
'Matched booking reference number.</span></div>';
|
||||
}
|
||||
else {
|
||||
watchdog('booking_debug', "<pre>booking_variety_regn_callback did not find valid attendee</pre>");
|
||||
return '<div id="booking_variety_regn_feedback_wrapper" class="form-item"><span style="color:#8c2e0b;font-weight: bold;">' .
|
||||
'You have not entered a valid booking reference number.</span></div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback function
|
||||
* Callback function to rebuild the variety session fieldset
|
||||
*/
|
||||
function booking_variety_session_form_callback($form, &$form_state) {
|
||||
$form['form']['identity']['booking_nid']['#description'] = "Done";
|
||||
$form_state['rebuild'] = TRUE;
|
||||
return $form['form']['variety-sessions'];
|
||||
}
|
||||
|
Reference in New Issue
Block a user