You are here

function availability_calendars_edit_calendar in Availability Calendars 7.2

Same name and namespace in other branches
  1. 6.2 availability_calendars.node.inc \availability_calendars_edit_calendar()

Show the availability calendar (callback for path availability-calendars/%).

Parameters

object $node: The node to show the calendar for.

int|NULL $year: The year to show the calendar for. If NULL, show from current month onwards.

int|NULL $month: The month to show the calendar for. If NULL, show the whole year.

boolean $edit: Whether to show the edit form for the given year and month?

Return value

string Themed calendar or edit calendar form.

1 string reference to 'availability_calendars_edit_calendar'
availability_calendars_menu in ./availability_calendars.module
Implements hook_menu().

File

./availability_calendars.node.inc, line 130

Code

function availability_calendars_edit_calendar($node = NULL, $year = NULL, $month = NULL, $edit = FALSE) {
  if ($node !== NULL) {
    drupal_set_title(t('Availability for !name', array(
      '!name' => $node->title,
    )));
    $settings = availability_calendars_get_settings($node);
    if (is_numeric($year) && is_numeric($month)) {
      $settings->monthcount = 1;
    }
    elseif (is_numeric($year)) {

      // Display availability calendar for a whole year.
      $month = 1;
      $settings->monthcount = 12;
    }
    else {

      // Display rolling availability calendar from this point onwards.
      $year = date('Y');
      $month = date('m');
    }
    if ($edit == 'edit') {

      // Display the edit form for the availability calendar on the node.
      drupal_set_title(t('Availability for !name in !date', array(
        '!name' => $node->title,
        '!date' => format_date(mktime(12, 0, 0, $month, 1, $year), 'custom', 'F Y'),
      )));
      return drupal_get_form('availability_calendars_node_edit_calendar_month_form', $node, $year, $month, $settings);
    }
    else {
      return array(
        '#theme' => 'availability_calendars_node',
        '#node' => $node,
        '#year' => $year,
        '#month' => $month,
        '#settings' => $settings,
      );
    }
  }
  else {
    print drupal_not_found();
  }
}