Bug 28130: Manage subscription alerts on OPAC

This patch adds an 'Alert subscriptions' tab to the patron's account on the OPAC, so they can easily view or cancel email alerts they have subscribed to.

To test:

1. Subscribe to email alerts for one or more subscriptions via the OPAC
2. Go to your account, notice the new 'Alert subscriptions' menu option, click here
3. Confirm your subscribed alerts show here. Confirm the table sorting works etc (JS enabled).
4. Test unsubscribing from email alerts, make sure the confirmation pop-up works as expected (JS enabled).
5. Confirm that, when unsubscribing, you are redirected back to this page.
6. Confirm the menu option disappears from the left sidebar navigation if you have no alert subscriptions.

Sponsored-by: Bibliotheksservice-Zentrum Baden-Wuerttemberg
Signed-off-by: Christian Stelzenmüller <christian.stelzenmueller@bsz-bw.de>
Signed-off-by: Sam Lau <samalau@gmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Aleisha Amohia 2023-05-24 21:53:38 +00:00 committed by Tomas Cohen Arazi
parent 84e5c570db
commit e790f75c0d
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
4 changed files with 177 additions and 0 deletions

View file

@ -157,6 +157,15 @@
<a href="/cgi-bin/koha/opac-curbside-pickups.pl">Curbside pickups</a></li>
[% END %]
[% IF logged_in_user.alert_subscriptions.count %]
[% IF ( alertsview ) %]
<li class="active">
[% ELSE %]
<li>
[% END %]
<a href="/cgi-bin/koha/opac-alert-subscriptions.pl">Alert subscriptions ([% logged_in_user.alert_subscriptions.count | html %])</a></li>
[% END %]
</ul>
</div>
[% END %]

View file

@ -0,0 +1,111 @@
[% USE Koha %]
[% USE Branches %]
[% USE AuthorisedValues %]
[% USE AdditionalContents %]
[% SET OpacNav = AdditionalContents.get( location => "OpacNav", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %]
[% SET OpacNavBottom = AdditionalContents.get( location => "OpacNavBottom", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Your alert subscriptions &rsaquo; [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog</title>
[% INCLUDE 'doc-head-close.inc' %]
[% BLOCK cssinclude %][% END %]
</head>
[% INCLUDE 'bodytag.inc' bodyid='opac-alert-subscriptions' %]
[% INCLUDE 'masthead.inc' %]
<div class="main">
<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumbs">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="/cgi-bin/koha/opac-main.pl">Home</a>
</li>
<li class="breadcrumb-item">
<a href="/cgi-bin/koha/opac-user.pl">[% INCLUDE 'patron-title.inc' patron = logged_in_user %]</a>
</li>
<li class="breadcrumb-item active">
<a href="#" aria-current="page">Your alert subscriptions</a>
</li>
</ol>
</nav> <!-- /#breadcrumbs -->
<div class="container-fluid">
<div class="row">
<div class="col col-lg-2 order-2 order-lg-1">
<div id="navigation">
[% INCLUDE 'navigation.inc' IsPatronPage=1 %]
</div>
</div>
<div class="col-md-12 col-lg-10 order-1">
<div id="alert-subscriptions" class="maincontent">
<h1>Alert subscriptions</h1>
[% IF patron.alert_subscriptions.count %]
<table id="subscriptions" class="table table-bordered table-striped">
<thead>
<tr>
<th>ISSN</th>
<th>Title</th>
<th>Library</th>
<th>Location</th>
<th>Call number</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
[% FOREACH sub IN patron.alert_subscriptions %]
<tr>
<td>
[% IF sub.biblio.biblioitem.issn %][% sub.biblio.biblioitem.issn | html %][% END %]
</td>
<td>
<a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% sub.biblionumber | uri %]">[% sub.biblio.title | html %] [% sub.biblio.subtitle | html %]</a>
</td>
<td>
[% IF ( sub.branchcode ) %][% Branches.GetName( sub.branchcode ) | html %][% END %]
</td>
<td>
[% IF ( sub.location ) %][% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => sub.location ) | html %][% END %]
</td>
<td>
[% IF ( sub.callnumber ) %][% sub.callnumber | html %][% END %]
</td>
<td class="actions">
<form action="/cgi-bin/koha/opac-alert-subscribe.pl" method="post" class="unsubscribe" data-title="[% sub.biblio.title | html %] [% sub.biblio.subtitle | html %]" data-patron="[% INCLUDE 'patron-title.inc' no_html=1 patron=logged_in_user%]">
<input type="hidden" name="subscriptionid" value="[% sub.subscriptionid | html %]">
<input type="hidden" name="referer" value="[% referer | html %]">
<input type="hidden" name="biblionumber" value="[% sub.biblionumber | html %]">
<input type="hidden" name="op" value="cancel_confirmed">
<button type="submit" class="btn btn-link btn-sm" name="submit"><i class="fa fa-times" aria-hidden="true"></i> Unsubscribe from email alerts</button>
</form>
</td>
</tr>
[% END %]
</tbody>
</table>
[% ELSE %]
<div class="dialog message">
<p>You have not subscribed to email alerts for any subscriptions.</p>
</div>
[% END %]
</div> <!-- /#alert-subscriptions -->
</div> <!-- / .col-lg-10 -->
</div> <!-- / .row -->
</div> <!-- / .container-fluid -->
</div> <!-- / .main -->
[% INCLUDE 'opac-bottom.inc' %]
[% BLOCK jsinclude %]
[% INCLUDE 'datatables.inc' %]
<script>
$(document).ready(function(){
$("#subscriptions").dataTable($.extend(true, {}, dataTablesDefaults, {
}));
$(".unsubscribe").submit(function(){
var patron = $(this).data('patron');
var title = $(this).data('title');
return confirmDelete(__("Are you sure you want to unsubscribe %s from email alerts for %s?").format(patron, title));
});
});
</script>
[% END %]

View file

@ -67,6 +67,10 @@ elsif ( $op eq 'cancel_confirmed' ) {
print $query->redirect(
"opac-serial-issues.pl?biblionumber=$biblionumber");
exit;
} elsif ( $referer eq 'patron' ) {
print $query->redirect(
"/cgi-bin/koha/opac-alert-subscriptions.pl"
);
} else {
print $query->redirect(
"opac-detail.pl?biblionumber=$biblionumber");

View file

@ -0,0 +1,53 @@
#!/usr/bin/perl
# Copyright 2023 Aleisha Amohia <aleisha@catalyst.net.nz>
#
# 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 CGI qw ( -utf8 );
use C4::Auth qw( get_template_and_user );
use C4::Context;
use C4::Output qw( output_html_with_http_headers );
use Koha::Patrons;
use Koha::Token;
my $query = CGI->new();
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
{
template_name => 'opac-alert-subscriptions.tt',
query => $query,
type => 'opac',
}
);
my $patron = Koha::Patrons->find( $borrowernumber );
$template->param(
alertsview => 1,
patron => $patron,
referer => 'patron',
);
my $new_session_id = $query->cookie('CGISESSID');
$template->param(
csrf_token => Koha::Token->new->generate_csrf({
session_id => $new_session_id,
}),
);
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };