Bug 27002: Update Koha::Biblio->pickup_locations to return a resultset
[koha.git] / labels / label-edit-profile.pl
blob3569f574fc0e588e496ac6ce70a7ffb4c58f6f0e
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
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>.
21 use Modern::Perl;
23 use CGI qw ( -utf8 );
25 use C4::Auth qw(get_template_and_user);
26 use C4::Output qw(output_html_with_http_headers);
27 use C4::Creators;
28 use C4::Labels;
30 my $cgi = CGI->new;
31 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
33 template_name => "labels/label-edit-profile.tt",
34 query => $cgi,
35 type => "intranet",
36 flagsrequired => { catalogue => 1 },
37 debug => 1,
41 my $op = $cgi->param('op');
42 my $profile_id = $cgi->param('profile_id') || $cgi->param('element_id');
43 my $profile = undef;
44 my $template_list = undef;
45 my @label_template = ();
47 my $units = get_unit_values();
49 if ($op eq 'edit') {
50 $profile = C4::Labels::Profile->retrieve(profile_id => $profile_id);
51 $template_list = get_all_templates( { fields => [ qw( template_id template_code profile_id) ] } );
53 elsif ($op eq 'save') {
54 my @params = (
55 printer_name => scalar $cgi->param('printer_name') || 'DEFAULT PRINTER',
56 paper_bin => scalar $cgi->param('paper_bin') || 'Tray 1',
57 offset_horz => scalar $cgi->param('offset_horz') || 0,
58 offset_vert => scalar $cgi->param('offset_vert') || 0,
59 creep_horz => scalar $cgi->param('creep_horz') || 0,
60 creep_vert => scalar $cgi->param('creep_vert') || 0,
61 units => scalar $cgi->param('units') || 'POINT',
63 if ($profile_id) { # if a label_id was passed in, this is an update to an existing layout
64 $profile = C4::Labels::Profile->retrieve(profile_id => $profile_id);
65 $profile->set_attr(@params);
66 $profile->save();
68 else { # if no label_id, this is a new layout so insert it
69 $profile = C4::Labels::Profile->new(@params);
70 $profile->save();
72 print $cgi->redirect("label-manage.pl?label_element=profile");
73 exit;
75 else { # if we get here, this is a new layout
76 $profile = C4::Labels::Profile->new();
79 if ($profile_id) {
80 @label_template = grep {
81 ($_->{'profile_id'} == $profile->get_attr('profile_id')) && ($_->{'template_id'} == $profile->get_attr('template_id'));
82 } @$template_list;
85 foreach my $unit (@$units) {
86 if ($unit->{'type'} eq $profile->get_attr('units')) {
87 $unit->{'selected'} = 1;
91 $template->param(profile_id => $profile->get_attr('profile_id')) if $profile->get_attr('profile_id') > 0;
93 $template->param(
94 label_template => $label_template[0]->{'template_code'} || '',
95 printer_name => $profile->get_attr('printer_name'),
96 paper_bin => $profile->get_attr('paper_bin'),
97 offset_horz => $profile->get_attr('offset_horz'),
98 offset_vert => $profile->get_attr('offset_vert'),
99 creep_horz => $profile->get_attr('creep_horz'),
100 creep_vert => $profile->get_attr('creep_vert'),
101 units => $units,
102 op => $op,
105 output_html_with_http_headers $cgi, $cookie, $template->output;