Fixed logic in room allocation form
This commit is contained in:
@@ -763,7 +763,7 @@ function booking_rooms_allocate_form($node, &$form_state, $location_id) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
watchdog('booking', "<pre>Loading existing room allocations:\n@info</pre>", array('@info' => print_r( $room_mapping, true)));
|
//watchdog('booking', "<pre>Loading existing room allocations:\n@info</pre>", array('@info' => print_r( $room_mapping, true)));
|
||||||
|
|
||||||
//attach the custom css
|
//attach the custom css
|
||||||
$form['#attached']['css'] = array(
|
$form['#attached']['css'] = array(
|
||||||
@@ -927,9 +927,7 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
|
|||||||
'booking_room_queenbed_p2' => 3,
|
'booking_room_queenbed_p2' => 3,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//watchdog('booking', "<pre>Room assignment submission form state:\n@info</pre>", array('@info' => print_r( $form_state, true)));
|
||||||
|
|
||||||
//watchdog('booking', "<pre>Room assignment submission:\n@info</pre>", array('@info' => print_r( $singlebed_ids, true)));
|
|
||||||
|
|
||||||
//go through the different bed types
|
//go through the different bed types
|
||||||
foreach ($bed_inputs as $type => $type_id)
|
foreach ($bed_inputs as $type => $type_id)
|
||||||
@@ -947,45 +945,90 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
|
|||||||
//go through each bed
|
//go through each bed
|
||||||
foreach ($value as $index => $nid)
|
foreach ($value as $index => $nid)
|
||||||
{
|
{
|
||||||
//if this is actually a person to process
|
//calculate the name of the field for the bed
|
||||||
|
$bed_lookup = $type . '[' . $room . '][' . $index . ']';
|
||||||
|
$previous_nid = 0;
|
||||||
|
$message = "";
|
||||||
|
|
||||||
|
//firstly check if there was a different nid here before
|
||||||
|
|
||||||
|
//iterate the option input-types in the form array that made up the original form
|
||||||
|
foreach ($form['form']['table']['#options'] as $option)
|
||||||
|
{
|
||||||
|
//if this one was defined and matches the bed we're looking at now
|
||||||
|
if (!empty($option[$type]) && $option[$type]['data']['#name'] == $bed_lookup)
|
||||||
|
{
|
||||||
|
$previous_nid = $option[$type]['data']['#value'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//if there is a person now selected for this bed
|
||||||
if ($nid > 0)
|
if ($nid > 0)
|
||||||
{
|
{
|
||||||
//this person didn't previously have a room/bed mapping
|
//remove any person previously defined here that doesn't match what is now defined
|
||||||
|
if ($previous_nid > 0 && $nid != $previous_nid)
|
||||||
|
{
|
||||||
|
$message = t('Bed allocation for room !room and bed index !index has changed. Removing !person from this location.',
|
||||||
|
array('!room' => $room, '!index' => $index, '!person' => $previous_nid));
|
||||||
|
watchdog('booking', $message);
|
||||||
|
drupal_set_message($message);
|
||||||
|
|
||||||
|
db_delete('booking_room_mapping')
|
||||||
|
->condition('booking_eventid', $event->eid)
|
||||||
|
->condition('booking_nodeid', $previous_nid)
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//if this person didn't previously have a room/bed mapping
|
||||||
if (empty($room_mapping[$nid]))
|
if (empty($room_mapping[$nid]))
|
||||||
{
|
{
|
||||||
|
|
||||||
//Validate that there is capacity for the person to be allocated to this room
|
//Validate that there is capacity for the person to be allocated to this room
|
||||||
if (_booking_room_capacity_check($room, $type_id))
|
if (_booking_room_capacity_check($room, $type_id))
|
||||||
{
|
{
|
||||||
drupal_set_message(t('Assigning person id !id to a type !type bed in room id !room.',
|
$message = t('Assigning person id !id to a type !type bed in room id !room.',
|
||||||
array('!id' => $nid, '!room' => $room, '!type' => $type_id)));
|
array('!id' => $nid, '!room' => $room, '!type' => $type_id));
|
||||||
|
|
||||||
|
//double check we haven't already allocated a bed during this submission
|
||||||
|
$check = db_query("SELECT * FROM {booking_room_mapping} " .
|
||||||
|
" WHERE booking_eventid = :eid AND booking_roomid = :rid " .
|
||||||
|
" AND booking_room_bedtype = :type AND booking_nodeid = :nid",
|
||||||
|
array(':eid' => $event->eid, ':rid' => $room, ':type' => $type_id,
|
||||||
|
':nid' => $nid,
|
||||||
|
))->fetchObject();
|
||||||
|
|
||||||
|
if (! $check)
|
||||||
|
{
|
||||||
|
$result = db_insert('booking_room_mapping')
|
||||||
|
->fields(array(
|
||||||
|
'booking_roomid' => $room,
|
||||||
|
'booking_eventid' => $event->eid,
|
||||||
|
'booking_nodeid' => $nid,
|
||||||
|
'booking_room_bedtype' => $type_id,
|
||||||
|
))
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$message .= t(' Except this person already exists.');
|
||||||
|
}
|
||||||
|
|
||||||
$result = db_insert('booking_room_mapping')
|
|
||||||
->fields(array(
|
|
||||||
'booking_roomid' => $room,
|
|
||||||
'booking_eventid' => $event->eid,
|
|
||||||
'booking_nodeid' => $nid,
|
|
||||||
'booking_room_bedtype' => $type_id,
|
|
||||||
))
|
|
||||||
->execute();
|
|
||||||
}
|
}
|
||||||
|
//no capacity available in this room
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
drupal_set_message(
|
$message = t('No capacity to assign person id !id to a type !type bed in room id !room.',
|
||||||
t('Insufficient capacity to assign person id !id to a type !type bed in room id !room.',
|
array('!id' => $nid, '!room' => $room, '!type' => $type_id)
|
||||||
array('!id' => $nid, '!room' => $room, '!type' => $type_id)
|
|
||||||
), 'error'
|
|
||||||
);
|
);
|
||||||
//, 'error', FALSE);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//this person previously had a room mapping but to a different room
|
||||||
}
|
elseif ((!empty($room_mapping[$nid])) && $room_mapping[$nid]->booking_roomid != $room)
|
||||||
//this person previously had a room mapping but to a different room
|
{
|
||||||
elseif ((!empty($room_mapping[$nid])) && $room_mapping[$nid]->booking_roomid != $room)
|
$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,
|
||||||
drupal_set_message(t('Changing person id !id from old room !oldroom to new room !room with type !type bed.',
|
'!oldroom' => $room_mapping[$nid]->booking_roomid));
|
||||||
array('!id' => $nid, '!room' => $room, '!type' => $type_id, '!oldroom' => $room_mapping[$nid]->booking_roomid)));
|
|
||||||
|
|
||||||
db_update('booking_room_mapping')
|
db_update('booking_room_mapping')
|
||||||
->fields(array(
|
->fields(array(
|
||||||
@@ -996,12 +1039,13 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
|
|||||||
->condition('booking_nodeid', $nid)
|
->condition('booking_nodeid', $nid)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
}
|
}
|
||||||
//this person previously had a room mapping but to a different bed type in the same room
|
//this person previously had a room mapping but to a different bed type in the same room
|
||||||
elseif ((!empty($room_mapping[$nid])) && $room_mapping[$nid]->booking_room_bedtype != $type_id)
|
elseif ((!empty($room_mapping[$nid])) && $room_mapping[$nid]->booking_room_bedtype != $type_id)
|
||||||
{
|
{
|
||||||
drupal_set_message(t('Changing person id !id in room !room to new bed type type !type .',
|
$message = t('Changing person id !id in room !room to new bed type type !type .',
|
||||||
array('!id' => $nid, '!room' => $room, '!type' => $type_id, '!oldroom' => $room_mapping[$nid]->booking_roomid)));
|
array('!id' => $nid, '!room' => $room, '!type' => $type_id,
|
||||||
|
'!oldroom' => $room_mapping[$nid]->booking_roomid));
|
||||||
|
|
||||||
db_update('booking_room_mapping')
|
db_update('booking_room_mapping')
|
||||||
->fields(array(
|
->fields(array(
|
||||||
@@ -1012,19 +1056,28 @@ function booking_rooms_allocate_form_submit($form, &$form_state) {
|
|||||||
->condition('booking_nodeid', $nid)
|
->condition('booking_nodeid', $nid)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//log the result
|
||||||
|
watchdog('booking', $message);
|
||||||
|
drupal_set_message($message);
|
||||||
|
}
|
||||||
|
//this bed has no ID assigned now, but did it have something before?
|
||||||
|
elseif ($nid == 0 && $previous_nid > 0)
|
||||||
|
{
|
||||||
|
$message = t('Removing person !person previously in room id !room with bed index !index.',
|
||||||
|
array('!room' => $room, '!index' => $index, '!person' => $option[$type]['data']['#value']));
|
||||||
|
watchdog('booking', $message);
|
||||||
|
drupal_set_message($message);
|
||||||
|
|
||||||
else
|
db_delete('booking_room_mapping')
|
||||||
{
|
->condition('booking_eventid', $event->eid)
|
||||||
//drupal_set_message(t('Person id !id already has some other room allocation.',
|
->condition('booking_nodeid', $previous_nid)
|
||||||
// array('!id' => $nid, '!room' => $room, '!type' => $type_id)));
|
->execute();
|
||||||
}
|
|
||||||
|
|
||||||
} //valid node id check
|
} //end node checking
|
||||||
} //each bed
|
} //each bed
|
||||||
} //each room
|
} //each room
|
||||||
} //each bed type
|
} //each bed type
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -323,7 +323,7 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text
|
|||||||
/*Text for emails*/
|
/*Text for emails*/
|
||||||
$form['emails'] = array(
|
$form['emails'] = array(
|
||||||
'#type' => 'fieldset',
|
'#type' => 'fieldset',
|
||||||
'#title' => 'Built-In Email Text Definitions',
|
'#title' => 'Built-In Workflow Email Definitions',
|
||||||
'#collapsible' => TRUE,
|
'#collapsible' => TRUE,
|
||||||
'#collapsed' => TRUE,
|
'#collapsed' => TRUE,
|
||||||
);
|
);
|
||||||
@@ -355,32 +355,6 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text
|
|||||||
'#description' => t(''),
|
'#description' => t(''),
|
||||||
'#default_value' => variable_get('booking_email_waitinglist_text', $booking_email_waitinglist_text),
|
'#default_value' => variable_get('booking_email_waitinglist_text', $booking_email_waitinglist_text),
|
||||||
);
|
);
|
||||||
$form['emails']['booking_email_travel_required_subject'] = array (
|
|
||||||
'#type' => 'textfield',
|
|
||||||
'#title' => t('Subject line for email requesting attendee to complete the travel form'),
|
|
||||||
'#size' => 150,
|
|
||||||
'#maxlength' => 300,
|
|
||||||
'#default_value' => variable_get('booking_email_travel_required_subject','[booking:eventname] Travel Details Required'),
|
|
||||||
);
|
|
||||||
$form['emails']['booking_email_travel_required_text'] = array(
|
|
||||||
'#title' => t('Email text requesting attendee to complete the travel form.'),
|
|
||||||
'#type' => 'textarea',
|
|
||||||
'#description' => t(''),
|
|
||||||
'#default_value' => variable_get('booking_email_travel_required_text', ''),
|
|
||||||
);
|
|
||||||
$form['emails']['booking_email_travel_complete_subject'] = array (
|
|
||||||
'#type' => 'textfield',
|
|
||||||
'#title' => t('Subject line for email indicating a person has completed the travel form'),
|
|
||||||
'#size' => 150,
|
|
||||||
'#maxlength' => 300,
|
|
||||||
'#default_value' => variable_get('booking_email_travel_complete_subject','[booking:eventname] Travel Details Received'),
|
|
||||||
);
|
|
||||||
$form['emails']['booking_email_travel_complete_text'] = array(
|
|
||||||
'#title' => t('Email text to indicate a person has completed the travel form.'),
|
|
||||||
'#type' => 'textarea',
|
|
||||||
'#description' => t(''),
|
|
||||||
'#default_value' => variable_get('booking_email_travel_complete_text', ''),
|
|
||||||
);
|
|
||||||
$form['emails']['booking_email_paymentoutstanding_text'] = array(
|
$form['emails']['booking_email_paymentoutstanding_text'] = array(
|
||||||
'#title' => t('Email text to send a person reminding them of how much they owe'),
|
'#title' => t('Email text to send a person reminding them of how much they owe'),
|
||||||
'#type' => 'textarea',
|
'#type' => 'textarea',
|
||||||
@@ -428,6 +402,32 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text
|
|||||||
'#description' => t(''),
|
'#description' => t(''),
|
||||||
'#default_value' => variable_get('booking_email_missedpayment', ''),
|
'#default_value' => variable_get('booking_email_missedpayment', ''),
|
||||||
);
|
);
|
||||||
|
$form['emails']['booking_email_travel_required_subject'] = array (
|
||||||
|
'#type' => 'textfield',
|
||||||
|
'#title' => t('Subject line for email requesting attendee to complete the travel form'),
|
||||||
|
'#size' => 150,
|
||||||
|
'#maxlength' => 300,
|
||||||
|
'#default_value' => variable_get('booking_email_travel_required_subject','[booking:eventname] Travel Details Required'),
|
||||||
|
);
|
||||||
|
$form['emails']['booking_email_travel_required_text'] = array(
|
||||||
|
'#title' => t('Email text requesting attendee to complete the travel form.'),
|
||||||
|
'#description' => t('This email will be sent from the !email email address', array('!email' => variable_get('booking_logistics_email'))),
|
||||||
|
'#type' => 'textarea',
|
||||||
|
'#default_value' => variable_get('booking_email_travel_required_text', ''),
|
||||||
|
);
|
||||||
|
$form['emails']['booking_email_travel_complete_subject'] = array (
|
||||||
|
'#type' => 'textfield',
|
||||||
|
'#title' => t('Subject line for email indicating a person has completed the travel form'),
|
||||||
|
'#size' => 150,
|
||||||
|
'#maxlength' => 300,
|
||||||
|
'#default_value' => variable_get('booking_email_travel_complete_subject','[booking:eventname] Travel Details Received'),
|
||||||
|
);
|
||||||
|
$form['emails']['booking_email_travel_complete_text'] = array(
|
||||||
|
'#title' => t('Email text to indicate a person has completed the travel form.'),
|
||||||
|
'#description' => t('This email will be sent from the !email email address', array('!email' => variable_get('booking_logistics_email'))),
|
||||||
|
'#type' => 'textarea',
|
||||||
|
'#default_value' => variable_get('booking_email_travel_complete_text', ''),
|
||||||
|
);
|
||||||
|
|
||||||
/*Text for emails*/
|
/*Text for emails*/
|
||||||
$form['custom-emails'] = array(
|
$form['custom-emails'] = array(
|
||||||
|
Reference in New Issue
Block a user