Bugzilla – Attachment 178759 Details for
Bug 33260
Show message queue on staff interface and make notices printable
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33260: Migrate notice printing to members/print_notice
Bug-33260-Migrate-notice-printing-to-membersprintn.patch (text/plain), 14.10 KB, created by
Martin Renvoize (ashimema)
on 2025-02-26 16:42:13 UTC
(
hide
)
Description:
Bug 33260: Migrate notice printing to members/print_notice
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-02-26 16:42:13 UTC
Size:
14.10 KB
patch
obsolete
>From 48ec8ea9534a4505470bc6b49bdf6e5dc33a77bc Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 7 Oct 2024 12:13:31 +0100 >Subject: [PATCH] Bug 33260: Migrate notice printing to members/print_notice > >This migrates the bulk notice printing from tools/print_notice.pl using >circ/printslip.tt to members/print_notice.pl using members/print_notice.tt > >This clarified that we are working on pre-existing notices in the message >queue and as such should be applying relevant print/email notice styling >and not slip styling. >--- > Koha/Notice/Message.pm | 47 ++++++++++++ > .../prog/en/modules/members/notices.tt | 4 +- > .../prog/en/modules/members/print_notice.tt | 46 ++++++++++++ > .../prog/en/modules/members/printnotice.tt | 36 ---------- > .../prog/en/modules/tools/notices.tt | 4 +- > {tools => members}/print_notice.pl | 21 ++++-- > members/printnotice.pl | 71 ------------------- > 7 files changed, 111 insertions(+), 118 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/members/print_notice.tt > delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt > rename {tools => members}/print_notice.pl (76%) > delete mode 100755 members/printnotice.pl > >diff --git a/Koha/Notice/Message.pm b/Koha/Notice/Message.pm >index 58122429c5f..75e09656666 100644 >--- a/Koha/Notice/Message.pm >+++ b/Koha/Notice/Message.pm >@@ -184,6 +184,53 @@ sub template { > return Koha::Notice::Template->_new_from_dbic($template_rs); > } > >+=head3 scoped_style >+ >+ my $scoped_style = $message->scoped_style; >+ >+Returns a string of all the scoped styles for the message >+ >+=cut >+ >+sub scoped_style { >+ my ($self) = @_; >+ my $type = $self->message_transport_type; >+ my $scoped_class = ".type_$type"; >+ my $css_content; >+ >+ if ( $self->message_transport_type eq 'email' ) { >+ $css_content = C4::Context->preference("EmailNoticeCSS"); >+ } elsif ( $self->message_transport_type eq 'print' ) { >+ $css_content = C4::Context->preference("PrintNoticeCSS"); >+ } >+ >+ # Modify the CSS content, handling @media, @supports, @document >+ $css_content =~ s! >+ (@(media|supports|-moz-document)[^\{]+\{) # Match the at-rule start >+ ( # Capture group for block content >+ (?: # Non-capturing group >+ [^{]+\{[^}]*\} # Match CSS rules within the at-rule block >+ )* >+ ) >+ \} >+ ! >+ my $header = $1; >+ my $inner_rules = $2; # Capture the rules within the at-rule block >+ >+ # Apply the scoped class to the inner rules >+ $inner_rules =~ s/([^{]+)\{/ $scoped_class $1\{/g; >+ >+ # Return the modified block >+ "$header$inner_rules" >+ >+ !egx; >+ >+ $css_content =~ s/([^{]+)\{/$scoped_class $1\{/g >+ unless $css_content =~ /\@(media|supports|-moz-document)/; >+ >+ return $css_content; >+} >+ > =head3 type > > =cut >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt >index 1eeac25000a..e6d6576a308 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt >@@ -54,7 +54,7 @@ > <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 > > >- <form id="print_multiple" action="/cgi-bin/koha/tools/print_notice.pl" method="post" target="_blank"> >+ <form id="print_multiple" action="/cgi-bin/koha/members/print_notice.pl" method="post" target="_blank"> > [% INCLUDE 'csrf-token.inc' %] > > <table id="noticestable"> >@@ -159,7 +159,7 @@ > </td> > <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> >+ <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 > > > </tr> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/print_notice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/print_notice.tt >new file mode 100644 >index 00000000000..6e3bd925dda >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/print_notice.tt >@@ -0,0 +1,46 @@ >+[% USE raw %] >+[% USE Asset %] >+[% USE Koha %] >+[% PROCESS 'i18n.inc' %] >+[% SET footerjs = 1 %] >+[% INCLUDE 'doc-head-open.inc' %] >+ [% UNLESS notices && notices.size %] >+ [% SET notices = [{content => notice, is_html => is_html, style => style, id => id }] %] >+ [% END %] >+ <title>[% FILTER collapse %] >+ [% IF notices.size > 1 %] >+ [% t("Print notices") | html %] › >+ [% ELSE %] >+ [% t("Print notice") | html %] › >+ [% END %] >+ [% t("Patrons") | html %] › >+ [% t("Koha") | html %] >+ [% END %]</title> >+ [% INCLUDE 'doc-head-close.inc' %] >+ [% Asset.css("css/print.css") | $raw %] >+ [% IF ( Koha.Preference('AllNoticeCSS') ) %] >+ <style>[% Koha.Preference('AllNoticeCSS') | $raw %]</style> >+ [% END %] >+ [% FOR style IN styles %] >+ <style>[% style | $raw %]</style> >+ [% END %] >+ [% FOR notice IN notices %] >+ [% IF notice.style %]<style>[% notice.style.replace('([^\{\}]+?)\s*\{', '#notice_' _ notice.id _ ' $1 {') | $raw %]</style>[% END %] >+ [% END %] >+</head> >+<body id="members_printnotice" class="member"> >+[% FOR notice IN notices %] >+ <div id="notice_[% notice.id | html %]" class="type_[% notice.type | html %]"> >+ [% IF notice.is_html %] >+ [% IF ( notice.content ) %][% notice.content | $raw %][% ELSE %]No notice template found[% END %] >+ [% ELSE %] >+ <pre>[% IF ( notice.content ) %][% notice.content | html %][% ELSE %]No notice template found[% END %]</pre> >+ [% END %] >+ </div> >+ [% IF notices.size > 1 && !loop.last%]<div class="pagebreak"></div>[% END %] >+[% END %] >+[% MACRO jsinclude BLOCK %] >+ [% INCLUDE 'slip-print.inc' #printThenClose %] >+[% END %] >+ >+[% INCLUDE 'intranet-bottom.inc' %] >\ No newline at end of file >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt >deleted file mode 100644 >index dd031b34fb2..00000000000 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/printnotice.tt >+++ /dev/null >@@ -1,36 +0,0 @@ >-[% USE raw %] >-[% USE Asset %] >-[% USE Koha %] >-[% PROCESS 'i18n.inc' %] >-[% SET footerjs = 1 %] >-[% INCLUDE 'doc-head-open.inc' %] >-<title >- >[% FILTER collapse %] >- [% title | html %] >- › [% t("Patrons") | html %] › [% t("Koha") | html %] >- [% END %]</title >-> >-[% INCLUDE 'doc-head-close.inc' %] >- >-<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" /> >- >-[% Asset.css("css/print.css") | $raw %] <!-- prettier-ignore-start --> >-[% IF style %]<style>[% style | $raw %]</style>[% END %] >-<!-- prettier-ignore-end --> >-</head> >- >-<body id="members_printslip" class="member"> >-<div id="slip"> >- [% IF plain %] >- <pre>[% IF ( slip ) %][% slip | html %][% ELSE %]No slip template found[% END %]</pre> >- [% ELSE %] >- [% IF ( slip ) %][% slip | $raw %][% ELSE %]No slip template found[% END %] >- [% END %] >-</div> >- >-[% MACRO jsinclude BLOCK %] >- [% INCLUDE 'slip-print.inc' #printThenClose %] >-[% END %] >- >-[% INCLUDE 'intranet-bottom.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/notices.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/notices.tt >index fad891d0e67..a4a7c36ae42 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/notices.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/notices.tt >@@ -56,7 +56,7 @@ > <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 > > >- <form id="print_multiple" action="/cgi-bin/koha/tools/print_notice.pl" method="post" target="_blank"> >+ <form id="print_multiple" action="/cgi-bin/koha/members/print_notice.pl" method="post" target="_blank"> > [% INCLUDE 'csrf-token.inc' %] > <table id="notices"> > <thead> >@@ -155,7 +155,7 @@ > [% END %] > </td> > <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 >+ ><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 > > > </tr> > [% END %] >diff --git a/tools/print_notice.pl b/members/print_notice.pl >similarity index 76% >rename from tools/print_notice.pl >rename to members/print_notice.pl >index 90f4617cff8..3a2da2c7461 100644 >--- a/tools/print_notice.pl >+++ b/members/print_notice.pl >@@ -27,33 +27,40 @@ my $input = CGI->new; > > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > { >- template_name => "circ/printslip.tt", >+ template_name => "members/print_notice.tt", > query => $input, > type => "intranet", > flagsrequired => { tools => 'view_generated_notices' }, > } > ); > >+my $types_seen = {}; >+my @scoped_styles; > my @message_ids = $input->multi_param('message_ids'); >-my @slips; >+my @notices; > foreach my $message_id (@message_ids) { > my $message = Koha::Notice::Messages->find($message_id); > my $template = $message->template; > >- push @slips, { >+ push @notices, { > content => $message->content, > is_html => $message->is_html, > style => $template ? $template->style : undef, > id => $message_id, >+ type => $message->message_transport_type, > }; > >+ unless ( $types_seen->{ $message->message_transport_type } ) { >+ push @scoped_styles, $message->scoped_style; >+ $types_seen->{ $message->message_transport_type } = 1; >+ } >+ > $message->update( { status => 'sent' } ); > } > $template->param( >- slips => \@slips, >- caller => 'notice_mgmt', >- stylesheet => C4::Context->preference("SlipCSS"), >- IntranetSlipPrinterJS => C4::Context->preference('IntranetSlipPrinterJS'), >+ notices => \@notices, >+ stylesheet => C4::Context->preference("AllNoticeStylesheet"), >+ styles => \@scoped_styles > ); > > output_html_with_http_headers $input, $cookie, $template->output; >diff --git a/members/printnotice.pl b/members/printnotice.pl >deleted file mode 100755 >index 7e7bdc81488..00000000000 >--- a/members/printnotice.pl >+++ /dev/null >@@ -1,71 +0,0 @@ >-#!/usr/bin/perl >- >-# Copyright PTFS Europe 2022 >-# >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-use C4::Auth qw( get_template_and_user ); >-use C4::Output qw( output_and_exit_if_error output_html_with_http_headers ); >-use CGI qw ( -utf8 ); >-use C4::Letters; >-use Koha::Account::Lines; >- >-my $input = CGI->new; >- >-my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >- { >- template_name => "members/printnotice.tt", >- query => $input, >- type => "intranet", >- flagsrequired => { >- borrowers => 'edit_borrowers', >- } >- } >-); >- >-my $logged_in_user = Koha::Patrons->find($loggedinuser); >-my $borrowernumber = $input->param('borrowernumber'); >-my $patron = Koha::Patrons->find($borrowernumber); >-output_and_exit_if_error( >- $input, $cookie, >- $template, >- { >- module => 'members', >- logged_in_user => $logged_in_user, >- current_patron => $patron >- } >-); >- >-my $letter_code = $input->param('notice'); >-my $letter = C4::Letters::GetPreparedLetter( >- module => 'members', >- letter_code => $letter_code, >- branchcode => C4::Context::mybranch, >- message_transport_type => 'print', >- lang => $patron->lang, >- tables => { borrowers => $patron->borrowernumber } >-); >- >-$template->param( >- title => $letter->{title}, >- slip => $letter->{content}, >- plain => !$letter->{is_html}, >- style => $letter->{style}, >-); >- >-output_html_with_http_headers $input, $cookie, $template->output; >-- >2.48.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33260
:
148437
|
148438
|
148439
|
148440
|
148943
|
149009
|
149413
|
149581
|
149593
|
149594
|
149595
|
149596
|
149597
|
149598
|
150346
|
150347
|
154927
|
154928
|
157383
|
157384
|
157385
|
157386
|
158852
|
158853
|
158854
|
158855
|
162570
|
162571
|
162572
|
162573
|
162574
|
162624
|
162625
|
162677
|
162678
|
162679
|
162680
|
162681
|
164783
|
164784
|
164785
|
164786
|
164787
|
165238
|
165239
|
165717
|
165939
|
165946
|
165947
|
165948
|
165949
|
165950
|
165951
|
166020
|
166178
|
166335
|
166336
|
166337
|
166338
|
166339
|
166340
|
166341
|
166342
|
166343
|
166344
|
166345
|
166362
|
166363
|
166364
|
166365
|
166366
|
166367
|
166368
|
166369
|
166370
|
166371
|
166372
|
166373
|
167909
|
167910
|
167911
|
167912
|
167913
|
167914
|
167915
|
167916
|
167917
|
167918
|
167919
|
167920
|
172247
|
172248
|
172303
|
172307
|
172308
|
172309
|
172310
|
172311
|
172312
|
172313
|
172314
|
172315
|
172316
|
172317
|
172318
|
172319
|
172320
|
172321
|
172322
|
172342
|
172343
|
172344
|
172345
|
172346
|
172347
|
172348
|
172349
|
172350
|
172351
|
172352
|
172353
|
172354
|
172355
|
172356
|
172357
|
172358
|
172359
|
172379
|
175501
|
175502
|
175503
|
175504
|
175505
|
175506
|
175507
|
175508
|
175509
|
175510
|
175511
|
175512
|
175513
|
175514
|
175515
|
175516
|
175517
|
175518
|
175519
|
175520
|
175521
|
175522
|
175523
|
175524
|
175525
|
175530
|
175537
|
175538
|
175539
|
175540
|
175541
|
175542
|
175543
|
175544
|
175545
|
175546
|
175547
|
175548
|
175549
|
175550
|
175551
|
175552
|
175553
|
175554
|
175555
|
175556
|
175557
|
175558
|
175559
|
175560
|
175561
|
175562
|
175563
|
175730
|
175731
|
175732
|
175733
|
175734
|
175735
|
175736
|
175737
|
175738
|
175739
|
175740
|
175741
|
175742
|
175743
|
175744
|
175745
|
175746
|
175747
|
175748
|
175749
|
175750
|
175751
|
175752
|
175753
|
175754
|
175755
|
175756
|
178733
|
178734
|
178735
|
178736
|
178737
|
178738
|
178739
|
178740
|
178741
|
178742
|
178743
|
178744
|
178745
|
178746
|
178747
|
178748
|
178749
|
178750
|
178751
|
178752
|
178753
|
178754
|
178755
|
178756
|
178757
|
178758
| 178759