You are here

function lingotek_admin_connection_form in Lingotek Translation 7.3

Same name and namespace in other branches
  1. 7.7 lingotek.admin.inc \lingotek_admin_connection_form()
  2. 7.4 lingotek.admin.inc \lingotek_admin_connection_form()
  3. 7.5 lingotek.admin.inc \lingotek_admin_connection_form()
  4. 7.6 lingotek.admin.inc \lingotek_admin_connection_form()

Lingotek Connection Settings Form

1 string reference to 'lingotek_admin_connection_form'
lingotek_admin_configuration_view in ./lingotek.admin.inc

File

./lingotek.admin.inc, line 721

Code

function lingotek_admin_connection_form($form, &$form_state, $show_fieldset = FALSE) {
  $account = LingotekAccount::instance();
  $api = LingotekApi::instance();
  $force = isset($_GET['test_connection']) ? TRUE : FALSE;
  $connected = $api
    ->testAuthentication($force);
  $is_enterprise = $account
    ->isEnterprise();
  $connection_error = t('Connect this site to your Lingotek account by filling in the fields below. If you do not yet have a Lingotek account, you can <a href="@signup_url">sign up</a> to create an ID and collect OAuth credentials. If all fields are complete, there is a problem with one or more of the values.', array(
    '@signup_url' => url(LINGOTEK_API_SERVER . '/lingopoint/portal/communitySignup.action'),
  ));
  if (!$connected) {
    drupal_set_message($connection_error, 'error');
  }
  else {

    // clear the prior error message
    $errors = drupal_get_messages('error');
    if (isset($errors['error'])) {
      foreach ($errors['error'] as $error) {
        if ($error != $connection_error) {
          drupal_set_message(check_plain($error), 'error');
        }
      }
    }
  }
  $edit_connection = isset($_GET['edit_connection']) || !$connected;
  $status_message = $connected ? t('Status: <b style="color: green;">OK</b>') : t('Status: <b style="color: red;">Not Connected</b>');
  $form['connection'] = array(
    '#type' => $show_fieldset ? 'fieldset' : 'item',
    '#title' => t('Connection') . ' ' . $status_message,
    //'#markup' => $status_message,
    '#collapsible' => TRUE,
    '#collapsed' => !$edit_connection,
    '#group' => 'administrative_settings',
    'actions' => array(
      '#type' => 'actions',
      'submit' => array(
        '#type' => 'submit',
        '#value' => t('Save'),
      ),
    ),
    '#submit' => array(
      'lingotek_admin_connection_form_submit',
    ),
  );

  /* $form['connection'][] = array(
     '#type' => 'item',
     '#description' => filter_xss($connection_group_description),
     ); */
  if ($is_enterprise || $edit_connection) {
    $form['connection']['lingotek_login_id'] = array(
      '#type' => 'textfield',
      '#title' => t('Lingotek ID'),
      '#description' => t('Enter the Lingotek ID you use to access the Lingotek Dashboard and Workbench.'),
      '#default_value' => variable_get('lingotek_login_id', ''),
    );
    $form['connection']['lingotek_oauth_consumer_id'] = array(
      '#type' => 'textfield',
      '#title' => t('OAuth Key'),
      '#description' => t('The OAuth Key used to connect with the Lingotek server.'),
      '#default_value' => variable_get('lingotek_oauth_consumer_id', ''),
    );
    $form['connection']['lingotek_oauth_consumer_secret'] = array(
      '#type' => 'textfield',
      '#title' => t('OAuth Secret'),
      '#description' => t('The OAuth Secret used to connect with the Lingotek server.'),
      '#default_value' => variable_get('lingotek_oauth_consumer_secret', ''),
    );

    // Note: The Lingotek servers may easily be set in code or by setting a 'lingotek_use_stage_servers' drupal variable
    $form['connection']['lingotek_use_stage_servers'] = array(
      '#type' => 'select',
      '#title' => t('Environment'),
      '#options' => array(
        0 => t('Production'),
        1 => t('Staging'),
      ),
      '#description' => LINGOTEK_DEV ? t('Note: The above Environment setting above will be overriden by your local configuration (i.e., settings.php).') : '',
      '#default_value' => variable_get('lingotek_use_stage_servers', 0),
    );
  }
  else {
    $form['connection'][] = array(
      '#type' => 'item',
      '#title' => t('Lingotek Servers'),
      '#markup' => theme('table', array(
        'header' => array(),
        'rows' => array(
          array(
            'TMS:',
            LINGOTEK_API_SERVER,
          ),
          array(
            'GMC:',
            LINGOTEK_GMC_SERVER,
          ),
          array(
            'Billing:',
            LINGOTEK_BILLING_SERVER,
          ),
        ),
      )),
    );
  }

  //$form = system_settings_form($form);
  if (!($is_enterprise || $edit_connection)) {
    unset($form['connection']['actions']);
  }
  return $form;
}