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

(-)a/Koha/Template/Plugin/NoticeTemplates.pm (+55 lines)
Line 0 Link Here
1
package Koha::Template::Plugin::NoticeTemplates;
2
3
# Copyright 2021 BibLibre
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 Template::Plugin;
23
use base qw( Template::Plugin );
24
25
use Koha::Notice::Templates;
26
27
sub GetByModule {
28
    my ( $self, $module ) = @_;
29
30
    return Koha::Notice::Templates->search({ module => $module });
31
}
32
33
=head1 NAME
34
35
Koha::Template::Plugin::NoticeTemplates - TT Plugin for notice templates
36
37
=head1 SYNOPSIS
38
39
[% USE NoticeTemplates %]
40
41
[% NoticeTemplates.GetByModule('members') %]
42
43
=head1 ROUTINES
44
45
=head2 GetByModule
46
47
In a template, you can get notice templates by module with
48
[% letters = NoticeTemplates.GetByModule( 'members' ) %]
49
50
=head1 AUTHOR
51
52
Alex Arnaud <alex.arnaud@biblibre.com>
53
54
=cut
55
1;
(-)a/circ/add_message.pl (-7 / +37 lines)
Lines 23-28 use CGI qw ( -utf8 ); Link Here
23
23
24
use C4::Auth qw( get_template_and_user );
24
use C4::Auth qw( get_template_and_user );
25
use C4::Output;
25
use C4::Output;
26
use C4::Letters;
26
use Koha::Patron::Message;
27
use Koha::Patron::Message;
27
28
28
my $input = CGI->new;
29
my $input = CGI->new;
Lines 41-46 my $borrowernumber = $input->param('borrowernumber'); Link Here
41
my $branchcode       = $input->param('branchcode');
42
my $branchcode       = $input->param('branchcode');
42
my $message_type     = $input->param('message_type');
43
my $message_type     = $input->param('message_type');
43
my $borrower_message = $input->param('borrower_message');
44
my $borrower_message = $input->param('borrower_message');
45
my $borrower_subject = $input->param('borrower_subject');
46
my $letter_code      = $input->param('select_patron_notice');
44
my $batch            = $input->param('batch');
47
my $batch            = $input->param('batch');
45
48
46
if ( $op eq 'cud-edit_message' && $message_id) {
49
if ( $op eq 'cud-edit_message' && $message_id) {
Lines 48-61 if ( $op eq 'cud-edit_message' && $message_id) { Link Here
48
    $message->update( { message => $borrower_message } ) if $message;
51
    $message->update( { message => $borrower_message } ) if $message;
49
}
52
}
50
elsif( $op eq 'cud-add_message' ) {
53
elsif( $op eq 'cud-add_message' ) {
51
    Koha::Patron::Message->new(
54
    if ( $message_type eq 'L' or $message_type eq 'B' ) {
52
        {
55
        Koha::Patron::Message->new(
53
            borrowernumber => $borrowernumber,
56
            {
54
            branchcode     => $branchcode,
57
                borrowernumber => $borrowernumber,
55
            message_type   => $message_type,
58
                branchcode     => $branchcode,
56
            message        => $borrower_message,
59
                message_type   => $message_type,
60
                message        => $borrower_message,
61
            }
62
        )->store;
63
    }
64
65
    if ( $message_type eq 'E' ) {
66
        my $letter = {
67
            title   => $borrower_subject,
68
            content => $borrower_message
69
        };
70
71
        if ( $letter_code ) {
72
            $letter = C4::Letters::GetPreparedLetter(
73
                module      => 'members',
74
                letter_code => $letter_code,
75
                tables      => {
76
                    'borrowers'   => $borrowernumber
77
                },
78
            );
57
        }
79
        }
58
    )->store;
80
81
        C4::Letters::EnqueueLetter(
82
            {
83
                letter         => $letter,
84
                borrowernumber => $borrowernumber,
85
                message_transport_type => 'email',
86
            }
87
        ) or warn "can't enqueue letter";
88
    }
59
}
89
}
60
90
61
my $url = $input->referer;
91
my $url = $input->referer;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc (-1 / +28 lines)
Lines 3-8 Link Here
3
[% USE Categories %]
3
[% USE Categories %]
4
[% USE Notices %]
4
[% USE Notices %]
5
[% USE AuthorisedValues %]
5
[% USE AuthorisedValues %]
6
[% USE NoticeTemplates %]
6
[% USE scalar %]
7
[% USE scalar %]
7
<div id="toolbar" class="btn-toolbar">
8
<div id="toolbar" class="btn-toolbar">
8
    [% IF CAN_user_borrowers_edit_borrowers %]
9
    [% IF CAN_user_borrowers_edit_borrowers %]
Lines 136-141 Link Here
136
                        <select name="message_type" id="message_type">
137
                        <select name="message_type" id="message_type">
137
                            <option value="L">Staff - Internal note</option>
138
                            <option value="L">Staff - Internal note</option>
138
                            <option value="B">OPAC - [% patron.firstname | html %] [% patron.surname | html %]</option>
139
                            <option value="B">OPAC - [% patron.firstname | html %] [% patron.surname | html %]</option>
140
                            <option value="E">Email - email addresses of patron</option>
139
                        </select>
141
                        </select>
140
                    </div>
142
                    </div>
141
                    [% bor_notes = AuthorisedValues.Get( 'BOR_NOTES' ) %]
143
                    [% bor_notes = AuthorisedValues.Get( 'BOR_NOTES' ) %]
Lines 150-157 Link Here
150
                            </select>
152
                            </select>
151
                        </div>
153
                        </div>
152
                    [% END %]
154
                    [% END %]
155
156
                    [% patron_letters = NoticeTemplates.GetByModule( 'members' ) %]
157
                    [% IF patron_letters %]
158
                        <div class="form-group">
159
                            <label for="select_patron_notice" style="display:none;">Patron notice: </label>
160
                            <select name="select_patron_notice" id="select_patron_notice" style="display:none;">
161
                                <option value="">Select notice</option>
162
                                [% FOREACH letter IN patron_letters %]
163
                                    <option value="[% letter.code | html %]">[% letter.name | html %]</option>
164
                                [% END %]
165
                            </select>
166
                        </div>
167
                    [% END %]
168
153
                    <div class="form-group">
169
                    <div class="form-group">
154
                        <textarea rows="3" class="modal-textarea" name="borrower_message" id="borrower_message" ></textarea>
170
                        <fieldset class="rows">
171
                            <ol>
172
                                <li id="subject_form" style="display: none;">
173
                                    <label for="borrower_subject">Subject:</label>
174
                                    <input type="text" size="60" name="borrower_subject" id="borrower_subject"/>
175
                                </li>
176
                                <li>
177
                                    <label for="borrower_message" style="display: none;">Body:</label>
178
                                    <textarea cols="65" rows="5" name="borrower_message" id="borrower_message" ></textarea>
179
                                </li>
180
                            </ol>
181
                        </fieldset>
155
                    </div>
182
                    </div>
156
                    <input type="hidden" name="borrowernumber" value="[% patron.borrowernumber | html %]" />
183
                    <input type="hidden" name="borrowernumber" value="[% patron.borrowernumber | html %]" />
157
                    <input type="hidden" name="batch" value="[% batch | html %]" />
184
                    <input type="hidden" name="batch" value="[% batch | html %]" />
(-)a/koha-tmpl/intranet-tmpl/prog/js/members-menu.js (+33 lines)
Lines 77-82 $(document).ready(function(){ Link Here
77
        startup();
77
        startup();
78
    });
78
    });
79
79
80
    $("#message_type").on("change",function(){
81
        if ($(this).val() == 'E') {
82
            $("label[for='borrower_message']").show();
83
            $('#subject_form').show();
84
            $("label[for='select_patron_notice']").show();
85
            $('#select_patron_notice').show();
86
            $("label[for='select_patron_messages']").hide();
87
            $('#select_patron_messages').hide();
88
            $('#borrower_message').val('');
89
            $('#select_patron_notice').val('');
90
        } else {
91
            $('#subject_form').hide();
92
            $("label[for='borrower_message']").hide();
93
            $("label[for='select_patron_notice']").hide();
94
            $('#select_patron_notice').hide();
95
            $("label[for='select_patron_messages']").show();
96
            $('#select_patron_messages').show();
97
            $('#borrower_subject').prop( "disabled", false );
98
            $('#borrower_message').prop( "disabled", false );
99
            $('#select_patron_messages').val('');
100
        }
101
    });
102
103
    $("#select_patron_notice").on("change",function(){
104
        if ($(this).val()) {
105
            $('#borrower_subject').prop( "disabled", true );
106
            $('#borrower_message').prop( "disabled", true );
107
        } else {
108
            $('#borrower_subject').prop( "disabled", false );
109
            $('#borrower_message').prop( "disabled", false );
110
        }
111
    });
112
80
    $(".edit-patronimage").on("click", function(e){
113
    $(".edit-patronimage").on("click", function(e){
81
        e.preventDefault();
114
        e.preventDefault();
82
        var borrowernumber = $(this).data("borrowernumber");
115
        var borrowernumber = $(this).data("borrowernumber");
(-)a/t/db_dependent/Template/Plugin/NoticeTemplates.t (-1 / +71 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, see <http://www.gnu.org/licenses>.
16
17
use Modern::Perl;
18
19
use Test::More tests => 4;
20
21
use Koha::Database;
22
use Koha::Notice::Templates;
23
24
use t::lib::TestBuilder;
25
26
BEGIN {
27
    use_ok('Koha::Template::Plugin::NoticeTemplates');
28
}
29
30
my $schema = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new;
32
$schema->storage->txn_begin;
33
34
Koha::Notice::Templates->delete();
35
36
my $notice_templates = Koha::Notice::Templates->search({ module => 'members'});
37
38
$builder->build({
39
    source => 'Letter',
40
    value => {
41
        name => 'Hold cancellation',
42
        module => 'reserves'
43
    }
44
});
45
46
$builder->build({
47
    source => 'Letter',
48
    value => {
49
        name => 'Account expiration',
50
        module => 'members'
51
    }
52
});
53
54
$builder->build({
55
    source => 'Letter',
56
    value => {
57
        name => 'Discharge',
58
        module => 'members'
59
    }
60
});
61
62
my $plugin = Koha::Template::Plugin::NoticeTemplates->new();
63
ok($plugin, "initialized notice templates plugin");
64
65
my $notices = $plugin->GetByModule('members');
66
is( $notices->count, 2, 'returns 2 defined members letters' );
67
68
$notices = $plugin->GetByModule('reserves');
69
is( $notices->count, 1, 'returns 2 defined reserves letters' );
70
71
$schema->storage->txn_rollback;

Return to bug 29393