function availability_calendars_node_edit_form_submit in Availability Calendars 5
Same name and namespace in other branches
- 6 availability_calendars.module \availability_calendars_node_edit_form_submit()
File
- ./
availability_calendars.module, line 200 - Availability Calendars Module
Code
function availability_calendars_node_edit_form_submit($form_id, $form_values) {
$nid = check_plain($form_values['nid']);
$year = check_plain($form_values['year']);
$month = check_plain($form_values['month']);
// save weekly notes
$week = 1;
$nomoreweeks = FALSE;
while (!$nomoreweeks) {
if (isset($form_values['note-' . $week])) {
$notes[$week] = check_plain($form_values['note-' . $week]);
$week++;
}
else {
$nomoreweeks = TRUE;
}
}
// save $days
$day = 1;
$nomoredays = FALSE;
while (!$nomoredays) {
if (isset($form_values['day-' . $day])) {
$days[$day] = $form_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) VALUES (%d, %d, %d, %d, %d)', $nid, $year, $month, $day, $status);
}
drupal_set_message('Availability information saved.');
}