diff --git a/booking.rooms_admin.inc b/booking.rooms_admin.inc index 791c70e..3613498 100644 --- a/booking.rooms_admin.inc +++ b/booking.rooms_admin.inc @@ -53,64 +53,55 @@ function booking_room_view_summary() { function booking_roomlocation_define_form($node, &$form_state, $create, $editid = 0) { $form = array (); - $prefix = "
Add a new study group definition
"; + $prefix = "Add a new room location definition
"; if ($create == true) { - drupal_set_title('Add Study Group'); + drupal_set_title('Add Room Location'); $data = $node; - watchdog('booking', 'Creating new study group: @info', array ('@info' => var_export($node, TRUE))); + watchdog('booking', 'Creating new room location: @info', array ('@info' => var_export($node, TRUE))); } else { - drupal_set_title('Edit Study Group'); + drupal_set_title('Edit Room Location'); //verify that $editid is a number if (! preg_match('/^[0-9]+$/', $editid)) { - drupal_set_message("Error: Invalid study group ID supplied. Unable to edit study group definition.", 'error', FALSE); - drupal_goto('admin/booking/config/studygroups'); + 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_studygroup_list} WHERE sid = :id", + $data = db_query("SELECT * FROM {booking_room_locations} WHERE lid = :id", array(':id' => $editid)) ->fetchObject(); - $prefix = t("Update the "!event " study group definition.
", array('!event' => $data->booking_studygroup_descrip)); + $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_sid'] = array ( + $form['booking_lid'] = array ( '#type' => 'hidden', '#value' => $editid, ); - watchdog('booking', 'Editing study group definition: @info', + watchdog('booking', 'Editing room location definition: @info', array ('@info' => var_export($data, TRUE))); } if(!isset($form_state['storage']['confirm'])) { - $form['booking_studygroup_descrip'] = array ( + $form['booking_roomlocation_descrip'] = array ( '#type' => 'textfield', - '#title' => t('Description of this study group (eg Monday)'), + '#title' => t('Description of this room location (eg Ramoth)'), '#size' => 60, '#maxlength' => 150, '#required' => TRUE, - '#default_value' => !empty($data->booking_studygroup_descrip) ? $data->booking_studygroup_descrip : '', + '#default_value' => !empty($data->booking_roomlocation_descrip) ? $data->booking_roomlocation_descrip : '', ); - $form['booking_num_group_sessions'] = array ( - '#type' => 'textfield', - '#title' => t('The number of sessions this study group will have'), - '#size' => 5, - '#maxlength' => 10, - '#required' => TRUE, - '#default_value' => !empty($data->booking_num_group_sessions) ? $data->booking_num_group_sessions : '', - ); - - $form['booking_is_readinggroup'] = array ( + $form['booking_roomlocation_active'] = array ( '#type' => 'radios', - '#title' => t('Reading group?'), - '#description' => t('Select whether this study group definition is for a reading group. Leave as No unless you want team colours associated with this group'), + '#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_is_readinggroup) ? ($data->booking_is_readinggroup == 'Y' ? 1 : 0) : 0, + '#default_value' => !empty($data->booking_roomlocation_active) ? ($data->booking_roomlocation_active == 'Y' ? 1 : 0) : 0, ); if ($create == true) @@ -118,18 +109,18 @@ function booking_roomlocation_define_form($node, &$form_state, $create, $editid $form['submit'] = array ( '#type' => 'submit', - '#value' => t('Create Study Group'), + '#value' => t('Create'), ); } else { $form['Update'] = array ( '#type' => 'submit', - '#value' => t('Update Study Group'), + '#value' => t('Updat'), ); $form['Delete'] = array ( '#type' => 'submit', - '#value' => t("Delete Study Group Definition"), + '#value' => t("Delete"), ); } @@ -144,8 +135,8 @@ function booking_roomlocation_define_form($node, &$form_state, $create, $editid //confirm delete else { - return confirm_form($form, "Are you sure you wish to delete studygroup definition with id " . $editid . "?", - current_path(), NULL, "Delete Study Group Definition"); + return confirm_form($form, "Are you sure you wish to delete room location definition with id " . $editid . "?", + current_path(), NULL, "Delete"); } } @@ -155,79 +146,72 @@ function booking_roomlocation_define_form_submit($form, &$form_state) { global $event; $values = $form_state['input']; - $redirect_path = array('admin/config/booking/studygroups'); + $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(); + //$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 Study Group') + if ($form_state['values']['op'] == 'Create') { - db_insert('booking_studygroup_list') + db_insert('booking_room_locations') ->fields(array( - 'booking_eventid' => $event->eid, - 'booking_studygroup_descrip' => $values['booking_studygroup_descrip'], - 'booking_num_group_sessions' => $values['booking_num_group_sessions'], - 'booking_is_readinggroup' => $values['booking_is_readinggroup'] == 1 ? 'Y' : 'N', + 'booking_roomlocation_descrip' => $values['booking_roomlocation_descrip'], + 'booking_roomlocation_active' => $values['booking_roomlocation_active'] == 1 ? 'Y' : 'N', )) ->execute(); - $new_count = $count->num + 1; + //$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 Study Group Definition" && (!isset($form_state['storage']['confirm']))) + elseif($form_state['values']['op'] == "Delete" && (!isset($form_state['storage']['confirm']))) { - watchdog('booking', "Studygroup deletion confirmation being set:\n@info", array('@info' => print_r( $form_state, true))); + 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; + //$new_count = $count->num; } - elseif ($form_state['values']['op'] == 'Delete Study Group Definition') + elseif ($form_state['values']['op'] == 'Delete') { //verify that booking_pid is a number - if (! preg_match('/^[0-9]+$/', $values['booking_sid'])) { - drupal_set_message("Error: Invalid studygroup ID supplied. Unable to delete entry.", 'error', FALSE); + if (! preg_match('/^[0-9]+$/', $values['booking_lid'])) { + drupal_set_message("Error: Invalid room location ID supplied. Unable to delete entry.", 'error', FALSE); return ""; } - - //TODO: Confirmation - //return confirm_form($form, "Really delete price?", 'admin/config/booking/prices'); - - $num_deleted = db_delete('booking_studygroup_list') - ->condition('sid', $values['booking_sid']) + + $num_deleted = db_delete('booking_room_locations') + ->condition('lid', $values['booking_lid']) ->execute(); - $new_count = $count->num - 1; + //$new_count = $count->num - 1; } - elseif ($form_state['values']['op'] == 'Update Study Group') + elseif ($form_state['values']['op'] == 'Update') { //verify that booking_sid is a number - if (! preg_match('/^[0-9]+$/', $values['booking_sid'])) { - drupal_set_message("Error: Invalid studygroup ID supplied. Unable to update study group.", 'error', FALSE); + 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_studygroup_list') + db_update('booking_room_locations') ->fields(array ( - 'booking_eventid' => $event->eid, - 'booking_studygroup_descrip' => $values['booking_studygroup_descrip'], - 'booking_num_group_sessions' => $values['booking_num_group_sessions'], - 'booking_is_readinggroup' => $values['booking_is_readinggroup'] == 1 ? 'Y' : 'N', + 'booking_roomlocation_descrip' => $values['booking_roomlocation_descrip'], + 'booking_roomlocation_active' => $values['booking_roomlocation_active'] == 1 ? 'Y' : 'N', )) - ->condition('sid', $values['booking_sid']) + ->condition('lid', $values['booking_lid']) ->execute(); - $new_count = $count->num; + //$new_count = $count->num; } //update the number of study groups now defined - variable_set('booking_studygroup_count', $new_count); + //variable_set('booking_studygroup_count', $new_count); $form_state['redirect'] = $redirect_path; } \ No newline at end of file