Various tweaks
This commit is contained in:
@@ -28,14 +28,13 @@ function booking_room_view_summary() {
|
||||
array_shift($room_definitions);
|
||||
$i = 1;
|
||||
*/
|
||||
foreach ($room_definitions as $room) {
|
||||
foreach ($result 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))),
|
||||
$room->booking_roomlocation_descrip,
|
||||
l(t('Allocate Rooms'), t('admin/booking/rooms/!id/assign', array('!id' => $room->lid))),
|
||||
l(t('View Rooms'), t('admin/booking/rooms/!id/view', array('!id' => $room->lid))),
|
||||
);
|
||||
|
||||
$i++;
|
||||
//$i++;
|
||||
}
|
||||
|
||||
//output everything
|
||||
@@ -177,7 +176,7 @@ function booking_roomlocation_define_form_submit($form, &$form_state) {
|
||||
}
|
||||
elseif ($form_state['values']['op'] == 'Delete')
|
||||
{
|
||||
//verify that booking_pid is a number
|
||||
//verify that booking_lid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $values['booking_lid'])) {
|
||||
drupal_set_message("Error: Invalid room location ID supplied. Unable to delete entry.", 'error', FALSE);
|
||||
return "";
|
||||
@@ -214,4 +213,270 @@ function booking_roomlocation_define_form_submit($form, &$form_state) {
|
||||
//variable_set('booking_studygroup_count', $new_count);
|
||||
|
||||
$form_state['redirect'] = $redirect_path;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function to display existing room definitions
|
||||
*/
|
||||
function booking_rooms_view_definitions() {
|
||||
global $event;
|
||||
$rows = array();
|
||||
$prefix = "<h2>Room Definitions</h2>";
|
||||
|
||||
$query = db_select('booking_room_definition', 'r');
|
||||
$query->join('booking_room_locations', 'l', 'l.lid = r.booking_room_location_id');
|
||||
$query->condition('l.booking_roomlocation_active', 'Y', '=')
|
||||
->fields('r')
|
||||
->fields('l');
|
||||
|
||||
$result = $query->execute();
|
||||
|
||||
//query for room definitions
|
||||
//$result = db_query("SELECT * from {booking_room_definition}");
|
||||
|
||||
|
||||
$header = array (
|
||||
'booking_room_location_description' => t('Room Location'),
|
||||
'booking_room_number' => t('Room Number'),
|
||||
'booking_room_singlebeds' => t('Number Single Beds'),
|
||||
'booking_room_doublebeds' => t('Number Double Beds'),
|
||||
'booking_room_queenbeds' => t('Number Queen Beds'),
|
||||
'booking_room_ensuite' => t('Ensuite?'),
|
||||
'booking_room_edit' => t('Edit Room'),
|
||||
);
|
||||
|
||||
foreach($result as $data)
|
||||
{
|
||||
$rows[] = array (
|
||||
//_booking_room_location_lookup($data->booking_room_location_id),
|
||||
$data->booking_roomlocation_descrip,
|
||||
$data->booking_room_number,
|
||||
$data->booking_room_singlebeds,
|
||||
$data->booking_room_doublebeds,
|
||||
$data->booking_room_queenbeds,
|
||||
$data->booking_room_ensuite == 'Y' ? 'Yes' : 'No',
|
||||
l(t('Edit'), t('admin/config/booking/rooms/!id/edit', array('!id' => $data->rid))),
|
||||
);
|
||||
/*
|
||||
$options[$data->rid] = array
|
||||
(
|
||||
'booking_room_location_description' => _booking_room_location_lookup($data->booking_room_location_id),
|
||||
'booking_room_number' => $data->booking_room_number,
|
||||
'booking_room_singlebeds' => $data->booking_room_singlebeds,
|
||||
'booking_room_doublebeds' => $data->booking_room_doublebeds,
|
||||
'booking_room_queenbeds' => $data->booking_room_queenbeds,
|
||||
'booking_room_ensuite' => $data->booking_room_ensuite == 'Y' ? 'Yes' : 'No',
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
$result = array (
|
||||
'first_para' => array (
|
||||
'#type' => 'markup',
|
||||
'#markup' => $prefix,
|
||||
),
|
||||
'table' => array (
|
||||
'#theme' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#empty' => t('No room definitions found.'),
|
||||
//'#attributes' => array('id' => 'sort-table'),
|
||||
)
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to define the form for configuring room definitions and also display existing room definitions
|
||||
*/
|
||||
function booking_rooms_definition_form($node, &$form_state, $create, $room_id = 0) {
|
||||
global $event;
|
||||
$prefix = "";
|
||||
$form = array();
|
||||
$location_options = array();
|
||||
$bedcount_options = array();
|
||||
|
||||
//TODO: update to be like booking_price_form()
|
||||
|
||||
$query = db_query("SELECT * FROM {booking_room_locations} where booking_roomlocation_active='Y'");
|
||||
|
||||
foreach($query as $row)
|
||||
{
|
||||
$location_options[$row->lid] = $row->booking_roomlocation_descrip;
|
||||
}
|
||||
|
||||
if ($create == true)
|
||||
{
|
||||
$data = $node;
|
||||
$prefix = t("<p>Create new room defintion.</p>");
|
||||
//watchdog('booking', 'Creating new room definition: @info', array ('@info' => var_export($node, TRUE)));
|
||||
}
|
||||
else
|
||||
{
|
||||
//verify that $editid is a number
|
||||
if (! preg_match('/^[0-9]+$/', $room_id)) {
|
||||
drupal_set_message("Error: Invalid room ID supplied. Unable to update room definition.", 'error', FALSE);
|
||||
drupal_goto('admin/config/booking/rooms');
|
||||
return "";
|
||||
}
|
||||
|
||||
//$data = $form_state['input'];
|
||||
$data = db_query("SELECT * FROM {booking_room_definition} WHERE rid = :id",
|
||||
array(':id' => $room_id))
|
||||
->fetchObject();
|
||||
$prefix = t("<p>Update the room defintions.</p>");
|
||||
//add this to the form in a hidden field so we can update the right price
|
||||
$form['booking_rid'] = array (
|
||||
'#type' => 'hidden',
|
||||
'#value' => $room_id,
|
||||
);
|
||||
//watchdog('booking', 'Editing existing room definition: @info', array ('@info' => var_export($data, TRUE)));
|
||||
}
|
||||
|
||||
//create the options array for bed counts
|
||||
for ($i = 0; $i <= 15; $i++)
|
||||
$bedcount_options[$i] = $i;
|
||||
|
||||
//define the form for adding to the room definitions
|
||||
|
||||
if(!isset($form_state['storage']['confirm'])) {
|
||||
|
||||
$form[] = array (
|
||||
'first_heading' => array (
|
||||
'#type' => 'markup',
|
||||
'#markup' => $prefix,
|
||||
),
|
||||
);
|
||||
|
||||
$form['booking_room_location_id'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Choose room location'),
|
||||
'#options' => $location_options,
|
||||
'#default_value' => !empty($data->booking_room_location_id) ? $data->booking_room_location_id : ''
|
||||
);
|
||||
$form['booking_room_number'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Specify room number'),
|
||||
'#size' => 5,
|
||||
'#maxlength' => 10,
|
||||
'#default_value' => !empty($data->booking_room_number) ? $data->booking_room_number : '',
|
||||
);
|
||||
$form['booking_room_singlebeds'] = array (
|
||||
'#type' => 'select',
|
||||
'#title' => t('Specify number of single beds'),
|
||||
'#options' => $bedcount_options,
|
||||
'#default_value' => !empty($data->booking_room_singlebeds) ? $data->booking_room_singlebeds : '',
|
||||
);
|
||||
$form['booking_room_doublebeds'] = array (
|
||||
'#type' => 'select',
|
||||
'#title' => t('Specify number of double beds'),
|
||||
'#options' => $bedcount_options,
|
||||
'#default_value' => !empty($data->booking_room_doublebeds) ? $data->booking_room_doublebeds : '',
|
||||
);
|
||||
$form['booking_room_queenbeds'] = array (
|
||||
'#type' => 'select',
|
||||
'#title' => t('Specify number of queen beds'),
|
||||
'#options' => $bedcount_options,
|
||||
'#default_value' => !empty($data->booking_room_queenbeds) ? $data->booking_room_queenbeds : '',
|
||||
);
|
||||
$form['booking_room_ensuite'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Tick if this room has an ensuite'),
|
||||
'#default_value' => (!empty($data->booking_room_ensuite) && $data->booking_room_ensuite == 'Y') ? 1 : 0,
|
||||
);
|
||||
|
||||
if ($create == true)
|
||||
{
|
||||
$form['submit'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Add Room'),
|
||||
);
|
||||
} else {
|
||||
$form['Update'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Update Room'),
|
||||
);
|
||||
$form['Delete'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Delete Room'),
|
||||
);
|
||||
}
|
||||
|
||||
return array (
|
||||
'form' => $form,
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return confirm_form($form, "Are you sure you wish to delete room definition with id " . $room_id . "?",
|
||||
current_path(), NULL, "Delete Room");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form for adding room definitions
|
||||
*/
|
||||
function booking_rooms_definition_form_submit($form, &$form_state) {
|
||||
global $event;
|
||||
$values = $form_state['input'];
|
||||
$redirect_path = "admin/config/booking/rooms";
|
||||
|
||||
//watchdog('booking', "<pre>Room definition submission:\n@info</pre>", array('@info' => print_r( $form_state, true)));
|
||||
|
||||
//if we're deleting, add the confirmation to the form if it hasn't been defined yet
|
||||
if($form_state['values']['op'] == 'Delete Room' && (!isset($form_state['storage']['confirm'])))
|
||||
{
|
||||
//watchdog('booking', "<pre>Room deletion confirmation being set:\n@info</pre>", array('@info' => print_r( $form_state, true)));
|
||||
$form_state['storage']['confirm'] = TRUE;
|
||||
$form_state['rebuild'] = TRUE;
|
||||
}
|
||||
elseif ($form_state['values']['op'] == 'Delete Room')
|
||||
{
|
||||
//delete the room
|
||||
watchdog('booking', "Deleting room ID !rid", array('!rid' => $values['booking_rid']));
|
||||
|
||||
db_delete('booking_room_definition')
|
||||
->condition('rid', $values['booking_rid'])
|
||||
->execute();
|
||||
|
||||
drupal_set_message('Deleted room id ' . $values['booking_rid'] );
|
||||
$form_state['redirect'] = $redirect_path;
|
||||
}
|
||||
elseif ($form_state['values']['op'] == 'Update Room')
|
||||
{
|
||||
$result = db_update('booking_room_definition')
|
||||
->fields(array(
|
||||
'booking_room_location_id' => $values['booking_room_location_id'],
|
||||
'booking_room_number' => $values['booking_room_number'],
|
||||
'booking_room_singlebeds' => $values['booking_room_singlebeds'],
|
||||
'booking_room_doublebeds' => $values['booking_room_doublebeds'],
|
||||
'booking_room_queenbeds' => $values['booking_room_queenbeds'],
|
||||
'booking_room_ensuite' => $values['booking_room_ensuite'] == 1 ? 'Y' : 'N',
|
||||
))
|
||||
->condition('rid', $values['booking_rid'] )
|
||||
->execute();
|
||||
drupal_set_message('Updated room id ' . $values['booking_rid'] );
|
||||
$form_state['redirect'] = $redirect_path;
|
||||
}
|
||||
elseif ($form_state['values']['op'] == 'Add Room')
|
||||
{
|
||||
db_insert('booking_room_definition')
|
||||
->fields(array(
|
||||
'booking_room_location_id' => $values['booking_room_location_id'],
|
||||
'booking_room_number' => $values['booking_room_number'],
|
||||
'booking_room_singlebeds' => $values['booking_room_singlebeds'],
|
||||
'booking_room_doublebeds' => $values['booking_room_doublebeds'],
|
||||
'booking_room_queenbeds' => $values['booking_room_queenbeds'],
|
||||
'booking_room_ensuite' => $values['booking_room_ensuite'] == 1 ? 'Y' : 'N',
|
||||
))
|
||||
->execute();
|
||||
drupal_set_message('Created new room definition');
|
||||
$form_state['redirect'] = $redirect_path;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user