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 39-54 my $borrowernumber = $input->param('borrowernumber'); Link Here
39
my $branchcode       = $input->param('branchcode');
40
my $branchcode       = $input->param('branchcode');
40
my $message_type     = $input->param('message_type');
41
my $message_type     = $input->param('message_type');
41
my $borrower_message = $input->param('borrower_message');
42
my $borrower_message = $input->param('borrower_message');
43
my $borrower_subject = $input->param('borrower_subject');
44
my $letter_code      = $input->param('select_patron_notice');
42
my $batch            = $input->param('batch');
45
my $batch            = $input->param('batch');
43
46
44
Koha::Patron::Message->new(
47
if ( $message_type eq 'L' or $message_type eq 'B' ) {
45
    {
48
    Koha::Patron::Message->new(
46
        borrowernumber => $borrowernumber,
49
        {
47
        branchcode     => $branchcode,
50
            borrowernumber => $borrowernumber,
48
        message_type   => $message_type,
51
            branchcode     => $branchcode,
49
        message        => $borrower_message,
52
            message_type   => $message_type,
53
            message        => $borrower_message,
54
        }
55
    )->store;
56
}
57
58
if ( $message_type eq 'E' ) {
59
    my $letter = {
60
        title   => $borrower_subject,
61
        content => $borrower_message
62
    };
63
64
    if ( $letter_code ) {
65
        $letter = C4::Letters::GetPreparedLetter(
66
            module      => 'members',
67
            letter_code => $letter_code,
68
            tables      => {
69
                'borrowers'   => $borrowernumber
70
            },
71
        );
50
    }
72
    }
51
)->store;
73
74
    C4::Letters::EnqueueLetter(
75
        {
76
            letter         => $letter,
77
            borrowernumber => $borrowernumber,
78
            message_transport_type => 'email',
79
        }
80
    ) or warn "can't enqueue letter";
81
}
52
82
53
my $url = $input->referer;
83
my $url = $input->referer;
54
if ( $url ) {
84
if ( $url ) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc (-1 / +28 lines)
Lines 3-8 Link Here
3
[% USE Branches %]
3
[% USE Branches %]
4
[% USE Categories %]
4
[% USE Categories %]
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 102-107 Link Here
102
                        <select name="message_type" id="message_type">
103
                        <select name="message_type" id="message_type">
103
                            <option value="L">Staff - Internal note</option>
104
                            <option value="L">Staff - Internal note</option>
104
                            <option value="B">OPAC - [% patron.firstname | html %] [% patron.surname | html %]</option>
105
                            <option value="B">OPAC - [% patron.firstname | html %] [% patron.surname | html %]</option>
106
                            <option value="E">Email - email addresses of patron</option>
105
                        </select>
107
                        </select>
106
                    </div>
108
                    </div>
107
                    [% bor_notes = AuthorisedValues.Get( 'BOR_NOTES' ) %]
109
                    [% bor_notes = AuthorisedValues.Get( 'BOR_NOTES' ) %]
Lines 116-123 Link Here
116
                            </select>
118
                            </select>
117
                        </div>
119
                        </div>
118
                    [% END %]
120
                    [% END %]
121
122
                    [% patron_letters = NoticeTemplates.GetByModule( 'members' ) %]
123
                    [% IF patron_letters %]
124
                        <div class="form-group">
125
                            <label for="select_patron_notice" style="display:none;">Patron notice: </label>
126
                            <select name="select_patron_notice" id="select_patron_notice" style="display:none;">
127
                                <option value="">Select notice</option>
128
                                [% FOREACH letter IN patron_letters %]
129
                                    <option value="[% letter.code | html %]">[% letter.name | html %]</option>
130
                                [% END %]
131
                            </select>
132
                        </div>
133
                    [% END %]
134
119
                    <div class="form-group">
135
                    <div class="form-group">
120
                        <textarea rows="3" class="modal-textarea" name="borrower_message" id="borrower_message" ></textarea>
136
                        <fieldset class="rows">
137
                            <ol>
138
                                <li id="subject_form" style="display: none;">
139
                                    <label for="borrower_subject">Subject:</label>
140
                                    <input type="text" size="60" name="borrower_subject" id="borrower_subject"/>
141
                                </li>
142
                                <li>
143
                                    <label for="borrower_message" style="display: none;">Body:</label>
144
                                    <textarea cols="65" rows="5" name="borrower_message" id="borrower_message" ></textarea>
145
                                </li>
146
                            </ol>
147
                        </fieldset>
121
                    </div>
148
                    </div>
122
                    <input type="hidden" name="borrowernumber" value="[% patron.borrowernumber | html %]" />
149
                    <input type="hidden" name="borrowernumber" value="[% patron.borrowernumber | html %]" />
123
                    <input type="hidden" name="batch" value="[% batch | html %]" />
150
                    <input type="hidden" name="batch" value="[% batch | html %]" />
(-)a/koha-tmpl/intranet-tmpl/prog/js/members-menu.js (+33 lines)
Lines 90-95 $(document).ready(function(){ Link Here
90
        $("#borrower_message").val( $(this).val() );
90
        $("#borrower_message").val( $(this).val() );
91
    });
91
    });
92
92
93
    $("#message_type").on("change",function(){
94
        if ($(this).val() == 'E') {
95
            $("label[for='borrower_message']").show();
96
            $('#subject_form').show();
97
            $("label[for='select_patron_notice']").show();
98
            $('#select_patron_notice').show();
99
            $("label[for='select_patron_messages']").hide();
100
            $('#select_patron_messages').hide();
101
            $('#borrower_message').val('');
102
            $('#select_patron_notice').val('');
103
        } else {
104
            $('#subject_form').hide();
105
            $("label[for='borrower_message']").hide();
106
            $("label[for='select_patron_notice']").hide();
107
            $('#select_patron_notice').hide();
108
            $("label[for='select_patron_messages']").show();
109
            $('#select_patron_messages').show();
110
            $('#borrower_subject').prop( "disabled", false );
111
            $('#borrower_message').prop( "disabled", false );
112
            $('#select_patron_messages').val('');
113
        }
114
    });
115
116
    $("#select_patron_notice").on("change",function(){
117
        if ($(this).val()) {
118
            $('#borrower_subject').prop( "disabled", true );
119
            $('#borrower_message').prop( "disabled", true );
120
        } else {
121
            $('#borrower_subject').prop( "disabled", false );
122
            $('#borrower_message').prop( "disabled", false );
123
        }
124
    });
125
93
    $(".edit-patronimage").on("click", function(e){
126
    $(".edit-patronimage").on("click", function(e){
94
        e.preventDefault();
127
        e.preventDefault();
95
        var borrowernumber = $(this).data("borrowernumber");
128
        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