You are here

function datex_admin_form in Datex 7.2

Same name and namespace in other branches
  1. 7.3 datex.admin.inc \datex_admin_form()
  2. 7 datex.module \datex_admin_form()

Provides administration form for datex module (menu callback).

1 string reference to 'datex_admin_form'
datex_menu in ./datex.module
Implements hook_menu().

File

./datex.admin.inc, line 15

Code

function datex_admin_form($form, $form_state) {
  $form['datex_register_names'] = array(
    '#type' => 'checkbox',
    '#title' => t('Re-register date/time names with t() function.'),
    '#default_value' => '0',
    '#description' => t("In order to make date/time name translatable they must be registererd with Drupal's t() function, This happen during first installation, By checkin this, Registering will run one more time."),
  );
  $form['datex_config'] = array(
    '#type' => 'vertical_tabs',
  );

  // __________________________________________________________GENERAL CONFIG.
  $form['datex'] = array(
    '#type' => 'fieldset',
    '#title' => t('Datex'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'datex_config',
  );
  $options = array(
    DATEX_PATCHING_MODE => t('Operate in patching mode (Pathcing of file <common.inc> is requied).'),
    DATEX_NONPATCHING_MODE => t('Operate in non-patching mode.'),
  );

  // Use PHP-Intl or not.
  $form['datex']['mode'] = array(
    '#type' => 'radios',
    '#title' => t('Date integration mode'),
    '#default_value' => _datex_cfg('mode'),
    '#description' => t('The mode which datex uses to integrate with Drupal. Patching mode needs patching a core file, But will support more modules and functionalities, Non patching mode (by using theming layer and form alters) has a more limited support, But it is safer. If you can ignore some dates not being localized, Then non-patching mode is recomended.'),
    '#options' => $options,
  );
  $options = array(
    1 => t('Use PHP-INTL'),
    0 => t('Use datex internal methods.'),
  );

  // Use PHP-Intl or not.
  $form['datex']['useintl'] = array(
    '#type' => 'radios',
    '#title' => t('Date conversion method'),
    '#options' => $options,
    '#description' => t('Intl is a PHP library for formatting dates, You can install it using php PECL or through your distrubuotion repositories if available, For further help, consult php.org or your operating system website. If you are on a shared hosting, You should ask your host provider to install it for you.'),
  );
  if (!class_exists('IntlDateFormatter')) {
    $markup = t('PHP-Intl is not available in this environment.');
    $disabled = TRUE;
    $default = 0;
  }
  else {
    $markup = t('PHP-Intl is available and may be used.');
    $disabled = FALSE;
    $default = _datex_cfg('useintl');
  }
  $form['datex']['useintl']['#disabled'] = $disabled;
  $form['datex']['useintl']['#default_value'] = $default;
  $form['datex']['datex_api_intl_status'] = array(
    '#type' => 'markup',
    '#title' => t('PHP-Intl status'),
    '#markup' => $markup,
  );
  $options = array();
  foreach (system_get_date_types() as $type) {
    $options[variable_get('date_format_' . $type['type'])] = $type['title'];
  }

  // ________________________________________________ NONPATHCHING ONLY CONFIG.
  if (_datex_cfg('mode') == DATEX_NONPATCHING_MODE) {
    $form['datex_nonpatching'] = array(
      '#type' => 'fieldset',
      '#title' => t('Non-patching mode'),
      '#collapsed' => TRUE,
      '#collapsible' => TRUE,
      '#group' => 'datex_config',
    );
    $form['datex_nonpatching']['node_fmt'] = array(
      '#type' => 'radios',
      '#title' => t('Date format for node display pages.'),
      '#default_value' => _datex_cfg('node_fmt'),
      '#description' => t('Date in node display page will be formatted with this format. Only applicable when using non-patching mode.'),
      '#options' => $options,
    );
    $form['datex_nonpatching']['comment_fmt'] = array(
      '#type' => 'radios',
      '#title' => t('Date format for comment display pages.'),
      '#default_value' => _datex_cfg('comment_fmt'),
      '#description' => t('Date in comment display will be formatted with this format. Only applicable when using non-patching mode.'),
      '#options' => $options,
    );
  }

  // ______________________________________________________________ NEW SCHEMA.
  $form['datex_new_schema'] = array(
    '#type' => 'fieldset',
    '#title' => t('New schema'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#group' => 'datex_config',
  );
  $calendars = _datex_api_available_calendars();
  $options = drupal_map_assoc($calendars);
  $form['datex_new_schema']['datex_new_schema_machine_name'] = array(
    '#title' => t('Schema machine name'),
    '#type' => 'machine_name',
    '#maxlength' => 31,
    '#description' => t('Schema machine readable name containing only letters, Numbers and underscores.'),
    '#machine_name' => array(
      'exists' => '_datex_machine_name',
    ),
    '#required' => FALSE,
  );
  foreach (language_list() as $code => $lang) {
    $t = array(
      '@name' => $lang->name,
      '@native' => $lang->native,
    );
    $name = 'new_datex_' . $code;
    $form['datex_new_schema'][$name] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable datex in @name (@native)', $t),
      '#default_value' => 0,
    );
    $form['datex_new_schema'][$name . '_calendar'] = array(
      '#type' => 'select',
      '#options' => $options,
      '#title' => t('Calendar'),
      '#states' => array(
        'invisible' => array(
          ':input[name="' . $name . '"]' => array(
            'checked' => FALSE,
          ),
        ),
      ),
    );
  }

  // ________________________________________________________ SCHEMA MANAGEMENT.
  $form['datex_schema_manage'] = array(
    '#type' => 'fieldset',
    '#description' => t('Mark schemas to delete after save.'),
    '#title' => t('Manage schemas'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#group' => 'datex_config',
  );
  $header = array(
    'title' => t('Title'),
    'operations' => array(
      'data' => t('Operations'),
    ),
  );
  $options = array();
  foreach (_datex_schema_list() as $name) {
    $operations['edit'] = array(
      'title' => t('edit'),
      'href' => 'admin/config/regional/date-time/datex/edit/' . $name,
    );
    $options[$name] = array(
      'title' => check_plain($name),
      'operations' => array(
        'data' => array(
          '#theme' => 'links__node_operations',
          '#links' => $operations,
          '#attribiutes' => array(
            'class' => array(
              'links',
              'inline',
            ),
          ),
        ),
      ),
    );
  }
  $form['datex_schema_manage']['datex_table'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#element_validate' => array(
      '_datax_schema_table_validate',
    ),
  );

  // _________________________________________________________________ ACTIONS.
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#submit' => array(
      'datex_admin_form_submit',
    ),
    '#value' => t('Save'),
    '#name' => 'config',
  );
  return $form;
}