BUGFIXING mail alert on issue arrival
authorPaul POULAIN <paul.poulain@biblibre.com>
Fri, 29 Feb 2008 00:38:13 +0000 (13:38 +1300)
committerJoshua Ferraro <jmf@liblime.com>
Fri, 29 Feb 2008 15:05:33 +0000 (09:05 -0600)
To make this feature work :
- create a "notice" (tools/letter.pl) of the category "serials"
- choose this notice in each subscription you want to enable this feature

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Letters.pm
koha-tmpl/opac-tmpl/prog/en/modules/opac-alert-subscribe.tmpl [new file with mode: 0644]
koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl
koha-tmpl/opac-tmpl/prog/en/modules/opac-serial-issues.tmpl
opac/opac-alert-subscribe.pl
opac/opac-detail.pl
opac/opac-serial-issues.pl

index 857dc56..dffe2c2 100644 (file)
@@ -173,21 +173,21 @@ sub delalert {
 sub getalert {
     my ( $borrowernumber, $type, $externalid ) = @_;
     my $dbh   = C4::Context->dbh;
-    my $query = "select * from alert where";
+    my $query = "SELECT * FROM alert WHERE";
     my @bind;
     if ($borrowernumber =~ /^\d+$/) {
-        $query .= " borrowernumber=? and";
+        $query .= " borrowernumber=? AND ";
         push @bind, $borrowernumber;
     }
     if ($type) {
-        $query .= " type=? and";
+        $query .= " type=? AND ";
         push @bind, $type;
     }
     if ($externalid) {
-        $query .= " externalid=? and";
+        $query .= " externalid=? AND ";
         push @bind, $externalid;
     }
-    $query =~ s/ and$//;
+    $query =~ s/ AND $//;
     my $sth = $dbh->prepare($query);
     $sth->execute(@bind);
     my @result;
@@ -252,7 +252,7 @@ sub SendAlerts {
         # search the biblionumber
         my $sth =
           $dbh->prepare(
-            "select biblionumber from subscription where subscriptionid=?");
+            "SELECT biblionumber FROM subscription WHERE subscriptionid=?");
         $sth->execute($externalid);
         my ($biblionumber) = $sth->fetchrow;
 
@@ -280,10 +280,10 @@ sub SendAlerts {
             parseletter( $innerletter, 'borrowers', $_->{'borrowernumber'} );
 
             # ... then send mail
-            if ( $borinfo->{emailaddress} ) {
+            if ( $borinfo->{email} ) {
                 my %mail = (
-                    To      => $borinfo->{emailaddress},
-                    From    => $userenv->{emailaddress},
+                    To      => $borinfo->{email},
+                    From    => $borinfo->{email},
                     Subject => "" . $innerletter->{title},
                     Message => "" . $innerletter->{content},
                 );
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-alert-subscribe.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-alert-subscribe.tmpl
new file mode 100644 (file)
index 0000000..d464832
--- /dev/null
@@ -0,0 +1,41 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><!-- TMPL_IF NAME="LibraryNameTitle" --><!-- TMPL_VAR NAME="LibraryNameTitle" --><!-- TMPL_ELSE -->Koha Online<!-- /TMPL_IF --> Catalog &rsaquo;  Serials
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+</head>
+<body>
+<!-- TMPL_INCLUDE name="masthead.inc" -->
+
+<div id="doc3" class="yui-t1">
+<div id="bd">
+    <div id="yui-main">
+    <div class="yui-b"><div class="yui-g">
+    <!-- TMPL_IF name="typeissue" -->
+        <h1 class="catalogue">Subscribe issue recieve warning</h1>
+            <form action="opac-alert-subscribe.pl" method="post">
+                <p>Do you want to be mailed when a new issue for this subscription arrives at the library ?</p>
+                <!-- TMPL_VAR name="bibliotitle" --> <!-- TMPL_IF name="notes" -->(<!-- TMPL_VAR name="notes" -->)<!-- /TMPL_IF --> arrive ?</p>
+                <input type="hidden" name="externalid" value="<!-- TMPL_VAR name="externalid" -->">
+                <input type="hidden" name="alerttype" value="issue">
+                <input type="hidden" name="biblionumber" value="<!-- TMPL_VAR name="biblionumber" -->">
+                <input type="hidden" name="op" value="alert_confirmed">
+                <input type="submit" value="Yes">
+                <a href="opac-serial-issues.pl?biblionumber=<!-- TMPL_VAR name="biblionumber" -->" >No</a>
+            </form>
+        </div>
+    <!-- /TMPL_IF -->
+    <!-- TMPL_IF name="typeissuecancel" -->
+        <h1 class="catalogue">Unsubscribe</h1>
+            <form action="opac-alert-subscribe.pl" method="post">
+                <p>Do you confirm you want to unsubscribe mail warning for this subscription ?</p>
+                <!-- TMPL_VAR name="bibliotitle" --> <!-- TMPL_IF name="notes" -->(<!-- TMPL_VAR name="notes" -->)<!-- /TMPL_IF --> ?</p>
+                <input type="hidden" name="externalid" value="<!-- TMPL_VAR name="externalid" -->">
+                <input type="hidden" name="alerttype" value="issue">
+                <input type="hidden" name="biblionumber" value="<!-- TMPL_VAR name="biblionumber" -->">
+                <input type="hidden" name="op" value="cancel_confirmed">
+                <input type="submit" value="Yes" class="button">
+                <a href="opac-serial-issues.pl?biblionumber=<!-- TMPL_VAR name="biblionumber" -->" class="button">No</a>
+            </form>
+        </div>
+    <!-- /TMPL_IF -->
+</div>
+
+<!-- TMPL_INCLUDE NAME="opac-bottom.inc" -->
index 36e0b9f..02989bc 100755 (executable)
         </table>
         <!-- /TMPL_IF -->
         <!-- /TMPL_LOOP -->
+               <p><a href="opac-serial-issues.pl?biblionumber=<!-- TMPl_VAR name="biblionumber" -->">More details</a></p>
     </div>
     <!-- /TMPL_IF -->
 
index e89da91..0594855 100644 (file)
             <!-- TMPL_VAR name="opacnote" -->
         </p>
     <!-- /TMPL_IF -->
+    <!-- TMPL_IF name="letter" -->
+        <!-- TMPL_IF name="hasalert" -->
+            You already follow this subscription <a href="opac-alert-subscribe.pl?op=cancel&amp;externalid=<!-- TMPL_VAR name="subscriptionid" -->&amp;alerttype=issue&amp;biblionumber=<!-- TMPL_VAR name="biblionumber" -->" class="button" title="Cancel alert">
+                Cancel mail alert
+            </a>
+        <!-- TMPL_ELSE -->
+            <a href="opac-alert-subscribe.pl?externalid=<!-- TMPL_VAR name="subscriptionid" -->&amp;alerttype=issue&amp;biblionumber=<!-- TMPL_VAR name="biblionumber" -->" class="button" title="Be alerted when an issue arrive at the library">
+                Be mailed when a new issue arrives at the library
+            </a>
+        <!-- /TMPL_IF -->
+    <!-- /TMPL_IF -->
+
 <!-- /TMPL_LOOP -->
 
 </div>
index d357af4..d0b68b1 100755 (executable)
@@ -59,6 +59,7 @@ if ( $op eq 'alert_confirmed' ) {
 }
 elsif ( $op eq 'cancel_confirmed' ) {
     my $alerts = getalert( $loggedinuser, $alerttype, $externalid );
+    warn "CANCEL confirmed : $loggedinuser, $alerttype, $externalid".Data::Dumper::Dumper( $alerts );
     foreach (@$alerts)
     {    # we are supposed to have only 1 result, but just in case...
         delalert( $_->{alertid} );
index b424ea7..2dcb22b 100755 (executable)
@@ -68,6 +68,7 @@ foreach my $subscription (@subscriptions) {
     $cell{subscriptionid}    = $subscription->{subscriptionid};
     $cell{subscriptionnotes} = $subscription->{notes};
     $cell{branchcode}        = $subscription->{branchcode};
+    $cell{hasalert}          = $subscription->{hasalert};
     #get the three latest serials.
     $cell{latestserials} =
       GetLatestSerials( $subscription->{subscriptionid}, 3 );
index 4aceed9..8fabcca 100755 (executable)
@@ -41,13 +41,6 @@ my $sth;
 my ( $template, $loggedinuser, $cookie );
 my $biblionumber = $query->param('biblionumber');
 if ( $selectview eq "full" ) {
-    my $subscriptions = GetFullSubscriptionsFromBiblionumber($biblionumber);
-    my $subscriptioninformation=PrepareSerialsData($subscriptions);
-
-    my $title   = $subscriptions->[0]{bibliotitle};
-    my $yearmin = $subscriptions->[0]{year};
-    my $yearmax = $subscriptions->[ scalar(@$subscriptions) - 1 ]{year};
-
     ( $template, $loggedinuser, $cookie ) = get_template_and_user(
         {
             template_name   => "opac-full-serial-issues.tmpl",
@@ -57,6 +50,19 @@ if ( $selectview eq "full" ) {
             debug           => 1,
         }
     );
+    my $subscriptions = GetFullSubscriptionsFromBiblionumber($biblionumber);
+    my $subscriptioninformation=PrepareSerialsData($subscriptions);
+    # now, check is there is an alert subscription for one of the subscriptions
+    foreach (@$subscriptions) {
+        if (getalert($loggedinuser,'issue',$_->{subscriptionid})) {
+            $_->{hasalert} = 1;
+        }
+    }
+
+    my $title   = $subscriptions->[0]{bibliotitle};
+    my $yearmin = $subscriptions->[0]{year};
+    my $yearmax = $subscriptions->[ scalar(@$subscriptions) - 1 ]{year};
+
 
     # replace CR by <br> in librarian note
     # $subscription->{opacnote} =~ s/\n/\<br\/\>/g;
@@ -73,8 +79,6 @@ if ( $selectview eq "full" ) {
 
 }
 else {
-    my $subscriptions = GetSubscriptionsFromBiblionumber($biblionumber);
-
     ( $template, $loggedinuser, $cookie ) = get_template_and_user(
         {
             template_name   => "opac-serial-issues.tmpl",
@@ -85,6 +89,16 @@ else {
         }
     );
 
+    my $subscriptions = GetSubscriptionsFromBiblionumber($biblionumber);
+    # now, check is there is an alert subscription for one of the subscriptions
+    foreach (@$subscriptions) {
+        my $subscription = getalert($loggedinuser,'issue',$_->{subscriptionid});
+        if (@$subscription[0]) {
+               warn ">>>>>>>>> has alert : loggedinuser / ".$_->{subscriptionid};
+            $_->{hasalert} = 1;
+        }
+    }
+
     # replace CR by <br> in librarian note
     # $subscription->{opacnote} =~ s/\n/\<br\/\>/g;