From 1159649fe8ca6d6e6aa73c34e8800bd960179856 Mon Sep 17 00:00:00 2001 From: tonnesen Date: Wed, 7 Feb 2001 20:27:16 +0000 Subject: [PATCH] Start of code to implement virtual bookshelves in Koha. --- C4/BookShelves.pm | 145 ++++++++++++++++++++++++++++++++++++++++++++++ shelves.pl | 124 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100755 C4/BookShelves.pm create mode 100755 shelves.pl diff --git a/C4/BookShelves.pm b/C4/BookShelves.pm new file mode 100755 index 0000000000..b192e7e776 --- /dev/null +++ b/C4/BookShelves.pm @@ -0,0 +1,145 @@ +package C4::BookShelves; #asummes C4/BookShelves + +# +# $Header$ +# +#requires DBI.pm to be installed + +use strict; +require Exporter; +use DBI; +use C4::Database; +use C4::Circulation::Circ2; +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); + +# set the version for version checking +$VERSION = 0.01; + +@ISA = qw(Exporter); +@EXPORT = qw(&GetShelfList &GetShelfContents &AddToShelf &RemoveFromShelf &AddShelf &RemoveShelf); + +sub AddShelf { +} + +sub RemoveShelf { +} +%EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], + +# your exported package globals go here, +# as well as any optionally exported functions + +@EXPORT_OK = qw($Var1 %Hashit); + + +# non-exported package globals go here +use vars qw(@more $stuff); + +# initalize package globals, first exported ones + +my $Var1 = ''; +my %Hashit = (); + +# then the others (which are still accessible as $Some::Module::stuff) +my $stuff = ''; +my @more = (); + +# all file-scoped lexicals must be created before +# the functions below that use them. + +# file-private lexicals go here +my $priv_var = ''; +my %secret_hash = (); + +# here's a file-private function as a closure, +# callable as &$priv_func; it cannot be prototyped. +my $priv_func = sub { + # stuff goes here. +}; + +# make all your functions, whether exported or not; + +my $dbh=C4Connect(); + +sub GetShelfList { + my $sth=$dbh->prepare("select shelfnumber,shelfname from bookshelf"); + $sth->execute; + my %shelflist; + while (my ($shelfnumber, $shelfname) = $sth->fetchrow) { + my $sti=$dbh->prepare("select count(*) from shelfcontents where shelfnumber=$shelfnumber"); + $sti->execute; + my ($count) = $sti->fetchrow; + $shelflist{$shelfnumber}->{'shelfname'}=$shelfname; + $shelflist{$shelfnumber}->{'count'}=$count; + } + return(\%shelflist); +} + + +sub GetShelfContents { + my ($env, $shelfnumber) = @_; + my @itemlist; + my $sth=$dbh->prepare("select itemnumber from shelfcontents where shelfnumber=$shelfnumber order by itemnumber"); + $sth->execute; + while (my ($itemnumber) = $sth->fetchrow) { + my ($item) = getiteminformation($env, $itemnumber, 0); + push (@itemlist, $item); + } + return (\@itemlist); +} + +sub AddToShelf { + my ($env, $itemnumber, $shelfnumber) = @_; + my $sth=$dbh->prepare("select * from shelfcontents where shelfnumber=$shelfnumber and itemnumber=$itemnumber"); + $sth->execute; + if ($sth->rows) { +# already on shelf + } else { + $sth=$dbh->prepare("insert into shelfcontents (shelfnumber, itemnumber, flags) values ($shelfnumber, $itemnumber, 0)"); + $sth->execute; + } +} + +sub RemoveFromShelf { + my ($env, $itemnumber, $shelfnumber) = @_; + my $sth=$dbh->prepare("delete from shelfcontents where shelfnumber=$shelfnumber and itemnumber=$itemnumber"); + $sth->execute; +} + +sub AddShelf { + my ($env, $shelfname) = @_; + my $q_shelfname=$dbh->quote($shelfname); + my $sth=$dbh->prepare("select * from bookshelf where shelfname=$q_shelfname"); + $sth->execute; + if ($sth->rows) { + return(0, "Shelf \"$shelfname\" already exists"); + } else { + $sth=$dbh->prepare("insert into bookshelf (shelfname) values ($q_shelfname)"); + $sth->execute; + return (1, "Done"); + } +} + +sub RemoveShelf { + my ($env, $shelfnumber) = @_; + my $sth=$dbh->prepare("select count(*) from shelfcontents where shelfnumber=$shelfnumber"); + $sth->execute; + my ($count)=$sth->fetchrow; + if ($count) { + return (0, "Shelf has $count items on it"); + } else { + $sth=$dbh->prepare("delete from bookshelf where shelfnumber=$shelfnumber"); + $sth->execute; + return (1, "Done"); + } +} + + +END { } # module clean-up code here (global destructor) + + +# +# $Log$ +# Revision 1.1 2001/02/07 20:27:17 tonnesen +# Start of code to implement virtual bookshelves in Koha. +# +# diff --git a/shelves.pl b/shelves.pl new file mode 100755 index 0000000000..68b6399e94 --- /dev/null +++ b/shelves.pl @@ -0,0 +1,124 @@ +#!/usr/bin/perl +#script to provide bookshelf management +# +# $Header$ +# + +use strict; +use C4::Search; +use CGI; +use C4::Output; +use C4::BookShelves; +use C4::Circulation::Circ2; + +my $env; +my $query = new CGI; +print $query->header; +my $headerbackgroundcolor='#663266'; +my $circbackgroundcolor='#555555'; +my $circbackgroundcolor='#550000'; +my $linecolor1='#bbbbbb'; +my $linecolor2='#dddddd'; + +print startpage(); +print startmenu('catalogue'); + + + + +my ($shelflist) = GetShelfList(); + +if ($query->param('modifyshelfcontents')) { + my $shelfnumber=$query->param('shelfnumber'); + my $barcode=$query->param('addbarcode'); + my ($item) = getiteminformation($env, 0, $barcode); + AddToShelf($env, $item->{'itemnumber'}, $shelfnumber); + foreach ($query->param) { + if (/REM-(\d*)/) { + my $itemnumber=$1; + RemoveFromShelf($env, $itemnumber, $shelfnumber); + } + } +} + +SWITCH: { + if ($query->param('viewshelf')) { viewshelf($query->param('viewshelf')); last SWITCH;} + print << "EOF"; +
+ + +EOF + my $color=''; + foreach (sort keys %$shelflist) { + ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1); + print "\n"; + } + print "
+ + +
+ Shelf List +
+
$shelflist->{$_}->{'shelfname'} ($shelflist->{$_}->{'count'} books)
\n"; +} + + +sub viewshelf { + my $shelfnumber=shift; + my ($itemlist) = GetShelfContents($env, $shelfnumber); + my $item=''; + print << "EOF"; +
+
+ Shelf List

+ + +EOF + my $color=''; + foreach $item (sort {$a->{'barcode'} cmp $b->{'barcode'}} @$itemlist) { + ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1); + print << "EOF"; + + + + + + + + + +EOF + } + print << "EOF"; +
+ + +
Add a book by barcode:
+
+ + +
+ Contents of $shelflist->{$shelfnumber}->{'shelfname'} shelf +
+
{'itemnumber'}>$item->{'barcode'}$item->{'title'}$item->{'author'}
+
+ + + + +

+EOF +} + + + +# +# $Log$ +# Revision 1.1 2001/02/07 20:27:16 tonnesen +# Start of code to implement virtual bookshelves in Koha. +# +# +# + + + -- 2.39.5