complete submit hook for variety session form
This commit is contained in:
@@ -241,76 +241,120 @@ function booking_variety_create_session_form($node, &$form_state, $create = TRUE
|
||||
);
|
||||
}
|
||||
|
||||
//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,
|
||||
),
|
||||
);
|
||||
|
||||
/*
|
||||
$data = db_select ('booking_variety_timeslots', 'v')
|
||||
->condition('v.tid', $editid, '=')
|
||||
->fields('v')
|
||||
->execute()
|
||||
->fetchObject();
|
||||
*/
|
||||
//add this to the form in a hidden field so we can update the right event
|
||||
$form['tid'] = array (
|
||||
'#type' => 'hidden',
|
||||
'#value' => $timeslot_id,
|
||||
);
|
||||
|
||||
//add this to the form in a hidden field so we can update the right event
|
||||
$form['tid'] = array (
|
||||
'#type' => 'hidden',
|
||||
'#value' => $timeslot_id,
|
||||
);
|
||||
$form['booking_variety_descrip'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('The name of the variety session to add to this timeslot'),
|
||||
'#size' => 60,
|
||||
'#maxlength' => 150,
|
||||
'#required' => TRUE,
|
||||
'#default_value' => !empty($data->booking_variety_descrip) ? $data->booking_variety_descrip : '',
|
||||
);
|
||||
|
||||
$form['booking_variety_descrip'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('The name of the variety session to add to this timeslot'),
|
||||
'#size' => 60,
|
||||
'#maxlength' => 150,
|
||||
'#required' => TRUE,
|
||||
'#default_value' => !empty($data->booking_variety_descrip) ? $data->booking_variety_descrip : '',
|
||||
);
|
||||
$form['booking_variety_status'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Make this variety session active?'),
|
||||
'#default_value' => !empty($data->booking_variety_status) ? $data->booking_variety_status : '',
|
||||
);
|
||||
|
||||
$form['booking_variety_status'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Make this variety session active?'),
|
||||
'#default_value' => !empty($data->booking_variety_status) ? $data->booking_variety_status : '',
|
||||
);
|
||||
$form['booking_variety_maxsize'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('The maximum number of people permitted in this variety session'),
|
||||
'#size' => 5,
|
||||
'#maxlength' => 5,
|
||||
'#required' => TRUE,
|
||||
'#default_value' => !empty($data->booking_variety_maxsize) ? $data->booking_variety_maxsize : '0',
|
||||
);
|
||||
|
||||
$form['booking_variety_maxsize'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('The maximum number of people permitted in this variety session'),
|
||||
'#size' => 5,
|
||||
'#maxlength' => 5,
|
||||
'#required' => TRUE,
|
||||
'#default_value' => !empty($data->booking_variety_maxsize) ? $data->booking_variety_maxsize : '0',
|
||||
);
|
||||
|
||||
$form['submit'] = array
|
||||
(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Create'),
|
||||
);
|
||||
|
||||
return array (
|
||||
'first_para' => array (
|
||||
'#type' => 'markup',
|
||||
'#markup' => $prefix,
|
||||
),
|
||||
'form' => $form,
|
||||
);
|
||||
if ($create == true) {
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#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 (
|
||||
'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";
|
||||
|
||||
db_insert('booking_variety_sessions')
|
||||
->fields(array(
|
||||
//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_timeslot_id' => $values['tid'],
|
||||
'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,
|
||||
'booking_variety_timeslot_id' => $values['tid'],
|
||||
'booking_variety_status' => $values['booking_variety_status'] == 1 ? 1 : 0,
|
||||
'booking_variety_descrip' => $values['booking_variety_descrip'],
|
||||
'booking_variety_maxsize' => $values['booking_variety_maxsize'],
|
||||
'booking_variety_regncount' => 0,
|
||||
))
|
||||
->execute();
|
||||
|
||||
$form_state['redirect'] = array('admin/config/booking/variety');
|
||||
'booking_variety_maxsize' => $values['booking_variety_maxsize'],
|
||||
'booking_variety_regncount' => 0,
|
||||
))
|
||||
->execute();
|
||||
drupal_set_message('Created new variety session definition');
|
||||
$form_state['redirect'] = $redirect_path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user