You are here

function lingotek_admin_form in Lingotek Translation 6

Same name and namespace in other branches
  1. 7.2 lingotek.admin.inc \lingotek_admin_form()
1 call to lingotek_admin_form()
lingotek_administrative_settings_form in ./lingotek.admin.inc

File

./lingotek.admin.inc, line 167

Code

function lingotek_admin_form() {
  global $_lingotek_client, $_version;
  $site = variable_get('site_name', "Drupal Site");

  //Dashboard Settings
  $form['dash'] = array(
    '#type' => 'fieldset',
    '#title' => t('Dashboard Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'administrative_settings',
  );

  //If projects are available from Lingotek because the above login credentials worked, then display them in a drop list instead of a text box for the Id
  if ($_lingotek_client
    ->canLogIn()) {
    $projects = lingotek_get_projects();
    $id = variable_get('lingotek_project', '');

    // No project id set, project deleted, or community changed to one without that project.  Try to find the Drupal project
    if ($id == '' || !array_key_exists($id, $projects)) {
      $id = array_search($site, $projects);

      // Setup a default Drupal project
      if ($id === False) {
        $id = lingotek_add_project($site);
        $projects = lingotek_get_projects();
      }
      else {
        variable_set('lingotek_project', $id);
      }
    }
    $form['dash']['lingotek_project'] = array(
      '#type' => 'select',
      '#title' => t('Project'),
      '#options' => $projects,
      '#description' => t('Project under which the translations will exist.'),
      '#default_value' => $id,
    );
  }
  else {
    $form['dash']['#description'] = 'Save your Authentication Settings first.  Then you can select projects and vaults by name instead of ID.';
    $form['dash']['lingotek_project'] = array(
      '#type' => 'textfield',
      '#title' => t('Project ID'),
      '#description' => t('Project id under which the translations will exist.'),
      '#default_value' => variable_get('lingotek_project', ''),
    );
  }
  $warning = t('If you want to use Machine Translation, then don\'t use the public vault and you need to add the selected vault to the project within the Lingotek Dashboard.');

  //If vaults are available from Lingotek because the above login credentials worked, then display them in a drop list instead of a text box for the Id
  if ($_lingotek_client
    ->canLogIn()) {
    $vaults = lingotek_get_vaults();
    $id = variable_get('lingotek_vault', '');

    // No vault id set. (Vaults are not community specific, so we don't have to test this like we did the project)  Try to find the Drupal vault
    if ($id == '') {
      $id = array_search($site, $vaults);

      // Setup a default Drupal vault
      if ($id === FALSE) {
        $id = lingotek_add_vault($site);
        $vaults = lingotek_get_vaults();
      }
      else {
        variable_set('lingotek_vault', $id);
      }
    }
    lingotek_add_vault_to_project();
    $form['dash']['lingotek_vault'] = array(
      '#type' => 'select',
      '#title' => t('Vault'),
      '#options' => $vaults,
      '#description' => t('Vault where translations are saved. %warning', array(
        '%warning' => $warning,
      )),
      '#default_value' => $id,
    );
  }
  else {
    $form['dash']['lingotek_vault'] = array(
      '#type' => 'textfield',
      '#title' => t('Vault ID'),
      '#description' => t('Vault id under which the translations will exist. (1 is typically the public vault.) %warning%', array(
        '%warning%' => $warning,
      )),
      '#default_value' => variable_get('lingotek_vault', 1),
    );
  }

  //Drupal Settings
  $form['drupal'] = array(
    '#type' => 'fieldset',
    '#title' => t('Drupal Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'administrative_settings',
  );

  //Display enabled languages for the neutral language setting.
  $options = array();
  foreach (language_list() as $language) {
    if ($language->enabled) {
      $options[$language->language] = $language->native;
    }
  }
  $form['drupal']['lingotek_neutral_language'] = array(
    '#type' => 'select',
    '#title' => t('Neutral Language'),
    '#description' => t('Use this language as the source language when an article is language neutral.'),
    '#options' => $options,
    '#default_value' => variable_get('lingotek_neutral_language', 'en'),
  );
  $form['drupal']['lingotek_menu_overwrite'] = array(
    '#type' => 'checkbox',
    '#title' => t('Overwrite Menus'),
    '#description' => t('Use this to help map menus to nodes point to the correct currently selected language.  This feature requires the Menu Translation module in i18n.'),
    '#default_value' => variable_get('lingotek_menu_overwrite', FALSE),
  );
  if (variable_get('lingotek_menu_overwrite', FALSE)) {
    db_query("UPDATE {system} SET weight = 1 WHERE name = 'i18nmenu'");
  }
  else {
    db_query("UPDATE {system} SET weight = 0 WHERE name = 'i18nmenu'");
  }

  //This setting may not work fluidly with the current version of Lingotek's workbench.
  $form['drupal']['lingotek_use_lightbox'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable Lightbox2'),
    '#description' => t('Use Lightbox2 to display LingoDex.  Disable this if you want it to load in another window.  This feature requires the Lightbox2 module.'),
    '#default_value' => variable_get('lingotek_use_lightbox', FALSE),
    '#disabled' => !module_exists('lightbox2'),
  );

  //Options
  $options = array();
  $options[FALSE] = t("Disabled");
  $options[TRUE] = t("Enabled");

  //Default Settings
  $form['defaults'] = array(
    '#type' => 'fieldset',
    '#title' => t('Page Default Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'administrative_settings',
  );
  $form['defaults']['lingotek_phase_template'] = array(
    '#type' => 'select',
    '#title' => t('Phase Template (Workflow)'),
    '#description' => t('Use this phase template as the default when creating new pages.'),
    '#options' => lingotek_get_phase_templates(),
    '#default_value' => variable_get('lingotek_phase_template', ''),
  );
  $engines = lingotek_get_machine_translation_engines();
  $form['defaults']['lingotek_available_mt_options'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Available Machine Translation Options'),
    '#description' => t('Choose which engines are available to the page creator.'),
    '#options' => $engines,
    '#default_value' => variable_get('lingotek_available_mt_options', array_keys($engines)),
  );

  //Developer Settings
  $form['developer_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Developer Settings'),
    '#description' => t('Help debug any issues with the module and adds ways to manipulate the module\'s data directly.') . ' ' . l(t('(tools)'), 'admin/settings/lingotek/dev'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'administrative_settings',
  );
  $form['developer_settings']['lingotek_error_log'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable Error Log'),
    '#description' => t('This prints errors and warnings to the web server\'s error logs in addition to adding them to watchdog.'),
    '#default_value' => variable_get('lingotek_error_log', FALSE),
  );
  $form['developer_settings']['lingotek_warning_log'] = array(
    '#type' => 'checkbox',
    '#title' => t('Supress Warnings'),
    '#description' => t('This prevents warnings from being sent to watchdog and the web server\'s error logs.'),
    '#default_value' => variable_get('lingotek_warning_log', FALSE),
  );
  $form['developer_settings']['lingotek_trace_log'] = array(
    '#type' => 'checkbox',
    '#title' => t('Supress Trace'),
    '#description' => t('This prevents debug messages from being sent to watchdog and the web server\'s error logs.'),
    '#default_value' => variable_get('lingotek_trace_log', TRUE),
  );
  $form['developer_settings']['lingotek_flush_cache'] = array(
    '#type' => 'checkbox',
    '#title' => t('Never cache'),
    '#description' => t('Skips caching so you can test easier.  This avoids frequent polling of fresh data from Lingotek.  Only those with Developer permissions will have caching disabled.'),
    '#default_value' => variable_get('lingotek_flush_cache', FALSE),
  );

  //Authentication Settings
  $form['auth'] = array(
    '#type' => 'fieldset',
    '#title' => t('Authentication Settings'),
    '#description' => t('Lingotek Module Version 6.22.@revision', array(
      '@revision' => $_version,
    )),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'administrative_settings',
  );
  $form['auth']['lingotek_login_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Login ID'),
    '#description' => t('During flow of control, sometimes a Dashboard login id is not available.  In such instances, this login id will be used.  The only restriction is that the login id must exist in the Dashboard.'),
    '#default_value' => variable_get('lingotek_login_id', ''),
  );
  $form['auth']['lingotek_login_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Login Key'),
    '#description' => t('Key to use authenticating.  The key must be generated by the Lingotek system.  Your password was used once to fetch this key and subsequently deleted.'),
    '#default_value' => variable_get('lingotek_login_key', ''),
  );
  $form['auth']['lingotek_url'] = array(
    '#type' => 'textfield',
    '#title' => t('Lingotek URL'),
    '#description' => t('URL pointing to the Lingotek instance to be used.'),
    '#default_value' => variable_get('lingotek_url', 'http://myaccount.lingotek.com'),
  );
  $form['auth']['lingotek_community'] = array(
    '#type' => 'select',
    '#title' => t('Community'),
    '#description' => t('Community in which the project exists and translations will be made.'),
    '#options' => lingotek_get_communities(),
    '#default_value' => variable_get('lingotek_community', ''),
  );
  return $form;
}