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 48-57 if ( $op eq 'add_form' ) { Link Here
48
    my $library;
54
    my $library;
49
    if ($branchcode) {
55
    if ($branchcode) {
50
        $library = Koha::Libraries->find($branchcode);
56
        $library = Koha::Libraries->find($branchcode);
57
        $template->param( selected_smtp_server => $library->smtp_server );
51
    }
58
    }
52
59
60
    my @smtp_servers = Koha::SMTP::Servers->search;
61
53
    $template->param(
62
    $template->param(
54
        library    => $library,
63
        library      => $library,
64
        smtp_servers => \@smtp_servers
55
    );
65
    );
56
} elsif ( $op eq 'add_validate' ) {
66
} elsif ( $op eq 'add_validate' ) {
57
    my @fields = qw(
67
    my @fields = qw(
Lines 83-93 if ( $op eq 'add_form' ) { Link Here
83
        for my $field (@fields) {
93
        for my $field (@fields) {
84
            $library->$field( scalar $input->param($field) );
94
            $library->$field( scalar $input->param($field) );
85
        }
95
        }
86
        eval { $library->store; };
96
87
        if ($@) {
97
        try {
98
            Koha::Database->new->schema->txn_do(
99
                sub {
100
                    $library->store->discard_changes;
101
                    # Deal with SMTP server
102
                    my $smtp_server_id = $input->param('smtp_server');
103
104
                    if ( $smtp_server_id ) {
105
                        if ( $smtp_server_id eq '*' ) {
106
                            $library->smtp_server({ smtp_server => undef });
107
                        }
108
                        else {
109
                            my $smtp_server = Koha::SMTP::Servers->find( $smtp_server_id );
110
                            Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' )
111
                                unless $smtp_server;
112
                            $library->smtp_server({ smtp_server => $smtp_server });
113
                        }
114
                    }
115
116
                    push @messages, { type => 'message', code => 'success_on_update' };
117
                }
118
            );
119
        }
120
        catch {
88
            push @messages, { type => 'alert', code => 'error_on_update' };
121
            push @messages, { type => 'alert', code => 'error_on_update' };
89
        } else {
90
            push @messages, { type => 'message', code => 'success_on_update' };
91
        }
122
        }
92
    } else {
123
    } else {
93
        $branchcode =~ s|\s||g;
124
        $branchcode =~ s|\s||g;
Lines 96-107 if ( $op eq 'add_form' ) { Link Here
96
                ( map { $_ => scalar $input->param($_) || undef } @fields )
127
                ( map { $_ => scalar $input->param($_) || undef } @fields )
97
            }
128
            }
98
        );
129
        );
99
        eval { $library->store; };
130
100
        if ($@) {
131
        try {
101
            push @messages, { type => 'alert', code => 'error_on_insert' };
132
            Koha::Database->new->schema->txn_do(
102
        } else {
133
                sub {
103
            push @messages, { type => 'message', code => 'success_on_insert' };
134
                    $library->store->discard_changes;
135
136
                    my $smtp_server_id = $input->param('smtp_server');
137
138
                    if ( $smtp_server_id ) {
139
                        if ( $smtp_server_id ne '*' ) {
140
                            my $smtp_server = Koha::SMTP::Servers->find( $smtp_server_id );
141
                            Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' )
142
                                unless $smtp_server;
143
                            $library->smtp_server({ smtp_server => $smtp_server });
144
                        }
145
                    }
146
147
                    push @messages, { type => 'message', code => 'success_on_insert' };
148
                }
149
            );
104
        }
150
        }
151
        catch {
152
            push @messages, { type => 'alert', code => 'error_on_insert' };
153
        };
105
    }
154
    }
106
    $op = 'list';
155
    $op = 'list';
107
} elsif ( $op eq 'delete_confirm' ) {
156
} 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