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