1 package C4::BookShelves; #asummes C4/BookShelves
6 #requires DBI.pm to be installed
9 # Copyright 2000-2002 Katipo Communications
11 # This file is part of Koha.
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA 02111-1307 USA
30 use C4::Circulation::Circ2;
31 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
33 # set the version for version checking
37 @EXPORT = qw(&GetShelfList &GetShelfContents &AddToShelf &RemoveFromShelf &AddShelf &RemoveShelf);
38 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
40 # your exported package globals go here,
41 # as well as any optionally exported functions
43 @EXPORT_OK = qw($Var1 %Hashit);
46 # non-exported package globals go here
47 use vars qw(@more $stuff);
49 # initalize package globals, first exported ones
54 # then the others (which are still accessible as $Some::Module::stuff)
58 # all file-scoped lexicals must be created before
59 # the functions below that use them.
61 # file-private lexicals go here
65 # here's a file-private function as a closure,
66 # callable as &$priv_func; it cannot be prototyped.
71 # make all your functions, whether exported or not;
76 my $sth=$dbh->prepare("select shelfnumber,shelfname from bookshelf");
79 while (my ($shelfnumber, $shelfname) = $sth->fetchrow) {
80 my $sti=$dbh->prepare("select count(*) from shelfcontents where shelfnumber=$shelfnumber");
82 my ($count) = $sti->fetchrow;
83 $shelflist{$shelfnumber}->{'shelfname'}=$shelfname;
84 $shelflist{$shelfnumber}->{'count'}=$count;
90 sub GetShelfContents {
91 my ($env, $shelfnumber) = @_;
93 my $sth=$dbh->prepare("select itemnumber from shelfcontents where shelfnumber=$shelfnumber order by itemnumber");
95 while (my ($itemnumber) = $sth->fetchrow) {
96 my ($item) = getiteminformation($env, $itemnumber, 0);
97 push (@itemlist, $item);
103 my ($env, $itemnumber, $shelfnumber) = @_;
104 my $sth=$dbh->prepare("select * from shelfcontents where shelfnumber=$shelfnumber and itemnumber=$itemnumber");
109 $sth=$dbh->prepare("insert into shelfcontents (shelfnumber, itemnumber, flags) values ($shelfnumber, $itemnumber, 0)");
114 sub RemoveFromShelf {
115 my ($env, $itemnumber, $shelfnumber) = @_;
116 my $sth=$dbh->prepare("delete from shelfcontents where shelfnumber=$shelfnumber and itemnumber=$itemnumber");
121 my ($env, $shelfname) = @_;
122 my $q_shelfname=$dbh->quote($shelfname);
123 my $sth=$dbh->prepare("select * from bookshelf where shelfname=$q_shelfname");
126 return(1, "Shelf \"$shelfname\" already exists");
128 $sth=$dbh->prepare("insert into bookshelf (shelfname) values ($q_shelfname)");
135 my ($env, $shelfnumber) = @_;
136 my $sth=$dbh->prepare("select count(*) from shelfcontents where shelfnumber=$shelfnumber");
138 my ($count)=$sth->fetchrow;
140 return (1, "Shelf has $count items on it. Please remove all items before deleting this shelf.");
142 $sth=$dbh->prepare("delete from bookshelf where shelfnumber=$shelfnumber");
149 END { } # module clean-up code here (global destructor)
154 # Revision 1.4 2002/08/14 18:12:51 tonnesen
155 # Added copyright statement to all .pl and .pm files
157 # Revision 1.3 2002/07/02 17:48:06 tonnesen
158 # Merged in updates from rel-1-2
160 # Revision 1.2.2.1 2002/06/26 20:46:48 tonnesen
161 # Inserting some changes I made locally a while ago.