fixes for printing a biblio
[koha.git] / opac / opac-shelves.pl
1 #!/usr/bin/perl
2 #script to provide bookshelf management
3 # WARNING: This file uses 4-character tabs!
4 #
5 # $Header$
6 #
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 use strict;
25 use C4::Search;
26 use CGI;
27 use C4::Output;
28 use C4::BookShelves;
29 use C4::Circulation::Circ2;
30 use C4::Auth;
31 use C4::Interface::CGI::Output;
32 use HTML::Template;
33
34 my $env;
35 my $query = new CGI;
36 my ($template, $loggedinuser, $cookie)
37     = get_template_and_user({template_name => "opac-shelves.tmpl",
38                                                         query => $query,
39                                                         type => "opac",
40                                                         authnotrequired => 1,
41                                                 });
42
43 if ($query->param('modifyshelfcontents')) {
44         my $shelfnumber=$query->param('shelfnumber');
45         my $barcode=$query->param('addbarcode');
46         my ($item) = getiteminformation($env, 0, $barcode);
47         if (ShelfPossibleAction($loggedinuser,$shelfnumber,'manage')) {
48                 AddToShelf($env, $item->{'itemnumber'}, $shelfnumber);
49                 foreach ($query->param) {
50                         if (/REM-(\d*)/) {
51                                 my $itemnumber=$1;
52                                 RemoveFromShelf($env, $itemnumber, $shelfnumber);
53                         }
54                 }
55         }
56 }
57 my ($shelflist) = GetShelfList($loggedinuser,2);
58
59 $template->param({      loggedinuser => $loggedinuser,
60                                              LibraryName => C4::Context->preference("LibraryName"),
61                                         });
62 SWITCH: {
63         if ($query->param('viewshelf')) {  viewshelf($query->param('viewshelf')); last SWITCH;}
64         if ($query->param('shelves')) {  shelves(); last SWITCH;}
65 }
66
67 ($shelflist) = GetShelfList($loggedinuser,2); # rebuild shelflist in case a shelf has been added
68
69 my $color=1;
70 my @shelvesloop;
71 foreach my $element (sort keys %$shelflist) {
72                 my %line;
73                 $line{'color'}= 1 if ($color eq 1);
74                 $color = -$color;
75                 $line{'shelf'}=$element;
76                 $line{'shelfname'}=$shelflist->{$element}->{'shelfname'};
77                 $line{'shelfbookcount'}=$shelflist->{$element}->{'count'};
78                 $line{'canmanage'} = ShelfPossibleAction($loggedinuser,$element,'manage');
79 ;
80                 push (@shelvesloop, \%line);
81 }
82 $template->param(shelvesloop => \@shelvesloop);
83
84 output_html_with_http_headers $query, $cookie, $template->output;
85
86 sub shelves {
87         if (my $newshelf=$query->param('addshelf')) {
88                 my ($status, $string) = AddShelf($env,$newshelf,$query->param('owner'),$query->param('category'));
89                 if ($status) {
90                         $template->param(status1 => $status, string1 => $string);
91                 }
92         }
93         my @paramsloop;
94         foreach ($query->param()) {
95                 my %line;
96                 if (/DEL-(\d+)/) {
97                         my $delshelf=$1;
98                         my ($status, $string) = RemoveShelf($env,$delshelf);
99                         if ($status) {
100                                 $line{'status'}=$status;
101                                 $line{'string'} = $string;
102                         }
103                 }
104                 #if the shelf is not deleted, %line points on null
105                 push(@paramsloop,\%line);
106         }
107         $template->param(paramsloop => \@paramsloop);
108         my ($shelflist) = GetShelfList($loggedinuser,2);
109         my $color=1;
110         my @shelvesloop;
111         foreach my $element (sort keys %$shelflist) {
112                 my %line;
113                 $line{'color'}=1 if ($color eq 1);
114                 $color = -$color;
115                 $line{'shelf'}=$element;
116                 $line{'shelfname'}=$shelflist->{$element}->{'shelfname'} ;
117                 $line{'shelfbookcount'}=$shelflist->{$element}->{'count'} ;
118                 push(@shelvesloop, \%line);
119         }
120         $template->param(shelvesloop=>\@shelvesloop,
121                                                         shelves => 1,
122                                                 );
123 }
124
125 sub viewshelf {
126         my $shelfnumber=shift;
127         #check that the user can view the shelf
128         return unless (ShelfPossibleAction($loggedinuser,$shelfnumber,'view'));
129         my ($itemlist) = GetShelfContents($env, $shelfnumber);
130         my $item='';
131         my $color=1;
132         my @itemsloop;
133         foreach $item (sort {$a->{'barcode'} cmp $b->{'barcode'}} @$itemlist) {
134                 my %line;
135                 $line{'color'}=1 if ($color eq 1);
136                 $color = -$color;
137                 $line{'itemnumber'}=$item->{'itemnumber'};
138                 $line{'barcode'}=$item->{'barcode'};
139                 $line{'title'}=$item->{'title'};
140                 $line{'author'}=$item->{'author'};
141                 $line{'biblionumber'} = $item->{'biblionumber'};
142                 push(@itemsloop, \%line);
143         }
144         $template->param(       itemsloop => \@itemsloop,
145                                                 shelfname => $shelflist->{$shelfnumber}->{'shelfname'},
146                                                 shelfnumber => $shelfnumber,
147                                                 viewshelf => $query->param('viewshelf'),
148                                                 manageshelf => &ShelfPossibleAction($loggedinuser,$shelfnumber,'manage'),
149                                         );
150 }
151
152 #
153 # $Log$
154 # Revision 1.2  2004/11/12 16:27:33  tipaul
155 # fixes for printing a biblio
156 #
157 # Revision 1.1  2004/03/15 15:02:19  tipaul
158 # adding virtual shelves to opac
159 #
160 # Revision 1.1.2.1  2004/03/10 15:08:18  tipaul
161 # modifying shelves : introducing category of shelf : private, public, free for all
162 #
163 # Revision 1.13  2004/02/11 08:35:31  tipaul
164 # synch'ing 2.0.0 branch and head
165 #
166 # Revision 1.12.2.1  2004/02/06 14:22:19  tipaul
167 # fixing bugs in bookshelves management.
168 #
169 # Revision 1.12  2003/02/05 10:04:14  acli
170 # Worked around weirdness with HTML::Template; without the {}, it complains
171 # of being passed an odd number of arguments even though we are not
172 #
173 # Revision 1.11  2003/02/05 09:23:03  acli
174 # Fixed a few minor errors to make it run
175 # Noted correct tab size
176 #
177 # Revision 1.10  2003/02/02 07:18:37  acli
178 # Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
179 #
180 # Create output_html_with_http_headers function to contain the "print $query
181 # ->header(-type => guesstype...),..." call. This is in preparation for
182 # non-HTML output (e.g., text/xml) and charset conversion before output in
183 # the future.
184 #
185 # Created C4/Interface/CGI/Template.pm to hold convenience functions specific
186 # to the CGI interface using HTML::Template
187 #
188 # Modified moremembers.pl to make the "sex" field localizable for languages
189 # where M and F doesn't make sense
190 #
191 # Revision 1.9  2002/12/19 18:55:40  hdl
192 # Templating reservereport et shelves.
193 #
194 # Revision 1.9  2002/08/14 18:12:51  hdl
195 # Templating files
196 #
197 # Revision 1.8  2002/08/14 18:12:51  tonnesen
198 # Added copyright statement to all .pl and .pm files
199 #
200 # Revision 1.7  2002/07/05 05:03:37  tonnesen
201 # Minor changes to authentication routines.
202 #
203 # Revision 1.5  2002/07/04 19:42:48  tonnesen
204 # Minor changes
205 #
206 # Revision 1.4  2002/07/04 19:21:29  tonnesen
207 # Beginning of authentication api.  Applied to shelves.pl for now as a test case.
208 #
209 # Revision 1.2.2.1  2002/06/26 20:28:15  tonnesen
210 # Some udpates that I made here locally a while ago.  Still won't be useful, but
211 # should be functional
212 #
213 #
214 #
215
216
217
218
219 # Local Variables:
220 # tab-width: 4
221 # End: