function availability_calendars_node_edit_form in Availability Calendars 5
Same name and namespace in other branches
- 6 availability_calendars.module \availability_calendars_node_edit_form()
1 string reference to 'availability_calendars_node_edit_form'
File
- ./
availability_calendars.module, line 131 - Availability Calendars Module
Code
function availability_calendars_node_edit_form() {
$nid = check_plain(arg(1));
$year = check_plain(arg(2));
$month = check_plain(arg(3));
$form['nid'] = array(
'#type' => 'hidden',
'#default_value' => $nid,
);
$form['year'] = array(
'#type' => 'hidden',
'#default_value' => $year,
);
$form['month'] = array(
'#type' => 'hidden',
'#default_value' => $month,
);
$startofweek = variable_get('availability_calendars_' . $nid . '_startofweek', 1);
$month_meta = availability_calendars_month_meta($year, $month, $startofweek);
// find all entries in database for this month ($availability, $notes) and pre-populate
$notes_result = db_query('SELECT week, note FROM {availability_calendars_week} WHERE nid = %d AND year = %d and month = %d', $nid, $year, $month);
while ($note = db_fetch_array($notes_result)) {
$notes[$note['week']] = $note['note'];
}
$status_result = db_query('SELECT day, status FROM {availability_calendars_day} WHERE nid = %d AND year = %d AND month = %d', $nid, $year, $month);
while ($status = db_fetch_array($status_result)) {
$day_status[$status['day']] = $status['status'];
}
$day = 1;
for ($week = 1; $week <= $month_meta['weeksinmonth']; $week++) {
$form['week-' . $week] = array(
'#type' => 'fieldset',
'#title' => t('Week @week', array(
'@week' => $week,
)),
);
$form['week-' . $week]['note-' . $week] = array(
'#type' => 'textfield',
'#title' => t('Note'),
'#default_value' => $notes[$week],
'#description' => t('This will be displayed beside the week in the calendar. It could include, for example, a weekly price.'),
);
if ($week == 1) {
$daysinweekremaining = 7 - $month_meta['firstday'];
}
else {
$daysinweekremaining = 7;
}
while ($daysinweekremaining > 0 && $day <= $month_meta['daysinmonth']) {
$form['week-' . $week]['day-' . $day] = array(
'#type' => 'select',
'#title' => t("@date", array(
'@date' => format_date(strtotime("{$year}-{$month}-{$day} 12:00"), 'custom', 'l d F'),
)),
'#options' => availability_calendars_options(),
'#default_value' => $day_status[$day],
);
$day++;
$daysinweekremaining--;
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}