View | Details | Raw Unified | Return to bug 19855
Collapse All | Expand All

(-)a/C4/Letters.pm (-19 / +13 lines)
Lines 262-285 sub DelLetter { Link Here
262
    , undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) );
262
    , undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) );
263
}
263
}
264
264
265
=head2 addalert ($borrowernumber, $type, $externalid)
265
=head2 addalert ($borrowernumber, $subscriptionid)
266
266
267
    parameters : 
267
    parameters : 
268
    - $borrowernumber : the number of the borrower subscribing to the alert
268
    - $borrowernumber : the number of the borrower subscribing to the alert
269
    - $type : the type of alert.
269
    - $subscriptionid
270
    - $externalid : the primary key of the object to put alert on. For issues, the alert is made on subscriptionid.
270
271
    
272
    create an alert and return the alertid (primary key)
271
    create an alert and return the alertid (primary key)
273
272
274
=cut
273
=cut
275
274
276
sub addalert {
275
sub addalert {
277
    my ( $borrowernumber, $type, $externalid ) = @_;
276
    my ( $borrowernumber, $subscriptionid) = @_;
278
    my $dbh = C4::Context->dbh;
277
    my $dbh = C4::Context->dbh;
279
    my $sth =
278
    my $sth =
280
      $dbh->prepare(
279
      $dbh->prepare(
281
        "insert into alert (borrowernumber, type, externalid) values (?,?,?)");
280
        "insert into alert (borrowernumber, externalid) values (?,?)");
282
    $sth->execute( $borrowernumber, $type, $externalid );
281
    $sth->execute( $borrowernumber, $subscriptionid );
283
282
284
    # get the alert number newly created and return it
283
    # get the alert number newly created and return it
285
    my $alertid = $dbh->{'mysql_insertid'};
284
    my $alertid = $dbh->{'mysql_insertid'};
Lines 301-318 sub delalert { Link Here
301
    $sth->execute($alertid);
300
    $sth->execute($alertid);
302
}
301
}
303
302
304
=head2 getalert ([$borrowernumber], [$type], [$externalid])
303
=head2 getalert ([$borrowernumber], [$subscriptionid])
305
304
306
    parameters :
305
    parameters :
307
    - $borrowernumber : the number of the borrower subscribing to the alert
306
    - $borrowernumber : the number of the borrower subscribing to the alert
308
    - $type : the type of alert.
307
    - $subscriptionid
309
    - $externalid : the primary key of the object to put alert on. For issues, the alert is made on subscriptionid.
308
    all parameters NON mandatory. If a parameter is omitted, the query is done without the corresponding parameter. For example, without $subscriptionid, returns all alerts for a borrower on a topic.
310
    all parameters NON mandatory. If a parameter is omitted, the query is done without the corresponding parameter. For example, without $externalid, returns all alerts for a borrower on a topic.
311
309
312
=cut
310
=cut
313
311
314
sub getalert {
312
sub getalert {
315
    my ( $borrowernumber, $type, $externalid ) = @_;
313
    my ( $borrowernumber, $subscriptionid ) = @_;
316
    my $dbh   = C4::Context->dbh;
314
    my $dbh   = C4::Context->dbh;
317
    my $query = "SELECT a.*, b.branchcode FROM alert a JOIN borrowers b USING(borrowernumber) WHERE 1";
315
    my $query = "SELECT a.*, b.branchcode FROM alert a JOIN borrowers b USING(borrowernumber) WHERE 1";
318
    my @bind;
316
    my @bind;
Lines 320-332 sub getalert { Link Here
320
        $query .= " AND borrowernumber=?";
318
        $query .= " AND borrowernumber=?";
321
        push @bind, $borrowernumber;
319
        push @bind, $borrowernumber;
322
    }
320
    }
323
    if ($type) {
321
    if ($subscriptionid) {
324
        $query .= " AND type=?";
325
        push @bind, $type;
326
    }
327
    if ($externalid) {
328
        $query .= " AND externalid=?";
322
        $query .= " AND externalid=?";
329
        push @bind, $externalid;
323
        push @bind, $subscriptionid;
330
    }
324
    }
331
    my $sth = $dbh->prepare($query);
325
    my $sth = $dbh->prepare($query);
332
    $sth->execute(@bind);
326
    $sth->execute(@bind);
Lines 382-388 sub SendAlerts { Link Here
382
376
383
        my %letter;
377
        my %letter;
384
        # find the list of borrowers to alert
378
        # find the list of borrowers to alert
385
        my $alerts = getalert( '', 'issue', $subscriptionid );
379
        my $alerts = getalert( '', $subscriptionid );
386
        foreach (@$alerts) {
380
        foreach (@$alerts) {
387
            my $patron = Koha::Patrons->find( $_->{borrowernumber} );
381
            my $patron = Koha::Patrons->find( $_->{borrowernumber} );
388
            next unless $patron; # Just in case
382
            next unless $patron; # Just in case
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-alert-subscribe.tt (-2 lines)
Lines 25-31 Link Here
25
                                <h4>[% bibliotitle %]</h4>
25
                                <h4>[% bibliotitle %]</h4>
26
                                [% IF ( notes ) %]<p>[% notes %]</p>[% END %]
26
                                [% IF ( notes ) %]<p>[% notes %]</p>[% END %]
27
                                <input type="hidden" name="externalid" value="[% externalid %]">
27
                                <input type="hidden" name="externalid" value="[% externalid %]">
28
                                <input type="hidden" name="alerttype" value="[% alerttype %]">
29
                                <input type="hidden" name="referer" value="[% referer %]">
28
                                <input type="hidden" name="referer" value="[% referer %]">
30
                                <input type="hidden" name="biblionumber" value="[% biblionumber | html %]">
29
                                <input type="hidden" name="biblionumber" value="[% biblionumber | html %]">
31
                                <input type="hidden" name="op" value="alert_confirmed">
30
                                <input type="hidden" name="op" value="alert_confirmed">
Lines 40-46 Link Here
40
                                <h4>[% bibliotitle %]</h4>
39
                                <h4>[% bibliotitle %]</h4>
41
                                [% IF ( notes ) %]<p>[% notes %]</p>[% END %]
40
                                [% IF ( notes ) %]<p>[% notes %]</p>[% END %]
42
                                <input type="hidden" name="externalid" value="[% externalid %]">
41
                                <input type="hidden" name="externalid" value="[% externalid %]">
43
                                <input type="hidden" name="alerttype" value="[% alerttype %]">
44
                                <input type="hidden" name="referer" value="[% referer %]">
42
                                <input type="hidden" name="referer" value="[% referer %]">
45
                                <input type="hidden" name="biblionumber" value="[% biblionumber | html %]">
43
                                <input type="hidden" name="biblionumber" value="[% biblionumber | html %]">
46
                                <input type="hidden" name="op" value="cancel_confirmed">
44
                                <input type="hidden" name="op" value="cancel_confirmed">
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt (-2 / +2 lines)
Lines 828-836 Link Here
828
                                [% IF ( subscription.letter ) %]<span class="email_notifications">
828
                                [% IF ( subscription.letter ) %]<span class="email_notifications">
829
                                    [% IF ( loggedinusername ) %]
829
                                    [% IF ( loggedinusername ) %]
830
                                        [% IF ( subscription.hasalert ) %]
830
                                        [% IF ( subscription.hasalert ) %]
831
                                            <span>You have subscribed to email notification on new issues. </span><a style="color:#000;" 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>
831
                                            <span>You have subscribed to email notification on new issues. </span><a style="color:#000;" class="btn" title="Cancel email notification" href="/cgi-bin/koha/opac-alert-subscribe.pl?op=cancel&amp;externalid=[% subscription.subscriptionid %]&amp;biblionumber=[% subscription.biblionumber %]">Cancel email notification</a>
832
                                        [% ELSE %]
832
                                        [% ELSE %]
833
                                            <a style="color:#000;" 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>
833
                                            <a style="color:#000;" class="btn" title="Subscribe to email notification on new issues" href="/cgi-bin/koha/opac-alert-subscribe.pl?externalid=[% subscription.subscriptionid %]&amp;biblionumber=[% subscription.biblionumber %]">Subscribe to email notification on new issues</a>
834
                                        [% END %]
834
                                        [% END %]
835
                                    [% ELSE %]
835
                                    [% ELSE %]
836
                                        <span>You must log in if you want to subscribe to email notification on new issues</span>
836
                                        <span>You must log in if you want to subscribe to email notification on new issues</span>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-serial-issues.tt (-2 / +2 lines)
Lines 137-147 Link Here
137
                                    [% IF ( subscription_LOO.letter ) %]
137
                                    [% IF ( subscription_LOO.letter ) %]
138
                                        [% IF ( loggedinusername ) %]
138
                                        [% IF ( loggedinusername ) %]
139
                                            [% IF ( subscription_LOO.hasalert ) %]
139
                                            [% IF ( subscription_LOO.hasalert ) %]
140
                                                You have subscribed to email notification on new issues <a href="opac-alert-subscribe.pl?op=cancel&amp;externalid=[% subscription_LOO.subscriptionid %]&amp;alerttype=issue&amp;referer=serial&amp;biblionumber=[% subscription_LOO.biblionumber %]" class="btn" title="Cancel email notification">
140
                                                You have subscribed to email notification on new issues <a href="opac-alert-subscribe.pl?op=cancel&amp;externalid=[% subscription_LOO.subscriptionid %]&amp;referer=serial&amp;biblionumber=[% subscription_LOO.biblionumber %]" class="btn" title="Cancel email notification">
141
                                                    Cancel email notification
141
                                                    Cancel email notification
142
                                                </a>
142
                                                </a>
143
                                            [% ELSE %]
143
                                            [% ELSE %]
144
                                                <a href="opac-alert-subscribe.pl?externalid=[% subscription_LOO.subscriptionid %]&amp;alerttype=issue&amp;referer=serial&amp;biblionumber=[% subscription_LOO.biblionumber %]" class="btn" title="Subscribe to email notification on new issues">
144
                                                <a href="opac-alert-subscribe.pl?externalid=[% subscription_LOO.subscriptionid %]&amp;referer=serial&amp;biblionumber=[% subscription_LOO.biblionumber %]" class="btn" title="Subscribe to email notification on new issues">
145
                                                    Subscribe to email notification on new issues
145
                                                    Subscribe to email notification on new issues
146
                                                </a>
146
                                                </a>
147
                                            [% END %]
147
                                            [% END %]
(-)a/opac/opac-alert-subscribe.pl (-16 / +12 lines)
Lines 37-43 my $dbh = C4::Context->dbh; Link Here
37
my $sth;
37
my $sth;
38
my ( $template, $loggedinuser, $cookie );
38
my ( $template, $loggedinuser, $cookie );
39
my $externalid   = $query->param('externalid');
39
my $externalid   = $query->param('externalid');
40
my $alerttype    = $query->param('alerttype') || '';
41
my $referer      = $query->param('referer') || 'detail';
40
my $referer      = $query->param('referer') || 'detail';
42
my $biblionumber = $query->param('biblionumber');
41
my $biblionumber = $query->param('biblionumber');
43
42
Lines 53-59 my $biblionumber = $query->param('biblionumber'); Link Here
53
);
52
);
54
53
55
if ( $op eq 'alert_confirmed' ) {
54
if ( $op eq 'alert_confirmed' ) {
56
    addalert( $loggedinuser, $alerttype, $externalid );
55
    addalert( $loggedinuser, $externalid );
57
    if ( $referer eq 'serial' ) {
56
    if ( $referer eq 'serial' ) {
58
        print $query->redirect(
57
        print $query->redirect(
59
            "opac-serial-issues.pl?biblionumber=$biblionumber");
58
            "opac-serial-issues.pl?biblionumber=$biblionumber");
Lines 65-72 if ( $op eq 'alert_confirmed' ) { Link Here
65
    }
64
    }
66
}
65
}
67
elsif ( $op eq 'cancel_confirmed' ) {
66
elsif ( $op eq 'cancel_confirmed' ) {
68
    my $alerts = getalert( $loggedinuser, $alerttype, $externalid );
67
    my $alerts = getalert( $loggedinuser, $externalid );
69
    warn "CANCEL confirmed : $loggedinuser, $alerttype, $externalid".Data::Dumper::Dumper( $alerts );
68
    warn "CANCEL confirmed : $loggedinuser, $externalid".Data::Dumper::Dumper( $alerts );
70
    foreach (@$alerts)
69
    foreach (@$alerts)
71
    {    # we are supposed to have only 1 result, but just in case...
70
    {    # we are supposed to have only 1 result, but just in case...
72
        delalert( $_->{alertid} );
71
        delalert( $_->{alertid} );
Lines 84-100 elsif ( $op eq 'cancel_confirmed' ) { Link Here
84
83
85
}
84
}
86
else {
85
else {
87
    if ( $alerttype eq 'issue' ) { # alert for subscription issues
86
    my $subscription = &GetSubscription($externalid);
88
        my $subscription = &GetSubscription($externalid);
87
    $template->param(
89
        $template->param(
88
        referer        => $referer,
90
            alerttype      => $alerttype,
89
        "typeissue$op" => 1,
91
            referer        => $referer,
90
        bibliotitle    => $subscription->{bibliotitle},
92
            "typeissue$op" => 1,
91
        notes          => $subscription->{notes},
93
            bibliotitle    => $subscription->{bibliotitle},
92
        externalid     => $externalid,
94
            notes          => $subscription->{notes},
93
        biblionumber   => $biblionumber,
95
            externalid     => $externalid,
94
    );
96
            biblionumber   => $biblionumber,
97
        );
98
    }
99
}
95
}
100
output_html_with_http_headers $query, $cookie, $template->output;
96
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/opac/opac-detail.pl (-1 / +1 lines)
Lines 584-590 foreach my $subscription (@subscriptions) { Link Here
584
    $cell{latestserials} =
584
    $cell{latestserials} =
585
      GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
585
      GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
586
    if ( $borrowernumber ) {
586
    if ( $borrowernumber ) {
587
        my $sub = getalert($borrowernumber,'issue',$subscription->{subscriptionid});
587
        my $sub = getalert($borrowernumber, $subscription->{subscriptionid});
588
        if (@$sub[0]) {
588
        if (@$sub[0]) {
589
            $cell{hasalert} = 1;
589
            $cell{hasalert} = 1;
590
        }
590
        }
(-)a/opac/opac-serial-issues.pl (-2 / +2 lines)
Lines 62-68 if ( $selectview eq "full" ) { Link Here
62
    # now, check is there is an alert subscription for one of the subscriptions
62
    # now, check is there is an alert subscription for one of the subscriptions
63
    if ($loggedinuser) {
63
    if ($loggedinuser) {
64
        foreach (@$subscriptions) {
64
        foreach (@$subscriptions) {
65
            my $sub = getalert($loggedinuser,'issue',$_->{subscriptionid});
65
            my $sub = getalert($loggedinuser, $_->{subscriptionid});
66
            if ($sub) {
66
            if ($sub) {
67
                $_->{hasalert} = 1;
67
                $_->{hasalert} = 1;
68
            }
68
            }
Lines 102-108 else { Link Here
102
    # now, check is there is an alert subscription for one of the subscriptions
102
    # now, check is there is an alert subscription for one of the subscriptions
103
    if ($loggedinuser){
103
    if ($loggedinuser){
104
        foreach (@$subscriptions) {
104
        foreach (@$subscriptions) {
105
            my $subscription = getalert($loggedinuser,'issue',$_->{subscriptionid});
105
            my $subscription = getalert($loggedinuser, $_->{subscriptionid});
106
            if (@$subscription[0]) {
106
            if (@$subscription[0]) {
107
                $_->{hasalert} = 1;
107
                $_->{hasalert} = 1;
108
            }
108
            }
(-)a/serials/viewalerts.pl (-1 / +1 lines)
Lines 44-50 my ($template, $loggedinuser, $cookie) Link Here
44
44
45
my $subscriptionid=$input->param('subscriptionid');
45
my $subscriptionid=$input->param('subscriptionid');
46
46
47
my $borrowers = getalert('','issue',$subscriptionid);
47
my $borrowers = getalert('', $subscriptionid);
48
my $subscription = GetSubscription($subscriptionid);
48
my $subscription = GetSubscription($subscriptionid);
49
49
50
for my $borrowernumber (@$borrowers) {
50
for my $borrowernumber (@$borrowers) {
(-)a/t/db_dependent/Letters.t (-11 / +6 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 77;
21
use Test::More tests => 75;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 236-244 my $letter14206_c = C4::Letters::getletter('my module', $overdue_rules->{"letter Link Here
236
is( $letter14206_c->{message_transport_type}, 'print', 'Bug 14206 - correct mtt detected for call from overdue_notices.pl' );
236
is( $letter14206_c->{message_transport_type}, 'print', 'Bug 14206 - correct mtt detected for call from overdue_notices.pl' );
237
237
238
# addalert
238
# addalert
239
my $type = 'my type';
240
my $externalid = 'my external id';
239
my $externalid = 'my external id';
241
my $alert_id = C4::Letters::addalert($borrowernumber, $type, $externalid);
240
my $alert_id = C4::Letters::addalert($borrowernumber, $externalid);
242
isnt( $alert_id, undef, 'addalert does not return undef' );
241
isnt( $alert_id, undef, 'addalert does not return undef' );
243
242
244
243
Lines 248-263 is( @$alerts, 1, 'getalert should not fail without parameter' ); Link Here
248
$alerts = C4::Letters::getalert($borrowernumber);
247
$alerts = C4::Letters::getalert($borrowernumber);
249
is( @$alerts, 1, 'addalert adds an alert' );
248
is( @$alerts, 1, 'addalert adds an alert' );
250
is( $alerts->[0]->{alertid}, $alert_id, 'addalert returns the alert id correctly' );
249
is( $alerts->[0]->{alertid}, $alert_id, 'addalert returns the alert id correctly' );
251
is( $alerts->[0]->{type}, $type, 'addalert stores the type correctly' );
252
is( $alerts->[0]->{externalid}, $externalid, 'addalert stores the externalid correctly' );
250
is( $alerts->[0]->{externalid}, $externalid, 'addalert stores the externalid correctly' );
253
251
254
$alerts = C4::Letters::getalert($borrowernumber, $type);
252
$alerts = C4::Letters::getalert($borrowernumber);
255
is( @$alerts, 1, 'getalert returns the correct number of alerts' );
253
is( @$alerts, 1, 'getalert returns the correct number of alerts' );
256
$alerts = C4::Letters::getalert($borrowernumber, $type, $externalid);
254
$alerts = C4::Letters::getalert($borrowernumber, $externalid);
257
is( @$alerts, 1, 'getalert returns the correct number of alerts' );
255
is( @$alerts, 1, 'getalert returns the correct number of alerts' );
258
$alerts = C4::Letters::getalert($borrowernumber, 'another type');
256
$alerts = C4::Letters::getalert($borrowernumber, 'another external id');
259
is( @$alerts, 0, 'getalert returns the correct number of alerts' );
260
$alerts = C4::Letters::getalert($borrowernumber, $type, 'another external id');
261
is( @$alerts, 0, 'getalert returns the correct number of alerts' );
257
is( @$alerts, 0, 'getalert returns the correct number of alerts' );
262
258
263
259
Lines 512-518 my $borrowernumber = AddMember( Link Here
512
    dateofbirth  => $date,
508
    dateofbirth  => $date,
513
    email        => 'john.smith@test.de',
509
    email        => 'john.smith@test.de',
514
);
510
);
515
my $alert_id = C4::Letters::addalert($borrowernumber, 'issue', $subscriptionid);
511
my $alert_id = C4::Letters::addalert($borrowernumber, $subscriptionid);
516
512
517
513
518
my $err2;
514
my $err2;
519
- 

Return to bug 19855