minor tweaks

This commit is contained in:
2014-06-03 22:21:52 +10:00
parent 6ca1c1ab80
commit 4f401aa245
2 changed files with 85 additions and 39 deletions

View File

@@ -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', "<pre>Room Number Options:\n@info</pre>", 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
}