504 lines
16 KiB
PHP
504 lines
16 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Admin pages for defining the room layouts
|
|
*/
|
|
|
|
/**
|
|
* 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:60%');
|
|
$rows = array();
|
|
|
|
//get study groups
|
|
$query = db_select('booking_room_locations', 'l')
|
|
->fields('l')
|
|
->condition('l.booking_roomlocation_active', 'Y', '=');
|
|
$result = $query->execute();
|
|
|
|
foreach ($result as $room) {
|
|
$rows[] = array(
|
|
$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++;
|
|
}
|
|
|
|
//output everything
|
|
$output .= t("<h3>!event Room Locations</h3>", array('!event' => $event->booking_eventname));
|
|
$output .= t("<p>Use the link above to view room mate preferences and room allocations.</p>");
|
|
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes));
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
/**
|
|
* Form to view or add a studygroup definition
|
|
*/
|
|
function booking_roomlocation_define_form($node, &$form_state, $create, $editid = 0)
|
|
{
|
|
$form = array ();
|
|
$prefix = "<p>Add a new room location definition</p>";
|
|
|
|
if ($create == true)
|
|
{
|
|
drupal_set_title('Add Room Location');
|
|
$data = $node;
|
|
watchdog('booking', 'Creating new room location: @info', array ('@info' => var_export($node, TRUE)));
|
|
}
|
|
else
|
|
{
|
|
drupal_set_title('Edit Room Location');
|
|
//verify that $editid is a number
|
|
if (! preg_match('/^[0-9]+$/', $editid)) {
|
|
drupal_set_message("Error: Invalid room location ID supplied. Unable to edit room location definition.", 'error', FALSE);
|
|
drupal_goto('admin/config/booking/rooms');
|
|
return "";
|
|
}
|
|
|
|
$data = db_query("SELECT * FROM {booking_room_locations} WHERE lid = :id",
|
|
array(':id' => $editid))
|
|
->fetchObject();
|
|
$prefix = t("<p>Update the "!event " room location definition.</p>", array('!event' => $data->booking_roomlocation_descrip));
|
|
//add this to the form in a hidden field so we can update the right price
|
|
$form['booking_lid'] = array (
|
|
'#type' => 'hidden',
|
|
'#value' => $editid,
|
|
);
|
|
watchdog('booking', 'Editing room location definition: @info',
|
|
array ('@info' => var_export($data, TRUE)));
|
|
}
|
|
|
|
|
|
if(!isset($form_state['storage']['confirm']))
|
|
{
|
|
$form['booking_roomlocation_descrip'] = array (
|
|
'#type' => 'textfield',
|
|
'#title' => t('Description of this room location (eg Ramoth)'),
|
|
'#size' => 60,
|
|
'#maxlength' => 150,
|
|
'#required' => TRUE,
|
|
'#default_value' => !empty($data->booking_roomlocation_descrip) ? $data->booking_roomlocation_descrip : '',
|
|
);
|
|
|
|
$form['booking_roomlocation_active'] = array (
|
|
'#type' => 'radios',
|
|
'#title' => t('Location active?'),
|
|
'#description' => t('Select whether this room location definition is active'),
|
|
'#options' => array (0 => t('No'), t('Yes')),
|
|
'#default_value' => !empty($data->booking_roomlocation_active) ? ($data->booking_roomlocation_active == 'Y' ? 1 : 0) : 0,
|
|
);
|
|
|
|
if ($create == true)
|
|
{
|
|
$form['submit'] = array
|
|
(
|
|
'#type' => 'submit',
|
|
'#value' => t('Create'),
|
|
);
|
|
} else {
|
|
$form['Update'] = array
|
|
(
|
|
'#type' => 'submit',
|
|
'#value' => t('Update'),
|
|
);
|
|
$form['Delete'] = array
|
|
(
|
|
'#type' => 'submit',
|
|
'#value' => t("Delete"),
|
|
);
|
|
}
|
|
|
|
return array (
|
|
'first_para' => array (
|
|
'#type' => 'markup',
|
|
'#markup' => $prefix,
|
|
),
|
|
'form' => $form,
|
|
);
|
|
}
|
|
//confirm delete
|
|
else
|
|
{
|
|
return confirm_form($form, "Are you sure you wish to delete room location definition with id " . $editid . "?",
|
|
current_path(), NULL, "Delete");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function booking_roomlocation_define_form_submit($form, &$form_state) {
|
|
|
|
global $event;
|
|
$values = $form_state['input'];
|
|
$redirect_path = array('admin/config/booking/rooms');
|
|
$new_count = 0;
|
|
|
|
//watchdog('booking', 'Checkboxes when setting buttons: @info', array ('@info' => var_export($checkboxes, TRUE)));
|
|
if ($form_state['values']['op'] == 'Create')
|
|
{
|
|
db_insert('booking_room_locations')
|
|
->fields(array(
|
|
'booking_roomlocation_descrip' => $values['booking_roomlocation_descrip'],
|
|
'booking_roomlocation_active' => $values['booking_roomlocation_active'] == 1 ? 'Y' : 'N',
|
|
))
|
|
->execute();
|
|
|
|
//$new_count = $count->num + 1;
|
|
}
|
|
//if we're deleting, add the confirmation to the form if it hasn't been defined yet
|
|
elseif($form_state['values']['op'] == "Delete" && (!isset($form_state['storage']['confirm'])))
|
|
{
|
|
watchdog('booking', "<pre>Room location definition deletion confirmation being set:\n@info</pre>", array('@info' => print_r( $form_state, true)));
|
|
$form_state['storage']['confirm'] = TRUE;
|
|
$form_state['rebuild'] = TRUE;
|
|
|
|
//$new_count = $count->num;
|
|
}
|
|
elseif ($form_state['values']['op'] == 'Delete')
|
|
{
|
|
//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 "";
|
|
}
|
|
|
|
$num_deleted = db_delete('booking_room_locations')
|
|
->condition('lid', $values['booking_lid'])
|
|
->execute();
|
|
|
|
//$new_count = $count->num - 1;
|
|
}
|
|
elseif ($form_state['values']['op'] == 'Update')
|
|
{
|
|
|
|
//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 update room location definition.", 'error', FALSE);
|
|
return "";
|
|
}
|
|
|
|
//update the study group
|
|
db_update('booking_room_locations')
|
|
->fields(array (
|
|
'booking_roomlocation_descrip' => $values['booking_roomlocation_descrip'],
|
|
'booking_roomlocation_active' => $values['booking_roomlocation_active'] == 1 ? 'Y' : 'N',
|
|
))
|
|
->condition('lid', $values['booking_lid'])
|
|
->execute();
|
|
|
|
//$new_count = $count->num;
|
|
}
|
|
|
|
//update the number of study groups now defined
|
|
//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;
|
|
$location_rows = array();
|
|
$definition_rows = array();
|
|
$attributes = array('style' => 'max-width:60%');
|
|
$location_prefix = "<h2>Room Locations</h2>";
|
|
$definition_prefix = "<h2>Room Definitions</h2>";
|
|
|
|
//get a list of all the room locations
|
|
$locations_query = db_select('booking_room_locations', 'l')
|
|
->fields('l');
|
|
$location_result = $locations_query->execute();
|
|
|
|
//get a list of all the room definitions at those locations
|
|
$definition_query = db_select('booking_room_definition', 'r');
|
|
$definition_query->join('booking_room_locations', 'l', 'l.lid = r.booking_room_location_id');
|
|
$definition_query->condition('l.booking_roomlocation_active', 'Y', '=')
|
|
->fields('r')
|
|
->fields('l')
|
|
->orderBy('lid')->orderBy('booking_room_number');
|
|
$definition_result = $definition_query->execute();
|
|
|
|
$location_header = array (
|
|
'booking_roomlocation_descrip' => t('Location Description'),
|
|
'booking_roomlocation_active' => t('Location Active?'),
|
|
'booking_location_edit' => t('Edit Location'),
|
|
);
|
|
|
|
$definition_header = array (
|
|
'booking_room_location_description' => t('Room Location'),
|
|
'booking_room_number' => t('Room Number'),
|
|
'booking_room_description' => t('Room Description'),
|
|
'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($location_result as $data) {
|
|
$location_rows[] = array (
|
|
$data->booking_roomlocation_descrip,
|
|
$data->booking_roomlocation_active == 'Y' ? 'Yes' : 'No',
|
|
l(t('Edit'), t('admin/config/booking/rooms/locations/!id/edit', array('!id' => $data->lid))),
|
|
);
|
|
}
|
|
|
|
foreach($definition_result as $data) {
|
|
$definition_rows[] = array (
|
|
//_booking_room_location_lookup($data->booking_room_location_id),
|
|
$data->booking_roomlocation_descrip,
|
|
$data->booking_room_number,
|
|
$data->booking_room_description,
|
|
$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))),
|
|
);
|
|
}
|
|
|
|
$result = array (
|
|
'locations_heading' => array (
|
|
'#type' => 'markup',
|
|
'#markup' => $location_prefix,
|
|
),
|
|
'table_locations' => array (
|
|
'#theme' => 'table',
|
|
'#header' => $location_header,
|
|
'#rows' => $location_rows,
|
|
'#empty' => t('No room location definitions found.'),
|
|
'#attributes' => $attributes,
|
|
),
|
|
'definitions_heading' => array (
|
|
'#type' => 'markup',
|
|
'#markup' => $definition_prefix,
|
|
),
|
|
'table_definitions' => array (
|
|
'#theme' => 'table',
|
|
'#header' => $definition_header,
|
|
'#rows' => $definition_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 "";
|
|
}
|
|
$prefix = t("<p>Update the room defintions.</p>");
|
|
|
|
//$data = $form_state['input'];
|
|
$data = db_query("SELECT * FROM {booking_room_definition} WHERE rid = :id", array(':id' => $room_id))
|
|
->fetchObject();
|
|
|
|
//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_description'] = array(
|
|
'#type' => 'textfield',
|
|
'#title' => t('Specify room label (not mandatory)'),
|
|
'#size' => 50,
|
|
'#maxlength' => 100,
|
|
'#default_value' => !empty($data->booking_room_description) ? $data->booking_room_description : '',
|
|
);
|
|
$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");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Validate the form for adding room definitions
|
|
*/
|
|
function booking_rooms_definition_form_validate($form, $form_state) {
|
|
//make sure room number is numerical
|
|
$values = $form_state['input'];
|
|
|
|
if ($form_state['values']['op'] != 'Delete Room') {
|
|
if (isset($values['booking_room_number']) && (! is_numeric($values['booking_room_number']))) {
|
|
form_set_error('booking_room_number', t('Room number must be numeric. If you need to use a more descriptive label, please use the room label field.'));
|
|
watchdog('booking_debug', "<pre>Room definition submission:\n@info</pre>", array('@info' => print_r( $form_state, true)));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 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_description' => $values['booking_room_description'],
|
|
'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_description' => $values['booking_room_description'],
|
|
'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;
|
|
}
|
|
} |