Merge branch 'patroncards-wip' of git://git.foundations.edu/koha into community
[koha.git] / rotating_collections / addItems.pl
1 #!/usr/bin/perl
2 use strict;
3 require Exporter;
4
5 use C4::Output;
6 use C4::Auth;
7 use C4::Context;
8 use C4::RotatingCollections;
9 use C4::Items;
10
11 use CGI;
12
13 my $query = new CGI;
14 my ($template, $loggedinuser, $cookie)
15     = get_template_and_user({template_name => "rotating_collections/addItems.tmpl",
16                              query => $query,
17                              type => "intranet",
18                              authnotrequired => 1,
19                              flagsrequired => {parameters => 1},
20                              debug => 1,
21                              });
22
23 if ( $query->param('action') eq 'addItem' ) {
24   ## Add the given item to the collection
25   my $colId = $query->param('colId');
26   my $barcode = $query->param('barcode');
27   my $removeItem = $query->param('removeItem');
28   my $itemnumber = GetItemnumberFromBarcode( $barcode );
29
30   my ( $success, $errorCode, $errorMessage );
31   
32   if ( ! $removeItem ) {
33     ( $success, $errorCode, $errorMessage ) = AddItemToCollection( $colId, $itemnumber );
34
35     $template->param(
36       previousActionAdd => 1,
37       addedBarcode => $barcode,
38     );
39
40     if ( $success ) {
41       $template->param( addSuccess => 1 );
42     } else {
43       $template->param( addFailure => 1 );
44       $template->param( failureMessage => $errorMessage );
45     }
46   } else {
47     ## Remove the given item from the collection
48     ( $success, $errorCode, $errorMessage ) = RemoveItemFromCollection( $colId, $itemnumber );
49
50     $template->param(
51       previousActionRemove => 1,
52       removedBarcode => $barcode,
53       removeChecked => 1,
54     );
55
56     if ( $success ) {
57       $template->param( removeSuccess => 1 );
58     } else {
59       $template->param( removeFailure => 1 );
60       $template->param( failureMessage => $errorMessage );
61     }
62
63   }  
64 }
65
66 my ( $colId, $colTitle, $colDescription, $colBranchcode ) = GetCollection( $query->param('colId') );
67 my $collectionItems = GetItemsInCollection( $colId );
68 if ( $collectionItems ) {
69   $template->param( collectionItemsLoop => $collectionItems );
70 }
71
72 $template->param(
73                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
74                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
75                 IntranetNav => C4::Context->preference("IntranetNav"),
76                                   
77                 colId => $colId,
78                 colTitle => $colTitle,
79                 colDescription => $colDescription,
80                 colBranchcode => $colBranchcode,
81                 );
82
83 output_html_with_http_headers $query, $cookie, $template->output;