Bug 13695: Add ISBD export option to OPAC (detail)
[koha.git] / rotating_collections / addItems.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17 #
18
19 use Modern::Perl;
20
21 use C4::Output;
22 use C4::Auth;
23 use C4::Context;
24 use C4::RotatingCollections;
25 use C4::Items;
26
27 use CGI qw ( -utf8 );
28
29 my $query = new CGI;
30
31 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
32     {
33         template_name   => "rotating_collections/addItems.tt",
34         query           => $query,
35         type            => "intranet",
36         authnotrequired => 0,
37         flagsrequired   => { tools => 'rotating_collections' },
38         debug           => 1,
39     }
40 );
41
42 if ( $query->param('action') eq 'addItem' ) {
43     ## Add the given item to the collection
44     my $colId      = $query->param('colId');
45     my $barcode    = $query->param('barcode');
46     my $removeItem = $query->param('removeItem');
47     my $itemnumber = GetItemnumberFromBarcode($barcode);
48
49     my ( $success, $errorCode, $errorMessage );
50
51     $template->param( barcode => $barcode );
52
53     if ( !$removeItem ) {
54         ( $success, $errorCode, $errorMessage ) =
55           AddItemToCollection( $colId, $itemnumber );
56
57         $template->param(
58             previousActionAdd => 1,
59         );
60
61         if ($success) {
62             $template->param( addSuccess => 1 );
63         }
64         else {
65             $template->param( addFailure     => 1 );
66             $template->param( failureMessage => $errorMessage );
67         }
68     }
69     else {
70         ## Remove the given item from the collection
71         ( $success, $errorCode, $errorMessage ) =
72           RemoveItemFromCollection( $colId, $itemnumber );
73
74         $template->param(
75             previousActionRemove => 1,
76             removeChecked        => 1,
77         );
78
79         if ($success) {
80             $template->param( removeSuccess => 1 );
81         }
82         else {
83             $template->param( removeFailure  => 1 );
84             $template->param( failureMessage => $errorMessage );
85         }
86
87     }
88 }
89
90 my ( $colId, $colTitle, $colDescription, $colBranchcode ) =
91   GetCollection( $query->param('colId') );
92 my $collectionItems = GetItemsInCollection($colId);
93 if ($collectionItems) {
94     $template->param( collectionItemsLoop => $collectionItems );
95 }
96
97 $template->param(
98     colId          => $colId,
99     colTitle       => $colTitle,
100     colDescription => $colDescription,
101     colBranchcode  => $colBranchcode,
102 );
103
104 output_html_with_http_headers $query, $cookie, $template->output;