You are here

function scheduler_admin in Scheduler 7

Same name and namespace in other branches
  1. 5 scheduler.module \scheduler_admin()
  2. 6 scheduler.module \scheduler_admin()

Form constructor for the main admin form for configuring Scheduler.

1 string reference to 'scheduler_admin'
scheduler_menu in ./scheduler.module
Implements hook_menu().

File

./scheduler.admin.inc, line 11
Administration forms for the Scheduler module.

Code

function scheduler_admin() {
  $now = t('Example: %date', array(
    '%date' => format_date(REQUEST_TIME, 'custom', variable_get('scheduler_date_format', SCHEDULER_DATE_FORMAT)),
  ));
  $form['scheduler_date_format'] = array(
    '#type' => 'textfield',
    '#title' => t('Date format'),
    '#default_value' => variable_get('scheduler_date_format', SCHEDULER_DATE_FORMAT),
    '#size' => 20,
    '#maxlength' => 20,
    '#required' => TRUE,
    '#field_suffix' => ' <small>' . $now . '</small>',
    '#description' => t('The format for entering scheduled dates and times. For the date use the letters !date_letters and for the time use !time_letters. See !url for more details.', array(
      '!date_letters' => SCHEDULER_DATE_LETTERS,
      '!time_letters' => SCHEDULER_TIME_LETTERS,
      '!url' => l(t('the PHP date() function'), 'http://www.php.net/manual/en/function.date.php'),
    )),
  );
  $form['scheduler_field_type'] = array(
    '#type' => 'radios',
    '#title' => t('Field type'),
    '#default_value' => variable_get('scheduler_field_type', 'date_popup'),
    '#options' => array(
      'textfield' => t('Standard text field'),
      'date_popup' => t('Date Popup calendar'),
    ),
    '#description' => t('Date Popup is enabled. See the !date_popup_config for details.', array(
      '!date_popup_config' => l(t('configuration page'), 'admin/config/date/date_popup'),
    )),
  );
  if (!module_exists('date_popup')) {
    $form['scheduler_field_type']['#default_value'] = 'textfield';
    $form['scheduler_field_type']['#disabled'] = TRUE;
    $form['scheduler_field_type']['#description'] = t('To use the calendar you need to enable Date, Date API and Date Popup. Download the module from the !url.', array(
      '!url' => l(t('Date project page'), 'http://drupal.org/project/date'),
    ));
  }

  // Variable 'date_popup_timepicker' holds the type of timepicker selected.
  $timepicker_enabled = variable_get('date_popup_timepicker', '') != 'none';
  $options = array(
    '@date_popup_config' => url('admin/config/date/date_popup'),
  );
  $description[] = t('Restrict the time entry to specific minute increments.');
  $description[] = $timepicker_enabled ? t('The timepicker type can be selected via the <a href="@date_popup_config">Date Popup configuration page</a>.', $options) : t('The timepicker is not enabled - turn it on via the <a href="@date_popup_config">Date Popup configuration page</a>.', $options);
  $form['scheduler_date_popup_minute_increment'] = array(
    '#type' => 'textfield',
    '#title' => t('Date Popup minute increment'),
    '#description' => implode(' ', $description),
    '#field_suffix' => t('minutes'),
    '#size' => 2,
    '#maxlength' => 2,
    '#disabled' => !$timepicker_enabled,
    '#default_value' => variable_get('scheduler_date_popup_minute_increment', 1),
    '#element_validate' => array(
      'element_validate_integer_positive',
    ),
    '#states' => array(
      'visible' => array(
        ':input[name="scheduler_field_type"]' => array(
          'value' => 'date_popup',
        ),
      ),
    ),
  );

  // Options for setting date-only with default time.
  $form['scheduler_date_only_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Date only'),
    '#collapsible' => FALSE,
  );
  $form['scheduler_date_only_fieldset']['scheduler_allow_date_only'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow users to enter only a date and provide a default time.'),
    '#default_value' => variable_get('scheduler_allow_date_only', FALSE),
    '#description' => t('When only a date is entered the time will default to a specified value, but the user can change this if required.'),
  );
  $form['scheduler_date_only_fieldset']['scheduler_default_time'] = array(
    '#type' => 'textfield',
    '#title' => t('Default time'),
    '#default_value' => variable_get('scheduler_default_time', SCHEDULER_DEFAULT_TIME),
    '#size' => 20,
    '#maxlength' => 20,
    '#description' => t('This is the time that will be used if the user does not enter a value. Format: HH:MM:SS.'),
    '#states' => array(
      'visible' => array(
        ':input[name="scheduler_allow_date_only"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['scheduler_extra_info'] = array(
    '#type' => 'textarea',
    '#title' => t('Extra Info'),
    '#default_value' => variable_get('scheduler_extra_info', ''),
    '#description' => t('The text entered into this field will be displayed above the scheduling fields in the node edit form.'),
  );
  $form['scheduler_cache_clear_all'] = array(
    '#prefix' => '<label>' . t('Cache') . '</label>',
    '#type' => 'checkbox',
    '#title' => t('Clear all expired block and page caches after publishing or unpublishing via cron.'),
    '#default_value' => variable_get('scheduler_cache_clear_all', 0),
    '#description' => t('If a node has been published or unpublished by Scheduler during a cron run, this option will clear the caches instead of relying on the Drupal core system cron task. Warning: This may have a detrimental effect on performance for large sites.'),
  );

  // Add a submit handler function.
  $form['#submit'][] = 'scheduler_admin_submit';
  return system_settings_form($form);
}