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

(-)a/admin/smtp_servers.pl (+182 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2020 Theke Solutions
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use CGI qw ( -utf8 );
23
use Scalar::Util qw(blessed);
24
use Try::Tiny;
25
26
use C4::Auth qw(get_template_and_user);
27
use C4::Output qw(output_html_with_http_headers);
28
29
use Koha::Libraries;
30
use Koha::SMTP::Servers;
31
32
my $input = CGI->new;
33
my $op    = $input->param('op') || 'list';
34
35
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
36
    {   template_name   => "admin/smtp_servers.tt",
37
        query           => $input,
38
        type            => "intranet",
39
        flagsrequired   => { parameters => 'manage_smtp_servers' },
40
    }
41
);
42
43
my @messages;
44
45
if ( $op eq 'add' ) {
46
47
    my $name       = $input->param('smtp_name');
48
    my $host       = $input->param('smtp_host');
49
    my $port       = $input->param('smtp_port') || 25;
50
    my $timeout    = $input->param('smtp_timeout') || 120;
51
    my $ssl_mode   = $input->param('smtp_ssl_mode');
52
    my $user_name  = $input->param('smtp_user_name') || undef;
53
    my $password   = $input->param('smtp_password') || undef;
54
    my $debug      = ( scalar $input->param('smtp_debug_mode') ) ? 1 : 0;
55
56
    try {
57
        Koha::SMTP::Server->new(
58
            {
59
                name       => $name,
60
                host       => $host,
61
                port       => $port,
62
                timeout    => $timeout,
63
                ssl_mode   => $ssl_mode,
64
                user_name  => $user_name,
65
                password   => $password,
66
                debug      => $debug,
67
            }
68
        )->store;
69
70
        push @messages, { type => 'message', code => 'success_on_insert' };
71
    }
72
    catch {
73
        if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
74
            push @messages,
75
              {
76
                type   => 'alert',
77
                code   => 'error_on_insert',
78
                reason => 'duplicate_id'
79
              };
80
        }
81
    };
82
83
    # list servers after adding
84
    $op = 'list';
85
}
86
elsif ( $op eq 'edit_form' ) {
87
    my $smtp_server_id = $input->param('smtp_server_id');
88
    my $smtp_server;
89
90
    $smtp_server = Koha::SMTP::Servers->find($smtp_server_id)
91
        unless !$smtp_server_id;
92
93
    if ( $smtp_server ) {
94
        $template->param(
95
            smtp_server => $smtp_server
96
        );
97
    }
98
    else {
99
        push @messages,
100
            {
101
                type   => 'alert',
102
                code   => 'error_on_edit',
103
                reason => 'invalid_id'
104
            };
105
    }
106
}
107
elsif ( $op eq 'edit_save' ) {
108
109
    my $smtp_server_id = $input->param('smtp_server_id');
110
    my $smtp_server;
111
112
    $smtp_server = Koha::SMTP::Servers->find($smtp_server_id)
113
        unless !$smtp_server_id;
114
115
    if ( $smtp_server ) {
116
117
        my $name       = $input->param('smtp_name');
118
        my $host       = $input->param('smtp_host');
119
        my $port       = $input->param('smtp_port') || 25;
120
        my $timeout    = $input->param('smtp_timeout') || 120;
121
        my $ssl_mode   = $input->param('smtp_ssl_mode');
122
        my $user_name  = $input->param('smtp_user_name') || undef;
123
        my $password   = $input->param('smtp_password') || undef;
124
        my $debug      = ( scalar $input->param('smtp_debug_mode') ) ? 1 : 0;
125
126
        try {
127
            $smtp_server->password( $password )
128
                if $password;
129
130
            $smtp_server->set(
131
                {
132
                    name      => $name,
133
                    host      => $host,
134
                    port      => $port,
135
                    timeout   => $timeout,
136
                    ssl_mode  => $ssl_mode,
137
                    user_name => $user_name,
138
                    debug     => $debug
139
                }
140
            )->store;
141
142
            push @messages,
143
            {
144
                type => 'message',
145
                code => 'success_on_update'
146
            };
147
        }
148
        catch {
149
            push @messages,
150
            {
151
                type   => 'alert',
152
                code   => 'error_on_update'
153
            };
154
        };
155
156
        # list servers after adding
157
        $op = 'list';
158
    }
159
    else {
160
        push @messages,
161
            {
162
                type   => 'alert',
163
                code   => 'error_on_update',
164
                reason => 'invalid_id'
165
            };
166
    }
167
}
168
169
if ( $op eq 'list' ) {
170
    my $smtp_servers = Koha::SMTP::Servers->search;
171
    $template->param(
172
        servers_count  => $smtp_servers->count,
173
        default_config => $smtp_servers->default_setting
174
    );
175
}
176
177
$template->param(
178
    op       => $op,
179
    messages => \@messages,
180
);
181
182
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc (-1 / +4 lines)
Lines 123-134 Link Here
123
        </ul>
123
        </ul>
124
    [% END %]
124
    [% END %]
125
125
126
    [% IF ( CAN_user_parameters_manage_search_targets || CAN_user_parameters_manage_didyoumean || CAN_user_parameters_manage_column_config || CAN_user_parameters_manage_audio_alerts || ( CAN_user_parameters_manage_sms_providers && Koha.Preference('SMSSendDriver') == 'Email' ) || CAN_user_parameters_manage_usage_stats || CAN_user_parameters_manage_additional_fields || ( Koha.Preference('EnableAdvancedCatalogingEditor') && CAN_user_parameters_manage_keyboard_shortcuts ) ) %]
126
    [% IF ( CAN_user_parameters_manage_smtp_servers || CAN_user_parameters_manage_search_targets || CAN_user_parameters_manage_didyoumean || CAN_user_parameters_manage_column_config || CAN_user_parameters_manage_audio_alerts || ( CAN_user_parameters_manage_sms_providers && Koha.Preference('SMSSendDriver') == 'Email' ) || CAN_user_parameters_manage_usage_stats || CAN_user_parameters_manage_additional_fields || ( Koha.Preference('EnableAdvancedCatalogingEditor') && CAN_user_parameters_manage_keyboard_shortcuts ) ) %]
127
        <h5>Additional parameters</h5>
127
        <h5>Additional parameters</h5>
128
        <ul>
128
        <ul>
129
            [% IF ( CAN_user_parameters_manage_search_targets ) %]
129
            [% IF ( CAN_user_parameters_manage_search_targets ) %]
130
                <li><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50/SRU servers</a></li>
130
                <li><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50/SRU servers</a></li>
131
            [% END %]
131
            [% END %]
132
            [% IF ( CAN_user_parameters_manage_smtp_servers ) %]
133
                <li><a href="/cgi-bin/koha/admin/smtp_servers.pl">SMTP servers</a></li>
134
            [% END %]
132
            [% IF ( CAN_user_parameters_manage_didyoumean ) %]
135
            [% IF ( CAN_user_parameters_manage_didyoumean ) %]
133
                <li><a href="/cgi-bin/koha/admin/didyoumean.pl">Did you mean?</a></li>
136
                <li><a href="/cgi-bin/koha/admin/didyoumean.pl">Did you mean?</a></li>
134
            [% END %]
137
            [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc (+5 lines)
Lines 220-225 Link Here
220
            Manage Did you mean? configuration
220
            Manage Did you mean? configuration
221
        </span>
221
        </span>
222
        <span class="permissioncode">([% name | html %])</span>
222
        <span class="permissioncode">([% name | html %])</span>
223
    [%- CASE 'manage_smtp_servers' -%]
224
        <span class="sub_permission manage_manage_smtp_servers_subpermission">
225
            Manage SMTP servers
226
        </span>
227
        <span class="permissioncode">([% name | html %])</span>
223
    [%- CASE 'manage_column_config' -%]
228
    [%- CASE 'manage_column_config' -%]
224
        <span class="sub_permission manage_column_config_subpermission">
229
        <span class="sub_permission manage_column_config_subpermission">
225
            Manage column configuration
230
            Manage column configuration
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (-1 / +5 lines)
Lines 199-205 Link Here
199
                </dl>
199
                </dl>
200
            [% END %]
200
            [% END %]
201
201
202
            [% IF ( ( CAN_user_parameters_manage_search_targets || CAN_user_parameters_manage_didyoumean || CAN_user_parameters_manage_column_config || CAN_user_parameters_manage_audio_alerts || CAN_user_parameters_manage_sms_providers && Koha.Preference('SMSSendDriver') == 'Email' ) || CAN_user_parameters_manage_usage_stats || CAN_user_parameters_manage_additional_fields || CAN_user_parameters_manage_mana || (Koha.Preference('EnableAdvancedCatalogingEditor') && CAN_user_parameters_manage_keyboard_shortcuts) ) %]
202
            [% IF ( ( CAN_user_parameters_manage_smtp_servers || CAN_user_parameters_manage_search_targets || CAN_user_parameters_manage_didyoumean || CAN_user_parameters_manage_column_config || CAN_user_parameters_manage_audio_alerts || CAN_user_parameters_manage_sms_providers && Koha.Preference('SMSSendDriver') == 'Email' ) || CAN_user_parameters_manage_usage_stats || CAN_user_parameters_manage_additional_fields || CAN_user_parameters_manage_mana || (Koha.Preference('EnableAdvancedCatalogingEditor') && CAN_user_parameters_manage_keyboard_shortcuts) ) %]
203
                <h3>Additional parameters</h3>
203
                <h3>Additional parameters</h3>
204
                <dl>
204
                <dl>
205
                        <!-- <dt><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></dt>
205
                        <!-- <dt><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></dt>
Lines 208-213 Link Here
208
                        <dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50/SRU servers</a></dt>
208
                        <dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50/SRU servers</a></dt>
209
                        <dd>Define which external servers to query for MARC data.</dd>
209
                        <dd>Define which external servers to query for MARC data.</dd>
210
                    [% END %]
210
                    [% END %]
211
                    [% IF ( CAN_user_parameters_manage_smtp_servers ) %]
212
                        <dt><a href="/cgi-bin/koha/admin/smtp_servers.pl">SMTP servers</a></dt>
213
                        <dd>Define which SMTP servers to use.</dd>
214
                    [% END %]
211
                    [% IF ( CAN_user_parameters_manage_didyoumean ) %]
215
                    [% IF ( CAN_user_parameters_manage_didyoumean ) %]
212
                        <dt><a href="/cgi-bin/koha/admin/didyoumean.pl">Did you mean?</a></dt>
216
                        <dt><a href="/cgi-bin/koha/admin/didyoumean.pl">Did you mean?</a></dt>
213
                        <dd>Choose which plugins to use to suggest searches to patrons and staff.</dd>
217
                        <dd>Choose which plugins to use to suggest searches to patrons and staff.</dd>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smtp_servers.tt (-1 / +382 lines)
Line 0 Link Here
0
- 
1
[% USE raw %]
2
[% USE Asset %]
3
[% SET footerjs = 1 %]
4
[% INCLUDE 'doc-head-open.inc' %]
5
<title>Koha &rsaquo;
6
Administration &rsaquo;
7
SMTP servers
8
[% IF    op == 'add_form' %]
9
    &rsaquo; New SMTP server
10
[% ELSIF op == 'edit_form' %]
11
    &rsaquo; Edit SMTP server
12
[% END %]
13
</title>
14
[% INCLUDE 'doc-head-close.inc' %]
15
</head>
16
17
<body id="admin_smtp_servers" class="admin">
18
[% INCLUDE 'header.inc' %]
19
[% INCLUDE 'prefs-admin-search.inc' %]
20
21
<div id="breadcrumbs">
22
    <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
23
    <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo;
24
    <a href="/cgi-bin/koha/admin/smtp_servers.pl">SMTP servers</a>
25
[% IF op == 'add_form' %]
26
 &rsaquo; <span> New</span>
27
[% ELSIF op == 'edit_form' %]
28
 &rsaquo; <span> Edit</span>
29
[% END %]
30
</div>
31
32
<div class="main container-fluid">
33
    <div class="row">
34
        <div class="col-sm-10 col-sm-push-2">
35
            <main>
36
37
[% FOREACH m IN messages %]
38
    <div class="dialog [% m.type | html %]" id="smtp_action_result_dialog">
39
        [% SWITCH m.code %]
40
        [% CASE 'error_on_update' %]
41
            An error occurred trying to open the server for editing. The passed id is invalid.
42
        [% CASE 'error_on_insert' %]
43
            An error occurred when adding the server. The library already has an SMTP server set.
44
        [% CASE 'success_on_update' %]
45
            Server updated successfully.
46
        [% CASE 'success_on_insert' %]
47
            Server added successfully.
48
        [% CASE %]
49
            [% m.code | html %]
50
        [% END %]
51
    </div>
52
[% END %]
53
54
    <div class="dialog message" id="smtp_delete_success" style="display: none;"></div>
55
    <div class="dialog alert"   id="smtp_delete_error"   style="display: none;"></div>
56
57
[% IF op == 'add_form' %]
58
    <h3>New SMTP server</h3>
59
    <form action="/cgi-bin/koha/admin/smtp_servers.pl" id="add" name="add" class="validated" method="post">
60
        <input type="hidden" name="op" value="add" />
61
        <fieldset class="rows">
62
            <ol>
63
                <li>
64
                    <label for="smtp_name" class="required">Name: </label>
65
                    <input type="text" name="smtp_name" id="smtp_name" size="60" class="required" required="required" />
66
                    <span class="required">Required</span>
67
                </li>
68
            </ol>
69
        </fieldset>
70
71
        <fieldset class="rows">
72
            <ol>
73
                <li>
74
                    <label for="smtp_host">Host: </label>
75
                    <input type="text" name="smtp_host" id="smtp_host" size="60" class="required"/>
76
                    <span class="required">Required</span>
77
                </li>
78
                <li>
79
                    <label for="smtp_port">Port: </label>
80
                    <input type="text" inputmode="numeric" pattern="[0-9]*" value="25" name="smtp_port" id="smtp_port" size="20" class="required"/>
81
                    <span class="required">Required</span>
82
                </li>
83
                <li>
84
                    <label for="smtp_timeout">Timeout (seconds): </label>
85
                    <input type="text" inputmode="numeric" pattern="[0-9]*" value="120" name="smtp_timeout" id="smtp_timeout" size="20" />
86
                </li>
87
                <li>
88
                    <label for="smtp_ssl_mode">SSL: </label>
89
                    <select name="smtp_ssl_mode" id="smtp_ssl_mode">
90
                        <option value="disabled" selected="selected">Disabled</option>
91
                        <option value="ssl">SSL</option>
92
                        <option value="starttls">STARTTLS</option>
93
                    </select>
94
                </li>
95
                <li>
96
                    <label for="smtp_user_name">User name: </label>
97
                    <input type="text" name="smtp_user_name" id="smtp_user_name" size="60" />
98
                </li>
99
                <li>
100
                    <label for="smtp_password">Password: </label>
101
                    <input type="password" name="smtp_password" id="smtp_password" size="60" />
102
                </li>
103
                <li>
104
                    <label for="smtp_debug_mode">Debug mode: </label>
105
                    <select name="smtp_debug_mode" id="smtp_debug_mode">
106
                        <option value="1">Enabled</option>
107
                        <option value="0" selected="selected">Disabled</option>
108
                    </select>
109
                </li>
110
            </ol>
111
        </fieldset>
112
        <fieldset class="action">
113
            <input type="submit" value="Submit" />
114
            <a class="cancel" href="/cgi-bin/koha/admin/smtp_servers.pl">Cancel</a>
115
        </fieldset>
116
    </form>
117
[% END %]
118
119
[% IF op == 'edit_form' %]
120
    <h3>Edit SMTP server</h3>
121
    <form action="/cgi-bin/koha/admin/smtp_servers.pl" id="edit_save" name="edit_save" class="validated" method="post">
122
        <input type="hidden" name="op" value="edit_save" />
123
        <input type="hidden" name="smtp_server_id" value="[%- smtp_server.id | html -%]" />
124
        <fieldset class="rows">
125
            <ol>
126
                <li>
127
                    <label for="smtp_name" class="required">Name: </label>
128
                    <input type="text" name="smtp_name" id="smtp_name" size="60" class="required" required="required" value="[%- smtp_server.name | html -%]"/>
129
                    <span class="required">Required</span>
130
                </li>
131
            </ol>
132
        </fieldset>
133
134
        <fieldset class="rows">
135
            <ol>
136
                <li>
137
                    <label for="smtp_host">Host: </label>
138
                    <input type="text" name="smtp_host" id="smtp_host" size="60" class="required" value="[%- smtp_server.host | html -%]"/>
139
                    <span class="required">Required</span>
140
                </li>
141
                <li>
142
                    <label for="smtp_port">Port: </label>
143
                    <input type="text" inputmode="numeric" pattern="[0-9]*" name="smtp_port" id="smtp_port" size="20" class="required" value="[%- smtp_server.port | html -%]"/>
144
                    <span class="required">Required</span>
145
                </li>
146
                <li>
147
                    <label for="smtp_timeout">Timeout (seconds): </label>
148
                    <input type="text" inputmode="numeric" pattern="[0-9]*" name="smtp_timeout" id="smtp_timeout" size="20" value="[%- smtp_server.timeout | html -%]"/>
149
                </li>
150
                <li>
151
                    <label for="smtp_ssl_mode">SSL: </label>
152
                    <select name="smtp_ssl_mode" id="smtp_ssl_mode">
153
                    [%- IF smtp_server.ssl_mode == 'disabled' -%]
154
                        <option value="disabled" selected="selected">Disabled</option>
155
                        <option value="ssl">SSL</option>
156
                        <option value="starttls">STARTTLS</option>
157
                    [%- ELSIF smtp_server.ssl_mode == 'ssl' -%]
158
                        <option value="disabled">Disabled</option>
159
                        <option value="ssl" selected="selected">SSL</option>
160
                        <option value="starttls">STARTTLS</option>
161
                    [%- ELSE -%]
162
                        <option value="disabled">Disabled</option>
163
                        <option value="ssl">SSL</option>
164
                        <option value="starttls" selected="selected">STARTTLS</option>
165
                    [%- END -%]
166
                    </select>
167
                </li>
168
                <li>
169
                    <label for="smtp_user_name">User name: </label>
170
                    <input type="text" name="smtp_user_name" id="smtp_user_name" size="60"  value="[%- smtp_server.user_name | html -%]"/>
171
                </li>
172
                <li>
173
                    <label for="smtp_password">Password: </label>
174
                    <input type="password" name="smtp_password" id="smtp_password" size="60"  value="[%- smtp_server.password | html -%]"/>
175
                </li>
176
                <li>
177
                    <label for="smtp_debug_mode">Debug mode: </label>
178
                    <select name="smtp_debug_mode" id="smtp_debug_mode">
179
                    [%- IF smtp_server.debug == 1 -%]
180
                        <option value="1" selected="selected">Enabled</option>
181
                        <option value="0">Disabled</option>
182
                    [%- ELSE -%]
183
                        <option value="1">Enabled</option>
184
                        <option value="0" selected="selected">Disabled</option>
185
                    [%- END -%]
186
                    </select>
187
                </li>
188
            </ol>
189
        </fieldset>
190
        <fieldset class="action">
191
            <input type="submit" value="Submit" />
192
            <a class="cancel" href="/cgi-bin/koha/admin/smtp_servers.pl">Cancel</a>
193
        </fieldset>
194
    </form>
195
[% END %]
196
197
[% IF op == 'list' %]
198
199
    <div id="toolbar" class="btn-toolbar">
200
        <a class="btn btn-default" id="new_smtp_server" href="/cgi-bin/koha/admin/smtp_servers.pl?op=add_form"><i class="fa fa-plus"></i> New SMTP server</a>
201
    </div>
202
203
    <h3>SMTP servers</h3>
204
205
        <div class="dialog message" id="default_server_message">
206
        <p>Default configuration:</p>
207
208
        <ul>
209
            <li><strong>Host</strong>: [%- default_config.host | html -%]</li>
210
            <li><strong>Port</strong>: [%- default_config.port | html -%]</li>
211
            <li><strong>Timeout (secs)</strong>: [%- default_config.timeout | html -%]</li>
212
            <li><strong>SSL</strong>: [%- IF default_config.ssl_mode == 'disabled' -%]Disabled[%- ELSIF default_config.ssl_mode == 'ssl' -%]SSL[%- ELSE -%]STARTTLS[%- END -%]</li>
213
            <li><strong>Debug mode</strong>: [%- IF default_config.debug -%]Yes[%- ELSE -%]No[%- END -%]</li>
214
        </ul>
215
    </div>
216
217
    [% IF servers_count > 0 %]
218
        <table id="smtp_servers">
219
            <thead>
220
                <tr>
221
                    <th>Name</th>
222
                    <th>Host</th>
223
                    <th>Port</th>
224
                    <th>Timeout (secs)</th>
225
                    <th>SSL</th>
226
                    <th>Authenticated</th>
227
                    <th data-class-name="actions">Actions</th>
228
                </tr>
229
            </thead>
230
        </table>
231
    [% END %]
232
[% END %]
233
234
            <div id="delete_confirm_modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="delete_confirm_modal_label" aria-hidden="true">
235
                <div class="modal-dialog">
236
                    <div class="modal-content">
237
                        <div class="modal-header">
238
                            <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
239
                            <h3 id="delete_confirm_modal_label">Delete server</h3>
240
                        </div>
241
                        <div class="modal-body">
242
                            <div id="delete_confirm_dialog"></div>
243
                        </div>
244
                        <div class="modal-footer">
245
                            <a href="#" class="btn btn-default" id="delete_confirm_modal_button" role="button" data-toggle="modal">Delete</a>
246
                            <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
247
                        </div>
248
                    </div> <!-- /.modal-content -->
249
                </div> <!-- /.modal-dialog -->
250
            </div> <!-- #delete_confirm_modal -->
251
252
            </main>
253
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
254
255
        <div class="col-sm-2 col-sm-pull-10">
256
            <aside>
257
                [% INCLUDE 'admin-menu.inc' %]
258
            </aside>
259
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
260
     </div> <!-- /.row -->
261
262
263
[% MACRO jsinclude BLOCK %]
264
    [% Asset.js("js/admin-menu.js") | $raw %]
265
    [% INCLUDE 'datatables.inc' %]
266
    <script>
267
        $(document).ready(function() {
268
269
            var smtp_servers_url = '/api/v1/config/smtp_servers';
270
            window.smtp_servers = $("#smtp_servers").api({
271
                "ajax": {
272
                    "url": smtp_servers_url
273
                },
274
                'language': {
275
                    'emptyTable': '<div class="dialog message">'+_("There are no SMTP servers defined.")+'</div>'
276
                },
277
                "columnDefs": [ {
278
                    "targets": [0,1],
279
                    "render": function (data, type, row, meta) {
280
                        if ( type == 'display' ) {
281
                            if ( data != null ) {
282
                                return data.escapeHtml();
283
                            }
284
                            else {
285
                                return "Default";
286
                            }
287
                        }
288
                        return data;
289
                    }
290
                } ],
291
                "columns": [
292
                    {
293
                        "data": "name",
294
                        "searchable": true,
295
                        "orderable": true
296
                    },
297
                    {
298
                        "data": "host",
299
                        "searchable": true,
300
                        "orderable": true
301
                    },
302
                    {
303
                        "data": "port",
304
                        "searchable": true,
305
                        "orderable": false
306
                    },
307
                    {
308
                        "data": "timeout",
309
                        "searchable": true,
310
                        "orderable": false
311
                    },
312
                    {
313
                        "data": "ssl_mode",
314
                        "render": function (data, type, row, meta) {
315
                            if (data == 'disabled') {
316
                                return _("Disabled");
317
                            }
318
                            else if (data == 'ssl') {
319
                                return _("SSL");
320
                            }
321
                            else {
322
                                return _("STARTTLS");
323
                            }
324
                        },
325
                        "searchable": false,
326
                        "orderable": false
327
                    },
328
                    {
329
                        "data": function( row, type, val, meta ) {
330
                            if ( row.user_name != null ) {
331
                                return _("Yes");
332
                            }
333
                            else {
334
                                return _("No");
335
                            }
336
                        },
337
                        "searchable": false,
338
                        "orderable": false
339
                    },
340
                    {
341
                        "data": function( row, type, val, meta ) {
342
                            var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/smtp_servers.pl?op=edit_form&amp;smtp_server_id='+ encodeURIComponent(row.smtp_server_id) +'"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>'+"\n";
343
                            result += '<a class="btn btn-default btn-xs delete_server" role="button" href="#" data-toggle="modal" data-target="#delete_confirm_modal" data-smtp-server-id="'+ encodeURIComponent(row.smtp_server_id) +'" data-smtp-server-name="'+ encodeURIComponent(row.name.escapeHtml()) +'"><i class="fa fa-trash" aria-hidden="true"></i>'+_("Delete")+'</a>';
344
                            return result;
345
                        },
346
                        "searchable": false,
347
                        "orderable": false
348
                    }
349
                ]
350
            });
351
352
            $('#smtp_servers').on( "click", '.delete_server', function () {
353
                var smtp_server_id   = $(this).data('smtp-server-id');
354
                var smtp_server_name = decodeURIComponent($(this).data('smtp-server-name'));
355
356
                $("#delete_confirm_dialog").html(
357
                    _("You are about to delete the '%s' SMTP server.").format(smtp_server_name)
358
                );
359
360
                $("#delete_confirm_modal_button").on( "click", function () {
361
                    $.ajax({
362
                        method: "DELETE",
363
                        url: "/api/v1/config/smtp_servers/"+smtp_server_id
364
                    }).success(function() {
365
                        $("#delete_confirm_modal").modal('hide');
366
                        window.smtp_servers.api().ajax.reload(function (data) {
367
                            if (data.recordsTotal == 0) {
368
                                $("#smtp_servers_wrapper").hide();
369
                            }
370
                            $("#smtp_action_result_dialog").hide();
371
                            $("#smtp_delete_success").html(_("Server '%s' deleted successfully.").format(smtp_server_name)).show();
372
                        });
373
                    }).error(function () {
374
                        $("#smtp_delete_error").html(_("Error deleting server '%s'. Check the logs.").format(smtp_server_name)).show();
375
                    });
376
                });
377
            });
378
        });
379
    </script>
380
[% END %]
381
382
[% INCLUDE 'intranet-bottom.inc' %]

Return to bug 22343