Bug 22970: Allow to change homebranch in batch add course reserves
[koha.git] / rotating_collections / addItems.pl
blob4c79328f3f472b09ef1db1f59a047272ae6c7b6e
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 use Modern::Perl;
21 use C4::Output;
22 use C4::Auth;
23 use C4::Context;
24 use C4::RotatingCollections;
25 use C4::Items;
27 use Koha::Items;
29 use CGI qw ( -utf8 );
31 my $query = new CGI;
33 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
35 template_name => "rotating_collections/addItems.tt",
36 query => $query,
37 type => "intranet",
38 authnotrequired => 0,
39 flagsrequired => { tools => 'rotating_collections' },
40 debug => 1,
44 if ( defined $query->param('action') and
45 $query->param('action') eq 'addItem' ) {
46 ## Add the given item to the collection
47 my $colId = $query->param('colId');
48 my $barcode = $query->param('barcode');
49 my $removeItem = $query->param('removeItem');
50 my $item = Koha::Items->find({barcode => $barcode});
51 my $itemnumber = $item ? $item->itemnumber : undef;
53 my ( $success, $errorCode, $errorMessage );
55 $template->param( barcode => $barcode );
57 if ( !$removeItem ) {
58 ( $success, $errorCode, $errorMessage ) =
59 AddItemToCollection( $colId, $itemnumber );
61 $template->param(
62 previousActionAdd => 1,
65 if ($success) {
66 $template->param( addSuccess => 1 );
68 else {
69 $template->param( addFailure => 1 );
70 $template->param( failureMessage => $errorMessage );
73 else {
74 ## Remove the given item from the collection
75 ( $success, $errorCode, $errorMessage ) =
76 RemoveItemFromCollection( $colId, $itemnumber );
78 $template->param(
79 previousActionRemove => 1,
80 removeChecked => 1,
83 if ($success) {
84 $template->param( removeSuccess => 1 );
86 else {
87 $template->param( removeFailure => 1 );
88 $template->param( failureMessage => $errorMessage );
94 my ( $colId, $colTitle, $colDescription, $colBranchcode ) =
95 GetCollection( scalar $query->param('colId') );
96 my $collectionItems = GetItemsInCollection($colId);
97 if ($collectionItems) {
98 $template->param( collectionItemsLoop => $collectionItems );
101 $template->param(
102 colId => $colId,
103 colTitle => $colTitle,
104 colDescription => $colDescription,
105 colBranchcode => $colBranchcode,
108 output_html_with_http_headers $query, $cookie, $template->output;