function library_validate_items in Library 6
Same name and namespace in other branches
- 5.2 library.module \library_validate_items()
- 6.2 library.module \library_validate_items()
Validate Library Item Data for a given node
1 call to library_validate_items()
- library_nodeapi in ./
library.module - Implementation of hook_nodeapi()
File
- ./
library.module, line 893
Code
function library_validate_items($node) {
if (variable_get('library_item_barcodes', LIBRARY_NO_BARCODES) == LIBRARY_BARCODES) {
$items = $node->items;
if ($items) {
global $base_path;
//Check that each barcode is unique
foreach ($items as $key => $item) {
$result = db_result(db_query("SELECT COUNT(*) FROM {library} WHERE barcode = '%s' AND barcode <> ''", $item['barcode']));
if (empty($item['id']) && $result || !empty($item['id']) && $result > 1) {
form_set_error('items][' . $key . '][barcode', t('The barcode %barcode already exists. Please enter a different barcode.', array(
'%barcode' => $item['barcode'],
)));
}
}
}
else {
form_set_error('items', t('You must enter information for at least one item.'));
}
}
}