diff --git a/booking.module b/booking.module index 0d7b71b..61cf793 100644 --- a/booking.module +++ b/booking.module @@ -111,6 +111,12 @@ function booking_permission() { 'edit study groups' => array( 'title' => t('Edit study groups'), ), + 'view room allocations' => array( + 'title' => t('View Room Allocations'), + ), + 'edit room allocations' => array( + 'title' => t('Edit Room Allocations'), + ), 'create_travel_forms' => array( 'title' => t('Create a new travel form entry'), ), @@ -383,15 +389,25 @@ function booking_menu() { 'type' => MENU_LOCAL_ACTION, ); } - + //configure rooms - $items['admin/booking/rooms/assign'] = array( + $items['admin/booking/rooms'] = array( + 'title' => 'View Rooms', + 'description' => 'View Room Locations', + 'page callback' => 'booking_room_view_summary', + 'access arguments' => array("view room allocations"), + 'type' => MENU_NORMAL_ITEM, + ); + + + $items['admin/booking/rooms/%/assign'] = array( 'title' => 'Assign Rooms', 'description' => 'Assign attendees to rooms', 'page callback' => 'drupal_get_form', - 'page arguments' => array('booking_rooms_allocate_form'), - 'access arguments' => array('edit bookings'), - 'type' => MENU_NORMAL_ITEM, + 'page arguments' => array('booking_rooms_allocate_form', 3), + //'page arguments' => array('booking_rooms_allocate_form'), + 'access arguments' => array('edit room allocations'), + //'type' => MENU_NORMAL_ITEM, ); diff --git a/booking.register.inc b/booking.register.inc index 4c2c5a8..624fe59 100644 --- a/booking.register.inc +++ b/booking.register.inc @@ -1093,8 +1093,8 @@ function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE) $query->fields('p') ->fields('t') ->fields('pr', array('booking_price', 'booking_price_descrip','booking_late_price')) - ->fields('rm', array('booking_roomid', 'booking_room_bedtype')) - ->fields('r', array('rid','booking_room_location_id', 'booking_room_number')); + ->fields('rm', array('booking_room_bedtype')) + ->fields('r', array('booking_room_location_id', 'booking_room_number')); //now add the study group fields if applicable if (variable_get('booking_enable_studygroups', 0) == 1) diff --git a/booking.reports.inc b/booking.reports.inc index 67573f8..77d511e 100644 --- a/booking.reports.inc +++ b/booking.reports.inc @@ -560,6 +560,18 @@ function booking_csv_report() { $output[] = _booking_studygroup_role_lookup($value); continue; } + + //room location + if ($key == 'booking_room_location_id') { + $output[] = _booking_room_location_lookup($value); + continue; + } + + //room bed type + if ($key == 'booking_room_bedtype') { + $output[] = _booking_room_bedtype_lookup($value); + continue; + } //add in the amount owing using the nid as the key if ($key == 'nid') diff --git a/booking.rooms.inc b/booking.rooms.inc index 200ce5b..66c17c4 100644 --- a/booking.rooms.inc +++ b/booking.rooms.inc @@ -5,10 +5,45 @@ * Functions to handle room allocation and administration for the booking module */ +/** + * Function for listing the room locations links to view each one and assign people to rooms + */ +function booking_room_view_summary() { + + global $event; + $output = ""; + $header = array('Location', 'Assign Attendees', 'View Rooms For Location'); + $attributes = array('style' => 'max-width:30%'); + $rows = array(); + + //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("
Loading existing room allocations:\n@info", array('@info' => print_r( $room_mapping, true))); + //watchdog('booking', "
Loading existing room allocations:\n@info", array('@info' => print_r( $room_mapping, true))); //attach the custom css $form['#attached']['css'] = array( @@ -203,6 +252,8 @@ function booking_rooms_allocate_form($node, &$form_state) { { foreach ($room_mapping as $mapping) { + //check that the room id in the mapping table matches the room that we're currently adding to the table + //and also the bed type matches the first dimension in the array if ($mapping->booking_roomid == $data->rid && $mapping->booking_room_bedtype == $i) { $existing_beds[$i][] = $mapping->booking_nodeid; @@ -210,8 +261,7 @@ function booking_rooms_allocate_form($node, &$form_state) { } } - watchdog('booking', "
Existing bed mappings:\n@info", array('@info' => print_r( $existing_beds, true))); - + //watchdog('booking', "
Existing bed mappings:\n@info", array('@info' => print_r( $existing_beds, true))); //create a row that contains just the room location and number $row = _booking_clone_array($default_row); @@ -284,15 +334,15 @@ function booking_rooms_allocate_form($node, &$form_state) { '#type' => 'tableselect', '#header' => $header, '#options' => $options, - '#empty' => t('No attendees found.'), + '#empty' => t('No rooms found for this room location id.'), ); //so we can access the dropdown elements - $form['booking_room_singlebed'] = array( '#type' => 'value', ); - $form['booking_room_queenbed_p1'] = array( '#type' => 'value', ); - $form['booking_room_queenbed_p2'] = array( '#type' => 'value', ); - $form['booking_room_doublebed_p1'] = array( '#type' => 'value', ); - $form['booking_room_doublebed_p2'] = array( '#type' => 'value', ); + $form['booking_room_singlebed'] = array( '#type' => 'value' ); + $form['booking_room_queenbed_p1'] = array( '#type' => 'value' ); + $form['booking_room_queenbed_p2'] = array( '#type' => 'value' ); + $form['booking_room_doublebed_p1'] = array( '#type' => 'value' ); + $form['booking_room_doublebed_p2'] = array( '#type' => 'value' ); $form['submit'] = array ( '#type' => 'submit', @@ -310,10 +360,10 @@ function booking_rooms_allocate_form($node, &$form_state) { */ function booking_rooms_allocate_form_submit($form, &$form_state) { global $event; - $counter = 0; - $checkboxes = $form_state['values']['table']; - //$singlebed_ids = $form_state['values']['booking_room_singlebed']; - $values = $form_state['input']; + + //query for existing room allocations + $room_mapping_query = db_query("SELECT * FROM {booking_room_mapping} WHERE booking_eventid = :eid", array(':eid' => $event->eid)); + $room_mapping = $room_mapping_query->fetchAllAssoc('booking_nodeid'); $bed_inputs = array( 'booking_room_singlebed' => 1, @@ -336,7 +386,7 @@ function booking_rooms_allocate_form_submit($form, &$form_state) { continue; //go through each room - foreach($form_state['values'][$type] as $key => $value) + foreach($form_state['values'][$type] as $room => $value) { //go through each bed foreach ($value as $index => $nid) @@ -344,23 +394,44 @@ function booking_rooms_allocate_form_submit($form, &$form_state) { //if this is actually a person to process if ($nid > 0) { - drupal_set_message(t('Assigning person id !id to a !type bed in room id !room.', - array('!id' => $nid, '!room' => $key, '!type' => $type_id))); - - //TODO: Check there isn't already a mapping for this person - - $result = db_insert('booking_room_mapping') - ->fields(array( - 'booking_roomid' => $key, - 'booking_eventid' => $event->eid, - 'booking_nodeid' => $nid, - 'booking_room_bedtype' => $type_id, - )) - ->execute(); + if (empty($room_mapping[$nid])) + { + drupal_set_message(t('Assigning person id !id to a type !type bed in room id !room.', + array('!id' => $nid, '!room' => $room, '!type' => $type_id))); + + $result = db_insert('booking_room_mapping') + ->fields(array( + 'booking_roomid' => $room, + 'booking_eventid' => $event->eid, + 'booking_nodeid' => $nid, + 'booking_room_bedtype' => $type_id, + )) + ->execute(); + } + elseif ((!empty($room_mapping[$nid])) && $room_mapping[$nid]->booking_roomid != $room) + { + drupal_set_message(t('Changing person id !id from old room !oldroom to new room !room with type !type bed.', + array('!id' => $nid, '!room' => $room, '!type' => $type_id, '!oldroom' => $room_mapping[$nid]->booking_roomid))); + + db_update('booking_room_mapping') + ->fields(array( + 'booking_roomid' => $room, + 'booking_room_bedtype' => $type_id, + )) + ->condition('booking_eventid', $event->eid) + ->condition('booking_nodeid', $nid) + ->execute(); + + } + else + { + //drupal_set_message(t('Person id !id already has some other room allocation.', + // array('!id' => $nid, '!room' => $room, '!type' => $type_id))); + } - } - } //each bed - } //each room - } //each bed type + } //valid node id check + } //each bed + } //each room + } //each bed type } \ No newline at end of file diff --git a/booking.studygroups.inc b/booking.studygroups.inc index f357ff2..e9d7d33 100644 --- a/booking.studygroups.inc +++ b/booking.studygroups.inc @@ -5,6 +5,39 @@ * Admin pages for calculating study group session membership */ +/** + * Function for listing the study groups and links to view each one + */ +function booking_studygroups_view_summary() { + + global $event; + $output = ""; + $header = array('Link','Study Group', 'Session Count', 'Select Leaders'); + $attributes = array('style' => 'max-width:30%'); + + //get study groups + $query = db_select('booking_studygroup_list', 's') + ->fields('s') + ->condition('s.booking_eventid', $event->eid, '='); + $result = $query->execute(); + + foreach ($result as $group) { + $rows[] = array( + l(t('View', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/view', array('!id' => $group->sid))), + $group->booking_studygroup_descrip, + $group->booking_num_group_sessions, + l(t('Edit Leaders/Helpers', array('!id' => $group->sid)), t('admin/booking/studygroups/!id/selectleaders', array('!id' => $group->sid))), + ); + } + + //output everything + $output .= t("