You are here

function wordstream_admin_settings in WordStream Keyword Tools 7

Same name and namespace in other branches
  1. 6 wordstream.admin.inc \wordstream_admin_settings()

Displays the form for the standard settings tab.

Return value

array A structured array for use with Forms API.

1 string reference to 'wordstream_admin_settings'
wordstream_menu in ./wordstream.module
Implements hook_menu(). ().

File

./wordstream.admin.inc, line 14
Admin include file.

Code

function wordstream_admin_settings($form, &$form_state) {
  $wordstream = wordstream_include_api_class();
  $account = 0;
  if ($wordstream) {
    $ret = $wordstream
      ->getAPICredits();
    if ($ret->credits_per_month) {
      $account = 1;
    }
  }
  if (!$account) {

    // remove error message from wordstream_include_api_class()
    if (isset($_SESSION['messages']['error'])) {
      unset($_SESSION['messages']['error']);
    }
    drupal_set_message(t('You are unable to log in to WordStream. Please enter a valid WordStream API username and password.'), 'error');
  }

  //dsm($ret);
  $form['wordstream_username'] = array(
    '#type' => 'textfield',
    '#title' => t('WordStream API username'),
    '#description' => t(''),
    '#default_value' => variable_get('wordstream_username', ''),
    '#description' => t('In order to enable the API tools you will need a WordStream account login (username & password). !wordstream_link.', array(
      '!wordstream_link' => l(t('Get your API account here'), WORDSTREAM_LINK_API_ACCOUNT, array(
        'attributes' => array(
          'target',
          'wordstream',
        ),
      )),
    )),
  );
  $form['wordstream_password'] = array(
    '#type' => 'password',
    '#title' => t('WordStream API password'),
    '#description' => t(''),
    '#default_value' => variable_get('wordstream_password', ''),
  );
  $form['wordstream_cache_time'] = array(
    '#type' => 'textfield',
    '#title' => t('Cache time'),
    '#description' => t('API results are cached. Use this value to set in seconds the time before checking if the cache data is out of date.'),
    '#default_value' => variable_get('wordstream_cache_time', WORDSTREAM_CACHE_TIME),
  );
  if ($account) {
    $form['wordstream_account_status'] = array(
      '#type' => 'markup',
      '#value' => '<h3>' . t('Account Status') . '</h3>',
    );
    $form['wordstream_remaining_monthly_credits'] = array(
      '#type' => 'item',
      '#title' => t('Remaining montly credits'),
      '#markup' => $ret->remaining_monthly_credits,
    );
    $form['wordstream_credits_per_month'] = array(
      '#type' => 'item',
      '#title' => t('Credits per month'),
      '#markup' => $ret->credits_per_month,
    );
  }
  $form['wordstream_stats_report_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Stats report options'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['wordstream_stats_report_options'] = array_merge($form['wordstream_stats_report_options'], wordstream_stats_report_form_options());
  return system_settings_form($form);
}