You are here

function library_update_items in Library 6.2

Same name and namespace in other branches
  1. 5.2 library.module \library_update_items()
  2. 6 library.module \library_update_items()

Update Library Item Data for a given node

1 call to library_update_items()
library_nodeapi in ./library.module
Implementation of hook_nodeapi()

File

./library.module, line 872

Code

function library_update_items($node) {
  $items = $node->items;
  $row = 0;
  if ($items) {
    foreach ($items as $key => $item) {
      if ($item['delete'] == 1) {
        db_query('DELETE FROM {library} WHERE id = %d', $item['id']);
        unset($node->items[$key]);
      }
      elseif (empty($item['id'])) {
        db_query("INSERT INTO {library} (nid, barcode, in_circulation, library_status, notes, created) VALUES (%d, '%s', %d, %d, '%s', %d)", $node->nid, check_plain($item['barcode'] . ''), $item['in_circulation'], LIBRARY_ITEM_AVAILABLE, $item['notes'], time());
        $node->items[$row]['id'] = db_last_insert_id('library', 'id');
      }
      else {
        db_query("UPDATE {library} SET barcode = '%s', in_circulation = %d, notes = '%s' WHERE id = %d", check_plain($item['barcode'] . ''), $item['in_circulation'], check_plain($item['notes']), $item['id']);
      }
      $row++;
    }
  }
}