From 654968dc576e8f7d0a4a5afac7d7152ac7d407bd Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Sat, 5 May 2018 12:05:35 +1000 Subject: [PATCH] test variety session edit form --- booking.module | 8 ++-- booking.variety_admin.inc | 99 ++++++++++++++++++++------------------- 2 files changed, 56 insertions(+), 51 deletions(-) diff --git a/booking.module b/booking.module index bcd49b5..f563d07 100644 --- a/booking.module +++ b/booking.module @@ -438,16 +438,16 @@ function booking_menu() { 'title' => 'Add New Variety Session', 'description' => 'Add variety session to the specified timeslot', 'page callback' => 'drupal_get_form', - 'page arguments' => array('booking_variety_create_session_form', 4), + 'page arguments' => array('booking_variety_create_session_form', TRUE, 4), 'access arguments' => array('access administration pages'), 'type' => MENU_CALLBACK, ); - $items['admin/config/booking/variety/session/%/edit'] = array( + $items['admin/config/booking/variety/%/session/%/edit'] = array( 'title' => 'Edit Variety Session', 'description' => 'Edit variety session for the specified timeslot', 'page callback' => 'drupal_get_form', - 'page arguments' => array('booking_variety_edit_session_form', 5), + 'page arguments' => array('booking_variety_edit_session_form', FALSE, 4, 6), 'access arguments' => array('access administration pages'), 'type' => MENU_CALLBACK, ); @@ -633,7 +633,7 @@ function booking_menu() { $items['admin/config/booking/rooms/%/edit'] = array( 'title' => 'Edit Room Definition', 'page callback' => 'drupal_get_form', - 'page arguments' => array('booking_rooms_definition_form', false, 4), + 'page arguments' => array('booking_rooms_definition_form', false, 4), 'access arguments' => array('administer site configuration'), 'type' => MENU_CALLBACK, ); diff --git a/booking.variety_admin.inc b/booking.variety_admin.inc index d75c455..ab112ab 100644 --- a/booking.variety_admin.inc +++ b/booking.variety_admin.inc @@ -6,8 +6,8 @@ * NOTE: This feature is not complete and probably never will be */ -function booking_variety_admin() -{ +function booking_variety_admin() { + global $event; //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 @@ -18,7 +18,8 @@ function booking_variety_admin() // array ('!link' => l('Add New Variety Timeslot', 'admin/config/booking/variety/create'))); $header = array ( - 'tid' => t('Event ID'), + 'eid' => t('Event'), + 'tid' => t('Timeslot ID'), 'booking_variety_time_descrip' => t('Description'), 'booking_variety_status' => t('Status'), 'booking_variety_start' => t('Timeslot Start'), @@ -31,10 +32,9 @@ function booking_variety_admin() $result = db_query("SELECT * from {booking_variety_timeslots}"); - foreach($result as $data) - { - $options[$data->tid] = array - ( + foreach($result as $data) { + $options[$data->tid] = array ( + 'eid' => $event->booking_eventname, 'tid' => $data->tid, 'booking_variety_time_descrip' => $data->booking_variety_time_descrip, 'booking_variety_status' => $data->booking_variety_status, @@ -66,18 +66,15 @@ 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; $form = array (); $prefix = "

Add a new variety session timeslot for the bookings module.

"; - if ($create == true) - { + if ($create == true) { $data = $node; } - else - { + 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); @@ -132,27 +129,24 @@ function booking_variety_timeslot_form($node, &$form_state, $create, $editid = 0 '#date_year_range' => '0:+5' ); - if ($create == true) - { - $form['submit'] = array - ( + if ($create == true) { + $form['submit'] = array ( '#type' => 'submit', '#value' => t('Create'), ); - } else { - $form['Update'] = array - ( + } + else { + $form['Update'] = array ( '#type' => 'submit', '#value' => t('Update'), ); - $form['Delete'] = array - ( + $form['Delete'] = array ( '#type' => 'submit', '#value' => t('Delete'), ); } - return array ( + return array( 'first_para' => array ( '#type' => 'markup', '#markup' => $prefix, @@ -165,8 +159,7 @@ function booking_variety_timeslot_form_submit($form, &$form_state) { global $event; $values = $form_state['input']; - if ($form_state['values']['op'] == 'Create') - { + if ($form_state['values']['op'] == 'Create') { db_insert('booking_variety_timeslots') ->fields(array( 'booking_eventid' => $event->eid, @@ -177,8 +170,7 @@ function booking_variety_timeslot_form_submit($form, &$form_state) { )) ->execute(); } - elseif ($form_state['values']['op'] == 'Delete') - { + 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); @@ -193,8 +185,7 @@ function booking_variety_timeslot_form_submit($form, &$form_state) { array('!num' => $num_deleted, '!desc' => $values['booking_variety_time_descrip'])); drupal_set_message($message, $type = 'status'); } - else - { + 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); @@ -217,20 +208,40 @@ function booking_variety_timeslot_form_submit($form, &$form_state) { $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, $create = TRUE, $timeslot_id = 0, $session_id = 0) { global $event; $form = array (); - $prefix = "

Add a new variety session to the specified variety session timeslot for the bookings module.

"; - $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 ""; - } + $prefix = ""; + if ($create == TRUE) { + $data = $node; + $prefix = "

Add a new variety session to the specified variety session timeslot for the bookings module.

"; + } + else { + //verify that $timeslot_id is a number + if (! preg_match('/^[0-9]+$/', $timeslot_id)) { + drupal_set_message("Error: Invalid timeslot ID supplied. Unable to update specified variety session.", 'error', FALSE); + drupal_goto('admin/config/booking/variety'); + return ""; + } + //verify that $session_id is a number + if (! preg_match('/^[0-9]+$/', $session_id)) { + drupal_set_message("Error: Invalid session ID supplied. Unable to update specified variety session.", 'error', FALSE); + drupal_goto('admin/config/booking/variety'); + return ""; + } + $prefix = t("

Update the variety session defintion.

"); + $data = db_query("SELECT * FROM {booking_variety_sessions} WHERE vid = :id", array(':id' => $session_id)) + ->fetchObject(); + + //add this to the form in a hidden field so we can update the right variety session + $form['booking_session_id'] = array( + '#type' => 'hidden', + '#value' => $session_id, + ); + } + + /* $data = db_select ('booking_variety_timeslots', 'v') ->condition('v.tid', $editid, '=') @@ -285,7 +296,7 @@ function booking_variety_create_session_form($node, &$form_state, $timeslot_id = } function booking_variety_create_session_form_submit($form, &$form_state) { - global $event; + global $event; $values = $form_state['input']; db_insert('booking_variety_sessions') @@ -366,12 +377,6 @@ function booking_variety_list_session_form($node, &$form_state, $timeslot_id = 0 ); } -function booking_variety_edit_session_form() -{ - -} - - /** * Function to generate a CSV file listing the session membership for the specified variety session timeslot */