From d000bd49c59862cf9ecd1ffdd359940dd79c388e Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Thu, 9 Oct 2025 16:11:56 +0000 Subject: [PATCH] Bug 40659: Add ability to customize OPACVirtualCard To test: 1. Turn on the OPACVirtualCard. 2. Log in to the OPAC as a patron and go look at your Library card ( opac-virtual-card.pl ) 3. APPLY PATCH, updatedatabase, restart_all 4. Go again at your patron's card on the OPAC ( opac-virtual-card.pl ), it should look exactly the same. 5. Go to Tools > Notices > VIRTUALCARD 6. You should see the default content for the library card. 7. Play around with different variables from borrower, like [% borrower.firstname%] and branches, like [% branch.branchcode %] 8. You can also move around the barcode by using the placeholder value [% my_barcode %]. 9. Put the [% my_barcode %] variable anywhere you want in the notice then go to the sys pref "OPACVirtualCardBarcode". 10. Change to different barcode types and relaod the library card page ( opac-virtual-card.pl ). You should notice the barcode type is being honored. 11. Turn on OPACpatronimages AND patronimages, then upload a patron image for your patron. 12. Use the [% my_image %] variable anywhere you want in the notice to place the patron image. 13. Leaving the [% my_image %] variable as is, turn off OPACpatronimages. 14. Reload the OPAC page, no image should display. 15. Delete the VIRTUALCARD notice. 16. Go back to the OPAC page and with the notice deleted you should see the hardcoded content. ie: the page should look exactly the same as it does without this patch. --- .../bootstrap/en/modules/opac-virtual-card.tt | 38 ++++++++++--------- opac/opac-virtual-card.pl | 32 ++++++++++++++-- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-virtual-card.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-virtual-card.tt index b0a9980c3ba..7448c0a9d13 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-virtual-card.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-virtual-card.tt @@ -33,24 +33,28 @@

Your library card

- [% IF ( display_patron_image ) %] -
- -
- [% END %]
-
- -
-
-

Library: [% Branches.GetName( patron.branchcode ) | html %]

-
-
-

Card number: [% patron.cardnumber | html %]

-
-
-

Expiration date: [% patron.dateexpiry | $KohaDates %]

-
+ [% IF content.content %] + [% content.content | $raw %] + [% ELSE %] + [% IF ( display_patron_image ) %] +
+ +
+ [% END %] +
+ +
+
+

Library: [% Branches.GetName( patron.branchcode ) | html %]

+
+
+

Card number: [% patron.cardnumber | html %]

+
+
+

Expiration date: [% patron.dateexpiry | $KohaDates %]

+
+ [% END %]
diff --git a/opac/opac-virtual-card.pl b/opac/opac-virtual-card.pl index aa2fe57187e..c44f84910d7 100755 --- a/opac/opac-virtual-card.pl +++ b/opac/opac-virtual-card.pl @@ -24,6 +24,8 @@ use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); use Koha::Libraries; use Koha::Patrons; +use C4::Letters qw( GetPreparedLetter ); +use C4::Scrubber; my $query = CGI->new; @@ -44,17 +46,41 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( my $patron = Koha::Patrons->find($borrowernumber); # Find and display patron image if allowed -if ( C4::Context->preference('OPACpatronimages') ) { - $template->param( display_patron_image => 1 ) if $patron->image; +my $image_html = ''; +if ( C4::Context->preference('OPACpatronimages') && $patron->image ) { + $template->param( display_patron_image => 1 ); + $image_html = + '
'; } # Get the desired barcode format -my $barcode_format = C4::Context->preference('OPACVirtualCardBarcode'); +my $barcode_format = C4::Context->preference('OPACVirtualCardBarcode') || 'Code39'; +my $barcode_html = + qq{
}; + +my $content = C4::Letters::GetPreparedLetter( + ( + module => 'members', + letter_code => 'VIRTUALCARD', + branchcode => $patron->branchcode, + tables => { + borrowers => $patron->borrowernumber, + branches => $patron->branchcode, + }, + lang => $patron->lang, + message_transport_type => 'email', + substitute => { + my_barcode => $barcode_html, + my_image => $image_html, + }, + ) +); $template->param( virtualcardview => 1, patron => $patron, barcode_format => $barcode_format, + content => $content, ); output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; -- 2.39.5