Fixing error on duplicate entry process.
[koha.git] / opac / opac-shelves.pl
blob683610c60f00e12191d91a2a9b79a79eb8d89c85
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
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.
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.
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
20 # $Id$
22 =head1 NAME
24 opac-shelves.pl
26 =head1 DESCRIPTION
28 this script is used to script to provide virtualshelf management
30 =head1 CGI PARAMETERS
32 =over 4
34 =item C<modifyshelfcontents>
36 if this script has to modify the shelve content.
38 =item C<shelfnumber>
40 to know on which shelve this script has to work.
42 =item C<addbarcode>
44 =item C<op>
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.
50 =item C<viewshelf>
52 to load the template with 'viewshelves param' which allow to read the shelves information.
54 =item C<shelves>
56 if equals to 1. then call the function shelves which add
57 or delete a shelf.
59 =item C<addshelf>
61 if the param shelves = 1 then addshelf must be equals to the name of the shelf to add.
63 =back
65 =cut
67 use strict;
68 use CGI;
69 use C4::Output;
70 use C4::VirtualShelves;
71 use C4::Circulation;
72 use C4::Auth;
73 use C4::Output;
74 use C4::Biblio;
76 my $query = new CGI;
78 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
80 template_name => "opac-shelves.tmpl",
81 query => $query,
82 type => "opac",
83 authnotrequired => 1,
87 if ( $query->param('modifyshelfcontents') ) {
88 my $shelfnumber = $query->param('viewshelf');
89 my $barcode = $query->param('addbarcode');
90 my ($item) = GetItemnumberFromBarcode($barcode);
91 my ($biblio) = GetBiblioFromItemNumber($item->{'itemnumber'});
92 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ) ) {
93 AddToShelf( $biblio->{'biblionumber'}, $shelfnumber );
94 foreach ( $query->param ) {
95 if (/MOD-(\d*)/) {
96 my $biblionumber = $1;
97 if ( $query->param('remove') eq "on" ) {
98 DelFromShelf( $biblionumber, $shelfnumber );
105 # getting the Shelves list
106 my $shelflist = GetShelves( $loggedinuser, 2 );
107 $template->param( { loggedinuser => $loggedinuser } );
108 my $op = $query->param('op');
110 SWITCH: {
111 if ( $op && ( $op eq 'modifsave' ) ) {
112 ModShelf(
113 $query->param('shelfnumber'), $query->param('shelfname'),
114 $loggedinuser, $query->param('category')
116 last SWITCH;
118 if ( $op && ( $op eq 'modif' ) ) {
119 my ( $shelfnumber, $shelfname, $owner, $category ) =
120 GetShelf( $query->param('shelf') );
121 $template->param(
122 edit => 1,
123 shelfnumber => $shelfnumber,
124 shelfname => $shelfname,
125 "category$category" => 1
128 # editshelf($query->param('shelf'));
129 last SWITCH;
131 if ( $query->param('viewshelf') ) {
132 #check that the user can view the shelf
133 my $shelfnumber = $query->param('viewshelf');
134 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
135 my $items = GetShelfContents($shelfnumber);
136 $template->param(
137 shelfname => $shelflist->{$shelfnumber}->{'shelfname'},
138 shelfnumber => $shelfnumber,
139 viewshelf => $query->param('viewshelf'),
140 manageshelf => &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ),
141 itemsloop => $items,
144 last SWITCH;
146 if ( $query->param('shelves') ) {
147 if ( my $newshelf = $query->param('addshelf') ) {
148 my $shelfnumber = AddShelf(
149 $newshelf,
150 $query->param('owner'),
151 $query->param('category')
154 if ( $shelfnumber == -1 ) { #shelf already exists.
155 $template->param(
157 shelfnumber => $shelfnumber,
158 already => 1
163 my @paramsloop;
164 foreach ( $query->param() ) {
165 my %line;
166 if (/DEL-(\d+)/) {
167 my $delshelf = $1;
168 my ( $status, $count ) = DelShelf($delshelf);
169 if ($status) {
170 $line{'status'} = $status;
171 $line{'count'} = $count;
175 #if the shelf is not deleted, %line points on null
176 push( @paramsloop, \%line );
178 $template->param( paramsloop => \@paramsloop );
179 my ($shelflist) = GetShelves( $loggedinuser, 2 );
180 my $color = '';
181 my @shelvesloop;
182 foreach my $element ( sort keys %$shelflist ) {
183 my %line;
184 ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
185 $line{'toggle'} = $color;
186 $line{'shelf'} = $element;
187 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
188 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
189 push( @shelvesloop, \%line );
191 $template->param(
192 shelvesloop => \@shelvesloop,
193 shelves => 1,
195 last SWITCH;
199 ($shelflist) =
200 GetShelves( $loggedinuser, 2 )
201 ; # rebuild shelflist in case a shelf has been added
203 my $color = '';
204 my @shelvesloop;
205 foreach my $element ( sort keys %$shelflist ) {
206 my %line;
207 ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
208 $line{'toggle'} = $color;
209 $line{'shelf'} = $element;
210 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
211 $line{ "category" . $shelflist->{$element}->{'category'} } = 1;
212 $line{'mine'} = 1 if $shelflist->{$element}->{'owner'} eq $loggedinuser;
213 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
214 $line{'canmanage'} =
215 ShelfPossibleAction( $loggedinuser, $element, 'manage' );
216 $line{'firstname'} = $shelflist->{$element}->{'firstname'}
217 unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
218 $line{'surname'} = $shelflist->{$element}->{'surname'}
219 unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
220 push( @shelvesloop, \%line );
223 $template->param(
224 shelvesloop => \@shelvesloop,
225 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
228 output_html_with_http_headers $query, $cookie, $template->output;
233 # $Log$
234 # Revision 1.12 2007/04/24 13:54:29 hdl
235 # functions that were in C4::Interface::CGI::Output are now in C4::Output.
236 # So this implies quite a change for files.
237 # Sorry about conflicts which will be caused.
238 # directory Interface::CGI should now be dropped.
239 # I noticed that many scripts (reports ones, but also some circ/stats.pl or opac-topissues) still use Date::Manip.
241 # Revision 1.11 2007/04/17 08:52:19 tipaul
242 # circulation cleaning continued: bufixing
244 # Revision 1.10 2007/04/04 16:46:23 tipaul
245 # HUGE COMMIT : code cleaning circulation.
247 # some stuff to do, i'll write a mail on koha-devel NOW !
249 # Revision 1.9 2007/03/09 15:12:54 tipaul
250 # rel_3_0 moved to HEAD
252 # Revision 1.8.2.12 2007/01/15 17:19:30 toins
253 # enable to add checked items to a shelf.
254 # Some display enhancements.
256 # Revision 1.8.2.11 2007/01/10 10:52:58 toins
257 # adding syspref directly to Auth.pm instead of to the template.
259 # Revision 1.8.2.10 2007/01/10 10:12:48 toins
260 # Adding OpacTopissue, OpacCloud, OpacAuthorithies to the template->param.
261 # + Some cleanup.
263 # Revision 1.8.2.9 2006/12/15 17:43:24 toins
264 # sync with intranet.
266 # Revision 1.8.2.8 2006/12/14 17:59:17 toins
267 # add the link to "BiblioDefaultView systempref" and not to opac-detail.pl
269 # Revision 1.8.2.7 2006/12/14 17:22:55 toins
270 # virtualshelves work perfectly with mod_perl and are cleaned.
272 # Revision 1.8.2.6 2006/12/14 16:04:25 toins
273 # sync with intranet.
275 # Revision 1.8.2.5 2006/12/11 17:10:06 toins
276 # fixing some bugs on virtualshelves.
278 # Revision 1.8.2.4 2006/12/07 15:42:15 toins
279 # synching opac & intranet.
280 # fix some broken link & bugs.
281 # removing warn compilation.
283 # Revision 1.8.2.3 2006/11/30 18:23:51 toins
284 # theses scripts don't need to use C4::Search.