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