Add form for defining rooms
This commit is contained in:
@@ -178,7 +178,7 @@ function booking_menu() {
|
|||||||
//http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form/
|
//http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form/
|
||||||
$items['admin/config/booking/text'] = array(
|
$items['admin/config/booking/text'] = array(
|
||||||
'title' => 'Booking module text definitions',
|
'title' => 'Booking module text definitions',
|
||||||
'description' => 'Configure text used in the CYC Booking module',
|
'description' => 'Configure text used in the Event Booking module',
|
||||||
'page callback' => 'drupal_get_form',
|
'page callback' => 'drupal_get_form',
|
||||||
'page arguments' => array('booking_tokens_admin'),
|
'page arguments' => array('booking_tokens_admin'),
|
||||||
'access arguments' => array('administer site configuration'),
|
'access arguments' => array('administer site configuration'),
|
||||||
@@ -209,14 +209,7 @@ function booking_menu() {
|
|||||||
'access arguments' => array('administer site configuration'),
|
'access arguments' => array('administer site configuration'),
|
||||||
//'type' => MENU_LOCAL_TASK,
|
//'type' => MENU_LOCAL_TASK,
|
||||||
);
|
);
|
||||||
$items['admin/config/booking/rooms'] = array(
|
|
||||||
'title' => 'Booking module room definitions',
|
|
||||||
'description' => 'Configure room definitions for the Event Booking module',
|
|
||||||
'page callback' => 'drupal_get_form',
|
|
||||||
'page arguments' => array('booking_rooms_define_form'),
|
|
||||||
'access arguments' => array('administer site configuration'),
|
|
||||||
//'type' => MENU_LOCAL_TASK,
|
|
||||||
);
|
|
||||||
|
|
||||||
//pages for attendees to fill out information
|
//pages for attendees to fill out information
|
||||||
$items['booking'] = array(
|
$items['booking'] = array(
|
||||||
@@ -393,6 +386,33 @@ function booking_menu() {
|
|||||||
//configure rooms
|
//configure rooms
|
||||||
if (variable_get('booking_enable_roomallocations', 0) == 1)
|
if (variable_get('booking_enable_roomallocations', 0) == 1)
|
||||||
{
|
{
|
||||||
|
//config pages
|
||||||
|
$items['admin/config/booking/rooms'] = array(
|
||||||
|
'title' => 'Booking module room definitions',
|
||||||
|
'description' => 'View and Configure room definitions for the Event Booking module',
|
||||||
|
'page callback' => 'drupal_get_form',
|
||||||
|
'page arguments' => array('booking_rooms_view_definitions'),
|
||||||
|
'access arguments' => array('administer site configuration'),
|
||||||
|
//'type' => MENU_LOCAL_TASK,
|
||||||
|
);
|
||||||
|
$items['admin/config/booking/rooms/create'] = array(
|
||||||
|
'title' => 'Add New Room Definition',
|
||||||
|
'description' => 'Add room definition for the Event Booking module',
|
||||||
|
'page callback' => 'drupal_get_form',
|
||||||
|
'page arguments' => array('booking_rooms_definition_form', true),
|
||||||
|
'access arguments' => array('administer site configuration'),
|
||||||
|
'type' => MENU_LOCAL_ACTION,
|
||||||
|
);
|
||||||
|
|
||||||
|
$items['admin/config/booking/rooms/%/edit'] = array(
|
||||||
|
'title' => 'Edit Room Definition',
|
||||||
|
'page callback' => 'drupal_get_form',
|
||||||
|
'page arguments' => array('booking_rooms_definition_form', false, 4),
|
||||||
|
'access arguments' => array('administer site configuration'),
|
||||||
|
'type' => MENU_CALLBACK,
|
||||||
|
);
|
||||||
|
|
||||||
|
//admin pages
|
||||||
$items['admin/booking/rooms'] = array(
|
$items['admin/booking/rooms'] = array(
|
||||||
'title' => 'View Room Locations',
|
'title' => 'View Room Locations',
|
||||||
'description' => 'View Room Locations',
|
'description' => 'View Room Locations',
|
||||||
|
@@ -131,7 +131,8 @@ function booking_price_form($node, &$form_state, $create, $editid = 0)
|
|||||||
'#type' => 'hidden',
|
'#type' => 'hidden',
|
||||||
'#value' => $editid,
|
'#value' => $editid,
|
||||||
);
|
);
|
||||||
watchdog('booking', 'Editing existing price entry: @info', array ('@info' => var_export($data, TRUE)));
|
watchdog('booking', 'Editing existing price entry: @info',
|
||||||
|
array ('@info' => var_export($data, TRUE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$form['booking_price_descrip'] = array (
|
$form['booking_price_descrip'] = array (
|
||||||
|
@@ -109,7 +109,7 @@ function booking_roomallocations_view_summary() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function for manually assigning study group sessions for a person
|
* Function for manually assigning room allocation for a person
|
||||||
* @see http://drupal.stackexchange.com/questions/10112/dynamic-select-list-in-the-form-dependent-dropdown
|
* @see http://drupal.stackexchange.com/questions/10112/dynamic-select-list-in-the-form-dependent-dropdown
|
||||||
*/
|
*/
|
||||||
function booking_room_edit_form($node, &$form_state, $nid) {
|
function booking_room_edit_form($node, &$form_state, $nid) {
|
||||||
@@ -449,79 +449,17 @@ function booking_room_edit_form_submit($form, &$form_state) {
|
|||||||
} //end operation check
|
} //end operation check
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to define the form for configuring room definitions and also display existing room definitions
|
* Function to display existing room definitions
|
||||||
*/
|
*/
|
||||||
function booking_rooms_define_form($node, &$form_state) {
|
function booking_rooms_view_definitions() {
|
||||||
global $event;
|
global $event;
|
||||||
$form = array();
|
$prefix = "<h2>Room Definitions</h2>";
|
||||||
$bedcount_options = array();
|
|
||||||
|
|
||||||
//create the options array for bed counts
|
|
||||||
for ($i = 0; $i <= 15; $i++)
|
|
||||||
$bedcount_options[$i] = $i;
|
|
||||||
|
|
||||||
//query for room definitions
|
//query for room definitions
|
||||||
$result = db_query("SELECT * from {booking_room_definition}");
|
$result = db_query("SELECT * from {booking_room_definition}");
|
||||||
|
|
||||||
//define the form for adding to the room definitions
|
|
||||||
|
|
||||||
$form[] = array (
|
|
||||||
'first_heading' => array (
|
|
||||||
'#type' => 'markup',
|
|
||||||
'#markup' => "<h2>Add Room</h2>",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
$form['booking_room_location_id'] = array(
|
|
||||||
'#type' => 'select',
|
|
||||||
'#title' => t('Choose room location'),
|
|
||||||
'#options' => _booking_room_location_lookup(),
|
|
||||||
);
|
|
||||||
$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,
|
|
||||||
);
|
|
||||||
$form['submit'] = array
|
|
||||||
(
|
|
||||||
'#type' => 'submit',
|
|
||||||
'#value' => t('Add Room'),
|
|
||||||
);
|
|
||||||
|
|
||||||
//display the existing room definitions
|
|
||||||
$form[] = array (
|
|
||||||
'first_heading' => array (
|
|
||||||
'#type' => 'markup',
|
|
||||||
'#markup' => "<h2>Room Definitions</h2>",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
$header = array (
|
$header = array (
|
||||||
'booking_room_location_description' => t('Room Location'),
|
'booking_room_location_description' => t('Room Location'),
|
||||||
@@ -530,10 +468,21 @@ function booking_rooms_define_form($node, &$form_state) {
|
|||||||
'booking_room_doublebeds' => t('Number Double Beds'),
|
'booking_room_doublebeds' => t('Number Double Beds'),
|
||||||
'booking_room_queenbeds' => t('Number Queen Beds'),
|
'booking_room_queenbeds' => t('Number Queen Beds'),
|
||||||
'booking_room_ensuite' => t('Ensuite?'),
|
'booking_room_ensuite' => t('Ensuite?'),
|
||||||
|
'booking_room_edit' => t('Edit Room'),
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach($result as $data)
|
foreach($result as $data)
|
||||||
{
|
{
|
||||||
|
$rows[] = array (
|
||||||
|
_booking_room_location_lookup($data->booking_room_location_id),
|
||||||
|
$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
|
$options[$data->rid] = array
|
||||||
(
|
(
|
||||||
'booking_room_location_description' => _booking_room_location_lookup($data->booking_room_location_id),
|
'booking_room_location_description' => _booking_room_location_lookup($data->booking_room_location_id),
|
||||||
@@ -543,36 +492,194 @@ function booking_rooms_define_form($node, &$form_state) {
|
|||||||
'booking_room_queenbeds' => $data->booking_room_queenbeds,
|
'booking_room_queenbeds' => $data->booking_room_queenbeds,
|
||||||
'booking_room_ensuite' => $data->booking_room_ensuite == 'Y' ? 'Yes' : 'No',
|
'booking_room_ensuite' => $data->booking_room_ensuite == 'Y' ? 'Yes' : 'No',
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
$form['table'] = array (
|
$result = array (
|
||||||
'#type' => 'tableselect',
|
'first_para' => array (
|
||||||
'#header' => $header,
|
'#type' => 'markup',
|
||||||
'#options' => $options,
|
'#markup' => $prefix,
|
||||||
'#multiple' => false,
|
),
|
||||||
);
|
'table' => array (
|
||||||
|
'#theme' => 'table',
|
||||||
/*
|
'#header' => $header,
|
||||||
$form['Delete'] = array
|
'#rows' => $rows,
|
||||||
(
|
//'#attributes' => array('id' => 'sort-table'),
|
||||||
'#type' => 'submit',
|
)
|
||||||
'#value' => t('Delete'),
|
|
||||||
);
|
);
|
||||||
*/
|
|
||||||
|
|
||||||
return array (
|
return $result;
|
||||||
'form' => $form,
|
}
|
||||||
);
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
$bedcount_options = array();
|
||||||
|
|
||||||
|
//TODO: update to be like booking_price_form()
|
||||||
|
|
||||||
|
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' => _booking_room_location_lookup(),
|
||||||
|
'#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
|
* Process the form for adding room definitions
|
||||||
*/
|
*/
|
||||||
function booking_rooms_define_form_submit($form, &$form_state) {
|
function booking_rooms_definition_form_submit($form, &$form_state) {
|
||||||
global $event;
|
global $event;
|
||||||
$values = $form_state['input'];
|
$values = $form_state['input'];
|
||||||
|
$redirect_path = "admin/config/booking/rooms";
|
||||||
if ($form_state['values']['op'] == 'Add Room')
|
|
||||||
|
//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')
|
db_insert('booking_room_definition')
|
||||||
->fields(array(
|
->fields(array(
|
||||||
@@ -583,7 +690,9 @@ function booking_rooms_define_form_submit($form, &$form_state) {
|
|||||||
'booking_room_queenbeds' => $values['booking_room_queenbeds'],
|
'booking_room_queenbeds' => $values['booking_room_queenbeds'],
|
||||||
'booking_room_ensuite' => $values['booking_room_ensuite'] == 1 ? 'Y' : 'N',
|
'booking_room_ensuite' => $values['booking_room_ensuite'] == 1 ? 'Y' : 'N',
|
||||||
))
|
))
|
||||||
->execute();
|
->execute();
|
||||||
|
drupal_set_message('Created new room definition');
|
||||||
|
$form_state['redirect'] = $redirect_path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user