You are here

function domain_prefix_configure_form in Domain Access 6.2

Same name and namespace in other branches
  1. 5 domain_prefix/domain_prefix.module \domain_prefix_configure_form()

FormsAPI for generating the configuration form

2 string references to 'domain_prefix_configure_form'
domain_prefix_form in domain_prefix/domain_prefix.admin.inc
The table prefixing page for a domain.
domain_prefix_menu in domain_prefix/domain_prefix.module
Implement hook_menu()

File

domain_prefix/domain_prefix.admin.inc, line 54
Admin page functions for selective table prefixing for use with Domain Access.

Code

function domain_prefix_configure_form() {

  // We must use the settings from the root domain.
  $default = domain_default();
  domain_set_domain($default['domain_id'], TRUE);

  // Get the tables for the root installation.
  $tables = domain_prefix_get_tables();

  // Remove the disallowed tables.
  $disallow = domain_prefix_disallow();

  // Get the current settings.
  $info = variable_get('domain_prefix', NULL);
  $settings = $info['settings'];
  $source_defaults = $info['sources'];
  $form = array();
  $form['domain'] = array(
    '#type' => 'fieldset',
    '#title' => t('Domain creation rules'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['domain']['domain_prefix_options'] = array(
    '#type' => 'radios',
    '#title' => t('Domain creation options'),
    '#description' => t('Determines what actions to take when creating new domain records.'),
    '#options' => array(
      1 => t('Generate tables as defined below'),
      0 => t('Do not generate any tables'),
    ),
    '#default_value' => variable_get('domain_prefix_options', 1),
    '#required' => TRUE,
  );
  $last = '';

  // Flag for module grouping.
  // Get the source table data.
  $root = domain_default();
  foreach ($tables as $table => $info) {
    if (!in_array($table, $disallow) && substr($table, 0, 7) != 'domain_') {
      if (empty($settings[$table])) {
        $settings[$table] = DOMAIN_PREFIX_IGNORE;
        $source_defaults['_source_' . $table] = 0;
      }
      $module = domain_prefix_get_name($info);
      if ($last != $module) {
        $last = $module;
      }
      else {
        $module = '';
      }
      $options = array();
      $options[DOMAIN_PREFIX_IGNORE] = t('ignore');
      $options[DOMAIN_PREFIX_CREATE] = t('create');
      $options[DOMAIN_PREFIX_COPY] = t('copy');
      $form['domain_prefix'][$table] = array(
        '#type' => 'radios',
        '#title' => $table,
        '#options' => $options,
        '#default_value' => $settings[$table],
        '#description' => $module,
      );

      // Get the table copying options for this entry.
      // Can't pass a zero through FormAPI select.
      $sources = array();
      $sources[0] = $root['sitename'];

      // Check to see if other table prefixes have been created.
      $result = db_query("SELECT dp.domain_id, d.sitename FROM {domain_prefix} dp\n        INNER JOIN {domain} d ON dp.domain_id = d.domain_id\n        WHERE dp.tablename = '%s' AND dp.status > %d", $table, 1);
      while ($data = db_fetch_array($result)) {
        $sources[$data['domain_id']] = $data['sitename'];
      }
      $form['domain_source']['_source_' . $table] = array(
        '#type' => 'select',
        '#title' => '',
        '#options' => $sources,
        '#default_value' => $source_defaults['_source_' . $table],
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save prefix settings'),
  );
  $form['restore'] = array(
    '#type' => 'submit',
    '#value' => t('Restore defaults'),
  );

  // Reset the active domain.
  domain_reset_domain(TRUE);
  return $form;
}