Bug 35267: Apply preferences to preview and mailing

This patch applies the new style preferences to the preview display and
email sending code.

Sponsored-by: Open Fifth <https://openfifth.co.uk>
Signed-off-by: Marion Durand <marion.durand@biblibre.com>
Signed-off-by: Thomas Klausner <domm@plix.at>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2023-11-13 15:31:53 +00:00 committed by Lucas Gass
parent 74d008d01e
commit 49651ddaf0
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
8 changed files with 73 additions and 30 deletions

View File

@ -338,7 +338,7 @@ sub SendAlerts {
); );
if ( $letter->{is_html} ) { if ( $letter->{is_html} ) {
$mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) ); $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title}, 'email' ) );
} else { } else {
$mail->text_body( $letter->{content} ); $mail->text_body( $letter->{content} );
} }
@ -510,7 +510,7 @@ sub SendAlerts {
); );
if ( $letter->{is_html} ) { if ( $letter->{is_html} ) {
$mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) ); $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title}, 'email' ) );
} else { } else {
$mail->text_body( "" . $letter->{content} ); $mail->text_body( "" . $letter->{content} );
} }
@ -1335,7 +1335,7 @@ sub _add_attachments {
my $message = Koha::Email->new; my $message = Koha::Email->new;
if ( $letter->{is_html} ) { if ( $letter->{is_html} ) {
$message->html_body( _wrap_html( $letter->{content}, $letter->{title} ) ); $message->html_body( _wrap_html( $letter->{content}, $letter->{title}, 'email' ) );
} else { } else {
$message->text_body( $letter->{content} ); $message->text_body( $letter->{content} );
} }
@ -1564,7 +1564,7 @@ sub _send_message_by_email {
} else { } else {
$email = Koha::Email->create($params); $email = Koha::Email->create($params);
if ($is_html) { if ($is_html) {
$email->html_body( _wrap_html( $content, $subject ) ); $email->html_body( _wrap_html( $content, $subject, 'email' ) );
} else { } else {
$email->text_body($content); $email->text_body($content);
} }
@ -1646,10 +1646,26 @@ sub _send_message_by_email {
} }
sub _wrap_html { sub _wrap_html {
my ( $content, $title ) = @_; my ( $content, $title, $type ) = @_;
my $stylesheets = '';
my $css = C4::Context->preference("NoticeCSS") || ''; my $all_stylesheets = C4::Context->preference("AllNoticeStylesheet") || '';
$css = qq{<link rel="stylesheet" type="text/css" href="$css">} if $css; $stylesheets .= qq{<link rel="stylesheet" type="text/css" href="$all_stylesheets">} if $all_stylesheets;
my $all_style_pref = C4::Context->preference("AllNoticeCSS");
$stylesheets .= qq{<style type="text/css">$all_style_pref</style>} if $all_style_pref;
if ( $type eq 'email' ) {
my $email_stylesheet = C4::Context->preference("EmailNoticeStylesheet") || '';
$stylesheets .= qq{<link rel="stylesheet" type="text/css" href="$email_stylesheet">} if $email_stylesheet;
my $email_style_pref = C4::Context->preference("EmailNoticeCSS");
$stylesheets .= qq{<style type="text/css">$email_style_pref</style>} if $email_style_pref;
}
if ( $type eq 'print' ) {
my $print_stylesheet = C4::Context->preference("PrintNoticeStylesheet") || '';
$stylesheets .= qq{<link rel="stylesheet" type="text/css" href="$print_stylesheet">} if $print_stylesheet;
my $print_style_pref = C4::Context->preference("PrintNoticeCSS");
$stylesheets .= qq{<style type="text/css">$print_style_pref</style>} if $print_style_pref;
}
$stylesheets =~ s/\n+\z//;
return <<EOS; return <<EOS;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@ -1657,7 +1673,7 @@ sub _wrap_html {
<head> <head>
<title>$title</title> <title>$title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
$css $stylesheets
</head> </head>
<body> <body>
$content $content

View File

@ -58,15 +58,12 @@ with HTML headers and CSS includes for HTML formatted notices.
sub html_content { sub html_content {
my ($self) = @_; my ($self) = @_;
my $title = $self->subject; my $title = $self->subject;
my $content = $self->content; my $content = $self->content;
my $stylesheets = $self->stylesheets;
my $wrapped; my $wrapped;
if ( $self->is_html ) { if ( $self->is_html ) {
my $css = C4::Context->preference("NoticeCSS") || '';
$css = qq{<link rel="stylesheet" type="text/css" href="$css">} if $css;
$wrapped = <<EOS; $wrapped = <<EOS;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@ -74,7 +71,7 @@ sub html_content {
<head> <head>
<title>$title</title> <title>$title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
$css $stylesheets
</head> </head>
<body> <body>
$content $content
@ -124,6 +121,39 @@ sub restrict_patron_when_notice_fails {
return $self; return $self;
} }
=head3 stylesheets
my $stylesheets = $message->stylesheets;
Returns a string of all the stylesheet links for the message
=cut
sub stylesheets {
my ($self) = @_;
my $stylesheets = '';
my $all_stylesheets = C4::Context->preference("AllNoticeStylesheet") || '';
$stylesheets .= qq{<link rel="stylesheet" type="text/css" href="$all_stylesheets">\n} if $all_stylesheets;
my $all_style_pref = C4::Context->preference("AllNoticeCSS");
$stylesheets .= qq{<style type="text/css">$all_style_pref</style>} if $all_style_pref;
if ( $self->message_transport_type eq 'email' ) {
my $email_stylesheet = C4::Context->preference("EmailNoticeStylesheet") || '';
$stylesheets .= qq{<link rel="stylesheet" type="text/css" href="$email_stylesheet">\n} if $email_stylesheet;
my $email_style_pref = C4::Context->preference("EmailNoticeCSS");
$stylesheets .= qq{<style type="text/css">$email_style_pref</style>} if $email_style_pref;
}
if ( $self->message_transport_type eq 'print' ) {
my $print_stylesheet = C4::Context->preference("PrintNoticeStylesheet") || '';
$stylesheets .= qq{<link rel="stylesheet" type="text/css" href="$print_stylesheet">\n} if $print_stylesheet;
my $print_style_pref = C4::Context->preference("PrintNoticeCSS");
$stylesheets .= qq{<style type="text/css">$print_style_pref</style>\n} if $print_style_pref;
}
$stylesheets =~ s/\n+\z//;
return $stylesheets;
}
=head3 type =head3 type
=cut =cut

View File

@ -53,12 +53,11 @@ if ( my $letter = TransferSlip( $session->param('branch') || $userenv->{branch},
$slip = "Item not found"; $slip = "Item not found";
} }
$template->param( $template->param(
slip => $slip, slip => $slip,
plain => !$is_html, plain => !$is_html,
caller => 'cud-transfer', caller => 'cud-transfer',
stylesheet => C4::Context->preference("SlipCSS"), style => $style,
style => $style, id => 'transfer_slip',
id => 'transfer_slip',
); );
output_html_with_http_headers $input, $cookie, $template->output; output_html_with_http_headers $input, $cookie, $template->output;

View File

@ -32,8 +32,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="[% IF ( IntranetFavicon ) %][% IntranetFavicon | url %][% ELSE %][% interface | html %]/[% theme | html %]/img/favicon.ico[% END %]" type="image/x-icon" /> <link rel="shortcut icon" href="[% IF ( IntranetFavicon ) %][% IntranetFavicon | url %][% ELSE %][% interface | html %]/[% theme | html %]/img/favicon.ico[% END %]" type="image/x-icon" />
[% Asset.css("css/print.css") | $raw %] [% Asset.css("css/print.css") | $raw %]
[% IF ( Koha.Preference('SlipCSS') ) %] [% IF ( Koha.Preference('PrintSlipStylesheet') ) %]
<link rel="stylesheet" type="text/css" href="[% Koha.Preference('SlipCSS') | $raw %]" /> <link rel="stylesheet" type="text/css" href="[% Koha.Preference('PrintSlipStylesheet') | $raw %]" />
[% END %] [% END %]
[% FOR slip IN slips %] [% FOR slip IN slips %]
[% IF slip.style %] [% IF slip.style %]

View File

@ -15,11 +15,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="[% IF ( IntranetFavicon ) %][% IntranetFavicon | url %][% ELSE %][% interface | html %]/[% theme | html %]/img/favicon.ico[% END %]" type="image/x-icon" /> <link rel="shortcut icon" href="[% IF ( IntranetFavicon ) %][% IntranetFavicon | url %][% ELSE %][% interface | html %]/[% theme | html %]/img/favicon.ico[% END %]" type="image/x-icon" />
[% Asset.css("css/print.css") | $raw %]
[% IF ( Koha.Preference('SlipCSS') ) %]
<link rel="stylesheet" type="text/css" href="[% Koha.Preference('SlipCSS') | $raw %]" />
[% END %]
<!-- prettier-ignore-start --> <!-- prettier-ignore-start -->
[% Asset.css("css/print.css") | $raw %] <!-- prettier-ignore-start -->
[% IF style %]<style nonce="[% Koha.CSPNonce | $raw %]">[% style | $raw %]</style>[% END %] [% IF style %]<style nonce="[% Koha.CSPNonce | $raw %]">[% style | $raw %]</style>[% END %]
<!-- prettier-ignore-end --> <!-- prettier-ignore-end -->
</head> </head>

View File

@ -117,10 +117,11 @@ $template->param(
plain => !$is_html, plain => !$is_html,
borrowernumber => $borrowernumber, borrowernumber => $borrowernumber,
caller => 'members', caller => 'members',
stylesheet => C4::Context->preference("SlipCSS"),
error => $error, error => $error,
style => $letter->{style}, style => $letter->{style},
id => $print, id => $print,
stylesheet => C4::Context->preference("PrintSlipStylesheet"),
error => $error,
); );
$template->param( IntranetSlipPrinterJS => C4::Context->preference('IntranetSlipPrinterJS') ); $template->param( IntranetSlipPrinterJS => C4::Context->preference('IntranetSlipPrinterJS') );

View File

@ -82,7 +82,7 @@ if ( my $letter =
$template->{VARS}->{slip} = $slip; $template->{VARS}->{slip} = $slip;
$template->{VARS}->{plain} = !$is_html; $template->{VARS}->{plain} = !$is_html;
$template->{VARS}->{borrowernumber} = $patron->borrowernumber; $template->{VARS}->{borrowernumber} = $patron->borrowernumber;
$template->{VARS}->{stylesheet} = C4::Context->preference("SlipCSS"); $template->{VARS}->{stylesheet} = C4::Context->preference("PrintSlipStylesheet");
$template->{VARS}->{error} = $error; $template->{VARS}->{error} = $error;
output_html_with_http_headers $input, $cookie, $template->output; output_html_with_http_headers $input, $cookie, $template->output;

View File

@ -64,7 +64,7 @@ for my $train_item_id (@train_item_ids) {
$template->param( $template->param(
slips => \@slips, slips => \@slips,
caller => 'preservation', caller => 'preservation',
stylesheet => C4::Context->preference("SlipCSS"), stylesheet => C4::Context->preference("PrintSlipStylesheet"),
); );
$template->param( IntranetSlipPrinterJS => C4::Context->preference('IntranetSlipPrinterJS') ); $template->param( IntranetSlipPrinterJS => C4::Context->preference('IntranetSlipPrinterJS') );