Bug 8020 [3.8.x/MASTER] - update git build script to 3.9
[koha.git] / rotating_collections / addItems.pl
blobae7070f8660ea83778f69a576d92384eadd59086
1 #!/usr/bin/perl
3 # This file is part of Koha.
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.
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.
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
19 use strict;
20 #use warnings; FIXME - Bug 2505
21 require Exporter;
23 use C4::Output;
24 use C4::Auth;
25 use C4::Context;
26 use C4::RotatingCollections;
27 use C4::Items;
29 use CGI;
31 my $query = new CGI;
32 my ($template, $loggedinuser, $cookie)
33 = get_template_and_user({template_name => "rotating_collections/addItems.tmpl",
34 query => $query,
35 type => "intranet",
36 authnotrequired => 0,
37 flagsrequired => {parameters => 1},
38 debug => 1,
39 });
41 if ( $query->param('action') eq 'addItem' ) {
42 ## Add the given item to the collection
43 my $colId = $query->param('colId');
44 my $barcode = $query->param('barcode');
45 my $removeItem = $query->param('removeItem');
46 my $itemnumber = GetItemnumberFromBarcode( $barcode );
48 my ( $success, $errorCode, $errorMessage );
50 if ( ! $removeItem ) {
51 ( $success, $errorCode, $errorMessage ) = AddItemToCollection( $colId, $itemnumber );
53 $template->param(
54 previousActionAdd => 1,
55 addedBarcode => $barcode,
58 if ( $success ) {
59 $template->param( addSuccess => 1 );
60 } else {
61 $template->param( addFailure => 1 );
62 $template->param( failureMessage => $errorMessage );
64 } else {
65 ## Remove the given item from the collection
66 ( $success, $errorCode, $errorMessage ) = RemoveItemFromCollection( $colId, $itemnumber );
68 $template->param(
69 previousActionRemove => 1,
70 removedBarcode => $barcode,
71 removeChecked => 1,
74 if ( $success ) {
75 $template->param( removeSuccess => 1 );
76 } else {
77 $template->param( removeFailure => 1 );
78 $template->param( failureMessage => $errorMessage );
84 my ( $colId, $colTitle, $colDescription, $colBranchcode ) = GetCollection( $query->param('colId') );
85 my $collectionItems = GetItemsInCollection( $colId );
86 if ( $collectionItems ) {
87 $template->param( collectionItemsLoop => $collectionItems );
90 $template->param(
91 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
92 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
93 IntranetNav => C4::Context->preference("IntranetNav"),
95 colId => $colId,
96 colTitle => $colTitle,
97 colDescription => $colDescription,
98 colBranchcode => $colBranchcode,
101 output_html_with_http_headers $query, $cookie, $template->output;