3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
25 # FIXME - C4::Search uses C4::Reserves2, which uses C4::Search.
26 # So Perl complains that all of the functions here get redefined.
29 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
31 # set the version for version checking
32 $VERSION = do { my @v = '$Revision$' =~ /\d+/g;
33 shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
37 C4::Search - Functions for searching the Koha catalog and other databases
43 my ($count, @results) = catalogsearch($env, $type, $search, $num, $offset);
47 This module provides the searching facilities for the Koha catalog and
50 C<&catalogsearch> is a front end to all the other searches. Depending
51 on what is passed to it, it calls the appropriate search function.
61 &CatSearch &BornameSearch &ItemInfo &KeywordSearch &subsearch
62 &itemdata &bibdata &GetItems &borrdata &itemnodata &itemcount
63 &borrdata2 &NewBorrowerNumber &bibitemdata &borrissues
64 &getboracctrecord &ItemType &itemissues &subject &subtitle
65 &addauthor &bibitems &barcodes &findguarantees &allissues
66 &findguarantor &getwebsites &getwebbiblioitems &catalogsearch &itemcount2
67 &isbnsearch &breedingsearch &getbranchname &getborrowercategory);
68 # make all your functions, whether exported or not;
73 ($num_children, $children_arrayref) = &findguarantees($parent_borrno);
74 $child0_cardno = $children_arrayref->[0]{"cardnumber"};
75 $child0_borrno = $children_arrayref->[0]{"borrowernumber"};
77 C<&findguarantees> takes a borrower number (e.g., that of a patron
78 with children) and looks up the borrowers who are guaranteed by that
79 borrower (i.e., the patron's children).
81 C<&findguarantees> returns two values: an integer giving the number of
82 borrowers guaranteed by C<$parent_borrno>, and a reference to an array
83 of references to hash, which gives the actual results.
89 my $dbh = C4::Context->dbh;
90 my $sth=$dbh->prepare("select cardnumber,borrowernumber, firstname, surname from borrowers where guarantor=?");
91 $sth->execute($bornum);
94 while (my $data = $sth->fetchrow_hashref)
99 return (scalar(@dat), \@dat);
104 $guarantor = &findguarantor($borrower_no);
105 $guarantor_cardno = $guarantor->{"cardnumber"};
106 $guarantor_surname = $guarantor->{"surname"};
109 C<&findguarantor> takes a borrower number (presumably that of a child
110 patron), finds the guarantor for C<$borrower_no> (the child's parent),
111 and returns the record for the guarantor.
113 C<&findguarantor> returns a reference-to-hash. Its keys are the fields
114 from the C<borrowers> database table;
120 my $dbh = C4::Context->dbh;
121 my $sth=$dbh->prepare("select guarantor from borrowers where borrowernumber=?");
122 $sth->execute($bornum);
123 my $data=$sth->fetchrow_hashref;
125 $sth=$dbh->prepare("Select * from borrowers where borrowernumber=?");
126 $sth->execute($data->{'guarantor'});
127 $data=$sth->fetchrow_hashref;
132 =item NewBorrowerNumber
134 $num = &NewBorrowerNumber();
136 Allocates a new, unused borrower number, and returns it.
140 # FIXME - This is identical to C4::Circulation::Borrower::NewBorrowerNumber.
141 # Pick one and stick with it. Preferably use the other one. This function
142 # doesn't belong in C4::Search.
143 sub NewBorrowerNumber {
144 my $dbh = C4::Context->dbh;
145 my $sth=$dbh->prepare("Select max(borrowernumber) from borrowers");
147 my $data=$sth->fetchrow_hashref;
149 $data->{'max(borrowernumber)'}++;
150 return($data->{'max(borrowernumber)'});
155 ($count, @results) = &catalogsearch($env, $type, $search, $num, $offset);
157 This is primarily a front-end to other, more specialized catalog
158 search functions: if C<$search-E<gt>{itemnumber}> or
159 C<$search-E<gt>{isbn}> is given, C<&catalogsearch> uses a precise
160 C<&CatSearch>. If $search->{subject} is given, it runs a subject
161 C<&CatSearch>. If C<$search-E<gt>{keyword}> is given, it runs a
162 C<&KeywordSearch>. Otherwise, it runs a loose C<&CatSearch>.
164 If C<$env-E<gt>{itemcount}> is 1, then C<&catalogsearch> also counts
165 the items for each result, and adds several keys:
171 The total number of copies of this book.
173 =item C<locationhash>
175 This is a reference-to-hash; the keys are the names of branches where
176 this book may be found, and the values are the number of copies at
181 A descriptive string saying where the book is located, and how many
182 copies there are, if greater than 1.
186 The book's subject, with spaces replaced with C<%20>, presumably for
194 my ($env,$type,$search,$num,$offset)=@_;
195 my $dbh = C4::Context->dbh;
196 # foreach my $key (%$search){
197 # $search->{$key}=$dbh->quote($search->{$key});
199 my ($count,@results);
200 if ($search->{'itemnumber'} ne '' || $search->{'isbn'} ne ''){
201 print STDERR "Doing a precise search\n";
202 ($count,@results)=CatSearch($env,'precise',$search,$num,$offset);
203 } elsif ($search->{'subject'} ne ''){
204 ($count,@results)=CatSearch($env,'subject',$search,$num,$offset);
205 } elsif ($search->{'keyword'} ne ''){
206 ($count,@results)=&KeywordSearch($env,'keyword',$search,$num,$offset);
208 ($count,@results)=CatSearch($env,'loose',$search,$num,$offset);
211 if ($env->{itemcount} eq '1') {
212 foreach my $data (@results){
213 my ($counts) = itemcount2($env, $data->{'biblionumber'}, 'intra');
214 my $subject2=$data->{'subject'};
215 $subject2=~ s/ /%20/g;
216 $data->{'itemcount'}=$counts->{'total'};
217 my $totalitemcounts=0;
218 foreach my $key (keys %$counts){
219 if ($key ne 'total'){ # FIXME - Should ignore 'order', too.
220 #$data->{'location'}.="$key $counts->{$key} ";
221 $totalitemcounts+=$counts->{$key};
222 $data->{'locationhash'}->{$key}=$counts->{$key};
226 my $locationtextonly='';
227 my $notavailabletext='';
228 foreach (sort keys %{$data->{'locationhash'}}) {
229 if ($_ eq 'notavailable') {
230 $notavailabletext="Not available";
231 my $c=$data->{'locationhash'}->{$_};
232 $data->{'not-available-p'}=$totalitemcounts;
233 if ($totalitemcounts>1) {
234 $notavailabletext.=" ($c)";
235 $data->{'not-available-plural-p'}=1;
239 my $c=$data->{'locationhash'}->{$_};
240 if ($_ eq 'Item Lost') {
241 $data->{'lost-p'}=$totalitemcounts;
242 $data->{'lost-plural-p'}=1
243 if $totalitemcounts > 1;
244 } elsif ($_ eq 'Withdrawn') {
245 $data->{'withdrawn-p'}=$totalitemcounts;
246 $data->{'withdrawn-plural-p'}=1
247 if $totalitemcounts > 1;
248 } elsif ($_ eq 'On Loan') {
249 $data->{'on-loan-p'}=$totalitemcounts;
250 $data->{'on-loan-plural-p'}=1
251 if $totalitemcounts > 1;
253 $locationtextonly.=$_;
254 $locationtextonly.=" ($c), "
255 if $totalitemcounts>1;
257 if ($totalitemcounts>1) {
258 $locationtext.=" ($c), ";
262 if ($notavailabletext) {
263 $locationtext.=$notavailabletext;
265 $locationtext=~s/, $//;
267 $data->{'location'}=$locationtext;
268 $data->{'location-only'}=$locationtextonly;
269 $data->{'subject2'}=$subject2;
270 $data->{'use-location-flags-p'}=1; # XXX
273 return ($count,@results);
278 $search = { "keyword" => "One or more keywords",
279 "class" => "VID|CD", # Limit search to fiction and CDs
282 ($count, @results) = &KeywordSearch($env, $type, $search, $num, $offset);
284 C<&KeywordSearch> searches the catalog by keyword: given a string
285 (C<$search-E<gt>{"keyword"}> consisting of a space-separated list of
286 keywords, it looks for books that contain any of those keywords in any
287 of a number of places.
289 C<&KeywordSearch> looks for keywords in the book title (and subtitle),
290 series name, notes (both C<biblio.notes> and C<biblioitems.notes>),
293 C<$search-E<gt>{"class"}> can be set to a C<|> (pipe)-separated list of
294 item class codes (e.g., "F" for fiction, "JNF" for junior nonfiction,
295 etc.). In this case, the search will be restricted to just those
298 If C<$search-E<gt>{"class"}> is not specified, you may specify
299 C<$search-E<gt>{"dewey"}>. This will restrict the search to that
300 particular Dewey Decimal Classification category. Setting
301 C<$search-E<gt>{"dewey"}> to "513" will return books about arithmetic,
302 whereas setting it to "5" will return all books with Dewey code 5I<xx>
303 (Science and Mathematics).
305 C<$env> and C<$type> are ignored.
307 C<$offset> and C<$num> specify the subset of results to return.
308 C<$num> specifies the number of results to return, and C<$offset> is
309 the number of the first result. Thus, setting C<$offset> to 100 and
310 C<$num> to 5 will return results 100 through 104 inclusive.
315 my ($env,$type,$search,$num,$offset)=@_;
316 my $dbh = C4::Context->dbh;
317 $search->{'keyword'}=~ s/ +$//;
318 my @key=split(' ',$search->{'keyword'});
319 # FIXME - Naive users might enter comma-separated
320 # words, e.g., "training, animal". Ought to cope with
324 my %biblionumbers; # Set of biblionumbers returned by the
327 # FIXME - Ought to filter the stopwords out of the list of keywords.
328 # @key = map { !defined($stopwords{$_}) } @key;
330 # FIXME - The way this code is currently set up, it looks for all of
331 # the keywords first in (title, notes, seriestitle), then in the
332 # subtitle, then in the subject. Thus, if you look for keywords
333 # "science fiction", this search won't find a book with
334 # title = "How to write fiction"
335 # subtitle = "A science-based approach"
336 # Is this the desired effect? If not, then the first SQL query
337 # should look in the biblio, subtitle, and subject tables all at
338 # once. The way the first query is built can accomodate this easily.
340 # Look for keywords in table 'biblio'.
342 # Build an SQL query that finds each of the keywords in any of the
343 # title, biblio.notes, or seriestitle. To do this, we'll build up an
344 # array of clauses, one for each keyword.
345 my $query; # The SQL query
346 my @clauses = (); # The search clauses
347 my @bind = (); # The term bindings
349 $query = <<EOT; # Beginning of the query
354 foreach my $keyword (@key)
356 my @subclauses = (); # Subclauses, one for each field we're
359 # For each field we're searching on, create a subclause that'll
360 # match the current keyword in the current field.
361 foreach my $field (qw(title notes seriestitle author))
364 "$field LIKE ? OR $field LIKE ?";
365 push(@bind,"\Q$keyword\E%","% \Q$keyword\E%");
367 # (Yes, this could have been done as
368 # @subclauses = map {...} qw(field1 field2 ...)
369 # )but I think this way is more readable.
371 # Construct the current clause by joining the subclauses.
372 push @clauses, "(" . join(")\n\tOR (", @subclauses) . ")";
374 # Now join all of the clauses together and append to the query.
375 $query .= "(" . join(")\nAND (", @clauses) . ")";
377 # FIXME - Perhaps use $sth->bind_columns() ? Documented as the most
378 # efficient way to fetch data.
379 my $sth=$dbh->prepare($query);
380 $sth->execute(@bind);
381 while (my @res = $sth->fetchrow_array) {
384 $biblionumbers{$_} = 1; # Add these results to the set
389 # Now look for keywords in the 'bibliosubtitle' table.
391 # Again, we build a list of clauses from the keywords.
394 $query = "SELECT biblionumber FROM bibliosubtitle WHERE ";
395 foreach my $keyword (@key)
398 "subtitle LIKE ? OR subtitle like ?";
399 push(@bind,"\Q$keyword\E%","% \Q$keyword\E%");
401 $query .= "(" . join(") AND (", @clauses) . ")";
403 $sth=$dbh->prepare($query);
404 $sth->execute(@bind);
405 while (my @res = $sth->fetchrow_array) {
408 $biblionumbers{$_} = 1; # Add these results to the set
413 # Look for the keywords in the notes for individual items
414 # ('biblioitems.notes')
416 # Again, we build a list of clauses from the keywords.
419 $query = "SELECT biblionumber FROM biblioitems WHERE ";
420 foreach my $keyword (@key)
423 "notes LIKE ? OR notes like ?";
424 push(@bind,"\Q$keyword\E%","% \Q$keyword\E%");
426 $query .= "(" . join(") AND (", @clauses) . ")";
428 $sth=$dbh->prepare($query);
429 $sth->execute(@bind);
430 while (my @res = $sth->fetchrow_array) {
433 $biblionumbers{$_} = 1; # Add these results to the set
438 # Look for keywords in the 'bibliosubject' table.
440 # FIXME - The other queries look for words in the desired field that
441 # begin with the individual keywords the user entered. This one
442 # searches for the literal string the user entered. Is this the
444 # Note in particular that spaces are retained: if the user typed
446 # (with two spaces), this won't find the subject "science fiction"
447 # (one space). Likewise, a search for "%" will return absolutely
449 # If this isn't the desired effect, see the previous searches for
452 $sth=$dbh->prepare("Select biblionumber from bibliosubject where subject
453 like ? group by biblionumber");
454 $sth->execute("%$search->{'keyword'}%");
456 while (my @res = $sth->fetchrow_array) {
459 $biblionumbers{$_} = 1; # Add these results to the set
469 my @res = keys %biblionumbers;
473 # print "count $count";
474 if ($search->{'class'} ne ''){
476 my $query="select * from biblio,biblioitems where
477 biblio.biblionumber=? and
478 biblio.biblionumber=biblioitems.biblionumber ";
479 my @bind = ($res[$i2]);
480 if ($search->{'class'} ne ''){ # FIXME - Redundant
481 my @temp=split(/\|/,$search->{'class'});
483 $query.= "and ( itemtype=?";
484 push(@bind,$temp[0]);
485 for (my $i=1;$i<$count;$i++){
486 $query.=" or itemtype=?";
487 push(@bind,$temp[$i]);
491 my $sth=$dbh->prepare($query);
493 $sth->execute(@bind);
494 if (my $data2=$sth->fetchrow_hashref){
495 my $dewey= $data2->{'dewey'};
496 my $subclass=$data2->{'subclass'};
497 # FIXME - This next bit is bogus, because it assumes that the
498 # Dewey code is a floating-point number. It isn't. It's
499 # actually a string that mainly consists of numbers. In
500 # particular, "4" is not a valid Dewey code, although "004"
501 # is ("Data processing; Computer science"). Likewise, zeros
502 # after the decimal are significant ("575" is not the same as
503 # "575.0"; the latter is more specific). And "000" is a
504 # perfectly good Dewey code ("General works; computer
505 # science") and should not be interpreted to mean "this
506 # database entry does not have a Dewey code". That's what
509 ($dewey == 0) && ($dewey='');
510 ($dewey) && ($dewey.=" $subclass") ;
512 my $end=$offset +$num;
517 if ($i4 <=$end && $i4 > $offset){
518 $data2->{'dewey'}=$dewey;
521 # $res2[$i3]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey";
524 # print "in here $i3<br>";
535 # $search->{'class'} was not specified
537 # FIXME - This is bogus: it makes a separate query for each
538 # biblioitem, and returns results in apparently random order. It'd
539 # be much better to combine all of the previous queries into one big
540 # one (building it up a little at a time, of course), and have that
541 # big query select all of the desired fields, instead of just
544 while ($i2 < $num && $i2 < $count){
545 my $query="select * from biblio,biblioitems where
546 biblio.biblionumber=? and
547 biblio.biblionumber=biblioitems.biblionumber ";
548 my @bind=($res[$i2+$offset]);
550 if ($search->{'dewey'} ne ''){
551 $query.= "and (dewey like ?)";
552 push(@bind,"$search->{'dewey'}%");
555 my $sth=$dbh->prepare($query);
557 $sth->execute(@bind);
558 if (my $data2=$sth->fetchrow_hashref){
559 my $dewey= $data2->{'dewey'};
560 my $subclass=$data2->{'subclass'};
562 ($dewey == 0) && ($dewey='');
563 ($dewey) && ($dewey.=" $subclass") ;
565 $data2->{'dewey'}=$dewey;
568 # $res2[$i]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey";
577 return($count,@res2);
581 my ($env,$type,$search,$num,$offset)=@_;
582 my $dbh = C4::Context->dbh;
583 $search->{'keyword'}=~ s/ +$//;
584 my @key=split(' ',$search->{'keyword'});
588 my $query ="Select * from biblio,bibliosubtitle,biblioitems where
589 biblio.biblionumber=biblioitems.biblionumber and
590 biblio.biblionumber=bibliosubtitle.biblionumber and
591 (((title like ? or title like ?)";
592 my @bind=("$key[0]%","% $key[0]%");
594 $query .= " and (title like ? or title like ?)";
595 push(@bind,"$key[$i]%","% $key[$i]%");
598 $query.= ") or ((subtitle like ? or subtitle like ?)";
599 push(@bind,"$key[0]%","% $key[0]%");
600 for ($i=1;$i<$count;$i++){
601 $query.= " and (subtitle like ? or subtitle like ?)";
602 push(@bind,"$key[$i]%","% $key[$i]%");
604 $query.= ") or ((seriestitle like ? or seriestitle like ?)";
605 push(@bind,"$key[0]%","% $key[0]%");
606 for ($i=1;$i<$count;$i++){
607 $query.=" and (seriestitle like ? or seriestitle like ?)";
608 push(@bind,"$key[$i]%","% $key[$i]%");
610 $query.= ") or ((biblio.notes like ? or biblio.notes like ?)";
611 push(@bind,"$key[0]%","% $key[0]%");
612 for ($i=1;$i<$count;$i++){
613 $query.=" and (biblio.notes like ? or biblio.notes like ?)";
614 push(@bind,"$key[$i]%","% $key[$i]%");
616 $query.= ") or ((biblioitems.notes like ? or biblioitems.notes like ?)";
617 push(@bind,"$key[0]%","% $key[0]%");
618 for ($i=1;$i<$count;$i++){
619 $query.=" and (biblioitems.notes like ? or biblioitems.notes like ?)";
620 push(@bind,"$key[$i]%","% $key[$i]%");
622 if ($search->{'keyword'} =~ /new zealand/i){
623 $query.= "or (title like 'nz%' or title like '% nz %' or title like '% nz' or subtitle like 'nz%'
624 or subtitle like '% nz %' or subtitle like '% nz' or author like 'nz %'
625 or author like '% nz %' or author like '% nz')"
627 if ($search->{'keyword'} eq 'nz' || $search->{'keyword'} eq 'NZ' ||
628 $search->{'keyword'} =~ /nz /i || $search->{'keyword'} =~ / nz /i ||
629 $search->{'keyword'} =~ / nz/i){
630 $query.= "or (title like 'new zealand%' or title like '% new zealand %'
631 or title like '% new zealand' or subtitle like 'new zealand%' or
632 subtitle like '% new zealand %'
633 or subtitle like '% new zealand' or author like 'new zealand%'
634 or author like '% new zealand %' or author like '% new zealand' or
635 seriestitle like 'new zealand%' or seriestitle like '% new zealand %'
636 or seriestitle like '% new zealand')"
639 if ($search->{'class'} ne ''){
640 my @temp=split(/\|/,$search->{'class'});
642 $query.= "and ( itemtype=?";
643 push(@bind,"$temp[0]");
644 for (my $i=1;$i<$count;$i++){
645 $query.=" or itemtype=?";
646 push(@bind,"$temp[$i]");
650 if ($search->{'dewey'} ne ''){
651 $query.= "and (dewey like '$search->{'dewey'}%') ";
653 $query.="group by biblio.biblionumber";
654 #$query.=" order by author,title";
656 my $sth=$dbh->prepare($query);
657 $sth->execute(@bind);
659 while (my $data=$sth->fetchrow_hashref){
660 #FIXME: rewrite to use ? before uncomment
661 # my $sti=$dbh->prepare("select dewey,subclass from biblioitems where biblionumber=$data->{'biblionumber'}
664 # my ($dewey, $subclass) = $sti->fetchrow;
665 my $dewey=$data->{'dewey'};
666 my $subclass=$data->{'subclass'};
668 ($dewey == 0) && ($dewey='');
669 ($dewey) && ($dewey.=" $subclass");
671 $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey";
672 # print $results[$i];
676 $sth=$dbh->prepare("Select biblionumber from bibliosubject where subject
677 like ? group by biblionumber");
678 $sth->execute("%".$search->{'keyword'}."%");
679 while (my $data=$sth->fetchrow_hashref){
680 $query="Select * from biblio,biblioitems where
681 biblio.biblionumber=? and
682 biblio.biblionumber=biblioitems.biblionumber ";
683 @bind=($data->{'biblionumber'});
684 if ($search->{'class'} ne ''){
685 my @temp=split(/\|/,$search->{'class'});
687 $query.= " and ( itemtype=?";
688 push(@bind,$temp[0]);
689 for (my $i=1;$i<$count;$i++){
690 $query.=" or itemtype=?";
691 push(@bind,$temp[$i]);
696 if ($search->{'dewey'} ne ''){
697 $query.= "and (dewey like ?)";
698 push(@bind,"$search->{'dewey'}%");
700 my $sth2=$dbh->prepare($query);
701 $sth2->execute(@bind);
703 while (my $data2=$sth2->fetchrow_hashref){
704 my $dewey= $data2->{'dewey'};
705 my $subclass=$data2->{'subclass'};
707 ($dewey == 0) && ($dewey='');
708 ($dewey) && ($dewey.=" $subclass") ;
710 $results[$i]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey";
711 # print $results[$i];
717 @results=sort @results;
724 while ($i2 < $count){
725 if ($results[$i2] ne $res[$i-1]){
726 $res[$i]=$results[$i2];
734 while ($i2 < $num && $i2 < $count){
735 $res2[$i2]=$res[$i2+$offset];
747 ($count, @results) = &CatSearch($env, $type, $search, $num, $offset);
749 C<&CatSearch> searches the Koha catalog. It returns a list whose first
750 element is the number of returned results, and whose subsequent
751 elements are the results themselves.
753 Each returned element is a reference-to-hash. Most of the keys are
754 simply the fields from the C<biblio> table in the Koha database, but
755 the following keys may also be present:
761 The book's illustrator.
771 C<$type> may be C<subject>, C<loose>, or C<precise>. This controls the
772 high-level behavior of C<&CatSearch>, as described below.
774 In many cases, the description below says that a certain field in the
775 database must match the search string. In these cases, it means that
776 the beginning of some word in the field must match the search string.
777 Thus, an author search for "sm" will return books whose author is
778 "John Smith" or "Mike Smalls", but not "Paul Grossman", since the "sm"
779 does not occur at the beginning of a word.
781 Note that within each search mode, the criteria are and-ed together.
782 That is, if you perform a loose search on the author "Jerome" and the
783 title "Boat", the search will only return books by Jerome containing
786 It is not possible to cross modes, e.g., set the author to "Asimov"
787 and the subject to "Math" in hopes of finding books on math by Asimov.
791 If C<$type> is set to C<loose>, the following search criteria may be
796 =item C<$search-E<gt>{author}>
798 The search string is a space-separated list of words. Each word must
799 match either the C<author> or C<additionalauthors> field.
801 =item C<$search-E<gt>{title}>
803 Each word in the search string must match the book title. If no author
804 is specified, the book subtitle will also be searched.
806 =item C<$search-E<gt>{abstract}>
808 Searches for the given search string in the book's abstract.
810 =item C<$search-E<gt>{'date-before'}>
812 Searches for books whose copyright date matches the search string.
813 That is, setting C<$search-E<gt>{'date-before'}> to "1985" will find
814 books written in 1985, and setting it to "198" will find books written
815 between 1980 and 1989.
817 =item C<$search-E<gt>{title}>
819 Searches by title are also affected by the value of
820 C<$search-E<gt>{"ttype"}>; if it is set to C<exact>, then the book
821 title, (one of) the series titleZ<>(s), or (one of) the unititleZ<>(s) must
822 match the search string exactly (the subtitle is not searched).
824 If C<$search-E<gt>{"ttype"}> is set to anything other than C<exact>,
825 each word in the search string must match the title, subtitle,
826 unititle, or series title.
828 =item C<$search-E<gt>{class}>
830 Restricts the search to certain item classes. The value of
831 C<$search-E<gt>{"class"}> is a | (pipe)-separated list of item types.
832 Thus, setting it to "F" restricts the search to fiction, and setting
833 it to "CD|CAS" will only look in compact disks and cassettes.
835 =item C<$search-E<gt>{dewey}>
837 Searches for books whose Dewey Decimal Classification code matches the
838 search string. That is, setting C<$search-E<gt>{"dewey"}> to "5" will
839 search for all books in 5I<xx> (Science and mathematics), setting it
840 to "54" will search for all books in 54I<x> (Chemistry), and setting
841 it to "546" will search for books on inorganic chemistry.
843 =item C<$search-E<gt>{publisher}>
845 Searches for books whose publisher contains the search string (unlike
846 other search criteria, C<$search-E<gt>{publisher}> is a string, not a
851 =head2 Subject search
853 If C<$type> is set to C<subject>, the following search criterion may
858 =item C<$search-E<gt>{subject}>
860 The search string is a space-separated list of words, each of which
861 must match the book's subject.
863 Special case: if C<$search-E<gt>{subject}> is set to C<nz>,
864 C<&CatSearch> will search for books whose subject is "New Zealand".
865 However, setting C<$search-E<gt>{subject}> to C<"nz football"> will
866 search for books on "nz" and "football", not books on "New Zealand"
871 =head2 Precise search
873 If C<$type> is set to C<precise>, the following search criteria may be
878 =item C<$search-E<gt>{item}>
880 Searches for books whose barcode exactly matches the search string.
882 =item C<$search-E<gt>{isbn}>
884 Searches for books whose ISBN exactly matches the search string.
888 For a loose search, if an author was specified, the results are
889 ordered by author and title. If no author was specified, the results
890 are ordered by title.
892 For other (non-loose) searches, if a subject was specified, the
893 results are ordered alphabetically by subject.
895 In all other cases (e.g., loose search by keyword), the results are
901 my ($env,$type,$search,$num,$offset)=@_;
902 my $dbh = C4::Context->dbh;
907 my $title = lc($search->{'title'});
909 if ($type eq 'loose') {
910 if ($search->{'author'} ne ''){
911 my @key=split(' ',$search->{'author'});
914 $query="select *,biblio.author,biblio.biblionumber from
916 left join additionalauthors
917 on additionalauthors.biblionumber =biblio.biblionumber
919 ((biblio.author like ? or biblio.author like ? or
920 additionalauthors.author like ? or additionalauthors.author
923 @bind=("$key[0]%","% $key[0]%","$key[0]%","% $key[0]%");
926 biblio.author like ? or biblio.author like ? or
927 additionalauthors.author like ? or additionalauthors.author like ?
929 push(@bind,"$key[$i]%","% $key[$i]%","$key[$i]%","% $key[$i]%");
933 if ($search->{'title'} ne ''){
934 my @key=split(' ',$search->{'title'});
937 $query.= " and (((title like ? or title like ?)";
938 push(@bind,"$key[0]%","% $key[0]%");
940 $query .= " and (title like ? or title like ?)";
941 push(@bind,"$key[$i]%","% $key[$i]%");
944 $query.=") or ((seriestitle like ? or seriestitle like ?)";
945 push(@bind,"$key[0]%","% $key[0]%");
946 for ($i=1;$i<$count;$i++){
947 $query.=" and (seriestitle like ? or seriestitle like ?)";
948 push(@bind,"$key[$i]%","% $key[$i]%");
950 $query.=") or ((unititle like ? or unititle like ?)";
951 push(@bind,"$key[0]%","% $key[0]%");
952 for ($i=1;$i<$count;$i++){
953 $query.=" and (unititle like ? or unititle like ?)";
954 push(@bind,"$key[$i]%","% $key[$i]%");
958 if ($search->{'abstract'} ne ''){
959 $query.= " and (abstract like ?)";
960 push(@bind,"%$search->{'abstract'}%");
962 if ($search->{'date-before'} ne ''){
963 $query.= " and (copyrightdate like ?)";
964 push(@bind,"%$search->{'date-before'}%");
966 $query.=" group by biblio.biblionumber";
968 if ($search->{'title'} ne '') {
969 if ($search->{'ttype'} eq 'exact'){
970 $query="select * from biblio
972 (biblio.title=? or (biblio.unititle = ?
973 or biblio.unititle like ? or
974 biblio.unititle like ? or
975 biblio.unititle like ?) or
976 (biblio.seriestitle = ? or
977 biblio.seriestitle like ? or
978 biblio.seriestitle like ? or
979 biblio.seriestitle like ?)
981 @bind=($search->{'title'},$search->{'title'},"$search->{'title'} |%","%| $search->{'title'} |%","%| $search->{'title'}",$search->{'title'},"$search->{'title'} |%","%| $search->{'title'} |%","%| $search->{'title'}");
983 my @key=split(' ',$search->{'title'});
986 $query="select biblio.biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp,subtitle from biblio
987 left join bibliosubtitle on
988 biblio.biblionumber=bibliosubtitle.biblionumber
990 (((title like ? or title like ?)";
991 @bind=("$key[0]%","% $key[0]%");
993 $query .= " and (title like ? or title like ?)";
994 push(@bind,"$key[$i]%","% $key[$i]%");
997 $query.=") or ((subtitle like ? or subtitle like ?)";
998 push(@bind,"$key[0]%","% $key[0]%");
999 for ($i=1;$i<$count;$i++){
1000 $query.=" and (subtitle like ? or subtitle like ?)";
1001 push(@bind,"$key[$i]%","% $key[$i]%");
1003 $query.=") or ((seriestitle like ? or seriestitle like ?)";
1004 push(@bind,"$key[0]%","% $key[0]%");
1005 for ($i=1;$i<$count;$i++){
1006 $query.=" and (seriestitle like ? or seriestitle like ?)";
1007 push(@bind,"$key[$i]%","% $key[$i]%");
1009 $query.=") or ((unititle like ? or unititle like ?)";
1010 push(@bind,"$key[0]%","% $key[0]%");
1011 for ($i=1;$i<$count;$i++){
1012 $query.=" and (unititle like ? or unititle like ?)";
1013 push(@bind,"$key[$i]%","% $key[$i]%");
1017 if ($search->{'abstract'} ne ''){
1018 $query.= " and (abstract like ?)";
1019 push(@bind,"%$search->{'abstract'}%");
1021 if ($search->{'date-before'} ne ''){
1022 $query.= " and (copyrightdate like ?)";
1023 push(@bind,"%$search->{'date-before'}%");
1025 } elsif ($search->{'class'} ne ''){
1026 $query="select * from biblioitems,biblio where biblio.biblionumber=biblioitems.biblionumber";
1027 my @temp=split(/\|/,$search->{'class'});
1029 $query.= " and ( itemtype= ?)";
1031 for (my $i=1;$i<$count;$i++){
1032 $query.=" or itemtype=?";
1033 push(@bind,$temp[$i]);
1036 if ($search->{'illustrator'} ne ''){
1037 $query.=" and illus like ?";
1038 push(@bind,"%".$search->{'illustrator'}."%");
1040 if ($search->{'dewey'} ne ''){
1041 $query.=" and biblioitems.dewey like ?";
1042 push(@bind,"$search->{'dewey'}%");
1044 } elsif ($search->{'dewey'} ne ''){
1045 $query="select * from biblioitems,biblio
1046 where biblio.biblionumber=biblioitems.biblionumber
1047 and biblioitems.dewey like ?";
1048 @bind=("$search->{'dewey'}%");
1049 } elsif ($search->{'illustrator'} ne '') {
1050 $query="select * from biblioitems,biblio
1051 where biblio.biblionumber=biblioitems.biblionumber
1052 and biblioitems.illus like ?";
1053 @bind=("%".$search->{'illustrator'}."%");
1054 } elsif ($search->{'publisher'} ne ''){
1055 $query = "Select * from biblio,biblioitems where biblio.biblionumber
1056 =biblioitems.biblionumber and (publishercode like ?)";
1057 @bind=("%$search->{'publisher'}%");
1058 } elsif ($search->{'abstract'} ne ''){
1059 $query = "Select * from biblio where abstract like ?";
1060 @bind=("%$search->{'abstract'}%");
1061 } elsif ($search->{'date-before'} ne ''){
1062 $query = "Select * from biblio where copyrightdate like ?";
1063 @bind=("%$search->{'date-before'}%");
1065 $query .=" group by biblio.biblionumber";
1068 if ($type eq 'subject'){
1069 my @key=split(' ',$search->{'subject'});
1072 $query="select * from bibliosubject, biblioitems where
1073 (bibliosubject.biblionumber = biblioitems.biblionumber) and ( subject like ? or subject like ? or subject like ?)";
1074 @bind=("$key[0]%","% $key[0]%","%($key[0])%");
1076 $query.=" and (subject like ? or subject like ? or subject like ?)";
1077 push(@bind,"$key[$i]%","% $key[$i]%","%($key[$i])%");
1081 # FIXME - Wouldn't it be better to fix the database so that if a
1082 # book has a subject "NZ", then it also gets added the subject
1084 # This can also be generalized by adding a table of subject
1085 # synonyms to the database: just declare "NZ" to be a synonym for
1086 # "New Zealand", "SF" a synonym for both "Science fiction" and
1087 # "Fantastic fiction", etc.
1089 if (lc($search->{'subject'}) eq 'nz'){
1090 $query.= " or (subject like 'NEW ZEALAND %' or subject like '% NEW ZEALAND %'
1091 or subject like '% NEW ZEALAND' or subject like '%(NEW ZEALAND)%' ) ";
1092 } elsif ( $search->{'subject'} =~ /^nz /i || $search->{'subject'} =~ / nz /i || $search->{'subject'} =~ / nz$/i){
1093 $query=~ s/ nz/ NEW ZEALAND/ig;
1094 $query=~ s/nz /NEW ZEALAND /ig;
1095 $query=~ s/\(nz\)/\(NEW ZEALAND\)/gi;
1098 if ($type eq 'precise'){
1099 if ($search->{'itemnumber'} ne ''){
1100 $query="select * from items,biblio ";
1101 my $search2=uc $search->{'itemnumber'};
1102 $query=$query." where
1103 items.biblionumber=biblio.biblionumber
1108 if ($search->{'isbn'} ne ''){
1109 my $search2=uc $search->{'isbn'};
1110 my $sth1=$dbh->prepare("select * from biblioitems where isbn=?");
1111 $sth1->execute($search2);
1113 while (my $data=$sth1->fetchrow_hashref) {
1114 my $sth=$dbh->prepare("select * from biblioitems,biblio where
1115 biblio.biblionumber = ?
1116 and biblioitems.biblionumber = biblio.biblionumber");
1117 $sth->execute($data->{'biblionumber'});
1118 # FIXME - There's already a $data in this scope.
1119 my $data=$sth->fetchrow_hashref;
1120 my ($dewey, $subclass) = ($data->{'dewey'}, $data->{'subclass'});
1121 # FIXME - The following assumes that the Dewey code is a
1122 # floating-point number. It isn't: it's a string.
1124 ($dewey == 0) && ($dewey='');
1125 ($dewey) && ($dewey.=" $subclass");
1126 $data->{'dewey'}=$dewey;
1127 $results[$i2]=$data;
1128 # $results[$i2]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'isbn'}\t$data->{'itemtype'}";
1135 if ($type ne 'precise' && $type ne 'subject'){
1136 if ($search->{'author'} ne ''){
1137 $query .= " order by biblio.author,title";
1139 $query .= " order by title";
1142 if ($type eq 'subject'){
1143 $query .= " group by subject ";
1146 my $sth=$dbh->prepare($query);
1147 $sth->execute(@bind);
1150 my $limit= $num+$offset;
1151 while (my $data=$sth->fetchrow_hashref){
1152 my $query="select classification,dewey,subclass,publishercode from biblioitems where biblionumber=?";
1153 my @bind=($data->{'biblionumber'});
1154 if ($search->{'class'} ne ''){
1155 my @temp=split(/\|/,$search->{'class'});
1157 $query.= " and ( itemtype= ?";
1158 push(@bind,$temp[0]);
1159 for (my $i=1;$i<$count;$i++){
1160 $query.=" or itemtype=?";
1161 push(@bind,$temp[$i]);
1165 if ($search->{'dewey'} ne ''){
1166 $query.=" and dewey=? ";
1167 push(@bind,$search->{'dewey'});
1169 if ($search->{'illustrator'} ne ''){
1170 $query.=" and illus like ?";
1171 push(@bind,"%$search->{'illustrator'}%");
1173 if ($search->{'publisher'} ne ''){
1174 $query.= " and (publishercode like ?)";
1175 push(@bind,"%$search->{'publisher'}%");
1177 my $sti=$dbh->prepare($query);
1178 $sti->execute(@bind);
1185 if ($bibitemdata = $sti->fetchrow_hashref()){
1187 $classification=$bibitemdata->{'classification'};
1188 $dewey=$bibitemdata->{'dewey'};
1189 $subclass=$bibitemdata->{'subclass'};
1190 $publishercode=$bibitemdata->{'publishercode'};
1192 # print STDERR "$dewey $subclass $publishercode\n";
1193 # FIXME - The Dewey code is a string, not a number.
1195 ($dewey == 0) && ($dewey='');
1196 ($dewey) && ($dewey.=" $subclass");
1197 $data->{'classification'}=$classification;
1198 $data->{'dewey'}=$dewey;
1199 $data->{'publishercode'}=$publishercode;
1202 if ($count > $offset && $count <= $limit){
1211 return($count,@results);
1214 sub updatesearchstats{
1215 my ($dbh,$query)=@_;
1221 @results = &subsearch($env, $subject);
1223 Searches for books that have a subject that exactly matches
1226 C<&subsearch> returns an array of results. Each element of this array
1227 is a string, containing the book's title, author, and biblionumber,
1235 my ($env,$subject)=@_;
1236 my $dbh = C4::Context->dbh;
1237 my $sth=$dbh->prepare("Select * from biblio,bibliosubject where
1238 biblio.biblionumber=bibliosubject.biblionumber and
1239 bibliosubject.subject=? group by biblio.biblionumber
1240 order by biblio.title");
1241 $sth->execute($subject);
1244 while (my $data=$sth->fetchrow_hashref){
1245 push @results, $data;
1254 @results = &ItemInfo($env, $biblionumber, $type);
1256 Returns information about books with the given biblionumber.
1258 C<$type> may be either C<intra> or anything else. If it is not set to
1259 C<intra>, then the search will exclude lost, very overdue, and
1264 C<&ItemInfo> returns a list of references-to-hash. Each element
1265 contains a number of keys. Most of them are table items from the
1266 C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
1267 Koha database. Other keys include:
1271 =item C<$data-E<gt>{branchname}>
1273 The name (not the code) of the branch to which the book belongs.
1275 =item C<$data-E<gt>{datelastseen}>
1277 This is simply C<items.datelastseen>, except that while the date is
1278 stored in YYYY-MM-DD format in the database, here it is converted to
1279 DD/MM/YYYY format. A NULL date is returned as C<//>.
1281 =item C<$data-E<gt>{datedue}>
1283 =item C<$data-E<gt>{class}>
1285 This is the concatenation of C<biblioitems.classification>, the book's
1286 Dewey code, and C<biblioitems.subclass>.
1288 =item C<$data-E<gt>{ocount}>
1290 I think this is the number of copies of the book available.
1292 =item C<$data-E<gt>{order}>
1294 If this is set, it is set to C<One Order>.
1301 my ($env,$biblionumber,$type) = @_;
1302 my $dbh = C4::Context->dbh;
1303 my $query = "SELECT *,items.notforloan as itemnotforloan FROM items, biblio, biblioitems
1304 left join itemtypes on biblioitems.itemtype = itemtypes.itemtype
1305 WHERE items.biblionumber = ?
1306 AND biblioitems.biblioitemnumber = items.biblioitemnumber
1307 AND biblio.biblionumber = items.biblionumber";
1308 if ($type ne 'intra'){
1309 $query .= " and ((items.itemlost<>1 and items.itemlost <> 2)
1310 or items.itemlost is NULL)
1311 and (wthdrawn <> 1 or wthdrawn is NULL)";
1313 $query .= " order by items.dateaccessioned desc";
1314 my $sth=$dbh->prepare($query);
1315 $sth->execute($biblionumber);
1318 while (my $data=$sth->fetchrow_hashref){
1320 my $isth=$dbh->prepare("Select * from issues where itemnumber = ? and returndate is null");
1321 $isth->execute($data->{'itemnumber'});
1322 if (my $idata=$isth->fetchrow_hashref){
1323 $datedue = format_date($idata->{'date_due'});
1325 if ($data->{'itemlost'} eq '2'){
1326 $datedue='Very Overdue';
1328 if ($data->{'itemlost'} eq '1'){
1331 if ($data->{'wthdrawn'} eq '1'){
1332 $datedue="Cancelled";
1334 if ($datedue eq ''){
1335 # $datedue="Available";
1336 my ($restype,$reserves)=C4::Reserves2::CheckReserves($data->{'itemnumber'});
1342 #get branch information.....
1343 my $bsth=$dbh->prepare("SELECT * FROM branches WHERE branchcode = ?");
1344 $bsth->execute($data->{'holdingbranch'});
1345 if (my $bdata=$bsth->fetchrow_hashref){
1346 $data->{'branchname'} = $bdata->{'branchname'};
1348 # $results[$i]="$data->{'title'}\t$data->{'barcode'}\t$datedue\t$data->{'branchname'}\t$data->{'dewey'}";
1349 # FIXME - If $data->{'datelastseen'} is NULL, perhaps it'd be prettier
1350 # to leave it empty, rather than convert it to "//".
1351 # Also ideally this should use the local format for displaying dates.
1352 my $date=format_date($data->{'datelastseen'});
1353 $data->{'datelastseen'}=$date;
1354 $data->{'datedue'}=$datedue;
1359 #FIXME: ordering/indentation here looks wrong
1360 my $sth2=$dbh->prepare("Select * from aqorders where biblionumber=?");
1361 $sth2->execute($biblionumber);
1364 if ($data=$sth2->fetchrow_hashref){
1365 $ocount=$data->{'quantity'} - $data->{'quantityreceived'};
1367 $data->{'ocount'}=$ocount;
1368 $data->{'order'}="One Order";
1379 @results = &GetItems($env, $biblionumber);
1381 Returns information about books with the given biblionumber.
1385 C<&GetItems> returns an array of strings. Each element is a
1386 tab-separated list of values: biblioitemnumber, itemtype,
1387 classification, Dewey number, subclass, ISBN, volume, number, and
1390 Itemdata, in turn, is a string of the form
1391 "I<barcode>C<[>I<holdingbranch>C<[>I<flags>" where I<flags> contains
1392 the string C<NFL> if the item is not for loan, and C<LOST> if the item
1398 my ($env,$biblionumber)=@_;
1399 #debug_msg($env,"GetItems");
1400 my $dbh = C4::Context->dbh;
1401 my $sth=$dbh->prepare("Select * from biblioitems where (biblionumber = ?)");
1402 $sth->execute($biblionumber);
1403 #debug_msg($env,"executed query");
1406 while (my $data=$sth->fetchrow_hashref) {
1407 #debug_msg($env,$data->{'biblioitemnumber'});
1408 my $dewey = $data->{'dewey'};
1410 my $line = $data->{'biblioitemnumber'}."\t".$data->{'itemtype'};
1411 $line .= "\t$data->{'classification'}\t$dewey";
1412 $line .= "\t$data->{'subclass'}\t$data->{isbn}";
1413 $line .= "\t$data->{'volume'}\t$data->{number}";
1414 my $isth= $dbh->prepare("select * from items where biblioitemnumber = ?");
1415 $isth->execute($data->{'biblioitemnumber'});
1416 while (my $idata = $isth->fetchrow_hashref) {
1417 my $iline = $idata->{'barcode'}."[".$idata->{'holdingbranch'}."[";
1418 if ($idata->{'notforloan'} == 1) {
1421 if ($idata->{'itemlost'} == 1) {
1424 $line .= "\t$iline";
1427 $results[$i] = $line;
1436 $item = &itemdata($barcode);
1438 Looks up the item with the given barcode, and returns a
1439 reference-to-hash containing information about that item. The keys of
1440 the hash are the fields from the C<items> and C<biblioitems> tables in
1447 my $dbh = C4::Context->dbh;
1448 my $sth=$dbh->prepare("Select * from items,biblioitems where barcode=?
1449 and items.biblioitemnumber=biblioitems.biblioitemnumber");
1450 $sth->execute($barcode);
1451 my $data=$sth->fetchrow_hashref;
1458 $data = &bibdata($biblionumber, $type);
1460 Returns information about the book with the given biblionumber.
1462 C<$type> is ignored.
1464 C<&bibdata> returns a reference-to-hash. The keys are the fields in
1465 the C<biblio>, C<biblioitems>, and C<bibliosubtitle> tables in the
1468 In addition, C<$data-E<gt>{subject}> is the list of the book's
1469 subjects, separated by C<" , "> (space, comma, space).
1471 If there are multiple biblioitems with the given biblionumber, only
1472 the first one is considered.
1477 my ($bibnum, $type) = @_;
1478 my $dbh = C4::Context->dbh;
1479 my $sth = $dbh->prepare("Select *, biblioitems.notes AS bnotes, biblio.notes
1480 from biblio, biblioitems
1481 left join bibliosubtitle on
1482 biblio.biblionumber = bibliosubtitle.biblionumber
1483 where biblio.biblionumber = ?
1484 and biblioitems.biblionumber = biblio.biblionumber");
1485 $sth->execute($bibnum);
1487 $data = $sth->fetchrow_hashref;
1489 $sth = $dbh->prepare("Select * from bibliosubject where biblionumber = ?");
1490 $sth->execute($bibnum);
1492 while (my $dat = $sth->fetchrow_hashref){
1494 $line{subject} = $dat->{'subject'};
1495 push @subjects, \%line;
1497 $data->{subjects} = \@subjects;
1499 $sth = $dbh->prepare("Select * from additionalauthors where biblionumber = ?");
1500 $sth->execute($bibnum);
1501 while (my $dat = $sth->fetchrow_hashref){
1502 $data->{'additionalauthors'} .= "$dat->{'author'} - ";
1504 chop $data->{'additionalauthors'};
1505 chop $data->{'additionalauthors'};
1506 chop $data->{'additionalauthors'};
1513 $itemdata = &bibitemdata($biblioitemnumber);
1515 Looks up the biblioitem with the given biblioitemnumber. Returns a
1516 reference-to-hash. The keys are the fields from the C<biblio>,
1517 C<biblioitems>, and C<itemtypes> tables in the Koha database, except
1518 that C<biblioitems.notes> is given as C<$itemdata-E<gt>{bnotes}>.
1524 my $dbh = C4::Context->dbh;
1525 my $sth = $dbh->prepare("Select *,biblioitems.notes as bnotes from biblio, biblioitems,itemtypes where biblio.biblionumber = biblioitems.biblionumber and biblioitemnumber = ? and biblioitems.itemtype = itemtypes.itemtype");
1528 $sth->execute($bibitem);
1530 $data = $sth->fetchrow_hashref;
1538 ($count, $subjects) = &subject($biblionumber);
1540 Looks up the subjects of the book with the given biblionumber. Returns
1541 a two-element list. C<$subjects> is a reference-to-array, where each
1542 element is a subject of the book, and C<$count> is the number of
1543 elements in C<$subjects>.
1549 my $dbh = C4::Context->dbh;
1550 my $sth=$dbh->prepare("Select * from bibliosubject where biblionumber=?");
1551 $sth->execute($bibnum);
1554 while (my $data=$sth->fetchrow_hashref){
1559 return($i,\@results);
1564 ($count, $authors) = &addauthors($biblionumber);
1566 Looks up the additional authors for the book with the given
1569 Returns a two-element list. C<$authors> is a reference-to-array, where
1570 each element is an additional author, and C<$count> is the number of
1571 elements in C<$authors>.
1577 my $dbh = C4::Context->dbh;
1578 my $sth=$dbh->prepare("Select * from additionalauthors where biblionumber=?");
1579 $sth->execute($bibnum);
1582 while (my $data=$sth->fetchrow_hashref){
1587 return($i,\@results);
1592 ($count, $subtitles) = &subtitle($biblionumber);
1594 Looks up the subtitles for the book with the given biblionumber.
1596 Returns a two-element list. C<$subtitles> is a reference-to-array,
1597 where each element is a subtitle, and C<$count> is the number of
1598 elements in C<$subtitles>.
1604 my $dbh = C4::Context->dbh;
1605 my $sth=$dbh->prepare("Select * from bibliosubtitle where biblionumber=?");
1606 $sth->execute($bibnum);
1609 while (my $data=$sth->fetchrow_hashref){
1614 return($i,\@results);
1619 @issues = &itemissues($biblioitemnumber, $biblio);
1621 Looks up information about who has borrowed the bookZ<>(s) with the
1622 given biblioitemnumber.
1624 C<$biblio> is ignored.
1626 C<&itemissues> returns an array of references-to-hash. The keys
1627 include the fields from the C<items> table in the Koha database.
1628 Additional keys include:
1634 If the item is currently on loan, this gives the due date.
1636 If the item is not on loan, then this is either "Available" or
1637 "Cancelled", if the item has been withdrawn.
1641 If the item is currently on loan, this gives the card number of the
1642 patron who currently has the item.
1644 =item C<timestamp0>, C<timestamp1>, C<timestamp2>
1646 These give the timestamp for the last three times the item was
1649 =item C<card0>, C<card1>, C<card2>
1651 The card number of the last three patrons who borrowed this item.
1653 =item C<borrower0>, C<borrower1>, C<borrower2>
1655 The borrower number of the last three patrons who borrowed this item.
1662 my ($bibitem, $biblio)=@_;
1663 my $dbh = C4::Context->dbh;
1664 # FIXME - If this function die()s, the script will abort, and the
1665 # user won't get anything; depending on how far the script has
1666 # gotten, the user might get a blank page. It would be much better
1667 # to at least print an error message. The easiest way to do this
1668 # is to set $SIG{__DIE__}.
1669 my $sth = $dbh->prepare("Select * from items where
1670 items.biblioitemnumber = ?")
1671 || die $dbh->errstr;
1675 $sth->execute($bibitem)
1676 || die $sth->errstr;
1678 while (my $data = $sth->fetchrow_hashref) {
1679 # Find out who currently has this item.
1680 # FIXME - Wouldn't it be better to do this as a left join of
1681 # some sort? Currently, this code assumes that if
1682 # fetchrow_hashref() fails, then the book is on the shelf.
1683 # fetchrow_hashref() can fail for any number of reasons (e.g.,
1684 # database server crash), not just because no items match the
1686 my $sth2 = $dbh->prepare("select * from issues,borrowers
1687 where itemnumber = ?
1688 and returndate is NULL
1689 and issues.borrowernumber = borrowers.borrowernumber");
1691 $sth2->execute($data->{'itemnumber'});
1692 if (my $data2 = $sth2->fetchrow_hashref) {
1693 $data->{'date_due'} = $data2->{'date_due'};
1694 $data->{'card'} = $data2->{'cardnumber'};
1695 $data->{'borrower'} = $data2->{'borrowernumber'};
1697 if ($data->{'wthdrawn'} eq '1') {
1698 $data->{'date_due'} = 'Cancelled';
1700 $data->{'date_due'} = 'Available';
1706 # Find the last 3 people who borrowed this item.
1707 $sth2 = $dbh->prepare("select * from issues, borrowers
1708 where itemnumber = ?
1709 and issues.borrowernumber = borrowers.borrowernumber
1710 and returndate is not NULL
1711 order by returndate desc,timestamp desc") || die $dbh->errstr;
1712 $sth2->execute($data->{'itemnumber'}) || die $sth2->errstr;
1713 for (my $i2 = 0; $i2 < 2; $i2++) { # FIXME : error if there is less than 3 pple borrowing this item
1714 if (my $data2 = $sth2->fetchrow_hashref) {
1715 $data->{"timestamp$i2"} = $data2->{'timestamp'};
1716 $data->{"card$i2"} = $data2->{'cardnumber'};
1717 $data->{"borrower$i2"} = $data2->{'borrowernumber'};
1722 $results[$i] = $data;
1732 $item = &itemnodata($env, $dbh, $biblioitemnumber);
1734 Looks up the item with the given biblioitemnumber.
1736 C<$env> and C<$dbh> are ignored.
1738 C<&itemnodata> returns a reference-to-hash whose keys are the fields
1739 from the C<biblio>, C<biblioitems>, and C<items> tables in the Koha
1745 my ($env,$dbh,$itemnumber) = @_;
1746 $dbh = C4::Context->dbh;
1747 my $sth=$dbh->prepare("Select * from biblio,items,biblioitems
1748 where items.itemnumber = ?
1749 and biblio.biblionumber = items.biblionumber
1750 and biblioitems.biblioitemnumber = items.biblioitemnumber");
1752 $sth->execute($itemnumber);
1753 my $data=$sth->fetchrow_hashref;
1760 ($count, $borrowers) = &BornameSearch($env, $searchstring, $type);
1762 Looks up patrons (borrowers) by name.
1766 BUGFIX 499: C<$type> is now used to determine type of search.
1767 if $type is "simple", search is performed on the first letter of the
1770 C<$searchstring> is a space-separated list of search terms. Each term
1771 must match the beginning a borrower's surname, first name, or other
1774 C<&BornameSearch> returns a two-element list. C<$borrowers> is a
1775 reference-to-array; each element is a reference-to-hash, whose keys
1776 are the fields of the C<borrowers> table in the Koha database.
1777 C<$count> is the number of elements in C<$borrowers>.
1781 #used by member enquiries from the intranet
1782 #called by member.pl
1784 my ($env,$searchstring,$type)=@_;
1785 my $dbh = C4::Context->dbh;
1786 my $query = ""; my $count; my @data;
1789 if($type eq "simple") # simple search for one letter only
1791 $query="Select * from borrowers where surname like ? order by surname,firstname";
1792 @bind=("$searchstring%");
1794 else # advanced search looking in surname, firstname and othernames
1796 @data=split(' ',$searchstring);
1798 $query="Select * from borrowers
1799 where ((surname like ? or surname like ?
1800 or firstname like ? or firstname like ?
1801 or othernames like ? or othernames like ?)
1803 @bind=("$data[0]%","% $data[0]%","$data[0]%","% $data[0]%","$data[0]%","% $data[0]%");
1804 for (my $i=1;$i<$count;$i++){
1805 $query=$query." and (".
1806 " surname like ? or surname like ?
1807 or firstname like ? or firstname like ?
1808 or othernames like ? or othernames like ?)";
1809 push(@bind,"$data[$i]%","% $data[$i]%","$data[$i]%","% $data[$i]%","$data[$i]%","% $data[$i]%");
1812 $query=$query.") or cardnumber = ?
1813 order by surname,firstname";
1814 push(@bind,$searchstring);
1818 my $sth=$dbh->prepare($query);
1819 $sth->execute(@bind);
1822 while (my $data=$sth->fetchrow_hashref){
1823 push(@results,$data);
1827 return ($cnt,\@results);
1832 $borrower = &borrdata($cardnumber, $borrowernumber);
1834 Looks up information about a patron (borrower) by either card number
1835 or borrower number. If $borrowernumber is specified, C<&borrdata>
1836 searches by borrower number; otherwise, it searches by card number.
1838 C<&borrdata> returns a reference-to-hash whose keys are the fields of
1839 the C<borrowers> table in the Koha database.
1844 my ($cardnumber,$bornum)=@_;
1845 $cardnumber = uc $cardnumber;
1846 my $dbh = C4::Context->dbh;
1849 $sth=$dbh->prepare("Select * from borrowers where cardnumber=?");
1850 $sth->execute($cardnumber);
1852 $sth=$dbh->prepare("Select * from borrowers where borrowernumber=?");
1853 $sth->execute($bornum);
1855 my $data=$sth->fetchrow_hashref;
1859 } else { # try with firstname
1861 my $sth=$dbh->prepare("select * from borrowers where firstname=?");
1862 $sth->execute($cardnumber);
1863 my $data=$sth->fetchrow_hashref;
1873 ($count, $issues) = &borrissues($borrowernumber);
1875 Looks up what the patron with the given borrowernumber has borrowed.
1877 C<&borrissues> returns a two-element array. C<$issues> is a
1878 reference-to-array, where each element is a reference-to-hash; the
1879 keys are the fields from the C<issues>, C<biblio>, and C<items> tables
1880 in the Koha database. C<$count> is the number of elements in
1887 my $dbh = C4::Context->dbh;
1888 my $sth=$dbh->prepare("Select * from issues,biblio,items where borrowernumber=?
1889 and items.itemnumber=issues.itemnumber
1890 and items.biblionumber=biblio.biblionumber
1891 and issues.returndate is NULL order by date_due");
1892 $sth->execute($bornum);
1894 while (my $data = $sth->fetchrow_hashref) {
1895 push @result, $data;
1898 return(scalar(@result), \@result);
1903 ($count, $issues) = &allissues($borrowernumber, $sortkey, $limit);
1905 Looks up what the patron with the given borrowernumber has borrowed,
1906 and sorts the results.
1908 C<$sortkey> is the name of a field on which to sort the results. This
1909 should be the name of a field in the C<issues>, C<biblio>,
1910 C<biblioitems>, or C<items> table in the Koha database.
1912 C<$limit> is the maximum number of results to return.
1914 C<&allissues> returns a two-element array. C<$issues> is a
1915 reference-to-array, where each element is a reference-to-hash; the
1916 keys are the fields from the C<issues>, C<biblio>, C<biblioitems>, and
1917 C<items> tables of the Koha database. C<$count> is the number of
1918 elements in C<$issues>
1923 my ($bornum,$order,$limit)=@_;
1924 #FIXME: sanity-check order and limit
1925 my $dbh = C4::Context->dbh;
1926 my $query="Select * from issues,biblio,items,biblioitems
1927 where borrowernumber=? and
1928 items.biblioitemnumber=biblioitems.biblioitemnumber and
1929 items.itemnumber=issues.itemnumber and
1930 items.biblionumber=biblio.biblionumber order by $order";
1932 $query.=" limit $limit";
1935 my $sth=$dbh->prepare($query);
1936 $sth->execute($bornum);
1939 while (my $data=$sth->fetchrow_hashref){
1944 return($i,\@result);
1949 ($borrowed, $due, $fine) = &borrdata2($env, $borrowernumber);
1951 Returns aggregate data about items borrowed by the patron with the
1952 given borrowernumber.
1956 C<&borrdata2> returns a three-element array. C<$borrowed> is the
1957 number of books the patron currently has borrowed. C<$due> is the
1958 number of overdue items the patron currently has borrowed. C<$fine> is
1959 the total fine currently due by the borrower.
1964 my ($env,$bornum)=@_;
1965 my $dbh = C4::Context->dbh;
1966 my $query="Select count(*) from issues where borrowernumber='$bornum' and
1967 returndate is NULL";
1969 my $sth=$dbh->prepare($query);
1971 my $data=$sth->fetchrow_hashref;
1973 $sth=$dbh->prepare("Select count(*) from issues where
1974 borrowernumber='$bornum' and date_due < now() and returndate is NULL");
1976 my $data2=$sth->fetchrow_hashref;
1978 $sth=$dbh->prepare("Select sum(amountoutstanding) from accountlines where
1979 borrowernumber='$bornum'");
1981 my $data3=$sth->fetchrow_hashref;
1984 return($data2->{'count(*)'},$data->{'count(*)'},$data3->{'sum(amountoutstanding)'});
1987 =item getboracctrecord
1989 ($count, $acctlines, $total) = &getboracctrecord($env, $borrowernumber);
1991 Looks up accounting data for the patron with the given borrowernumber.
1995 (FIXME - I'm not at all sure what this is about.)
1997 C<&getboracctrecord> returns a three-element array. C<$acctlines> is a
1998 reference-to-array, where each element is a reference-to-hash; the
1999 keys are the fields of the C<accountlines> table in the Koha database.
2000 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
2001 total amount outstanding for all of the account lines.
2005 sub getboracctrecord {
2006 my ($env,$params) = @_;
2007 my $dbh = C4::Context->dbh;
2010 my $sth=$dbh->prepare("Select * from accountlines where
2011 borrowernumber=? order by date desc,timestamp desc");
2013 $sth->execute($params->{'borrowernumber'});
2015 while (my $data=$sth->fetchrow_hashref){
2016 #FIXME before reinstating: insecure?
2017 # if ($data->{'itemnumber'} ne ''){
2018 # $query="Select * from items,biblio where items.itemnumber=
2019 # '$data->{'itemnumber'}' and biblio.biblionumber=items.biblionumber";
2020 # my $sth2=$dbh->prepare($query);
2022 # my $data2=$sth2->fetchrow_hashref;
2026 $acctlines[$numlines] = $data;
2028 $total += $data->{'amountoutstanding'};
2031 return ($numlines,\@acctlines,$total);
2036 ($count, $lcount, $nacount, $fcount, $scount, $lostcount,
2037 $mending, $transit,$ocount) =
2038 &itemcount($env, $biblionumber, $type);
2040 Counts the number of items with the given biblionumber, broken down by
2045 If C<$type> is not set to C<intra>, lost, very overdue, and withdrawn
2046 items will not be counted.
2048 C<&itemcount> returns a nine-element list:
2050 C<$count> is the total number of items with the given biblionumber.
2052 C<$lcount> is the number of items at the Levin branch.
2054 C<$nacount> is the number of items that are neither borrowed, lost,
2055 nor withdrawn (and are therefore presumably on a shelf somewhere).
2057 C<$fcount> is the number of items at the Foxton branch.
2059 C<$scount> is the number of items at the Shannon branch.
2061 C<$lostcount> is the number of lost and very overdue items.
2063 C<$mending> is the number of items at the Mending branch (being
2066 C<$transit> is the number of items at the Transit branch (in transit
2069 C<$ocount> is the number of items that haven't arrived yet
2070 (aqorders.quantity - aqorders.quantityreceived).
2075 # FIXME - There's also a &C4::Biblio::itemcount.
2076 # Since they're all exported, acqui/acquire.pl doesn't compile with -w.
2078 my ($env,$bibnum,$type)=@_;
2079 my $dbh = C4::Context->dbh;
2080 my $query="Select * from items where
2082 if ($type ne 'intra'){
2083 $query.=" and ((itemlost <>1 and itemlost <> 2) or itemlost is NULL) and
2084 (wthdrawn <> 1 or wthdrawn is NULL)";
2086 my $sth=$dbh->prepare($query);
2088 $sth->execute($bibnum);
2098 while (my $data=$sth->fetchrow_hashref){
2101 my $sth2=$dbh->prepare("select * from issues,items where issues.itemnumber=
2102 ? and returndate is NULL
2103 and items.itemnumber=issues.itemnumber and ((items.itemlost <>1 and
2104 items.itemlost <> 2) or items.itemlost is NULL)
2105 and (wthdrawn <> 1 or wthdrawn is NULL)");
2106 $sth2->execute($data->{'itemnumber'});
2107 if (my $data2=$sth2->fetchrow_hashref){
2110 if ($data->{'holdingbranch'} eq 'C' || $data->{'holdingbranch'} eq 'LT'){
2113 if ($data->{'holdingbranch'} eq 'F' || $data->{'holdingbranch'} eq 'FP'){
2116 if ($data->{'holdingbranch'} eq 'S' || $data->{'holdingbranch'} eq 'SP'){
2119 if ($data->{'itemlost'} eq '1'){
2122 if ($data->{'itemlost'} eq '2'){
2125 if ($data->{'holdingbranch'} eq 'FM'){
2128 if ($data->{'holdingbranch'} eq 'TR'){
2135 my $sth2=$dbh->prepare("Select * from aqorders where biblionumber=?");
2136 $sth2->execute($bibnum);
2137 if (my $data=$sth2->fetchrow_hashref){
2138 $ocount=$data->{'quantity'} - $data->{'quantityreceived'};
2143 return ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit,$ocount);
2148 $counts = &itemcount2($env, $biblionumber, $type);
2150 Counts the number of items with the given biblionumber, broken down by
2155 C<$type> may be either C<intra> or anything else. If it is not set to
2156 C<intra>, then the search will exclude lost, very overdue, and
2159 C<$&itemcount2> returns a reference-to-hash, with the following fields:
2165 The total number of items with this biblionumber.
2169 The number of items on order (aqorders.quantity -
2170 aqorders.quantityreceived).
2174 For each branch that has at least one copy of the book, C<$counts>
2175 will have a key with the branch name, giving the number of copies at
2183 my ($env,$bibnum,$type)=@_;
2184 my $dbh = C4::Context->dbh;
2185 my $query="Select * from items,branches where
2186 biblionumber=? and items.holdingbranch=branches.branchcode";
2187 if ($type ne 'intra'){
2188 $query.=" and ((itemlost <>1 and itemlost <> 2) or itemlost is NULL) and
2189 (wthdrawn <> 1 or wthdrawn is NULL)";
2191 my $sth=$dbh->prepare($query);
2193 $sth->execute($bibnum);
2196 while (my $data=$sth->fetchrow_hashref){
2203 'select * from items
2205 and not ((items.itemlost <>1 and items.itemlost <> 2)
2206 or items.itemlost is NULL)'
2209 'select * from items
2210 where itemnumber=? and not (wthdrawn <> 1 or wthdrawn is NULL)'
2212 'On Loan', "select * from issues,items
2213 where issues.itemnumber=? and returndate is NULL
2214 and items.itemnumber=issues.itemnumber"
2217 my($testlabel, $query2) = @$test;
2219 my $sth2=$dbh->prepare($query2);
2220 $sth2->execute($data->{'itemnumber'});
2222 # FIXME - fetchrow_hashref() can fail for any number of reasons
2223 # (e.g., a database server crash). Perhaps use a left join of some
2225 $status = $testlabel if $sth2->fetchrow_hashref;
2227 last if defined $status;
2229 $status = $data->{'branchname'} unless defined $status;
2232 my $sth2=$dbh->prepare("Select * from aqorders where biblionumber=? and
2233 datecancellationprinted is NULL and quantity > quantityreceived");
2234 $sth2->execute($bibnum);
2235 if (my $data=$sth2->fetchrow_hashref){
2236 $counts{'order'}=$data->{'quantity'} - $data->{'quantityreceived'};
2245 $description = &ItemType($itemtype);
2247 Given an item type code, returns the description for that type.
2252 # FIXME - I'm pretty sure that after the initial setup, the list of
2253 # item types doesn't change very often. Hence, it seems slow and
2254 # inefficient to make yet another database call to look up information
2255 # that'll only change every few months or years.
2257 # Much better, I think, to automatically build a Perl file that can be
2258 # included in those scripts that require it, e.g.:
2259 # @itemtypes = qw( ART BCD CAS CD F ... );
2261 # ART => "Art Prints",
2262 # BCD => "CD-ROM from book",
2263 # CD => "Compact disc (WN)",
2264 # F => "Free Fiction",
2267 # The web server can then run a cron job to rebuild this file from the
2268 # database every hour or so.
2270 # The same thing goes for branches, book funds, book sellers, currency
2271 # rates, printers, stopwords, and perhaps others.
2274 my $dbh = C4::Context->dbh;
2275 my $sth=$dbh->prepare("select description from itemtypes where itemtype=?");
2276 $sth->execute($type);
2277 my $dat=$sth->fetchrow_hashref;
2279 return ($dat->{'description'});
2284 ($count, @results) = &bibitems($biblionumber);
2286 Given the biblionumber for a book, C<&bibitems> looks up that book's
2287 biblioitems (different publications of the same book, the audio book
2288 and film versions, etc.).
2290 C<$count> is the number of elements in C<@results>.
2292 C<@results> is an array of references-to-hash; the keys are the fields
2293 of the C<biblioitems> and C<itemtypes> tables of the Koha database. In
2294 addition, C<itemlost> indicates the availability of the item: if it is
2295 "2", then all copies of the item are long overdue; if it is "1", then
2296 all copies are lost; otherwise, there is at least one copy available.
2302 my $dbh = C4::Context->dbh;
2303 my $sth = $dbh->prepare("SELECT biblioitems.*,
2305 MIN(items.itemlost) as itemlost,
2306 MIN(items.dateaccessioned) as dateaccessioned
2307 FROM biblioitems, itemtypes, items
2308 WHERE biblioitems.biblionumber = ?
2309 AND biblioitems.itemtype = itemtypes.itemtype
2310 AND biblioitems.biblioitemnumber = items.biblioitemnumber
2311 GROUP BY items.biblioitemnumber");
2314 $sth->execute($bibnum);
2315 while (my $data = $sth->fetchrow_hashref) {
2316 $results[$count] = $data;
2320 return($count, @results);
2325 @barcodes = &barcodes($biblioitemnumber);
2327 Given a biblioitemnumber, looks up the corresponding items.
2329 Returns an array of references-to-hash; the keys are C<barcode> and
2332 The returned items include very overdue items, but not lost ones.
2337 #called from request.pl
2338 my ($biblioitemnumber)=@_;
2339 my $dbh = C4::Context->dbh;
2340 my $sth=$dbh->prepare("SELECT barcode, itemlost, holdingbranch FROM items
2341 WHERE biblioitemnumber = ?
2342 AND (wthdrawn <> 1 OR wthdrawn IS NULL)");
2343 $sth->execute($biblioitemnumber);
2346 while (my $data=$sth->fetchrow_hashref){
2347 $barcodes[$i]=$data;
2356 ($count, @websites) = &getwebsites($biblionumber);
2358 Looks up the web sites pertaining to the book with the given
2361 C<$count> is the number of elements in C<@websites>.
2363 C<@websites> is an array of references-to-hash; the keys are the
2364 fields from the C<websites> table in the Koha database.
2369 my ($biblionumber) = @_;
2370 my $dbh = C4::Context->dbh;
2371 my $sth = $dbh->prepare("Select * from websites where biblionumber = ?");
2375 $sth->execute($biblionumber);
2376 while (my $data = $sth->fetchrow_hashref) {
2377 # FIXME - The URL scheme shouldn't be stripped off, at least
2378 # not here, since it's part of the URL, and will be useful in
2379 # constructing a link to the site. If you don't want the user
2380 # to see the "http://" part, strip that off when building the
2382 $data->{'url'} =~ s/^http:\/\///; # FIXME - Leaning toothpick
2384 $results[$count] = $data;
2389 return($count, @results);
2392 =item getwebbiblioitems
2394 ($count, @results) = &getwebbiblioitems($biblionumber);
2396 Given a book's biblionumber, looks up the web versions of the book
2397 (biblioitems with itemtype C<WEB>).
2399 C<$count> is the number of items in C<@results>. C<@results> is an
2400 array of references-to-hash; the keys are the items from the
2401 C<biblioitems> table of the Koha database.
2405 sub getwebbiblioitems {
2406 my ($biblionumber) = @_;
2407 my $dbh = C4::Context->dbh;
2408 my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?
2409 and itemtype = 'WEB'");
2413 $sth->execute($biblionumber);
2414 while (my $data = $sth->fetchrow_hashref) {
2415 $data->{'url'} =~ s/^http:\/\///;
2416 $results[$count] = $data;
2421 return($count, @results);
2422 } # sub getwebbiblioitems
2425 =item breedingsearch
2427 ($count, @results) = &breedingsearch($title,$isbn,$random);
2428 C<$title> contains the title,
2429 C<$isbn> contains isbn or issn,
2430 C<$random> contains the random seed from a z3950 search.
2432 C<$count> is the number of items in C<@results>. C<@results> is an
2433 array of references-to-hash; the keys are the items from the C<marc_breeding> table of the Koha database.
2437 sub breedingsearch {
2438 my ($title,$isbn,$z3950random) = @_;
2439 my $dbh = C4::Context->dbh;
2445 $query = "Select id,file,isbn,title,author from marc_breeding where ";
2447 $query .= "z3950random = ?";
2448 @bind=($z3950random);
2452 $query .= "title like ?";
2453 push(@bind,"$title%");
2455 if ($title && $isbn) {
2459 $query .= "isbn like ?";
2460 push(@bind,"$isbn%");
2463 $sth = $dbh->prepare($query);
2464 $sth->execute(@bind);
2465 while (my $data = $sth->fetchrow_hashref) {
2466 $results[$count] = $data;
2471 return($count, @results);
2472 } # sub breedingsearch
2480 ($count, @results) = &isbnsearch($isbn,$title);
2482 Given an isbn and/or a title, returns the biblios having it.
2483 Used in acqui.simple, isbnsearch.pl only
2485 C<$count> is the number of items in C<@results>. C<@results> is an
2486 array of references-to-hash; the keys are the items from the
2487 C<biblioitems> table of the Koha database.
2492 my ($isbn,$title) = @_;
2493 my $dbh = C4::Context->dbh;
2499 $query = "Select distinct biblio.*, biblioitems.classification from biblio, biblioitems where
2500 biblio.biblionumber = biblioitems.biblionumber";
2503 $query .= " and isbn like ?";
2504 @bind=(uc($isbn)."%");
2507 $query .= " and title like ?";
2510 $sth = $dbh->prepare($query);
2512 $sth->execute(@bind);
2513 while (my $data = $sth->fetchrow_hashref) {
2514 $results[$count] = $data;
2519 return($count, @results);
2524 $branchname = &getbranchname($branchcode);
2526 Given the branch code, the function returns the corresponding
2527 branch name for a comprehensive information display
2533 my ($branchcode) = @_;
2534 my $dbh = C4::Context->dbh;
2535 my $sth = $dbh->prepare("SELECT branchname FROM branches WHERE branchcode = ?");
2536 $sth->execute($branchcode);
2537 my $branchname = $sth->fetchrow();
2540 } # sub getbranchname
2542 =item getborrowercategory
2544 $description = &getborrowercategory($categorycode);
2546 Given the borrower's category code, the function returns the corresponding
2547 description for a comprehensive information display.
2551 sub getborrowercategory
2554 my $dbh = C4::Context->dbh;
2555 my $sth = $dbh->prepare("SELECT description FROM categories WHERE categorycode = ?");
2556 $sth->execute($catcode);
2557 my $description = $sth->fetchrow();
2559 return $description;
2560 } # sub getborrowercategory
2563 END { } # module clean-up code here (global destructor)
2572 Koha Developement team <info@koha.org>