You are here

function library_update_items in Library 5.2

Same name and namespace in other branches
  1. 6.2 library.module \library_update_items()
  2. 6 library.module \library_update_items()
1 call to library_update_items()
library_nodeapi in ./library.module
Implementation of hook_nodeapi()

File

./library.module, line 859

Code

function library_update_items($node) {
  $items = $node->items;
  $row = 0;
  foreach ($items as $key => $item) {
    if ($item['delete'] == 1) {
      db_query('DELETE FROM {library} WHERE id = %d', $item['id']);
      unset($node->items[$key]);
    }
    else {
      if (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++;
  }
}