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

(-)a/admin/branches.pl (-11 / +60 lines)
Lines 19-34 Link Here
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
20
21
use Modern::Perl;
21
use Modern::Perl;
22
22
use CGI qw ( -utf8 );
23
use CGI qw ( -utf8 );
24
use Try::Tiny;
25
23
use C4::Auth;
26
use C4::Auth;
24
use C4::Context;
27
use C4::Context;
25
use C4::Output;
28
use C4::Output;
26
use C4::Koha;
29
use C4::Koha;
30
31
use Koha::Database;
27
use Koha::Patrons;
32
use Koha::Patrons;
28
use Koha::Items;
33
use Koha::Items;
29
use Koha::Libraries;
34
use Koha::Libraries;
35
use Koha::SMTP::Servers;
30
36
31
my $input        = new CGI;
37
my $input        = CGI->new;
32
my $branchcode   = $input->param('branchcode');
38
my $branchcode   = $input->param('branchcode');
33
my $categorycode = $input->param('categorycode');
39
my $categorycode = $input->param('categorycode');
34
my $op           = $input->param('op') || 'list';
40
my $op           = $input->param('op') || 'list';
Lines 47-56 if ( $op eq 'add_form' ) { Link Here
47
    my $library;
53
    my $library;
48
    if ($branchcode) {
54
    if ($branchcode) {
49
        $library = Koha::Libraries->find($branchcode);
55
        $library = Koha::Libraries->find($branchcode);
56
        $template->param( selected_smtp_server => $library->smtp_server );
50
    }
57
    }
51
58
59
    my @smtp_servers = Koha::SMTP::Servers->search;
60
52
    $template->param(
61
    $template->param(
53
        library    => $library,
62
        library      => $library,
63
        smtp_servers => \@smtp_servers
54
    );
64
    );
55
} elsif ( $op eq 'add_validate' ) {
65
} elsif ( $op eq 'add_validate' ) {
56
    my @fields = qw(
66
    my @fields = qw(
Lines 82-92 if ( $op eq 'add_form' ) { Link Here
82
        for my $field (@fields) {
92
        for my $field (@fields) {
83
            $library->$field( scalar $input->param($field) );
93
            $library->$field( scalar $input->param($field) );
84
        }
94
        }
85
        eval { $library->store; };
95
86
        if ($@) {
96
        try {
97
            Koha::Database->new->schema->txn_do(
98
                sub {
99
                    $library->store->discard_changes;
100
                    # Deal with SMTP server
101
                    my $smtp_server_id = $input->param('smtp_server');
102
103
                    if ( $smtp_server_id ) {
104
                        if ( $smtp_server_id eq '*' ) {
105
                            $library->smtp_server({ smtp_server => undef });
106
                        }
107
                        else {
108
                            my $smtp_server = Koha::SMTP::Servers->find( $smtp_server_id );
109
                            Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' )
110
                                unless $smtp_server;
111
                            $library->smtp_server({ smtp_server => $smtp_server });
112
                        }
113
                    }
114
115
                    push @messages, { type => 'message', code => 'success_on_update' };
116
                }
117
            );
118
        }
119
        catch {
87
            push @messages, { type => 'alert', code => 'error_on_update' };
120
            push @messages, { type => 'alert', code => 'error_on_update' };
88
        } else {
89
            push @messages, { type => 'message', code => 'success_on_update' };
90
        }
121
        }
91
    } else {
122
    } else {
92
        $branchcode =~ s|\s||g;
123
        $branchcode =~ s|\s||g;
Lines 95-106 if ( $op eq 'add_form' ) { Link Here
95
                ( map { $_ => scalar $input->param($_) || undef } @fields )
126
                ( map { $_ => scalar $input->param($_) || undef } @fields )
96
            }
127
            }
97
        );
128
        );
98
        eval { $library->store; };
129
99
        if ($@) {
130
        try {
100
            push @messages, { type => 'alert', code => 'error_on_insert' };
131
            Koha::Database->new->schema->txn_do(
101
        } else {
132
                sub {
102
            push @messages, { type => 'message', code => 'success_on_insert' };
133
                    $library->store->discard_changes;
134
135
                    my $smtp_server_id = $input->param('smtp_server');
136
137
                    if ( $smtp_server_id ) {
138
                        if ( $smtp_server_id ne '*' ) {
139
                            my $smtp_server = Koha::SMTP::Servers->find( $smtp_server_id );
140
                            Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' )
141
                                unless $smtp_server;
142
                            $library->smtp_server({ smtp_server => $smtp_server });
143
                        }
144
                    }
145
146
                    push @messages, { type => 'message', code => 'success_on_insert' };
147
                }
148
            );
103
        }
149
        }
150
        catch {
151
            push @messages, { type => 'alert', code => 'error_on_insert' };
152
        };
104
    }
153
    }
105
    $op = 'list';
154
    $op = 'list';
106
} elsif ( $op eq 'delete_confirm' ) {
155
} elsif ( $op eq 'delete_confirm' ) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-1 / +16 lines)
Lines 141-146 Link Here
141
                <li><label for="branchemail">Email: </label><input type="text" name="branchemail" id="branchemail" class="email"  size="80" value="[% library.branchemail | html %]" /></li>
141
                <li><label for="branchemail">Email: </label><input type="text" name="branchemail" id="branchemail" class="email"  size="80" value="[% library.branchemail | html %]" /></li>
142
                <li><label for="branchreplyto">Reply-To: </label> <input type="text" name="branchreplyto" id="branchreplyto" class="email"  size="80" value="[% library.branchreplyto | html %]" /><br /><span class="hint">Default: ReplyToDefault system preference</span></li>
142
                <li><label for="branchreplyto">Reply-To: </label> <input type="text" name="branchreplyto" id="branchreplyto" class="email"  size="80" value="[% library.branchreplyto | html %]" /><br /><span class="hint">Default: ReplyToDefault system preference</span></li>
143
                <li><label for="branchreturnpath">Return-Path: </label> <input type="text" name="branchreturnpath" id="branchreturnpath" class="email"  size="80" value="[% library.branchreturnpath | html %]" /><br /><span class="hint">Default: ReturnpathDefault system preference</span></li>
143
                <li><label for="branchreturnpath">Return-Path: </label> <input type="text" name="branchreturnpath" id="branchreturnpath" class="email"  size="80" value="[% library.branchreturnpath | html %]" /><br /><span class="hint">Default: ReturnpathDefault system preference</span></li>
144
                <li><label for="smtp_server">SMTP server: </label>
145
                    <select name="smtp_server" id="smtp_server">
146
                    [% IF selected_smtp_server.is_system_default %]
147
                        <option value="*" selected="selected">Default</option>
148
                    [% ELSE %]
149
                        <option value="*">Default</option>
150
                    [% END %]
151
                    [% FOREACH smtp_server IN smtp_servers %]
152
                        [% IF smtp_server.id == selected_smtp_server.id %]
153
                            <option value="[% smtp_server.id | html %]" selected="selected">[% smtp_server.name | html %]</option>
154
                        [% ELSE %]
155
                            <option value="[% smtp_server.id | html %]">[% smtp_server.name | html %]</option>
156
                        [% END %]
157
                    [% END %]
158
                    </select>
159
                </li>
144
                <li><label for="branchurl">URL: </label><input type="text" name="branchurl" id="branchurl"  size="80" value="[% library.branchurl | html %]" class="url" /></li>
160
                <li><label for="branchurl">URL: </label><input type="text" name="branchurl" id="branchurl"  size="80" value="[% library.branchurl | html %]" class="url" /></li>
145
                <li><label for="opac_info">OPAC info: </label><textarea name="opac_info" id="opac_info">[% library.opac_info | $raw %]</textarea></li>
161
                <li><label for="opac_info">OPAC info: </label><textarea name="opac_info" id="opac_info">[% library.opac_info | $raw %]</textarea></li>
146
                <li><label for="branchip">IP: </label><input type="text" name="branchip" id="branchip"  size="15" maxlength="15" value="[% library.branchip | html %]" /> <span class="hint">Can be entered as a single IP, or a subnet such as 192.168.1.*</span></li>
162
                <li><label for="branchip">IP: </label><input type="text" name="branchip" id="branchip"  size="15" maxlength="15" value="[% library.branchip | html %]" /> <span class="hint">Can be entered as a single IP, or a subnet such as 192.168.1.*</span></li>
147
- 

Return to bug 22343