View | Details | Raw Unified | Return to bug 14520
Collapse All | Expand All

(-)a/admin/currency.pl (-3 / +11 lines)
Lines 51-56 our $offset = $input->param('offset') || 0; Link Here
51
my $op          = $input->param('op')     || q{};
51
my $op          = $input->param('op')     || q{};
52
my $script_name = '/cgi-bin/koha/admin/currency.pl';
52
my $script_name = '/cgi-bin/koha/admin/currency.pl';
53
our $pagesize = 20;
53
our $pagesize = 20;
54
my @messages;
54
55
55
our ($template, $loggedinuser, $cookie) = get_template_and_user({
56
our ($template, $loggedinuser, $cookie) = get_template_and_user({
56
    template_name => 'admin/currency.tt',
57
    template_name => 'admin/currency.tt',
Lines 72-78 if ( $op eq 'add_form' ) { Link Here
72
    add_form($searchfield);
73
    add_form($searchfield);
73
} elsif ( $op eq 'save' ) {
74
} elsif ( $op eq 'save' ) {
74
    add_validate();
75
    add_validate();
75
    print $input->redirect('/cgi-bin/koha/admin/currency.pl');
76
    default_path();
76
} elsif ( $op eq 'delete_confirm' ) {
77
} elsif ( $op eq 'delete_confirm' ) {
77
    delete_confirm($searchfield);
78
    delete_confirm($searchfield);
78
} elsif ( $op eq 'delete_confirmed' ) {
79
} elsif ( $op eq 'delete_confirmed' ) {
Lines 107-112 sub default_path { Link Here
107
    $template->param(
108
    $template->param(
108
        loop           => \@display_curr,
109
        loop           => \@display_curr,
109
        activecurrency => defined $activecurrency,
110
        activecurrency => defined $activecurrency,
111
        messages       => \@messages,
110
    );
112
    );
111
113
112
    if ( $offset > 0 ) {
114
    if ( $offset > 0 ) {
Lines 174-179 sub add_form { Link Here
174
176
175
sub add_validate {
177
sub add_validate {
176
    $template->param( add_validate => 1 );
178
    $template->param( add_validate => 1 );
179
    my $is_a_modif = $input->param('is_a_modif');
177
180
178
    my $rec = {
181
    my $rec = {
179
        rate     => $input->param('rate'),
182
        rate     => $input->param('rate'),
Lines 190-196 sub add_validate { Link Here
190
    my ($row_count) = $dbh->selectrow_array(
193
    my ($row_count) = $dbh->selectrow_array(
191
        'select count(*) as count from currency where currency = ?',
194
        'select count(*) as count from currency where currency = ?',
192
        {}, $input->param('currency') );
195
        {}, $input->param('currency') );
193
    if ($row_count) {
196
    if ($row_count and $is_a_modif) {
194
        $dbh->do(
197
        $dbh->do(
195
q|UPDATE currency SET rate = ?, symbol = ?, isocode = ?, active = ? WHERE currency = ? |,
198
q|UPDATE currency SET rate = ?, symbol = ?, isocode = ?, active = ? WHERE currency = ? |,
196
            {},
199
            {},
Lines 200-206 q|UPDATE currency SET rate = ?, symbol = ?, isocode = ?, active = ? WHERE curren Link Here
200
            $rec->{active},
203
            $rec->{active},
201
            $rec->{currency}
204
            $rec->{currency}
202
        );
205
        );
203
    } else {
206
    } elsif (not $row_count and not $is_a_modif) {
204
        $dbh->do(
207
        $dbh->do(
205
q|INSERT INTO currency (currency, rate, symbol, isocode, active) VALUES (?,?,?,?,?) |,
208
q|INSERT INTO currency (currency, rate, symbol, isocode, active) VALUES (?,?,?,?,?) |,
206
            {},
209
            {},
Lines 211-216 q|INSERT INTO currency (currency, rate, symbol, isocode, active) VALUES (?,?,?,? Link Here
211
            $rec->{active}
214
            $rec->{active}
212
        );
215
        );
213
216
217
    } else {
218
            push @messages, {
219
                type => 'error',
220
                code => 'already_exists'
221
            };
214
    }
222
    }
215
    return;
223
    return;
216
}
224
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt (-1 / +15 lines)
Lines 68-73 Link Here
68
</div>
68
</div>
69
[% END %]
69
[% END %]
70
70
71
[% FOREACH message IN messages %]
72
    [% IF message.type == 'success' %]
73
        <div class="dialog message">
74
    [% ELSIF message.type == 'warning' %]
75
        <div class="dialog alert">
76
    [% ELSIF message.type == 'error' %]
77
        <div class="dialog error" style="margin:auto;">
78
    [% END %]
79
    [% IF message.code == 'already_exists' %]
80
        This currency already exists.
81
    [% END %]
82
 </div>
83
[% END %]
84
71
[% IF ( add_form ) %]
85
[% IF ( add_form ) %]
72
86
73
<form action="[% script_name %]" name="Aform" method="post" class="validated">
87
<form action="[% script_name %]" name="Aform" method="post" class="validated">
Lines 81-86 Link Here
81
    <ol>
95
    <ol>
82
        <li>
96
        <li>
83
    [% IF ( searchfield ) %]
97
    [% IF ( searchfield ) %]
98
            <input type="hidden" name="is_a_modif" value="1" />
84
            <span class="label">Currency: </span>
99
            <span class="label">Currency: </span>
85
            <input type="hidden" name="currency" id="currency" value="[% searchfield %]" />[% searchfield %]
100
            <input type="hidden" name="currency" id="currency" value="[% searchfield %]" />[% searchfield %]
86
    [% ELSE %]
101
    [% ELSE %]
87
- 

Return to bug 14520