From 3876834846d4ff781968c11f5a2ce002eb149927 Mon Sep 17 00:00:00 2001
From: Aleisha Amohia <aleishaamohia@hotmail.com>
Date: Mon, 6 Feb 2017 21:26:54 +0000
Subject: [PATCH] Bug 10357: Adding link for email notification for new
 subscription issues to opac-detail
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch adds the link to the opac-detail.pl page so it is less hard
to find.
Update: Fixing link to look like button, adding span ID around element

To test:
1) Add a subscription, attach it to a record and select a notice under
'Patron notification'. Hit Next, fill in some fields and save the
subscription
2) Go to that record detail page in the OPAC. Go to the subscriptions
tab, click 'More details'. Notice how many clicks it takes to see the
'Subscribe' button
3) Apply patch and go back to the details page for the record
4) Notice now there is a 'subscribe' link
5) Confirm this link still works as expected

Sponsored-by: Catalyst IT

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>
Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>
---
 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt | 11 +++++++++++
 opac/opac-detail.pl                                     | 10 +++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
index e4fb61f..3c4b181 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
@@ -810,6 +810,17 @@
                                     <p>[% subscription.subscriptionnotes FILTER html_line_break %] </p>
                                 [% END %]
                                 <p>Subscription from: [% subscription.histstartdate | $KohaDates %] to:[% IF ( subscription.histenddate ) %] [% subscription.histenddate | $KohaDates %] [% ELSE %] now (current)[% END %]</p>
+                                <span id="email_notifications">[% IF ( subscription.letter ) %]
+                                    [% IF ( loggedinusername ) %]
+                                        [% IF ( subscription.hasalert ) %]
+                                            You have subscribed to email notification on new issues. <a class="btn" title="Cancel email notification" href="/cgi-bin/koha/opac-alert-subscribe.pl?op=cancel&amp;externalid=[% subscription.subscriptionid %]&amp;alerttype=issue&amp;biblionumber=[% subscription.biblionumber %]">Cancel email notification</a>
+                                        [% ELSE %]
+                                            <a class="btn" title="Subscribe to email notification on new issues" href="/cgi-bin/koha/opac-alert-subscribe.pl?externalid=[% subscription.subscriptionid %]&amp;alerttype=issue&amp;biblionumber=[% subscription.biblionumber %]">Subscribe to email notification on new issues</a>
+                                        [% END %]
+                                    [% ELSE %]
+                                        You must log in if you want to subscribe to email notification on new issues
+                                    [% END %]
+                                [% END %]</span>
                                 [% IF ( subscription.missinglist ) %]
                                     <p>Missing issues: [% subscription.missinglist %] </p>
                                 [% END %]
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl
index a7e643c..10e8184 100755
--- a/opac/opac-detail.pl
+++ b/opac/opac-detail.pl
@@ -40,6 +40,7 @@ use C4::XSLT;
 use C4::ShelfBrowser;
 use C4::Reserves;
 use C4::Charset;
+use C4::Letters;
 use MARC::Record;
 use MARC::Field;
 use List::MoreUtils qw/any none/;
@@ -568,15 +569,22 @@ foreach my $subscription (@subscriptions) {
     $cell{histstartdate}     = $subscription->{histstartdate};
     $cell{histenddate}       = $subscription->{histenddate};
     $cell{branchcode}        = $subscription->{branchcode};
-    $cell{hasalert}          = $subscription->{hasalert};
     $cell{callnumber}        = $subscription->{callnumber};
     $cell{closed}            = $subscription->{closed};
+    $cell{letter}            = $subscription->{letter};
+    $cell{biblionumber}      = $subscription->{biblionumber};
     #get the three latest serials.
     $serials_to_display = $subscription->{opacdisplaycount};
     $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
 	$cell{opacdisplaycount} = $serials_to_display;
     $cell{latestserials} =
       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
+    if ( $borrowernumber ) {
+        my $sub = getalert($borrowernumber,'issue',$subscription->{subscriptionid});
+        if (@$sub[0]) {
+            $cell{hasalert} = 1;
+        }
+    }
     push @subs, \%cell;
 }
 
-- 
2.1.4