bugfix
[koha.git] / shelves.pl
1 #!/usr/bin/perl
2 #script to provide bookshelf management
3 #
4 # $Header$
5 #
6
7
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA  02111-1307 USA
24
25 use strict;
26 use C4::Search;
27 use CGI;
28 use C4::Output;
29 use C4::BookShelves;
30 use C4::Circulation::Circ2;
31 use C4::Auth;
32 use HTML::Template;
33
34 my $env;
35 my $query = new CGI;
36 my ($loggedinuser, $cookie, $sessionID) = checkauth($query);
37 #print $query->header(-cookie => $cookie);
38 my $headerbackgroundcolor='#663266';
39 my $circbackgroundcolor='#555555';
40 my $circbackgroundcolor='#550000';
41 my $linecolor1='#bbbbbb';
42 my $linecolor2='#dddddd';
43 my $template=gettemplate("shelves.tmpl");
44 #print startpage();
45 #print startmenu('catalogue');
46 #print "<p align=left>Logged in as: $loggedinuser [<a href=/cgi-bin/koha/logout.pl>Log Out</a>]</p>\n";
47
48
49 my ($shelflist) = GetShelfList();
50
51 if ($query->param('modifyshelfcontents')) {
52     my $shelfnumber=$query->param('shelfnumber');
53     my $barcode=$query->param('addbarcode');
54     my ($item) = getiteminformation($env, 0, $barcode);
55     AddToShelf($env, $item->{'itemnumber'}, $shelfnumber);
56     foreach ($query->param) {
57         if (/REM-(\d*)/) {
58             my $itemnumber=$1;
59             RemoveFromShelf($env, $itemnumber, $shelfnumber);
60         }
61     }
62 }
63
64 SWITCH: {
65         $template->param(       loggedinuser => $loggedinuser,
66                                                                         viewshelf => $query->param('viewshelf'),
67                                                                         shelves => $query->param('shelves'),
68                                                                         headerbackground => $headerbackground,
69                                                                         circbackgroundcolor => $circbackgroundcolor);
70     if ($query->param('viewshelf')) {  viewshelf($query->param('viewshelf')); last SWITCH;}
71     if ($query->param('shelves')) {  shelves(); last SWITCH;}
72         my $color='';
73         my @shelvesloop;
74     foreach $element (sort keys %$shelflist) {
75                 my %line;
76                 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
77                 $line{'color'}= $color;
78                 $line{'shelf'}=$element;
79                 $line{'shelfname'}=$shelflist->{$element}->{'shelfname'};
80                 $line{'shelfbookcount'}=$shelflist->{$element}->{'count'};
81                 push (@shelvesloop, \%line);
82     }
83         $template->param(shelvesloop => \@shelvesloop);
84 }
85
86 print $query->header(-cookie => $cookie), $template->output;
87
88
89 sub shelves {
90     if (my $newshelf=$query->param('addshelf')) {
91         my ($status, $string) = AddShelf($env,$newshelf);
92         if ($status) {
93             $template->param(status1 => $status, string1 => $string);
94         }
95     }
96         my @paramsloop;
97     foreach ($query->param()) {
98                 my %line;
99                 if (/DEL-(\d+)/) {
100                         my $delshelf=$1;
101                         my ($status, $string) = RemoveShelf($env,$delshelf);
102                         if ($status) {
103                                 $line{'status'}=$status;
104                                 $line{'string'} = $string;
105                         }
106                 }
107                 #if the shelf is not deleted, %line points on null
108                 push(@paramsloop,\%line);
109     }
110         $template->param(paramsloop => \@paramsloop);
111     my ($shelflist) = GetShelfList();
112     my $color='';
113         my @shelvesloop;
114     foreach $element (sort keys %$shelflist) {
115                 my %line;
116                 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
117                 $line{'color'}=$color;
118                 $line{'shelf'}=$element;
119                 $line{'shelfname'}=$shelflist->{$element}->{'shelfname'} ;
120                 $line{'shelfbookcount'}=$shelflist->{$element}->{'count'} ;
121                 push(@shelvesloop, \%line);
122     }
123         $template->param(shelvesloop=>\@shelvesloop);
124 }
125
126
127
128 sub viewshelf {
129     my $shelfnumber=shift;
130     my ($itemlist) = GetShelfContents($env, $shelfnumber);
131     my $item='';
132     my $color='';
133         my @itemsloop;
134     foreach $item (sort {$a->{'barcode'} cmp $b->{'barcode'}} @$itemlist) {
135                 my %line;
136                 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
137                 $line{'color'}=$color;
138                 $line{'itemnumber'}=$item->{'itemnumber'};
139                 $line{'barcode'}=$item->{'barcode'};
140                 $line{'title'}=$item->{'title'};
141                 $line{'author'}=$item->{'author'};
142                 push(@itemsloop, \%line);
143     }
144         $template->param(       itemsloop => \@itemsloop);
145         $template->param(       shelfname => $shelflist->{$shelfnumber}->{'shelfname'});
146         $template->param(       shelfnumber => $shelfnumber);
147 }
148
149 #print endpage();
150 #print endmenu('catalogue');
151
152 #
153 # $Log$
154 # Revision 1.9  2002/12/19 18:55:40  hdl
155 # Templating reservereport et shelves.
156 #
157 # Revision 1.9  2002/08/14 18:12:51  hdl
158 # Templating files
159 #
160 # Revision 1.8  2002/08/14 18:12:51  tonnesen
161 # Added copyright statement to all .pl and .pm files
162 #
163 # Revision 1.7  2002/07/05 05:03:37  tonnesen
164 # Minor changes to authentication routines.
165 #
166 # Revision 1.5  2002/07/04 19:42:48  tonnesen
167 # Minor changes
168 #
169 # Revision 1.4  2002/07/04 19:21:29  tonnesen
170 # Beginning of authentication api.  Applied to shelves.pl for now as a test case.
171 #
172 # Revision 1.2.2.1  2002/06/26 20:28:15  tonnesen
173 # Some udpates that I made here locally a while ago.  Still won't be useful, but
174 # should be functional
175 #
176 #
177 #
178
179
180