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
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 use C4::Auth qw( get_template_and_user );
26 use C4::Output qw( output_html_with_http_headers );
37 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39 template_name => "labels/label-manage.tt",
42 flagsrequired => { catalogue => 1 },
47 my $display_columns = { layout => [ # db column => {col label is link?
48 {layout_id => {label => 'Layout ID', link_field => 0}},
49 {layout_name => {label => 'Layout', link_field => 0}},
50 {barcode_type => {label => 'Barcode Type', link_field => 0}},
51 {printing_type => {label => 'Print Type', link_field => 0}},
52 {format_string => {label => 'Fields to Print',link_field => 0}},
53 {select => {label => 'Actions', value => 'layout_id'}},
56 {template_id => {label => 'Template ID', link_field => 0}},
57 {template_code => {label => 'Template Name', link_field => 0}},
58 {template_desc => {label => 'Description', link_field => 0}},
59 {select => {label => 'Actions', value => 'template_id'}},
62 {profile_id => {label => 'Profile ID', link_field => 0}},
63 {printer_name => {label => 'Printer Name', link_field => 0}},
64 {paper_bin => {label => 'Paper Bin', link_field => 0}},
65 {_template_code => {label => 'Template Name', link_field => 0}}, # this display column does not have a corresponding db column in the profile table, hence the underscore
66 {select => {label => 'Actions', value => 'profile_id'}},
69 {batch_id => {label => 'Batch ID', link_field => 0}},
70 {description => {label => 'Description', link_field => 0}},
71 {_item_count => {label => 'Item Count', link_field => 0}},
72 {select => {label => 'Actions', value => 'batch_id'}},
73 {select1 => {label => ' ', link_field => 'batch_id'}},
77 my $label_element = $cgi->param('label_element') || 'template'; # default to template management
78 my $op = $cgi->param('op') || 'none';
79 my $element_id = $cgi->param('element_id') || undef;
80 my $error = $cgi->param('error') || 0;
82 my $branch_code = ($label_element eq 'batch' ? C4::Context->userenv->{'branch'} : '');
84 if ($op eq 'delete') {
85 if ($label_element eq 'layout') {$error = C4::Labels::Layout::delete(layout_id => $element_id);}
86 elsif ($label_element eq 'template') {$error = C4::Labels::Template::delete(template_id => $element_id);}
87 elsif ($label_element eq 'profile') {$error = C4::Labels::Profile::delete(profile_id => $element_id);}
88 elsif ($label_element eq 'batch') {$error = C4::Labels::Batch::delete(batch_id => $element_id, branch_code => $branch_code);}
89 else {} # FIXME: Some error trapping code
92 if ($label_element eq 'layout') {$db_rows = get_all_layouts( { filters => { creator => 'Labels' } });}
93 elsif ($label_element eq 'template') {$db_rows = get_all_templates( { filters => { creator => 'Labels' } });}
94 elsif ($label_element eq 'profile') {$db_rows = get_all_profiles( { filters => { creator => 'Labels' } });}
95 elsif ($label_element eq 'batch') {$db_rows = get_batch_summary( { filters => { branch_code => [$branch_code, 'NB'], creator => 'Labels' } });}
96 else {} # FIXME: Some error trapping code
98 my $table = html_table($display_columns->{$label_element}, $db_rows);
100 $template->param(error => $error) if ($error) && ($error ne 0);
101 $template->param(print => 1) if ($label_element eq 'batch');
104 element_id => $element_id,
105 table_loop => $table,
106 label_element => $label_element,
107 label_element_title => (
108 $label_element eq 'layout' ? 'Layouts' :
109 $label_element eq 'template' ? 'Templates' :
110 $label_element eq 'profile' ? 'Profiles' :
111 $label_element eq 'batch' ? 'Batches' :
115 output_html_with_http_headers $cgi, $cookie, $template->output;