fixing syntax error in sysprefs.sql
[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
21 =head1 NAME
22
23     opac-shelves.pl
24
25 =head1 DESCRIPTION
26
27     this script is used to script to provide virtualshelf management
28
29 =head1 CGI PARAMETERS
30
31 =over 4
32
33 =item C<modifyshelfcontents>
34
35     if this script has to modify the shelve content.
36
37 =item C<shelfnumber>
38
39     to know on which shelve this script has to work.
40
41 =item C<addbarcode>
42
43 =item C<op>
44
45     op can be equals to:
46         * modifsave to save change on the shelves
47         * modif to change the template to allow to modify the shelves.
48
49 =item C<viewshelf>
50
51     to load the template with 'viewshelves param' which allow to read the shelves information.
52
53 =item C<shelves>
54
55     if equals to 1. then call the function shelves which add
56     or delete a shelf.
57
58 =item C<addshelf>
59
60     if the param shelves = 1 then addshelf must be equals to the name of the shelf to add.
61
62 =back
63
64 =cut
65
66 use strict;
67 use CGI;
68 use C4::Output;
69 use C4::VirtualShelves;
70 use C4::Circulation;
71 use C4::Auth;
72 use C4::Output;
73 use C4::Biblio;
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         my ($biblio) = GetBiblioFromItemNumber($item->{'itemnumber'});
91     if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ) ) {
92         AddToShelf( $biblio->{'biblionumber'}, $shelfnumber );
93         foreach ( $query->param ) {
94             if (/MOD-(\d*)/) {
95                 my $biblionumber = $1;
96                 if ( $query->param('remove') eq "on" ) {
97                     DelFromShelf( $biblionumber, $shelfnumber );
98                 }
99             }
100         }
101     }
102 }
103
104         # set the default tab, etc.
105         my $shelf_type = $query->param('display');
106         if ((!$shelf_type) || ($shelf_type eq 'privateshelves'))  {
107                 $template->param(showprivateshelves => 1);
108         } elsif ($shelf_type eq 'publicshelves') {
109                 $template->param(showpublicshelves => 1);
110         }
111
112 # getting the Shelves list
113 my $shelflist = GetShelves( $loggedinuser, 2 );
114 $template->param( { loggedinuser => $loggedinuser } );
115 my $op = $query->param('op');
116
117 SWITCH: {
118     if ( $op && ( $op eq 'modifsave' ) ) {
119         ModShelf(
120             $query->param('shelfnumber'), $query->param('shelfname'),
121             $loggedinuser,                $query->param('category')
122         );
123         last SWITCH;
124     }
125     if ( $op && ( $op eq 'modif' ) ) {
126         my ( $shelfnumber, $shelfname, $owner, $category ) =
127           GetShelf( $query->param('shelf') );
128         $template->param(
129             edit                => 1,
130             shelfnumber         => $shelfnumber,
131             shelfname           => $shelfname,
132             "category$category" => 1
133         );
134
135         #         editshelf($query->param('shelf'));
136         last SWITCH;
137     }
138     if ( $query->param('viewshelf') ) {
139         #check that the user can view the shelf
140         my $shelfnumber = $query->param('viewshelf');
141         if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
142             my $items = GetShelfContents($shelfnumber);
143             $template->param(
144                 shelfname   => $shelflist->{$shelfnumber}->{'shelfname'},
145                 shelfnumber => $shelfnumber,
146                 viewshelf   => $query->param('viewshelf'),
147                 manageshelf => &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ),
148                 itemsloop   => $items,
149             );
150         }
151         last SWITCH;
152     }
153     if ( $query->param('shelves') ) {
154         if ( my $newshelf = $query->param('addshelf') ) {
155             my $shelfnumber = AddShelf(
156                 $newshelf,
157                 $query->param('owner'),
158                 $query->param('category')
159             );
160
161             if ( $shelfnumber == -1 ) {    #shelf already exists.
162                 $template->param(
163                     {
164                         shelfnumber => $shelfnumber,
165                         already     => 1
166                     }
167                 );
168             }
169     }
170     my @paramsloop;
171     foreach ( $query->param() ) {
172         my %line;
173         if (/DEL-(\d+)/) {
174             my $delshelf = $1;
175             my ( $status, $count ) = DelShelf($delshelf);
176             if ($status) {
177                 $line{'status'} = $status;
178                 $line{'count'}  = $count;
179             }
180         }
181
182         #if the shelf is not deleted, %line points on null
183         push( @paramsloop, \%line );
184     }
185     $template->param( paramsloop => \@paramsloop );
186     my ($shelflist) = GetShelves( $loggedinuser, 2 );
187     my $color = '';
188     my @shelvesloop;
189     foreach my $element ( sort keys %$shelflist ) {
190         my %line;
191         ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
192         $line{'toggle'}         = $color;
193         $line{'shelf'}          = $element;
194         $line{'shelfname'}      = $shelflist->{$element}->{'shelfname'};
195         $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
196         push( @shelvesloop, \%line );
197     }
198     $template->param(
199         shelvesloop => \@shelvesloop,
200         shelves     => 1,
201     );
202         last SWITCH;
203     }
204 }
205
206 ($shelflist) =
207   GetShelves( $loggedinuser, 2 )
208   ;    # rebuild shelflist in case a shelf has been added
209
210 my $color='';
211 my @shelvesloop;
212 my @shelveslooppriv;
213 foreach my $element (sort keys %$shelflist) {
214                 my %line;
215                 my %linepriv;
216                 ($color eq 0) ? ($color=1) : ($color=0);
217                 if ($shelflist->{$element}->{'category'} eq 2) {
218                 $line{'color'}= $color;
219                 $line{'shelf'}=$element;
220                 $line{'shelfname'}=$shelflist->{$element}->{'shelfname'};
221                 $line{"category".$shelflist->{$element}->{'category'}} = 1;
222                 $line{'mine'} = 1 if $shelflist->{$element}->{'owner'} eq $loggedinuser;
223                 $line{'shelfbookcount'}=$shelflist->{$element}->{'count'};
224                 $line{'canmanage'} = ShelfPossibleAction($loggedinuser,$element,'manage');
225                 $line{'firstname'}=$shelflist->{$element}->{'firstname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
226                 $line{'surname'}=$shelflist->{$element}->{'surname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
227                 
228                 push (@shelvesloop, \%line);
229                 } elsif ($shelflist->{$element}->{'category'} eq 1) {
230                 $linepriv{'color'}= $color;
231                 $linepriv{'shelf'}=$element;
232                 $linepriv{'shelfname'}=$shelflist->{$element}->{'shelfname'};
233                 $linepriv{"category".$shelflist->{$element}->{'category'}} = 1;
234                 $linepriv{'mine'} = 1 if $shelflist->{$element}->{'owner'} eq $loggedinuser;
235                 $linepriv{'shelfbookcount'}=$shelflist->{$element}->{'count'};
236                 $linepriv{'canmanage'} = ShelfPossibleAction($loggedinuser,$element,'manage');
237                 $linepriv{'firstname'}=$shelflist->{$element}->{'firstname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
238                 $linepriv{'surname'}=$shelflist->{$element}->{'surname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
239                 push (@shelveslooppriv, \%linepriv);
240                 }
241 }
242
243 $template->param(
244         shelveslooppriv => \@shelveslooppriv,
245     shelvesloop             => \@shelvesloop,
246     "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
247 );
248
249 output_html_with_http_headers $query, $cookie, $template->output;
250
251
252
253 #
254 # Revision 1.12  2007/04/24 13:54:29  hdl
255 # functions that were in C4::Interface::CGI::Output are now in C4::Output.
256 # So this implies quite a change for files.
257 # Sorry about conflicts which will be caused.
258 # directory Interface::CGI should now be dropped.
259 # I noticed that many scripts (reports ones, but also some circ/stats.pl or opac-topissues) still use Date::Manip.
260 #
261 # Revision 1.11  2007/04/17 08:52:19  tipaul
262 # circulation cleaning continued: bufixing
263 #
264 # Revision 1.10  2007/04/04 16:46:23  tipaul
265 # HUGE COMMIT : code cleaning circulation.
266 #
267 # some stuff to do, i'll write a mail on koha-devel NOW !
268 #
269 # Revision 1.9  2007/03/09 15:12:54  tipaul
270 # rel_3_0 moved to HEAD
271 #
272 # Revision 1.8.2.12  2007/01/15 17:19:30  toins
273 # enable to add checked items to a shelf.
274 # Some display enhancements.
275 #
276 # Revision 1.8.2.11  2007/01/10 10:52:58  toins
277 # adding syspref directly to Auth.pm instead of to the template.
278 #
279 # Revision 1.8.2.10  2007/01/10 10:12:48  toins
280 # Adding OpacTopissue, OpacCloud, OpacAuthorithies to the template->param.
281 # + Some cleanup.
282 #
283 # Revision 1.8.2.9  2006/12/15 17:43:24  toins
284 # sync with intranet.
285 #
286 # Revision 1.8.2.8  2006/12/14 17:59:17  toins
287 # add the link to "BiblioDefaultView systempref" and not to opac-detail.pl
288 #
289 # Revision 1.8.2.7  2006/12/14 17:22:55  toins
290 # virtualshelves work perfectly with mod_perl and are cleaned.
291 #
292 # Revision 1.8.2.6  2006/12/14 16:04:25  toins
293 # sync with intranet.
294 #
295 # Revision 1.8.2.5  2006/12/11 17:10:06  toins
296 # fixing some bugs on virtualshelves.
297 #
298 # Revision 1.8.2.4  2006/12/07 15:42:15  toins
299 # synching opac & intranet.
300 # fix some broken link & bugs.
301 # removing warn compilation.
302 #
303 # Revision 1.8.2.3  2006/11/30 18:23:51  toins
304 # theses scripts don't need to use C4::Search.
305 #