X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FBookseller.pm;h=e19378ea48f1ad398b36b1c738ed19a76f6d7128;hb=8cd4d221d880da21a1d2c5d83fac792934f1c87e;hp=b30c1bfbb6ae275d7b2c68faa9edff5873989a46;hpb=06d8e7d4cf2622505fd062ea356d3f8a050abd37;p=koha.git diff --git a/C4/Bookseller.pm b/C4/Bookseller.pm index b30c1bfbb6..e19378ea48 100644 --- a/C4/Bookseller.pm +++ b/C4/Bookseller.pm @@ -17,22 +17,22 @@ package C4::Bookseller; # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, # Suite 330, Boston, MA 02111-1307 USA -# $Id$ - use strict; use vars qw($VERSION @ISA @EXPORT); -# set the version for version checking -$VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); }; - -@ISA = qw(Exporter); -@EXPORT = qw( - &GetBookSeller &GetBooksellersWithLateOrders - &ModBookseller - &DelBookseller - &AddBookseller -); +BEGIN { + # set the version for version checking + $VERSION = 3.01; + require Exporter; + @ISA = qw(Exporter); + @EXPORT = qw( + &GetBookSeller &GetBooksellersWithLateOrders &GetBookSellerFromId + &ModBookseller + &DelBookseller + &AddBookseller + ); +} =head1 NAME @@ -51,10 +51,6 @@ a bookseller. =head1 FUNCTIONS -=cut - -#-------------------------------------------------------------------# - =head2 GetBookSeller @results = &GetBookSeller($searchstring); @@ -67,23 +63,22 @@ aqbooksellers table in the Koha database. =cut -sub GetBookSeller { +# FIXME: This function is badly named. It should be something like +# SearchBookSellersByName. It is NOT a singular return value. + +sub GetBookSeller($) { my ($searchstring) = @_; my $dbh = C4::Context->dbh; - my $query = " - SELECT * - FROM aqbooksellers - WHERE name LIKE ? OR id = ? - "; + my $query = "SELECT * FROM aqbooksellers WHERE name LIKE ?"; my $sth =$dbh->prepare($query); - $sth->execute("$searchstring%", $searchstring ); + $sth->execute( "$searchstring%" ); my @results; # count how many baskets this bookseller has. # if it has none, the bookseller can be deleted - my $sth2 = $dbh->prepare("select count(*) from aqbasket where booksellerid=?"); + my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?"); while ( my $data = $sth->fetchrow_hashref ) { $sth2->execute($data->{id}); - ($data->{basketcount}) = $sth2->fetchrow(); + $data->{basketcount} = $sth2->fetchrow(); push( @results, $data ); } $sth->finish; @@ -91,6 +86,20 @@ sub GetBookSeller { } +sub GetBookSellerFromId($) { + my ($id) = shift or return undef; + my $dbh = C4::Context->dbh(); + my $query = "SELECT * FROM aqbooksellers WHERE id = ?"; + my $sth =$dbh->prepare($query); + $sth->execute( $id ); + if (my $data = $sth->fetchrow_hashref()){ + my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?"); + $sth2->execute($id); + $data->{basketcount}=$sth2->fetchrow(); + return ($data); + } + return 0; +} #-----------------------------------------------------------------# =head2 GetBooksellersWithLateOrders @@ -102,7 +111,7 @@ Searches for suppliers with late orders. =cut sub GetBooksellersWithLateOrders { - my ($delay,$branch) = @_; + my ($delay,$branch) = @_; # FIXME: Branch argument unused. my $dbh = C4::Context->dbh; # FIXME NOT quite sure that this operation is valid for DBMs different from Mysql, HOPING so @@ -187,6 +196,7 @@ sub AddBookseller { ); # return the id of this new supplier + # FIXME: no protection against simultaneous addition: max(id) might be wrong! $query = " SELECT max(id) FROM aqbooksellers @@ -260,7 +270,6 @@ sub DelBookseller { my $sth=$dbh->prepare("DELETE FROM aqbooksellers WHERE id=?"); $sth->execute($id); } -END { } # module clean-up code here (global destructor) 1;