adding virtual shelves to opac
[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 => 0,
41                                                         flagsrequired => {catalogue => 1},
42                                                 });
43
44 if ($query->param('modifyshelfcontents')) {
45         my $shelfnumber=$query->param('shelfnumber');
46         my $barcode=$query->param('addbarcode');
47         my ($item) = getiteminformation($env, 0, $barcode);
48         if (ShelfPossibleAction($loggedinuser,$shelfnumber,'manage')) {
49                 AddToShelf($env, $item->{'itemnumber'}, $shelfnumber);
50                 foreach ($query->param) {
51                         if (/REM-(\d*)/) {
52                                 my $itemnumber=$1;
53                                 RemoveFromShelf($env, $itemnumber, $shelfnumber);
54                         }
55                 }
56         }
57 }
58 my ($shelflist) = GetShelfList($loggedinuser,2);
59
60 $template->param({      loggedinuser => $loggedinuser,
61                                              LibraryName => C4::Context->preference("LibraryName"),
62                                         });
63 SWITCH: {
64         if ($query->param('viewshelf')) {  viewshelf($query->param('viewshelf')); last SWITCH;}
65         if ($query->param('shelves')) {  shelves(); last SWITCH;}
66 }
67
68 ($shelflist) = GetShelfList($loggedinuser,2); # rebuild shelflist in case a shelf has been added
69
70 my $color=1;
71 my @shelvesloop;
72 foreach my $element (sort keys %$shelflist) {
73                 my %line;
74                 $line{'color'}= 1 if ($color eq 1);
75                 $color = -$color;
76                 $line{'shelf'}=$element;
77                 $line{'shelfname'}=$shelflist->{$element}->{'shelfname'};
78                 $line{'shelfbookcount'}=$shelflist->{$element}->{'count'};
79                 $line{'canmanage'} = ShelfPossibleAction($loggedinuser,$element,'manage');
80 ;
81                 push (@shelvesloop, \%line);
82 }
83 $template->param(shelvesloop => \@shelvesloop);
84
85 output_html_with_http_headers $query, $cookie, $template->output;
86
87 sub shelves {
88         if (my $newshelf=$query->param('addshelf')) {
89                 my ($status, $string) = AddShelf($env,$newshelf,$query->param('owner'),$query->param('category'));
90                 if ($status) {
91                         $template->param(status1 => $status, string1 => $string);
92                 }
93         }
94         my @paramsloop;
95         foreach ($query->param()) {
96                 my %line;
97                 if (/DEL-(\d+)/) {
98                         my $delshelf=$1;
99                         my ($status, $string) = RemoveShelf($env,$delshelf);
100                         if ($status) {
101                                 $line{'status'}=$status;
102                                 $line{'string'} = $string;
103                         }
104                 }
105                 #if the shelf is not deleted, %line points on null
106                 push(@paramsloop,\%line);
107         }
108         $template->param(paramsloop => \@paramsloop);
109         my ($shelflist) = GetShelfList($loggedinuser,2);
110         my $color=1;
111         my @shelvesloop;
112         foreach my $element (sort keys %$shelflist) {
113                 my %line;
114                 $line{'color'}=1 if ($color eq 1);
115                 $color = -$color;
116                 $line{'shelf'}=$element;
117                 $line{'shelfname'}=$shelflist->{$element}->{'shelfname'} ;
118                 $line{'shelfbookcount'}=$shelflist->{$element}->{'count'} ;
119                 push(@shelvesloop, \%line);
120         }
121         $template->param(shelvesloop=>\@shelvesloop,
122                                                         shelves => 1,
123                                                 );
124 }
125
126 sub viewshelf {
127         my $shelfnumber=shift;
128         #check that the user can view the shelf
129         return unless (ShelfPossibleAction($loggedinuser,$shelfnumber,'view'));
130         my ($itemlist) = GetShelfContents($env, $shelfnumber);
131         my $item='';
132         my $color=1;
133         my @itemsloop;
134         foreach $item (sort {$a->{'barcode'} cmp $b->{'barcode'}} @$itemlist) {
135                 my %line;
136                 $line{'color'}=1 if ($color eq 1);
137                 $color = -$color;
138                 $line{'itemnumber'}=$item->{'itemnumber'};
139                 $line{'barcode'}=$item->{'barcode'};
140                 $line{'title'}=$item->{'title'};
141                 $line{'author'}=$item->{'author'};
142                 $line{'biblionumber'} = $item->{'biblionumber'};
143                 push(@itemsloop, \%line);
144         }
145         $template->param(       itemsloop => \@itemsloop,
146                                                 shelfname => $shelflist->{$shelfnumber}->{'shelfname'},
147                                                 shelfnumber => $shelfnumber,
148                                                 viewshelf => $query->param('viewshelf'),
149                                                 manageshelf => &ShelfPossibleAction($loggedinuser,$shelfnumber,'manage'),
150                                         );
151 }
152
153 #
154 # $Log$
155 # Revision 1.1  2004/03/15 15:02:19  tipaul
156 # adding virtual shelves to opac
157 #
158 # Revision 1.1.2.1  2004/03/10 15:08:18  tipaul
159 # modifying shelves : introducing category of shelf : private, public, free for all
160 #
161 # Revision 1.13  2004/02/11 08:35:31  tipaul
162 # synch'ing 2.0.0 branch and head
163 #
164 # Revision 1.12.2.1  2004/02/06 14:22:19  tipaul
165 # fixing bugs in bookshelves management.
166 #
167 # Revision 1.12  2003/02/05 10:04:14  acli
168 # Worked around weirdness with HTML::Template; without the {}, it complains
169 # of being passed an odd number of arguments even though we are not
170 #
171 # Revision 1.11  2003/02/05 09:23:03  acli
172 # Fixed a few minor errors to make it run
173 # Noted correct tab size
174 #
175 # Revision 1.10  2003/02/02 07:18:37  acli
176 # Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
177 #
178 # Create output_html_with_http_headers function to contain the "print $query
179 # ->header(-type => guesstype...),..." call. This is in preparation for
180 # non-HTML output (e.g., text/xml) and charset conversion before output in
181 # the future.
182 #
183 # Created C4/Interface/CGI/Template.pm to hold convenience functions specific
184 # to the CGI interface using HTML::Template
185 #
186 # Modified moremembers.pl to make the "sex" field localizable for languages
187 # where M and F doesn't make sense
188 #
189 # Revision 1.9  2002/12/19 18:55:40  hdl
190 # Templating reservereport et shelves.
191 #
192 # Revision 1.9  2002/08/14 18:12:51  hdl
193 # Templating files
194 #
195 # Revision 1.8  2002/08/14 18:12:51  tonnesen
196 # Added copyright statement to all .pl and .pm files
197 #
198 # Revision 1.7  2002/07/05 05:03:37  tonnesen
199 # Minor changes to authentication routines.
200 #
201 # Revision 1.5  2002/07/04 19:42:48  tonnesen
202 # Minor changes
203 #
204 # Revision 1.4  2002/07/04 19:21:29  tonnesen
205 # Beginning of authentication api.  Applied to shelves.pl for now as a test case.
206 #
207 # Revision 1.2.2.1  2002/06/26 20:28:15  tonnesen
208 # Some udpates that I made here locally a while ago.  Still won't be useful, but
209 # should be functional
210 #
211 #
212 #
213
214
215
216
217 # Local Variables:
218 # tab-width: 4
219 # End: