'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("
Use the link above to view room mate preferences and room allocations.
"); $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 = "Add a new room location definition
"; 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("Update the "!event " room location definition.
", 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', "Room location definition deletion confirmation being set:\n@info", 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 = "
Create new room defintion.
"); //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("Update the room defintions.
"); //$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', "Room definition submission:\n@info", 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', "
Room definition submission:\n@info", 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', "
Room deletion confirmation being set:\n@info", 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; } }