Bug 7460: Add template toolkit's FILTER html_line_break on opac details description...
[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 strict;
20 #use warnings; FIXME - Bug 2505
21 require Exporter;
22
23 use C4::Output;
24 use C4::Auth;
25 use C4::Context;
26 use C4::RotatingCollections;
27 use C4::Items;
28
29 use CGI;
30
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                              });
40
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 );
47
48   my ( $success, $errorCode, $errorMessage );
49   
50   if ( ! $removeItem ) {
51     ( $success, $errorCode, $errorMessage ) = AddItemToCollection( $colId, $itemnumber );
52
53     $template->param(
54       previousActionAdd => 1,
55       addedBarcode => $barcode,
56     );
57
58     if ( $success ) {
59       $template->param( addSuccess => 1 );
60     } else {
61       $template->param( addFailure => 1 );
62       $template->param( failureMessage => $errorMessage );
63     }
64   } else {
65     ## Remove the given item from the collection
66     ( $success, $errorCode, $errorMessage ) = RemoveItemFromCollection( $colId, $itemnumber );
67
68     $template->param(
69       previousActionRemove => 1,
70       removedBarcode => $barcode,
71       removeChecked => 1,
72     );
73
74     if ( $success ) {
75       $template->param( removeSuccess => 1 );
76     } else {
77       $template->param( removeFailure => 1 );
78       $template->param( failureMessage => $errorMessage );
79     }
80
81   }  
82 }
83
84 my ( $colId, $colTitle, $colDescription, $colBranchcode ) = GetCollection( $query->param('colId') );
85 my $collectionItems = GetItemsInCollection( $colId );
86 if ( $collectionItems ) {
87   $template->param( collectionItemsLoop => $collectionItems );
88 }
89
90 $template->param(
91                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
92                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
93                 IntranetNav => C4::Context->preference("IntranetNav"),
94                                   
95                 colId => $colId,
96                 colTitle => $colTitle,
97                 colDescription => $colDescription,
98                 colBranchcode => $colBranchcode,
99                 );
100
101 output_html_with_http_headers $query, $cookie, $template->output;