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