You are here

function library_admin_action in Library 6

Same name and namespace in other branches
  1. 5.2 library.admin.inc \library_admin_action()
  2. 6.2 library.admin.inc \library_admin_action()
  3. 7 library.admin.inc \library_admin_action()

Menu callback: Edit Library Action.

See also

library_admin_action_validate()

library_admin_action_submit()

theme_library_admin_new_action()

2 string references to 'library_admin_action'
library_forms in ./library.module
Implementation of hook_forms().
library_menu in ./library.module
Implementation of hook_menu().

File

./library.admin.inc, line 242
Administrative settings for the library module

Code

function library_admin_action() {
  $aid = arg(5);
  if ($aid) {

    // Display the edit action form.
    $action = library_get_action($aid);
    $show_delete = TRUE;
    if ($action && $action->status_change > 0) {
      $result = db_result(db_query("SELECT COUNT(*) FROM {library_actions} WHERE status_change = '%d' AND aid <> %d", $action->status_change, $action->aid));
      if ($result) {
      }
      else {
        $show_delete = FALSE;
      }
    }
    $form['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Action name'),
      '#default_value' => $action->name,
      '#size' => 20,
      '#required' => TRUE,
      '#maxlength' => 60,
      '#description' => t('The name for this action.'),
    );
    $form['status_change'] = array(
      '#type' => 'radios',
      '#title' => t('Status Change'),
      '#description' => t('How this action changes the status of a library item.'),
      '#default_value' => isset($action->status_change) ? $action->status_change : 0,
      '#options' => array(
        LIBRARY_ACTION_NO_CHANGE => t('No Change'),
        LIBRARY_ACTION_TYPE_UNAVAILABLE => t('Unavailable'),
        LIBRARY_ACTION_TYPE_AVAILABLE => t('Available'),
      ),
    );
    $form['aid'] = array(
      '#type' => 'value',
      '#value' => $aid,
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save action'),
    );
    if ($show_delete) {
      $form['delete'] = array(
        '#type' => 'submit',
        '#value' => t('Delete action'),
      );
    }
  }
  else {
    $form['name'] = array(
      '#type' => 'textfield',
      '#size' => 20,
      '#maxlength' => 60,
    );
    $form['status_change'] = array(
      '#type' => 'radios',
      '#default_value' => 0,
      '#options' => array(
        LIBRARY_ACTION_NO_CHANGE => t('No Change'),
        LIBRARY_ACTION_TYPE_UNAVAILABLE => t('Unavailable'),
        LIBRARY_ACTION_TYPE_AVAILABLE => t('Available'),
      ),
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Add action'),
    );
    $form['#submit'][] = 'library_admin_action_submit';
    $form['#validate'][] = 'library_admin_action_validate';
  }
  return $form;
}