function availability_calendars_node_edit_form_submit in Availability Calendars 6
Same name and namespace in other branches
- 5 availability_calendars.module \availability_calendars_node_edit_form_submit()
Callback function for submitting a node edit form.
_state
Parameters
array $form:
File
- ./
availability_calendars.module, line 303 - Availability Calendars Module.
Code
function availability_calendars_node_edit_form_submit($form, &$form_state) {
$nid = check_plain($form_state['values']['nid']);
$year = check_plain($form_state['values']['year']);
$month = check_plain($form_state['values']['month']);
// save weekly notes
$week = 1;
$nomoreweeks = FALSE;
while (!$nomoreweeks) {
if (isset($form_state['values']['note-' . $week])) {
$notes[$week] = check_plain($form_state['values']['note-' . $week]);
$week++;
}
else {
$nomoreweeks = TRUE;
}
}
// save $days
$day = 1;
$nomoredays = FALSE;
while (!$nomoredays) {
if (isset($form_state['values']['day-' . $day])) {
$days[$day] = $form_state['values']['day-' . $day];
$day++;
}
else {
$nomoredays = TRUE;
}
}
db_query('DELETE FROM {availability_calendars_week} WHERE nid = %d AND year = %d AND month = %d', $nid, $year, $month);
foreach ($notes as $week => $note) {
db_query('INSERT INTO {availability_calendars_week} (nid, year, month, week, note) VALUES (%d, %d, %d, %d, "%s")', $nid, $year, $month, $week, $note);
}
db_query('DELETE FROM {availability_calendars_day} WHERE nid = %d AND year = %d AND month = %d', $nid, $year, $month);
foreach ($days as $day => $status) {
db_query("INSERT INTO {availability_calendars_day} (nid, year, month, day, status, date) VALUES (%d, %d, %d, %d, '%s', '%s')", $nid, $year, $month, $day, $status, "{$year}-{$month}-{$day} 12:00:00");
}
cache_clear_all();
// clear cache so that updates to this node show
drupal_set_message(t('Availability information saved.'));
}