if ($db->next_record()) { alloc_redirect($TPL["url_alloc_item"] . "itemID=" . $db->f("itemID")); } } else { //open the index $index = new Zend_Search_Lucene(ATTACHMENTS_DIR . 'search/item'); $query = Zend_Search_Lucene_Search_QueryParser::parse($needle); $hits = $index->find($needle); $TPL["index_count"] = $index->count(); $TPL["hits_count"] = count($hits); $p =& get_cached_table("person"); foreach ($hits as $hit) { $d = $hit->getDocument(); $item = new item(); $item->set_id($d->getFieldValue('id')); $item->select(); $row = array(); $row["idx"] = $hit->id; $author = $item->get_value("itemAuthor"); $author and $author = " by " . $author; $row["title"] = $item->get_id() . " " . $item->get_link() . $author; $row["score"] = sprintf('%d%%', $hit->score * 100); $row["desc"] = page::htmlentities($d->getFieldValue('desc')); // get availability of loan $db2 = new db_alloc(); $query = prepare("SELECT * FROM loan WHERE itemID = %d AND dateReturned='0000-00-00'", $item->get_id()); $db2->query($query); if ($db2->next_record()) { $loan = new loan(); $loan->read_db_record($db2); if ($loan->have_perm(PERM_READ_WRITE)) {