[Koha-cvs] CVS: koha/C4 Accounts2.pm,1.24,1.25 Accounts.pm,1.15,1.16 Biblio.pm,1.130,1.131 Koha.pm,1.23,1.24 Members.pm,1.10,1.11 Reserves2.pm,1.39,1.40 Search.pm,1.107,1.108

Paul POULAIN tipaul at users.sourceforge.net
Thu Sep 22 12:01:48 CEST 2005


Update of /cvsroot/koha/koha/C4
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6231/C4

Modified Files:
	Accounts2.pm Accounts.pm Biblio.pm Koha.pm Members.pm 
	Reserves2.pm Search.pm 
Log Message:
see mail on koha-devel : code cleaning on Search.pm + normalizing API + use of biblionumber everywhere (instead of bn, biblio, ...)

Index: Accounts2.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Accounts2.pm,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -r1.24 -r1.25
*** Accounts2.pm	18 Aug 2005 21:15:20 -0000	1.24
--- Accounts2.pm	22 Sep 2005 10:01:45 -0000	1.25
***************
*** 24,28 ****
  use C4::Context;
  use C4::Stats;
! use C4::Search;
  use C4::Circulation::Circ2;
  use vars qw($VERSION @ISA @EXPORT);
--- 24,28 ----
  use C4::Context;
  use C4::Stats;
! use C4::Members;
  use C4::Circulation::Circ2;
  use vars qw($VERSION @ISA @EXPORT);
***************
*** 254,258 ****
    my ($borrnum,$itemnum)=@_;
    my $dbh = C4::Context->dbh;
!   my $borrower=borrdata('',$borrnum); #from C4::Search;
    my $sth=$dbh->prepare("Update issues set returndate=now() where
    borrowernumber=? and itemnumber=? and returndate is null");
--- 254,258 ----
    my ($borrnum,$itemnum)=@_;
    my $dbh = C4::Context->dbh;
!   my $borrower=borrdata('',$borrnum);
    my $sth=$dbh->prepare("Update issues set returndate=now() where
    borrowernumber=? and itemnumber=? and returndate is null");

Index: Accounts.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Accounts.pm,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** Accounts.pm	14 May 2005 22:20:17 -0000	1.15
--- Accounts.pm	22 Sep 2005 10:01:45 -0000	1.16
***************
*** 31,35 ****
  use C4::Context;
  use C4::Format;
! use C4::Search;
  use C4::Stats;
  #use C4::InterfaceCDK;
--- 31,35 ----
  use C4::Context;
  use C4::Format;
! use C4::Biblio;
  use C4::Stats;
  #use C4::InterfaceCDK;
***************
*** 138,142 ****
      my $line=$i+1;
      my $amount=0+$data->{'amountoutstanding'};
!     my $itemdata = itemnodata($env,$dbh,$data->{'itemnumber'});
      $line= $data->{'accountno'}." ".$data->{'date'}." ".$data->{'accounttype'}." ";
      my $title = $itemdata->{'title'};
--- 138,142 ----
      my $line=$i+1;
      my $amount=0+$data->{'amountoutstanding'};
!     my $itemdata = getbibliofromitemnumber($env,$dbh,$data->{'itemnumber'});
      $line= $data->{'accountno'}." ".$data->{'date'}." ".$data->{'accounttype'}." ";
      my $title = $itemdata->{'title'};

Index: Biblio.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Biblio.pm,v
retrieving revision 1.130
retrieving revision 1.131
diff -C2 -r1.130 -r1.131
*** Biblio.pm	2 Sep 2005 14:34:14 -0000	1.130
--- Biblio.pm	22 Sep 2005 10:01:45 -0000	1.131
***************
*** 22,25 ****
--- 22,26 ----
  use C4::Context;
  use C4::Database;
+ use C4::Date;
  use MARC::Record;
  use MARC::File::USMARC;
***************
*** 38,48 ****
  #
  @EXPORT = qw(
!   &itemcount &newbiblio &newbiblioitem
!   &newsubject &newsubtitle
!   &modbiblio &checkitems
!   &newitems &modbibitem
    &modsubtitle &modsubject &modaddauthor &moditem
    &delitem &deletebiblioitem &delbiblio
!   &getbiblio
    &getbiblioitembybiblionumber
    &getbiblioitem &getitemsbybiblioitem
--- 39,54 ----
  #
  @EXPORT = qw(
!   &newbiblio &newbiblioitem
!   &newsubject &newsubtitle &newitems 
!   
!   &modbiblio &checkitems &modbibitem
    &modsubtitle &modsubject &modaddauthor &moditem
+   
    &delitem &deletebiblioitem &delbiblio
!   
!   &getbiblio &bibdata &bibitems &bibitemdata 
!   &barcodes &ItemInfo &itemdata &itemissues &itemcount 
!   &getsubject &getaddauthor &getsubtitle
!   &getwebbiblioitems &getwebsites
    &getbiblioitembybiblionumber
    &getbiblioitem &getitemsbybiblioitem
***************
*** 144,148 ****
  	my $res = system("cd $cgidir/zebra;/usr/local/bin/zebraidx update biblios");
  	unlink($filename);
- 	warn "$biblionumber : $res";
  }
  
--- 150,153 ----
***************
*** 396,400 ****
  	}
  	
- 	warn "RECORD : ".$record->as_formatted;
  	return $record;
  }
--- 401,404 ----
***************
*** 414,449 ****
  
      # this function builds partial MARC::Record from the old koha-DB fields
!     my ( $dbh, $biblionumber, $itemnumber ) = @_;
  
      #    my $dbh=&C4Connect;
!     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},'' );
!             }
!         }
!     }
      return $record;
  }
--- 418,433 ----
  
      # this function builds partial MARC::Record from the old koha-DB fields
!     my ( $dbh, $item ) = @_;
  
      #    my $dbh=&C4Connect;
!     my $sth = $dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?");
      my $record = MARC::Record->new();
  
! 	foreach( keys %$item ) {
! 		if ( $item->{$_} ) {
! 			&MARCkoha2marcOnefield( $sth, $record, "items." . $_,
! 				$item->{$_},'' );
! 		}
! 	}
      return $record;
  }
***************
*** 1091,1095 ****
      my $query;
  
!     my $sth = $dbh->prepare("update biblioitems set	itemtype=?,			url=?,				isbn=?,	issn=?,
  										publishercode=?,	publicationyear=?,	classification=?,	dewey=?,
  										subclass=?,			illus=?,			pages=?,			volumeddesc=?,
--- 1075,1080 ----
      my $query;
  
!     my $sth = $dbh->prepare("update biblioitems set number=?,volume=?,			volumedate=?,		lccn=?,
! 										itemtype=?,			url=?,				isbn=?,				issn=?,
  										publishercode=?,	publicationyear=?,	classification=?,	dewey=?,
  										subclass=?,			illus=?,			pages=?,			volumeddesc=?,
***************
*** 1097,1101 ****
  										marcxml=?
  							where biblioitemnumber=?");
! 	$sth->execute(	$biblioitem->{itemtype},		$biblioitem->{url},		$biblioitem->{isbn},	$biblioitem->{issn},
      				$biblioitem->{publishercode},	$biblioitem->{publicationyear}, $biblioitem->{classification},	$biblioitem->{dewey},
      				$biblioitem->{subclass},		$biblioitem->{illus},		$biblioitem->{pages},	$biblioitem->{volumeddesc},
--- 1082,1087 ----
  										marcxml=?
  							where biblioitemnumber=?");
! 	$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},
***************
*** 1204,1208 ****
  # 	warn "OLDNEWITEMS";
  	
! 	$dbh->do('lock tables items WRITE, biblio WRITE,biblioitems WRITE');
      my $sth = $dbh->prepare("Select max(itemnumber) from items");
      my $data;
--- 1190,1194 ----
  # 	warn "OLDNEWITEMS";
  	
! 	$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;
***************
*** 1238,1242 ****
  			$itemnumber,				$item->{'biblionumber'},
  			$item->{'multivolumepart'},
! 			$item->{'biblioitemnumber'},$barcode,
  			$item->{'booksellerid'},	$item->{'dateaccessioned'},
  			$item->{'homebranch'},		$item->{'holdingbranch'},
--- 1224,1228 ----
  			$itemnumber,				$item->{'biblionumber'},
  			$item->{'multivolumepart'},
! 			$item->{'biblioitemnumber'},$item->{barcode},
  			$item->{'booksellerid'},	$item->{'dateaccessioned'},
  			$item->{'homebranch'},		$item->{'holdingbranch'},
***************
*** 1271,1275 ****
  			$itemnumber,				$item->{'biblionumber'},
  			$item->{'multivolumepart'},
! 			$item->{'biblioitemnumber'},$barcode,
  			$item->{'booksellerid'},
  			$item->{'homebranch'},		$item->{'holdingbranch'},
--- 1257,1261 ----
  			$itemnumber,				$item->{'biblionumber'},
  			$item->{'multivolumepart'},
! 			$item->{'biblioitemnumber'},$item->{barcode},
  			$item->{'booksellerid'},
  			$item->{'homebranch'},		$item->{'holdingbranch'},
***************
*** 1294,1298 ****
      }
  	my ($rawmarc,$frameworkcode) = $sth->fetchrow;
! 	warn "ERROR IN OLDnewitem, 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)
--- 1280,1284 ----
      }
  	my ($rawmarc,$frameworkcode) = $sth->fetchrow;
! 	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)
***************
*** 1617,1621 ****
  	my $dbh  = C4::Context->dbh;
  	my $biblionumber=REALmodbiblio($dbh,$biblio);
- 	warn "in MODBIBLIO";
  	my $record = MARCkoha2marcBiblio($dbh,$biblionumber,$biblionumber);
  	# finds new (MARC bibid
--- 1603,1606 ----
***************
*** 1763,1771 ****
      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} );
      }
      return ($errors);
--- 1748,1759 ----
      my $error;
      foreach my $barcode (@barcodes) {
! 		# 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);
***************
*** 1903,1906 ****
--- 1891,1962 ----
  }    # 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, at results) = getbiblioitem($biblioitemnumber);
  
***************
*** 1997,2000 ****
--- 2053,2578 ----
  }    # 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 {
  
***************
*** 2299,2302 ****
--- 2877,2883 ----
  # $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.

Index: Koha.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Koha.pm,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -r1.23 -r1.24
*** Koha.pm	2 Sep 2005 14:30:28 -0000	1.23
--- Koha.pm	22 Sep 2005 10:01:45 -0000	1.24
***************
*** 51,60 ****
  
  @ISA = qw(Exporter);
! @EXPORT = qw(&slashifyDate
  			&fixEthnicity
! 			&borrowercategories
  			&ethnicitycategories
  			&subfield_is_koha_internal_p
! 			&getbranches &getbranch
  			&getprinters &getprinter
  			&getitemtypes &getitemtypeinfo
--- 51,60 ----
  
  @ISA = qw(Exporter);
! @EXPORT = qw(
  			&fixEthnicity
! 			&borrowercategories &getborrowercategory
  			&ethnicitycategories
  			&subfield_is_koha_internal_p
! 			&getbranches &getbranch &getbranchname
  			&getprinters &getprinter
  			&getitemtypes &getitemtypeinfo
***************
*** 68,86 ****
  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]")
! }
  
  =head2 fixEthnicity
--- 68,72 ----
  my $DEBUG = 0;
  
! # removed slashifyDate => useless
  
  =head2 fixEthnicity
***************
*** 132,135 ****
--- 118,142 ----
  }
  
+ =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
  
***************
*** 453,456 ****
--- 460,464 ----
      return (\%printers);
  }
+ 
  sub getbranch ($$) {
      my($query, $branches) = @_; # get branch for this query from branches
***************
*** 461,464 ****
--- 469,492 ----
  }
  
+ =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

Index: Members.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Members.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** Members.pm	5 Sep 2005 19:27:21 -0000	1.10
--- Members.pm	22 Sep 2005 10:01:45 -0000	1.11
***************
*** 50,57 ****
  
  @EXPORT = qw(
! 	&getmember &fixup_cardnumber &findguarantees &findguarantor &NewBorrowerNumber &modmember &newmember &changepassword
      );
  
! 	
  =item getmember
  
--- 50,131 ----
  
  @EXPORT = qw(
! 	&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
  
***************
*** 95,98 ****
--- 169,253 ----
  }
  
+ =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 {
***************
*** 328,330 ****
--- 483,608 ----
  }
  
+ =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: Reserves2.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Reserves2.pm,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -r1.39 -r1.40
*** Reserves2.pm	6 Sep 2005 05:34:52 -0000	1.39
--- Reserves2.pm	22 Sep 2005 10:01:46 -0000	1.40
***************
*** 27,34 ****
  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 vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
--- 27,31 ----
  use DBI;
  use C4::Context;
! use C4::Biblio;
  
  use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
***************
*** 158,162 ****
  			$csth->finish;
  			# Look up the book we just found.
! 			my $bdata = C4::Search::bibitemdata($bibitemno);
  			# Add the results of this latest search to the current
  			# results.
--- 155,159 ----
  			$csth->finish;
  			# Look up the book we just found.
! 			my $bdata = bibitemdata($bibitemno);
  			# Add the results of this latest search to the current
  			# results.

Index: Search.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Search.pm,v
retrieving revision 1.107
retrieving revision 1.108
diff -C2 -r1.107 -r1.108
*** Search.pm	5 Sep 2005 19:27:21 -0000	1.107
--- Search.pm	22 Sep 2005 10:01:46 -0000	1.108
***************
*** 59,68 ****
  @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);
  # make all your functions, whether exported or not;
  
[...1351 lines suppressed...]
- 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)
  
--- 992,995 ----





More information about the Koha-cvs mailing list