writing absolute path.
[koha.git] / opac / opac-shelves.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 # $Id$
21
22 =head1 NAME
23
24     opac-shelves.pl
25
26 =head1 DESCRIPTION
27
28     this script is used to script to provide bookshelf management
29
30 =head1 CGI PARAMETERS
31
32 =over 4
33
34 =item C<modifyshelfcontents>
35
36     if this script has to modify the shelve content.
37
38 =item C<shelfnumber>
39
40     to know on which shelve this script has to work.
41
42 =item C<addbarcode>
43
44 =item C<op>
45
46     op can be equals to:
47         * modifsave to save change on the shelves
48         * modif to change the template to allow to modify the shelves.
49
50 =item C<viewshelf>
51
52     to load the template with 'viewshelves param' which allow to read the shelves information.
53
54 =item C<shelves>
55
56     if equals to 1. then call the function shelves which add
57     or delete a shelf.
58
59 =item C<addshelf>
60
61     if the param shelves = 1 then addshelf must be equals to the name of the shelf to add.
62
63 =back
64
65 =cut
66
67 use strict;
68 use CGI;
69 use C4::Output;
70 use C4::BookShelves;
71 use C4::Circulation;
72 use C4::Auth;
73 use C4::Output;
74
75 my $query = new CGI;
76
77 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
78     {
79         template_name   => "opac-shelves.tmpl",
80         query           => $query,
81         type            => "opac",
82         authnotrequired => 1,
83     }
84 );
85
86 if ( $query->param('modifyshelfcontents') ) {
87     my $shelfnumber = $query->param('viewshelf');
88     my $barcode     = $query->param('addbarcode');
89     my ($item) = GetItemnumberFromBarcode($barcode);
90     if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ) ) {
91         AddToShelf( $item->{'itemnumber'}, $shelfnumber );
92         foreach ( $query->param ) {
93             if (/MOD-(\d*)/) {
94                 my $itemnumber = $1;
95                 if ( $query->param('remove') eq "on" ) {
96                     DelFromShelf( $itemnumber, $shelfnumber );
97                 }
98             }
99         }
100     }
101 }
102
103 # getting the Shelves list
104 my $shelflist = GetShelves( $loggedinuser, 2 );
105 $template->param( { loggedinuser => $loggedinuser } );
106 my $op = $query->param('op');
107
108 SWITCH: {
109     if ( $op && ( $op eq 'modifsave' ) ) {
110         ModShelf(
111             $query->param('shelfnumber'), $query->param('shelfname'),
112             $loggedinuser,                $query->param('category')
113         );
114         last SWITCH;
115     }
116     if ( $op && ( $op eq 'modif' ) ) {
117         my ( $shelfnumber, $shelfname, $owner, $category ) =
118           GetShelf( $query->param('shelf') );
119         $template->param(
120             edit                => 1,
121             shelfnumber         => $shelfnumber,
122             shelfname           => $shelfname,
123             "category$category" => 1
124         );
125
126         #         editshelf($query->param('shelf'));
127         last SWITCH;
128     }
129     if ( $query->param('viewshelf') ) {
130         #check that the user can view the shelf
131         my $shelfnumber = $query->param('viewshelf');
132         if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
133             my $items = GetShelfContents($shelfnumber);
134             $template->param(
135                 shelfname   => $shelflist->{$shelfnumber}->{'shelfname'},
136                 shelfnumber => $shelfnumber,
137                 viewshelf   => $query->param('viewshelf'),
138                 manageshelf => &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ),
139                 itemsloop   => $items,
140             );
141         }
142         last SWITCH;
143     }
144     if ( $query->param('shelves') ) {
145         if ( my $newshelf = $query->param('addshelf') ) {
146             my $shelfnumber = AddShelf(
147                 $newshelf,
148                 $query->param('owner'),
149                 $query->param('category')
150             );
151
152             if ( $shelfnumber == -1 ) {    #shelf already exists.
153                 $template->param(
154                     {
155                         shelfnumber => $shelfnumber,
156                         already     => 1
157                     }
158                 );
159             }
160     }
161     my @paramsloop;
162     foreach ( $query->param() ) {
163         my %line;
164         if (/DEL-(\d+)/) {
165             my $delshelf = $1;
166             my ( $status, $count ) = DelShelf($delshelf);
167             if ($status) {
168                 $line{'status'} = $status;
169                 $line{'count'}  = $count;
170             }
171         }
172
173         #if the shelf is not deleted, %line points on null
174         push( @paramsloop, \%line );
175     }
176     $template->param( paramsloop => \@paramsloop );
177     my ($shelflist) = GetShelves( $loggedinuser, 2 );
178     my $color = '';
179     my @shelvesloop;
180     foreach my $element ( sort keys %$shelflist ) {
181         my %line;
182         ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
183         $line{'toggle'}         = $color;
184         $line{'shelf'}          = $element;
185         $line{'shelfname'}      = $shelflist->{$element}->{'shelfname'};
186         $line{'shelfbookcount'} = $shelflist->{$element}->{'count'};
187         push( @shelvesloop, \%line );
188     }
189     $template->param(
190         shelvesloop => \@shelvesloop,
191         shelves     => 1,
192     );
193         last SWITCH;
194     }
195 }
196
197 ($shelflist) =
198   GetShelves( $loggedinuser, 2 )
199   ;    # rebuild shelflist in case a shelf has been added
200
201 my $color = '';
202 my @shelvesloop;
203 foreach my $element ( sort keys %$shelflist ) {
204     my %line;
205     ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
206     $line{'toggle'}    = $color;
207         $line{'shelf'}     = $element;
208         $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
209         $line{ "category" . $shelflist->{$element}->{'category'} } = 1;
210         $line{'mine'} = 1 if $shelflist->{$element}->{'owner'} eq $loggedinuser;
211         $line{'shelfbookcount'} = $shelflist->{$element}->{'count'};
212         $line{'canmanage'}      =
213           ShelfPossibleAction( $loggedinuser, $element, 'manage' );
214         $line{'firstname'} = $shelflist->{$element}->{'firstname'}
215           unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
216         $line{'surname'} = $shelflist->{$element}->{'surname'}
217           unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
218         push( @shelvesloop, \%line );
219     }
220
221 $template->param(
222     shelvesloop             => \@shelvesloop,
223     "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
224 );
225
226 output_html_with_http_headers $query, $cookie, $template->output;
227
228
229
230 #
231 # $Log$
232 # Revision 1.12  2007/04/24 13:54:29  hdl
233 # functions that were in C4::Interface::CGI::Output are now in C4::Output.
234 # So this implies quite a change for files.
235 # Sorry about conflicts which will be caused.
236 # directory Interface::CGI should now be dropped.
237 # I noticed that many scripts (reports ones, but also some circ/stats.pl or opac-topissues) still use Date::Manip.
238 #
239 # Revision 1.11  2007/04/17 08:52:19  tipaul
240 # circulation cleaning continued: bufixing
241 #
242 # Revision 1.10  2007/04/04 16:46:23  tipaul
243 # HUGE COMMIT : code cleaning circulation.
244 #
245 # some stuff to do, i'll write a mail on koha-devel NOW !
246 #
247 # Revision 1.9  2007/03/09 15:12:54  tipaul
248 # rel_3_0 moved to HEAD
249 #
250 # Revision 1.8.2.12  2007/01/15 17:19:30  toins
251 # enable to add checked items to a shelf.
252 # Some display enhancements.
253 #
254 # Revision 1.8.2.11  2007/01/10 10:52:58  toins
255 # adding syspref directly to Auth.pm instead of to the template.
256 #
257 # Revision 1.8.2.10  2007/01/10 10:12:48  toins
258 # Adding OpacTopissue, OpacCloud, OpacAuthorithies to the template->param.
259 # + Some cleanup.
260 #
261 # Revision 1.8.2.9  2006/12/15 17:43:24  toins
262 # sync with intranet.
263 #
264 # Revision 1.8.2.8  2006/12/14 17:59:17  toins
265 # add the link to "BiblioDefaultView systempref" and not to opac-detail.pl
266 #
267 # Revision 1.8.2.7  2006/12/14 17:22:55  toins
268 # bookshelves work perfectly with mod_perl and are cleaned.
269 #
270 # Revision 1.8.2.6  2006/12/14 16:04:25  toins
271 # sync with intranet.
272 #
273 # Revision 1.8.2.5  2006/12/11 17:10:06  toins
274 # fixing some bugs on bookshelves.
275 #
276 # Revision 1.8.2.4  2006/12/07 15:42:15  toins
277 # synching opac & intranet.
278 # fix some broken link & bugs.
279 # removing warn compilation.
280 #
281 # Revision 1.8.2.3  2006/11/30 18:23:51  toins
282 # theses scripts don't need to use C4::Search.
283 #