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