You are here

function availability_calendars_admin_settings in Availability Calendars 7.2

Same name and namespace in other branches
  1. 5 availability_calendars.module \availability_calendars_admin_settings()
  2. 6.2 availability_calendars.admin.inc \availability_calendars_admin_settings()
  3. 6 availability_calendars.module \availability_calendars_admin_settings()

Retrieve form callback for the admin/config/availability-calendars/settings page.

Return value

array The form

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

File

./availability_calendars.admin.inc, line 21

Code

function availability_calendars_admin_settings($form) {
  drupal_add_css(drupal_get_path('module', 'availability_calendars') . '/availability_calendars.admin.css', array(
    'every_page' => FALSE,
  ));
  $form['#validate'][] = 'availability_calendars_admin_settings_validate';
  $form['#submit'][] = 'availability_calendars_admin_settings_submit';
  $settings = availability_calendars_get_settings();
  $form['availability_calendars_settings_content_types'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Availability calendar enabled content types'),
    '#description' => t('Availability calendars allows you to enable the calendar component for any content type. Choose the types on which you would like to associate availability calendar.'),
    '#options' => node_type_get_names(),
    '#default_value' => $settings->contenttypes,
  );
  $form['availability_calendars_settings_system_nodeview'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show automatically on node page'),
    '#default_value' => $settings->nodeview,
    '#description' => t("Check whether you want availability calendars to be displayed on the node page. If you don't check this, you will need to output it manually using the %func function.", array(
      '%func' => "theme('availability_calendars_node')",
    )),
  );
  $form['availability_calendars_settings_system_pernodeoverride'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow to override settings per node'),
    '#description' => t("If you check this setting, all settings in the '!block_name' block below will be overridden on a per node basis.", array(
      '!block_name' => t('Global settings'),
    )),
    '#default_value' => $settings->pernodeoverride,
  );
  $form['availability_calendars_settings_system'] = array(
    '#type' => 'fieldset',
    '#title' => t('Global settings'),
    '#description' => t("The following settings define the look & feel of the calendars on a system wide basis. If '!setting_name' is enabled, these can be overridden on a per node basis.", array(
      '!setting_name' => t('Allow to override settings per node'),
    )),
    '#tree' => TRUE,
  );
  $form['availability_calendars_settings_system']['showteaser'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show availability calendars within teasers'),
    '#default_value' => $settings->showteaser,
  );

  // Allow users to choose whether a key should be shown together with the calendar.
  $form['availability_calendars_settings_system']['showkey'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show a key for the availability calendars'),
    '#default_value' => $settings->showkey,
  );

  // Allow users to choose whether the edit link should be shown or not.
  $form['availability_calendars_settings_system']['showeditlink'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show an edit link per month on the edit availability calendars tab'),
    '#description' => t('You will need to enable this option if you want to edit week notes or want to edit the statuses per day using dropdowns.'),
    '#default_value' => $settings->showeditlink,
  );

  // Allow users to choose whether the week notes should be shown or not.
  $form['availability_calendars_settings_system']['showweeknotes'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show a note before each week of the availability calendars'),
    '#default_value' => $settings->showweeknotes,
  );

  // Whether to use only the first letter for the day of the week or not.
  $form['availability_calendars_settings_system']['firstletter'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use only the first letter from the day of the week'),
    '#default_value' => $settings->firstletter,
  );
  $form['availability_calendars_settings_system']['hideold'] = array(
    '#type' => 'checkbox',
    '#title' => t('Do not show availability state of dates in the past'),
    '#default_value' => $settings->hideold,
  );
  $form['availability_calendars_settings_system']['splitday'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow split day statuses'),
    '#default_value' => $settings->splitday,
  );
  $form['availability_calendars_settings_system']['startofweek'] = array(
    '#type' => 'select',
    '#title' => t('First day of week'),
    '#default_value' => $settings->startofweek,
    '#options' => array(
      6 => t('Monday'),
      5 => t('Tuesday'),
      4 => t('Wednesday'),
      3 => t('Thursday'),
      2 => t('Friday'),
      1 => t('Saturday'),
      0 => t('Sunday'),
    ),
  );
  $form['availability_calendars_settings_system']['monthcount'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of months to display'),
    '#default_value' => $settings->monthcount,
    '#description' => t("The number of months to display to normal visitors."),
  );
  $form['availability_calendars_settings_system']['editormonthcount'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of months to display to editors'),
    '#default_value' => $settings->editormonthcount,
    '#description' => t("The number of months to display to visitors who are allowed to edit the calendar to be displayed. Setting this larger than the previous value allows editors to enter information into future calendars before it is made publicly available."),
  );

  // Add states.
  $form['states'] = array(
    '#type' => 'fieldset',
    '#title' => t('States'),
    '#tree' => TRUE,
    '#description' => t('<p>You can modify the availability states here.</p>
      <ul>
        <li>The label is what visitors will see in the legend and what editors will see when editing the calendar.</li>
        <li>The class must be unique and will be used for the css.</li>
        <li>Default defines the status to use for days that have a state not yet set.</li>
        <li>The weight defines the order in the legend and in the dropdown on the edit form.</li>
        <li>The "is available" checkbox defines whether this state should be treated as available in searches.</li>
        <li>Make a label empty to remove the row.</li>
        <li>If there are no more empty lines to add new states, save the form and you will be able to add another state.</li>
        <li><strong>Changes made to existing classes will not be updated in existing calendars!</strong> So do not change on live sites.</li>
        <li>If you define new classes, visit the styling page to define its colors.</li>
      </ul>
    '),
    '#attributes' => array(
      'class' => array(
        'state-list',
      ),
    ),
  );
  $element =& $form['states'];
  $i = 0;
  foreach ($settings->states as $state) {
    availability_calendars_admin_settings_add_state($element, $i, $state, $settings);
    $i++;
  }

  // Show a minimum of 4 available states with at least one empty state.
  do {
    availability_calendars_admin_settings_add_state($element, $i, array(
      'css_class' => '',
      'label' => '',
      'weight' => 0,
      'is_available' => 0,
    ), $settings);
    $i++;
  } while ($i < 4);
  return system_settings_form($form);
}