You are here

bat_fullcalendar.module in Booking and Availability Management Tools for Drupal 7

Same filename and directory in other branches
  1. 8 modules/bat_fullcalendar/bat_fullcalendar.module

Manages the display of FullCalendar and provides ways for other modules to easily modify it.

File

modules/bat_fullcalendar/bat_fullcalendar.module
View source
<?php

/**
 * @file
 * Manages the display of FullCalendar and provides ways for other modules
 * to easily modify it.
 */

/**
 * Implements hook_permission().
 */
function bat_fullcalendar_permission() {
  $permissions = array(
    'administer calendar events' => array(
      'title' => t('Administer calendar events'),
      'description' => t('Allows users to manipulate events on calendar.'),
      'restrict access' => TRUE,
    ),
    'view past event information' => array(
      'title' => t('View past event information'),
      'description' => t('Allow users to view event info in the past (especially via event reference field).'),
    ),
  );
  return $permissions;
}

/**
 * Implements hook_menu().
 */
function bat_fullcalendar_menu() {
  $items = array();
  $items['admin/bat/fullcalendar/%/event/%bat_event_type/%/%bat_date/%bat_date'] = array(
    'title' => 'Event Management',
    'page callback' => 'bat_fullcalendar_event_management',
    'page arguments' => array(
      3,
      5,
      6,
      7,
      8,
    ),
    'access callback' => 'bat_fullcalendar_event_management_access',
    'access arguments' => array(
      3,
      5,
      6,
      7,
      8,
    ),
    'type' => MENU_CALLBACK,
    'weight' => 30,
  );
  $items['admin/bat/config/fullcalendar'] = array(
    'title' => 'Fullcalendar',
    'description' => 'Configure settings for Fullcalendar.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'bat_fullcalendar_settings',
    ),
    'access arguments' => array(
      'configure bat settings',
    ),
    'type' => MENU_NORMAL_ITEM,
    'weight' => 30,
  );
  return $items;
}

/**
 * The EventManager page access callback.
 *
 * @param $entity_id
 * @param string $event_type
 * @param $event_id
 * @param $start_date
 * @param $end_date
 */
function bat_fullcalendar_event_management_access($entity_id, $event_type, $event_id, $start_date, $end_date) {
  if ($event_id == 0) {
    return bat_event_access('create', bat_event_create(array(
      'type' => $event_type->type,
    )));
  }
  else {
    $event = bat_event_load($event_id);
    return bat_event_access('update', $event);
  }
}

/**
 * The EventManager page shows when clicking on an event in the
 * calendar - will allow a user to manipulate that event.
 *
 * @param $entity_id
 * @param string $event_type
 * @param $event_id
 * @param $start_date
 * @param $end_date
 */
function bat_fullcalendar_event_management($entity_id, $event_type, $event_id, $start_date, $end_date) {

  // Include modal library.
  ctools_include('modal');

  // If any info missing we cannot load the event.
  if ($event_id == NULL || $start_date === 0 || $end_date === 0) {
    $output[] = ctools_modal_command_dismiss();
    drupal_set_message(t('Unable to load event.'), 'error');
  }
  $args = array(
    $entity_id,
    $event_type,
    $event_id,
    $start_date,
    $end_date,
  );
  foreach (array_reverse(module_implements('bat_fullcalendar_modal_content')) as $module) {
    $function = $module . '_bat_fullcalendar_modal_content';
    if (function_exists($function)) {
      $result = call_user_func_array($function, $args);
      if (isset($result) && is_array($result)) {
        $modal_content = reset($result);
        break;
      }
    }
  }
  if (isset($modal_content['title']) && isset($modal_content['content'])) {
    ctools_modal_render($modal_content['title'], $modal_content['content']);
  }
  elseif (isset($modal_content['commands'])) {
    print ajax_render($modal_content['commands']);
    exit;
  }
}

/**
 * Implements hook_bat_fullcalendar_modal_content().
 */
function bat_fullcalendar_bat_fullcalendar_modal_content($entity_id, $event_type, $event_id, $start_date, $end_date) {
  if ($event_id > 0) {

    // For existing events allow to edit in the modal.
    module_load_include('inc', 'bat_event', 'bat_event.admin');
    $event = bat_event_load($event_id);
    $form_state = array(
      'title' => t('Edit event'),
      'ajax' => TRUE,
      'build_info' => array(
        'args' => array(
          $event,
        ),
        'files' => array(
          'bat_event' => array(
            'module' => 'bat_event',
            'name' => 'bat_event.admin',
            'type' => 'inc',
          ),
        ),
      ),
    );

    // Wrap the form via ctools modal.
    $output = ctools_modal_form_wrapper('bat_event_edit_form', $form_state);
    if ($form_state['executed']) {
      if (!empty($form_state['event_deleted'])) {

        // If there are messages for the form, render them.
        $messages = theme('status_messages');
        $output = array();

        // If the form has not yet been rendered, render it.
        $output[] = ctools_modal_command_display(t('Event deleted'), $messages);
      }
      else {
        $output = array(
          ctools_modal_command_dismiss(),
        );
      }
    }
    return array(
      'bat_fullcalendar' => array(
        'commands' => $output,
      ),
    );
  }
  return array(
    'bat_fullcalendar' => array(
      'title' => t('Event Management'),
      'content' => drupal_get_form('bat_fullcalendar_event_manager_form', $entity_id, $event_type, $event_id, $start_date, $end_date),
    ),
  );
}

/**
 * The Event Manager Form.
 */
function bat_fullcalendar_event_manager_form($form, &$form_state, $entity_id, $event_type, $event_id, $start_date, $end_date) {
  $form = array();
  $new_event_id = $event_id;
  if (isset($form_state['values']['change_event_status'])) {
    $new_event_id = $form_state['values']['change_event_status'];
  }
  $form['#attributes']['class'][] = 'bat-management-form bat-event-form';

  // This entire form element will be replaced whenever 'changethis' is updated.
  $form['#prefix'] = '<div id="replace_textfield_div">';
  $form['#suffix'] = '</div>';
  $form['entity_id'] = array(
    '#type' => 'hidden',
    '#value' => $entity_id,
  );
  $form['event_type'] = array(
    '#type' => 'hidden',
    '#value' => $event_type->type,
  );
  $form['event_id'] = array(
    '#type' => 'hidden',
    '#value' => $event_id,
  );
  $form['bat_start_date'] = array(
    '#type' => 'hidden',
    '#value' => $start_date,
  );
  $form['bat_end_date'] = array(
    '#type' => 'hidden',
    '#value' => $end_date,
  );
  $unit = entity_load_single($event_type->target_entity_type, $entity_id);
  $form['event_title'] = array(
    '#prefix' => '<h2>',
    '#markup' => t('@unit_name', array(
      '@unit_name' => $unit->name,
    )),
    '#suffix' => '</h2>',
  );
  $date_format = variable_get('bat_date_format', 'Y-m-d H:i');
  $form['event_details'] = array(
    '#prefix' => '<div class="event-details">',
    '#markup' => t('Date range selected: @startdate to @enddate', array(
      '@startdate' => $start_date
        ->format($date_format),
      '@enddate' => $end_date
        ->format($date_format),
    )),
    '#suffix' => '</div>',
  );
  if ($event_type->fixed_event_states) {
    $state_options = bat_unit_state_options($event_type->type);
    $form['change_event_status'] = array(
      '#title' => t('Change the state for this event to') . ': ',
      '#type' => 'select',
      '#options' => $state_options,
      '#ajax' => array(
        'callback' => 'bat_fullcalendar_ajax_event_status_change',
        'wrapper' => 'replace_textfield_div',
      ),
      '#empty_option' => t('- Select -'),
    );
  }
  else {
    if (isset($event_type->default_event_value_field_ids[$event_type->type])) {
      $field_name = $event_type->default_event_value_field_ids[$event_type->type];
      $form['field_name'] = array(
        '#type' => 'hidden',
        '#value' => $field_name,
      );
      $field = field_info_field($field_name);
      $instance = field_info_instance('bat_event', $field_name, $event_type->type);
      $element = array(
        '#parents' => array(),
      );
      $widget = field_default_form('bat_event', NULL, $field, $instance, LANGUAGE_NONE, NULL, $element, $form_state);
      $form[$field_name] = $widget[$field_name];
      $form[$field_name]['#weight'] = 1;
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Update value'),
        '#weight' => 2,
        '#ajax' => array(
          'callback' => 'bat_fullcalendar_event_manager_form_ajax_submit',
          'wrapper' => 'replace_textfield_div',
        ),
      );
    }
  }
  return $form;
}

/**
 * The callback for the change_event_status widget of the event manager form.
 */
function bat_fullcalendar_ajax_event_status_change($form, &$form_state) {
  global $user;
  $start_date = $form_state['values']['bat_start_date'];
  $end_date = $form_state['values']['bat_end_date'];
  $entity_id = $form_state['values']['entity_id'];
  $event_id = $form_state['values']['event_id'];
  $event_type = $form_state['values']['event_type'];
  $state_id = $form_state['values']['change_event_status'];
  $event = bat_event_create(array(
    'type' => $event_type,
  ));
  $event->created = REQUEST_TIME;
  $event->uid = $user->uid;
  $event->start_date = $start_date
    ->format('Y-m-d H:i');

  // Always subtract one minute from the end time. FullCalendar provides
  // start and end time with the assumption that the last minute is *excluded*
  // while BAT deals with times assuming that the last minute is included.
  $end_date
    ->sub(new DateInterval('PT1M'));
  $event->end_date = $end_date
    ->format('Y-m-d H:i');
  $event_type_entity = bat_event_type_load($event_type);

  // Construct target entity reference field name using this event type's target entity type.
  $target_field_name = 'event_' . $event_type_entity->target_entity_type . '_reference';
  $event->{$target_field_name}[LANGUAGE_NONE][0]['target_id'] = $entity_id;
  $event->event_state_reference[LANGUAGE_NONE][0]['state_id'] = $state_id;
  $event
    ->save();
  $state_options = bat_unit_state_options($event_type);
  $form['form_wrapper_bottom'] = array(
    '#prefix' => '<div>',
    '#markup' => t('New Event state is <strong>@state</strong>.', array(
      '@state' => $state_options[$state_id],
    )),
    '#suffix' => '</div>',
    '#weight' => 9,
  );
  return $form;
}

/**
 * The callback for the change_event_status widget of the event manager form.
 */
function bat_fullcalendar_event_manager_form_ajax_submit($form, &$form_state) {
  global $user;
  $start_date = $form_state['values']['bat_start_date'];
  $end_date = $form_state['values']['bat_end_date'];
  $entity_id = $form_state['values']['entity_id'];
  $event_id = $form_state['values']['event_id'];
  $event_type = $form_state['values']['event_type'];
  $field_name = $form_state['values']['field_name'];
  $event = bat_event_create(array(
    'type' => $event_type,
  ));
  $event->created = REQUEST_TIME;
  $event->uid = $user->uid;
  $event->start_date = $start_date
    ->format('Y-m-d H:i');

  // Always subtract one minute from the end time. FullCalendar provides
  // start and end time with the assumption that the last minute is *excluded*
  // while BAT deals with times assuming that the last minute is included.
  $end_date
    ->sub(new DateInterval('PT1M'));
  $event->end_date = $end_date
    ->format('Y-m-d H:i');
  $event_type_entity = bat_event_type_load($event_type);

  // Construct target entity reference field name using this event type's target entity type.
  $target_field_name = 'event_' . $event_type_entity->target_entity_type . '_reference';
  $event->{$target_field_name}[LANGUAGE_NONE][0]['target_id'] = $entity_id;
  $event->{$field_name} = $form_state['values'][$field_name];
  $event
    ->save();
  $unit = entity_load_single($event_type_entity->target_entity_type, $entity_id);
  $value = field_view_value('bat_event', $event, $field_name, $form_state['values'][$field_name][LANGUAGE_NONE][0]);
  $form['form_wrapper_bottom'] = array(
    '#prefix' => '<div>',
    '#markup' => t('Value for @name changed to @value', array(
      '@name' => $unit->name,
      '@value' => $value['#markup'],
    )),
    '#suffix' => '</div>',
    '#weight' => 9,
  );
  return $form;
}

/**
 * Implements hook_libraries_info().
 */
function bat_fullcalendar_libraries_info() {
  $libraries['fullcalendar'] = array(
    'name' => 'Full Calendar',
    'vendor url' => 'http://fullcalendar.io',
    'download url' => 'https://github.com/arshaw/fullcalendar/releases/download/v3.9.0/fullcalendar-3.9.0.zip',
    'version arguments' => array(
      'file' => 'fullcalendar.min.js',
      'pattern' => '/v(\\d+\\.\\d+\\.\\d)/',
      'lines' => 3,
    ),
    'files' => array(
      'js' => array(
        'lib/moment.min.js',
        'fullcalendar.js',
        'gcal.js',
        'locale-all.js',
      ),
      'css' => array(
        'fullcalendar.css',
      ),
    ),
    'variants' => array(
      'minified' => array(
        'files' => array(
          'js' => array(
            'lib/moment.min.js',
            'fullcalendar.min.js',
            'gcal.js',
            'locale-all.js',
          ),
          'css' => array(
            'fullcalendar.min.css',
          ),
        ),
        'dependencies' => array(),
      ),
      'source' => array(
        'files' => array(
          'js' => array(
            'lib/moment.min.js',
            'fullcalendar.js',
            'gcal.js',
            'locale-all.js',
          ),
          'css' => array(
            'fullcalendar.css',
          ),
        ),
        'dependencies' => array(),
      ),
    ),
  );
  $libraries['fullcalendar-scheduler'] = array(
    'name' => 'Fullcalendar Scheduler',
    'vendor url' => 'http://fullcalendar.io',
    'download url' => 'https://github.com/fullcalendar/fullcalendar-scheduler/releases/download/v1.9.4/fullcalendar-scheduler-1.9.4.zip',
    'version arguments' => array(
      'file' => 'scheduler.min.js',
      'pattern' => '/(\\d+\\.\\d+\\.\\d)/',
    ),
    'files' => array(
      'js' => array(
        'scheduler.min.js',
      ),
    ),
    'variants' => array(
      'minified' => array(
        'files' => array(
          'js' => array(
            'scheduler.min.js',
          ),
          'css' => array(
            'scheduler.min.css',
          ),
        ),
        'dependencies' => array(
          'fullcalendar (>=3.9.0)',
        ),
      ),
      'source' => array(
        'files' => array(
          'js' => array(
            'scheduler.js',
          ),
          'css' => array(
            'scheduler.css',
          ),
        ),
        'dependencies' => array(
          'fullcalendar (>=3.9.0)',
        ),
      ),
    ),
  );
  return $libraries;
}

/**
 * Helper function to check if a library is loaded properly or not.
 *
 * @param $name - string fullcalendar or fullcalendar-scheduler
 * @param $variant - string source or minified
 *
 * @return bool
 *   Boolean indicating if the library is properly loaded or not.
 */
function bat_fullcalendar_library_loaded($name, $variant = 'minified') {
  return ($library = libraries_load($name, $variant)) && !empty($library['loaded']);
}

/**
 * Fullcalendar settings.
 *
 * @param array $user_settings
 *
 * @return array
 */
function bat_fullcalendar_configure($user_settings) {
  global $language;
  $settings = array();
  foreach ($user_settings['batCalendar'] as $id => $user_setting) {

    // Set the scheduler license.
    $schedulerlicense = variable_get('bat_fullcalendar_scheduler_key', '');
    switch ($schedulerlicense) {
      case 'gpl':
        $schedulerlicensekey = 'GPL-My-Project-Is-Open-Source';
        break;
      case 'non-commercial':
        $schedulerlicensekey = 'CC-Attribution-NonCommercial-NoDerivatives';
        break;
      case 'commercial':
        $schedulerlicensekey = variable_get('bat_fullcalendar_scheduler_commercial_key', '');
        break;
      case 'none':
        $schedulerlicensekey = '';
        break;
      default:
        $schedulerlicensekey = '';
        break;
    }
    $calendar_views = 'timelineDay, timelineTenDay, timelineMonth, timelineYear';
    $default_view = 'timelineDay';
    if ($user_setting['eventGranularity'] == 'bat_daily') {
      $calendar_views = 'timelineThirtyDay, timelineYear';
      $default_view = 'timelineThirtyDay';
      $default_date = (new DateTime())
        ->modify('-5 days')
        ->format('Y-m-d');
    }
    elseif ($user_setting['eventGranularity']) {
      $calendar_views = 'timelineDay, timelineTenDay, timelineMonth';
      $default_view = 'timelineDay';
      $default_date = (new DateTime())
        ->format('Y-m-d');
    }
    if (isset($user_setting['views']) && !empty($user_setting['views'])) {
      $calendar_views = $user_setting['views'];
    }
    if (isset($user_setting['defaultView']) && !empty($user_setting['defaultView'])) {
      $default_view = $user_setting['defaultView'];
    }
    $business_hours = array(
      'start' => '00:00',
      'end' => '24:00',
      'dow' => array(
        0,
        1,
        2,
        3,
        4,
        5,
        6,
      ),
    );
    $config = array(
      'schedulerLicenseKey' => $schedulerlicensekey,
      'themeSystem' => 'standard',
      'unitType' => '',
      'eventType' => '',
      'grouping_entity_type' => '',
      'grouping_ids' => '',
      'collapse_childrens' => 0,
      'eventGranularity' => $user_setting['eventGranularity'],
      'locale' => $language->language,
      'slotWidth' => FALSE,
      'calendarHeight' => 500,
      'editable' => TRUE,
      'selectable' => TRUE,
      'eventStartEditable' => TRUE,
      'eventDurationEditable' => TRUE,
      'headerLeft' => 'prev, today, datepicker, next',
      'headerCenter' => 'title',
      'headerRight' => $calendar_views,
      'views' => $calendar_views,
      'defaultView' => $default_view,
      'viewsTimelineDayButtonText' => ':15 slots',
      'viewsTimelineDaySlotDuration' => '00:15',
      'viewsTimelineDaySlotLabelFormat' => FALSE,
      'viewsTimelineDayTitleFormat' => '',
      'viewsTimelineSevenDayButtonText' => '7 days',
      'viewsTimelineSevenDayDuration' => array(
        'days' => 7,
      ),
      'viewsTimelineSevenDaySlotDuration' => '01:00',
      'viewsTimelineSevenDayTitleFormat' => '',
      'viewsTimelineSevenDaySlotLabelFormat' => FALSE,
      'viewsTimelineTenDayButtonText' => '10 days',
      'viewsTimelineTenDayDuration' => array(
        'days' => 10,
      ),
      'viewsTimelineTenDaySlotDuration' => '01:00',
      'viewsTimelineTenDaySlotLabelFormat' => FALSE,
      'viewsTimelineTenDayTitleFormat' => '',
      'viewsTimelineThirtyDayButtonText' => '30 days',
      'viewsTimelineThirtyDayDuration' => array(
        'days' => 30,
      ),
      'viewsTimelineThirtyDaySlotDuration' => '01:00',
      'viewsTimelineThirtyDaySlotLabelFormat' => FALSE,
      'viewsTimelineThirtyDayTitleFormat' => '',
      'viewsTimeline365DayButtonText' => '1 year',
      'viewsTimeline365DayDuration' => array(
        'days' => 365,
      ),
      'viewsTimeline365DaySlotLabelFormat' => FALSE,
      'viewsTimeline365DayTitleFormat' => '',
      'viewsAgendaOneDayButtonText' => 'day',
      'viewsAgendaOneDayDuration' => array(
        'days' => 1,
      ),
      'viewsAgendaSevenDayButtonText' => 'week',
      'viewsAgendaSevenDayDuration' => array(
        'days' => 7,
      ),
      'resourceAreaWidth' => '25%',
      'resourceLabelText' => t('Types'),
      'errorMessage' => t('Action not allowed. User may not have the right permissions.'),
      'businessHours' => $business_hours,
      'selectConstraint' => NULL,
      'scrollTime' => '06:00:00',
      'minTime' => '00:00:00',
      'maxTime' => '24:00:00',
      'hiddenDays' => array(),
      'validRange' => NULL,
      'defaultDate' => $default_date,
      'repeatEventTitle' => TRUE,
      'showBackgroundEventTitle' => FALSE,
      'enableModal' => TRUE,
      'customButtons' => array(),
      'eventOrder' => 'title',
      'titleFormat' => '',
      'slotLabelFormat' => FALSE,
      'defaultTimedEventDuration' => '00:00:00',
      'selectAllowBusinessHours' => FALSE,
      'groupByResource' => FALSE,
      'groupByDateAndResource' => FALSE,
      'allDaySlot' => TRUE,
      'hideResourceTypes' => FALSE,
      'firstDay' => 0,
      'viewsAgendaButtonText' => '',
      'viewsWeekButtonText' => '',
      'viewsDayButtonText' => '',
      'allDayDefault' => NULL,
    );
    $settings['batCalendar'][$id] = array_replace_recursive($config, $user_setting);

    // Allow other modules to alter further.
    drupal_alter('bat_calendar_settings', $settings);
  }
  date_popup_add();
  return $settings;
}

/**
 * Sets up JS files for fullcalendar and calls an alter to allow other modules to change them.
 *
 * @param array $user_js_files
 *
 * @return array
 */
function bat_fullcalendar_set_js_files($user_js_files = array()) {
  if (count($user_js_files) > 0) {
    $js_files = $user_js_files;
  }
  else {
    $js_files = array(
      drupal_get_path('module', 'bat_fullcalendar') . '/js/bat_fullcalendar_timeline.js',
    );
    if (module_exists('qtip_library')) {
      libraries_load('qtip');
    }
  }

  // Provide alter hook to change calendar js files.
  drupal_alter('bat_fullcalendar_render_js', $js_files);
  return $js_files;
}

/**
 * Sets up CSS files for fullcalendar and calls an alter to allow other modules to change them.
 *
 * @param array $user_css_files
 *
 * @return array
 */
function bat_fullcalendar_set_css_files($user_css_files = array()) {
  if (count($user_css_files) > 0) {
    $css_files = $user_css_files;
  }
  else {
    $css_files = array(
      drupal_get_path('module', 'bat_fullcalendar') . '/css/bat_fullcalendar_timeline.css',
      drupal_get_path('module', 'bat_fullcalendar') . '/css/fullcalendar.theme.css',
    );
  }

  // Provide alter hook to change calendar css files.
  drupal_alter('bat_fullcalendar_render_css', $css_files);
  return $css_files;
}

/**
 * Theme function for FullCalendar.
 */
function theme_bat_fullcalendar($vars) {
  $calendar_id = $vars['calendar_settings']['calendar_id'];
  $modal_style = $vars['calendar_settings']['modal_style'];
  $user_settings = $vars['calendar_settings']['user_settings'];

  // Check if user has defined js files and swap those in.
  if (!empty($vars['js_files'])) {
    $js_files = bat_fullcalendar_set_js_files($vars['js_files']);
  }
  else {
    $js_files = bat_fullcalendar_set_js_files();
  }

  // Check for CSS files.
  if (!empty($vars['css_files'])) {
    $css_files = bat_fullcalendar_set_css_files($vars['css_files']);
  }
  else {
    $css_files = bat_fullcalendar_set_css_files();
  }

  // Attributes.
  if (!empty($vars['attributes'])) {
    $attributes = $vars['attributes'];
  }
  else {
    $attributes = array(
      'id' => drupal_html_id('calendar'),
      'class' => array(
        'calendar-set',
        'clearfix',
      ),
    );
    if (isset($vars['calendar_settings']['class']) && !empty($vars['calendar_settings']['class'])) {
      $attributes['class'] = array_merge($attributes['class'], $vars['calendar_settings']['class']);
    }
  }

  // Override default settings with ones coming form user.
  $settings = bat_fullcalendar_configure($vars['calendar_settings']['user_settings']);

  // Add FullCalendar JS.
  bat_fullcalendar_library_loaded($calendar_id);
  bat_fullcalendar_modal_style($modal_style);
  foreach ($js_files as $js_file) {
    drupal_add_js($js_file, array(
      'type' => 'file',
      'scope' => 'footer',
    ));
  }
  foreach ($css_files as $css_file) {
    drupal_add_css($css_file, array(
      'type' => 'file',
    ));
  }
  $settings['batCalendar'][0]['id'] = $attributes['id'];
  drupal_add_js($settings, 'setting');
  $render_array = array(
    '#markup' => '<div' . drupal_attributes($attributes) . '></div>',
  );
  return render($render_array);
}

/**
 * Implements hook_theme().
 */
function bat_fullcalendar_theme($existing, $type, $theme, $path) {
  return array(
    'bat_fullcalendar' => array(
      'variables' => array(
        'calendar_settings' => array(
          NULL,
        ),
        'js_files' => array(),
        'css_files' => array(),
        'attributes' => array(),
      ),
    ),
  );
}

/**
 * Allows us to define the license to use with Scheduler.
 */
function bat_fullcalendar_settings($form, &$form_state) {
  $form['bat_fullcalendar_scheduler'] = array(
    '#type' => 'container',
    '#prefix' => '<div id="label-settings">',
    '#suffix' => '</div>',
  );
  $form['bat_fullcalendar_scheduler']['bat_fullcalendar_scheduler_key'] = array(
    '#type' => 'radios',
    '#title' => t('FullCalendar Scheduler License'),
    '#default_value' => variable_get('bat_fullcalendar_scheduler_key', ''),
    '#options' => array(
      'commercial' => t('Commercial License'),
      'non-commercial' => t('Non-Commercial Creative Commons'),
      'gpl' => t('GPL License'),
      'none' => t('None'),
    ),
    '#description' => t('Please visit http://fullcalendar.io/scheduler/license/ to find out about the license terms for the Scheduler View of FullCalendar'),
    '#ajax' => array(
      'callback' => 'bat_fullcalendar_settings_ajax_callback',
      'wrapper' => 'label-settings',
    ),
  );
  if (!isset($form_state['values']['bat_fullcalendar_scheduler_key']) && $form['bat_fullcalendar_scheduler']['bat_fullcalendar_scheduler_key']['#default_value'] == 'commercial' || isset($form_state['values']['bat_fullcalendar_scheduler_key']) && $form_state['values']['bat_fullcalendar_scheduler_key'] == 'commercial') {
    $form['bat_fullcalendar_scheduler']['bat_fullcalendar_scheduler_commercial_key'] = array(
      '#type' => 'textfield',
      '#title' => t('FullCalendar Scheduler Commercial License Key'),
      '#required' => TRUE,
      '#default_value' => variable_get('bat_fullcalendar_scheduler_commercial_key', ''),
    );
  }
  return system_settings_form($form);
}

/**
 * Ajax callback for bat_fullcalendar_settings form.
 */
function bat_fullcalendar_settings_ajax_callback($form, &$form_state) {
  return $form['bat_fullcalendar_scheduler'];
}

/**
 * Define modal JS style and dependencies.
 *
 * @param string $style
 */
function bat_fullcalendar_modal_style($style = 'default') {

  // Include libraries.
  ctools_include('modal');
  ctools_include('ajax');
  ctools_modal_add_js();

  // Styles to use for the modal.
  $modal_style = array(
    'bat-modal-style' => array(
      'modalSize' => array(
        'type' => 'fixed',
        'width' => 520,
        'height' => 520,
        'addWidth' => 0,
        'addHeight' => 0,
      ),
      'modalOptions' => array(
        'opacity' => 0.0,
        'background-color' => '#000',
      ),
      'animation' => 'fadeIn',
    ),
  );

  // Allow other modules to change the modal style.
  drupal_alter('bat_fullcalendar_modal_style', $modal_style);

  // Add the ctool modal configuration to settings.
  drupal_add_js($modal_style, 'setting');

  // Add the ctools modal stylesheet.
  drupal_add_css(drupal_get_path('module', 'bat_fullcalendar') . '/css/bat_modal.css');
}

Functions

Namesort descending Description
bat_fullcalendar_ajax_event_status_change The callback for the change_event_status widget of the event manager form.
bat_fullcalendar_bat_fullcalendar_modal_content Implements hook_bat_fullcalendar_modal_content().
bat_fullcalendar_configure Fullcalendar settings.
bat_fullcalendar_event_management The EventManager page shows when clicking on an event in the calendar - will allow a user to manipulate that event.
bat_fullcalendar_event_management_access The EventManager page access callback.
bat_fullcalendar_event_manager_form The Event Manager Form.
bat_fullcalendar_event_manager_form_ajax_submit The callback for the change_event_status widget of the event manager form.
bat_fullcalendar_libraries_info Implements hook_libraries_info().
bat_fullcalendar_library_loaded Helper function to check if a library is loaded properly or not.
bat_fullcalendar_menu Implements hook_menu().
bat_fullcalendar_modal_style Define modal JS style and dependencies.
bat_fullcalendar_permission Implements hook_permission().
bat_fullcalendar_settings Allows us to define the license to use with Scheduler.
bat_fullcalendar_settings_ajax_callback Ajax callback for bat_fullcalendar_settings form.
bat_fullcalendar_set_css_files Sets up CSS files for fullcalendar and calls an alter to allow other modules to change them.
bat_fullcalendar_set_js_files Sets up JS files for fullcalendar and calls an alter to allow other modules to change them.
bat_fullcalendar_theme Implements hook_theme().
theme_bat_fullcalendar Theme function for FullCalendar.