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