You are here

function lingotek_setup_new_account_form_submit in Lingotek Translation 7.7

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

New Account - Form Processor Provisions a Lingotek account and sends activation notice.

File

./lingotek.setup.inc, line 144

Code

function lingotek_setup_new_account_form_submit($form, &$form_state) {
  global $base_url;
  $extras = array();

  // Store the info so users dont have to retype stuff
  $first_name = $form_state['values']['first_name'];
  $last_name = $form_state['values']['last_name'];
  $email = $form_state['values']['email'];
  variable_set('lingotek_activation_first_name', $first_name);
  variable_set('lingotek_activation_last_name', $last_name);
  variable_set('lingotek_activation_email', $email);

  // Check the current settings
  $current_community_identifier = variable_get('lingotek_community_identifier', '');
  $current_oauth_consumer_id = variable_get('lingotek_oauth_consumer_id', '');
  $current_oauth_consumer_secret = variable_get('lingotek_oauth_consumer_secret', '');
  $current_login_id = variable_get('lingotek_login_id', '');
  $current_project = variable_get('lingotek_project', '');
  $current_vault = variable_get('lingotek_vault', '');
  $current_workflow = variable_get('lingotek_workflow', '');

  // Provision a new community if any critical data is missing.
  if ($current_community_identifier == '' || $current_oauth_consumer_id == '' || $current_oauth_consumer_secret == '' || $current_login_id == '' || $current_project == '' || $current_vault == '' || $current_workflow == '') {

    // Provision a new Community & Save the Credentials
    $lead = lingotek_identify_lead(array(
      'first_name' => $first_name,
      'last_name' => $last_name,
      'email' => $email,
    ));
    $notify_url = lingotek_notify_url_generate();
    $parameters = array_merge($lead, array(
      'communityDisplayName' => lingotek_get_site_name(),
      'contactName' => $first_name . ' ' . $last_name,
      'contactEmail' => $email,
      'company' => lingotek_get_site_name(),
      //currently we are not asking for this.
      'website' => $base_url,
      'lead' => json_encode($lead),
    ));
    $api = LingotekApi::instance();
    $response = $api
      ->createCommunity($parameters, $notify_url);
    if ($response && $response->results == "success") {
      $community = $response;

      /*
       stdClass::__set_state(array(
       'results' => 'success',
       'community' => 'EDZDDWXA',
       'oauth_key' => '9a7187ea-fad9-41c0-9c0c-3eedbf9dffd0',
       'oauth_secret' => '58f059b9-d167-4f87-b29a-acbc4e0c67c9',
       'external_id' => 'community_admin',
       'tm_vault_id' => 212,
       'workflow_id' => '22092f38-a1f9-4499-b8d4-9e260e7e5d16',
       'project_id' => 411,
       ))
      */
      variable_set('lingotek_community_identifier', $community->community);
      variable_set('lingotek_oauth_consumer_id', $community->oauth_key);
      variable_set('lingotek_oauth_consumer_secret', $community->oauth_secret);
      variable_set('lingotek_login_id', $community->external_id);

      // Used as the 'External ID'.  For old users, this is their login name / email.
      variable_set('lingotek_project', $community->project_id);
      variable_set('lingotek_vault', $community->tm_vault_id);
      variable_set('lingotek_workflow', $community->workflow_id);
      variable_set('lingotek_translate_comments_workflow_id', $community->workflow_id);
      variable_set('lingotek_translate_config_workflow_id', $community->workflow_id);
      variable_set('lingotek_integration_method', $community->integration_method_id);
      variable_set('lingotek_notify_url', $notify_url);
      variable_set('lingotek_cms_tag', $lead['distribution']);
      $_SESSION['lingotek_setup_path'] = array(
        LINGOTEK_MENU_LANG_BASE_URL . '/new-account',
      );
      drupal_set_message(t('Your new Lingotek account has been setup.'));
      drupal_goto(LINGOTEK_MENU_LANG_BASE_URL . '/setup-language-switcher');
    }
    else {

      // If there were any setup or communication problems.
      drupal_set_message(t('There was an error contacting the Lingotek servers to create your account.  Please try again later. [Server: @server]', array(
        '@server' => LINGOTEK_API_SERVER,
      )), 'error');
    }

    // END:  if error.
  }
  else {

    // If the user already has all the required community credentials, just direct them to the next step.
    $_SESSION['lingotek_setup_path'] = array(
      LINGOTEK_MENU_LANG_BASE_URL . '/new-account',
    );
    drupal_set_message(t('Your Lingotek account settings have been saved.'));
    drupal_goto(LINGOTEK_MENU_LANG_BASE_URL . '/setup-language-switcher');
  }
}