You are here

lingotek.admin.inc in Lingotek Translation 6

File

lingotek.admin.inc
View source
<?php

/**
 * @file
 * Administrative Settings for the module
 */
include_once 'lingotek.session.inc';
preg_match('.Revision: (\\d+) .', '$Revision: 24094 $', $revision);
$GLOBALS['_version'] = $revision[1];

/*
 * Implementation of hook_settings_page
 *
 * Get the form for the view lingotek administration page
 */
function lingotek_settings_page() {
  return drupal_get_form('lingotek_administrative_settings_form');
}

/*
 * Admistration Form for configuring the Lingotek Module.
 */
function lingotek_administrative_settings_form() {
  global $_lingotek_client;
  $login = variable_get('lingotek_login_id', '');
  $key = variable_get('lingotek_login_key', '');
  $password = variable_get('lingotek_password', '');
  $community = variable_get('lingotek_community', '');
  $wizard = "full";
  if ($_lingotek_client
    ->canLogIn()) {
    if ($community == '') {
      $communities = lingotek_get_communities();
      $num = count($communities);

      //User doesn't have any communities.  This should rarely happen.
      if ($num == 0) {
        $wizard = "signup";
        drupal_set_message(t("Your user isn't part of any community.  Please correct this with Lingotek."), 'error');
      }
      elseif ($num == 1) {
        $wizard = "full";
        reset($communities);
        variable_set('lingotek_community', key($communities));
        variable_set('lingotek_login_key', lingotek_get_cms_key());
      }
      else {
        $wizard = "community";
      }
    }
    else {
      variable_set('lingotek_login_key', lingotek_get_cms_key());
    }
  }
  else {
    $wizard = "signup";
    if ($password != '' && $login != '') {
      drupal_set_message(t("Login incorrect."), 'error');
      variable_del('lingotek_password');
    }
  }
  switch ($wizard) {
    case "signup":
      $form = lingotek_signup_form();
      break;
    case "community":

      //Get Community, this step could be skipped if only a member of a single community.
      $form = lingotek_community_form();
      break;
    case "full":
    default:
      $form = lingotek_admin_form();
  }
  return system_settings_form($form);
}
function lingotek_community_form() {
  global $_version;
  $form['auth'] = array(
    '#type' => 'fieldset',
    '#title' => t('Community Setting'),
    '#description' => t('Lingotek Module Version 6.22.@revision', array(
      '@revision' => $_version,
    )),
  );
  $form['auth']['lingotek_community'] = array(
    '#type' => 'select',
    '#title' => t('Community'),
    '#description' => t('Use this community to sign and store translations in.'),
    '#options' => lingotek_get_communities(),
    '#default_value' => variable_get('lingotek_community', ''),
  );
  return $form;
}
function lingotek_signup_form() {
  global $_version;
  $form['auth'] = array(
    '#type' => 'fieldset',
    '#title' => t('Authentication Settings'),
    '#description' => t('Lingotek Module Version 6.22.@revision<br />Please login using your existing Lingotek ID, or click !link if you need to create a new account.', array(
      '@revision' => $_version,
      '!link' => l(t("here"), variable_get('lingotek_url', 'http://myaccount.lingotek.com') . "/lingopoint/portal/communitySignup.action"),
    )),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#group' => 'administrative_settings',
  );
  $form['auth']['lingotek_login_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Login ID'),
    '#description' => t('Lingotek User ID'),
    '#default_value' => variable_get('lingotek_login_id', ''),
  );
  $form['auth']['lingotek_password'] = array(
    '#type' => 'password',
    '#title' => t('Password'),
    '#description' => t('Lingotek Password'),
    '#default_value' => '',
  );

  //Advanced settings
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced Settings'),
    '#description' => t('These settings will only be changed in rare cases.  If your user is not a Community Admin on the Lingotek platform, then you will need to authenticate here.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'administrative_settings',
  );
  $form['advanced']['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['advanced']['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 and it specific to a community.'),
    '#default_value' => variable_get('lingotek_login_key', ''),
  );
  $form['advanced']['lingotek_community'] = array(
    '#type' => 'textfield',
    '#title' => t('Community ID'),
    '#description' => t('Community in which the project exists and translations will be made.'),
    '#default_value' => variable_get('lingotek_community', ''),
  );
  return $form;
}
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;
}