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
36 C4::Search - Functions for searching the Koha catalog and other databases
42 my ($count, @results) = catalogsearch($env, $type, $search, $num, $offset);
46 This module provides the searching facilities for the Koha catalog and
49 C<&catalogsearch> is a front end to all the other searches. Depending
50 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 &getallthemes &getalllanguages &getbranchname &getborrowercategory);
68 # make all your functions, whether exported or not;
72 my (@results) = newsearch($itemtype,$duration,$number_of_results,$startfrom);
73 c<newsearch> find biblio acquired recently (last 30 days)
76 my ($itemtype,$duration,$num,$offset)=@_;
78 my $dbh = C4::Context->dbh;
79 my $sth=$dbh->prepare("SELECT to_days( now( ) ) - to_days( dateaccessioned ) AS duration, biblio.biblionumber, barcode, title, author, classification, itemtype, dewey, dateaccessioned, price, replacementprice
80 FROM items, biblio, biblioitems
81 WHERE biblio.biblionumber = biblioitems.biblionumber AND
82 items.biblionumber = biblio.biblionumber AND
83 to_days( now( ) ) - to_days( dateaccessioned ) < ? and itemtype=?
84 ORDER BY duration ASC ");
85 $sth->execute($duration,$itemtype);
88 while (my $line = $sth->fetchrow_hashref) {
89 if ($i>=$offset && $i+$offset<$num) {
100 ($num_children, $children_arrayref) = &findguarantees($parent_borrno);
101 $child0_cardno = $children_arrayref->[0]{"cardnumber"};
102 $child0_borrno = $children_arrayref->[0]{"borrowernumber"};
104 C<&findguarantees> takes a borrower number (e.g., that of a patron
105 with children) and looks up the borrowers who are guaranteed by that
106 borrower (i.e., the patron's children).
108 C<&findguarantees> returns two values: an integer giving the number of
109 borrowers guaranteed by C<$parent_borrno>, and a reference to an array
110 of references to hash, which gives the actual results.
116 my $dbh = C4::Context->dbh;
117 my $sth=$dbh->prepare("select cardnumber,borrowernumber, firstname, surname from borrowers where guarantor=?");
118 $sth->execute($bornum);
121 while (my $data = $sth->fetchrow_hashref)
126 return (scalar(@dat), \@dat);
131 $guarantor = &findguarantor($borrower_no);
132 $guarantor_cardno = $guarantor->{"cardnumber"};
133 $guarantor_surname = $guarantor->{"surname"};
136 C<&findguarantor> takes a borrower number (presumably that of a child
137 patron), finds the guarantor for C<$borrower_no> (the child's parent),
138 and returns the record for the guarantor.
140 C<&findguarantor> returns a reference-to-hash. Its keys are the fields
141 from the C<borrowers> database table;
147 my $dbh = C4::Context->dbh;
148 my $sth=$dbh->prepare("select guarantor from borrowers where borrowernumber=?");
149 $sth->execute($bornum);
150 my $data=$sth->fetchrow_hashref;
152 $sth=$dbh->prepare("Select * from borrowers where borrowernumber=?");
153 $sth->execute($data->{'guarantor'});
154 $data=$sth->fetchrow_hashref;
159 =item NewBorrowerNumber
161 $num = &NewBorrowerNumber();
163 Allocates a new, unused borrower number, and returns it.
167 # FIXME - This is identical to C4::Circulation::Borrower::NewBorrowerNumber.
168 # Pick one and stick with it. Preferably use the other one. This function
169 # doesn't belong in C4::Search.
170 sub NewBorrowerNumber {
171 my $dbh = C4::Context->dbh;
172 my $sth=$dbh->prepare("Select max(borrowernumber) from borrowers");
174 my $data=$sth->fetchrow_hashref;
176 $data->{'max(borrowernumber)'}++;
177 return($data->{'max(borrowernumber)'});
182 ($count, @results) = &catalogsearch($env, $type, $search, $num, $offset);
184 This is primarily a front-end to other, more specialized catalog
185 search functions: if C<$search-E<gt>{itemnumber}> or
186 C<$search-E<gt>{isbn}> is given, C<&catalogsearch> uses a precise
187 C<&CatSearch>. If $search->{subject} is given, it runs a subject
188 C<&CatSearch>. If C<$search-E<gt>{keyword}> is given, it runs a
189 C<&KeywordSearch>. Otherwise, it runs a loose C<&CatSearch>.
191 If C<$env-E<gt>{itemcount}> is 1, then C<&catalogsearch> also counts
192 the items for each result, and adds several keys:
198 The total number of copies of this book.
200 =item C<locationhash>
202 This is a reference-to-hash; the keys are the names of branches where
203 this book may be found, and the values are the number of copies at
208 A descriptive string saying where the book is located, and how many
209 copies there are, if greater than 1.
213 The book's subject, with spaces replaced with C<%20>, presumably for
221 my ($env,$type,$search,$num,$offset)=@_;
222 my $dbh = C4::Context->dbh;
223 # foreach my $key (%$search){
224 # $search->{$key}=$dbh->quote($search->{$key});
226 my ($count,@results);
227 # print STDERR "Doing a search \n";
228 if ($search->{'itemnumber'} ne '' || $search->{'isbn'} ne ''){
229 print STDERR "Doing a precise search\n";
230 ($count,@results)=CatSearch($env,'precise',$search,$num,$offset);
231 } elsif ($search->{'subject'} ne ''){
232 ($count,@results)=CatSearch($env,'subject',$search,$num,$offset);
233 } elsif ($search->{'keyword'} ne ''){
234 ($count,@results)=&KeywordSearch($env,'keyword',$search,$num,$offset);
236 ($count,@results)=CatSearch($env,'loose',$search,$num,$offset);
239 if ($env->{itemcount} eq '1') {
240 foreach my $data (@results){
241 my ($counts) = itemcount2($env, $data->{'biblionumber'}, 'intra');
242 my $subject2=$data->{'subject'};
243 $subject2=~ s/ /%20/g;
244 $data->{'itemcount'}=$counts->{'total'};
245 my $totalitemcounts=0;
246 foreach my $key (keys %$counts){
247 if ($key ne 'total'){ # FIXME - Should ignore 'order', too.
248 #$data->{'location'}.="$key $counts->{$key} ";
249 $totalitemcounts+=$counts->{$key};
250 $data->{'locationhash'}->{$key}=$counts->{$key};
254 my $notavailabletext='';
255 foreach (sort keys %{$data->{'locationhash'}}) {
256 if ($_ eq 'notavailable') {
257 $notavailabletext="Not available";
258 my $c=$data->{'locationhash'}->{$_};
259 if ($totalitemcounts>1) {
260 $notavailabletext.=" ($c)";
264 my $c=$data->{'locationhash'}->{$_};
265 if ($totalitemcounts>1) {
266 $locationtext.=" ($c), ";
270 if ($notavailabletext) {
271 $locationtext.=$notavailabletext;
273 $locationtext=~s/, $//;
275 $data->{'location'}=$locationtext;
276 $data->{'subject2'}=$subject2;
279 return ($count,@results);
284 $search = { "keyword" => "One or more keywords",
285 "class" => "VID|CD", # Limit search to fiction and CDs
288 ($count, @results) = &KeywordSearch($env, $type, $search, $num, $offset);
290 C<&KeywordSearch> searches the catalog by keyword: given a string
291 (C<$search-E<gt>{"keyword"}> consisting of a space-separated list of
292 keywords, it looks for books that contain any of those keywords in any
293 of a number of places.
295 C<&KeywordSearch> looks for keywords in the book title (and subtitle),
296 series name, notes (both C<biblio.notes> and C<biblioitems.notes>),
299 C<$search-E<gt>{"class"}> can be set to a C<|> (pipe)-separated list of
300 item class codes (e.g., "F" for fiction, "JNF" for junior nonfiction,
301 etc.). In this case, the search will be restricted to just those
304 If C<$search-E<gt>{"class"}> is not specified, you may specify
305 C<$search-E<gt>{"dewey"}>. This will restrict the search to that
306 particular Dewey Decimal Classification category. Setting
307 C<$search-E<gt>{"dewey"}> to "513" will return books about arithmetic,
308 whereas setting it to "5" will return all books with Dewey code 5I<xx>
309 (Science and Mathematics).
311 C<$env> and C<$type> are ignored.
313 C<$offset> and C<$num> specify the subset of results to return.
314 C<$num> specifies the number of results to return, and C<$offset> is
315 the number of the first result. Thus, setting C<$offset> to 100 and
316 C<$num> to 5 will return results 100 through 104 inclusive.
321 my ($env,$type,$search,$num,$offset)=@_;
322 my $dbh = C4::Context->dbh;
323 $search->{'keyword'}=~ s/ +$//;
324 my @key=split(' ',$search->{'keyword'});
325 # FIXME - Naive users might enter comma-separated
326 # words, e.g., "training, animal". Ought to cope with
330 my %biblionumbers; # Set of biblionumbers returned by the
333 # FIXME - Ought to filter the stopwords out of the list of keywords.
334 # @key = map { !defined($stopwords{$_}) } @key;
336 # FIXME - The way this code is currently set up, it looks for all of
337 # the keywords first in (title, notes, seriestitle), then in the
338 # subtitle, then in the subject. Thus, if you look for keywords
339 # "science fiction", this search won't find a book with
340 # title = "How to write fiction"
341 # subtitle = "A science-based approach"
342 # Is this the desired effect? If not, then the first SQL query
343 # should look in the biblio, subtitle, and subject tables all at
344 # once. The way the first query is built can accomodate this easily.
346 # Look for keywords in table 'biblio'.
348 # Build an SQL query that finds each of the keywords in any of the
349 # title, biblio.notes, or seriestitle. To do this, we'll build up an
350 # array of clauses, one for each keyword.
351 my $query; # The SQL query
352 my @clauses = (); # The search clauses
353 my @bind = (); # The term bindings
355 $query = <<EOT; # Beginning of the query
360 foreach my $keyword (@key)
362 my @subclauses = (); # Subclauses, one for each field we're
365 # For each field we're searching on, create a subclause that'll
366 # match the current keyword in the current field.
367 foreach my $field (qw(title notes seriestitle author))
370 "$field LIKE ? OR $field LIKE ?";
371 push(@bind,"\Q$keyword\E%","% \Q$keyword\E%");
373 # (Yes, this could have been done as
374 # @subclauses = map {...} qw(field1 field2 ...)
375 # )but I think this way is more readable.
377 # Construct the current clause by joining the subclauses.
378 push @clauses, "(" . join(")\n\tOR (", @subclauses) . ")";
380 # Now join all of the clauses together and append to the query.
381 $query .= "(" . join(")\nAND (", @clauses) . ")";
383 # FIXME - Perhaps use $sth->bind_columns() ? Documented as the most
384 # efficient way to fetch data.
385 my $sth=$dbh->prepare($query);
386 $sth->execute(@bind);
387 while (my @res = $sth->fetchrow_array) {
390 $biblionumbers{$_} = 1; # Add these results to the set
395 # Now look for keywords in the 'bibliosubtitle' table.
397 # Again, we build a list of clauses from the keywords.
399 $query = "SELECT biblionumber FROM bibliosubtitle WHERE ";
400 foreach my $keyword (@key)
403 "subtitle LIKE ? OR subtitle like ?";
404 push(@bind,"\Q$keyword\E%","% \Q$keyword\E%");
406 $query .= "(" . join(") AND (", @clauses) . ")";
408 $sth=$dbh->prepare($query);
409 $sth->execute(@bind);
410 while (my @res = $sth->fetchrow_array) {
413 $biblionumbers{$_} = 1; # Add these results to the set
418 # Look for the keywords in the notes for individual items
419 # ('biblioitems.notes')
421 # Again, we build a list of clauses from the keywords.
424 $query = "SELECT biblionumber FROM biblioitems WHERE ";
425 foreach my $keyword (@key)
428 "notes LIKE ? OR notes like ?";
429 push(@bind,"\Q$keyword\E%","% \Q$keyword\E%");
431 $query .= "(" . join(") AND (", @clauses) . ")";
433 $sth=$dbh->prepare($query);
434 $sth->execute(@bind);
435 while (my @res = $sth->fetchrow_array) {
438 $biblionumbers{$_} = 1; # Add these results to the set
443 # Look for keywords in the 'bibliosubject' table.
445 # FIXME - The other queries look for words in the desired field that
446 # begin with the individual keywords the user entered. This one
447 # searches for the literal string the user entered. Is this the
449 # Note in particular that spaces are retained: if the user typed
451 # (with two spaces), this won't find the subject "science fiction"
452 # (one space). Likewise, a search for "%" will return absolutely
454 # If this isn't the desired effect, see the previous searches for
457 $sth=$dbh->prepare("Select biblionumber from bibliosubject where subject
458 like ? group by biblionumber");
459 $sth->execute("%$search->{'keyword'}%");
461 while (my @res = $sth->fetchrow_array) {
464 $biblionumbers{$_} = 1; # Add these results to the set
474 my @res = keys %biblionumbers;
478 # print "count $count";
479 if ($search->{'class'} ne ''){
481 my $query="select * from biblio,biblioitems where
482 biblio.biblionumber=? and
483 biblio.biblionumber=biblioitems.biblionumber ";
484 my @bind = ($res[$i2]);
485 if ($search->{'class'} ne ''){ # FIXME - Redundant
486 my @temp=split(/\|/,$search->{'class'});
488 $query.= "and ( itemtype=?";
489 push(@bind,$temp[0]);
490 for (my $i=1;$i<$count;$i++){
491 $query.=" or itemtype=?";
492 push(@bind,$temp[$i]);
496 my $sth=$dbh->prepare($query);
498 $sth->execute(@bind);
499 if (my $data2=$sth->fetchrow_hashref){
500 my $dewey= $data2->{'dewey'};
501 my $subclass=$data2->{'subclass'};
502 # FIXME - This next bit is bogus, because it assumes that the
503 # Dewey code is a floating-point number. It isn't. It's
504 # actually a string that mainly consists of numbers. In
505 # particular, "4" is not a valid Dewey code, although "004"
506 # is ("Data processing; Computer science"). Likewise, zeros
507 # after the decimal are significant ("575" is not the same as
508 # "575.0"; the latter is more specific). And "000" is a
509 # perfectly good Dewey code ("General works; computer
510 # science") and should not be interpreted to mean "this
511 # database entry does not have a Dewey code". That's what
514 ($dewey == 0) && ($dewey='');
515 ($dewey) && ($dewey.=" $subclass") ;
517 my $end=$offset +$num;
522 if ($i4 <=$end && $i4 > $offset){
523 $data2->{'dewey'}=$dewey;
526 # $res2[$i3]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey";
529 # print "in here $i3<br>";
540 # $search->{'class'} was not specified
542 # FIXME - This is bogus: it makes a separate query for each
543 # biblioitem, and returns results in apparently random order. It'd
544 # be much better to combine all of the previous queries into one big
545 # one (building it up a little at a time, of course), and have that
546 # big query select all of the desired fields, instead of just
549 while ($i2 < $num && $i2 < $count){
550 my $query="select * from biblio,biblioitems where
551 biblio.biblionumber=? and
552 biblio.biblionumber=biblioitems.biblionumber ";
553 my @bind=($res[$i2+$offset]);
555 if ($search->{'dewey'} ne ''){
556 $query.= "and (dewey like ?)";
557 push(@bind,"$search->{'dewey'}%");
560 my $sth=$dbh->prepare($query);
562 $sth->execute(@bind);
563 if (my $data2=$sth->fetchrow_hashref){
564 my $dewey= $data2->{'dewey'};
565 my $subclass=$data2->{'subclass'};
567 ($dewey == 0) && ($dewey='');
568 ($dewey) && ($dewey.=" $subclass") ;
570 $data2->{'dewey'}=$dewey;
573 # $res2[$i]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey";
582 return($count,@res2);
586 my ($env,$type,$search,$num,$offset)=@_;
587 my $dbh = C4::Context->dbh;
588 $search->{'keyword'}=~ s/ +$//;
589 my @key=split(' ',$search->{'keyword'});
593 my $query ="Select * from biblio,bibliosubtitle,biblioitems where
594 biblio.biblionumber=biblioitems.biblionumber and
595 biblio.biblionumber=bibliosubtitle.biblionumber and
596 (((title like ? or title like ?)";
597 my @bind=("$key[0]%","% $key[0]%");
599 $query .= " and (title like ? or title like ?)";
600 push(@bind,"$key[$i]%","% $key[$i]%");
603 $query.= ") or ((subtitle like ? or subtitle like ?)";
604 push(@bind,"$key[0]%","% $key[0]%");
605 for ($i=1;$i<$count;$i++){
606 $query.= " and (subtitle like ? or subtitle like ?)";
607 push(@bind,"$key[$i]%","% $key[$i]%");
609 $query.= ") or ((seriestitle like ? or seriestitle like ?)";
610 push(@bind,"$key[0]%","% $key[0]%");
611 for ($i=1;$i<$count;$i++){
612 $query.=" and (seriestitle like ? or seriestitle like ?)";
613 push(@bind,"$key[$i]%","% $key[$i]%");
615 $query.= ") or ((biblio.notes like ? or biblio.notes like ?)";
616 push(@bind,"$key[0]%","% $key[0]%");
617 for ($i=1;$i<$count;$i++){
618 $query.=" and (biblio.notes like ? or biblio.notes like ?)";
619 push(@bind,"$key[$i]%","% $key[$i]%");
621 $query.= ") or ((biblioitems.notes like ? or biblioitems.notes like ?)";
622 push(@bind,"$key[0]%","% $key[0]%");
623 for ($i=1;$i<$count;$i++){
624 $query.=" and (biblioitems.notes like ? or biblioitems.notes like ?)";
625 push(@bind,"$key[$i]%","% $key[$i]%");
627 if ($search->{'keyword'} =~ /new zealand/i){
628 $query.= "or (title like 'nz%' or title like '% nz %' or title like '% nz' or subtitle like 'nz%'
629 or subtitle like '% nz %' or subtitle like '% nz' or author like 'nz %'
630 or author like '% nz %' or author like '% nz')"
632 if ($search->{'keyword'} eq 'nz' || $search->{'keyword'} eq 'NZ' ||
633 $search->{'keyword'} =~ /nz /i || $search->{'keyword'} =~ / nz /i ||
634 $search->{'keyword'} =~ / nz/i){
635 $query.= "or (title like 'new zealand%' or title like '% new zealand %'
636 or title like '% new zealand' or subtitle like 'new zealand%' or
637 subtitle like '% new zealand %'
638 or subtitle like '% new zealand' or author like 'new zealand%'
639 or author like '% new zealand %' or author like '% new zealand' or
640 seriestitle like 'new zealand%' or seriestitle like '% new zealand %'
641 or seriestitle like '% new zealand')"
644 if ($search->{'class'} ne ''){
645 my @temp=split(/\|/,$search->{'class'});
647 $query.= "and ( itemtype=?";
648 push(@bind,"$temp[0]");
649 for (my $i=1;$i<$count;$i++){
650 $query.=" or itemtype=?";
651 push(@bind,"$temp[$i]");
655 if ($search->{'dewey'} ne ''){
656 $query.= "and (dewey like '$search->{'dewey'}%') ";
658 $query.="group by biblio.biblionumber";
659 #$query.=" order by author,title";
661 my $sth=$dbh->prepare($query);
662 $sth->execute(@bind);
664 while (my $data=$sth->fetchrow_hashref){
665 #FIXME: rewrite to use ? before uncomment
666 # my $sti=$dbh->prepare("select dewey,subclass from biblioitems where biblionumber=$data->{'biblionumber'}
669 # my ($dewey, $subclass) = $sti->fetchrow;
670 my $dewey=$data->{'dewey'};
671 my $subclass=$data->{'subclass'};
673 ($dewey == 0) && ($dewey='');
674 ($dewey) && ($dewey.=" $subclass");
676 $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey";
677 # print $results[$i];
681 $sth=$dbh->prepare("Select biblionumber from bibliosubject where subject
682 like ? group by biblionumber");
683 $sth->execute("%".$search->{'keyword'}."%");
684 while (my $data=$sth->fetchrow_hashref){
685 $query="Select * from biblio,biblioitems where
686 biblio.biblionumber=? and
687 biblio.biblionumber=biblioitems.biblionumber ";
688 @bind=($data->{'biblionumber'});
689 if ($search->{'class'} ne ''){
690 my @temp=split(/\|/,$search->{'class'});
692 $query.= " and ( itemtype=?";
693 push(@bind,$temp[0]);
694 for (my $i=1;$i<$count;$i++){
695 $query.=" or itemtype=?";
696 push(@bind,$temp[$i]);
701 if ($search->{'dewey'} ne ''){
702 $query.= "and (dewey like ?)";
703 push(@bind,"$search->{'dewey'}%");
705 my $sth2=$dbh->prepare($query);
706 $sth2->execute(@bind);
708 while (my $data2=$sth2->fetchrow_hashref){
709 my $dewey= $data2->{'dewey'};
710 my $subclass=$data2->{'subclass'};
712 ($dewey == 0) && ($dewey='');
713 ($dewey) && ($dewey.=" $subclass") ;
715 $results[$i]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey";
716 # print $results[$i];
722 @results=sort @results;
729 while ($i2 < $count){
730 if ($results[$i2] ne $res[$i-1]){
731 $res[$i]=$results[$i2];
739 while ($i2 < $num && $i2 < $count){
740 $res2[$i2]=$res[$i2+$offset];
752 ($count, @results) = &CatSearch($env, $type, $search, $num, $offset);
754 C<&CatSearch> searches the Koha catalog. It returns a list whose first
755 element is the number of returned results, and whose subsequent
756 elements are the results themselves.
758 Each returned element is a reference-to-hash. Most of the keys are
759 simply the fields from the C<biblio> table in the Koha database, but
760 the following keys may also be present:
766 The book's illustrator.
776 C<$type> may be C<subject>, C<loose>, or C<precise>. This controls the
777 high-level behavior of C<&CatSearch>, as described below.
779 In many cases, the description below says that a certain field in the
780 database must match the search string. In these cases, it means that
781 the beginning of some word in the field must match the search string.
782 Thus, an author search for "sm" will return books whose author is
783 "John Smith" or "Mike Smalls", but not "Paul Grossman", since the "sm"
784 does not occur at the beginning of a word.
786 Note that within each search mode, the criteria are and-ed together.
787 That is, if you perform a loose search on the author "Jerome" and the
788 title "Boat", the search will only return books by Jerome containing
791 It is not possible to cross modes, e.g., set the author to "Asimov"
792 and the subject to "Math" in hopes of finding books on math by Asimov.
796 If C<$type> is set to C<loose>, the following search criteria may be
801 =item C<$search-E<gt>{author}>
803 The search string is a space-separated list of words. Each word must
804 match either the C<author> or C<additionalauthors> field.
806 =item C<$search-E<gt>{title}>
808 Each word in the search string must match the book title. If no author
809 is specified, the book subtitle will also be searched.
811 =item C<$search-E<gt>{abstract}>
813 Searches for the given search string in the book's abstract.
815 =item C<$search-E<gt>{'date-before'}>
817 Searches for books whose copyright date matches the search string.
818 That is, setting C<$search-E<gt>{'date-before'}> to "1985" will find
819 books written in 1985, and setting it to "198" will find books written
820 between 1980 and 1989.
822 =item C<$search-E<gt>{title}>
824 Searches by title are also affected by the value of
825 C<$search-E<gt>{"ttype"}>; if it is set to C<exact>, then the book
826 title, (one of) the series titleZ<>(s), or (one of) the unititleZ<>(s) must
827 match the search string exactly (the subtitle is not searched).
829 If C<$search-E<gt>{"ttype"}> is set to anything other than C<exact>,
830 each word in the search string must match the title, subtitle,
831 unititle, or series title.
833 =item C<$search-E<gt>{class}>
835 Restricts the search to certain item classes. The value of
836 C<$search-E<gt>{"class"}> is a | (pipe)-separated list of item types.
837 Thus, setting it to "F" restricts the search to fiction, and setting
838 it to "CD|CAS" will only look in compact disks and cassettes.
840 =item C<$search-E<gt>{dewey}>
842 Searches for books whose Dewey Decimal Classification code matches the
843 search string. That is, setting C<$search-E<gt>{"dewey"}> to "5" will
844 search for all books in 5I<xx> (Science and mathematics), setting it
845 to "54" will search for all books in 54I<x> (Chemistry), and setting
846 it to "546" will search for books on inorganic chemistry.
848 =item C<$search-E<gt>{publisher}>
850 Searches for books whose publisher contains the search string (unlike
851 other search criteria, C<$search-E<gt>{publisher}> is a string, not a
856 =head2 Subject search
858 If C<$type> is set to C<subject>, the following search criterion may
863 =item C<$search-E<gt>{subject}>
865 The search string is a space-separated list of words, each of which
866 must match the book's subject.
868 Special case: if C<$search-E<gt>{subject}> is set to C<nz>,
869 C<&CatSearch> will search for books whose subject is "New Zealand".
870 However, setting C<$search-E<gt>{subject}> to C<"nz football"> will
871 search for books on "nz" and "football", not books on "New Zealand"
876 =head2 Precise search
878 If C<$type> is set to C<precise>, the following search criteria may be
883 =item C<$search-E<gt>{item}>
885 Searches for books whose barcode exactly matches the search string.
887 =item C<$search-E<gt>{isbn}>
889 Searches for books whose ISBN exactly matches the search string.
893 For a loose search, if an author was specified, the results are
894 ordered by author and title. If no author was specified, the results
895 are ordered by title.
897 For other (non-loose) searches, if a subject was specified, the
898 results are ordered alphabetically by subject.
900 In all other cases (e.g., loose search by keyword), the results are
906 my ($env,$type,$search,$num,$offset)=@_;
907 my $dbh = C4::Context->dbh;
912 my $title = lc($search->{'title'});
913 if ($type eq 'loose') {
914 if ($search->{'author'} ne ''){
915 my @key=split(' ',$search->{'author'});
918 $query="select *,biblio.author,biblio.biblionumber from
920 left join additionalauthors
921 on additionalauthors.biblionumber =biblio.biblionumber
923 ((biblio.author like ? or biblio.author like ? or
924 additionalauthors.author like ? or additionalauthors.author
927 @bind=("$key[0]%","% $key[0]%","$key[0]%","% $key[0]%");
930 biblio.author like ? or biblio.author like ? or
931 additionalauthors.author like ? or additionalauthors.author like ?
933 push(@bind,"$key[$i]%","% $key[$i]%","$key[$i]%","% $key[$i]%");
937 if ($search->{'title'} ne ''){
938 my @key=split(' ',$search->{'title'});
941 $query.= " and (((title like ? or title like ?)";
942 push(@bind,"$key[0]%","% $key[0]%");
944 $query .= " and (title like ? or title like ?)";
945 push(@bind,"$key[$i]%","% $key[$i]%");
948 $query.=") or ((seriestitle like ? or seriestitle like ?)";
949 push(@bind,"$key[0]%","% $key[0]%");
950 for ($i=1;$i<$count;$i++){
951 $query.=" and (seriestitle like ? or seriestitle like ?)";
952 push(@bind,"$key[$i]%","% $key[$i]%");
954 $query.=") or ((unititle like ? or unititle like ?)";
955 push(@bind,"$key[0]%","% $key[0]%");
956 for ($i=1;$i<$count;$i++){
957 $query.=" and (unititle like ? or unititle like ?)";
958 push(@bind,"$key[$i]%","% $key[$i]%");
962 if ($search->{'abstract'} ne ''){
963 $query.= " and (abstract like ?)";
964 push(@bind,"%$search->{'abstract'}%");
966 if ($search->{'date-before'} ne ''){
967 $query.= " and (copyrightdate like ?)";
968 push(@bind,"%$search->{'date-before'}%");
970 $query.=" group by biblio.biblionumber";
972 if ($search->{'title'} ne '') {
973 if ($search->{'ttype'} eq 'exact'){
974 $query="select * from biblio
976 (biblio.title=? or (biblio.unititle = ?
977 or biblio.unititle like ? or
978 biblio.unititle like ? or
979 biblio.unititle like ?) or
980 (biblio.seriestitle = ? or
981 biblio.seriestitle like ? or
982 biblio.seriestitle like ? or
983 biblio.seriestitle like ?)
985 @bind=($search->{'title'},$search->{'title'},"$search->{'title'} |%","%| $search->{'title'} |%","%| $search->{'title'}",$search->{'title'},"$search->{'title'} |%","%| $search->{'title'} |%","%| $search->{'title'}");
987 my @key=split(' ',$search->{'title'});
990 $query="select biblio.biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp,subtitle from biblio
991 left join bibliosubtitle on
992 biblio.biblionumber=bibliosubtitle.biblionumber
994 (((title like ? or title like ?)";
995 @bind=("$key[0]%","% $key[0]%");
997 $query .= " and (title like ? or title like ?)";
998 push(@bind,"$key[$i]%","% $key[$i]%");
1001 $query.=") or ((subtitle like ? or subtitle like ?)";
1002 push(@bind,"$key[0]%","% $key[0]%");
1003 for ($i=1;$i<$count;$i++){
1004 $query.=" and (subtitle like ? or subtitle like ?)";
1005 push(@bind,"$key[$i]%","% $key[$i]%");
1007 $query.=") or ((seriestitle like ? or seriestitle like ?)";
1008 push(@bind,"$key[0]%","% $key[0]%");
1009 for ($i=1;$i<$count;$i++){
1010 $query.=" and (seriestitle like ? or seriestitle like ?)";
1011 push(@bind,"$key[$i]%","% $key[$i]%");
1013 $query.=") or ((unititle like ? or unititle like ?)";
1014 push(@bind,"$key[0]%","% $key[0]%");
1015 for ($i=1;$i<$count;$i++){
1016 $query.=" and (unititle like ? or unititle like ?)";
1017 push(@bind,"$key[$i]%","% $key[$i]%");
1021 if ($search->{'abstract'} ne ''){
1022 $query.= " and (abstract like ?)";
1023 push(@bind,"%$search->{'abstract'}%");
1025 if ($search->{'date-before'} ne ''){
1026 $query.= " and (copyrightdate like ?)";
1027 push(@bind,"%$search->{'date-before'}%");
1029 } elsif ($search->{'class'} ne ''){
1030 $query="select * from biblioitems,biblio where biblio.biblionumber=biblioitems.biblionumber";
1031 my @temp=split(/\|/,$search->{'class'});
1033 $query.= " and ( itemtype= ?)";
1035 for (my $i=1;$i<$count;$i++){
1036 $query.=" or itemtype=?";
1037 push(@bind,$temp[$i]);
1040 if ($search->{'illustrator'} ne ''){
1041 $query.=" and illus like ?";
1042 push(@bind,"%".$search->{'illustrator'}."%");
1044 if ($search->{'dewey'} ne ''){
1045 $query.=" and biblioitems.dewey like ?";
1046 push(@bind,"$search->{'dewey'}%");
1048 } elsif ($search->{'dewey'} ne ''){
1049 $query="select * from biblioitems,biblio
1050 where biblio.biblionumber=biblioitems.biblionumber
1051 and biblioitems.dewey like ?";
1052 @bind=("$search->{'dewey'}%");
1053 } elsif ($search->{'illustrator'} ne '') {
1054 $query="select * from biblioitems,biblio
1055 where biblio.biblionumber=biblioitems.biblionumber
1056 and biblioitems.illus like ?";
1057 @bind=("%".$search->{'illustrator'}."%");
1058 } elsif ($search->{'publisher'} ne ''){
1059 $query = "Select * from biblio,biblioitems where biblio.biblionumber
1060 =biblioitems.biblionumber and (publishercode like ?)";
1061 @bind=("%$search->{'publisher'}%");
1062 } elsif ($search->{'abstract'} ne ''){
1063 $query = "Select * from biblio where abstract like ?";
1064 @bind=("%$search->{'abstract'}%");
1065 } elsif ($search->{'date-before'} ne ''){
1066 $query = "Select * from biblio where copyrightdate like ?";
1067 @bind=("%$search->{'date-before'}%");
1069 $query .=" group by biblio.biblionumber";
1072 if ($type eq 'subject'){
1073 my @key=split(' ',$search->{'subject'});
1076 $query="select * from bibliosubject, biblioitems where
1077 (bibliosubject.biblionumber = biblioitems.biblionumber) and ( subject like ? or subject like ? or subject like ?)";
1078 @bind=("$key[0]%","% $key[0]%","%($key[0])%");
1080 $query.=" and (subject like ? or subject like ? or subject like ?)";
1081 push(@bind,"$key[$i]%","% $key[$i]%","%($key[$i])%");
1085 # FIXME - Wouldn't it be better to fix the database so that if a
1086 # book has a subject "NZ", then it also gets added the subject
1088 # This can also be generalized by adding a table of subject
1089 # synonyms to the database: just declare "NZ" to be a synonym for
1090 # "New Zealand", "SF" a synonym for both "Science fiction" and
1091 # "Fantastic fiction", etc.
1093 if (lc($search->{'subject'}) eq 'nz'){
1094 $query.= " or (subject like 'NEW ZEALAND %' or subject like '% NEW ZEALAND %'
1095 or subject like '% NEW ZEALAND' or subject like '%(NEW ZEALAND)%' ) ";
1096 } elsif ( $search->{'subject'} =~ /^nz /i || $search->{'subject'} =~ / nz /i || $search->{'subject'} =~ / nz$/i){
1097 $query=~ s/ nz/ NEW ZEALAND/ig;
1098 $query=~ s/nz /NEW ZEALAND /ig;
1099 $query=~ s/\(nz\)/\(NEW ZEALAND\)/gi;
1102 if ($type eq 'precise'){
1103 if ($search->{'itemnumber'} ne ''){
1104 $query="select * from items,biblio ";
1105 my $search2=uc $search->{'itemnumber'};
1106 $query=$query." where
1107 items.biblionumber=biblio.biblionumber
1112 if ($search->{'isbn'} ne ''){
1113 my $search2=uc $search->{'isbn'};
1114 my $sth1=$dbh->prepare("select * from biblioitems where isbn=?");
1115 $sth1->execute($search2);
1117 while (my $data=$sth1->fetchrow_hashref) {
1118 my $sth=$dbh->prepare("select * from biblioitems,biblio where
1119 biblio.biblionumber = ?
1120 and biblioitems.biblionumber = biblio.biblionumber");
1121 $sth->execute($data->{'biblionumber'});
1122 # FIXME - There's already a $data in this scope.
1123 my $data=$sth->fetchrow_hashref;
1124 my ($dewey, $subclass) = ($data->{'dewey'}, $data->{'subclass'});
1125 # FIXME - The following assumes that the Dewey code is a
1126 # floating-point number. It isn't: it's a string.
1128 ($dewey == 0) && ($dewey='');
1129 ($dewey) && ($dewey.=" $subclass");
1130 $data->{'dewey'}=$dewey;
1131 $results[$i2]=$data;
1132 # $results[$i2]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'isbn'}\t$data->{'itemtype'}";
1139 if ($type ne 'precise' && $type ne 'subject'){
1140 if ($search->{'author'} ne ''){
1141 $query .= " order by biblio.author,title";
1143 $query .= " order by title";
1146 if ($type eq 'subject'){
1147 $query .= "group by subject order by subject ";
1150 my $sth=$dbh->prepare($query);
1151 $sth->execute(@bind);
1154 my $limit= $num+$offset;
1155 while (my $data=$sth->fetchrow_hashref){
1156 my $query="select dewey,subclass,publishercode from biblioitems where biblionumber=?";
1157 my @bind=($data->{'biblionumber'});
1158 if ($search->{'class'} ne ''){
1159 my @temp=split(/\|/,$search->{'class'});
1161 $query.= " and ( itemtype= ?";
1162 push(@bind,$temp[0]);
1163 for (my $i=1;$i<$count;$i++){
1164 $query.=" or itemtype=?";
1165 push(@bind,$temp[$i]);
1169 if ($search->{'dewey'} ne ''){
1170 $query.=" and dewey=? ";
1171 push(@bind,$search->{'dewey'});
1173 if ($search->{'illustrator'} ne ''){
1174 $query.=" and illus like ?";
1175 push(@bind,"%$search->{'illustrator'}%");
1177 if ($search->{'publisher'} ne ''){
1178 $query.= " and (publishercode like ?)";
1179 push(@bind,"%$search->{'publisher'}%");
1181 my $sti=$dbh->prepare($query);
1182 $sti->execute(@bind);
1188 if ($bibitemdata = $sti->fetchrow_hashref()){
1190 $dewey=$bibitemdata->{'dewey'};
1191 $subclass=$bibitemdata->{'subclass'};
1192 $publishercode=$bibitemdata->{'publishercode'};
1194 # print STDERR "$dewey $subclass $publishercode\n";
1195 # FIXME - The Dewey code is a string, not a number.
1197 ($dewey == 0) && ($dewey='');
1198 ($dewey) && ($dewey.=" $subclass");
1199 $data->{'dewey'}=$dewey;
1200 $data->{'publishercode'}=$publishercode;
1203 if ($count > $offset && $count <= $limit){
1212 return($count,@results);
1215 sub updatesearchstats{
1216 my ($dbh,$query)=@_;
1222 @results = &subsearch($env, $subject);
1224 Searches for books that have a subject that exactly matches
1227 C<&subsearch> returns an array of results. Each element of this array
1228 is a string, containing the book's title, author, and biblionumber,
1236 my ($env,$subject)=@_;
1237 my $dbh = C4::Context->dbh;
1238 my $sth=$dbh->prepare("Select * from biblio,bibliosubject where
1239 biblio.biblionumber=bibliosubject.biblionumber and
1240 bibliosubject.subject=? group by biblio.biblionumber
1241 order by biblio.title");
1242 $sth->execute($subject);
1245 while (my $data=$sth->fetchrow_hashref){
1246 push @results, $data;
1255 @results = &ItemInfo($env, $biblionumber, $type);
1257 Returns information about books with the given biblionumber.
1259 C<$type> may be either C<intra> or anything else. If it is not set to
1260 C<intra>, then the search will exclude lost, very overdue, and
1265 C<&ItemInfo> returns a list of references-to-hash. Each element
1266 contains a number of keys. Most of them are table items from the
1267 C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
1268 Koha database. Other keys include:
1272 =item C<$data-E<gt>{branchname}>
1274 The name (not the code) of the branch to which the book belongs.
1276 =item C<$data-E<gt>{datelastseen}>
1278 This is simply C<items.datelastseen>, except that while the date is
1279 stored in YYYY-MM-DD format in the database, here it is converted to
1280 DD/MM/YYYY format. A NULL date is returned as C<//>.
1282 =item C<$data-E<gt>{datedue}>
1284 =item C<$data-E<gt>{class}>
1286 This is the concatenation of C<biblioitems.classification>, the book's
1287 Dewey code, and C<biblioitems.subclass>.
1289 =item C<$data-E<gt>{ocount}>
1291 I think this is the number of copies of the book available.
1293 =item C<$data-E<gt>{order}>
1295 If this is set, it is set to C<One Order>.
1302 my ($env,$biblionumber,$type) = @_;
1303 my $dbh = C4::Context->dbh;
1304 my $query = "SELECT *,items.notforloan as itemnotforloan FROM items, biblio, biblioitems 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";
1315 my $sth=$dbh->prepare($query);
1316 $sth->execute($biblionumber);
1319 while (my $data=$sth->fetchrow_hashref){
1321 my $isth=$dbh->prepare("Select * from issues where itemnumber = ? and returndate is null");
1322 $isth->execute($data->{'itemnumber'});
1323 if (my $idata=$isth->fetchrow_hashref){
1324 $datedue = format_date($idata->{'date_due'});
1326 if ($data->{'itemlost'} eq '2'){
1327 $datedue='Very Overdue';
1329 if ($data->{'itemlost'} eq '1'){
1332 if ($data->{'wthdrawn'} eq '1'){
1333 $datedue="Cancelled";
1335 if ($datedue eq ''){
1336 # $datedue="Available";
1337 my ($restype,$reserves)=CheckReserves($data->{'itemnumber'});
1343 #get branch information.....
1344 my $bsth=$dbh->prepare("SELECT * FROM branches
1345 WHERE branchcode = ?");
1346 $bsth->execute($data->{'holdingbranch'});
1347 if (my $bdata=$bsth->fetchrow_hashref){
1348 $data->{'branchname'} = $bdata->{'branchname'};
1351 my $class = $data->{'classification'};
1352 my $dewey = $data->{'dewey'};
1354 if ($dewey eq "000.") { $dewey = "";}; # FIXME - "000" is general
1355 # books about computer science
1356 if ($dewey < 10){$dewey='00'.$dewey;}
1357 if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
1364 $class .= $data->{'subclass'};
1366 # $results[$i]="$data->{'title'}\t$data->{'barcode'}\t$datedue\t$data->{'branchname'}\t$data->{'dewey'}";
1367 # FIXME - If $data->{'datelastseen'} is NULL, perhaps it'd be prettier
1368 # to leave it empty, rather than convert it to "//".
1369 # Also ideally this should use the local format for displaying dates.
1370 my $date=format_date($data->{'datelastseen'});
1371 $data->{'datelastseen'}=$date;
1372 $data->{'datedue'}=$datedue;
1373 $data->{'class'}=$class;
1378 #FIXME: ordering/indentation here looks wrong
1379 my $sth2=$dbh->prepare("Select * from aqorders where biblionumber=>");
1380 $sth2->execute($biblionumber);
1383 if ($data=$sth2->fetchrow_hashref){
1384 $ocount=$data->{'quantity'} - $data->{'quantityreceived'};
1386 $data->{'ocount'}=$ocount;
1387 $data->{'order'}="One Order";
1398 @results = &GetItems($env, $biblionumber);
1400 Returns information about books with the given biblionumber.
1404 C<&GetItems> returns an array of strings. Each element is a
1405 tab-separated list of values: biblioitemnumber, itemtype,
1406 classification, Dewey number, subclass, ISBN, volume, number, and
1409 Itemdata, in turn, is a string of the form
1410 "I<barcode>C<[>I<holdingbranch>C<[>I<flags>" where I<flags> contains
1411 the string C<NFL> if the item is not for loan, and C<LOST> if the item
1417 my ($env,$biblionumber)=@_;
1418 #debug_msg($env,"GetItems");
1419 my $dbh = C4::Context->dbh;
1420 my $sth=$dbh->prepare("Select * from biblioitems where (biblionumber = ?)");
1421 $sth->execute($biblionumber);
1422 #debug_msg($env,"executed query");
1425 while (my $data=$sth->fetchrow_hashref) {
1426 #debug_msg($env,$data->{'biblioitemnumber'});
1427 my $dewey = $data->{'dewey'};
1429 my $line = $data->{'biblioitemnumber'}."\t".$data->{'itemtype'};
1430 $line .= "\t$data->{'classification'}\t$dewey";
1431 $line .= "\t$data->{'subclass'}\t$data->{isbn}";
1432 $line .= "\t$data->{'volume'}\t$data->{number}";
1433 my $isth= $dbh->prepare("select * from items where biblioitemnumber = ?");
1434 $isth->execute($data->{'biblioitemnumber'});
1435 while (my $idata = $isth->fetchrow_hashref) {
1436 my $iline = $idata->{'barcode'}."[".$idata->{'holdingbranch'}."[";
1437 if ($idata->{'notforloan'} == 1) {
1440 if ($idata->{'itemlost'} == 1) {
1443 $line .= "\t$iline";
1446 $results[$i] = $line;
1455 $item = &itemdata($barcode);
1457 Looks up the item with the given barcode, and returns a
1458 reference-to-hash containing information about that item. The keys of
1459 the hash are the fields from the C<items> and C<biblioitems> tables in
1466 my $dbh = C4::Context->dbh;
1467 my $sth=$dbh->prepare("Select * from items,biblioitems where barcode=?
1468 and items.biblioitemnumber=biblioitems.biblioitemnumber");
1469 $sth->execute($barcode);
1470 my $data=$sth->fetchrow_hashref;
1477 $data = &bibdata($biblionumber, $type);
1479 Returns information about the book with the given biblionumber.
1481 C<$type> is ignored.
1483 C<&bibdata> returns a reference-to-hash. The keys are the fields in
1484 the C<biblio>, C<biblioitems>, and C<bibliosubtitle> tables in the
1487 In addition, C<$data-E<gt>{subject}> is the list of the book's
1488 subjects, separated by C<" , "> (space, comma, space).
1490 If there are multiple biblioitems with the given biblionumber, only
1491 the first one is considered.
1496 my ($bibnum, $type) = @_;
1497 my $dbh = C4::Context->dbh;
1498 my $sth = $dbh->prepare("Select *, biblioitems.notes AS bnotes, biblio.notes
1499 from biblio, biblioitems
1500 left join bibliosubtitle on
1501 biblio.biblionumber = bibliosubtitle.biblionumber
1502 where biblio.biblionumber = ?
1503 and biblioitems.biblionumber = biblio.biblionumber");
1504 $sth->execute($bibnum);
1506 $data = $sth->fetchrow_hashref;
1508 $sth = $dbh->prepare("Select * from bibliosubject where biblionumber = ?");
1509 $sth->execute($bibnum);
1510 while (my $dat = $sth->fetchrow_hashref){
1511 $data->{'subject'} .= "$dat->{'subject'}, ";
1513 chop $data->{'subject'};
1514 chop $data->{'subject'};
1516 $sth = $dbh->prepare("Select * from additionalauthors where biblionumber = ?");
1517 $sth->execute($bibnum);
1518 while (my $dat = $sth->fetchrow_hashref){
1519 $data->{'additionalauthors'} .= "$dat->{'author'}, ";
1521 chop $data->{'additionalauthors'};
1522 chop $data->{'additionalauthors'};
1529 $itemdata = &bibitemdata($biblioitemnumber);
1531 Looks up the biblioitem with the given biblioitemnumber. Returns a
1532 reference-to-hash. The keys are the fields from the C<biblio>,
1533 C<biblioitems>, and C<itemtypes> tables in the Koha database, except
1534 that C<biblioitems.notes> is given as C<$itemdata-E<gt>{bnotes}>.
1540 my $dbh = C4::Context->dbh;
1541 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");
1544 $sth->execute($bibitem);
1546 $data = $sth->fetchrow_hashref;
1554 ($count, $subjects) = &subject($biblionumber);
1556 Looks up the subjects of the book with the given biblionumber. Returns
1557 a two-element list. C<$subjects> is a reference-to-array, where each
1558 element is a subject of the book, and C<$count> is the number of
1559 elements in C<$subjects>.
1565 my $dbh = C4::Context->dbh;
1566 my $sth=$dbh->prepare("Select * from bibliosubject where biblionumber=?");
1567 $sth->execute($bibnum);
1570 while (my $data=$sth->fetchrow_hashref){
1575 return($i,\@results);
1580 ($count, $authors) = &addauthors($biblionumber);
1582 Looks up the additional authors for the book with the given
1585 Returns a two-element list. C<$authors> is a reference-to-array, where
1586 each element is an additional author, and C<$count> is the number of
1587 elements in C<$authors>.
1593 my $dbh = C4::Context->dbh;
1594 my $sth=$dbh->prepare("Select * from additionalauthors where biblionumber=?");
1595 $sth->execute($bibnum);
1598 while (my $data=$sth->fetchrow_hashref){
1603 return($i,\@results);
1608 ($count, $subtitles) = &subtitle($biblionumber);
1610 Looks up the subtitles for the book with the given biblionumber.
1612 Returns a two-element list. C<$subtitles> is a reference-to-array,
1613 where each element is a subtitle, and C<$count> is the number of
1614 elements in C<$subtitles>.
1620 my $dbh = C4::Context->dbh;
1621 my $sth=$dbh->prepare("Select * from bibliosubtitle where biblionumber=?");
1622 $sth->execute($bibnum);
1625 while (my $data=$sth->fetchrow_hashref){
1630 return($i,\@results);
1635 @issues = &itemissues($biblioitemnumber, $biblio);
1637 Looks up information about who has borrowed the bookZ<>(s) with the
1638 given biblioitemnumber.
1640 C<$biblio> is ignored.
1642 C<&itemissues> returns an array of references-to-hash. The keys
1643 include the fields from the C<items> table in the Koha database.
1644 Additional keys include:
1650 If the item is currently on loan, this gives the due date.
1652 If the item is not on loan, then this is either "Available" or
1653 "Cancelled", if the item has been withdrawn.
1657 If the item is currently on loan, this gives the card number of the
1658 patron who currently has the item.
1660 =item C<timestamp0>, C<timestamp1>, C<timestamp2>
1662 These give the timestamp for the last three times the item was
1665 =item C<card0>, C<card1>, C<card2>
1667 The card number of the last three patrons who borrowed this item.
1669 =item C<borrower0>, C<borrower1>, C<borrower2>
1671 The borrower number of the last three patrons who borrowed this item.
1678 my ($bibitem, $biblio)=@_;
1679 my $dbh = C4::Context->dbh;
1680 # FIXME - If this function die()s, the script will abort, and the
1681 # user won't get anything; depending on how far the script has
1682 # gotten, the user might get a blank page. It would be much better
1683 # to at least print an error message. The easiest way to do this
1684 # is to set $SIG{__DIE__}.
1685 my $sth = $dbh->prepare("Select * from items where
1686 items.biblioitemnumber = ?")
1687 || die $dbh->errstr;
1691 $sth->execute($bibitem)
1692 || die $sth->errstr;
1694 while (my $data = $sth->fetchrow_hashref) {
1695 # Find out who currently has this item.
1696 # FIXME - Wouldn't it be better to do this as a left join of
1697 # some sort? Currently, this code assumes that if
1698 # fetchrow_hashref() fails, then the book is on the shelf.
1699 # fetchrow_hashref() can fail for any number of reasons (e.g.,
1700 # database server crash), not just because no items match the
1702 my $sth2 = $dbh->prepare("select * from issues,borrowers
1703 where itemnumber = ?
1704 and returndate is NULL
1705 and issues.borrowernumber = borrowers.borrowernumber");
1707 $sth2->execute($data->{'itemnumber'});
1708 if (my $data2 = $sth2->fetchrow_hashref) {
1709 $data->{'date_due'} = $data2->{'date_due'};
1710 $data->{'card'} = $data2->{'cardnumber'};
1711 $data->{'borrower'} = $data2->{'borrowernumber'};
1713 if ($data->{'wthdrawn'} eq '1') {
1714 $data->{'date_due'} = 'Cancelled';
1716 $data->{'date_due'} = 'Available';
1722 # Find the last 3 people who borrowed this item.
1723 $sth2 = $dbh->prepare("select * from issues, borrowers
1724 where itemnumber = ?
1725 and issues.borrowernumber = borrowers.borrowernumber
1726 and returndate is not NULL
1727 order by returndate desc,timestamp desc") || die $dbh->errstr;
1728 $sth2->execute($data->{'itemnumber'}) || die $sth2->errstr;
1729 for (my $i2 = 0; $i2 < 2; $i2++) { # FIXME : error if there is less than 3 pple borrowing this item
1730 if (my $data2 = $sth2->fetchrow_hashref) {
1731 $data->{"timestamp$i2"} = $data2->{'timestamp'};
1732 $data->{"card$i2"} = $data2->{'cardnumber'};
1733 $data->{"borrower$i2"} = $data2->{'borrowernumber'};
1738 $results[$i] = $data;
1748 $item = &itemnodata($env, $dbh, $biblioitemnumber);
1750 Looks up the item with the given biblioitemnumber.
1752 C<$env> and C<$dbh> are ignored.
1754 C<&itemnodata> returns a reference-to-hash whose keys are the fields
1755 from the C<biblio>, C<biblioitems>, and C<items> tables in the Koha
1761 my ($env,$dbh,$itemnumber) = @_;
1762 $dbh = C4::Context->dbh;
1763 my $sth=$dbh->prepare("Select * from biblio,items,biblioitems
1764 where items.itemnumber = ?
1765 and biblio.biblionumber = items.biblionumber
1766 and biblioitems.biblioitemnumber = items.biblioitemnumber");
1768 $sth->execute($itemnumber);
1769 my $data=$sth->fetchrow_hashref;
1776 ($count, $borrowers) = &BornameSearch($env, $searchstring, $type);
1778 Looks up patrons (borrowers) by name.
1782 BUGFIX 499: C<$type> is now used to determine type of search.
1783 if $type is "simple", search is performed on the first letter of the
1786 C<$searchstring> is a space-separated list of search terms. Each term
1787 must match the beginning a borrower's surname, first name, or other
1790 C<&BornameSearch> returns a two-element list. C<$borrowers> is a
1791 reference-to-array; each element is a reference-to-hash, whose keys
1792 are the fields of the C<borrowers> table in the Koha database.
1793 C<$count> is the number of elements in C<$borrowers>.
1797 #used by member enquiries from the intranet
1798 #called by member.pl
1800 my ($env,$searchstring,$type)=@_;
1801 my $dbh = C4::Context->dbh;
1802 my $query = ""; my $count; my @data;
1805 if($type eq "simple") # simple search for one letter only
1807 $query="Select * from borrowers where surname like ? order by surname,firstname";
1808 @bind=("$searchstring%");
1810 else # advanced search looking in surname, firstname and othernames
1812 @data=split(' ',$searchstring);
1814 $query="Select * from borrowers
1815 where ((surname like ? or surname like ?
1816 or firstname like ? or firstname like ?
1817 or othernames like ? or othernames like ?)
1819 @bind=("$data[0]%","% $data[0]%","$data[0]%","% $data[0]%","$data[0]%","% $data[0]%");
1820 for (my $i=1;$i<$count;$i++){
1821 $query=$query." and (".
1822 " firstname like ? or firstname like ?
1823 or othernames like ? or othernames like ?)";
1824 push(@bind,"$data[$i]%","% $data[$i]%","$data[$i]%","% $data[$i]%");
1827 $query=$query.") or cardnumber = ?
1828 order by surname,firstname";
1829 push(@bind,$searchstring);
1833 my $sth=$dbh->prepare($query);
1834 $sth->execute(@bind);
1837 while (my $data=$sth->fetchrow_hashref){
1838 push(@results,$data);
1842 return ($cnt,\@results);
1847 $borrower = &borrdata($cardnumber, $borrowernumber);
1849 Looks up information about a patron (borrower) by either card number
1850 or borrower number. If $borrowernumber is specified, C<&borrdata>
1851 searches by borrower number; otherwise, it searches by card number.
1853 C<&borrdata> returns a reference-to-hash whose keys are the fields of
1854 the C<borrowers> table in the Koha database.
1859 my ($cardnumber,$bornum)=@_;
1860 $cardnumber = uc $cardnumber;
1861 my $dbh = C4::Context->dbh;
1864 $sth=$dbh->prepare("Select * from borrowers where cardnumber=?");
1865 $sth->execute($cardnumber);
1867 $sth=$dbh->prepare("Select * from borrowers where borrowernumber=?");
1868 $sth->execute($bornum);
1870 my $data=$sth->fetchrow_hashref;
1874 } else { # try with firstname
1876 my $sth=$dbh->prepare("select * from borrowers where firstname=?");
1877 $sth->execute($cardnumber);
1878 my $data=$sth->fetchrow_hashref;
1888 ($count, $issues) = &borrissues($borrowernumber);
1890 Looks up what the patron with the given borrowernumber has borrowed.
1892 C<&borrissues> returns a two-element array. C<$issues> is a
1893 reference-to-array, where each element is a reference-to-hash; the
1894 keys are the fields from the C<issues>, C<biblio>, and C<items> tables
1895 in the Koha database. C<$count> is the number of elements in
1902 my $dbh = C4::Context->dbh;
1903 my $sth=$dbh->prepare("Select * from issues,biblio,items where borrowernumber=?
1904 and items.itemnumber=issues.itemnumber
1905 and items.biblionumber=biblio.biblionumber
1906 and issues.returndate is NULL order by date_due");
1907 $sth->execute($bornum);
1909 while (my $data = $sth->fetchrow_hashref) {
1910 push @result, $data;
1913 return(scalar(@result), \@result);
1918 ($count, $issues) = &allissues($borrowernumber, $sortkey, $limit);
1920 Looks up what the patron with the given borrowernumber has borrowed,
1921 and sorts the results.
1923 C<$sortkey> is the name of a field on which to sort the results. This
1924 should be the name of a field in the C<issues>, C<biblio>,
1925 C<biblioitems>, or C<items> table in the Koha database.
1927 C<$limit> is the maximum number of results to return.
1929 C<&allissues> returns a two-element array. C<$issues> is a
1930 reference-to-array, where each element is a reference-to-hash; the
1931 keys are the fields from the C<issues>, C<biblio>, C<biblioitems>, and
1932 C<items> tables of the Koha database. C<$count> is the number of
1933 elements in C<$issues>
1938 my ($bornum,$order,$limit)=@_;
1939 #FIXME: sanity-check order and limit
1940 my $dbh = C4::Context->dbh;
1941 my $query="Select * from issues,biblio,items,biblioitems
1942 where borrowernumber=? and
1943 items.biblioitemnumber=biblioitems.biblioitemnumber and
1944 items.itemnumber=issues.itemnumber and
1945 items.biblionumber=biblio.biblionumber order by $order";
1947 $query.=" limit $limit";
1950 my $sth=$dbh->prepare("");
1951 $sth->execute($bornum);
1954 while (my $data=$sth->fetchrow_hashref){
1959 return($i,\@result);
1964 ($borrowed, $due, $fine) = &borrdata2($env, $borrowernumber);
1966 Returns aggregate data about items borrowed by the patron with the
1967 given borrowernumber.
1971 C<&borrdata2> returns a three-element array. C<$borrowed> is the
1972 number of books the patron currently has borrowed. C<$due> is the
1973 number of overdue items the patron currently has borrowed. C<$fine> is
1974 the total fine currently due by the borrower.
1979 my ($env,$bornum)=@_;
1980 my $dbh = C4::Context->dbh;
1981 my $query="Select count(*) from issues where borrowernumber='$bornum' and
1982 returndate is NULL";
1984 my $sth=$dbh->prepare($query);
1986 my $data=$sth->fetchrow_hashref;
1988 $sth=$dbh->prepare("Select count(*) from issues where
1989 borrowernumber='$bornum' and date_due < now() and returndate is NULL");
1991 my $data2=$sth->fetchrow_hashref;
1993 $sth=$dbh->prepare("Select sum(amountoutstanding) from accountlines where
1994 borrowernumber='$bornum'");
1996 my $data3=$sth->fetchrow_hashref;
1999 return($data2->{'count(*)'},$data->{'count(*)'},$data3->{'sum(amountoutstanding)'});
2002 =item getboracctrecord
2004 ($count, $acctlines, $total) = &getboracctrecord($env, $borrowernumber);
2006 Looks up accounting data for the patron with the given borrowernumber.
2010 (FIXME - I'm not at all sure what this is about.)
2012 C<&getboracctrecord> returns a three-element array. C<$acctlines> is a
2013 reference-to-array, where each element is a reference-to-hash; the
2014 keys are the fields of the C<accountlines> table in the Koha database.
2015 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
2016 total amount outstanding for all of the account lines.
2020 sub getboracctrecord {
2021 my ($env,$params) = @_;
2022 my $dbh = C4::Context->dbh;
2025 my $sth=$dbh->prepare("Select * from accountlines where
2026 borrowernumber=? order by date desc,timestamp desc");
2028 $sth->execute($params->{'borrowernumber'});
2030 while (my $data=$sth->fetchrow_hashref){
2031 #FIXME before reinstating: insecure?
2032 # if ($data->{'itemnumber'} ne ''){
2033 # $query="Select * from items,biblio where items.itemnumber=
2034 # '$data->{'itemnumber'}' and biblio.biblionumber=items.biblionumber";
2035 # my $sth2=$dbh->prepare($query);
2037 # my $data2=$sth2->fetchrow_hashref;
2041 $acctlines[$numlines] = $data;
2043 $total += $data->{'amountoutstanding'};
2046 return ($numlines,\@acctlines,$total);
2051 ($count, $lcount, $nacount, $fcount, $scount, $lostcount,
2052 $mending, $transit,$ocount) =
2053 &itemcount($env, $biblionumber, $type);
2055 Counts the number of items with the given biblionumber, broken down by
2060 If C<$type> is not set to C<intra>, lost, very overdue, and withdrawn
2061 items will not be counted.
2063 C<&itemcount> returns a nine-element list:
2065 C<$count> is the total number of items with the given biblionumber.
2067 C<$lcount> is the number of items at the Levin branch.
2069 C<$nacount> is the number of items that are neither borrowed, lost,
2070 nor withdrawn (and are therefore presumably on a shelf somewhere).
2072 C<$fcount> is the number of items at the Foxton branch.
2074 C<$scount> is the number of items at the Shannon branch.
2076 C<$lostcount> is the number of lost and very overdue items.
2078 C<$mending> is the number of items at the Mending branch (being
2081 C<$transit> is the number of items at the Transit branch (in transit
2084 C<$ocount> is the number of items that haven't arrived yet
2085 (aqorders.quantity - aqorders.quantityreceived).
2090 # FIXME - There's also a &C4::Biblio::itemcount.
2091 # Since they're all exported, acqui/acquire.pl doesn't compile with -w.
2093 my ($env,$bibnum,$type)=@_;
2094 my $dbh = C4::Context->dbh;
2095 my $query="Select * from items where
2097 if ($type ne 'intra'){
2098 $query.=" and ((itemlost <>1 and itemlost <> 2) or itemlost is NULL) and
2099 (wthdrawn <> 1 or wthdrawn is NULL)";
2101 my $sth=$dbh->prepare($query);
2103 $sth->execute($bibnum);
2113 while (my $data=$sth->fetchrow_hashref){
2116 my $sth2=$dbh->prepare("select * from issues,items where issues.itemnumber=
2117 ? and returndate is NULL
2118 and items.itemnumber=issues.itemnumber and ((items.itemlost <>1 and
2119 items.itemlost <> 2) or items.itemlost is NULL)
2120 and (wthdrawn <> 1 or wthdrawn is NULL)");
2121 $sth2->execute($data->{'itemnumber'});
2122 if (my $data2=$sth2->fetchrow_hashref){
2125 if ($data->{'holdingbranch'} eq 'C' || $data->{'holdingbranch'} eq 'LT'){
2128 if ($data->{'holdingbranch'} eq 'F' || $data->{'holdingbranch'} eq 'FP'){
2131 if ($data->{'holdingbranch'} eq 'S' || $data->{'holdingbranch'} eq 'SP'){
2134 if ($data->{'itemlost'} eq '1'){
2137 if ($data->{'itemlost'} eq '2'){
2140 if ($data->{'holdingbranch'} eq 'FM'){
2143 if ($data->{'holdingbranch'} eq 'TR'){
2150 my $sth2=$dbh->prepare("Select * from aqorders where biblionumber=?");
2151 $sth2->execute($bibnum);
2152 if (my $data=$sth2->fetchrow_hashref){
2153 $ocount=$data->{'quantity'} - $data->{'quantityreceived'};
2158 return ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit,$ocount);
2163 $counts = &itemcount2($env, $biblionumber, $type);
2165 Counts the number of items with the given biblionumber, broken down by
2170 C<$type> may be either C<intra> or anything else. If it is not set to
2171 C<intra>, then the search will exclude lost, very overdue, and
2174 C<$&itemcount2> returns a reference-to-hash, with the following fields:
2180 The total number of items with this biblionumber.
2184 The number of items on order (aqorders.quantity -
2185 aqorders.quantityreceived).
2189 For each branch that has at least one copy of the book, C<$counts>
2190 will have a key with the branch name, giving the number of copies at
2198 my ($env,$bibnum,$type)=@_;
2199 my $dbh = C4::Context->dbh;
2200 my $query="Select * from items,branches where
2201 biblionumber=? and items.holdingbranch=branches.branchcode";
2202 if ($type ne 'intra'){
2203 $query.=" and ((itemlost <>1 and itemlost <> 2) or itemlost is NULL) and
2204 (wthdrawn <> 1 or wthdrawn is NULL)";
2206 my $sth=$dbh->prepare($query);
2208 $sth->execute($bibnum);
2211 while (my $data=$sth->fetchrow_hashref){
2218 'select * from items
2220 and not ((items.itemlost <>1 and items.itemlost <> 2)
2221 or items.itemlost is NULL)'
2224 'select * from items
2225 where itemnumber=? and not (wthdrawn <> 1 or wthdrawn is NULL)'
2227 'On Loan', "select * from issues,items
2228 where issues.itemnumber=? and returndate is NULL
2229 and items.itemnumber=issues.itemnumber"
2232 my($testlabel, $query2) = @$test;
2234 my $sth2=$dbh->prepare($query2);
2235 $sth2->execute($data->{'itemnumber'});
2237 # FIXME - fetchrow_hashref() can fail for any number of reasons
2238 # (e.g., a database server crash). Perhaps use a left join of some
2240 $status = $testlabel if $sth2->fetchrow_hashref;
2242 last if defined $status;
2244 $status = $data->{'branchname'} unless defined $status;
2247 my $sth2=$dbh->prepare("Select * from aqorders where biblionumber=? and
2248 datecancellationprinted is NULL and quantity > quantityreceived");
2249 $sth2->execute($bibnum);
2250 if (my $data=$sth2->fetchrow_hashref){
2251 $counts{'order'}=$data->{'quantity'} - $data->{'quantityreceived'};
2260 $description = &ItemType($itemtype);
2262 Given an item type code, returns the description for that type.
2267 # FIXME - I'm pretty sure that after the initial setup, the list of
2268 # item types doesn't change very often. Hence, it seems slow and
2269 # inefficient to make yet another database call to look up information
2270 # that'll only change every few months or years.
2272 # Much better, I think, to automatically build a Perl file that can be
2273 # included in those scripts that require it, e.g.:
2274 # @itemtypes = qw( ART BCD CAS CD F ... );
2276 # ART => "Art Prints",
2277 # BCD => "CD-ROM from book",
2278 # CD => "Compact disc (WN)",
2279 # F => "Free Fiction",
2282 # The web server can then run a cron job to rebuild this file from the
2283 # database every hour or so.
2285 # The same thing goes for branches, book funds, book sellers, currency
2286 # rates, printers, stopwords, and perhaps others.
2289 my $dbh = C4::Context->dbh;
2290 my $sth=$dbh->prepare("select description from itemtypes where itemtype=?");
2291 $sth->execute($type);
2292 my $dat=$sth->fetchrow_hashref;
2294 return ($dat->{'description'});
2299 ($count, @results) = &bibitems($biblionumber);
2301 Given the biblionumber for a book, C<&bibitems> looks up that book's
2302 biblioitems (different publications of the same book, the audio book
2303 and film versions, etc.).
2305 C<$count> is the number of elements in C<@results>.
2307 C<@results> is an array of references-to-hash; the keys are the fields
2308 of the C<biblioitems> and C<itemtypes> tables of the Koha database. In
2309 addition, C<itemlost> indicates the availability of the item: if it is
2310 "2", then all copies of the item are long overdue; if it is "1", then
2311 all copies are lost; otherwise, there is at least one copy available.
2317 my $dbh = C4::Context->dbh;
2318 my $sth = $dbh->prepare("SELECT biblioitems.*,
2320 MIN(items.itemlost) as itemlost,
2321 MIN(items.dateaccessioned) as dateaccessioned
2322 FROM biblioitems, itemtypes, items
2323 WHERE biblioitems.biblionumber = ?
2324 AND biblioitems.itemtype = itemtypes.itemtype
2325 AND biblioitems.biblioitemnumber = items.biblioitemnumber
2326 GROUP BY items.biblioitemnumber");
2329 $sth->execute($bibnum);
2330 while (my $data = $sth->fetchrow_hashref) {
2331 $results[$count] = $data;
2335 return($count, @results);
2340 @barcodes = &barcodes($biblioitemnumber);
2342 Given a biblioitemnumber, looks up the corresponding items.
2344 Returns an array of references-to-hash; the keys are C<barcode> and
2347 The returned items include very overdue items, but not lost ones.
2352 #called from request.pl
2353 my ($biblioitemnumber)=@_;
2354 my $dbh = C4::Context->dbh;
2355 my $sth=$dbh->prepare("SELECT barcode, itemlost, holdingbranch FROM items
2356 WHERE biblioitemnumber = ?
2357 AND (wthdrawn <> 1 OR wthdrawn IS NULL)");
2358 $sth->execute($biblioitemnumber);
2361 while (my $data=$sth->fetchrow_hashref){
2362 $barcodes[$i]=$data;
2371 ($count, @websites) = &getwebsites($biblionumber);
2373 Looks up the web sites pertaining to the book with the given
2376 C<$count> is the number of elements in C<@websites>.
2378 C<@websites> is an array of references-to-hash; the keys are the
2379 fields from the C<websites> table in the Koha database.
2384 my ($biblionumber) = @_;
2385 my $dbh = C4::Context->dbh;
2386 my $sth = $dbh->prepare("Select * from websites where biblionumber = ?");
2390 $sth->execute($biblionumber);
2391 while (my $data = $sth->fetchrow_hashref) {
2392 # FIXME - The URL scheme shouldn't be stripped off, at least
2393 # not here, since it's part of the URL, and will be useful in
2394 # constructing a link to the site. If you don't want the user
2395 # to see the "http://" part, strip that off when building the
2397 $data->{'url'} =~ s/^http:\/\///; # FIXME - Leaning toothpick
2399 $results[$count] = $data;
2404 return($count, @results);
2407 =item getwebbiblioitems
2409 ($count, @results) = &getwebbiblioitems($biblionumber);
2411 Given a book's biblionumber, looks up the web versions of the book
2412 (biblioitems with itemtype C<WEB>).
2414 C<$count> is the number of items in C<@results>. C<@results> is an
2415 array of references-to-hash; the keys are the items from the
2416 C<biblioitems> table of the Koha database.
2420 sub getwebbiblioitems {
2421 my ($biblionumber) = @_;
2422 my $dbh = C4::Context->dbh;
2423 my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?
2424 and itemtype = 'WEB'");
2428 $sth->execute($biblionumber);
2429 while (my $data = $sth->fetchrow_hashref) {
2430 $data->{'url'} =~ s/^http:\/\///;
2431 $results[$count] = $data;
2436 return($count, @results);
2437 } # sub getwebbiblioitems
2440 =item breedingsearch
2442 ($count, @results) = &breedingsearch($title,$isbn,$random);
2443 C<$title> contains the title,
2444 C<$isbn> contains isbn or issn,
2445 C<$random> contains the random seed from a z3950 search.
2447 C<$count> is the number of items in C<@results>. C<@results> is an
2448 array of references-to-hash; the keys are the items from the C<marc_breeding> table of the Koha database.
2452 sub breedingsearch {
2453 my ($title,$isbn,$z3950random) = @_;
2454 my $dbh = C4::Context->dbh;
2460 $query = "Select id,file,isbn,title,author from marc_breeding where ";
2462 $query .= "z3950random = ?";
2463 @bind=($z3950random);
2467 $query .= "title like ?";
2468 push(@bind,"$title%");
2470 if ($title && $isbn) {
2474 $query .= "isbn like ?";
2475 push(@bind,"$isbn%");
2478 $sth = $dbh->prepare($query);
2479 $sth->execute(@bind);
2480 while (my $data = $sth->fetchrow_hashref) {
2481 $results[$count] = $data;
2486 return($count, @results);
2487 } # sub breedingsearch
2490 =item getalllanguages
2492 (@languages) = &getalllanguages();
2493 (@languages) = &getalllanguages($theme);
2495 Returns an array of all available languages.
2499 sub getalllanguages {
2504 if ($type eq 'opac') {
2505 $htdocs=C4::Context->config('opachtdocs');
2506 if ($theme and -d "$htdocs/$theme") {
2507 opendir D, "$htdocs/$theme";
2508 foreach my $language (readdir D) {
2509 next if $language=~/^\./;
2510 next if $language eq 'all';
2511 push @languages, $language;
2513 return sort @languages;
2516 foreach my $theme (getallthemes('opac')) {
2517 opendir D, "$htdocs/$theme";
2518 foreach my $language (readdir D) {
2519 next if $language=~/^\./;
2520 next if $language eq 'all';
2521 $lang->{$language}=1;
2524 @languages=keys %$lang;
2525 return sort @languages;
2527 } elsif ($type eq 'intranet') {
2528 $htdocs=C4::Context->config('intrahtdocs');
2529 if ($theme and -d "$htdocs/$theme") {
2530 opendir D, "$htdocs/$theme";
2531 foreach my $language (readdir D) {
2532 next if $language=~/^\./;
2533 next if $language eq 'all';
2534 push @languages, $language;
2536 return sort @languages;
2539 foreach my $theme (getallthemes('opac')) {
2540 opendir D, "$htdocs/$theme";
2541 foreach my $language (readdir D) {
2542 next if $language=~/^\./;
2543 next if $language eq 'all';
2544 $lang->{$language}=1;
2547 @languages=keys %$lang;
2548 return sort @languages;
2552 my $htdocs=C4::Context->config('intrahtdocs');
2553 foreach my $theme (getallthemes('intranet')) {
2554 opendir D, "$htdocs/$theme";
2555 foreach my $language (readdir D) {
2556 next if $language=~/^\./;
2557 next if $language eq 'all';
2558 $lang->{$language}=1;
2561 my $htdocs=C4::Context->config('opachtdocs');
2562 foreach my $theme (getallthemes('opac')) {
2563 opendir D, "$htdocs/$theme";
2564 foreach my $language (readdir D) {
2565 next if $language=~/^\./;
2566 next if $language eq 'all';
2567 $lang->{$language}=1;
2570 @languages=keys %$lang;
2571 return sort @languages;
2577 (@themes) = &getallthemes('opac');
2578 (@themes) = &getallthemes('intranet');
2580 Returns an array of all available themes.
2588 if ($type eq 'intranet') {
2589 $htdocs=C4::Context->config('intrahtdocs');
2591 $htdocs=C4::Context->config('opachtdocs');
2593 opendir D, "$htdocs";
2594 my @dirlist=readdir D;
2595 foreach my $directory (@dirlist) {
2596 -d "$htdocs/$directory/en" and push @themes, $directory;
2605 ($count, @results) = &isbnsearch($isbn,$title);
2607 Given an isbn and/or a title, returns the biblios having it.
2608 Used in acqui.simple, isbnsearch.pl only
2610 C<$count> is the number of items in C<@results>. C<@results> is an
2611 array of references-to-hash; the keys are the items from the
2612 C<biblioitems> table of the Koha database.
2617 my ($isbn,$title) = @_;
2618 my $dbh = C4::Context->dbh;
2624 $query = "Select distinct biblio.* from biblio, biblioitems where
2625 biblio.biblionumber = biblioitems.biblionumber";
2628 $query .= " and isbn=?";
2632 $query .= " and title like ?";
2635 $sth = $dbh->prepare($query);
2637 $sth->execute(@bind);
2638 while (my $data = $sth->fetchrow_hashref) {
2639 $results[$count] = $data;
2644 return($count, @results);
2649 $branchname = &getbranchname($branchcode);
2651 Given the branch code, the function returns the corresponding
2652 branch name for a comprehensive information display
2658 my ($branchcode) = @_;
2659 my $dbh = C4::Context->dbh;
2660 my $sth = $dbh->prepare("SELECT branchname FROM branches WHERE branchcode = ?");
2661 $sth->execute($branchcode);
2662 my $branchname = $sth->fetchrow();
2665 } # sub getbranchname
2667 =item getborrowercategory
2669 $description = &getborrowercategory($categorycode);
2671 Given the borrower's category code, the function returns the corresponding
2672 description for a comprehensive information display.
2676 sub getborrowercategory
2679 my $dbh = C4::Context->dbh;
2680 my $sth = $dbh->prepare("SELECT description FROM categories WHERE categorycode = ?");
2681 $sth->execute($catcode);
2682 my $description = $sth->fetchrow();
2684 return $description;
2685 } # sub getborrowercategory
2688 END { } # module clean-up code here (global destructor)
2697 Koha Developement team <info@koha.org>