add CSV report for variety session
This commit is contained in:
@@ -8,53 +8,55 @@
|
||||
|
||||
function booking_variety_admin()
|
||||
{
|
||||
//see http://www.jaypan.com/blog/themeing-drupal-7-forms-tables-checkboxes-or-radios
|
||||
// tableselect with text fields http://drupal.stackexchange.com/questions/75950/tableselect-with-textfields/82763#82763
|
||||
// inline edit buttons http://drupal.stackexchange.com/questions/31942/how-do-i-add-an-edit-button-on-each-row-of-a-tableselect-form-element
|
||||
// tabledrag example http://dropbucket.org/node/204
|
||||
$form = array ();
|
||||
$options = array ();
|
||||
//$prefix = t("<p>!link</p>",
|
||||
// array ('!link' => l('Add New Variety Timeslot', 'admin/config/booking/variety/create')));
|
||||
//see http://www.jaypan.com/blog/themeing-drupal-7-forms-tables-checkboxes-or-radios
|
||||
// tableselect with text fields http://drupal.stackexchange.com/questions/75950/tableselect-with-textfields/82763#82763
|
||||
// inline edit buttons http://drupal.stackexchange.com/questions/31942/how-do-i-add-an-edit-button-on-each-row-of-a-tableselect-form-element
|
||||
// tabledrag example http://dropbucket.org/node/204
|
||||
$form = array ();
|
||||
$options = array ();
|
||||
//$prefix = t("<p>!link</p>",
|
||||
// array ('!link' => l('Add New Variety Timeslot', 'admin/config/booking/variety/create')));
|
||||
|
||||
$header = array (
|
||||
'tid' => t('Event ID'),
|
||||
'booking_variety_time_descrip' => t('Description'),
|
||||
'booking_variety_status' => t('Status'),
|
||||
'booking_variety_start' => t('Timeslot Start'),
|
||||
'booking_variety_end' => t('Timeslot End'),
|
||||
'variety_edit' => t('Edit Timeslot'),
|
||||
'variety_session_list' => t('List Sessions'),
|
||||
'variety_session_add' => t('Add Session'),
|
||||
);
|
||||
$header = array (
|
||||
'tid' => t('Event ID'),
|
||||
'booking_variety_time_descrip' => t('Description'),
|
||||
'booking_variety_status' => t('Status'),
|
||||
'booking_variety_start' => t('Timeslot Start'),
|
||||
'booking_variety_end' => t('Timeslot End'),
|
||||
'variety_edit' => t('Edit Timeslot'),
|
||||
'variety_session_list' => t('List Sessions'),
|
||||
'variety_session_add' => t('Add Session'),
|
||||
'variety_session_csv' => t('CSV Report'),
|
||||
);
|
||||
|
||||
$result = db_query("SELECT * from {booking_variety_timeslots}");
|
||||
$result = db_query("SELECT * from {booking_variety_timeslots}");
|
||||
|
||||
foreach($result as $data)
|
||||
{
|
||||
$options[$data->tid] = array
|
||||
(
|
||||
'tid' => $data->tid,
|
||||
'booking_variety_time_descrip' => $data->booking_variety_time_descrip,
|
||||
'booking_variety_status' => $data->booking_variety_status,
|
||||
'booking_variety_start' => date("Y-m-d H:i", $data->booking_variety_start),
|
||||
'booking_variety_end' => date("Y-m-d H:i", $data->booking_variety_end),
|
||||
'variety_edit' => l('Edit Timeslot', t('admin/config/booking/variety/!tid/edit', array('!tid' => $data->tid))),
|
||||
'variety_session_list' => l('List Sessions', t('admin/config/booking/variety/!tid/session/list', array('!tid' => $data->tid))),
|
||||
'variety_session_add' => l('Add Session', t('admin/config/booking/variety/!tid/session/create', array('!tid' => $data->tid))),
|
||||
);
|
||||
}
|
||||
foreach($result as $data)
|
||||
{
|
||||
$options[$data->tid] = array
|
||||
(
|
||||
'tid' => $data->tid,
|
||||
'booking_variety_time_descrip' => $data->booking_variety_time_descrip,
|
||||
'booking_variety_status' => $data->booking_variety_status,
|
||||
'booking_variety_start' => date("Y-m-d H:i", $data->booking_variety_start),
|
||||
'booking_variety_end' => date("Y-m-d H:i", $data->booking_variety_end),
|
||||
'variety_edit' => l('Edit Timeslot', t('admin/config/booking/variety/!tid/edit', array('!tid' => $data->tid))),
|
||||
'variety_session_list' => l('List Sessions', t('admin/config/booking/variety/!tid/session/list', array('!tid' => $data->tid))),
|
||||
'variety_session_add' => l('Add Session', t('admin/config/booking/variety/!tid/session/create', array('!tid' => $data->tid))),
|
||||
'variety_session_csv' => l('CSV Report', t('admin/config/booking/variety/!tid/csv', array('!tid' => $data->tid))),
|
||||
);
|
||||
}
|
||||
|
||||
$form['table'] = array (
|
||||
'#type' => 'tableselect',
|
||||
'#header' => $header,
|
||||
'#options' => $options,
|
||||
'#multiple' => false,
|
||||
);
|
||||
$form['table'] = array (
|
||||
'#type' => 'tableselect',
|
||||
'#header' => $header,
|
||||
'#options' => $options,
|
||||
'#multiple' => false,
|
||||
);
|
||||
|
||||
return array (
|
||||
'form' => $form,
|
||||
);
|
||||
return array (
|
||||
'form' => $form,
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -66,302 +68,302 @@ function booking_variety_admin_submit($form, &$form_state)
|
||||
|
||||
function booking_variety_timeslot_form($node, &$form_state, $create, $editid = 0)
|
||||
{
|
||||
global $event;
|
||||
$form = array ();
|
||||
$prefix = "<p>Add a new variety session timeslot for the bookings module.</p>";
|
||||
global $event;
|
||||
$form = array ();
|
||||
$prefix = "<p>Add a new variety session timeslot for the bookings module.</p>";
|
||||
|
||||
if ($create == true)
|
||||
{
|
||||
$data = $node;
|
||||
}
|
||||
else
|
||||
{
|
||||
//verify that $editid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $editid)) {
|
||||
drupal_set_message("Error: Invalid variety ID supplied. Unable to update variety session information.", 'error', FALSE);
|
||||
drupal_goto('admin/config/booking/variety');
|
||||
return "";
|
||||
}
|
||||
if ($create == true)
|
||||
{
|
||||
$data = $node;
|
||||
}
|
||||
else
|
||||
{
|
||||
//verify that $editid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $editid)) {
|
||||
drupal_set_message("Error: Invalid variety ID supplied. Unable to update variety session information.", 'error', FALSE);
|
||||
drupal_goto('admin/config/booking/variety');
|
||||
return "";
|
||||
}
|
||||
|
||||
$data = db_select ('booking_variety_timeslots', 'v')
|
||||
->condition('v.tid', $editid, '=')
|
||||
->fields('v')
|
||||
->execute()
|
||||
->fetchObject();
|
||||
$data = db_select ('booking_variety_timeslots', 'v')
|
||||
->condition('v.tid', $editid, '=')
|
||||
->fields('v')
|
||||
->execute()
|
||||
->fetchObject();
|
||||
|
||||
$prefix = t("<p>Update the !event variety session details.</p>", array('!event' => $event->booking_eventname));
|
||||
//add this to the form in a hidden field so we can update the right event
|
||||
$form['tid'] = array (
|
||||
'#type' => 'hidden',
|
||||
'#value' => $editid,
|
||||
);
|
||||
}
|
||||
$prefix = t("<p>Update the !event variety session details.</p>", array('!event' => $event->booking_eventname));
|
||||
//add this to the form in a hidden field so we can update the right event
|
||||
$form['tid'] = array (
|
||||
'#type' => 'hidden',
|
||||
'#value' => $editid,
|
||||
);
|
||||
}
|
||||
|
||||
$form['booking_variety_time_descrip'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('The name of this variety session timeslot'),
|
||||
'#size' => 60,
|
||||
'#maxlength' => 150,
|
||||
'#required' => TRUE,
|
||||
'#default_value' => !empty($data->booking_variety_time_descrip) ? $data->booking_variety_time_descrip : '',
|
||||
);
|
||||
$form['booking_variety_time_descrip'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('The name of this variety session timeslot'),
|
||||
'#size' => 60,
|
||||
'#maxlength' => 150,
|
||||
'#required' => TRUE,
|
||||
'#default_value' => !empty($data->booking_variety_time_descrip) ? $data->booking_variety_time_descrip : '',
|
||||
);
|
||||
|
||||
$form['booking_variety_status'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Make this variety session timeslot active'),
|
||||
'#default_value' => !empty($data->booking_variety_status) ? $data->booking_variety_status : '',
|
||||
);
|
||||
$form['booking_variety_status'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Make this variety session timeslot active'),
|
||||
'#default_value' => !empty($data->booking_variety_status) ? $data->booking_variety_status : '',
|
||||
);
|
||||
|
||||
$form['booking_variety_start'] = array(
|
||||
'#type' => 'date_select',
|
||||
'#title' => t('When will this variety session start'),
|
||||
'#default_value' => empty($data->booking_variety_start) ? date("Y-m-d H:i:s") : date("Y-m-d H:i:s", $data->booking_variety_start),
|
||||
'#date_format' => 'd/m/Y H:i',
|
||||
'#date_label_position' => 'within',
|
||||
'#date_year_range' => '0:+5'
|
||||
);
|
||||
$form['booking_variety_start'] = array(
|
||||
'#type' => 'date_select',
|
||||
'#title' => t('When will this variety session start'),
|
||||
'#default_value' => empty($data->booking_variety_start) ? date("Y-m-d H:i:s") : date("Y-m-d H:i:s", $data->booking_variety_start),
|
||||
'#date_format' => 'd/m/Y H:i',
|
||||
'#date_label_position' => 'within',
|
||||
'#date_year_range' => '0:+5'
|
||||
);
|
||||
|
||||
$form['booking_variety_end'] = array(
|
||||
'#type' => 'date_select',
|
||||
'#title' => t('When will this variety session end?'),
|
||||
'#default_value' => empty($data->booking_variety_end) ? date("Y-m-d H:i:s") : date("Y-m-d H:i:s", $data->booking_variety_end),
|
||||
'#date_format' => 'd/m/Y H:i',
|
||||
'#date_label_position' => 'within',
|
||||
'#date_year_range' => '0:+5'
|
||||
);
|
||||
$form['booking_variety_end'] = array(
|
||||
'#type' => 'date_select',
|
||||
'#title' => t('When will this variety session end?'),
|
||||
'#default_value' => empty($data->booking_variety_end) ? date("Y-m-d H:i:s") : date("Y-m-d H:i:s", $data->booking_variety_end),
|
||||
'#date_format' => 'd/m/Y H:i',
|
||||
'#date_label_position' => 'within',
|
||||
'#date_year_range' => '0:+5'
|
||||
);
|
||||
|
||||
if ($create == true)
|
||||
{
|
||||
$form['submit'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Create'),
|
||||
);
|
||||
} else {
|
||||
$form['Update'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Update'),
|
||||
);
|
||||
$form['Delete'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Delete'),
|
||||
);
|
||||
}
|
||||
if ($create == true)
|
||||
{
|
||||
$form['submit'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Create'),
|
||||
);
|
||||
} else {
|
||||
$form['Update'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Update'),
|
||||
);
|
||||
$form['Delete'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Delete'),
|
||||
);
|
||||
}
|
||||
|
||||
return array (
|
||||
'first_para' => array (
|
||||
'#type' => 'markup',
|
||||
'#markup' => $prefix,
|
||||
),
|
||||
'form' => $form,
|
||||
);
|
||||
return array (
|
||||
'first_para' => array (
|
||||
'#type' => 'markup',
|
||||
'#markup' => $prefix,
|
||||
),
|
||||
'form' => $form,
|
||||
);
|
||||
}
|
||||
|
||||
function booking_variety_timeslot_form_submit($form, &$form_state) {
|
||||
global $event;
|
||||
$values = $form_state['input'];
|
||||
global $event;
|
||||
$values = $form_state['input'];
|
||||
|
||||
if ($form_state['values']['op'] == 'Create')
|
||||
{
|
||||
db_insert('booking_variety_timeslots')
|
||||
->fields(array(
|
||||
'booking_eventid' => $event->eid,
|
||||
'booking_variety_status' => $values['booking_variety_status'] == 1 ? 1 : 0,
|
||||
'booking_variety_time_descrip' => $values['booking_variety_time_descrip'],
|
||||
'booking_variety_start' => _datetime_array_to_ts($values['booking_variety_start']),
|
||||
'booking_variety_end' => _datetime_array_to_ts($values['booking_variety_end']),
|
||||
))
|
||||
->execute();
|
||||
}
|
||||
elseif ($form_state['values']['op'] == 'Delete')
|
||||
{
|
||||
//verify that tid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $values['tid'])) {
|
||||
drupal_set_message("Error: Invalid variety timeslot ID supplied. Unable to delete entry.", 'error', FALSE);
|
||||
return "";
|
||||
}
|
||||
if ($form_state['values']['op'] == 'Create')
|
||||
{
|
||||
db_insert('booking_variety_timeslots')
|
||||
->fields(array(
|
||||
'booking_eventid' => $event->eid,
|
||||
'booking_variety_status' => $values['booking_variety_status'] == 1 ? 1 : 0,
|
||||
'booking_variety_time_descrip' => $values['booking_variety_time_descrip'],
|
||||
'booking_variety_start' => _datetime_array_to_ts($values['booking_variety_start']),
|
||||
'booking_variety_end' => _datetime_array_to_ts($values['booking_variety_end']),
|
||||
))
|
||||
->execute();
|
||||
}
|
||||
elseif ($form_state['values']['op'] == 'Delete')
|
||||
{
|
||||
//verify that tid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $values['tid'])) {
|
||||
drupal_set_message("Error: Invalid variety timeslot ID supplied. Unable to delete entry.", 'error', FALSE);
|
||||
return "";
|
||||
}
|
||||
|
||||
$num_deleted = db_delete('booking_variety_timeslots')
|
||||
->condition('tid', $values['tid'])
|
||||
->execute();
|
||||
$num_deleted = db_delete('booking_variety_timeslots')
|
||||
->condition('tid', $values['tid'])
|
||||
->execute();
|
||||
|
||||
$message = t("Successfully deleted !num row(s), corresponding to variety session timeslot '!desc'",
|
||||
array('!num' => $num_deleted, '!desc' => $values['booking_variety_time_descrip']));
|
||||
drupal_set_message($message, $type = 'status');
|
||||
}
|
||||
else
|
||||
{
|
||||
//verify that booking_eid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $values['tid'])) {
|
||||
drupal_set_message("Error: Invalid variety session timeslot ID supplied. Unable to update entry.", 'error', FALSE);
|
||||
return "";
|
||||
}
|
||||
$message = t("Successfully deleted !num row(s), corresponding to variety session timeslot '!desc'",
|
||||
array('!num' => $num_deleted, '!desc' => $values['booking_variety_time_descrip']));
|
||||
drupal_set_message($message, $type = 'status');
|
||||
}
|
||||
else
|
||||
{
|
||||
//verify that booking_eid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $values['tid'])) {
|
||||
drupal_set_message("Error: Invalid variety session timeslot ID supplied. Unable to update entry.", 'error', FALSE);
|
||||
return "";
|
||||
}
|
||||
|
||||
//update the event
|
||||
db_update('booking_variety_timeslots')
|
||||
->fields(array (
|
||||
'booking_eventid' => $event->eid,
|
||||
'booking_variety_time_descrip' => $values['booking_variety_time_descrip'],
|
||||
'booking_variety_status' => $values['booking_variety_status'] == 1 ? 1 : 0,
|
||||
'booking_variety_start' => _datetime_array_to_ts($values['booking_variety_start']),
|
||||
'booking_variety_end' => _datetime_array_to_ts($values['booking_variety_end']),
|
||||
))
|
||||
->condition('tid', $values['tid'])
|
||||
->execute();
|
||||
}
|
||||
//update the event
|
||||
db_update('booking_variety_timeslots')
|
||||
->fields(array (
|
||||
'booking_eventid' => $event->eid,
|
||||
'booking_variety_time_descrip' => $values['booking_variety_time_descrip'],
|
||||
'booking_variety_status' => $values['booking_variety_status'] == 1 ? 1 : 0,
|
||||
'booking_variety_start' => _datetime_array_to_ts($values['booking_variety_start']),
|
||||
'booking_variety_end' => _datetime_array_to_ts($values['booking_variety_end']),
|
||||
))
|
||||
->condition('tid', $values['tid'])
|
||||
->execute();
|
||||
}
|
||||
|
||||
$form_state['redirect'] = array('admin/config/booking/variety');
|
||||
$form_state['redirect'] = array('admin/config/booking/variety');
|
||||
}
|
||||
|
||||
function booking_variety_create_session_form($node, &$form_state, $timeslot_id = 0)
|
||||
{
|
||||
global $event;
|
||||
$form = array ();
|
||||
$prefix = "<p>Add a new variety session to the specified variety session timeslot for the bookings module.</p>";
|
||||
$data = $node;
|
||||
global $event;
|
||||
$form = array ();
|
||||
$prefix = "<p>Add a new variety session to the specified variety session timeslot for the bookings module.</p>";
|
||||
$data = $node;
|
||||
|
||||
//verify that $editid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $timeslot_id)) {
|
||||
drupal_set_message("Error: Invalid variety ID supplied. Unable to update variety session information.", 'error', FALSE);
|
||||
drupal_goto('admin/config/booking/variety');
|
||||
return "";
|
||||
}
|
||||
//verify that $editid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $timeslot_id)) {
|
||||
drupal_set_message("Error: Invalid variety ID supplied. Unable to update variety session information.", 'error', FALSE);
|
||||
drupal_goto('admin/config/booking/variety');
|
||||
return "";
|
||||
}
|
||||
|
||||
/*
|
||||
$data = db_select ('booking_variety_timeslots', 'v')
|
||||
->condition('v.tid', $editid, '=')
|
||||
->fields('v')
|
||||
->execute()
|
||||
->fetchObject();
|
||||
*/
|
||||
/*
|
||||
$data = db_select ('booking_variety_timeslots', 'v')
|
||||
->condition('v.tid', $editid, '=')
|
||||
->fields('v')
|
||||
->execute()
|
||||
->fetchObject();
|
||||
*/
|
||||
|
||||
//add this to the form in a hidden field so we can update the right event
|
||||
$form['tid'] = array (
|
||||
'#type' => 'hidden',
|
||||
'#value' => $timeslot_id,
|
||||
);
|
||||
//add this to the form in a hidden field so we can update the right event
|
||||
$form['tid'] = array (
|
||||
'#type' => 'hidden',
|
||||
'#value' => $timeslot_id,
|
||||
);
|
||||
|
||||
$form['booking_variety_descrip'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('The name of the variety session to add to this timeslot'),
|
||||
'#size' => 60,
|
||||
'#maxlength' => 150,
|
||||
'#required' => TRUE,
|
||||
'#default_value' => !empty($data->booking_variety_descrip) ? $data->booking_variety_descrip : '',
|
||||
);
|
||||
$form['booking_variety_descrip'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('The name of the variety session to add to this timeslot'),
|
||||
'#size' => 60,
|
||||
'#maxlength' => 150,
|
||||
'#required' => TRUE,
|
||||
'#default_value' => !empty($data->booking_variety_descrip) ? $data->booking_variety_descrip : '',
|
||||
);
|
||||
|
||||
$form['booking_variety_status'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Make this variety session active?'),
|
||||
'#default_value' => !empty($data->booking_variety_status) ? $data->booking_variety_status : '',
|
||||
);
|
||||
$form['booking_variety_status'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Make this variety session active?'),
|
||||
'#default_value' => !empty($data->booking_variety_status) ? $data->booking_variety_status : '',
|
||||
);
|
||||
|
||||
$form['booking_variety_maxsize'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('The maximum number of people permitted in this variety session'),
|
||||
'#size' => 5,
|
||||
'#maxlength' => 5,
|
||||
'#required' => TRUE,
|
||||
'#default_value' => !empty($data->booking_variety_maxsize) ? $data->booking_variety_maxsize : '0',
|
||||
);
|
||||
$form['booking_variety_maxsize'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('The maximum number of people permitted in this variety session'),
|
||||
'#size' => 5,
|
||||
'#maxlength' => 5,
|
||||
'#required' => TRUE,
|
||||
'#default_value' => !empty($data->booking_variety_maxsize) ? $data->booking_variety_maxsize : '0',
|
||||
);
|
||||
|
||||
$form['submit'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Create'),
|
||||
);
|
||||
$form['submit'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Create'),
|
||||
);
|
||||
|
||||
return array (
|
||||
'first_para' => array (
|
||||
'#type' => 'markup',
|
||||
'#markup' => $prefix,
|
||||
),
|
||||
'form' => $form,
|
||||
);
|
||||
return array (
|
||||
'first_para' => array (
|
||||
'#type' => 'markup',
|
||||
'#markup' => $prefix,
|
||||
),
|
||||
'form' => $form,
|
||||
);
|
||||
}
|
||||
|
||||
function booking_variety_create_session_form_submit($form, &$form_state) {
|
||||
global $event;
|
||||
$values = $form_state['input'];
|
||||
global $event;
|
||||
$values = $form_state['input'];
|
||||
|
||||
db_insert('booking_variety_sessions')
|
||||
->fields(array(
|
||||
'booking_eventid' => $event->eid,
|
||||
'booking_variety_timeslot_id' => $values['tid'],
|
||||
'booking_variety_status' => $values['booking_variety_status'] == 1 ? 1 : 0,
|
||||
'booking_variety_descrip' => $values['booking_variety_descrip'],
|
||||
'booking_variety_maxsize' => $values['booking_variety_maxsize'],
|
||||
'booking_variety_regncount' => 0,
|
||||
))
|
||||
->execute();
|
||||
db_insert('booking_variety_sessions')
|
||||
->fields(array(
|
||||
'booking_eventid' => $event->eid,
|
||||
'booking_variety_timeslot_id' => $values['tid'],
|
||||
'booking_variety_status' => $values['booking_variety_status'] == 1 ? 1 : 0,
|
||||
'booking_variety_descrip' => $values['booking_variety_descrip'],
|
||||
'booking_variety_maxsize' => $values['booking_variety_maxsize'],
|
||||
'booking_variety_regncount' => 0,
|
||||
))
|
||||
->execute();
|
||||
|
||||
$form_state['redirect'] = array('admin/config/booking/variety');
|
||||
$form_state['redirect'] = array('admin/config/booking/variety');
|
||||
}
|
||||
|
||||
function booking_variety_list_session_form($node, &$form_state, $timeslot_id = 0)
|
||||
{
|
||||
global $event;
|
||||
$form = array ();
|
||||
$options = array ();
|
||||
$data = $node;
|
||||
global $event;
|
||||
$form = array ();
|
||||
$options = array ();
|
||||
$data = $node;
|
||||
|
||||
//verify that $editid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $timeslot_id)) {
|
||||
drupal_set_message("Error: Invalid variety ID supplied. Unable to select variety session information.", 'error', FALSE);
|
||||
drupal_goto('admin/config/booking/variety');
|
||||
return "";
|
||||
}
|
||||
//verify that $editid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $timeslot_id)) {
|
||||
drupal_set_message("Error: Invalid variety ID supplied. Unable to select variety session information.", 'error', FALSE);
|
||||
drupal_goto('admin/config/booking/variety');
|
||||
return "";
|
||||
}
|
||||
|
||||
$prefix = t("<p>!link</p>",
|
||||
array ('!link' => l('Add New Variety Session', "admin/config/booking/variety/$timeslot_id/session/create")));
|
||||
$prefix = t("<p>!link</p>",
|
||||
array ('!link' => l('Add New Variety Session', "admin/config/booking/variety/$timeslot_id/session/create")));
|
||||
|
||||
$query = db_select ('booking_variety_sessions', 'v');
|
||||
$query->join('booking_variety_timeslots', 't', 'v.booking_variety_timeslot_id = t.tid');
|
||||
$query->condition('v.booking_variety_timeslot_id', $timeslot_id, '=')
|
||||
->fields('v')
|
||||
->fields('t', array('booking_variety_time_descrip'));
|
||||
$result = $query->execute();
|
||||
$query = db_select ('booking_variety_sessions', 'v');
|
||||
$query->join('booking_variety_timeslots', 't', 'v.booking_variety_timeslot_id = t.tid');
|
||||
$query->condition('v.booking_variety_timeslot_id', $timeslot_id, '=')
|
||||
->fields('v')
|
||||
->fields('t', array('booking_variety_time_descrip'));
|
||||
$result = $query->execute();
|
||||
|
||||
//watchdog('booking', 'Variety session query: @info', array ('@info' => (string)$query));
|
||||
//watchdog('booking', 'Variety session query: @info', array ('@info' => (string)$query));
|
||||
|
||||
$header = array (
|
||||
'variety_timeslot' => t('Variety Timeslot'),
|
||||
'booking_variety_descrip' => t('Variety Session Description'),
|
||||
'booking_variety_status' => t('Status'),
|
||||
'booking_variety_maxsize' => t('Maximum Capacity'),
|
||||
'booking_variety_regncount' => t('Current Registration Count'),
|
||||
'variety_edit' => t('Edit Session')
|
||||
);
|
||||
$header = array (
|
||||
'variety_timeslot' => t('Variety Timeslot'),
|
||||
'booking_variety_descrip' => t('Variety Session Description'),
|
||||
'booking_variety_status' => t('Status'),
|
||||
'booking_variety_maxsize' => t('Maximum Capacity'),
|
||||
'booking_variety_regncount' => t('Current Registration Count'),
|
||||
'variety_edit' => t('Edit Session')
|
||||
);
|
||||
|
||||
foreach($result as $data)
|
||||
{
|
||||
$options[$data->vid] = array
|
||||
(
|
||||
'variety_timeslot' => $data->booking_variety_time_descrip,
|
||||
'booking_variety_descrip' => $data->booking_variety_descrip,
|
||||
'booking_variety_status' => $data->booking_variety_status == 1 ? 'Active' : 'Inactive',
|
||||
'booking_variety_maxsize' => $data->booking_variety_maxsize,
|
||||
'booking_variety_regncount' => $data->booking_variety_regncount,
|
||||
'variety_edit' => l('Edit Session', t('admin/config/booking/variety/session/!vid/edit', array('!vid' => $data->vid))),
|
||||
);
|
||||
}
|
||||
foreach($result as $data)
|
||||
{
|
||||
$options[$data->vid] = array
|
||||
(
|
||||
'variety_timeslot' => $data->booking_variety_time_descrip,
|
||||
'booking_variety_descrip' => $data->booking_variety_descrip,
|
||||
'booking_variety_status' => $data->booking_variety_status == 1 ? 'Active' : 'Inactive',
|
||||
'booking_variety_maxsize' => $data->booking_variety_maxsize,
|
||||
'booking_variety_regncount' => $data->booking_variety_regncount,
|
||||
'variety_edit' => l('Edit Session', t('admin/config/booking/variety/session/!vid/edit', array('!vid' => $data->vid))),
|
||||
);
|
||||
}
|
||||
|
||||
$form['table'] = array (
|
||||
'#type' => 'tableselect',
|
||||
'#header' => $header,
|
||||
'#options' => $options,
|
||||
'#multiple' => false,
|
||||
);
|
||||
$form['table'] = array (
|
||||
'#type' => 'tableselect',
|
||||
'#header' => $header,
|
||||
'#options' => $options,
|
||||
'#multiple' => false,
|
||||
);
|
||||
|
||||
return array (
|
||||
'first_para' => array (
|
||||
'#type' => 'markup',
|
||||
'#markup' => $prefix,
|
||||
),
|
||||
'form' => $form,
|
||||
);
|
||||
return array (
|
||||
'first_para' => array (
|
||||
'#type' => 'markup',
|
||||
'#markup' => $prefix,
|
||||
),
|
||||
'form' => $form,
|
||||
);
|
||||
}
|
||||
|
||||
function booking_variety_edit_session_form()
|
||||
@@ -377,66 +379,59 @@ function booking_varietysessions_csv_report($timeslot_id) {
|
||||
global $event;
|
||||
$data = array();
|
||||
|
||||
//verify that $group_id is a number
|
||||
if (! preg_match('/^[0-9]+$/', $timeslot_id)) {
|
||||
drupal_set_message("Error: Invalid variety session timeslot ID '" . $group_id . "' supplied.", 'error', FALSE);
|
||||
drupal_goto('admin/config/booking/variety');
|
||||
return "";
|
||||
}
|
||||
//verify that $group_id is a number
|
||||
if (! preg_match('/^[0-9]+$/', $timeslot_id)) {
|
||||
drupal_set_message("Error: Invalid variety session timeslot ID '" . $group_id . "' supplied.", 'error', FALSE);
|
||||
drupal_goto('admin/config/booking/variety');
|
||||
return "";
|
||||
}
|
||||
|
||||
// TODO - UPDATE FROM HERE ON!
|
||||
//retrieve the sessions for the specified timeslot
|
||||
$variety_sessions = db_query("SELECT * FROM {booking_variety_sessions} WHERE booking_eventid = :eid and booking_variety_timeslot_id = :tid",
|
||||
array(':eid' => $event->eid, ':tid' => $timeslot_id))
|
||||
->fetchObject();
|
||||
|
||||
//retrieve the name of the study group for the specified ID
|
||||
$variety_session_timeslot = db_query("SELECT * FROM {booking_variety_timeslots} WHERE booking_eventid = :eid and tid = :tid",
|
||||
array(':eid' => $event->eid, ':tid' => $timeslot_id))
|
||||
->fetchObject();
|
||||
|
||||
if (! $variety_session_timeslot) {
|
||||
drupal_set_message("Error: Could not find matching variety session timeslot. Unable to view session membership.", 'error', FALSE);
|
||||
drupal_goto('admin/config/booking/variety');
|
||||
return "";
|
||||
}
|
||||
if (! $variety_sessions) {
|
||||
drupal_set_message("Error: Could not find matching variety session timeslot. Unable to view session membership.", 'error', FALSE);
|
||||
drupal_goto('admin/config/booking/variety');
|
||||
return "";
|
||||
}
|
||||
|
||||
//set options for the CSV file
|
||||
$name = 'bookings-variety-sessions-' . format_date(time(), 'custom', 'Y-m-d-His');
|
||||
$filename = file_directory_temp() . '/' . $name;
|
||||
$csv = '';
|
||||
$delimiter = ',';
|
||||
$enclosure = '"';
|
||||
$encloseAll = true;
|
||||
$nullToMysqlNull = true;
|
||||
$name = 'bookings-variety-sessions-' . format_date(time(), 'custom', 'Y-m-d-His');
|
||||
$filename = file_directory_temp() . '/' . $name;
|
||||
$csv = '';
|
||||
$delimiter = ',';
|
||||
$enclosure = '"';
|
||||
$encloseAll = true;
|
||||
$nullToMysqlNull = true;
|
||||
$delimiter_esc = preg_quote($delimiter, '/');
|
||||
$enclosure_esc = preg_quote($enclosure, '/');
|
||||
|
||||
//get the list of study group session memberships
|
||||
$session_members_query = db_query("SELECT m.*, p.* FROM {booking_studygroup_mapping} m
|
||||
inner join {booking_person} p on p.nid = m.booking_node_id
|
||||
WHERE m.booking_studygroup_id = :sid ORDER BY m.booking_session_id, m.booking_studygroup_role DESC, p.booking_lastname",
|
||||
array(':sid' => $group_id));
|
||||
$session_members_query = db_query("SELECT r.*, p.* FROM {booking_variety_regn} r
|
||||
inner join {booking_person} p on p.nid = r.booking_person_nid
|
||||
WHERE p.booking_eventid = :eid ORDER BY r.brid",
|
||||
array(':eid' => $event->eid));
|
||||
$session_members = $session_members_query->fetchAll();
|
||||
|
||||
watchdog('booking_debug', 'booking_varietysessions_csv_report session members: <pre>@info</pre>', array('@info' => print_r( $session_members, true)));
|
||||
|
||||
//generate the row data
|
||||
foreach ($session_members as $member) {
|
||||
if (! isset($data[$member->booking_session_id])) {
|
||||
$data[$member->booking_session_id] = array();
|
||||
}
|
||||
// lookup the name and role for this entry in the study group session and optionally include age
|
||||
if (variable_get('booking_studygroup_csv_ages', 0) == 1) {
|
||||
$text = array($member->booking_firstname, $member->booking_lastname, '[' . _booking_get_age_years($member->booking_dob) .']');
|
||||
}
|
||||
else {
|
||||
$text = array($member->booking_firstname, $member->booking_lastname);
|
||||
}
|
||||
//add their role if they're leading/helping etc
|
||||
if ($member->booking_studygroup_role > 0) {
|
||||
array_push($text, '(' . _booking_studygroup_role_lookup($member->booking_studygroup_role) . ')');
|
||||
}
|
||||
//also tag committee members
|
||||
if ($member->booking_committee_member == 'Y') {
|
||||
array_push($text, '(committee)');
|
||||
$session_ids = drupal_json_decode($member->booking_variety_ids);
|
||||
watchdog('booking_debug', 'booking_varietysessions_csv_report person session ids: <pre>@info</pre>', array('@info' => print_r( $session_ids, true)));
|
||||
|
||||
//get the session id that matches our timeslot
|
||||
$sid = $session_ids[$timeslot_id];
|
||||
|
||||
if (! isset($data[$sid])) {
|
||||
$data[$sid] = array();
|
||||
}
|
||||
$text = array($member->booking_firstname, $member->booking_lastname);
|
||||
|
||||
//add the spaces and put this element in the right array
|
||||
$data[$member->booking_session_id][] = implode(' ', $text);
|
||||
$data[$sid][] = implode(' ', $text);
|
||||
|
||||
}
|
||||
//watchdog('booking_debug', "<pre>Study Group CSV Report\n@info</pre>", array('@info' => print_r( $data_array, true)));
|
||||
@@ -448,16 +443,11 @@ function booking_varietysessions_csv_report($timeslot_id) {
|
||||
foreach ($header_array as $column) {
|
||||
$maximums[] = count($data[$column]);
|
||||
//make the column headings a bit more user friendly
|
||||
if ($group->booking_is_readinggroup == 'Y') {
|
||||
$column_headings[] = _booking_readinggroup_colour_lookup($column);
|
||||
}
|
||||
else {
|
||||
$column_headings[] = "Session " . $column;
|
||||
}
|
||||
$column_headings[] = $variety_sessions[$column]->booking_variety_descrip;
|
||||
}
|
||||
|
||||
//add the column headings to the CSV
|
||||
$header = implode( $delimiter, $column_headings );
|
||||
$header = implode($delimiter, $column_headings);
|
||||
$csv .= $header . "\n";
|
||||
|
||||
//generate each row for the CSV
|
||||
@@ -482,6 +472,6 @@ function booking_varietysessions_csv_report($timeslot_id) {
|
||||
//output the CSV to the browser
|
||||
drupal_add_http_header("Content-type", "application/octet-stream; charset=utf-8");
|
||||
drupal_add_http_header("Content-Disposition", "attachment; filename=" . $name . ".csv");
|
||||
print $csv;
|
||||
print $csv;
|
||||
exit(0);
|
||||
}
|
Reference in New Issue
Block a user