Bug 5466 On new orders get currency from vendor
[koha.git] / patroncards / edit-profile.pl
1 #!/usr/bin/perl
2 #
3 # Copyright 2006 Katipo Communications.
4 # Parts Copyright 2009 Foundations Bible College.
5 #
6 # This file is part of Koha.
7 #
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.
12 #
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.
16 #
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.
20
21 use strict;
22 use warnings;
23
24 use CGI;
25
26 use C4::Auth qw(get_template_and_user);
27 use C4::Output qw(output_html_with_http_headers);
28 use C4::Creators::Lib 1.000000 qw(get_all_templates get_unit_values);
29 use C4::Patroncards::Profile 1.000000;
30
31 my $cgi = new CGI;
32 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
33     {
34         template_name   => "patroncards/edit-profile.tmpl",
35         query           => $cgi,
36         type            => "intranet",
37         authnotrequired => 0,
38         flagsrequired   => { catalogue => 1 },
39         debug           => 1,
40     }
41 );
42
43 my $op = $cgi->param('op') || '';
44 my $profile_id = $cgi->param('profile_id') || $cgi->param('element_id');
45 my $profile = undef;
46 my $template_list = undef;
47 my @label_template = ();
48
49 my $units = get_unit_values();
50
51 if ($op eq 'edit') {
52     $profile = C4::Patroncards::Profile->retrieve(profile_id => $profile_id);
53     $template_list = get_all_templates(table_name => 'creator_templates', field_list => 'template_id,template_code, profile_id');
54 }
55 elsif ($op eq 'save') {
56     my @params = (
57         printer_name        => $cgi->param('printer_name'),
58         paper_bin           => $cgi->param('paper_bin'),
59         offset_horz         => $cgi->param('offset_horz'),
60         offset_vert         => $cgi->param('offset_vert'),
61         creep_horz          => $cgi->param('creep_horz'),
62         creep_vert          => $cgi->param('creep_vert'),
63         units               => $cgi->param('units'),
64     );
65     if ($profile_id) {   # if a label_id was passed in, this is an update to an existing layout
66         $profile = C4::Patroncards::Profile->retrieve(profile_id => $profile_id);
67         $profile->set_attr(@params);
68         $profile->save();
69     }
70     else {      # if no label_id, this is a new layout so insert it
71         $profile = C4::Patroncards::Profile->new(@params);
72         $profile->save();
73     }
74     print $cgi->redirect("manage.pl?card_element=profile");
75     exit;
76 }
77 else {  # if we get here, this is a new layout
78     $profile = C4::Patroncards::Profile->new();
79 }
80
81 if ($profile_id) {
82     @label_template = grep{($_->{'profile_id'} == $profile->get_attr('profile_id')) && ($_->{'template_id'} == $profile->get_attr('template_id'))} @$template_list;
83 }
84
85 foreach my $unit (@$units) {
86     if ($unit->{'type'} eq $profile->get_attr('units')) {
87         $unit->{'selected'} = 1;
88     }
89 }
90
91 $template->param(profile_id => $profile->get_attr('profile_id')) if $profile->get_attr('profile_id') > 0;
92
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,
103 );
104
105 output_html_with_http_headers $cgi, $cookie, $template->output;