complete submit hook for variety session form

This commit is contained in:
Nathan Coad
2018-05-05 12:20:58 +10:00
parent be12693e1c
commit e6f46f554d

View File

@@ -241,14 +241,14 @@ function booking_variety_create_session_form($node, &$form_state, $create = TRUE
);
}
/*
$data = db_select ('booking_variety_timeslots', 'v')
->condition('v.tid', $editid, '=')
->fields('v')
->execute()
->fetchObject();
*/
//define the form for variety session configuration if we're not deleting a session
if(!isset($form_state['storage']['confirm'])) {
$form[] = array (
'first_heading' => array(
'#type' => 'markup',
'#markup' => $prefix,
),
);
//add this to the form in a hidden field so we can update the right event
$form['tid'] = array (
@@ -280,25 +280,68 @@ function booking_variety_create_session_form($node, &$form_state, $create = TRUE
'#default_value' => !empty($data->booking_variety_maxsize) ? $data->booking_variety_maxsize : '0',
);
$form['submit'] = array
(
if ($create == true) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Create'),
'#value' => t('Create Session'),
);
}
else {
$form['Update'] = array(
'#type' => 'submit',
'#value' => t('Update Session'),
);
$form['Delete'] = array(
'#type' => 'submit',
'#value' => t('Delete Delete'),
);
}
return array (
'first_para' => array (
'#type' => 'markup',
'#markup' => $prefix,
),
'form' => $form,
);
} //end checking for delete confirmation
else {
return confirm_form($form, "Are you sure you wish to delete variety session definition with id " . $session_id . "?",
current_path(), NULL, "Delete Session");
}
}
function booking_variety_create_session_form_submit($form, &$form_state) {
global $event;
$values = $form_state['input'];
$redirect_path = "admin/config/booking/variety";
//if we're deleting, add the confirmation to the form if it hasn't been defined yet
if($form_state['values']['op'] == 'Delete Session' && (!isset($form_state['storage']['confirm']))) {
//watchdog('booking_debug', "<pre>Variety session 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 Session') {
//delete the variety session
watchdog('booking', "Deleting variety session ID !sid", array('!sid' => $values['booking_session_id']));
db_delete('booking_variety_sessions')
->condition('vid', $values['booking_session_id'])
->execute();
drupal_set_message('Deleted variety session id ' . $values['booking_session_id'] );
$form_state['redirect'] = $redirect_path;
}
elseif ($form_state['values']['op'] == 'Update Session') {
$result = db_update('booking_variety_sessions')
->fields(array(
'booking_eventid' => $event->eid,
'booking_variety_descrip' => $values['booking_variety_descrip'],
'booking_variety_status' => $values['booking_variety_status'] == 1 ? 1 : 0,
'booking_variety_maxsize' => $values['booking_variety_maxsize'],
))
->condition('vid', $values['booking_session_id'] )
->execute();
drupal_set_message('Updated variety session id ' . $values['booking_session_id'] );
$form_state['redirect'] = $redirect_path;
}
elseif ($form_state['values']['op'] == 'Create Session') {
db_insert('booking_variety_sessions')
->fields(array(
'booking_eventid' => $event->eid,
@@ -309,8 +352,9 @@ function booking_variety_create_session_form_submit($form, &$form_state) {
'booking_variety_regncount' => 0,
))
->execute();
$form_state['redirect'] = array('admin/config/booking/variety');
drupal_set_message('Created new variety session definition');
$form_state['redirect'] = $redirect_path;
}
}
/**