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 40-45 my $borrowernumber = $input->param('borrowernumber'); Link Here
40
my $branchcode       = $input->param('branchcode');
41
my $branchcode       = $input->param('branchcode');
41
my $message_type     = $input->param('message_type');
42
my $message_type     = $input->param('message_type');
42
my $borrower_message = $input->param('borrower_message');
43
my $borrower_message = $input->param('borrower_message');
44
my $borrower_subject = $input->param('borrower_subject');
45
my $letter_code      = $input->param('select_patron_notice');
43
my $batch            = $input->param('batch');
46
my $batch            = $input->param('batch');
44
47
45
if ($message_id) {
48
if ($message_id) {
Lines 47-60 if ($message_id) { Link Here
47
    $message->update( { message => $borrower_message } ) if $message;
50
    $message->update( { message => $borrower_message } ) if $message;
48
}
51
}
49
else {
52
else {
50
    Koha::Patron::Message->new(
53
    if ( $message_type eq 'L' or $message_type eq 'B' ) {
51
        {
54
        Koha::Patron::Message->new(
52
            borrowernumber => $borrowernumber,
55
            {
53
            branchcode     => $branchcode,
56
                borrowernumber => $borrowernumber,
54
            message_type   => $message_type,
57
                branchcode     => $branchcode,
55
            message        => $borrower_message,
58
                message_type   => $message_type,
59
                message        => $borrower_message,
60
            }
61
        )->store;
62
    }
63
64
    if ( $message_type eq 'E' ) {
65
        my $letter = {
66
            title   => $borrower_subject,
67
            content => $borrower_message
68
        };
69
    
70
        if ( $letter_code ) {
71
            $letter = C4::Letters::GetPreparedLetter(
72
                module      => 'members',
73
                letter_code => $letter_code,
74
                tables      => {
75
                    'borrowers'   => $borrowernumber
76
                },
77
            );
56
        }
78
        }
57
    )->store;
79
    
80
        C4::Letters::EnqueueLetter(
81
            {
82
                letter         => $letter,
83
                borrowernumber => $borrowernumber,
84
                message_transport_type => 'email',
85
            }
86
        ) or warn "can't enqueue letter";
87
    }
58
}
88
}
59
89
60
my $url = $input->referer;
90
my $url = $input->referer;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc (-1 / +28 lines)
Lines 4-9 Link Here
4
[% USE Categories %]
4
[% USE Categories %]
5
[% USE Notices %]
5
[% USE Notices %]
6
[% USE AuthorisedValues %]
6
[% USE AuthorisedValues %]
7
[% USE NoticeTemplates %]
7
[% USE scalar %]
8
[% USE scalar %]
8
<div id="toolbar" class="btn-toolbar">
9
<div id="toolbar" class="btn-toolbar">
9
    [% IF CAN_user_borrowers_edit_borrowers %]
10
    [% IF CAN_user_borrowers_edit_borrowers %]
Lines 129-134 Link Here
129
                        <select name="message_type" id="message_type">
130
                        <select name="message_type" id="message_type">
130
                            <option value="L">Staff - Internal note</option>
131
                            <option value="L">Staff - Internal note</option>
131
                            <option value="B">OPAC - [% patron.firstname | html %] [% patron.surname | html %]</option>
132
                            <option value="B">OPAC - [% patron.firstname | html %] [% patron.surname | html %]</option>
133
                            <option value="E">Email - email addresses of patron</option>
132
                        </select>
134
                        </select>
133
                    </div>
135
                    </div>
134
                    [% bor_notes = AuthorisedValues.Get( 'BOR_NOTES' ) %]
136
                    [% bor_notes = AuthorisedValues.Get( 'BOR_NOTES' ) %]
Lines 143-150 Link Here
143
                            </select>
145
                            </select>
144
                        </div>
146
                        </div>
145
                    [% END %]
147
                    [% END %]
148
149
                    [% patron_letters = NoticeTemplates.GetByModule( 'members' ) %]
150
                    [% IF patron_letters %]
151
                        <div class="form-group">
152
                            <label for="select_patron_notice" style="display:none;">Patron notice: </label>
153
                            <select name="select_patron_notice" id="select_patron_notice" style="display:none;">
154
                                <option value="">Select notice</option>
155
                                [% FOREACH letter IN patron_letters %]
156
                                    <option value="[% letter.code | html %]">[% letter.name | html %]</option>
157
                                [% END %]
158
                            </select>
159
                        </div>
160
                    [% END %]
161
146
                    <div class="form-group">
162
                    <div class="form-group">
147
                        <textarea rows="3" class="modal-textarea" name="borrower_message" id="borrower_message" ></textarea>
163
                        <fieldset class="rows">
164
                            <ol>
165
                                <li id="subject_form" style="display: none;">
166
                                    <label for="borrower_subject">Subject:</label>
167
                                    <input type="text" size="60" name="borrower_subject" id="borrower_subject"/>
168
                                </li>
169
                                <li>
170
                                    <label for="borrower_message" style="display: none;">Body:</label>
171
                                    <textarea cols="65" rows="5" name="borrower_message" id="borrower_message" ></textarea>
172
                                </li>
173
                            </ol>
174
                        </fieldset>
148
                    </div>
175
                    </div>
149
                    <input type="hidden" name="borrowernumber" value="[% patron.borrowernumber | html %]" />
176
                    <input type="hidden" name="borrowernumber" value="[% patron.borrowernumber | html %]" />
150
                    <input type="hidden" name="batch" value="[% batch | html %]" />
177
                    <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