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;
34 use autouse 'C4::Branch' => qw(get_branch_code_from_name);
36 use C4::Labels::Lib 1.000000 qw(get_all_templates get_all_layouts get_all_profiles get_batch_summary html_table);
37 use C4::Labels::Layout 1.000000;
38 use C4::Labels::Template 1.000000;
39 use C4::Labels::Profile 1.000000;
40 use C4::Labels::Batch 1.000000;
43 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45 template_name => "labels/label-manage.tmpl",
49 flagsrequired => { catalogue => 1 },
56 my $display_columns = { layout => [ #db column => display column
57 {layout_id => 'Layout ID'},
58 {layout_name => 'Layout'},
59 {barcode_type => 'Barcode Type'},
60 {printing_type => 'Print Type'},
61 {format_string => 'Fields to Print'},
62 {select => {label => 'Select', value => 'layout_id'}},
64 template => [ {template_id => 'Template ID'},
65 {template_code => 'Template Name'},
66 {template_desc => 'Description'},
67 {select => {label => 'Select', value => 'template_id'}},
69 profile => [ {profile_id => 'Profile ID'},
70 {printer_name => 'Printer Name'},
71 {paper_bin => 'Paper Bin'},
72 {_template_code => 'Template Name'}, # this display column does not have a corrisponding db column in the profile table, hence the underscore
73 {select => {label => 'Select', value => 'profile_id'}},
75 batch => [ {batch_id => 'Batch ID'},
76 {_item_count => 'Item Count'},
77 {select => {label => 'Select', value => 'batch_id'}},
81 my $label_element = $cgi->param('label_element') || $ARGV[0];
82 my $op = $cgi->param('op') || $ARGV[1] || '';
83 my $element_id = $cgi->param('element_id') || $ARGV[2] || '';
84 my $branch_code = ($label_element eq 'batch' ? get_branch_code_from_name($template->param('LoginBranchname')) : '');
86 if ($op eq 'delete') {
87 given ($label_element) {
88 when 'layout' {$error = C4::Labels::Layout::delete(layout_id => $element_id); last;}
89 when 'template' {$error = C4::Labels::Template::delete(template_id => $element_id); last;}
90 when 'profile' {$error = C4::Labels::Profile::delete(profile_id => $element_id); last;}
91 when 'batch' {$error = C4::Labels::Batch::delete(batch_id => $element_id, branch_code => $branch_code); last;}
92 default {} # FIXME: Some error trapping code
94 # FIXME: this does not allow us to process any errors
95 # print $cgi->redirect("label-manage.pl?label_element=$label_element");
99 given ($label_element) {
100 when 'layout' {$db_rows = get_all_layouts();}
101 when 'template' {$db_rows = get_all_templates();}
102 when 'profile' {$db_rows = get_all_profiles();}
103 when 'batch' {$db_rows = get_batch_summary(filter => "branch_code=\'$branch_code\'");}
104 default {} # FIXME: Some error trapping code
107 my $table = html_table($display_columns->{$label_element}, $db_rows);
109 $template->param(error => $error) if ($error ne 0);
110 $template->param(print => 1) if ($label_element eq 'batch');
113 element_id => $element_id,
114 table_loop => $table,
115 label_element => $label_element,
116 label_element_title => ($label_element eq 'layout' ? 'Layouts' :
117 $label_element eq 'template' ? 'Templates' :
118 $label_element eq 'profile' ? 'Profiles' :
119 $label_element eq 'batch' ? 'Batches' :
124 output_html_with_http_headers $cgi, $cookie, $template->output;