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