You are here

function lingotek_community_select_form in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.setup.inc \lingotek_community_select_form()
  2. 7.2 lingotek.setup.inc \lingotek_community_select_form()
  3. 7.3 lingotek.setup.inc \lingotek_community_select_form()
  4. 7.4 lingotek.setup.inc \lingotek_community_select_form()
  5. 7.5 lingotek.setup.inc \lingotek_community_select_form()

Community Select Screen (for Current Users) - Form

1 string reference to 'lingotek_community_select_form'
lingotek_menu in ./lingotek.module
Implements hook_menu().

File

./lingotek.setup.inc, line 311

Code

function lingotek_community_select_form() {
  $login_id = variable_get('lingotek_login_id', '');
  $password = variable_get('lingotek_password', '');
  $form = array();
  list($success, $msg) = lingotek_list_community_integrations($login_id, $password);
  if ($success == FALSE) {
    drupal_set_message(check_plain($msg), 'error');
    drupal_goto('admin/config/lingotek/account-settings');

    // Shouldnt be here.  So something messed up.  Go back.
  }
  else {
    $community_integrations = $msg;
    $count = count($community_integrations);
    if ($count == 1) {

      // Just one community, use that.
      $ci = array_pop($community_integrations);
      variable_set('lingotek_community_identifier', $ci->community_id);
      variable_set('lingotek_oauth_consumer_id', $ci->key);
      variable_set('lingotek_oauth_consumer_secret', $ci->secret);
      drupal_goto('admin/config/lingotek/project-vault-select');

      // Default path, if they belong to one community.
    }
    elseif ($count > 1) {

      // More than 1 community
      // Stay on this page
    }
    else {

      // 0 Results, we have an error.  Or, we should create a community for them.
      drupal_set_message(t('Error Accessing Account. Please contact customer service.'), 'error');
      drupal_goto('admin/config/lingotek/account-settings');

      // Shouldnt be here.  So something messed up.  Go back.
    }
  }

  // END:  Community Select Paths
  $form['lingotek_user_directions_1'] = array(
    '#markup' => '<p>Your account is associated with multiple Lingotek communities.</p>
    <p>Select the community to associate this site with:</p>',
  );
  $community_options = array();
  foreach ($community_integrations as $ci) {
    $community_options[$ci->community_id] = $ci->community_name . ' (' . $ci->community_id . ')';
  }
  $form['lingotek_site_community'] = array(
    '#title' => t('Community'),
    '#type' => 'select',
    '#options' => $community_options,
    //array_combine(array_keys($communities),array_keys($communities)),

    //'#default_value' => ,

    //'#description' => t( '' ),
    '#required' => TRUE,
  );
  $form['lingotek_communities'] = array(
    '#type' => 'hidden',
    '#value' => json_encode($community_integrations),
  );
  $form['lingotek_button_spacer'] = array(
    '#markup' => '<div>&nbsp;</div>',
  );
  if (is_array($_SESSION['lingotek_setup_path'])) {
    if (end($_SESSION['lingotek_setup_path']) == 'admin/config/lingotek/community-select') {
      $null = array_pop($_SESSION['lingotek_setup_path']);
    }

    // if the user went back, remove the last element, which is this page.
    $form['lingotek_back_button'] = lingotek_setup_link(end($_SESSION['lingotek_setup_path']), t('Previous Step'));
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Next'),
  );
  $form['lingotek_support_footer'] = lingotek_support_footer();
  return $form;
}