You are here

function library_autocomplete in Library 6

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

Retrieve a pipe delimited string of autocomplete suggestions for library items

1 string reference to 'library_autocomplete'
library_menu in ./library.module
Implementation of hook_menu().

File

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

Code

function library_autocomplete($string) {
  $matches = array();
  if (variable_get('library_item_barcodes', LIBRARY_NO_BARCODES) == LIBRARY_BARCODES) {
    $result = db_query_range("SELECT l.id, l.barcode, n.title FROM {node} n INNER JOIN {library} l ON n.nid = l.nid WHERE n.status = 1 AND n.type <> 'patron' AND l.barcode <> '' AND LOWER(l.barcode) LIKE LOWER('%s%%')", check_plain($string), 0, 10);
    while ($item = db_fetch_object($result)) {
      $matches[$item->barcode . ' [title:' . $item->title . '] [id:' . $item->id . ']'] = check_plain($item->barcode);
    }
  }
  else {
    $result = db_query_range("SELECT DISTINCT l.id, n.title FROM {node} n INNER JOIN {library} l ON n.nid = l.nid WHERE n.status = 1 AND n.type <> 'patron' AND LOWER(n.title) LIKE LOWER('%s%%')", check_plain($string), 0, 10);
    while ($item = db_fetch_object($result)) {
      $my_key = $item->title . ' [id:' . $item->id . ']';
      $matches[$my_key] = check_plain($my_key);
    }
  }
  print drupal_to_js($matches);
  exit;
}