diff --git a/booking.reports.inc b/booking.reports.inc index 71e43a6..fe2b849 100644 --- a/booking.reports.inc +++ b/booking.reports.inc @@ -38,7 +38,8 @@ function booking_report_summary() { array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'), array('data' => t('Name'), 'field' => 'booking_lastname'), array('data' => t('Booking Status'), 'field' => 'booking_status'), - array('data' => t('Edit Studygroups')), + array('data' => t('Studygroups')), + array('data' => t('Room')), array('data' => t('Email'), 'field' => 'booking_email'), array('data' => t('Payment To Date'), 'field' => 'booking_amount_paid'), array('data' => t('Total Payment Required')), @@ -113,7 +114,8 @@ function booking_report_summary() { t('node/!id/edit', array('!id' => $person->nid)) ), _booking_status_generate($person->booking_status), - l(t('Edit Groups'), t('admin/booking/!id/edit-studygroup', array('!id' => $person->nid))), + l(t('Groups'), t('admin/booking/!id/edit-studygroup', array('!id' => $person->nid))), + l(t('Room'), t('admin/booking/!id/edit-room', array('!id' => $person->nid))), t('!email', array('!email' => $person->booking_email)), t('!payment', array('!payment' => $person->booking_amount_paid)), t('!payment', array('!payment' => $amount_owing == 0 ? $person->booking_total_pay_reqd : _booking_total_due($person))), diff --git a/booking.rooms.inc b/booking.rooms.inc index d5ea3f7..117204c 100644 --- a/booking.rooms.inc +++ b/booking.rooms.inc @@ -198,6 +198,10 @@ function booking_room_edit_form($node, &$form_state, $nid) { $form['submit'] = array ( '#type' => 'submit', '#value' => t('Submit'), + ); + $form['remove'] = array ( + '#type' => 'submit', + '#value' => t('Remove'), ); return array ( @@ -257,19 +261,23 @@ function _booking_get_roomedit_bedtype_options($location_id, $room_num) { $details = db_query("SELECT * FROM {booking_room_definition} WHERE booking_room_location_id = :lid AND booking_room_number = :num", array(':lid' => $location_id, ':num' => $room_num))->fetchObject(); - //go through the bed options - if ($details->booking_room_singlebeds > 0) + //check we got a response from the query + if ($details) { - $bed_options[1] = "Single"; + //go through the bed options + if ($details->booking_room_singlebeds > 0) + { + $bed_options[1] = "Single"; + } + if ($details->booking_room_doublebeds > 0) + { + $bed_options[2] = "Double"; + } + if ($details->booking_room_queenbeds > 0) + { + $bed_options[3] = "Queen"; + } } - if ($details->booking_room_doublebeds > 0) - { - $bed_options[2] = "Double"; - } - if ($details->booking_room_queenbeds > 0) - { - $bed_options[3] = "Queen"; - } //watchdog('booking', "
Room Number Options:\n@info", array('@info' => print_r( $bed_options, true))); @@ -323,39 +331,75 @@ function booking_room_edit_form_validate($form, &$form_state) { function booking_room_edit_form_submit($form, &$form_state) { global $event; $values = $form_state['input']; - - $details = db_query("SELECT * FROM {booking_room_definition} WHERE booking_room_location_id = :lid AND booking_room_number = :num", - array(':lid' => $values['booking_room_location_id'], ':num' => $values['booking_room_number']))->fetchObject(); - - $check = db_query("SELECT * FROM {booking_room_mapping} WHERE booking_eventid = :eid AND booking_nodeid = :nid", - array(':eid' => $event->eid, ':nid' => $values['personid']))->fetchObject(); - if ($check) + //check if we should remove the room allocation + if ($form_state['values']['op'] == 'Remove') { - //there is an existing mapping to update - $result = db_update('booking_room_mapping') - ->fields(array( - 'booking_roomid' => $details->rid, - 'booking_room_bedtype' => $values['booking_room_bedtype'], - )) + $message = t("Removing id !nid from room number !number in location !location", + array('!nid' => $values['personid'], '!location' => $values['booking_room_location_id'], + '!number' => $values['booking_room_number']) + ); + watchdog('booking', $message); + drupal_set_message($message, 'status', FALSE); + + db_delete('booking_room_mapping') ->condition('booking_eventid', $event->eid) ->condition('booking_nodeid', $values['personid']) - ->execute(); - drupal_set_message("Successfully updated " . $result . " row(s) in the room allocation table.", $type = 'status'); + ->execute(); + + return; } + //otherwise, continue with adding/updating the room allocation else { - //create a new room mapping for this person - $result = db_insert('booking_room_mapping') - ->fields(array( - 'booking_roomid' => $details->rid, - 'booking_eventid' => $event->eid, - 'booking_nodeid' => $values['personid'], - 'booking_room_bedtype' => $values['booking_room_bedtype'], - )) - ->execute(); - drupal_set_message("Successfully added " . $result . " row(s) to the room allocation table.", $type = 'status'); - } + $details = db_query("SELECT * FROM {booking_room_definition} WHERE booking_room_location_id = :lid AND booking_room_number = :num", + array(':lid' => $values['booking_room_location_id'], ':num' => $values['booking_room_number']))->fetchObject(); + + $check = db_query("SELECT * FROM {booking_room_mapping} WHERE booking_eventid = :eid AND booking_nodeid = :nid", + array(':eid' => $event->eid, ':nid' => $values['personid']))->fetchObject(); + + //this person already exists in mapping table + if ($check) + { + $message = t("Updating person id !nid to room id !id with bedtype !type", + array('!nid' => $values['personid'], '!id' => $details->rid, '!type' => $values['booking_room_bedtype'], + '!number' => $values['booking_room_number']) + ); + + //there is an existing mapping to update + $result = db_update('booking_room_mapping') + ->fields(array( + 'booking_roomid' => $details->rid, + 'booking_room_bedtype' => $values['booking_room_bedtype'], + )) + ->condition('booking_eventid', $event->eid) + ->condition('booking_nodeid', $values['personid']) + ->execute(); + //drupal_set_message("Successfully updated " . $result . " row(s) in the room allocation table.", $type = 'status'); + } + //create a new record in the mapping table + else + { + $message = t("Allocating person id !nid to room id !id with bedtype !type", + array('!nid' => $values['personid'], '!id' => $details->rid, '!type' => $values['booking_room_bedtype'], + '!number' => $values['booking_room_number']) + ); + + //create a new room mapping for this person + $result = db_insert('booking_room_mapping') + ->fields(array( + 'booking_roomid' => $details->rid, + 'booking_eventid' => $event->eid, + 'booking_nodeid' => $values['personid'], + 'booking_room_bedtype' => $values['booking_room_bedtype'], + )) + ->execute(); + //drupal_set_message("Successfully added id " . $values['personid'] . " to the room allocation table.", $type = 'status'); + } + watchdog('booking', $message); + drupal_set_message($message, 'status', FALSE); + + } //end operation check }