Bug 13522: Make it explicit that scalar containd a hash ref
[koha.git] / patroncards / manage.pl
blob2c13a4e62abc5c659cfdf441c2a272abc6595e19
1 #!/usr/bin/perl
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
11 # version.
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
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 use strict;
22 use warnings;
23 use vars qw($debug);
25 use CGI;
26 use autouse 'Data::Dumper' => qw(Dumper);
28 use C4::Auth qw(get_template_and_user);
29 use C4::Output qw(output_html_with_http_headers);
30 use C4::Creators;
31 use C4::Patroncards;
32 use C4::Labels;
34 my $cgi = new CGI;
35 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37 template_name => "patroncards/manage.tt",
38 query => $cgi,
39 type => "intranet",
40 authnotrequired => 0,
41 flagsrequired => { catalogue => 1 },
42 debug => 1,
46 my $op = $cgi->param('op') || 'none';
47 my $card_element = $cgi->param('card_element') || 'template'; # default to template managment
48 my $element_id = $cgi->param('element_id') || 0; # there should never be an element with a id of 0 so this is a safe default
50 my $db_rows = {};
51 my $display_columns = { layout => [ # db column => {col label is link?
52 {layout_id => {label => 'Layout ID', link_field => 0}},
53 {layout_name => {label => 'Layout', link_field => 0}},
54 #{layout_xml => {label => 'Layout XML', link_field => 0}},
55 {select => {label => 'Select', value => 'layout_id'}},
57 template => [ {template_id => {label => 'Template ID', link_field => 0}},
58 {template_code => {label => 'Template Name', link_field => 0}},
59 {template_desc => {label => 'Description', link_field => 0}},
60 {select => {label => 'Select', value => 'template_id'}},
62 profile => [ {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 corrisponding db column in the profile table, hence the underscore
66 {select => {label => 'Select', value => 'profile_id'}},
68 batch => [ {batch_id => {label => 'Batch ID', link_field => 0}},
69 {_item_count => {label => 'Item Count', link_field => 0}},
70 {select => {label => 'Select', value => 'batch_id'}},
74 my $errstr = ($cgi->param('error') ? $cgi->param('error') : '');
75 my $branch_code = ($card_element eq 'batch' ? C4::Context->userenv->{'branch'} : '');
77 if ($op eq 'delete') {
78 my $err = 0;
79 if ($card_element eq 'layout') {$err = C4::Patroncards::Layout::delete(layout_id => $element_id);}
80 elsif ($card_element eq 'template') {$err = C4::Patroncards::Template::delete(template_id => $element_id);}
81 elsif ($card_element eq 'profile') {$err = C4::Patroncards::Profile::delete(profile_id => $element_id);}
82 elsif ($card_element eq 'batch') {$err = C4::Labels::Batch::delete(batch_id => $element_id, branch_code => $branch_code);}
83 else {warn sprintf("Unknown card element passed in for delete operation: %s.",$card_element); $errstr = 202;}
84 print $cgi->redirect("manage.pl?card_element=$card_element" . ($err ? "&error=102" : ''));
85 exit;
87 elsif ($op eq 'none') {
88 if ($card_element eq 'layout') {$db_rows = get_all_layouts(table_name => 'creator_layouts', filter => 'creator=\'Patroncards\'');}
89 elsif ($card_element eq 'template') {$db_rows = get_all_templates(table_name => 'creator_templates', filter => 'creator=\'Patroncards\'');}
90 elsif ($card_element eq 'profile') {$db_rows = get_all_profiles(table_name => 'printers_profile', filter => 'creator=\'Patroncards\'');}
91 elsif ($card_element eq 'batch') {$db_rows = get_batch_summary(filter => "branch_code=\'$branch_code\' OR branch_code=\'NB\'", creator => 'Patroncards');}
92 else {warn sprintf("Unknown card element passed in: %s.",$card_element); $errstr = 202;}
94 else { # trap unsupported operations here
95 warn sprintf('Manage interface called an unsupported operation: %s',$op);
96 print $cgi->redirect("manage.pl?card_element=$card_element&error=201");
97 exit;
100 my $table = html_table($display_columns->{$card_element}, $db_rows);
102 $template->param(print => 1) if ($card_element eq 'batch');
103 $template->param(
104 error => $errstr,
106 $template->param(
107 op => $op,
108 element_id => $element_id,
109 table_loop => $table,
110 card_element => $card_element,
111 card_element_title => ($card_element eq 'layout' ? 'Layouts' :
112 $card_element eq 'template' ? 'Templates' :
113 $card_element eq 'profile' ? 'Profiles' :
114 $card_element eq 'batch' ? 'Batches' :
119 output_html_with_http_headers $cgi, $cookie, $template->output;