From 61812d0f6c6b27b9bf21d05adb40f08d3f9876bf Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 13 Nov 2023 15:31:53 +0000 Subject: [PATCH] Bug 35267: Apply preferences to preview and mailing This patch applies the new style preferences to the preview display and email sending code. --- C4/Letters.pm | 32 ++++++++++++----- Koha/Notice/Message.pm | 34 ++++++++++++++++++- circ/transfer-slip.pl | 7 ++-- .../prog/en/modules/circ/printslip.tt | 4 +-- .../prog/en/modules/members/printnotice.tt | 3 -- members/printslip.pl | 3 +- opac/sco/printslip.pl | 2 +- preservation/print_slip.pl | 2 +- 8 files changed, 65 insertions(+), 22 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 7bdbfc9bf24..a58b921df6f 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -340,7 +340,7 @@ sub SendAlerts { ); if ( $letter->{is_html} ) { - $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) ); + $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title}, 'email' ) ); } else { $mail->text_body( $letter->{content} ); @@ -516,7 +516,7 @@ sub SendAlerts { ); if ( $letter->{is_html} ) { - $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) ); + $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title}, 'email' ) ); } else { $mail->text_body( "" . $letter->{content} ); @@ -1266,7 +1266,7 @@ sub _add_attachments { my $message = Koha::Email->new; if ( $letter->{is_html} ) { - $message->html_body( _wrap_html( $letter->{content}, $letter->{title} ) ); + $message->html_body( _wrap_html( $letter->{content}, $letter->{title}, 'email' ) ); } else { $message->text_body( $letter->{content} ); @@ -1488,7 +1488,7 @@ sub _send_message_by_email { } else { $email = Koha::Email->create($params); if ($is_html) { - $email->html_body( _wrap_html( $content, $subject ) ); + $email->html_body( _wrap_html( $content, $subject, 'email' ) ); } else { $email->text_body($content); } @@ -1573,10 +1573,24 @@ sub _send_message_by_email { } sub _wrap_html { - my ($content, $title) = @_; - - my $css = C4::Context->preference("NoticeCSS") || ''; - $css = qq{} if $css; + my ( $content, $title, $type ) = @_; + + my $all_stylesheets = C4::Context->preference("AllNoticeStylesheet") || ''; + $all_stylesheets .= qq{} if $all_stylesheets; + my $all_style_pref = C4::Context->preference("AllNoticeCSS"); + $all_stylesheets .= qq{} if $all_style_pref; + if ( $type eq 'email' ) { + my $email_stylesheet = C4::Context->preference("EmailNoticeStylesheet") || ''; + $all_stylesheets .= qq{} if $email_stylesheet; + my $email_style_pref = C4::Context->preference("EmailNoticeCSS"); + $all_stylesheets .= qq{} if $email_style_pref; + } + if ( $type eq 'print' ) { + my $print_stylesheet = C4::Context->preference("PrintNoticeStylesheet") || ''; + $all_stylesheets .= qq{} if $print_stylesheet; + my $print_style_pref = C4::Context->preference("PrintNoticeCSS"); + $all_stylesheets .= qq{} if $print_style_pref; + } return < @@ -1584,7 +1598,7 @@ sub _wrap_html { $title -$css +$all_stylesheets $content diff --git a/Koha/Notice/Message.pm b/Koha/Notice/Message.pm index 1caa6e90bae..a0cd923c9b5 100644 --- a/Koha/Notice/Message.pm +++ b/Koha/Notice/Message.pm @@ -59,6 +59,7 @@ sub html_content { my $title = $self->subject; my $content = $self->content; + my $stylesheets = $self->stylesheets; my $wrapped; if ( $self->is_html ) { @@ -73,7 +74,7 @@ sub html_content { $title - $css + $stylesheets $content @@ -88,6 +89,37 @@ EOS return $wrapped; } +=head3 stylesheets + + my $stylesheets = $message->stylesheets; + +Returns a string of all the stylesheet links for the message + +=cut + +sub stylesheets { + my ($self) = @_; + + my $all_stylesheets = C4::Context->preference("AllNoticeStylesheet") || ''; + $all_stylesheets .= qq{\n} if $all_stylesheets; + my $all_style_pref = C4::Context->preference("AllNoticeCSS"); + $all_stylesheets .= qq{} if $all_style_pref; + if ( $self->message_transport_type eq 'email' ) { + my $email_stylesheet = C4::Context->preference("EmailNoticeStylesheet") || ''; + $all_stylesheets .= qq{\n} if $email_stylesheet; + my $email_style_pref = C4::Context->preference("EmailNoticeCSS"); + $all_stylesheets .= qq{} if $email_style_pref; + } + if ( $self->message_transport_type eq 'print' ) { + my $print_stylesheet = C4::Context->preference("PrintNoticeStylesheet") || ''; + $all_stylesheets .= qq{\n} if $print_stylesheet; + my $print_style_pref = C4::Context->preference("PrintNoticeCSS"); + $all_stylesheets .= qq{\n} if $print_style_pref; + } + + return $all_stylesheets; +} + =head3 patron my $patron = $message->patron diff --git a/circ/transfer-slip.pl b/circ/transfer-slip.pl index 5282bbe44eb..9f2212e66e0 100755 --- a/circ/transfer-slip.pl +++ b/circ/transfer-slip.pl @@ -55,11 +55,10 @@ else { $slip = "Item not found"; } $template->param( - slip => $slip, - plain => !$is_html, + slip => $slip, + plain => !$is_html, caller => 'cud-transfer', - stylesheet => C4::Context->preference("SlipCSS"), - style => $style, + style => $style, ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/printslip.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/printslip.tt index 432b8c3b9c7..26ebc3eb551 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/printslip.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/printslip.tt @@ -36,8 +36,8 @@ [% Asset.css("css/print.css") | $raw %] -[% IF ( Koha.Preference('SlipCSS') ) %] - +[% IF ( Koha.Preference('PrintSlipStylesheet') ) %] + [% END %] [% FOR slip IN slips %] [% IF slip.style %][% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt index fbe6587a987..0e105e0a336 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt @@ -15,9 +15,6 @@ [% Asset.css("css/print.css") | $raw %] -[% IF ( Koha.Preference('SlipCSS') ) %] - -[% END %] [% IF style %][% END %] diff --git a/members/printslip.pl b/members/printslip.pl index 9cf130c22fd..243285faf18 100755 --- a/members/printslip.pl +++ b/members/printslip.pl @@ -117,10 +117,11 @@ $template->param( plain => !$is_html, borrowernumber => $borrowernumber, caller => 'members', - stylesheet => C4::Context->preference("SlipCSS"), error => $error, style => $letter->{style}, id => $print, + stylesheet => C4::Context->preference("PrintSlipStylesheet"), + error => $error, ); $template->param( IntranetSlipPrinterJS => C4::Context->preference('IntranetSlipPrinterJS' ) ); diff --git a/opac/sco/printslip.pl b/opac/sco/printslip.pl index cc24c0d9d66..6e8ffc0ac24 100755 --- a/opac/sco/printslip.pl +++ b/opac/sco/printslip.pl @@ -80,7 +80,7 @@ if (my $letter = IssueSlip (Koha::Patrons->find( $loggedinuser )->branchcode, $p $template->{VARS}->{slip} = $slip; $template->{VARS}->{plain} = !$is_html; $template->{VARS}->{borrowernumber} = $patron->borrowernumber; -$template->{VARS}->{stylesheet} = C4::Context->preference("SlipCSS"); +$template->{VARS}->{stylesheet} = C4::Context->preference("PrintSlipStylesheet"); $template->{VARS}->{error} = $error; output_html_with_http_headers $input, $cookie, $template->output; diff --git a/preservation/print_slip.pl b/preservation/print_slip.pl index 285319e036d..5be1a0882b4 100755 --- a/preservation/print_slip.pl +++ b/preservation/print_slip.pl @@ -61,7 +61,7 @@ for my $train_item_id (@train_item_ids) { $template->param( slips => \@slips, caller => 'preservation', - stylesheet => C4::Context->preference("SlipCSS"), + stylesheet => C4::Context->preference("PrintSlipStylesheet"), ); $template->param( IntranetSlipPrinterJS => C4::Context->preference('IntranetSlipPrinterJS') ); -- 2.46.2