Bug 21334: Unit tests
[koha.git] / rotating_collections / addItems.pl
blob7d4fd644bb1a00d19cac9c30306e35d5c96a1192
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 ( $query->param('action') eq 'addItem' ) {
45 ## Add the given item to the collection
46 my $colId = $query->param('colId');
47 my $barcode = $query->param('barcode');
48 my $removeItem = $query->param('removeItem');
49 my $item = Koha::Items->find({barcode => $barcode});
50 my $itemnumber = $item ? $item->itemnumber : undef;
52 my ( $success, $errorCode, $errorMessage );
54 $template->param( barcode => $barcode );
56 if ( !$removeItem ) {
57 ( $success, $errorCode, $errorMessage ) =
58 AddItemToCollection( $colId, $itemnumber );
60 $template->param(
61 previousActionAdd => 1,
64 if ($success) {
65 $template->param( addSuccess => 1 );
67 else {
68 $template->param( addFailure => 1 );
69 $template->param( failureMessage => $errorMessage );
72 else {
73 ## Remove the given item from the collection
74 ( $success, $errorCode, $errorMessage ) =
75 RemoveItemFromCollection( $colId, $itemnumber );
77 $template->param(
78 previousActionRemove => 1,
79 removeChecked => 1,
82 if ($success) {
83 $template->param( removeSuccess => 1 );
85 else {
86 $template->param( removeFailure => 1 );
87 $template->param( failureMessage => $errorMessage );
93 my ( $colId, $colTitle, $colDescription, $colBranchcode ) =
94 GetCollection( $query->param('colId') );
95 my $collectionItems = GetItemsInCollection($colId);
96 if ($collectionItems) {
97 $template->param( collectionItemsLoop => $collectionItems );
100 $template->param(
101 colId => $colId,
102 colTitle => $colTitle,
103 colDescription => $colDescription,
104 colBranchcode => $colBranchcode,
107 output_html_with_http_headers $query, $cookie, $template->output;