see mail on koha-devel : code cleaning on Search.pm + normalizing API + use of biblio...
authortipaul <tipaul>
Thu, 22 Sep 2005 10:01:45 +0000 (10:01 +0000)
committertipaul <tipaul>
Thu, 22 Sep 2005 10:01:45 +0000 (10:01 +0000)
42 files changed:
C4/Accounts.pm
C4/Accounts2.pm
C4/Biblio.pm
C4/Koha.pm
C4/Members.pm
C4/Reserves2.pm
C4/Search.pm
ISBDdetail.pl
MARCdetail.pl
acqui.simple/additem.pl
boraccount.pl
bull/subscription-bib-search.pl
bull/subscription-detail.pl
circ/circulation.pl
detail.pl
detailprint.pl
mancredit.pl
maninvoice.pl
members/member-flags.pl
members/member.pl
members/moremember.pl
misc/cronjobs/reservelist.pl
misc/fines2.pl
misc/notifys/fines.pl
modbib.pl
modbibitem.pl
moditem.pl
modrequest.pl
modwebsites.pl
opac/opac-account.pl
opac/opac-basket.pl
opac/opac-detail.pl
opac/opac-detailprint.pl
opac/opac-readingrecord.pl
opac/opac-reserve.pl
opac/opac-searchresults.pl
opac/opac-sendbasket.pl
opac/opac-user.pl
pay.pl
placerequest.pl
readingrec.pl
request.pl

index 83ae1a2..b991e26 100755 (executable)
@@ -30,7 +30,7 @@ require Exporter;
 use DBI;
 use C4::Context;
 use C4::Format;
-use C4::Search;
+use C4::Biblio;
 use C4::Stats;
 #use C4::InterfaceCDK;
 #use C4::Interface::AccountsCDK;
@@ -137,7 +137,7 @@ sub reconcileaccount {
   while (my $data=$sth->fetchrow_hashref){
     my $line=$i+1;
     my $amount=0+$data->{'amountoutstanding'};
-    my $itemdata = itemnodata($env,$dbh,$data->{'itemnumber'});
+    my $itemdata = getbibliofromitemnumber($env,$dbh,$data->{'itemnumber'});
     $line= $data->{'accountno'}." ".$data->{'date'}." ".$data->{'accounttype'}." ";
     my $title = $itemdata->{'title'};
     if (length($title) > 15 ) {$title = substr($title,0,15);}
index 3efec32..8052db4 100755 (executable)
@@ -23,7 +23,7 @@ require Exporter;
 use DBI;
 use C4::Context;
 use C4::Stats;
-use C4::Search;
+use C4::Members;
 use C4::Circulation::Circ2;
 use vars qw($VERSION @ISA @EXPORT);
 
@@ -253,7 +253,7 @@ EOT
 sub returnlost{
   my ($borrnum,$itemnum)=@_;
   my $dbh = C4::Context->dbh;
-  my $borrower=borrdata('',$borrnum); #from C4::Search;
+  my $borrower=borrdata('',$borrnum);
   my $sth=$dbh->prepare("Update issues set returndate=now() where
   borrowernumber=? and itemnumber=? and returndate is null");
   $sth->execute($borrnum,$itemnum);
index 088945e..a3af5b9 100644 (file)
@@ -21,6 +21,7 @@ use strict;
 require Exporter;
 use C4::Context;
 use C4::Database;
+use C4::Date;
 use MARC::Record;
 use MARC::File::USMARC;
 use MARC::File::XML;
@@ -37,13 +38,18 @@ $VERSION = 0.01;
 # as the old-style API and the NEW one are the only public functions.
 #
 @EXPORT = qw(
-  &itemcount &newbiblio &newbiblioitem
-  &newsubject &newsubtitle
-  &modbiblio &checkitems
-  &newitems &modbibitem
+  &newbiblio &newbiblioitem
+  &newsubject &newsubtitle &newitems 
+  
+  &modbiblio &checkitems &modbibitem
   &modsubtitle &modsubject &modaddauthor &moditem
+  
   &delitem &deletebiblioitem &delbiblio
-  &getbiblio
+  
+  &getbiblio &bibdata &bibitems &bibitemdata 
+  &barcodes &ItemInfo &itemdata &itemissues &itemcount 
+  &getsubject &getaddauthor &getsubtitle
+  &getwebbiblioitems &getwebsites
   &getbiblioitembybiblionumber
   &getbiblioitem &getitemsbybiblioitem
 
@@ -143,7 +149,6 @@ sub zebra_create {
        close F;
        my $res = system("cd $cgidir/zebra;/usr/local/bin/zebraidx update biblios");
        unlink($filename);
-       warn "$biblionumber : $res";
 }
 
 =head2 @tagslib = &MARCgettagslib($dbh,1|0,$frameworkcode);
@@ -395,7 +400,6 @@ sub MARCkoha2marcBiblio {
                &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle", $row->{'subtitle'},'' );
        }
        
-       warn "RECORD : ".$record->as_formatted;
        return $record;
 }
 
@@ -413,38 +417,18 @@ all entries of the hash are transformed into their matching MARC field/subfield.
 sub MARCkoha2marcItem {
 
     # this function builds partial MARC::Record from the old koha-DB fields
-    my ( $dbh, $biblionumber, $itemnumber ) = @_;
+    my ( $dbh, $item ) = @_;
 
     #    my $dbh=&C4Connect;
-    my $sth =
-      $dbh->prepare(
-"select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
-    );
+    my $sth = $dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?");
     my $record = MARC::Record->new();
 
-    #--- if item, then retrieve old-style koha data
-    if ( $itemnumber > 0 ) {
-
-        #      print STDERR "prepare $biblionumber,$itemnumber\n";
-        my $sth2 =
-          $dbh->prepare(
-"SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
-                                               booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
-                                               datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,itemcallnumber,issues,renewals,
-                                       reserves,restricted,binding,itemnotes,holdingbranch,timestamp
-                                       FROM items
-                                       WHERE itemnumber=?"
-        );
-        $sth2->execute($itemnumber);
-        my $row = $sth2->fetchrow_hashref;
-        my $code;
-        foreach $code ( keys %$row ) {
-            if ( $row->{$code} ) {
-                &MARCkoha2marcOnefield( $sth, $record, "items." . $code,
-                    $row->{$code},'' );
-            }
-        }
-    }
+       foreach( keys %$item ) {
+               if ( $item->{$_} ) {
+                       &MARCkoha2marcOnefield( $sth, $record, "items." . $_,
+                               $item->{$_},'' );
+               }
+       }
     return $record;
 }
 
@@ -1090,13 +1074,15 @@ sub REALmodbiblioitem {
     my ( $dbh, $biblioitem ) = @_;
     my $query;
 
-    my $sth = $dbh->prepare("update biblioitems set    itemtype=?,                     url=?,                          isbn=?, issn=?,
+    my $sth = $dbh->prepare("update biblioitems set number=?,volume=?,                 volumedate=?,           lccn=?,
+                                                                               itemtype=?,                     url=?,                          isbn=?,                         issn=?,
                                                                                publishercode=?,        publicationyear=?,      classification=?,       dewey=?,
                                                                                subclass=?,                     illus=?,                        pages=?,                        volumeddesc=?,
                                                                                notes=?,                        size=?,                         place=?,                        marc=?,
                                                                                marcxml=?
                                                        where biblioitemnumber=?");
-       $sth->execute(  $biblioitem->{itemtype},                $biblioitem->{url},             $biblioitem->{isbn},    $biblioitem->{issn},
+       $sth->execute(  $biblioitem->{number},                  $biblioitem->{volume},  $biblioitem->{volumedate},      $biblioitem->{lccn},
+                                       $biblioitem->{itemtype},                $biblioitem->{url},             $biblioitem->{isbn},    $biblioitem->{issn},
                                $biblioitem->{publishercode},   $biblioitem->{publicationyear}, $biblioitem->{classification},  $biblioitem->{dewey},
                                $biblioitem->{subclass},                $biblioitem->{illus},           $biblioitem->{pages},   $biblioitem->{volumeddesc},
                                $biblioitem->{bnotes},                  $biblioitem->{size},            $biblioitem->{place},   $biblioitem->{marc},
@@ -1203,7 +1189,7 @@ sub REALnewitems {
 
 #      warn "OLDNEWITEMS";
        
-       $dbh->do('lock tables items WRITE, biblio WRITE,biblioitems WRITE');
+       $dbh->do('lock tables items WRITE, biblio WRITE,biblioitems WRITE,marc_subfield_structure WRITE');
     my $sth = $dbh->prepare("Select max(itemnumber) from items");
     my $data;
     my $itemnumber;
@@ -1237,7 +1223,7 @@ sub REALnewitems {
         $sth->execute(
                        $itemnumber,                            $item->{'biblionumber'},
                        $item->{'multivolumepart'},
-                       $item->{'biblioitemnumber'},$barcode,
+                       $item->{'biblioitemnumber'},$item->{barcode},
                        $item->{'booksellerid'},        $item->{'dateaccessioned'},
                        $item->{'homebranch'},          $item->{'holdingbranch'},
                        $item->{'price'},                       $item->{'replacementprice'},
@@ -1270,7 +1256,7 @@ sub REALnewitems {
         $sth->execute(
                        $itemnumber,                            $item->{'biblionumber'},
                        $item->{'multivolumepart'},
-                       $item->{'biblioitemnumber'},$barcode,
+                       $item->{'biblioitemnumber'},$item->{barcode},
                        $item->{'booksellerid'},
                        $item->{'homebranch'},          $item->{'holdingbranch'},
                        $item->{'price'},                       $item->{'replacementprice'},
@@ -1293,7 +1279,7 @@ sub REALnewitems {
         $error .= $sth->errstr;
     }
        my ($rawmarc,$frameworkcode) = $sth->fetchrow;
-       warn "ERROR IN OLDnewitem, MARC record not found FOR $item->{biblionumber} => $rawmarc <=" unless $rawmarc;
+       warn "ERROR IN REALnewitem, MARC record not found FOR $item->{biblionumber} => $rawmarc <=" unless $rawmarc;
        my $record = MARC::File::USMARC::decode($rawmarc);
        # ok, we have the marc record, add item number to the item field (in {marc}, and add the field to the record)
        my ($itemnumberfield,$itemnumbersubfield) = MARCfind_marc_from_kohafield($dbh,'items.itemnumber',$frameworkcode);
@@ -1616,7 +1602,6 @@ sub modbiblio {
        my ($biblio) = @_;
        my $dbh  = C4::Context->dbh;
        my $biblionumber=REALmodbiblio($dbh,$biblio);
-       warn "in MODBIBLIO";
        my $record = MARCkoha2marcBiblio($dbh,$biblionumber,$biblionumber);
        # finds new (MARC bibid
        my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
@@ -1762,11 +1747,14 @@ sub newitems {
     my $itemnumber;
     my $error;
     foreach my $barcode (@barcodes) {
-        ( $itemnumber, $error ) = &REALnewitems( $dbh, $item, uc($barcode) );
-        $errors .= $error;
-        my $MARCitem =
-          &MARCkoha2marcItem( $dbh, $item->{biblionumber}, $itemnumber );
-        &MARCadditem( $dbh, $MARCitem, $item->{biblionumber} );
+               # add items, one by one for each barcode.
+               my $oneitem=$item;
+               $oneitem->{barcode}= $barcode;
+        my $MARCitem = &MARCkoha2marcItem( $dbh, $oneitem);
+               $oneitem->{marc} = $MARCitem->as_usmarc;
+        ( $itemnumber, $error ) = &REALnewitems( $dbh, $oneitem);
+#         $errors .= $error;
+#         &MARCadditem( $dbh, $MARCitem, $item->{biblionumber} );
     }
     return ($errors);
 }
@@ -1902,6 +1890,74 @@ sub getbiblio {
     return ( $count, @results );
 }    # sub getbiblio
 
+=item bibdata
+
+  $data = &bibdata($biblionumber, $type);
+
+Returns information about the book with the given biblionumber.
+
+C<$type> is ignored.
+
+C<&bibdata> returns a reference-to-hash. The keys are the fields in
+the C<biblio>, C<biblioitems>, and C<bibliosubtitle> tables in the
+Koha database.
+
+In addition, C<$data-E<gt>{subject}> is the list of the book's
+subjects, separated by C<" , "> (space, comma, space).
+
+If there are multiple biblioitems with the given biblionumber, only
+the first one is considered.
+
+=cut
+#'
+sub bibdata {
+       my ($bibnum, $type) = @_;
+       my $dbh   = C4::Context->dbh;
+       my $sth   = $dbh->prepare("Select *, biblioitems.notes AS bnotes, biblio.notes
+                                                               from biblio 
+                                                               left join biblioitems on biblioitems.biblionumber = biblio.biblionumber
+                                                               left join bibliosubtitle on
+                                                               biblio.biblionumber = bibliosubtitle.biblionumber
+                                                               left join itemtypes on biblioitems.itemtype=itemtypes.itemtype
+                                                               where biblio.biblionumber = ?
+                                                               ");
+       $sth->execute($bibnum);
+       my $data;
+       $data  = $sth->fetchrow_hashref;
+       $sth->finish;
+       # handle management of repeated subtitle
+       $sth   = $dbh->prepare("Select * from bibliosubtitle where biblionumber = ?");
+       $sth->execute($bibnum);
+       my @subtitles;
+       while (my $dat = $sth->fetchrow_hashref){
+               my %line;
+               $line{subtitle} = $dat->{subtitle};
+               push @subtitles, \%line;
+       } # while
+       $data->{subtitles} = \@subtitles;
+       $sth->finish;
+       $sth   = $dbh->prepare("Select * from bibliosubject where biblionumber = ?");
+       $sth->execute($bibnum);
+       my @subjects;
+       while (my $dat = $sth->fetchrow_hashref){
+               my %line;
+               $line{subject} = $dat->{'subject'};
+               push @subjects, \%line;
+       } # while
+       $data->{subjects} = \@subjects;
+       $sth->finish;
+       $sth   = $dbh->prepare("Select * from additionalauthors where biblionumber = ?");
+       $sth->execute($bibnum);
+       while (my $dat = $sth->fetchrow_hashref){
+               $data->{'additionalauthors'} .= "$dat->{'author'} - ";
+       } # while
+       chop $data->{'additionalauthors'};
+       chop $data->{'additionalauthors'};
+       chop $data->{'additionalauthors'};
+       $sth->finish;
+       return($data);
+} # sub bibdata
+
 =head2 ($count,@results) = getbiblioitem($biblioitemnumber);
 
 =over 4
@@ -1996,6 +2052,528 @@ biblio.biblionumber = items.biblionumber and biblioitemnumber
     return ( $count, @results );
 }    # sub getitemsbybiblioitem
 
+=item ItemInfo
+
+  @results = &ItemInfo($env, $biblionumber, $type);
+
+Returns information about books with the given biblionumber.
+
+C<$type> may be either C<intra> or anything else. If it is not set to
+C<intra>, then the search will exclude lost, very overdue, and
+withdrawn items.
+
+C<$env> is ignored.
+
+C<&ItemInfo> returns a list of references-to-hash. Each element
+contains a number of keys. Most of them are table items from the
+C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
+Koha database. Other keys include:
+
+=over 4
+
+=item C<$data-E<gt>{branchname}>
+
+The name (not the code) of the branch to which the book belongs.
+
+=item C<$data-E<gt>{datelastseen}>
+
+This is simply C<items.datelastseen>, except that while the date is
+stored in YYYY-MM-DD format in the database, here it is converted to
+DD/MM/YYYY format. A NULL date is returned as C<//>.
+
+=item C<$data-E<gt>{datedue}>
+
+=item C<$data-E<gt>{class}>
+
+This is the concatenation of C<biblioitems.classification>, the book's
+Dewey code, and C<biblioitems.subclass>.
+
+=item C<$data-E<gt>{ocount}>
+
+I think this is the number of copies of the book available.
+
+=item C<$data-E<gt>{order}>
+
+If this is set, it is set to C<One Order>.
+
+=back
+
+=cut
+#'
+sub ItemInfo {
+       my ($env,$biblionumber,$type) = @_;
+       my $dbh   = C4::Context->dbh;
+       my $query = "SELECT *,items.notforloan as itemnotforloan FROM items, biblio, biblioitems 
+                                       left join itemtypes on biblioitems.itemtype = itemtypes.itemtype
+                                       WHERE items.biblionumber = ?
+                                       AND biblioitems.biblioitemnumber = items.biblioitemnumber
+                                       AND biblio.biblionumber = items.biblionumber";
+       $query .= " order by items.dateaccessioned desc";
+       my $sth=$dbh->prepare($query);
+       $sth->execute($biblionumber);
+       my $i=0;
+       my @results;
+       while (my $data=$sth->fetchrow_hashref){
+               my $datedue = '';
+               my $isth=$dbh->prepare("Select issues.*,borrowers.cardnumber from issues,borrowers where itemnumber = ? and returndate is null and issues.borrowernumber=borrowers.borrowernumber");
+               $isth->execute($data->{'itemnumber'});
+               if (my $idata=$isth->fetchrow_hashref){
+               $data->{borrowernumber} = $idata->{borrowernumber};
+               $data->{cardnumber} = $idata->{cardnumber};
+               $datedue = format_date($idata->{'date_due'});
+               }
+               if ($datedue eq ''){
+                       my ($restype,$reserves)=C4::Reserves2::CheckReserves($data->{'itemnumber'});
+                       if ($restype) {
+                               $datedue=$restype;
+                       }
+               }
+               $isth->finish;
+       #get branch information.....
+               my $bsth=$dbh->prepare("SELECT * FROM branches WHERE branchcode = ?");
+               $bsth->execute($data->{'holdingbranch'});
+               if (my $bdata=$bsth->fetchrow_hashref){
+                       $data->{'branchname'} = $bdata->{'branchname'};
+               }
+               my $date=format_date($data->{'datelastseen'});
+               $data->{'datelastseen'}=$date;
+               $data->{'datedue'}=$datedue;
+       # get notforloan complete status if applicable
+               my $sthnflstatus = $dbh->prepare('select authorised_value from marc_subfield_structure where kohafield="items.notforloan"');
+               $sthnflstatus->execute;
+               my ($authorised_valuecode) = $sthnflstatus->fetchrow;
+               if ($authorised_valuecode) {
+                       $sthnflstatus = $dbh->prepare("select lib from authorised_values where category=? and authorised_value=?");
+                       $sthnflstatus->execute($authorised_valuecode,$data->{itemnotforloan});
+                       my ($lib) = $sthnflstatus->fetchrow;
+                       $data->{notforloan} = $lib;
+               }
+               $results[$i]=$data;
+               $i++;
+       }
+       $sth->finish;
+       return(@results);
+}
+
+=item bibitems
+
+  ($count, @results) = &bibitems($biblionumber);
+
+Given the biblionumber for a book, C<&bibitems> looks up that book's
+biblioitems (different publications of the same book, the audio book
+and film versions, etc.).
+
+C<$count> is the number of elements in C<@results>.
+
+C<@results> is an array of references-to-hash; the keys are the fields
+of the C<biblioitems> and C<itemtypes> tables of the Koha database. In
+addition, C<itemlost> indicates the availability of the item: if it is
+"2", then all copies of the item are long overdue; if it is "1", then
+all copies are lost; otherwise, there is at least one copy available.
+
+=cut
+#'
+sub bibitems {
+    my ($bibnum) = @_;
+    my $dbh   = C4::Context->dbh;
+    my $sth   = $dbh->prepare("SELECT biblioitems.*,
+                        itemtypes.*,
+                        MIN(items.itemlost)        as itemlost,
+                        MIN(items.dateaccessioned) as dateaccessioned
+                          FROM biblioitems, itemtypes, items
+                         WHERE biblioitems.biblionumber     = ?
+                           AND biblioitems.itemtype         = itemtypes.itemtype
+                           AND biblioitems.biblioitemnumber = items.biblioitemnumber
+                      GROUP BY items.biblioitemnumber");
+    my $count = 0;
+    my @results;
+    $sth->execute($bibnum);
+    while (my $data = $sth->fetchrow_hashref) {
+        $results[$count] = $data;
+        $count++;
+    } # while
+    $sth->finish;
+    return($count, @results);
+} # sub bibitems
+
+
+=item bibitemdata
+
+  $itemdata = &bibitemdata($biblioitemnumber);
+
+Looks up the biblioitem with the given biblioitemnumber. Returns a
+reference-to-hash. The keys are the fields from the C<biblio>,
+C<biblioitems>, and C<itemtypes> tables in the Koha database, except
+that C<biblioitems.notes> is given as C<$itemdata-E<gt>{bnotes}>.
+
+=cut
+#'
+sub bibitemdata {
+    my ($bibitem) = @_;
+    my $dbh   = C4::Context->dbh;
+    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");
+    my $data;
+
+    $sth->execute($bibitem);
+
+    $data = $sth->fetchrow_hashref;
+
+    $sth->finish;
+    return($data);
+} # sub bibitemdata
+
+
+=item getbibliofromitemnumber
+
+  $item = &getbibliofromitemnumber($env, $dbh, $itemnumber);
+
+Looks up the item with the given itemnumber.
+
+C<$env> and C<$dbh> are ignored.
+
+C<&itemnodata> returns a reference-to-hash whose keys are the fields
+from the C<biblio>, C<biblioitems>, and C<items> tables in the Koha
+database.
+
+=cut
+#'
+sub getbibliofromitemnumber {
+  my ($env,$dbh,$itemnumber) = @_;
+  $dbh = C4::Context->dbh;
+  my $sth=$dbh->prepare("Select * from biblio,items,biblioitems
+    where items.itemnumber = ?
+    and biblio.biblionumber = items.biblionumber
+    and biblioitems.biblioitemnumber = items.biblioitemnumber");
+#  print $query;
+  $sth->execute($itemnumber);
+  my $data=$sth->fetchrow_hashref;
+  $sth->finish;
+  return($data);
+}
+
+=item barcodes
+
+  @barcodes = &barcodes($biblioitemnumber);
+
+Given a biblioitemnumber, looks up the corresponding items.
+
+Returns an array of references-to-hash; the keys are C<barcode> and
+C<itemlost>.
+
+The returned items include very overdue items, but not lost ones.
+
+=cut
+#'
+sub barcodes{
+    #called from request.pl
+    my ($biblioitemnumber)=@_;
+    my $dbh = C4::Context->dbh;
+    my $sth=$dbh->prepare("SELECT barcode, itemlost, holdingbranch FROM items
+                           WHERE biblioitemnumber = ?
+                             AND (wthdrawn <> 1 OR wthdrawn IS NULL)");
+    $sth->execute($biblioitemnumber);
+    my @barcodes;
+    my $i=0;
+    while (my $data=$sth->fetchrow_hashref){
+       $barcodes[$i]=$data;
+       $i++;
+    }
+    $sth->finish;
+    return(@barcodes);
+}
+
+
+=item itemdata
+
+  $item = &itemdata($barcode);
+
+Looks up the item with the given barcode, and returns a
+reference-to-hash containing information about that item. The keys of
+the hash are the fields from the C<items> and C<biblioitems> tables in
+the Koha database.
+
+=cut
+#'
+sub get_item_from_barcode {
+  my ($barcode)=@_;
+  my $dbh = C4::Context->dbh;
+  my $sth=$dbh->prepare("Select * from items,biblioitems where barcode=?
+  and items.biblioitemnumber=biblioitems.biblioitemnumber");
+  $sth->execute($barcode);
+  my $data=$sth->fetchrow_hashref;
+  $sth->finish;
+  return($data);
+}
+
+
+=item itemissues
+
+  @issues = &itemissues($biblioitemnumber, $biblio);
+
+Looks up information about who has borrowed the bookZ<>(s) with the
+given biblioitemnumber.
+
+C<$biblio> is ignored.
+
+C<&itemissues> returns an array of references-to-hash. The keys
+include the fields from the C<items> table in the Koha database.
+Additional keys include:
+
+=over 4
+
+=item C<date_due>
+
+If the item is currently on loan, this gives the due date.
+
+If the item is not on loan, then this is either "Available" or
+"Cancelled", if the item has been withdrawn.
+
+=item C<card>
+
+If the item is currently on loan, this gives the card number of the
+patron who currently has the item.
+
+=item C<timestamp0>, C<timestamp1>, C<timestamp2>
+
+These give the timestamp for the last three times the item was
+borrowed.
+
+=item C<card0>, C<card1>, C<card2>
+
+The card number of the last three patrons who borrowed this item.
+
+=item C<borrower0>, C<borrower1>, C<borrower2>
+
+The borrower number of the last three patrons who borrowed this item.
+
+=back
+
+=cut
+#'
+sub itemissues {
+    my ($bibitem, $biblio)=@_;
+    my $dbh   = C4::Context->dbh;
+    # FIXME - If this function die()s, the script will abort, and the
+    # user won't get anything; depending on how far the script has
+    # gotten, the user might get a blank page. It would be much better
+    # to at least print an error message. The easiest way to do this
+    # is to set $SIG{__DIE__}.
+    my $sth   = $dbh->prepare("Select * from items where
+items.biblioitemnumber = ?")
+      || die $dbh->errstr;
+    my $i     = 0;
+    my @results;
+
+    $sth->execute($bibitem)
+      || die $sth->errstr;
+
+    while (my $data = $sth->fetchrow_hashref) {
+        # Find out who currently has this item.
+        # FIXME - Wouldn't it be better to do this as a left join of
+        # some sort? Currently, this code assumes that if
+        # fetchrow_hashref() fails, then the book is on the shelf.
+        # fetchrow_hashref() can fail for any number of reasons (e.g.,
+        # database server crash), not just because no items match the
+        # search criteria.
+        my $sth2   = $dbh->prepare("select * from issues,borrowers
+where itemnumber = ?
+and returndate is NULL
+and issues.borrowernumber = borrowers.borrowernumber");
+
+        $sth2->execute($data->{'itemnumber'});
+        if (my $data2 = $sth2->fetchrow_hashref) {
+            $data->{'date_due'} = $data2->{'date_due'};
+            $data->{'card'}     = $data2->{'cardnumber'};
+           $data->{'borrower'}     = $data2->{'borrowernumber'};
+        } else {
+            if ($data->{'wthdrawn'} eq '1') {
+                $data->{'date_due'} = 'Cancelled';
+            } else {
+                $data->{'date_due'} = 'Available';
+            } # else
+        } # else
+
+        $sth2->finish;
+
+        # Find the last 3 people who borrowed this item.
+        $sth2 = $dbh->prepare("select * from issues, borrowers
+                                               where itemnumber = ?
+                                                                       and issues.borrowernumber = borrowers.borrowernumber
+                                                                       and returndate is not NULL
+                                                                       order by returndate desc,timestamp desc") || die $dbh->errstr;
+        $sth2->execute($data->{'itemnumber'}) || die $sth2->errstr;
+        for (my $i2 = 0; $i2 < 2; $i2++) { # FIXME : error if there is less than 3 pple borrowing this item
+            if (my $data2 = $sth2->fetchrow_hashref) {
+                $data->{"timestamp$i2"} = $data2->{'timestamp'};
+                $data->{"card$i2"}      = $data2->{'cardnumber'};
+                $data->{"borrower$i2"}  = $data2->{'borrowernumber'};
+            } # if
+        } # for
+
+        $sth2->finish;
+        $results[$i] = $data;
+        $i++;
+    }
+
+    $sth->finish;
+    return(@results);
+}
+
+=item getsubject
+
+  ($count, $subjects) = &getsubject($biblionumber);
+
+Looks up the subjects of the book with the given biblionumber. Returns
+a two-element list. C<$subjects> is a reference-to-array, where each
+element is a subject of the book, and C<$count> is the number of
+elements in C<$subjects>.
+
+=cut
+#'
+sub getsubject {
+  my ($bibnum)=@_;
+  my $dbh = C4::Context->dbh;
+  my $sth=$dbh->prepare("Select * from bibliosubject where biblionumber=?");
+  $sth->execute($bibnum);
+  my @results;
+  my $i=0;
+  while (my $data=$sth->fetchrow_hashref){
+    $results[$i]=$data;
+    $i++;
+  }
+  $sth->finish;
+  return($i,\@results);
+}
+
+=item getaddauthor
+
+  ($count, $authors) = &getaddauthor($biblionumber);
+
+Looks up the additional authors for the book with the given
+biblionumber.
+
+Returns a two-element list. C<$authors> is a reference-to-array, where
+each element is an additional author, and C<$count> is the number of
+elements in C<$authors>.
+
+=cut
+#'
+sub getaddauthor {
+  my ($bibnum)=@_;
+  my $dbh = C4::Context->dbh;
+  my $sth=$dbh->prepare("Select * from additionalauthors where biblionumber=?");
+  $sth->execute($bibnum);
+  my @results;
+  my $i=0;
+  while (my $data=$sth->fetchrow_hashref){
+    $results[$i]=$data;
+    $i++;
+  }
+  $sth->finish;
+  return($i,\@results);
+}
+
+
+=item getsubtitle
+
+  ($count, $subtitles) = &getsubtitle($biblionumber);
+
+Looks up the subtitles for the book with the given biblionumber.
+
+Returns a two-element list. C<$subtitles> is a reference-to-array,
+where each element is a subtitle, and C<$count> is the number of
+elements in C<$subtitles>.
+
+=cut
+#'
+sub getsubtitle {
+  my ($bibnum)=@_;
+  my $dbh = C4::Context->dbh;
+  my $sth=$dbh->prepare("Select * from bibliosubtitle where biblionumber=?");
+  $sth->execute($bibnum);
+  my @results;
+  my $i=0;
+  while (my $data=$sth->fetchrow_hashref){
+    $results[$i]=$data;
+    $i++;
+  }
+  $sth->finish;
+  return($i,\@results);
+}
+
+
+=item getwebsites
+
+  ($count, @websites) = &getwebsites($biblionumber);
+
+Looks up the web sites pertaining to the book with the given
+biblionumber.
+
+C<$count> is the number of elements in C<@websites>.
+
+C<@websites> is an array of references-to-hash; the keys are the
+fields from the C<websites> table in the Koha database.
+
+=cut
+#FIXME : could maybe be deleted. Otherwise, would be better in a Websites.pm package
+#(with add / modify / delete subs)
+
+sub getwebsites {
+    my ($biblionumber) = @_;
+    my $dbh   = C4::Context->dbh;
+    my $sth   = $dbh->prepare("Select * from websites where biblionumber = ?");
+    my $count = 0;
+    my @results;
+
+    $sth->execute($biblionumber);
+    while (my $data = $sth->fetchrow_hashref) {
+        # FIXME - The URL scheme shouldn't be stripped off, at least
+        # not here, since it's part of the URL, and will be useful in
+        # constructing a link to the site. If you don't want the user
+        # to see the "http://" part, strip that off when building the
+        # HTML code.
+        $data->{'url'} =~ s/^http:\/\///;      # FIXME - Leaning toothpick
+                                               # syndrome
+        $results[$count] = $data;
+       $count++;
+    } # while
+
+    $sth->finish;
+    return($count, @results);
+} # sub getwebsites
+
+=item getwebbiblioitems
+
+  ($count, @results) = &getwebbiblioitems($biblionumber);
+
+Given a book's biblionumber, looks up the web versions of the book
+(biblioitems with itemtype C<WEB>).
+
+C<$count> is the number of items in C<@results>. C<@results> is an
+array of references-to-hash; the keys are the items from the
+C<biblioitems> table of the Koha database.
+
+=cut
+#'
+sub getwebbiblioitems {
+    my ($biblionumber) = @_;
+    my $dbh   = C4::Context->dbh;
+    my $sth   = $dbh->prepare("Select * from biblioitems where biblionumber = ?
+and itemtype = 'WEB'");
+    my $count = 0;
+    my @results;
+
+    $sth->execute($biblionumber);
+    while (my $data = $sth->fetchrow_hashref) {
+        $data->{'url'} =~ s/^http:\/\///;
+        $results[$count] = $data;
+        $count++;
+    } # while
+
+    $sth->finish;
+    return($count, @results);
+} # sub getwebbiblioitems
+
 sub char_decode {
 
     # converts ISO 5426 coded string to ISO 8859-1
@@ -2298,6 +2876,9 @@ Paul POULAIN paul.poulain@free.fr
 
 # $Id$
 # $Log$
+# Revision 1.131  2005/09/22 10:01:45  tipaul
+# see mail on koha-devel : code cleaning on Search.pm + normalizing API + use of biblionumber everywhere (instead of bn, biblio, ...)
+#
 # Revision 1.130  2005/09/02 14:34:14  tipaul
 # continuing the work to move to zebra. Begin of work for MARC=OFF support.
 # IMPORTANT NOTE : the MARCkoha2marc sub API has been modified. Instead of biblionumber & biblioitemnumber, it now gets a hash.
index f87e2ae..3dbef30 100644 (file)
@@ -50,12 +50,12 @@ Koha.pm provides many functions for Koha scripts.
 =cut
 
 @ISA = qw(Exporter);
-@EXPORT = qw(&slashifyDate
+@EXPORT = qw(
                        &fixEthnicity
-                       &borrowercategories
+                       &borrowercategories &getborrowercategory
                        &ethnicitycategories
                        &subfield_is_koha_internal_p
-                       &getbranches &getbranch
+                       &getbranches &getbranch &getbranchname
                        &getprinters &getprinter
                        &getitemtypes &getitemtypeinfo
                        &getframeworks &getframeworkinfo
@@ -67,21 +67,7 @@ use vars qw();
 
 my $DEBUG = 0;
 
-=head2 slashifyDate
-
-  $slash_date = &slashifyDate($dash_date);
-
-Takes a string of the form "DD-MM-YYYY" (or anything separated by
-dashes), converts it to the form "YYYY/MM/DD", and returns the result.
-
-=cut
-
-sub slashifyDate {
-    # accepts a date of the form xx-xx-xx[xx] and returns it in the
-    # form xx/xx/xx[xx]
-    my @dateOut = split('-', shift);
-    return("$dateOut[2]/$dateOut[1]/$dateOut[0]")
-}
+# removed slashifyDate => useless
 
 =head2 fixEthnicity
 
@@ -131,6 +117,27 @@ sub borrowercategories {
     return(\@codes,\%labels);
 }
 
+=item getborrowercategory
+
+  $description = &getborrowercategory($categorycode);
+
+Given the borrower's category code, the function returns the corresponding
+description for a comprehensive information display.
+
+=cut
+
+sub getborrowercategory
+{
+       my ($catcode) = @_;
+       my $dbh = C4::Context->dbh;
+       my $sth = $dbh->prepare("SELECT description FROM categories WHERE categorycode = ?");
+       $sth->execute($catcode);
+       my $description = $sth->fetchrow();
+       $sth->finish();
+       return $description;
+} # sub getborrowercategory
+
+
 =head2 ethnicitycategories
 
   ($codes_arrayref, $labels_hashref) = &ethnicitycategories();
@@ -452,6 +459,7 @@ sub getprinters {
     }
     return (\%printers);
 }
+
 sub getbranch ($$) {
     my($query, $branches) = @_; # get branch for this query from branches
     my $branch = $query->param('branch');
@@ -460,6 +468,26 @@ sub getbranch ($$) {
     return $branch;
 }
 
+=item getbranchname
+
+  $branchname = &getbranchname($branchcode);
+
+Given the branch code, the function returns the corresponding
+branch name for a comprehensive information display
+
+=cut
+
+sub getbranchname
+{
+       my ($branchcode) = @_;
+       my $dbh = C4::Context->dbh;
+       my $sth = $dbh->prepare("SELECT branchname FROM branches WHERE branchcode = ?");
+       $sth->execute($branchcode);
+       my $branchname = $sth->fetchrow();
+       $sth->finish();
+       return $branchname;
+} # sub getbranchname
+
 sub getprinter ($$) {
     my($query, $printers) = @_; # get printer for this query from printers
     my $printer = $query->param('printer');
index aa5551d..1d74912 100644 (file)
@@ -49,10 +49,84 @@ C4::Members - Perl Module containing convenience functions for member handling
 @EXPORT = qw();
 
 @EXPORT = qw(
-       &getmember &fixup_cardnumber &findguarantees &findguarantor &NewBorrowerNumber &modmember &newmember &changepassword
+       &BornameSearch &getmember &borrdata &borrdata2 &fixup_cardnumber &findguarantees &findguarantor &NewBorrowerNumber &modmember &newmember &changepassword &borrissues &allissues
+       &getboracctrecord
     );
 
-       
+
+=item BornameSearch
+
+  ($count, $borrowers) = &BornameSearch($env, $searchstring, $type);
+
+Looks up patrons (borrowers) by name.
+
+C<$env> is ignored.
+
+BUGFIX 499: C<$type> is now used to determine type of search.
+if $type is "simple", search is performed on the first letter of the
+surname only.
+
+C<$searchstring> is a space-separated list of search terms. Each term
+must match the beginning a borrower's surname, first name, or other
+name.
+
+C<&BornameSearch> returns a two-element list. C<$borrowers> is a
+reference-to-array; each element is a reference-to-hash, whose keys
+are the fields of the C<borrowers> table in the Koha database.
+C<$count> is the number of elements in C<$borrowers>.
+
+=cut
+#'
+#used by member enquiries from the intranet
+#called by member.pl
+sub BornameSearch  {
+       my ($env,$searchstring,$orderby,$type)=@_;
+       my $dbh = C4::Context->dbh;
+       my $query = ""; my $count; my @data;
+       my @bind=();
+
+       if($type eq "simple")   # simple search for one letter only
+       {
+               $query="Select * from borrowers where surname like ? order by $orderby";
+               @bind=("$searchstring%");
+       }
+       else    # advanced search looking in surname, firstname and othernames
+       {
+               @data=split(' ',$searchstring);
+               $count=@data;
+               $query="Select * from borrowers
+               where ((surname like ? or surname like ?
+               or firstname  like ? or firstname like ?
+               or othernames like ? or othernames like ?)
+               ";
+               @bind=("$data[0]%","% $data[0]%","$data[0]%","% $data[0]%","$data[0]%","% $data[0]%");
+               for (my $i=1;$i<$count;$i++){
+                       $query=$query." and (".
+                       " surname like ? or surname like ?
+                        or firstname  like ? or firstname like ?
+                       or othernames like ? or othernames like ?)";
+                       push(@bind,"$data[$i]%","% $data[$i]%","$data[$i]%","% $data[$i]%","$data[$i]%","% $data[$i]%");
+                                       # FIXME - .= <<EOT;
+               }
+               $query=$query.") or cardnumber like ?
+               order by $orderby";
+               push(@bind,$searchstring);
+                                       # FIXME - .= <<EOT;
+       }
+
+       my $sth=$dbh->prepare($query);
+#      warn "Q $orderby : $query";
+       $sth->execute(@bind);
+       my @results;
+       my $cnt=$sth->rows;
+       while (my $data=$sth->fetchrow_hashref){
+       push(@results,$data);
+       }
+       #  $sth->execute;
+       $sth->finish;
+       return ($cnt,\@results);
+}
+
 =item getmember
 
   $borrower = &getmember($cardnumber, $borrowernumber);
@@ -94,6 +168,87 @@ sub getmember {
        return undef;
 }
 
+=item borrdata
+
+  $borrower = &borrdata($cardnumber, $borrowernumber);
+
+Looks up information about a patron (borrower) by either card number
+or borrower number. If $borrowernumber is specified, C<&borrdata>
+searches by borrower number; otherwise, it searches by card number.
+
+C<&borrdata> returns a reference-to-hash whose keys are the fields of
+the C<borrowers> table in the Koha database.
+
+=cut
+#'
+sub borrdata {
+  my ($cardnumber,$bornum)=@_;
+  $cardnumber = uc $cardnumber;
+  my $dbh = C4::Context->dbh;
+  my $sth;
+  if ($bornum eq ''){
+    $sth=$dbh->prepare("Select * from borrowers where cardnumber=?");
+    $sth->execute($cardnumber);
+  } else {
+    $sth=$dbh->prepare("Select * from borrowers where borrowernumber=?");
+  $sth->execute($bornum);
+  }
+  my $data=$sth->fetchrow_hashref;
+  $sth->finish;
+  if ($data) {
+       return($data);
+       } else { # try with firstname
+               if ($cardnumber) {
+                       my $sth=$dbh->prepare("select * from borrowers where firstname=?");
+                       $sth->execute($cardnumber);
+                       my $data=$sth->fetchrow_hashref;
+                       $sth->finish;
+                       return($data);
+               }
+       }
+       return undef;
+}
+
+
+=item borrdata2
+
+  ($borrowed, $due, $fine) = &borrdata2($env, $borrowernumber);
+
+Returns aggregate data about items borrowed by the patron with the
+given borrowernumber.
+
+C<$env> is ignored.
+
+C<&borrdata2> returns a three-element array. C<$borrowed> is the
+number of books the patron currently has borrowed. C<$due> is the
+number of overdue items the patron currently has borrowed. C<$fine> is
+the total fine currently due by the borrower.
+
+=cut
+#'
+sub borrdata2 {
+  my ($env,$bornum)=@_;
+  my $dbh = C4::Context->dbh;
+  my $query="Select count(*) from issues where borrowernumber='$bornum' and
+    returndate is NULL";
+    # print $query;
+  my $sth=$dbh->prepare($query);
+  $sth->execute;
+  my $data=$sth->fetchrow_hashref;
+  $sth->finish;
+  $sth=$dbh->prepare("Select count(*) from issues where
+    borrowernumber='$bornum' and date_due < now() and returndate is NULL");
+  $sth->execute;
+  my $data2=$sth->fetchrow_hashref;
+  $sth->finish;
+  $sth=$dbh->prepare("Select sum(amountoutstanding) from accountlines where
+    borrowernumber='$bornum'");
+  $sth->execute;
+  my $data3=$sth->fetchrow_hashref;
+  $sth->finish;
+
+return($data2->{'count(*)'},$data->{'count(*)'},$data3->{'sum(amountoutstanding)'});
+}
 
 sub modmember {
        my (%data) = @_;
@@ -327,4 +482,127 @@ sub NewBorrowerNumber {
   return($data->{'max(borrowernumber)'});
 }
 
+=item borrissues
+
+  ($count, $issues) = &borrissues($borrowernumber);
+
+Looks up what the patron with the given borrowernumber has borrowed.
+
+C<&borrissues> returns a two-element array. C<$issues> is a
+reference-to-array, where each element is a reference-to-hash; the
+keys are the fields from the C<issues>, C<biblio>, and C<items> tables
+in the Koha database. C<$count> is the number of elements in
+C<$issues>.
+
+=cut
+#'
+sub borrissues {
+  my ($bornum)=@_;
+  my $dbh = C4::Context->dbh;
+  my $sth=$dbh->prepare("Select * from issues,biblio,items where borrowernumber=?
+   and items.itemnumber=issues.itemnumber
+       and items.biblionumber=biblio.biblionumber
+       and issues.returndate is NULL order by date_due");
+    $sth->execute($bornum);
+  my @result;
+  while (my $data = $sth->fetchrow_hashref) {
+    push @result, $data;
+  }
+  $sth->finish;
+  return(scalar(@result), \@result);
+}
+
+=item allissues
+
+  ($count, $issues) = &allissues($borrowernumber, $sortkey, $limit);
+
+Looks up what the patron with the given borrowernumber has borrowed,
+and sorts the results.
+
+C<$sortkey> is the name of a field on which to sort the results. This
+should be the name of a field in the C<issues>, C<biblio>,
+C<biblioitems>, or C<items> table in the Koha database.
+
+C<$limit> is the maximum number of results to return.
+
+C<&allissues> returns a two-element array. C<$issues> is a
+reference-to-array, where each element is a reference-to-hash; the
+keys are the fields from the C<issues>, C<biblio>, C<biblioitems>, and
+C<items> tables of the Koha database. C<$count> is the number of
+elements in C<$issues>
+
+=cut
+#'
+sub allissues {
+  my ($bornum,$order,$limit)=@_;
+  #FIXME: sanity-check order and limit
+  my $dbh = C4::Context->dbh;
+  my $query="Select * from issues,biblio,items,biblioitems
+  where borrowernumber=? and
+  items.biblioitemnumber=biblioitems.biblioitemnumber and
+  items.itemnumber=issues.itemnumber and
+  items.biblionumber=biblio.biblionumber order by $order";
+  if ($limit !=0){
+    $query.=" limit $limit";
+  }
+  #print $query;
+  my $sth=$dbh->prepare($query);
+  $sth->execute($bornum);
+  my @result;
+  my $i=0;
+  while (my $data=$sth->fetchrow_hashref){
+    $result[$i]=$data;;
+    $i++;
+  }
+  $sth->finish;
+  return($i,\@result);
+}
+
+=item getboracctrecord
+
+  ($count, $acctlines, $total) = &getboracctrecord($env, $borrowernumber);
+
+Looks up accounting data for the patron with the given borrowernumber.
+
+C<$env> is ignored.
+
+(FIXME - I'm not at all sure what this is about.)
+
+C<&getboracctrecord> returns a three-element array. C<$acctlines> is a
+reference-to-array, where each element is a reference-to-hash; the
+keys are the fields of the C<accountlines> table in the Koha database.
+C<$count> is the number of elements in C<$acctlines>. C<$total> is the
+total amount outstanding for all of the account lines.
+
+=cut
+#'
+sub getboracctrecord {
+   my ($env,$params) = @_;
+   my $dbh = C4::Context->dbh;
+   my @acctlines;
+   my $numlines=0;
+   my $sth=$dbh->prepare("Select * from accountlines where
+borrowernumber=? order by date desc,timestamp desc");
+#   print $query;
+   $sth->execute($params->{'borrowernumber'});
+   my $total=0;
+   while (my $data=$sth->fetchrow_hashref){
+   #FIXME before reinstating: insecure?
+#      if ($data->{'itemnumber'} ne ''){
+#        $query="Select * from items,biblio where items.itemnumber=
+#      '$data->{'itemnumber'}' and biblio.biblionumber=items.biblionumber";
+#      my $sth2=$dbh->prepare($query);
+#      $sth2->execute;
+#      my $data2=$sth2->fetchrow_hashref;
+#      $sth2->finish;
+#      $data=$data2;
+ #     }
+      $acctlines[$numlines] = $data;
+      $numlines++;
+      $total += $data->{'amountoutstanding'};
+   }
+   $sth->finish;
+   return ($numlines,\@acctlines,$total);
+}
+
 1;
index d50221b..4ed9829 100755 (executable)
@@ -26,10 +26,7 @@ use strict;
 require Exporter;
 use DBI;
 use C4::Context;
-use C4::Search;
-       # FIXME - C4::Reserves2 uses C4::Search, which uses C4::Reserves2.
-       # So Perl complains that all of the functions here get redefined.
-#use C4::Accounts;
+use C4::Biblio;
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
@@ -157,7 +154,7 @@ sub FindReserves {
                        my ($bibitemno) = $csth->fetchrow_array;
                        $csth->finish;
                        # Look up the book we just found.
-                       my $bdata = C4::Search::bibitemdata($bibitemno);
+                       my $bdata = bibitemdata($bibitemno);
                        # Add the results of this latest search to the current
                        # results.
                        # FIXME - An 'each' would probably be more efficient.
index 7cd16e3..73f6db6 100755 (executable)
@@ -58,12 +58,8 @@ on what is passed to it, it calls the appropriate search function.
 
 @ISA = qw(Exporter);
 @EXPORT = qw(
-&CatSearch &BornameSearch &ItemInfo &KeywordSearch &subsearch
-&itemdata &bibdata &GetItems &borrdata &itemnodata
-&borrdata2 &NewBorrowerNumber &bibitemdata &borrissues
-&getboracctrecord &ItemType &itemissues &subject &subtitle
-&addauthor &bibitems &barcodes &allissues &getwebsites &getwebbiblioitems &catalogsearch &itemcount2
-&isbnsearch &getbranchname &getborrowercategory);
+       &catalogsearch &KeywordSearch &CatSearch &subsearch
+);
 # make all your functions, whether exported or not;
 
 =item catalogsearch
@@ -493,171 +489,6 @@ EOT
   return($count,@res2);
 }
 
-sub KeywordSearch2 {
-  my ($env,$type,$search,$num,$offset)=@_;
-  my $dbh = C4::Context->dbh;
-  $search->{'keyword'}=~ s/ +$//;
-  my @key=split(' ',$search->{'keyword'});
-  my $count=@key;
-  my $i=1;
-  my @results;
-  my $query ="Select * from biblio,bibliosubtitle,biblioitems where
-  biblio.biblionumber=biblioitems.biblionumber and
-  biblio.biblionumber=bibliosubtitle.biblionumber and
-  (((title like ? or title like ?)";
-  my @bind=("$key[0]%","% $key[0]%");
-  while ($i < $count){
-    $query .= " and (title like ? or title like ?)";
-    push(@bind,"$key[$i]%","% $key[$i]%");
-    $i++;
-  }
-  $query.= ") or ((subtitle like ? or subtitle like ?)";
-  push(@bind,"$key[0]%","% $key[0]%");
-  for ($i=1;$i<$count;$i++){
-    $query.= " and (subtitle like ? or subtitle like ?)";
-    push(@bind,"$key[$i]%","% $key[$i]%");
-  }
-  $query.= ") or ((seriestitle like ? or seriestitle like ?)";
-  push(@bind,"$key[0]%","% $key[0]%");
-  for ($i=1;$i<$count;$i++){
-    $query.=" and (seriestitle like ? or seriestitle like ?)";
-    push(@bind,"$key[$i]%","% $key[$i]%");
-  }
-  $query.= ") or ((biblio.notes like ? or biblio.notes like ?)";
-  push(@bind,"$key[0]%","% $key[0]%");
-  for ($i=1;$i<$count;$i++){
-    $query.=" and (biblio.notes like ? or biblio.notes like ?)";
-    push(@bind,"$key[$i]%","% $key[$i]%");
-  }
-  $query.= ") or ((biblioitems.notes like ? or biblioitems.notes like ?)";
-  push(@bind,"$key[0]%","% $key[0]%");
-  for ($i=1;$i<$count;$i++){
-    $query.=" and (biblioitems.notes like ? or biblioitems.notes like ?)";
-    push(@bind,"$key[$i]%","% $key[$i]%");
-  }
-  if ($search->{'keyword'} =~ /new zealand/i){
-    $query.= "or (title like 'nz%' or title like '% nz %' or title like '% nz' or subtitle like 'nz%'
-    or subtitle like '% nz %' or subtitle like '% nz' or author like 'nz %'
-    or author like '% nz %' or author like '% nz')"
-  }
-  if ($search->{'keyword'} eq  'nz' || $search->{'keyword'} eq 'NZ' ||
-  $search->{'keyword'} =~ /nz /i || $search->{'keyword'} =~ / nz /i ||
-  $search->{'keyword'} =~ / nz/i){
-    $query.= "or (title like 'new zealand%' or title like '% new zealand %'
-    or title like '% new zealand' or subtitle like 'new zealand%' or
-    subtitle like '% new zealand %'
-    or subtitle like '% new zealand' or author like 'new zealand%'
-    or author like '% new zealand %' or author like '% new zealand' or
-    seriestitle like 'new zealand%' or seriestitle like '% new zealand %'
-    or seriestitle like '% new zealand')"
-  }
-  $query .= "))";
-  if ($search->{'class'} ne ''){
-    my @temp=split(/\|/,$search->{'class'});
-    my $count=@temp;
-    $query.= "and ( itemtype=?";
-    push(@bind,"$temp[0]");
-    for (my $i=1;$i<$count;$i++){
-      $query.=" or itemtype=?";
-      push(@bind,"$temp[$i]");
-     }
-  $query.=")";
-  }
-  if ($search->{'dewey'} ne ''){
-    $query.= "and (dewey like '$search->{'dewey'}%') ";
-  }
-   $query.="group by biblio.biblionumber";
-   #$query.=" order by author,title";
-#  print $query;
-  my $sth=$dbh->prepare($query);
-  $sth->execute(@bind);
-  $i=0;
-  while (my $data=$sth->fetchrow_hashref){
-#FIXME: rewrite to use ? before uncomment
-#    my $sti=$dbh->prepare("select dewey,subclass from biblioitems where biblionumber=$data->{'biblionumber'}
-#    ");
-#    $sti->execute;
-#    my ($dewey, $subclass) = $sti->fetchrow;
-    my $dewey=$data->{'dewey'};
-    my $subclass=$data->{'subclass'};
-    $dewey=~s/\.*0*$//;
-    ($dewey == 0) && ($dewey='');
-    ($dewey) && ($dewey.=" $subclass");
-#    $sti->finish;
-    $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey";
-#      print $results[$i];
-    $i++;
-  }
-  $sth->finish;
-  $sth=$dbh->prepare("Select biblionumber from bibliosubject where subject
-  like ? group by biblionumber");
-  $sth->execute("%".$search->{'keyword'}."%");
-  while (my $data=$sth->fetchrow_hashref){
-    $query="Select * from biblio,biblioitems where
-    biblio.biblionumber=? and
-    biblio.biblionumber=biblioitems.biblionumber ";
-    @bind=($data->{'biblionumber'});
-    if ($search->{'class'} ne ''){
-      my @temp=split(/\|/,$search->{'class'});
-      my $count=@temp;
-      $query.= " and ( itemtype=?";
-      push(@bind,$temp[0]);
-      for (my $i=1;$i<$count;$i++){
-        $query.=" or itemtype=?";
-        push(@bind,$temp[$i]);
-      }
-      $query.=")";
-
-    }
-    if ($search->{'dewey'} ne ''){
-      $query.= "and (dewey like ?)";
-      push(@bind,"$search->{'dewey'}%");
-    }
-    my $sth2=$dbh->prepare($query);
-    $sth2->execute(@bind);
-#    print $query;
-    while (my $data2=$sth2->fetchrow_hashref){
-      my $dewey= $data2->{'dewey'};
-      my $subclass=$data2->{'subclass'};
-      $dewey=~s/\.*0*$//;
-      ($dewey == 0) && ($dewey='');
-      ($dewey) && ($dewey.=" $subclass") ;
-#      $sti->finish;
-       $results[$i]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey";
-#      print $results[$i];
-      $i++;
-    }
-    $sth2->finish;
-  }
-  my $i2=1;
-  @results=sort @results;
-  my @res;
-  $count=@results;
-  $i=1;
-  if ($count > 0){
-    $res[0]=$results[0];
-  }
-  while ($i2 < $count){
-    if ($results[$i2] ne $res[$i-1]){
-      $res[$i]=$results[$i2];
-      $i++;
-    }
-    $i2++;
-  }
-  $i2=0;
-  my @res2;
-  $count=@res;
-  while ($i2 < $num && $i2 < $count){
-    $res2[$i2]=$res[$i2+$offset];
-#    print $res2[$i2];
-    $i2++;
-  }
-  $sth->finish;
-#  $i--;
-#  $i++;
-  return($i,@res2);
-}
-
 =item CatSearch
 
   ($count, @results) = &CatSearch($env, $type, $search, $num, $offset);
@@ -1127,11 +958,6 @@ sub CatSearch  {
        return($count,@results);
 }
 
-sub updatesearchstats{
-  my ($dbh,$query)=@_;
-
-}
-
 =item subsearch
 
   @results = &subsearch($env, $subject);
@@ -1165,1179 +991,6 @@ sub subsearch {
   return(@results);
 }
 
-=item ItemInfo
-
-  @results = &ItemInfo($env, $biblionumber, $type);
-
-Returns information about books with the given biblionumber.
-
-C<$type> may be either C<intra> or anything else. If it is not set to
-C<intra>, then the search will exclude lost, very overdue, and
-withdrawn items.
-
-C<$env> is ignored.
-
-C<&ItemInfo> returns a list of references-to-hash. Each element
-contains a number of keys. Most of them are table items from the
-C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
-Koha database. Other keys include:
-
-=over 4
-
-=item C<$data-E<gt>{branchname}>
-
-The name (not the code) of the branch to which the book belongs.
-
-=item C<$data-E<gt>{datelastseen}>
-
-This is simply C<items.datelastseen>, except that while the date is
-stored in YYYY-MM-DD format in the database, here it is converted to
-DD/MM/YYYY format. A NULL date is returned as C<//>.
-
-=item C<$data-E<gt>{datedue}>
-
-=item C<$data-E<gt>{class}>
-
-This is the concatenation of C<biblioitems.classification>, the book's
-Dewey code, and C<biblioitems.subclass>.
-
-=item C<$data-E<gt>{ocount}>
-
-I think this is the number of copies of the book available.
-
-=item C<$data-E<gt>{order}>
-
-If this is set, it is set to C<One Order>.
-
-=back
-
-=cut
-#'
-sub ItemInfo {
-       my ($env,$biblionumber,$type) = @_;
-       my $dbh   = C4::Context->dbh;
-       my $query = "SELECT *,items.notforloan as itemnotforloan FROM items, biblio, biblioitems 
-                                       left join itemtypes on biblioitems.itemtype = itemtypes.itemtype
-                                       WHERE items.biblionumber = ?
-                                       AND biblioitems.biblioitemnumber = items.biblioitemnumber
-                                       AND biblio.biblionumber = items.biblionumber";
-# buggy : opac & librarian interface can show the same info level & itemstatus should not be hardcoded
-#      if ($type ne 'intra'){
-#              $query .= " and ((items.itemlost<>1 and items.itemlost <> 2)
-#              or items.itemlost is NULL)
-#              and (wthdrawn <> 1 or wthdrawn is NULL)";
-#      }
-       $query .= " order by items.dateaccessioned desc";
-       my $sth=$dbh->prepare($query);
-       $sth->execute($biblionumber);
-       my $i=0;
-       my @results;
-       while (my $data=$sth->fetchrow_hashref){
-               my $datedue = '';
-               my $isth=$dbh->prepare("Select issues.*,borrowers.cardnumber from issues,borrowers where itemnumber = ? and returndate is null and issues.borrowernumber=borrowers.borrowernumber");
-               $isth->execute($data->{'itemnumber'});
-               if (my $idata=$isth->fetchrow_hashref){
-               $data->{borrowernumber} = $idata->{borrowernumber};
-               $data->{cardnumber} = $idata->{cardnumber};
-               $datedue = format_date($idata->{'date_due'});
-               }
-# buggy : hardcoded & non-translatable
-# more : why don't you want to show the datedue if it's very very overdue ?
-#              if ($data->{'itemlost'} eq '2'){
-#                      $datedue='Very Overdue';
-#              }
-#              if ($data->{'itemlost'} eq '1'){
-#                      $datedue='Lost';
-#              }
-#              if ($data->{'wthdrawn'} eq '1'){
-#                      $datedue="Cancelled";
-#              }
-               if ($datedue eq ''){
-       #       $datedue="Available";
-                       my ($restype,$reserves)=C4::Reserves2::CheckReserves($data->{'itemnumber'});
-                       if ($restype) {
-                               $datedue=$restype;
-                       }
-               }
-               $isth->finish;
-       #get branch information.....
-               my $bsth=$dbh->prepare("SELECT * FROM branches WHERE branchcode = ?");
-               $bsth->execute($data->{'holdingbranch'});
-               if (my $bdata=$bsth->fetchrow_hashref){
-                       $data->{'branchname'} = $bdata->{'branchname'};
-               }
-               my $date=format_date($data->{'datelastseen'});
-               $data->{'datelastseen'}=$date;
-               $data->{'datedue'}=$datedue;
-       # get notforloan complete status if applicable
-               my $sthnflstatus = $dbh->prepare('select authorised_value from marc_subfield_structure where kohafield="items.notforloan"');
-               $sthnflstatus->execute;
-               my ($authorised_valuecode) = $sthnflstatus->fetchrow;
-               if ($authorised_valuecode) {
-                       $sthnflstatus = $dbh->prepare("select lib from authorised_values where category=? and authorised_value=?");
-                       $sthnflstatus->execute($authorised_valuecode,$data->{itemnotforloan});
-                       my ($lib) = $sthnflstatus->fetchrow;
-                       $data->{notforloan} = $lib;
-               }
-               $results[$i]=$data;
-               $i++;
-       }
-       $sth->finish;
-       #FIXME: ordering/indentation here looks wrong
-# buggy : count in $i+1 the info on qty ordered for $i : total shown is real total +1
-# useless : Koha 2.2.2 now automatically show the existing number of items
-# and if there is no items, and at least one is on order, show "on order".
-#      my $sth2=$dbh->prepare("Select * from aqorders where biblionumber=?");
-#      $sth2->execute($biblionumber);
-#      my $data;
-#      my $ocount;
-#      if ($data=$sth2->fetchrow_hashref){
-#              $ocount=$data->{'quantity'} - $data->{'quantityreceived'};
-#              if ($ocount > 0){
-#              $data->{'ocount'}=$ocount;
-#              $data->{'order'}="One Order";
-#              $results[$i]=$data;
-#              }
-#      }
-#      $sth2->finish;
-       return(@results);
-}
-
-=item GetItems
-
-  @results = &GetItems($env, $biblionumber);
-
-Returns information about books with the given biblionumber.
-
-C<$env> is ignored.
-
-C<&GetItems> returns an array of strings. Each element is a
-tab-separated list of values: biblioitemnumber, itemtype,
-classification, Dewey number, subclass, ISBN, volume, number, and
-itemdata.
-
-Itemdata, in turn, is a string of the form
-"I<barcode>C<[>I<holdingbranch>C<[>I<flags>" where I<flags> contains
-the string C<NFL> if the item is not for loan, and C<LOST> if the item
-is lost.
-
-=cut
-#'
-sub GetItems {
-   my ($env,$biblionumber)=@_;
-   #debug_msg($env,"GetItems");
-   my $dbh = C4::Context->dbh;
-   my $sth=$dbh->prepare("Select * from biblioitems where (biblionumber = ?)");
-   $sth->execute($biblionumber);
-   #debug_msg($env,"executed query");
-   my $i=0;
-   my @results;
-   while (my $data=$sth->fetchrow_hashref) {
-      #debug_msg($env,$data->{'biblioitemnumber'});
-      my $dewey = $data->{'dewey'};
-      $dewey =~ s/0+$//;
-      my $line = $data->{'biblioitemnumber'}."\t".$data->{'itemtype'};
-      $line .= "\t$data->{'classification'}\t$dewey";
-      $line .= "\t$data->{'subclass'}\t$data->{isbn}";
-      $line .= "\t$data->{'volume'}\t$data->{number}";
-      my $isth= $dbh->prepare("select * from items where biblioitemnumber = ?");
-      $isth->execute($data->{'biblioitemnumber'});
-      while (my $idata = $isth->fetchrow_hashref) {
-        my $iline = $idata->{'barcode'}."[".$idata->{'holdingbranch'}."[";
-       if ($idata->{'notforloan'} == 1) {
-         $iline .= "NFL ";
-       }
-       if ($idata->{'itemlost'} == 1) {
-         $iline .= "LOST ";
-       }
-        $line .= "\t$iline";
-      }
-      $isth->finish;
-      $results[$i] = $line;
-      $i++;
-   }
-   $sth->finish;
-   return(@results);
-}
-
-=item itemdata
-
-  $item = &itemdata($barcode);
-
-Looks up the item with the given barcode, and returns a
-reference-to-hash containing information about that item. The keys of
-the hash are the fields from the C<items> and C<biblioitems> tables in
-the Koha database.
-
-=cut
-#'
-sub itemdata {
-  my ($barcode)=@_;
-  my $dbh = C4::Context->dbh;
-  my $sth=$dbh->prepare("Select * from items,biblioitems where barcode=?
-  and items.biblioitemnumber=biblioitems.biblioitemnumber");
-  $sth->execute($barcode);
-  my $data=$sth->fetchrow_hashref;
-  $sth->finish;
-  return($data);
-}
-
-=item bibdata
-
-  $data = &bibdata($biblionumber, $type);
-
-Returns information about the book with the given biblionumber.
-
-C<$type> is ignored.
-
-C<&bibdata> returns a reference-to-hash. The keys are the fields in
-the C<biblio>, C<biblioitems>, and C<bibliosubtitle> tables in the
-Koha database.
-
-In addition, C<$data-E<gt>{subject}> is the list of the book's
-subjects, separated by C<" , "> (space, comma, space).
-
-If there are multiple biblioitems with the given biblionumber, only
-the first one is considered.
-
-=cut
-#'
-sub bibdata {
-       my ($bibnum, $type) = @_;
-       my $dbh   = C4::Context->dbh;
-       my $sth   = $dbh->prepare("Select *, biblioitems.notes AS bnotes, biblio.notes
-                                                               from biblio, biblioitems
-                                                               left join bibliosubtitle on
-                                                               biblio.biblionumber = bibliosubtitle.biblionumber
-                                                               left join itemtypes on biblioitems.itemtype=itemtypes.itemtype
-                                                               where biblio.biblionumber = ?
-                                                               and biblioitems.biblionumber = biblio.biblionumber");
-       $sth->execute($bibnum);
-       my $data;
-       $data  = $sth->fetchrow_hashref;
-       $sth->finish;
-       # handle management of repeated subtitle
-       $sth   = $dbh->prepare("Select * from bibliosubtitle where biblionumber = ?");
-       $sth->execute($bibnum);
-       my @subtitles;
-       while (my $dat = $sth->fetchrow_hashref){
-               my %line;
-               $line{subtitle} = $dat->{subtitle};
-               push @subtitles, \%line;
-       } # while
-       $data->{subtitles} = \@subtitles;
-       $sth->finish;
-       $sth   = $dbh->prepare("Select * from bibliosubject where biblionumber = ?");
-       $sth->execute($bibnum);
-       my @subjects;
-       while (my $dat = $sth->fetchrow_hashref){
-               my %line;
-               $line{subject} = $dat->{'subject'};
-               push @subjects, \%line;
-       } # while
-       $data->{subjects} = \@subjects;
-       $sth->finish;
-       $sth   = $dbh->prepare("Select * from additionalauthors where biblionumber = ?");
-       $sth->execute($bibnum);
-       while (my $dat = $sth->fetchrow_hashref){
-               $data->{'additionalauthors'} .= "$dat->{'author'} - ";
-       } # while
-       chop $data->{'additionalauthors'};
-       chop $data->{'additionalauthors'};
-       chop $data->{'additionalauthors'};
-       $sth->finish;
-       return($data);
-} # sub bibdata
-
-=item bibitemdata
-
-  $itemdata = &bibitemdata($biblioitemnumber);
-
-Looks up the biblioitem with the given biblioitemnumber. Returns a
-reference-to-hash. The keys are the fields from the C<biblio>,
-C<biblioitems>, and C<itemtypes> tables in the Koha database, except
-that C<biblioitems.notes> is given as C<$itemdata-E<gt>{bnotes}>.
-
-=cut
-#'
-sub bibitemdata {
-    my ($bibitem) = @_;
-    my $dbh   = C4::Context->dbh;
-    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");
-    my $data;
-
-    $sth->execute($bibitem);
-
-    $data = $sth->fetchrow_hashref;
-
-    $sth->finish;
-    return($data);
-} # sub bibitemdata
-
-=item subject
-
-  ($count, $subjects) = &subject($biblionumber);
-
-Looks up the subjects of the book with the given biblionumber. Returns
-a two-element list. C<$subjects> is a reference-to-array, where each
-element is a subject of the book, and C<$count> is the number of
-elements in C<$subjects>.
-
-=cut
-#'
-sub subject {
-  my ($bibnum)=@_;
-  my $dbh = C4::Context->dbh;
-  my $sth=$dbh->prepare("Select * from bibliosubject where biblionumber=?");
-  $sth->execute($bibnum);
-  my @results;
-  my $i=0;
-  while (my $data=$sth->fetchrow_hashref){
-    $results[$i]=$data;
-    $i++;
-  }
-  $sth->finish;
-  return($i,\@results);
-}
-
-=item addauthor
-
-  ($count, $authors) = &addauthors($biblionumber);
-
-Looks up the additional authors for the book with the given
-biblionumber.
-
-Returns a two-element list. C<$authors> is a reference-to-array, where
-each element is an additional author, and C<$count> is the number of
-elements in C<$authors>.
-
-=cut
-#'
-sub addauthor {
-  my ($bibnum)=@_;
-  my $dbh = C4::Context->dbh;
-  my $sth=$dbh->prepare("Select * from additionalauthors where biblionumber=?");
-  $sth->execute($bibnum);
-  my @results;
-  my $i=0;
-  while (my $data=$sth->fetchrow_hashref){
-    $results[$i]=$data;
-    $i++;
-  }
-  $sth->finish;
-  return($i,\@results);
-}
-
-=item subtitle
-
-  ($count, $subtitles) = &subtitle($biblionumber);
-
-Looks up the subtitles for the book with the given biblionumber.
-
-Returns a two-element list. C<$subtitles> is a reference-to-array,
-where each element is a subtitle, and C<$count> is the number of
-elements in C<$subtitles>.
-
-=cut
-#'
-sub subtitle {
-  my ($bibnum)=@_;
-  my $dbh = C4::Context->dbh;
-  my $sth=$dbh->prepare("Select * from bibliosubtitle where biblionumber=?");
-  $sth->execute($bibnum);
-  my @results;
-  my $i=0;
-  while (my $data=$sth->fetchrow_hashref){
-    $results[$i]=$data;
-    $i++;
-  }
-  $sth->finish;
-  return($i,\@results);
-}
-
-=item itemissues
-
-  @issues = &itemissues($biblioitemnumber, $biblio);
-
-Looks up information about who has borrowed the bookZ<>(s) with the
-given biblioitemnumber.
-
-C<$biblio> is ignored.
-
-C<&itemissues> returns an array of references-to-hash. The keys
-include the fields from the C<items> table in the Koha database.
-Additional keys include:
-
-=over 4
-
-=item C<date_due>
-
-If the item is currently on loan, this gives the due date.
-
-If the item is not on loan, then this is either "Available" or
-"Cancelled", if the item has been withdrawn.
-
-=item C<card>
-
-If the item is currently on loan, this gives the card number of the
-patron who currently has the item.
-
-=item C<timestamp0>, C<timestamp1>, C<timestamp2>
-
-These give the timestamp for the last three times the item was
-borrowed.
-
-=item C<card0>, C<card1>, C<card2>
-
-The card number of the last three patrons who borrowed this item.
-
-=item C<borrower0>, C<borrower1>, C<borrower2>
-
-The borrower number of the last three patrons who borrowed this item.
-
-=back
-
-=cut
-#'
-sub itemissues {
-    my ($bibitem, $biblio)=@_;
-    my $dbh   = C4::Context->dbh;
-    # FIXME - If this function die()s, the script will abort, and the
-    # user won't get anything; depending on how far the script has
-    # gotten, the user might get a blank page. It would be much better
-    # to at least print an error message. The easiest way to do this
-    # is to set $SIG{__DIE__}.
-    my $sth   = $dbh->prepare("Select * from items where
-items.biblioitemnumber = ?")
-      || die $dbh->errstr;
-    my $i     = 0;
-    my @results;
-
-    $sth->execute($bibitem)
-      || die $sth->errstr;
-
-    while (my $data = $sth->fetchrow_hashref) {
-        # Find out who currently has this item.
-        # FIXME - Wouldn't it be better to do this as a left join of
-        # some sort? Currently, this code assumes that if
-        # fetchrow_hashref() fails, then the book is on the shelf.
-        # fetchrow_hashref() can fail for any number of reasons (e.g.,
-        # database server crash), not just because no items match the
-        # search criteria.
-        my $sth2   = $dbh->prepare("select * from issues,borrowers
-where itemnumber = ?
-and returndate is NULL
-and issues.borrowernumber = borrowers.borrowernumber");
-
-        $sth2->execute($data->{'itemnumber'});
-        if (my $data2 = $sth2->fetchrow_hashref) {
-            $data->{'date_due'} = $data2->{'date_due'};
-            $data->{'card'}     = $data2->{'cardnumber'};
-           $data->{'borrower'}     = $data2->{'borrowernumber'};
-        } else {
-            if ($data->{'wthdrawn'} eq '1') {
-                $data->{'date_due'} = 'Cancelled';
-            } else {
-                $data->{'date_due'} = 'Available';
-            } # else
-        } # else
-
-        $sth2->finish;
-
-        # Find the last 3 people who borrowed this item.
-        $sth2 = $dbh->prepare("select * from issues, borrowers
-                                               where itemnumber = ?
-                                                                       and issues.borrowernumber = borrowers.borrowernumber
-                                                                       and returndate is not NULL
-                                                                       order by returndate desc,timestamp desc") || die $dbh->errstr;
-        $sth2->execute($data->{'itemnumber'}) || die $sth2->errstr;
-        for (my $i2 = 0; $i2 < 2; $i2++) { # FIXME : error if there is less than 3 pple borrowing this item
-            if (my $data2 = $sth2->fetchrow_hashref) {
-                $data->{"timestamp$i2"} = $data2->{'timestamp'};
-                $data->{"card$i2"}      = $data2->{'cardnumber'};
-                $data->{"borrower$i2"}  = $data2->{'borrowernumber'};
-            } # if
-        } # for
-
-        $sth2->finish;
-        $results[$i] = $data;
-        $i++;
-    }
-
-    $sth->finish;
-    return(@results);
-}
-
-=item itemnodata
-
-  $item = &itemnodata($env, $dbh, $biblioitemnumber);
-
-Looks up the item with the given biblioitemnumber.
-
-C<$env> and C<$dbh> are ignored.
-
-C<&itemnodata> returns a reference-to-hash whose keys are the fields
-from the C<biblio>, C<biblioitems>, and C<items> tables in the Koha
-database.
-
-=cut
-#'
-sub itemnodata {
-  my ($env,$dbh,$itemnumber) = @_;
-  $dbh = C4::Context->dbh;
-  my $sth=$dbh->prepare("Select * from biblio,items,biblioitems
-    where items.itemnumber = ?
-    and biblio.biblionumber = items.biblionumber
-    and biblioitems.biblioitemnumber = items.biblioitemnumber");
-#  print $query;
-  $sth->execute($itemnumber);
-  my $data=$sth->fetchrow_hashref;
-  $sth->finish;
-  return($data);
-}
-
-=item BornameSearch
-
-  ($count, $borrowers) = &BornameSearch($env, $searchstring, $type);
-
-Looks up patrons (borrowers) by name.
-
-C<$env> is ignored.
-
-BUGFIX 499: C<$type> is now used to determine type of search.
-if $type is "simple", search is performed on the first letter of the
-surname only.
-
-C<$searchstring> is a space-separated list of search terms. Each term
-must match the beginning a borrower's surname, first name, or other
-name.
-
-C<&BornameSearch> returns a two-element list. C<$borrowers> is a
-reference-to-array; each element is a reference-to-hash, whose keys
-are the fields of the C<borrowers> table in the Koha database.
-C<$count> is the number of elements in C<$borrowers>.
-
-=cut
-#'
-#used by member enquiries from the intranet
-#called by member.pl
-sub BornameSearch  {
-       my ($env,$searchstring,$orderby,$type)=@_;
-       my $dbh = C4::Context->dbh;
-       my $query = ""; my $count; my @data;
-       my @bind=();
-
-       if($type eq "simple")   # simple search for one letter only
-       {
-               $query="Select * from borrowers where surname like ? order by $orderby";
-               @bind=("$searchstring%");
-       }
-       else    # advanced search looking in surname, firstname and othernames
-       {
-               @data=split(' ',$searchstring);
-               $count=@data;
-               $query="Select * from borrowers
-               where ((surname like ? or surname like ?
-               or firstname  like ? or firstname like ?
-               or othernames like ? or othernames like ?)
-               ";
-               @bind=("$data[0]%","% $data[0]%","$data[0]%","% $data[0]%","$data[0]%","% $data[0]%");
-               for (my $i=1;$i<$count;$i++){
-                       $query=$query." and (".
-                       " surname like ? or surname like ?
-                        or firstname  like ? or firstname like ?
-                       or othernames like ? or othernames like ?)";
-                       push(@bind,"$data[$i]%","% $data[$i]%","$data[$i]%","% $data[$i]%","$data[$i]%","% $data[$i]%");
-                                       # FIXME - .= <<EOT;
-               }
-               $query=$query.") or cardnumber like ?
-               order by $orderby";
-               push(@bind,$searchstring);
-                                       # FIXME - .= <<EOT;
-       }
-
-       my $sth=$dbh->prepare($query);
-#      warn "Q $orderby : $query";
-       $sth->execute(@bind);
-       my @results;
-       my $cnt=$sth->rows;
-       while (my $data=$sth->fetchrow_hashref){
-       push(@results,$data);
-       }
-       #  $sth->execute;
-       $sth->finish;
-       return ($cnt,\@results);
-}
-
-=item borrdata
-
-  $borrower = &borrdata($cardnumber, $borrowernumber);
-
-Looks up information about a patron (borrower) by either card number
-or borrower number. If $borrowernumber is specified, C<&borrdata>
-searches by borrower number; otherwise, it searches by card number.
-
-C<&borrdata> returns a reference-to-hash whose keys are the fields of
-the C<borrowers> table in the Koha database.
-
-=cut
-#'
-sub borrdata {
-  my ($cardnumber,$bornum)=@_;
-  $cardnumber = uc $cardnumber;
-  my $dbh = C4::Context->dbh;
-  my $sth;
-  if ($bornum eq ''){
-    $sth=$dbh->prepare("Select * from borrowers where cardnumber=?");
-    $sth->execute($cardnumber);
-  } else {
-    $sth=$dbh->prepare("Select * from borrowers where borrowernumber=?");
-  $sth->execute($bornum);
-  }
-  my $data=$sth->fetchrow_hashref;
-  $sth->finish;
-  if ($data) {
-       return($data);
-       } else { # try with firstname
-               if ($cardnumber) {
-                       my $sth=$dbh->prepare("select * from borrowers where firstname=?");
-                       $sth->execute($cardnumber);
-                       my $data=$sth->fetchrow_hashref;
-                       $sth->finish;
-                       return($data);
-               }
-       }
-       return undef;
-}
-
-=item borrissues
-
-  ($count, $issues) = &borrissues($borrowernumber);
-
-Looks up what the patron with the given borrowernumber has borrowed.
-
-C<&borrissues> returns a two-element array. C<$issues> is a
-reference-to-array, where each element is a reference-to-hash; the
-keys are the fields from the C<issues>, C<biblio>, and C<items> tables
-in the Koha database. C<$count> is the number of elements in
-C<$issues>.
-
-=cut
-#'
-sub borrissues {
-  my ($bornum)=@_;
-  my $dbh = C4::Context->dbh;
-  my $sth=$dbh->prepare("Select * from issues,biblio,items where borrowernumber=?
-   and items.itemnumber=issues.itemnumber
-       and items.biblionumber=biblio.biblionumber
-       and issues.returndate is NULL order by date_due");
-    $sth->execute($bornum);
-  my @result;
-  while (my $data = $sth->fetchrow_hashref) {
-    push @result, $data;
-  }
-  $sth->finish;
-  return(scalar(@result), \@result);
-}
-
-=item allissues
-
-  ($count, $issues) = &allissues($borrowernumber, $sortkey, $limit);
-
-Looks up what the patron with the given borrowernumber has borrowed,
-and sorts the results.
-
-C<$sortkey> is the name of a field on which to sort the results. This
-should be the name of a field in the C<issues>, C<biblio>,
-C<biblioitems>, or C<items> table in the Koha database.
-
-C<$limit> is the maximum number of results to return.
-
-C<&allissues> returns a two-element array. C<$issues> is a
-reference-to-array, where each element is a reference-to-hash; the
-keys are the fields from the C<issues>, C<biblio>, C<biblioitems>, and
-C<items> tables of the Koha database. C<$count> is the number of
-elements in C<$issues>
-
-=cut
-#'
-sub allissues {
-  my ($bornum,$order,$limit)=@_;
-  #FIXME: sanity-check order and limit
-  my $dbh = C4::Context->dbh;
-  my $query="Select * from issues,biblio,items,biblioitems
-  where borrowernumber=? and
-  items.biblioitemnumber=biblioitems.biblioitemnumber and
-  items.itemnumber=issues.itemnumber and
-  items.biblionumber=biblio.biblionumber order by $order";
-  if ($limit !=0){
-    $query.=" limit $limit";
-  }
-  #print $query;
-  my $sth=$dbh->prepare($query);
-  $sth->execute($bornum);
-  my @result;
-  my $i=0;
-  while (my $data=$sth->fetchrow_hashref){
-    $result[$i]=$data;;
-    $i++;
-  }
-  $sth->finish;
-  return($i,\@result);
-}
-
-=item borrdata2
-
-  ($borrowed, $due, $fine) = &borrdata2($env, $borrowernumber);
-
-Returns aggregate data about items borrowed by the patron with the
-given borrowernumber.
-
-C<$env> is ignored.
-
-C<&borrdata2> returns a three-element array. C<$borrowed> is the
-number of books the patron currently has borrowed. C<$due> is the
-number of overdue items the patron currently has borrowed. C<$fine> is
-the total fine currently due by the borrower.
-
-=cut
-#'
-sub borrdata2 {
-  my ($env,$bornum)=@_;
-  my $dbh = C4::Context->dbh;
-  my $query="Select count(*) from issues where borrowernumber='$bornum' and
-    returndate is NULL";
-    # print $query;
-  my $sth=$dbh->prepare($query);
-  $sth->execute;
-  my $data=$sth->fetchrow_hashref;
-  $sth->finish;
-  $sth=$dbh->prepare("Select count(*) from issues where
-    borrowernumber='$bornum' and date_due < now() and returndate is NULL");
-  $sth->execute;
-  my $data2=$sth->fetchrow_hashref;
-  $sth->finish;
-  $sth=$dbh->prepare("Select sum(amountoutstanding) from accountlines where
-    borrowernumber='$bornum'");
-  $sth->execute;
-  my $data3=$sth->fetchrow_hashref;
-  $sth->finish;
-
-return($data2->{'count(*)'},$data->{'count(*)'},$data3->{'sum(amountoutstanding)'});
-}
-
-=item getboracctrecord
-
-  ($count, $acctlines, $total) = &getboracctrecord($env, $borrowernumber);
-
-Looks up accounting data for the patron with the given borrowernumber.
-
-C<$env> is ignored.
-
-(FIXME - I'm not at all sure what this is about.)
-
-C<&getboracctrecord> returns a three-element array. C<$acctlines> is a
-reference-to-array, where each element is a reference-to-hash; the
-keys are the fields of the C<accountlines> table in the Koha database.
-C<$count> is the number of elements in C<$acctlines>. C<$total> is the
-total amount outstanding for all of the account lines.
-
-=cut
-#'
-sub getboracctrecord {
-   my ($env,$params) = @_;
-   my $dbh = C4::Context->dbh;
-   my @acctlines;
-   my $numlines=0;
-   my $sth=$dbh->prepare("Select * from accountlines where
-borrowernumber=? order by date desc,timestamp desc");
-#   print $query;
-   $sth->execute($params->{'borrowernumber'});
-   my $total=0;
-   while (my $data=$sth->fetchrow_hashref){
-   #FIXME before reinstating: insecure?
-#      if ($data->{'itemnumber'} ne ''){
-#        $query="Select * from items,biblio where items.itemnumber=
-#      '$data->{'itemnumber'}' and biblio.biblionumber=items.biblionumber";
-#      my $sth2=$dbh->prepare($query);
-#      $sth2->execute;
-#      my $data2=$sth2->fetchrow_hashref;
-#      $sth2->finish;
-#      $data=$data2;
- #     }
-      $acctlines[$numlines] = $data;
-      $numlines++;
-      $total += $data->{'amountoutstanding'};
-   }
-   $sth->finish;
-   return ($numlines,\@acctlines,$total);
-}
-
-=item itemcount2
-
-  $counts = &itemcount2($env, $biblionumber, $type);
-
-Counts the number of items with the given biblionumber, broken down by
-category.
-
-C<$env> is ignored.
-
-C<$type> may be either C<intra> or anything else. If it is not set to
-C<intra>, then the search will exclude lost, very overdue, and
-withdrawn items.
-
-C<$&itemcount2> returns a reference-to-hash, with the following fields:
-
-=over 4
-
-=item C<total>
-
-The total number of items with this biblionumber.
-
-=item C<order>
-
-The number of items on order (aqorders.quantity -
-aqorders.quantityreceived).
-
-=item I<branchname>
-
-For each branch that has at least one copy of the book, C<$counts>
-will have a key with the branch name, giving the number of copies at
-that branch.
-
-=back
-
-=cut
-#'
-sub itemcount2 {
-  my ($env,$bibnum,$type)=@_;
-  my $dbh = C4::Context->dbh;
-  my $query="Select * from items,branches where
-  biblionumber=? and items.holdingbranch=branches.branchcode";
-  if ($type ne 'intra'){
-    $query.=" and ((itemlost <>1 and itemlost <> 2) or itemlost is NULL) and
-    (wthdrawn <> 1 or wthdrawn is NULL)";
-  }
-  my $sth=$dbh->prepare($query);
-  #  print $query;
-  $sth->execute($bibnum);
-  my %counts;
-  $counts{'total'}=0;
-  while (my $data=$sth->fetchrow_hashref){
-    $counts{'total'}++;
-
-    my $status;
-    for my $test (
-      [
-       'Item Lost',
-       'select * from items
-         where itemnumber=?
-           and not ((items.itemlost <>1 and items.itemlost <> 2)
-                     or items.itemlost is NULL)'
-      ], [
-       'Withdrawn',
-       'select * from items
-         where itemnumber=? and not (wthdrawn <> 1 or wthdrawn is NULL)'
-      ], [
-       'On Loan', "select * from issues,items
-         where issues.itemnumber=? and returndate is NULL
-           and items.itemnumber=issues.itemnumber"
-      ],
-    ) {
-       my($testlabel, $query2) = @$test;
-
-       my $sth2=$dbh->prepare($query2);
-       $sth2->execute($data->{'itemnumber'});
-
-       # FIXME - fetchrow_hashref() can fail for any number of reasons
-       # (e.g., a database server crash). Perhaps use a left join of some
-       # sort for this?
-       $status = $testlabel if $sth2->fetchrow_hashref;
-       $sth2->finish;
-    last if defined $status;
-    }
-    $status = $data->{'branchname'} unless defined $status;
-    $counts{$status}++;
-  }
-  my $sth2=$dbh->prepare("Select * from aqorders where biblionumber=? and
-  datecancellationprinted is NULL and quantity > quantityreceived");
-  $sth2->execute($bibnum);
-  if (my $data=$sth2->fetchrow_hashref){
-      $counts{'order'}=$data->{'quantity'} - $data->{'quantityreceived'};
-  }
-  $sth2->finish;
-  $sth->finish;
-  return (\%counts);
-}
-
-=item ItemType
-
-  $description = &ItemType($itemtype);
-
-Given an item type code, returns the description for that type.
-
-=cut
-#'
-
-# FIXME - I'm pretty sure that after the initial setup, the list of
-# item types doesn't change very often. Hence, it seems slow and
-# inefficient to make yet another database call to look up information
-# that'll only change every few months or years.
-#
-# Much better, I think, to automatically build a Perl file that can be
-# included in those scripts that require it, e.g.:
-#      @itemtypes = qw( ART BCD CAS CD F ... );
-#      %itemtypedesc = (
-#              ART     => "Art Prints",
-#              BCD     => "CD-ROM from book",
-#              CD      => "Compact disc (WN)",
-#              F       => "Free Fiction",
-#              ...
-#      );
-# The web server can then run a cron job to rebuild this file from the
-# database every hour or so.
-#
-# The same thing goes for branches, book funds, book sellers, currency
-# rates, printers, stopwords, and perhaps others.
-sub ItemType {
-  my ($type)=@_;
-  my $dbh = C4::Context->dbh;
-  my $sth=$dbh->prepare("select description from itemtypes where itemtype=?");
-  $sth->execute($type);
-  my $dat=$sth->fetchrow_hashref;
-  $sth->finish;
-  return ($dat->{'description'});
-}
-
-=item bibitems
-
-  ($count, @results) = &bibitems($biblionumber);
-
-Given the biblionumber for a book, C<&bibitems> looks up that book's
-biblioitems (different publications of the same book, the audio book
-and film versions, etc.).
-
-C<$count> is the number of elements in C<@results>.
-
-C<@results> is an array of references-to-hash; the keys are the fields
-of the C<biblioitems> and C<itemtypes> tables of the Koha database. In
-addition, C<itemlost> indicates the availability of the item: if it is
-"2", then all copies of the item are long overdue; if it is "1", then
-all copies are lost; otherwise, there is at least one copy available.
-
-=cut
-#'
-sub bibitems {
-    my ($bibnum) = @_;
-    my $dbh   = C4::Context->dbh;
-    my $sth   = $dbh->prepare("SELECT biblioitems.*,
-                        itemtypes.*,
-                        MIN(items.itemlost)        as itemlost,
-                        MIN(items.dateaccessioned) as dateaccessioned
-                          FROM biblioitems, itemtypes, items
-                         WHERE biblioitems.biblionumber     = ?
-                           AND biblioitems.itemtype         = itemtypes.itemtype
-                           AND biblioitems.biblioitemnumber = items.biblioitemnumber
-                      GROUP BY items.biblioitemnumber");
-    my $count = 0;
-    my @results;
-    $sth->execute($bibnum);
-    while (my $data = $sth->fetchrow_hashref) {
-        $results[$count] = $data;
-        $count++;
-    } # while
-    $sth->finish;
-    return($count, @results);
-} # sub bibitems
-
-=item barcodes
-
-  @barcodes = &barcodes($biblioitemnumber);
-
-Given a biblioitemnumber, looks up the corresponding items.
-
-Returns an array of references-to-hash; the keys are C<barcode> and
-C<itemlost>.
-
-The returned items include very overdue items, but not lost ones.
-
-=cut
-#'
-sub barcodes{
-    #called from request.pl
-    my ($biblioitemnumber)=@_;
-    my $dbh = C4::Context->dbh;
-    my $sth=$dbh->prepare("SELECT barcode, itemlost, holdingbranch FROM items
-                           WHERE biblioitemnumber = ?
-                             AND (wthdrawn <> 1 OR wthdrawn IS NULL)");
-    $sth->execute($biblioitemnumber);
-    my @barcodes;
-    my $i=0;
-    while (my $data=$sth->fetchrow_hashref){
-       $barcodes[$i]=$data;
-       $i++;
-    }
-    $sth->finish;
-    return(@barcodes);
-}
-
-=item getwebsites
-
-  ($count, @websites) = &getwebsites($biblionumber);
-
-Looks up the web sites pertaining to the book with the given
-biblionumber.
-
-C<$count> is the number of elements in C<@websites>.
-
-C<@websites> is an array of references-to-hash; the keys are the
-fields from the C<websites> table in the Koha database.
-
-=cut
-#'
-sub getwebsites {
-    my ($biblionumber) = @_;
-    my $dbh   = C4::Context->dbh;
-    my $sth   = $dbh->prepare("Select * from websites where biblionumber = ?");
-    my $count = 0;
-    my @results;
-
-    $sth->execute($biblionumber);
-    while (my $data = $sth->fetchrow_hashref) {
-        # FIXME - The URL scheme shouldn't be stripped off, at least
-        # not here, since it's part of the URL, and will be useful in
-        # constructing a link to the site. If you don't want the user
-        # to see the "http://" part, strip that off when building the
-        # HTML code.
-        $data->{'url'} =~ s/^http:\/\///;      # FIXME - Leaning toothpick
-                                               # syndrome
-        $results[$count] = $data;
-       $count++;
-    } # while
-
-    $sth->finish;
-    return($count, @results);
-} # sub getwebsites
-
-=item getwebbiblioitems
-
-  ($count, @results) = &getwebbiblioitems($biblionumber);
-
-Given a book's biblionumber, looks up the web versions of the book
-(biblioitems with itemtype C<WEB>).
-
-C<$count> is the number of items in C<@results>. C<@results> is an
-array of references-to-hash; the keys are the items from the
-C<biblioitems> table of the Koha database.
-
-=cut
-#'
-sub getwebbiblioitems {
-    my ($biblionumber) = @_;
-    my $dbh   = C4::Context->dbh;
-    my $sth   = $dbh->prepare("Select * from biblioitems where biblionumber = ?
-and itemtype = 'WEB'");
-    my $count = 0;
-    my @results;
-
-    $sth->execute($biblionumber);
-    while (my $data = $sth->fetchrow_hashref) {
-        $data->{'url'} =~ s/^http:\/\///;
-        $results[$count] = $data;
-        $count++;
-    } # while
-
-    $sth->finish;
-    return($count, @results);
-} # sub getwebbiblioitems
-
-
-
-=item isbnsearch
-
-  ($count, @results) = &isbnsearch($isbn,$title);
-
-Given an isbn and/or a title, returns the biblios having it.
-Used in acqui.simple, isbnsearch.pl only
-
-C<$count> is the number of items in C<@results>. C<@results> is an
-array of references-to-hash; the keys are the items from the
-C<biblioitems> table of the Koha database.
-
-=cut
-
-sub isbnsearch {
-    my ($isbn,$title) = @_;
-    my $dbh   = C4::Context->dbh;
-    my $count = 0;
-    my ($query,@bind);
-    my $sth;
-    my @results;
-
-    $query = "Select distinct biblio.*, biblioitems.classification from biblio, biblioitems where
-                               biblio.biblionumber = biblioitems.biblionumber";
-       @bind=();
-       if ($isbn) {
-               $query .= " and isbn like ?";
-               @bind=(uc($isbn)."%");
-       }
-       if ($title) {
-               $query .= " and title like ?";
-               @bind=($title."%");
-       }
-    $sth   = $dbh->prepare($query);
-
-    $sth->execute(@bind);
-    while (my $data = $sth->fetchrow_hashref) {
-        $results[$count] = $data;
-       $count++;
-    } # while
-
-    $sth->finish;
-    return($count, @results);
-} # sub isbnsearch
-
-=item getbranchname
-
-  $branchname = &getbranchname($branchcode);
-
-Given the branch code, the function returns the corresponding
-branch name for a comprehensive information display
-
-=cut
-
-sub getbranchname
-{
-       my ($branchcode) = @_;
-       my $dbh = C4::Context->dbh;
-       my $sth = $dbh->prepare("SELECT branchname FROM branches WHERE branchcode = ?");
-       $sth->execute($branchcode);
-       my $branchname = $sth->fetchrow();
-       $sth->finish();
-       return $branchname;
-} # sub getbranchname
-
-=item getborrowercategory
-
-  $description = &getborrowercategory($categorycode);
-
-Given the borrower's category code, the function returns the corresponding
-description for a comprehensive information display.
-
-=cut
-
-sub getborrowercategory
-{
-       my ($catcode) = @_;
-       my $dbh = C4::Context->dbh;
-       my $sth = $dbh->prepare("SELECT description FROM categories WHERE categorycode = ?");
-       $sth->execute($catcode);
-       my $description = $sth->fetchrow();
-       $sth->finish();
-       return $description;
-} # sub getborrowercategory
-
-
 END { }       # module clean-up code here (global destructor)
 
 1;
index 831fe63..473713b 100755 (executable)
@@ -137,7 +137,8 @@ sub get_authorised_value_desc ($$$$$) {
 
    #---- itemtypes
    if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
-       return ItemType($value);
+               my $itemtypedef = getitemtypeinfo($itemtype);
+       return $itemtypedef->{description};
     }
 
    #---- "true" authorized value
index d9efbd3..5777ed6 100755 (executable)
@@ -52,7 +52,7 @@ use C4::Context;
 use C4::Output;
 use C4::Interface::CGI::Output;
 use CGI;
-use C4::Search;
+use C4::Koha;
 use MARC::Record;
 use C4::Biblio;
 use C4::Acquisition;
@@ -240,7 +240,8 @@ sub get_authorised_value_desc ($$$$$) {
 
    #---- itemtypes
    if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
-       return ItemType($value);
+               my $itemtypedef = getitemtypeinfo($itemtype);
+       return $itemtypedef->{description};
     }
 
    #---- "true" authorized value
index c6ae94c..6310f57 100755 (executable)
@@ -79,7 +79,7 @@ if ($op eq "additem") {
        my $addeditem = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators);
 # check for item barcode # being unique
        my $addedolditem = MARCmarc2koha($dbh,$addeditem);
-       my $exists = itemdata($addedolditem->{'barcode'});
+       my $exists = get_item_from_barcode($addedolditem->{'barcode'});
        push @errors,"barcode_not_unique" if($exists);
        # if barcode exists, don't create, but report The problem.
        $itemnumber = NEWnewitem($dbh,$addeditem,$biblionumber,$biblioitemnumber) unless ($exists);
index 332e07d..eb37b95 100755 (executable)
@@ -29,7 +29,7 @@ use C4::Output;
 use C4::Interface::CGI::Output;
 use C4::Date;
 use CGI;
-use C4::Search;
+use C4::Members;
 use HTML::Template;
 
 my $input=new CGI;
index ca62bd5..4356b52 100755 (executable)
@@ -25,71 +25,9 @@ use C4::Koha;
 use C4::Auth;
 use HTML::Template;
 use C4::Context;
-use C4::Search;
-use C4::Auth;
 use C4::Output;
 use C4::Interface::CGI::Output;
-use C4::Biblio;
-use C4::Acquisition;
 use C4::SearchMarc;
-use C4::Koha; # XXX subfield_is_koha_internal_p
-
-# Creates the list of active tags using the active MARC configuration
-sub create_marclist {
-       my $dbh = C4::Context->dbh;
-       my $tagslib = &MARCgettagslib($dbh,1);
-       my @marcarray;
-       push @marcarray,"";
-       my $widest_menu_item_width = 0;
-       for (my $pass = 1; $pass <= 2; $pass += 1)
-       {
-               for (my $tabloop = 0; $tabloop<=9;$tabloop++)
-               {
-                       my $separator_inserted_p = 0; # FIXME... should not use!!
-                       foreach my $tag (sort(keys (%{$tagslib})))
-                       {
-                               foreach my $subfield (sort(keys %{$tagslib->{$tag}}))
-                               {
-                                       next if subfield_is_koha_internal_p($subfield);
-                                       next unless ($tagslib->{$tag}->{$subfield}->{tab} eq $tabloop);
-                                       my $menu_item = "$tag$subfield - $tagslib->{$tag}->{$subfield}->{lib}";
-                                       if ($pass == 1)
-                                       {
-                                               $widest_menu_item_width = length $menu_item if($widest_menu_item_width < length $menu_item);
-                                       } else {
-                                               if (!$separator_inserted_p)
-                                               {
-                                                       my $w = int(($widest_menu_item_width - 3 + 0.5)/2);
-                                                       my $s = ('-' x ($w * 4/5));
-                                                       push @marcarray,  "$s $tabloop $s";
-                                                       $separator_inserted_p = 1;
-                                               }
-                                       push @marcarray, $menu_item;
-                                       }
-                               }
-                       }
-               }
-       }
-       return \@marcarray;
-}
-
-# Creates a scrolling list with the associated default value.
-# Using more than one scrolling list in a CGI assigns the same default value to all the
-# scrolling lists on the page !?!? That's why this function was written.
-sub create_scrolling_list {
-       my ($params) = @_;
-       my $scrollist = sprintf("<select name=\"%s\" size=\"%d\" onChange='%s'>\n", $params->{'name'}, $params->{'size'}, $params->{'onChange'});
-
-       foreach my $tag (@{$params->{'values'}})
-       {
-               my $selected = "selected " if($params->{'default'} eq $tag);
-               $scrollist .= sprintf("<option %svalue=\"%s\">%s</option>\n", $selected, $tag, $tag);
-       }
-
-       $scrollist .= "</select>\n";
-
-       return $scrollist;
-}
 
 my $query=new CGI;
 my $type=$query->param('type');
@@ -209,64 +147,6 @@ if ($op eq "do_search") {
                                flagsrequired => {catalogue => 1},
                                debug => 1,
                                });
-       #$template->param(loggedinuser => $loggedinuser);
-
-       my $marcarray = create_marclist();
-
-       my $marclist = CGI::scrolling_list(-name=>"marclist",
-                                       -values=> $marcarray,
-                                       -size=>1,
-                                       -multiple=>0,
-                                       -onChange => "sql_update()",
-                                       );
-
-       my @statements = ();
-
-       # Considering initial search with 3 criterias
-       push @statements, { "marclist" => $marclist, "first" => 1 };
-       push @statements, { "marclist" => $marclist, "first" => 0 };
-       push @statements, { "marclist" => $marclist, "first" => 0 };
-       my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
-       $sth->execute;
-       my  @itemtype;
-       my %itemtypes;
-       push @itemtype, "";
-       $itemtypes{''} = "";
-       while (my ($value,$lib) = $sth->fetchrow_array) {
-               push @itemtype, $value;
-               $itemtypes{$value}=$lib;
-       }
-
-       my $CGIitemtype=CGI::scrolling_list( -name     => 'value',
-                               -values   => \@itemtype,
-                               -labels   => \%itemtypes,
-                               -size     => 1,
-                               -multiple => 0 );
-       $sth->finish;
-
-       my @branches;
-       my @select_branch;
-       my %select_branches;
-       my ($count2,@branches)=branches();
-       push @select_branch, "";
-       $select_branches{''} = "";
-       for (my $i=0;$i<$count2;$i++){
-               push @select_branch, $branches[$i]->{'branchcode'};#
-               $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
-       }
-       my $CGIbranch=CGI::scrolling_list( -name     => 'value',
-                               -values   => \@select_branch,
-                               -labels   => \%select_branches,
-                               -size     => 1,
-                               -multiple => 0 );
-       $sth->finish;
-
-
-       $template->param("statements" => \@statements,
-                       "nbstatements" => 3,
-                       CGIitemtype => $CGIitemtype,
-                       CGIbranch => $CGIbranch,
-                       );
 }
 
 
index b73f6d7..f375c6e 100755 (executable)
@@ -129,6 +129,7 @@ $template->param(
        bibliotitle => $subs->{bibliotitle},
        notes => $subs->{notes},
        letter => $subs->{letter},
+       distributedto => $subs->{distributedto},
        subscriptionid => $subs->{subscriptionid},
        serialslist => \@serialslist,
        totalissues => $totalissues,
index e5696e5..e183539 100755 (executable)
@@ -26,7 +26,7 @@
 use strict;
 use CGI;
 use C4::Circulation::Circ2;
-use C4::Search;
+use C4::Members;
 use C4::Output;
 use C4::Print;
 use DBI;
index 4e2a8d1..6779128 100755 (executable)
--- a/detail.pl
+++ b/detail.pl
@@ -2,7 +2,6 @@
 use strict;
 require Exporter;
 use CGI;
-use C4::Search;
 use C4::Auth;
 use C4::Bull; #uses getsubscriptionfrom biblionumber
 use C4::Interface::CGI::Output;
@@ -26,7 +25,7 @@ $template->param(biblionumber => $biblionumber);
 # change back when ive fixed request.pl
 my @items                                 = &ItemInfo(undef, $biblionumber, 'intra');
 my $dat                                   = &bibdata($biblionumber);
-my ($authorcount, $addauthor)             = &addauthor($biblionumber);
+my ($authorcount, $addauthor)             = &getaddauthor($biblionumber);
 my ($webbiblioitemcount, @webbiblioitems) = &getwebbiblioitems($biblionumber);
 my ($websitecount, @websites)             = &getwebsites($biblionumber);
 my $subscriptionsnumber = getsubscriptionfrombiblionumber($biblionumber);
index dd22665..55cbed7 100755 (executable)
@@ -24,8 +24,8 @@ require Exporter;
 use C4::Context;
 use C4::Output;  # contains gettemplate
 use CGI;
-use C4::Search;
 use C4::Auth;
+use C4::Biblio;
 use C4::Interface::CGI::Output;
 use C4::Date;
 
@@ -45,7 +45,7 @@ foreach my $itm (@items) {
 
 
 my $dat=bibdata($biblionumber);
-my ($authorcount, $addauthor)= &addauthor($biblionumber);
+my ($authorcount, $addauthor)= &getaddauthor($biblionumber);
 my ($webbiblioitemcount, @webbiblioitems) = &getwebbiblioitems($biblionumber);
 my ($websitecount, @websites)             = &getwebsites($biblionumber);
 
index 300e0a2..da02bc4 100755 (executable)
@@ -27,7 +27,7 @@ use C4::Output;
 use C4::Interface::CGI::Output;
 use CGI;
 use HTML::Template;
-use C4::Search;
+use C4::Members;
 use C4::Accounts2;
 my $input=new CGI;
 
index 62d3d6f..20213dd 100755 (executable)
@@ -26,7 +26,7 @@ use C4::Auth;
 use C4::Output;
 use C4::Interface::CGI::Output;
 use CGI;
-use C4::Search;
+use C4::Members;
 use C4::Accounts2;
 use HTML::Template;
 
index 844536f..2e117f8 100755 (executable)
@@ -27,7 +27,7 @@ my ($template, $loggedinuser, $cookie)
                                query => $input,
                                type => "intranet",
                                authnotrequired => 0,
-                               flagsrequired => {borrowers => 1},
+                               flagsrequired => {permissions => 1},
                                debug => 1,
                                });
 
index e01b4bf..bceb3b2 100755 (executable)
@@ -28,7 +28,7 @@ use C4::Auth;
 use C4::Output;
 use C4::Interface::CGI::Output;
 use CGI;
-use C4::Search;
+use C4::Members;
 use HTML::Template;
 
 my $input = new CGI;
index 6240915..5030ff2 100755 (executable)
@@ -37,7 +37,7 @@ use C4::Output;
 use C4::Interface::CGI::Output;
 use C4::Interface::CGI::Template;
 use CGI;
-use C4::Search;
+use C4::Members;
 use Date::Manip;
 use C4::Date;
 use C4::Reserves2;
@@ -174,7 +174,8 @@ for (my $i=0;$i<$count;$i++){
        # return the correct item type either (or a properly-formatted
        # charge, for that matter).
        my ($charge,$itemtype)=calc_charges($dbh,$issue->[$i]{'itemnumber'},$bornum);
-       $row{'itemtype'}=&ItemType($itemtype);
+       my $itemtypedef = getitemtypeinfo($itemtype);
+       $row{'itemtype'}=$itemtypedef->{description};
        $row{'charge'}= sprintf("%.2f",$charge);
 
        #check item is not reserved
index 14001f1..c548dcf 100755 (executable)
@@ -16,7 +16,7 @@ use lib '/usr/local/koha/intranet/modules/';
 
 use strict;
 use C4::Context;
-use C4::Search;
+use C4::Biblio;
 
 my ($biblionumber,$barcode,$holdingbranch,$pickbranch,$notes,$cardnumber,$lastname,$firstname,$phone,$title,$callno,$rdate,$borrno);
 
index dc62189..f6be018 100755 (executable)
@@ -131,7 +131,7 @@ for (my $i=0;$i<$numOverdueItems;$i++){
        my $dbh = C4::Context->dbh;
        my $env;
        my $accountno=C4::Circulation::Circ2::getnextacctno($env,$data->[$i]->{'borrowernumber'},$dbh);
-       my $item=itemnodata($env,$dbh,$data->[$i]->{'itemnumber'});
+       my $item=getbibliofromitemnumber($env,$dbh,$data->[$i]->{'itemnumber'});
        if ($item->{'itemlost'} ne '1' && $item->{'itemlost'} ne '2' ){
               # FIXME
               # this should be a separate function
index b2064c5..939c918 100755 (executable)
@@ -4,7 +4,7 @@
 
 
 use C4::Database;
-use C4::Search;
+use C4::Members;
 use C4::Circulation::Circ2;
 use C4::Circulation::Fines;
 use Date::Manip;
@@ -90,7 +90,7 @@ sub levyFines {
                                        my $env;
 
                                        my $accountno=C4::Circulation::Circ2::getnextacctno($env,$overdue->{'borrowernumber'},$dbh);
-                                               my $item=itemnodata($env,$dbh,$overdue->{'itemnumber'});
+                                               my $item=getbibliofromitemnumber($env,$dbh,$overdue->{'itemnumber'});
                                        if ($item->{'itemlost'} ne '1' && $item->{'itemlost'} ne '2' ){
                                                $item->{'title'}=~ s/\'/\\'/g;
                                                my $query="Insert into accountlines (borrowernumber,itemnumber,accountno,date,amount, description,accounttype,amountoutstanding) 
@@ -265,7 +265,7 @@ my %actions;
                                                        my %row_data;
                                                        my $env;        #FIXME what is this varible for?
                                                      
-                                                       if ( my $item = itemnodata($env, $dbh, $over->{'itemnumber'})){
+                                                       if ( my $item = getbibliofromitemnumber($env, $dbh, $over->{'itemnumber'})){
                                                            print "getting fine ($over->{'itemnumber'} $overdue->{'borrowernumber'} $over->{'borrowernumber'}\n";
                                                        my $fine = GetFine($over->{'itemnumber'},$overdue->{'borrowernumber'}); 
                                                            
index ead8781..4e02339 100755 (executable)
--- a/modbib.pl
+++ b/modbib.pl
@@ -3,10 +3,6 @@
 # $Id$
 
 #script to modify/delete biblios
-#written 8/11/99
-# modified 11/11/99 by chris@katipo.co.nz
-# modified 12/16/2002 by hdl@ifrance.com : templating
-
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -27,7 +23,7 @@
 
 use strict;
 
-use C4::Search;
+use C4::Biblio;
 use CGI;
 use C4::Output;
 use HTML::Template;
@@ -39,9 +35,9 @@ my $input = new CGI;
 
 my $bibnum=$input->param('bibnum');
 my $data=&bibdata($bibnum);
-my ($subjectcount, $subject)     = &subject($bibnum);
-my ($subtitlecount, $subtitle)   = &subtitle($bibnum);
-my ($addauthorcount, $addauthor) = &addauthor($bibnum);
+my ($subjectcount, $subject)     = &getsubject($bibnum);
+my ($subtitlecount, $subtitle)   = &getsubtitle($bibnum);
+my ($addauthorcount, $addauthor) = &getaddauthor($bibnum);
 my $sub        = $subject->[0]->{'subject'};
 my $additional = $addauthor->[0]->{'author'};
 my $dewey;
index c2e1998..07b3756 100755 (executable)
@@ -28,7 +28,6 @@
 use strict;
 require Exporter;
 
-use C4::Search;
 use C4::Output;
 use C4::Koha;
 use CGI;
index 13608df..cfeffd7 100755 (executable)
@@ -49,7 +49,7 @@ if ($submit ne ''){
 
 my $data=bibitemdata($bibitemnum);
 
-my $item=itemnodata('blah','',$itemnum);
+my $item=getbibliofromitemnumber('blah','',$itemnum);
 #my ($analytictitle)=analytic($biblionumber,'t');
 #my ($analyticauthor)=analytic($biblionumber,'a');
 
index c8c1590..36ef7a6 100755 (executable)
@@ -35,7 +35,7 @@ my $input = new CGI;
 #print $input->Dump;
 
 my @rank=$input->param('rank-request');
-my @biblio=$input->param('biblio');
+my @biblionumber=$input->param('biblionumber');
 my @borrower=$input->param('borrowernumber');
 my @branch=$input->param('pickup');
 my $count=@rank;
@@ -43,12 +43,12 @@ my $count=@rank;
 # goes through and manually changes the reserves record....
 # no attempt is made to check consistency.
 for (my $i=0;$i<$count;$i++){
-    UpdateReserve($rank[$i],$biblio[$i],$borrower[$i],$branch[$i]); #from C4::Reserves2
+    UpdateReserve($rank[$i],$biblionumber[$i],$borrower[$i],$branch[$i]); #from C4::Reserves2
 }
 
 my $from=$input->param('from');
 if ($from eq 'borrower'){
   print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$borrower[0]");
  } else {
-   print $input->redirect("/cgi-bin/koha/request.pl?bib=$biblio[0]");
+   print $input->redirect("/cgi-bin/koha/request.pl?biblionumber=$biblionumber[0]");
 }
index 70f846d..05a4a54 100755 (executable)
@@ -22,7 +22,7 @@
 
 use strict;
 
-use C4::Search;
+use C4::Biblio;
 use CGI;
 use C4::Output;
 use HTML::Template;
index 755a9f0..35c61f1 100755 (executable)
@@ -6,7 +6,7 @@
 use strict;
 use C4::Output;
 use CGI;
-use C4::Search;
+use C4::Members;
 use C4::Circulation::Circ2;
 use C4::Auth;
 use C4::Interface::CGI::Output;
index 0e60998..4156dd7 100755 (executable)
@@ -2,7 +2,7 @@
 use strict;
 require Exporter;
 use CGI;
-use C4::Search;
+use C4::Biblio;
 use C4::Auth;
 use C4::Interface::CGI::Output;
 use HTML::Template;
@@ -33,7 +33,7 @@ foreach my $biblionumber (@bibs) {
        $template->param(biblionumber => $biblionumber);
 
        my $dat                                   = &bibdata($biblionumber);
-       my ($authorcount, $addauthor)             = &addauthor($biblionumber);
+       my ($authorcount, $addauthor)             = &getaddauthor($biblionumber);
        my @items                                 = &ItemInfo(undef, $biblionumber, 'opac');
 
        $dat->{'additional'}=$addauthor->[0]->{'author'};
index ccafafe..26fedc6 100755 (executable)
@@ -2,7 +2,6 @@
 use strict;
 require Exporter;
 use CGI;
-use C4::Search;
 use C4::Auth;
 use C4::Bull; #uses getsubscriptionfrom biblionumber
 use C4::Interface::CGI::Output;
@@ -28,7 +27,7 @@ $template->param(biblionumber => $biblionumber);
 # change back when ive fixed request.pl
 my @items                                 = &ItemInfo(undef, $biblionumber, 'opac');
 my $dat                                   = &bibdata($biblionumber);
-my ($authorcount, $addauthor)             = &addauthor($biblionumber);
+my ($authorcount, $addauthor)             = &getaddauthor($biblionumber);
 my ($webbiblioitemcount, @webbiblioitems) = &getwebbiblioitems($biblionumber);
 my ($websitecount, @websites)             = &getwebsites($biblionumber);
 my $subscriptionsnumber = getsubscriptionfrombiblionumber($biblionumber);
index d9934a8..60eb240 100755 (executable)
@@ -24,7 +24,7 @@ require Exporter;
 use C4::Context;
 use C4::Output;  # contains gettemplate
 use CGI;
-use C4::Search;
+use C4::Biblio;
 use C4::Auth;
 use C4::Interface::CGI::Output;
 use C4::Date;
@@ -45,7 +45,7 @@ foreach my $itm (@items) {
 
 
 my $dat=bibdata($biblionumber);
-my ($authorcount, $addauthor)= &addauthor($biblionumber);
+my ($authorcount, $addauthor)= &getaddauthor($biblionumber);
 my ($webbiblioitemcount, @webbiblioitems) = &getwebbiblioitems($biblionumber);
 my ($websitecount, @websites)             = &getwebsites($biblionumber);
 
index 1604585..895b4c3 100755 (executable)
@@ -7,7 +7,7 @@ use C4::Auth;
 use C4::Koha;
 use C4::Circulation::Circ2;
 use C4::Date;
-use C4::Search;
+use C4::Members;
 use HTML::Template;
 use C4::Interface::CGI::Output;
 
index e72fa7b..888c88d 100755 (executable)
@@ -5,7 +5,7 @@ use strict;
 require Exporter;
 use CGI;
 
-use C4::Search;
+use C4::Biblio;
 use C4::Auth;         # checkauth, getborrowernumber.
 use C4::Koha;
 use C4::Circulation::Circ2;
index f2b0733..bf54a86 100755 (executable)
@@ -3,6 +3,7 @@ use strict;
 require Exporter;
 use CGI;
 use C4::Search;
+use C4::Biblio;
 use C4::Auth;
 use C4::Interface::CGI::Output;
 use HTML::Template;
index c0bc03c..90835a9 100755 (executable)
@@ -6,7 +6,6 @@ use Mail::Sendmail;
 use MIME::QuotedPrint;
 use MIME::Base64;
 use C4::Context;
-use C4::Search;
 use C4::Biblio;
 use C4::Auth;
 use C4::Interface::CGI::Output;
@@ -52,7 +51,7 @@ if ($email_add) {
                $template2->param(biblionumber => $biblionumber);
 
                my $dat = &bibdata($biblionumber);
-               my ($authorcount, $addauthor) = &addauthor($biblionumber);
+               my ($authorcount, $addauthor) = &getaddauthor($biblionumber);
                my @items                     = &ItemInfo(undef, $biblionumber, 'opac');
 
                $dat->{'additional'}=$addauthor->[0]->{'author'};
index e03ab9e..0d417b6 100755 (executable)
@@ -7,7 +7,7 @@ use C4::Auth;
 use C4::Koha;
 use C4::Circulation::Circ2;
 use C4::Reserves2;
-use C4::Search;
+use C4::Members;
 use C4::Interface::CGI::Output;
 use HTML::Template;
 use C4::Date;
diff --git a/pay.pl b/pay.pl
index 80ad227..9804ca9 100755 (executable)
--- a/pay.pl
+++ b/pay.pl
@@ -30,7 +30,7 @@ use C4::Context;
 use C4::Auth;
 use C4::Output;
 use CGI;
-use C4::Search;
+use C4::Members;
 use C4::Accounts2;
 use C4::Stats;
 use HTML::Template;
index ece3e2a..c6ea752 100755 (executable)
 
 use strict;
 #use DBI;
-use C4::Search;
+use C4::Biblio;
 use CGI;
 use C4::Output;
 use C4::Reserves2;
+use C4::Members;
 
 my $input = new CGI;
 #print $input->header;
 
 my @bibitems=$input->param('biblioitem');
 my @reqbib=$input->param('reqbib');
-my $biblio=$input->param('biblio');
+my $biblionumber=$input->param('biblionumber');
 my $borrower=$input->param('member');
 my $notes=$input->param('notes');
 my $branch=$input->param('pickup');
@@ -42,36 +43,33 @@ my $type=$input->param('type');
 my $title=$input->param('title');
 my $bornum=borrdata($borrower,'');
 if ($type eq 'str8' && $bornum ne ''){
-    my $count=@bibitems;
-    @bibitems=sort @bibitems;
-    my $i2=1;
-    my @realbi;
-    $realbi[0]=$bibitems[0];
-for (my $i=1;$i<$count;$i++){
-    my $i3=$i2-1;
-    if ($realbi[$i3] ne $bibitems[$i]){
-       $realbi[$i2]=$bibitems[$i];
-       $i2++;
-    }
-}
-
-my $env;
-
-my $const;
-if ($input->param('request') eq 'any'){
-  $const='a';
-  CreateReserve(\$env,$branch,$bornum->{'borrowernumber'},$biblio,$const,\@realbi,$rank[0],$notes,$title);
-} elsif ($reqbib[0] ne ''){
-  $const='o';
-  CreateReserve(\$env,$branch,$bornum->{'borrowernumber'},$biblio,$const,\@reqbib,$rank[0],$notes,$title);
-} else {
-  CreateReserve(\$env,$branch,$bornum->{'borrowernumber'},$biblio,'a',\@realbi,$rank[0],$notes,$title);
-}
-#print @realbi;
-
-print $input->redirect("request.pl?bib=$biblio");
+       my $count=@bibitems;
+       @bibitems=sort @bibitems;
+       my $i2=1;
+       my @realbi;
+       $realbi[0]=$bibitems[0];
+       for (my $i=1;$i<$count;$i++) {
+               my $i3=$i2-1;
+               if ($realbi[$i3] ne $bibitems[$i]) {
+                       $realbi[$i2]=$bibitems[$i];
+                       $i2++;
+               }
+       }
+       my $env;
+       my $const;
+       if ($input->param('request') eq 'any'){
+       $const='a';
+       CreateReserve(\$env,$branch,$bornum->{'borrowernumber'},$biblionumber,$const,\@realbi,$rank[0],$notes,$title);
+       } elsif ($reqbib[0] ne ''){
+       $const='o';
+       CreateReserve(\$env,$branch,$bornum->{'borrowernumber'},$biblionumber,$const,\@reqbib,$rank[0],$notes,$title);
+       } else {
+       CreateReserve(\$env,$branch,$bornum->{'borrowernumber'},$biblionumber,'a',\@realbi,$rank[0],$notes,$title);
+       }
+       
+       print $input->redirect("request.pl?biblionumber=$biblionumber");
 } elsif ($bornum eq ''){
-  print $input->header();
-  print "Invalid card number please try again";
-  print $input->Dump;
+       print $input->header();
+       print "Invalid card number please try again";
+       print $input->Dump;
 }
index 3c1d3e5..f7925b5 100755 (executable)
@@ -27,7 +27,7 @@ use C4::Auth;
 use C4::Output;
 use C4::Interface::CGI::Output;
 use CGI;
-use C4::Search;
+use C4::Members;
 use HTML::Template;
 use C4::Date;
 my $input=new CGI;
index f575402..7dd925a 100755 (executable)
@@ -24,7 +24,6 @@
 # Suite 330, Boston, MA  02111-1307 USA
 
 use strict;
-use C4::Search;
 use C4::Output;
 use C4::Interface::CGI::Output;
 use C4::Auth;
@@ -40,11 +39,11 @@ use C4::Date;
 my $input = new CGI;
 
 # get biblio information....
-my $bib = $input->param('bib');
-my $dat = bibdata($bib);
+my $biblionumber = $input->param('biblionumber');
+my $dat = bibdata($biblionumber);
 
 # get existing reserves .....
-my ($count,$reserves) = FindReserves($bib);
+my ($count,$reserves) = FindReserves($biblionumber);
 my $totalcount = $count;
 foreach my $res (@$reserves) {
     if ($res->{'found'} eq 'W') {
@@ -72,7 +71,7 @@ my $date=format_date("$year-$mon-$mday");
 
 
 # get biblioitem information and build rows for form
-my ($count2,@data) = bibitems($bib);
+my ($count2,@data) = bibitems($biblionumber);
 
 my @bibitemloop;
 foreach my $dat (sort {$b->{'dateaccessioned'} cmp $a->{'dateaccessioned'}} @data) {
@@ -164,21 +163,18 @@ foreach my $res (sort {$a->{'found'} cmp $b->{'found'}} @$reserves){
 my @branches;
 my @select_branch;
 my %select_branches;
-my ($count2,@branches)=branches();
-for (my $i=0;$i<$count2;$i++){
-       push @select_branch, $branches[$i]->{'branchcode'};#
-       $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
+my ($count2,@branches)=getbranches();
+my @branchloop;
+foreach my $thisbranch (sort keys %$branches) {
+       my %row =(value => $thisbranch,
+                               branchname => $branches->{$thisbranch}->{'branchname'},
+                       );
+       push @branchloop, \%row;
 }
-my $CGIbranch=CGI::scrolling_list( -name     => 'pickup',
-                       -values   => \@select_branch,
-                       -labels   => \%select_branches,
-                       -size     => 1,
-                       -multiple => 0 );
 
 #get the time for the form name...
 my $time = time();
 
-#setup colours
 my ($template, $borrowernumber, $cookie)
     = get_template_and_user({template_name => "request.tmpl",
                                                        query => $input,
@@ -187,12 +183,12 @@ my ($template, $borrowernumber, $cookie)
                             flagsrequired => {parameters => 1},
                          });
 $template->param(      optionloop =>\@optionloop,
-                                                               CGIbranch => $CGIbranch,
+                                                               branchloop => \@branchloop,
                                                                reserveloop => \@reserveloop,
                                                                'time' => $time,
                                                                bibitemloop => \@bibitemloop,
                                                                date => $date,
-                                                               bib => $bib,
+                                                               biblionumber => $biblionumber,
                                                                title =>$dat->{title});
 # printout the page
 print $input->header(