diff --git a/booking.install b/booking.install index 39077c2..9600a6c 100644 --- a/booking.install +++ b/booking.install @@ -465,6 +465,23 @@ function booking_update_7225() { db_add_field('booking_studygroup_list', 'booking_is_readinggroup', $spec); } +/** +* Add table for defininig room location layouts rather than hard coding +*/ +function booking_update_7226() { + //NOTE: This doesn't need a reference to the current event, since it is not anticipated that successive events will have a different room layout + + $booking_room_locations = array( + 'fields' => array( + 'lid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'), + 'booking_roomlocation_descrip' => array('type' => 'varchar', 'length' => '500', 'not null' => FALSE), + 'booking_roomlocation_active' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE, 'default' => 'Y'), + ), + 'primary key' => array('lid'), + ); + + db_create_table('booking_room_locations', $booking_room_locations); +} /** * Implementation of hook_install(). @@ -819,6 +836,15 @@ function booking_schema() { 'primary key' => array('rid'), ); + $schema['booking_room_locations'] = array( + 'fields' => array( + 'lid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'), + 'booking_roomlocation_descrip' => array('type' => 'varchar', 'length' => '500', 'not null' => FALSE), + 'booking_roomlocation_active' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE, 'default' => 'N'), + ), + 'primary key' => array('lid'), + ); + $schema['booking_room_mapping'] = array( 'fields' => array( 'mid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'), diff --git a/booking.module b/booking.module index 20ee749..c7a4a64 100644 --- a/booking.module +++ b/booking.module @@ -64,6 +64,8 @@ module_load_include('inc', 'booking', 'booking.studygroups_admin'); module_load_include('inc', 'booking', 'booking.travel'); // Load the include for managing room bookings and definitions module_load_include('inc', 'booking', 'booking.rooms'); +// Load the include for room layout definitions +module_load_include('inc', 'booking', 'booking.rooms_admin'); function booking_init() { date_default_timezone_set(TIMEZONE); @@ -466,8 +468,27 @@ function booking_menu() { 'page callback' => 'drupal_get_form', 'page arguments' => array('booking_rooms_view_definitions'), 'access arguments' => array('administer site configuration'), - //'type' => MENU_LOCAL_TASK, + 'type' => MENU_NORMAL_ITEM, ); + + $items['admin/config/booking/rooms/locations/add'] = array( + 'title' => 'Add Room Location Definition', + 'description' => 'Add Room Location Definition', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('booking_roomlocation_define_form', true), + 'access arguments' => array('administer site configuration'), + 'type' => MENU_LOCAL_ACTION, + ); + + $items['admin/config/booking/rooms/locations/%/edit'] = array( + 'title' => 'Edit Room Location Definition', + 'description' => 'Edit Room Location Definition', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('booking_roomlocation_define_form', false, 5), + 'access arguments' => array('administer site configuration'), + //'type' => MENU_LOCAL_ACTION, + ); + $items['admin/config/booking/rooms/create'] = array( 'title' => 'Add New Room Definition', 'description' => 'Add room definition for the Event Booking module', diff --git a/booking.rooms.inc b/booking.rooms.inc index 471d733..db37ff0 100644 --- a/booking.rooms.inc +++ b/booking.rooms.inc @@ -8,6 +8,7 @@ /** * Function for listing the room locations links to view each one and assign people to rooms */ +/* function booking_room_view_summary() { global $event; @@ -39,7 +40,7 @@ function booking_room_view_summary() { return $output; } - +*/ /** * Function for viewing a printable format of who belongs to which study group diff --git a/booking.rooms_admin.inc b/booking.rooms_admin.inc new file mode 100644 index 0000000..791c70e --- /dev/null +++ b/booking.rooms_admin.inc @@ -0,0 +1,233 @@ + 'max-width:60%'); + $rows = array(); + + //get study groups + $query = db_select('booking_room_locations', 'l') + ->fields('l') + ->condition('l.booking_roomlocation_active', 'Y', '='); + $result = $query->execute(); + /* + //get room definitions + $room_definitions = _booking_room_location_lookup(); + //ditch the first element which is empty + array_shift($room_definitions); + $i = 1; + */ + foreach ($room_definitions as $room) { + $rows[] = array( + $room, + l(t('Allocate Rooms'), t('admin/booking/rooms/!id/assign', array('!id' => $i))), + l(t('View Rooms'), t('admin/booking/rooms/!id/view', array('!id' => $i))), + ); + + $i++; + } + + //output everything + $output .= t("

!event Room Locations

", array('!event' => $event->booking_eventname)); + $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes)); + + return $output; + +} + + +/** + * Form to view or add a studygroup definition + */ +function booking_roomlocation_define_form($node, &$form_state, $create, $editid = 0) +{ + $form = array (); + $prefix = "

Add a new study group definition

"; + + if ($create == true) + { + drupal_set_title('Add Study Group'); + $data = $node; + watchdog('booking', 'Creating new study group: @info', array ('@info' => var_export($node, TRUE))); + } + else + { + drupal_set_title('Edit Study Group'); + //verify that $editid is a number + if (! preg_match('/^[0-9]+$/', $editid)) { + drupal_set_message("Error: Invalid study group ID supplied. Unable to edit study group definition.", 'error', FALSE); + drupal_goto('admin/booking/config/studygroups'); + return ""; + } + + $data = db_query("SELECT * FROM {booking_studygroup_list} WHERE sid = :id", + array(':id' => $editid)) + ->fetchObject(); + $prefix = t("

Update the "!event " study group definition.

", array('!event' => $data->booking_studygroup_descrip)); + //add this to the form in a hidden field so we can update the right price + $form['booking_sid'] = array ( + '#type' => 'hidden', + '#value' => $editid, + ); + watchdog('booking', 'Editing study group definition: @info', + array ('@info' => var_export($data, TRUE))); + } + + + if(!isset($form_state['storage']['confirm'])) + { + $form['booking_studygroup_descrip'] = array ( + '#type' => 'textfield', + '#title' => t('Description of this study group (eg Monday)'), + '#size' => 60, + '#maxlength' => 150, + '#required' => TRUE, + '#default_value' => !empty($data->booking_studygroup_descrip) ? $data->booking_studygroup_descrip : '', + ); + + $form['booking_num_group_sessions'] = array ( + '#type' => 'textfield', + '#title' => t('The number of sessions this study group will have'), + '#size' => 5, + '#maxlength' => 10, + '#required' => TRUE, + '#default_value' => !empty($data->booking_num_group_sessions) ? $data->booking_num_group_sessions : '', + ); + + $form['booking_is_readinggroup'] = array ( + '#type' => 'radios', + '#title' => t('Reading group?'), + '#description' => t('Select whether this study group definition is for a reading group. Leave as No unless you want team colours associated with this group'), + '#options' => array (0 => t('No'), t('Yes')), + '#default_value' => !empty($data->booking_is_readinggroup) ? ($data->booking_is_readinggroup == 'Y' ? 1 : 0) : 0, + ); + + if ($create == true) + { + $form['submit'] = array + ( + '#type' => 'submit', + '#value' => t('Create Study Group'), + ); + } else { + $form['Update'] = array + ( + '#type' => 'submit', + '#value' => t('Update Study Group'), + ); + $form['Delete'] = array + ( + '#type' => 'submit', + '#value' => t("Delete Study Group Definition"), + ); + } + + return array ( + 'first_para' => array ( + '#type' => 'markup', + '#markup' => $prefix, + ), + 'form' => $form, + ); + } + //confirm delete + else + { + return confirm_form($form, "Are you sure you wish to delete studygroup definition with id " . $editid . "?", + current_path(), NULL, "Delete Study Group Definition"); + } + +} + + +function booking_roomlocation_define_form_submit($form, &$form_state) { + + global $event; + $values = $form_state['input']; + $redirect_path = array('admin/config/booking/studygroups'); + $new_count = 0; + + //get the number of study groups before making this update + $count = db_query("SELECT count(*) as num FROM {booking_studygroup_list} WHERE booking_eventid = :eid", + array(':eid' => $event->eid))->fetchObject(); + + + //watchdog('booking', 'Checkboxes when setting buttons: @info', array ('@info' => var_export($checkboxes, TRUE))); + if ($form_state['values']['op'] == 'Create Study Group') + { + db_insert('booking_studygroup_list') + ->fields(array( + 'booking_eventid' => $event->eid, + 'booking_studygroup_descrip' => $values['booking_studygroup_descrip'], + 'booking_num_group_sessions' => $values['booking_num_group_sessions'], + 'booking_is_readinggroup' => $values['booking_is_readinggroup'] == 1 ? 'Y' : 'N', + )) + ->execute(); + + $new_count = $count->num + 1; + } + //if we're deleting, add the confirmation to the form if it hasn't been defined yet + elseif($form_state['values']['op'] == "Delete Study Group Definition" && (!isset($form_state['storage']['confirm']))) + { + watchdog('booking', "
Studygroup deletion confirmation being set:\n@info
", array('@info' => print_r( $form_state, true))); + $form_state['storage']['confirm'] = TRUE; + $form_state['rebuild'] = TRUE; + + $new_count = $count->num; + } + elseif ($form_state['values']['op'] == 'Delete Study Group Definition') + { + //verify that booking_pid is a number + if (! preg_match('/^[0-9]+$/', $values['booking_sid'])) { + drupal_set_message("Error: Invalid studygroup ID supplied. Unable to delete entry.", 'error', FALSE); + return ""; + } + + //TODO: Confirmation + //return confirm_form($form, "Really delete price?", 'admin/config/booking/prices'); + + $num_deleted = db_delete('booking_studygroup_list') + ->condition('sid', $values['booking_sid']) + ->execute(); + + $new_count = $count->num - 1; + } + elseif ($form_state['values']['op'] == 'Update Study Group') + { + + //verify that booking_sid is a number + if (! preg_match('/^[0-9]+$/', $values['booking_sid'])) { + drupal_set_message("Error: Invalid studygroup ID supplied. Unable to update study group.", 'error', FALSE); + return ""; + } + + //update the study group + db_update('booking_studygroup_list') + ->fields(array ( + 'booking_eventid' => $event->eid, + 'booking_studygroup_descrip' => $values['booking_studygroup_descrip'], + 'booking_num_group_sessions' => $values['booking_num_group_sessions'], + 'booking_is_readinggroup' => $values['booking_is_readinggroup'] == 1 ? 'Y' : 'N', + )) + ->condition('sid', $values['booking_sid']) + ->execute(); + + $new_count = $count->num; + } + + //update the number of study groups now defined + variable_set('booking_studygroup_count', $new_count); + + $form_state['redirect'] = $redirect_path; +} \ No newline at end of file diff --git a/booking.tokens.inc b/booking.tokens.inc index cdf03f0..fca1a96 100644 --- a/booking.tokens.inc +++ b/booking.tokens.inc @@ -506,7 +506,7 @@ function booking_token_info() { ); $info['tokens']['booking']['contact-email'] = array( 'name' => t('Event Contact Email'), - 'description' => t('Contact Address for the current event.') + 'description' => t('Contact email address for the current event.') ); $info['tokens']['booking']['eventdates'] = array( 'name' => t('Event Dates'),