3 # Copyright 2006 Katipo Communications.
4 # Parts Copyright 2009 Foundations Bible College.
6 # This file is part of Koha.
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
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.
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
25 use Sys::Syslog qw(syslog);
28 use HTML::Template::Pro;
35 use C4::Branch qw(get_branch_code_from_name);
37 use C4::Labels::Lib 1.000000 qw(get_label_summary html_table);
38 use C4::Labels::Batch 1.000000;
41 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43 template_name => "labels/label-edit-batch.tmpl",
47 flagsrequired => { catalogue => 1 },
55 my $display_columns = [ {_label_number => {label => 'Label Number', link_field => 0}},
56 {_summary => {label => 'Summary', link_field => 0}},
57 {_item_type => {label => 'Item Type', link_field => 0}},
58 {_barcode => {label => 'Barcode', link_field => 0}},
59 {select => {label => 'Select', value => '_label_id'}},
61 my $op = $cgi->param('op') || undef;
62 my @label_ids = $cgi->param('label_id') if $cgi->param('label_id');
63 my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || undef;
64 my @item_numbers = $cgi->param('item_number') if $cgi->param('item_number');
65 my $branch_code = get_branch_code_from_name($template->param('LoginBranchname'));
67 if ($op eq 'remove') {
68 $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
69 foreach my $label_id (@label_ids) {
70 $err = $batch->remove_item($label_id);
72 $errstr = "item(s) not removed from batch $batch_id." if $err;
73 # Something like this would be nice to avoid problems with the browser's 'refresh' button, but it needs an error handling mechanism...
74 # print $cgi->redirect("label-edit-batch.pl?op=edit&batch_id=$batch_id");
77 elsif ($op eq 'delete') {
78 $err = C4::Labels::Batch::delete(batch_id => $batch_id, branch_code => $branch_code);
79 $errstr = "batch $batch_id was not deleted." if $err;
81 elsif ($op eq 'add') {
82 $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
83 $batch = C4::Labels::Batch->new(branch_code => $branch_code) if $batch == -2;
84 foreach my $item_number (@item_numbers) {
85 $err = $batch->add_item($item_number);
87 $errstr = "item(s) not added to batch $batch_id." if $err;
89 elsif ($op eq 'new') {
90 $batch = C4::Labels::Batch->new(branch_code => $branch_code);
91 $batch_id = $batch->get_attr('batch_id');
93 else { # display batch
94 $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
97 my $items = $batch->get_attr('items');
98 $db_rows = get_label_summary(items => $items, batch_id => $batch_id);
100 my $table = html_table($display_columns, $db_rows);
102 $template->param( err => $err,
107 batch_id => $batch_id,
108 table_loop => $table,
111 output_html_with_http_headers $cgi, $cookie, $template->output;