'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(); /* //get room definitions $room_definitions = _booking_room_location_lookup(); //ditch the first element which is empty array_shift($room_definitions); $i = 1; */ foreach ($room_definitions 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))), ); $i++; } //output everything $output .= t("

!event Room Locations

", array('!event' => $event->booking_eventname)); $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('Updat'), ); $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; //get the number of study groups before making this update //$count = db_query("SELECT count(*) as num FROM {booking_studygroup_list} WHERE booking_eventid = :eid", // array(':eid' => $event->eid))->fetchObject(); //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_pid 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_sid 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; }