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 / +386 lines)
Line 0 Link Here
0
- 
1
[% USE raw %]
2
[% USE Asset %]
3
[% SET footerjs = 1 %]
4
[% USE TablesSettings %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha &rsaquo;
7
Administration &rsaquo;
8
SMTP servers
9
[% IF    op == 'add_form' %]
10
    &rsaquo; New SMTP server
11
[% ELSIF op == 'edit_form' %]
12
    &rsaquo; Edit SMTP server
13
[% END %]
14
</title>
15
[% INCLUDE 'doc-head-close.inc' %]
16
</head>
17
18
<body id="admin_smtp_servers" class="admin">
19
[% INCLUDE 'header.inc' %]
20
[% INCLUDE 'prefs-admin-search.inc' %]
21
22
<div id="breadcrumbs">
23
    <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
24
    <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo;
25
    <a href="/cgi-bin/koha/admin/smtp_servers.pl">SMTP servers</a>
26
[% IF op == 'add_form' %]
27
 &rsaquo; <span> New</span>
28
[% ELSIF op == 'edit_form' %]
29
 &rsaquo; <span> Edit</span>
30
[% END %]
31
</div>
32
33
<div class="main container-fluid">
34
    <div class="row">
35
        <div class="col-sm-10 col-sm-push-2">
36
            <main>
37
38
[% FOREACH m IN messages %]
39
    <div class="dialog [% m.type | html %]" id="smtp_action_result_dialog">
40
        [% SWITCH m.code %]
41
        [% CASE 'error_on_update' %]
42
            An error occurred trying to open the server for editing. The passed id is invalid.
43
        [% CASE 'error_on_insert' %]
44
            An error occurred when adding the server. The library already has an SMTP server set.
45
        [% CASE 'success_on_update' %]
46
            Server updated successfully.
47
        [% CASE 'success_on_insert' %]
48
            Server added successfully.
49
        [% CASE %]
50
            [% m.code | html %]
51
        [% END %]
52
    </div>
53
[% END %]
54
55
    <div class="dialog message" id="smtp_delete_success" style="display: none;"></div>
56
    <div class="dialog alert"   id="smtp_delete_error"   style="display: none;"></div>
57
58
[% IF op == 'add_form' %]
59
    <h3>New SMTP server</h3>
60
    <form action="/cgi-bin/koha/admin/smtp_servers.pl" id="add" name="add" class="validated" method="post">
61
        <input type="hidden" name="op" value="add" />
62
        <fieldset class="rows">
63
            <ol>
64
                <li>
65
                    <label for="smtp_name" class="required">Name: </label>
66
                    <input type="text" name="smtp_name" id="smtp_name" size="60" class="required" required="required" />
67
                    <span class="required">Required</span>
68
                </li>
69
            </ol>
70
        </fieldset>
71
72
        <fieldset class="rows">
73
            <ol>
74
                <li>
75
                    <label for="smtp_host">Host: </label>
76
                    <input type="text" name="smtp_host" id="smtp_host" size="60" class="required"/>
77
                    <span class="required">Required</span>
78
                </li>
79
                <li>
80
                    <label for="smtp_port">Port: </label>
81
                    <input type="text" inputmode="numeric" pattern="[0-9]*" value="25" name="smtp_port" id="smtp_port" size="20" class="required"/>
82
                    <span class="required">Required</span>
83
                </li>
84
                <li>
85
                    <label for="smtp_timeout">Timeout (seconds): </label>
86
                    <input type="text" inputmode="numeric" pattern="[0-9]*" value="120" name="smtp_timeout" id="smtp_timeout" size="20" />
87
                </li>
88
                <li>
89
                    <label for="smtp_ssl_mode">SSL: </label>
90
                    <select name="smtp_ssl_mode" id="smtp_ssl_mode">
91
                        <option value="disabled" selected="selected">Disabled</option>
92
                        <option value="ssl">SSL</option>
93
                        <option value="starttls">STARTTLS</option>
94
                    </select>
95
                </li>
96
                <li>
97
                    <label for="smtp_user_name">User name: </label>
98
                    <input type="text" name="smtp_user_name" id="smtp_user_name" size="60" />
99
                </li>
100
                <li>
101
                    <label for="smtp_password">Password: </label>
102
                    <input type="password" name="smtp_password" id="smtp_password" size="60" />
103
                </li>
104
                <li>
105
                    <label for="smtp_debug_mode">Debug mode: </label>
106
                    <select name="smtp_debug_mode" id="smtp_debug_mode">
107
                        <option value="1">Enabled</option>
108
                        <option value="0" selected="selected">Disabled</option>
109
                    </select>
110
                </li>
111
            </ol>
112
        </fieldset>
113
        <fieldset class="action">
114
            <input type="submit" value="Submit" />
115
            <a class="cancel" href="/cgi-bin/koha/admin/smtp_servers.pl">Cancel</a>
116
        </fieldset>
117
    </form>
118
[% END %]
119
120
[% IF op == 'edit_form' %]
121
    <h3>Edit SMTP server</h3>
122
    <form action="/cgi-bin/koha/admin/smtp_servers.pl" id="edit_save" name="edit_save" class="validated" method="post">
123
        <input type="hidden" name="op" value="edit_save" />
124
        <input type="hidden" name="smtp_server_id" value="[%- smtp_server.id | html -%]" />
125
        <fieldset class="rows">
126
            <ol>
127
                <li>
128
                    <label for="smtp_name" class="required">Name: </label>
129
                    <input type="text" name="smtp_name" id="smtp_name" size="60" class="required" required="required" value="[%- smtp_server.name | html -%]"/>
130
                    <span class="required">Required</span>
131
                </li>
132
            </ol>
133
        </fieldset>
134
135
        <fieldset class="rows">
136
            <ol>
137
                <li>
138
                    <label for="smtp_host">Host: </label>
139
                    <input type="text" name="smtp_host" id="smtp_host" size="60" class="required" value="[%- smtp_server.host | html -%]"/>
140
                    <span class="required">Required</span>
141
                </li>
142
                <li>
143
                    <label for="smtp_port">Port: </label>
144
                    <input type="text" inputmode="numeric" pattern="[0-9]*" name="smtp_port" id="smtp_port" size="20" class="required" value="[%- smtp_server.port | html -%]"/>
145
                    <span class="required">Required</span>
146
                </li>
147
                <li>
148
                    <label for="smtp_timeout">Timeout (seconds): </label>
149
                    <input type="text" inputmode="numeric" pattern="[0-9]*" name="smtp_timeout" id="smtp_timeout" size="20" value="[%- smtp_server.timeout | html -%]"/>
150
                </li>
151
                <li>
152
                    <label for="smtp_ssl_mode">SSL: </label>
153
                    <select name="smtp_ssl_mode" id="smtp_ssl_mode">
154
                    [%- IF smtp_server.ssl_mode == 'disabled' -%]
155
                        <option value="disabled" selected="selected">Disabled</option>
156
                        <option value="ssl">SSL</option>
157
                        <option value="starttls">STARTTLS</option>
158
                    [%- ELSIF smtp_server.ssl_mode == 'ssl' -%]
159
                        <option value="disabled">Disabled</option>
160
                        <option value="ssl" selected="selected">SSL</option>
161
                        <option value="starttls">STARTTLS</option>
162
                    [%- ELSE -%]
163
                        <option value="disabled">Disabled</option>
164
                        <option value="ssl">SSL</option>
165
                        <option value="starttls" selected="selected">STARTTLS</option>
166
                    [%- END -%]
167
                    </select>
168
                </li>
169
                <li>
170
                    <label for="smtp_user_name">User name: </label>
171
                    <input type="text" name="smtp_user_name" id="smtp_user_name" size="60"  value="[%- smtp_server.user_name | html -%]"/>
172
                </li>
173
                <li>
174
                    <label for="smtp_password">Password: </label>
175
                    <input type="password" name="smtp_password" id="smtp_password" size="60"  value="[%- smtp_server.password | html -%]"/>
176
                </li>
177
                <li>
178
                    <label for="smtp_debug_mode">Debug mode: </label>
179
                    <select name="smtp_debug_mode" id="smtp_debug_mode">
180
                    [%- IF smtp_server.debug == 1 -%]
181
                        <option value="1" selected="selected">Enabled</option>
182
                        <option value="0">Disabled</option>
183
                    [%- ELSE -%]
184
                        <option value="1">Enabled</option>
185
                        <option value="0" selected="selected">Disabled</option>
186
                    [%- END -%]
187
                    </select>
188
                </li>
189
            </ol>
190
        </fieldset>
191
        <fieldset class="action">
192
            <input type="submit" value="Submit" />
193
            <a class="cancel" href="/cgi-bin/koha/admin/smtp_servers.pl">Cancel</a>
194
        </fieldset>
195
    </form>
196
[% END %]
197
198
[% IF op == 'list' %]
199
200
    <div id="toolbar" class="btn-toolbar">
201
        <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>
202
    </div>
203
204
    <h3>SMTP servers</h3>
205
206
        <div class="dialog message" id="default_server_message">
207
        <p>Default configuration:</p>
208
209
        <ul>
210
            <li><strong>Host</strong>: [%- default_config.host | html -%]</li>
211
            <li><strong>Port</strong>: [%- default_config.port | html -%]</li>
212
            <li><strong>Timeout (secs)</strong>: [%- default_config.timeout | html -%]</li>
213
            <li><strong>SSL</strong>: [%- IF default_config.ssl_mode == 'disabled' -%]Disabled[%- ELSIF default_config.ssl_mode == 'ssl' -%]SSL[%- ELSE -%]STARTTLS[%- END -%]</li>
214
            <li><strong>Debug mode</strong>: [%- IF default_config.debug -%]Yes[%- ELSE -%]No[%- END -%]</li>
215
        </ul>
216
    </div>
217
218
    [% IF servers_count > 0 %]
219
        <table id="smtp_servers">
220
            <thead>
221
                <tr>
222
                    <th>Name</th>
223
                    <th>Host</th>
224
                    <th>Port</th>
225
                    <th>Timeout (secs)</th>
226
                    <th>SSL</th>
227
                    <th>Authenticated</th>
228
                    <th data-class-name="actions">Actions</th>
229
                </tr>
230
            </thead>
231
        </table>
232
    [% END %]
233
[% END %]
234
235
            <div id="delete_confirm_modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="delete_confirm_modal_label" aria-hidden="true">
236
                <div class="modal-dialog">
237
                    <div class="modal-content">
238
                        <div class="modal-header">
239
                            <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
240
                            <h3 id="delete_confirm_modal_label">Delete server</h3>
241
                        </div>
242
                        <div class="modal-body">
243
                            <div id="delete_confirm_dialog"></div>
244
                        </div>
245
                        <div class="modal-footer">
246
                            <a href="#" class="btn btn-default" id="delete_confirm_modal_button" role="button" data-toggle="modal">Delete</a>
247
                            <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
248
                        </div>
249
                    </div> <!-- /.modal-content -->
250
                </div> <!-- /.modal-dialog -->
251
            </div> <!-- #delete_confirm_modal -->
252
253
            </main>
254
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
255
256
        <div class="col-sm-2 col-sm-pull-10">
257
            <aside>
258
                [% INCLUDE 'admin-menu.inc' %]
259
            </aside>
260
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
261
     </div> <!-- /.row -->
262
263
264
[% MACRO jsinclude BLOCK %]
265
    [% Asset.js("js/admin-menu.js") | $raw %]
266
    [% INCLUDE 'datatables.inc' %]
267
    [% INCLUDE 'columns_settings.inc' %]
268
    [% Asset.js("lib/tiny_mce/tinymce.min.js") | $raw %]
269
    [% INCLUDE 'str/tinymce_i18n.inc' %]
270
    <script>
271
        $(document).ready(function() {
272
273
            var smtp_servers_url = '/api/v1/config/smtp_servers';
274
            window.smtp_servers = $("#smtp_servers").api({
275
                "ajax": {
276
                    "url": smtp_servers_url
277
                },
278
                'language': {
279
                    'emptyTable': '<div class="dialog message">'+_("There are no SMTP servers defined.")+'</div>'
280
                },
281
                "columnDefs": [ {
282
                    "targets": [0,1],
283
                    "render": function (data, type, row, meta) {
284
                        if ( type == 'display' ) {
285
                            if ( data != null ) {
286
                                return data.escapeHtml();
287
                            }
288
                            else {
289
                                return "Default";
290
                            }
291
                        }
292
                        return data;
293
                    }
294
                } ],
295
                "columns": [
296
                    {
297
                        "data": "name",
298
                        "searchable": true,
299
                        "orderable": true
300
                    },
301
                    {
302
                        "data": "host",
303
                        "searchable": true,
304
                        "orderable": true
305
                    },
306
                    {
307
                        "data": "port",
308
                        "searchable": true,
309
                        "orderable": false
310
                    },
311
                    {
312
                        "data": "timeout",
313
                        "searchable": true,
314
                        "orderable": false
315
                    },
316
                    {
317
                        "data": "ssl_mode",
318
                        "render": function (data, type, row, meta) {
319
                            if (data == 'disabled') {
320
                                return _("Disabled");
321
                            }
322
                            else if (data == 'ssl') {
323
                                return _("SSL");
324
                            }
325
                            else {
326
                                return _("STARTTLS");
327
                            }
328
                        },
329
                        "searchable": false,
330
                        "orderable": false
331
                    },
332
                    {
333
                        "data": function( row, type, val, meta ) {
334
                            if ( row.user_name != null ) {
335
                                return _("Yes");
336
                            }
337
                            else {
338
                                return _("No");
339
                            }
340
                        },
341
                        "searchable": false,
342
                        "orderable": false
343
                    },
344
                    {
345
                        "data": function( row, type, val, meta ) {
346
                            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";
347
                            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>';
348
                            return result;
349
                        },
350
                        "searchable": false,
351
                        "orderable": false
352
                    }
353
                ]
354
            });
355
356
            $('#smtp_servers').on( "click", '.delete_server', function () {
357
                var smtp_server_id   = $(this).data('smtp-server-id');
358
                var smtp_server_name = decodeURIComponent($(this).data('smtp-server-name'));
359
360
                $("#delete_confirm_dialog").html(
361
                    _("You are about to delete the '%s' SMTP server.").format(smtp_server_name)
362
                );
363
364
                $("#delete_confirm_modal_button").on( "click", function () {
365
                    $.ajax({
366
                        method: "DELETE",
367
                        url: "/api/v1/config/smtp_servers/"+smtp_server_id
368
                    }).success(function() {
369
                        $("#delete_confirm_modal").modal('hide');
370
                        window.smtp_servers.api().ajax.reload(function (data) {
371
                            if (data.recordsTotal == 0) {
372
                                $("#smtp_servers_wrapper").hide();
373
                            }
374
                            $("#smtp_action_result_dialog").hide();
375
                            $("#smtp_delete_success").html(_("Server '%s' deleted successfully.").format(smtp_server_name)).show();
376
                        });
377
                    }).error(function () {
378
                        $("#smtp_delete_error").html(_("Error deleting server '%s'. Check the logs.").format(smtp_server_name)).show();
379
                    });
380
                });
381
            });
382
        });
383
    </script>
384
[% END %]
385
386
[% INCLUDE 'intranet-bottom.inc' %]

Return to bug 22343