You are here

function services_keyauth_admin_keys_form in Services 6.2

Same name and namespace in other branches
  1. 7 auth/services_keyauth/services_keyauth.admin.inc \services_keyauth_admin_keys_form()

Display the form to create or edit API keys.

1 string reference to 'services_keyauth_admin_keys_form'
services_keyauth_menu in auth/services_keyauth/services_keyauth.module
Implementation of hook_menu().

File

auth/services_keyauth/services_keyauth.admin.inc, line 48
Generate security keys.

Code

function services_keyauth_admin_keys_form() {
  $kid = arg(4);
  $key = db_fetch_object(db_query("SELECT * FROM {services_keys} WHERE kid = '%s'", $kid));
  $key_kid = isset($key->kid) ? $key->kid : '';
  $key_title = isset($key->title) ? $key->title : '';
  $domain = isset($key->domain) ? $key->domain : '';
  $form['kid'] = array(
    '#type' => 'value',
    '#value' => $key_kid,
  );
  $form['previous_domain'] = array(
    '#type' => 'value',
    '#value' => $domain,
  );
  $accessible_methods = array();
  if ($key_kid != '') {
    $form['key'] = array(
      '#type' => 'markup',
      '#title' => t('Key'),
      '#value' => '<strong>' . t('API Key') . ':</strong> ' . $key_kid,
    );
    $result = db_query("SELECT method FROM {services_key_permissions} WHERE kid = '%s'", $key->kid);
    while ($kid = db_fetch_object($result)) {
      $accessible_methods[] = $kid->method;
    }
  }
  $form['title'] = array(
    '#title' => t('Application title'),
    '#type' => 'textfield',
    '#default_value' => $key_title,
    '#description' => t('The title of the application or website using the service.'),
  );
  $form['domain'] = array(
    '#title' => t('Allowed domain'),
    '#type' => 'textfield',
    '#default_value' => $domain,
    '#description' => t('External domain allowed to use this key.'),
    '#required' => TRUE,
  );
  $methods = services_get_all();
  foreach ($methods as $method) {
    $form_methods[$method['method']] = $method['method'];
  }
  $form['method_access'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Method access'),
    '#options' => $form_methods,
    '#default_value' => $accessible_methods,
    '#description' => t('Define which methods are accessible.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => $key_title != '' ? t('Save key') : t('Create key'),
  );
  return $form;
}