[17/40] Work on C4::Labels::Lib::html_table api to add link field option
[koha.git] / labels / label-edit-batch.pl
1 #!/usr/bin/perl
2 #
3 # Copyright 2006 Katipo Communications.
4 # Parts Copyright 2009 Foundations Bible College.
5 #
6 # This file is part of Koha.
7 #       
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 use strict;
22 use warnings;
23 use vars qw($debug);
24
25 use Sys::Syslog qw(syslog);
26 use Switch qw(Perl6);
27 use CGI;
28 use HTML::Template::Pro;
29 use Data::Dumper;
30
31 use C4::Auth;
32 use C4::Output;
33 use C4::Context;
34 use C4::Branch qw(get_branch_code_from_name);
35 use C4::Debug;
36 use C4::Labels::Lib 1.000000 qw(get_label_summary html_table);
37 use C4::Labels::Batch 1.000000;
38
39 my $cgi = new CGI;
40 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
41     {
42         template_name   => "labels/label-edit-batch.tmpl",
43         query           => $cgi,
44         type            => "intranet",
45         authnotrequired => 0,
46         flagsrequired   => { catalogue => 1 },
47         debug           => 1,
48     }
49 );
50 my $err = 0;
51 my $errstr = undef;
52 my $db_rows = {};
53 my $batch = undef;
54 my $display_columns = [ {_label_number  => {label => 'Label Number', link_field => 0}},
55                         {_summary       => {label => 'Summary', link_field => 0}},
56                         {_item_type     => {label => 'Item Type', link_field => 0}},
57                         {_barcode       => {label => 'Barcode', link_field => 0}},
58                         {select         => {label => 'Select', value => '_item_number'}},
59                       ];
60 my $op = $cgi->param('op') || undef;
61 my $label_id = $cgi->param('label_id') || undef;
62 my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || undef;
63 my $branch_code = get_branch_code_from_name($template->param('LoginBranchname'));
64
65 if ($op eq 'remove') {
66     $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
67     $err = $batch->remove_item($label_id);
68     $errstr = "item $label_id was not removed." if $err;
69 }
70 elsif ($op eq 'delete') {
71     $err = C4::Labels::Batch::delete(batch_id => $batch_id, branch_code => $branch_code);
72     $errstr = "batch $batch_id was not deleted." if $err;
73 }
74 else{
75     $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
76 }
77
78 my $items = $batch->get_attr('items');
79 $db_rows = get_label_summary(items => $items, batch_id => $batch_id);
80
81 my $table = html_table($display_columns, $db_rows);
82
83 $template->param(   err         => $err,
84                     errstr      => $errstr,
85                 ) if ($err ne 0);
86 $template->param(
87                 op              => $op,
88                 batch_id        => $batch_id,
89                 table_loop      => $table,
90 );
91
92 output_html_with_http_headers $cgi, $cookie, $template->output;