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

(-)a/Koha/Notice/Message.pm (-2 / +49 lines)
Lines 57-64 with HTML headers and CSS includes for HTML formatted notices. Link Here
57
sub html_content {
57
sub html_content {
58
    my ($self) = @_;
58
    my ($self) = @_;
59
59
60
    my $title   = $self->subject;
60
    my $title       = $self->subject;
61
    my $content = $self->content;
61
    my $content     = $self->content;
62
    my $stylesheets = $self->stylesheets;
62
    my $stylesheets = $self->stylesheets;
63
63
64
    my $wrapped;
64
    my $wrapped;
Lines 120-125 sub stylesheets { Link Here
120
    return $all_stylesheets;
120
    return $all_stylesheets;
121
}
121
}
122
122
123
=head3 scoped_style
124
125
  my $scoped_style = $message->scoped_style;
126
127
Returns a string of all the scoped styles for the message
128
129
=cut
130
131
sub scoped_style {
132
    my ($self)       = @_;
133
    my $type         = $self->message_transport_type;
134
    my $scoped_class = ".type_$type";
135
    my $css_content;
136
137
    if ( $self->message_transport_type eq 'email' ) {
138
        $css_content = C4::Context->preference("EmailNoticeCSS");
139
    } elsif ( $self->message_transport_type eq 'print' ) {
140
        $css_content = C4::Context->preference("PrintNoticeCSS");
141
    }
142
143
    # Modify the CSS content, handling @media, @supports, @document
144
    $css_content =~ s!
145
        (@(media|supports|-moz-document)[^\{]+\{)  # Match the at-rule start
146
        (                                         # Capture group for block content
147
          (?:                                     # Non-capturing group
148
            [^{]+\{[^}]*\}                        # Match CSS rules within the at-rule block
149
          )*
150
        )
151
        \}
152
    !
153
        my $header = $1;
154
        my $inner_rules = $2;                     # Capture the rules within the at-rule block
155
156
        # Apply the scoped class to the inner rules
157
        $inner_rules =~ s/([^{]+)\{/ $scoped_class $1\{/g;
158
159
        # Return the modified block
160
        "$header$inner_rules"
161
162
    !egx;
163
164
    $css_content =~ s/([^{]+)\{/$scoped_class $1\{/g
165
        unless $css_content =~ /\@(media|supports|-moz-document)/;
166
167
    return $css_content;
168
}
169
123
=head3 patron
170
=head3 patron
124
171
125
    my $patron = $message->patron
172
    my $patron = $message->patron
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt (-2 / +2 lines)
Lines 53-59 Link Here
53
                    [% IF ( QUEUED_MESSAGES ) %]
53
                    [% IF ( QUEUED_MESSAGES ) %]
54
                    <div class="page-section">
54
                    <div class="page-section">
55
                        <span id="checkbox_actions"><a href="#" class="select_all"><i class="fa fa-check"></i> Select all</a> | <a href="#" class="clear_all"><i class="fa fa-remove"></i> Clear all</a></span>
55
                        <span id="checkbox_actions"><a href="#" class="select_all"><i class="fa fa-check"></i> Select all</a> | <a href="#" class="clear_all"><i class="fa fa-remove"></i> Clear all</a></span>
56
                        <form id="print_multiple" action="/cgi-bin/koha/tools/print_notice.pl" method="post" target="_blank">
56
                        <form id="print_multiple" action="/cgi-bin/koha/members/print_notice.pl" method="post" target="_blank">
57
                            [% INCLUDE 'csrf-token.inc' %]
57
                            [% INCLUDE 'csrf-token.inc' %]
58
58
59
                            <table id="noticestable">
59
                            <table id="noticestable">
Lines 121-127 Link Here
121
                                                    [% END %]
121
                                                    [% END %]
122
                                                [% END %]
122
                                                [% END %]
123
                                            </td>
123
                                            </td>
124
                                            <td class="actions">[% IF QUEUED_MESSAGE.status != 'pending' %]<a target="_blank" class="btn btn-default btn-xs" href="/cgi-bin/koha/tools/print_notice.pl?message_ids=[% QUEUED_MESSAGE.message_id | uri %]"><i class="fa fa-print"></i> Print</a>[% END %]</td>
124
                                            <td class="actions">[% IF QUEUED_MESSAGE.status != 'pending' %]<a target="_blank" class="btn btn-default btn-xs" href="/cgi-bin/koha/members/print_notice.pl?message_ids=[% QUEUED_MESSAGE.message_id | uri %]"><i class="fa fa-print"></i> Print</a>[% END %]</td>
125
                                        </tr>
125
                                        </tr>
126
                                    [% END %]
126
                                    [% END %]
127
                                </tbody>
127
                                </tbody>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/print_notice.tt (+46 lines)
Line 0 Link Here
1
[% USE raw %]
2
[% USE Asset %]
3
[% USE Koha %]
4
[% PROCESS 'i18n.inc' %]
5
[% SET footerjs = 1 %]
6
[% INCLUDE 'doc-head-open.inc' %]
7
    [% UNLESS notices && notices.size %]
8
        [% SET notices = [{content => notice, is_html => is_html, style => style, id => id }] %]
9
    [% END %]
10
    <title>[% FILTER collapse %]
11
        [% IF notices.size > 1 %]
12
        [% t("Print notices") | html %] &rsaquo;
13
        [% ELSE %]
14
        [% t("Print notice") | html %] &rsaquo;
15
        [% END %]
16
        [% t("Patrons") | html %] &rsaquo;
17
        [% t("Koha") | html %]
18
    [% END %]</title>
19
    [% INCLUDE 'doc-head-close.inc' %]
20
    [% Asset.css("css/print.css") | $raw %]
21
    [% IF ( Koha.Preference('AllNoticeCSS') ) %]
22
    <style>[% Koha.Preference('AllNoticeCSS') | $raw %]</style>
23
    [% END %]
24
    [% FOR style IN styles %]
25
    <style>[% style | $raw %]</style>
26
    [% END %]
27
    [% FOR notice IN notices %]
28
        [% IF notice.style %]<style>[% notice.style.replace('([^\{\}]+?)\s*\{', '#notice_' _ notice.id _ ' $1 {') | $raw %]</style>[% END %]
29
    [% END %]
30
</head>
31
<body id="members_printnotice" class="member">
32
[% FOR notice IN notices %]
33
    <div id="notice_[% notice.id | html %]" class="type_[% notice.type | html %]">
34
        [% IF notice.is_html %]
35
            [% IF ( notice.content ) %][% notice.content | $raw %][% ELSE %]No notice template found[% END %]
36
        [% ELSE %]
37
            <pre>[% IF ( notice.content ) %][% notice.content | html %][% ELSE %]No notice template found[% END %]</pre>
38
        [% END %]
39
    </div>
40
    [% IF notices.size > 1 && !loop.last%]<div class="pagebreak"></div>[% END %]
41
[% END %]
42
[% MACRO jsinclude BLOCK %]
43
    [% INCLUDE 'slip-print.inc' #printThenClose %]
44
[% END %]
45
46
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt (-34 lines)
Lines 1-34 Link Here
1
[% USE raw %]
2
[% USE Asset %]
3
[% USE Koha %]
4
[% PROCESS 'i18n.inc' %]
5
[% SET footerjs = 1 %]
6
[% INCLUDE 'doc-head-open.inc' %]
7
<title>[% FILTER collapse %]
8
    [% title | html %] &rsaquo;
9
    [% t("Patrons") | html %] &rsaquo;
10
    [% t("Koha") | html %]
11
[% END %]</title>
12
[% INCLUDE 'doc-head-close.inc' %]
13
14
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
15
<link rel="shortcut icon" href="[% IF ( IntranetFavicon ) %][% IntranetFavicon | url %][% ELSE %][% interface | html %]/[% theme | html %]/img/favicon.ico[% END %]" type="image/x-icon" />
16
17
[% Asset.css("css/print.css") | $raw %]
18
[% IF style %]<style>[% style | $raw %]</style>[% END %]
19
</head>
20
21
<body id="members_printslip" class="member">
22
    <div id="slip">
23
        [% IF plain %]
24
            <pre>[% IF ( slip ) %][% slip | html %][% ELSE %]No slip template found[% END %]</pre>
25
        [% ELSE %]
26
            [% IF ( slip ) %][% slip | $raw %][% ELSE %]No slip template found[% END %]
27
        [% END %]
28
    </div>
29
30
[% MACRO jsinclude BLOCK %]
31
    [% INCLUDE 'slip-print.inc' #printThenClose %]
32
[% END %]
33
34
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/notices.tt (-2 / +2 lines)
Lines 58-64 Link Here
58
58
59
                <div class="page-section">
59
                <div class="page-section">
60
                    <span id="checkbox_actions"><a href="#" class="select_all"><i class="fa fa-check"></i> Select all</a> | <a href="#" class="clear_all"><i class="fa fa-remove"></i> Clear all</a></span>
60
                    <span id="checkbox_actions"><a href="#" class="select_all"><i class="fa fa-check"></i> Select all</a> | <a href="#" class="clear_all"><i class="fa fa-remove"></i> Clear all</a></span>
61
                    <form id="print_multiple" action="/cgi-bin/koha/tools/print_notice.pl" method="post" target="_blank">
61
                    <form id="print_multiple" action="/cgi-bin/koha/members/print_notice.pl" method="post" target="_blank">
62
                        [% INCLUDE 'csrf-token.inc' %]
62
                        [% INCLUDE 'csrf-token.inc' %]
63
                        <table id="notices">
63
                        <table id="notices">
64
                            <thead>
64
                            <thead>
Lines 127-133 Link Here
127
                                            [% END %]
127
                                            [% END %]
128
                                        [% END %]
128
                                        [% END %]
129
                                    </td>
129
                                    </td>
130
                                    <td class="actions"><a target="_blank" class="btn btn-default btn-xs print" href="/cgi-bin/koha/tools/print_notice.pl?message_ids=[% notice.message_id | uri %]"><i class="fa fa-print"></i> Print</a></td>
130
                                    <td class="actions"><a target="_blank" class="btn btn-default btn-xs print" href="/cgi-bin/koha/members/print_notice.pl?message_ids=[% notice.message_id | uri %]"><i class="fa fa-print"></i> Print</a></td>
131
                                </tr>
131
                                </tr>
132
                                [% END %]
132
                                [% END %]
133
                            </tbody>
133
                            </tbody>
(-)a/tools/print_notice.pl (-7 / +14 lines)
Lines 27-59 my $input = CGI->new; Link Here
27
27
28
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
28
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
29
    {
29
    {
30
        template_name => "circ/printslip.tt",
30
        template_name => "members/print_notice.tt",
31
        query         => $input,
31
        query         => $input,
32
        type          => "intranet",
32
        type          => "intranet",
33
        flagsrequired => { tools => 'view_generated_notices' },
33
        flagsrequired => { tools => 'view_generated_notices' },
34
    }
34
    }
35
);
35
);
36
36
37
my $types_seen = {};
38
my @scoped_styles;
37
my @message_ids = $input->multi_param('message_ids');
39
my @message_ids = $input->multi_param('message_ids');
38
my @slips;
40
my @notices;
39
foreach my $message_id (@message_ids) {
41
foreach my $message_id (@message_ids) {
40
    my $message  = Koha::Notice::Messages->find($message_id);
42
    my $message  = Koha::Notice::Messages->find($message_id);
41
    my $template = $message->template;
43
    my $template = $message->template;
42
44
43
    push @slips, {
45
    push @notices, {
44
        content => $message->content,
46
        content => $message->content,
45
        is_html => $message->is_html,
47
        is_html => $message->is_html,
46
        style   => $template ? $template->style : undef,
48
        style   => $template ? $template->style : undef,
47
        id      => $message_id,
49
        id      => $message_id,
50
        type    => $message->message_transport_type,
48
    };
51
    };
49
52
53
    unless ( $types_seen->{ $message->message_transport_type } ) {
54
        push @scoped_styles, $message->scoped_style;
55
        $types_seen->{ $message->message_transport_type } = 1;
56
    }
57
50
    $message->update( { status => 'sent' } );
58
    $message->update( { status => 'sent' } );
51
}
59
}
52
$template->param(
60
$template->param(
53
    slips                 => \@slips,
61
    notices    => \@notices,
54
    caller                => 'notice_mgmt',
62
    stylesheet => C4::Context->preference("AllNoticeStylesheet"),
55
    stylesheet            => C4::Context->preference("SlipCSS"),
63
    styles     => \@scoped_styles
56
    IntranetSlipPrinterJS => C4::Context->preference('IntranetSlipPrinterJS'),
57
);
64
);
58
65
59
output_html_with_http_headers $input, $cookie, $template->output;
66
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/members/printnotice.pl (-74 lines)
Lines 1-73 Link Here
1
#!/usr/bin/perl
2
3
# Copyright PTFS Europe 2022
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 C4::Auth qw( get_template_and_user );
23
use C4::Output qw( output_and_exit_if_error output_html_with_http_headers );
24
use CGI qw ( -utf8 );
25
use C4::Letters;
26
use Koha::Account::Lines;
27
28
my $input = CGI->new;
29
30
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
31
    {
32
        template_name => "members/printnotice.tt",
33
        query         => $input,
34
        type          => "intranet",
35
        flagsrequired => {
36
            borrowers => 'edit_borrowers',
37
        }
38
    }
39
);
40
41
my $logged_in_user = Koha::Patrons->find($loggedinuser);
42
my $borrowernumber = $input->param('borrowernumber');
43
my $patron         = Koha::Patrons->find($borrowernumber);
44
output_and_exit_if_error(
45
    $input, $cookie,
46
    $template,
47
    {
48
        module         => 'members',
49
        logged_in_user => $logged_in_user,
50
        current_patron => $patron
51
    }
52
);
53
54
my $letter_code = $input->param('notice');
55
my $letter = C4::Letters::GetPreparedLetter(
56
    module                 => 'members',
57
    letter_code            => $letter_code,
58
    branchcode             => C4::Context::mybranch,
59
    message_transport_type => 'print',
60
    lang                   => $patron->lang,
61
    tables                 => {
62
        borrowers => $patron->borrowernumber
63
    }
64
);
65
66
$template->param(
67
    title => $letter->{title},
68
    slip  => $letter->{content},
69
    plain => !$letter->{is_html},
70
    style => $letter->{style},
71
);
72
73
output_html_with_http_headers $input, $cookie, $template->output;
74
- 

Return to bug 35267