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

(-)a/C4/Letters.pm (-19 / +13 lines)
Lines 266-289 sub DelLetter { Link Here
266
    , undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) );
266
    , undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) );
267
}
267
}
268
268
269
=head2 addalert ($borrowernumber, $type, $externalid)
269
=head2 addalert ($borrowernumber, $subscriptionid)
270
270
271
    parameters : 
271
    parameters : 
272
    - $borrowernumber : the number of the borrower subscribing to the alert
272
    - $borrowernumber : the number of the borrower subscribing to the alert
273
    - $type : the type of alert.
273
    - $subscriptionid
274
    - $externalid : the primary key of the object to put alert on. For issues, the alert is made on subscriptionid.
274
275
    
276
    create an alert and return the alertid (primary key)
275
    create an alert and return the alertid (primary key)
277
276
278
=cut
277
=cut
279
278
280
sub addalert {
279
sub addalert {
281
    my ( $borrowernumber, $type, $externalid ) = @_;
280
    my ( $borrowernumber, $subscriptionid) = @_;
282
    my $dbh = C4::Context->dbh;
281
    my $dbh = C4::Context->dbh;
283
    my $sth =
282
    my $sth =
284
      $dbh->prepare(
283
      $dbh->prepare(
285
        "insert into alert (borrowernumber, type, externalid) values (?,?,?)");
284
        "insert into alert (borrowernumber, externalid) values (?,?)");
286
    $sth->execute( $borrowernumber, $type, $externalid );
285
    $sth->execute( $borrowernumber, $subscriptionid );
287
286
288
    # get the alert number newly created and return it
287
    # get the alert number newly created and return it
289
    my $alertid = $dbh->{'mysql_insertid'};
288
    my $alertid = $dbh->{'mysql_insertid'};
Lines 305-322 sub delalert { Link Here
305
    $sth->execute($alertid);
304
    $sth->execute($alertid);
306
}
305
}
307
306
308
=head2 getalert ([$borrowernumber], [$type], [$externalid])
307
=head2 getalert ([$borrowernumber], [$subscriptionid])
309
308
310
    parameters :
309
    parameters :
311
    - $borrowernumber : the number of the borrower subscribing to the alert
310
    - $borrowernumber : the number of the borrower subscribing to the alert
312
    - $type : the type of alert.
311
    - $subscriptionid
313
    - $externalid : the primary key of the object to put alert on. For issues, the alert is made on subscriptionid.
312
    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.
314
    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.
315
313
316
=cut
314
=cut
317
315
318
sub getalert {
316
sub getalert {
319
    my ( $borrowernumber, $type, $externalid ) = @_;
317
    my ( $borrowernumber, $subscriptionid ) = @_;
320
    my $dbh   = C4::Context->dbh;
318
    my $dbh   = C4::Context->dbh;
321
    my $query = "SELECT a.*, b.branchcode FROM alert a JOIN borrowers b USING(borrowernumber) WHERE 1";
319
    my $query = "SELECT a.*, b.branchcode FROM alert a JOIN borrowers b USING(borrowernumber) WHERE 1";
322
    my @bind;
320
    my @bind;
Lines 324-336 sub getalert { Link Here
324
        $query .= " AND borrowernumber=?";
322
        $query .= " AND borrowernumber=?";
325
        push @bind, $borrowernumber;
323
        push @bind, $borrowernumber;
326
    }
324
    }
327
    if ($type) {
325
    if ($subscriptionid) {
328
        $query .= " AND type=?";
329
        push @bind, $type;
330
    }
331
    if ($externalid) {
332
        $query .= " AND externalid=?";
326
        $query .= " AND externalid=?";
333
        push @bind, $externalid;
327
        push @bind, $subscriptionid;
334
    }
328
    }
335
    my $sth = $dbh->prepare($query);
329
    my $sth = $dbh->prepare($query);
336
    $sth->execute(@bind);
330
    $sth->execute(@bind);
Lines 386-392 sub SendAlerts { Link Here
386
380
387
        my %letter;
381
        my %letter;
388
        # find the list of borrowers to alert
382
        # find the list of borrowers to alert
389
        my $alerts = getalert( '', 'issue', $subscriptionid );
383
        my $alerts = getalert( '', $subscriptionid );
390
        foreach (@$alerts) {
384
        foreach (@$alerts) {
391
            my $patron = Koha::Patrons->find( $_->{borrowernumber} );
385
            my $patron = Koha::Patrons->find( $_->{borrowernumber} );
392
            next unless $patron; # Just in case
386
            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 834-842 Link Here
834
                                [% IF ( subscription.letter ) %]<span class="email_notifications">
834
                                [% IF ( subscription.letter ) %]<span class="email_notifications">
835
                                    [% IF ( loggedinusername ) %]
835
                                    [% IF ( loggedinusername ) %]
836
                                        [% IF ( subscription.hasalert ) %]
836
                                        [% IF ( subscription.hasalert ) %]
837
                                            <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>
837
                                            <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>
838
                                        [% ELSE %]
838
                                        [% ELSE %]
839
                                            <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>
839
                                            <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>
840
                                        [% END %]
840
                                        [% END %]
841
                                    [% ELSE %]
841
                                    [% ELSE %]
842
                                        <span>You must log in if you want to subscribe to email notification on new issues</span>
842
                                        <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 589-595 foreach my $subscription (@subscriptions) { Link Here
589
    $cell{latestserials} =
589
    $cell{latestserials} =
590
      GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
590
      GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
591
    if ( $borrowernumber ) {
591
    if ( $borrowernumber ) {
592
        my $sub = getalert($borrowernumber,'issue',$subscription->{subscriptionid});
592
        my $sub = getalert($borrowernumber, $subscription->{subscriptionid});
593
        if (@$sub[0]) {
593
        if (@$sub[0]) {
594
            $cell{hasalert} = 1;
594
            $cell{hasalert} = 1;
595
        }
595
        }
(-)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 43-49 my ($template, $loggedinuser, $cookie) Link Here
43
43
44
my $subscriptionid=$input->param('subscriptionid');
44
my $subscriptionid=$input->param('subscriptionid');
45
45
46
my $borrowers = getalert('','issue',$subscriptionid);
46
my $borrowers = getalert('', $subscriptionid);
47
my $subscription = GetSubscription($subscriptionid);
47
my $subscription = GetSubscription($subscriptionid);
48
48
49
for my $borrowernumber (@$borrowers) {
49
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 237-245 my $letter14206_c = C4::Letters::getletter('my module', $overdue_rules->{"letter Link Here
237
is( $letter14206_c->{message_transport_type}, 'print', 'Bug 14206 - correct mtt detected for call from overdue_notices.pl' );
237
is( $letter14206_c->{message_transport_type}, 'print', 'Bug 14206 - correct mtt detected for call from overdue_notices.pl' );
238
238
239
# addalert
239
# addalert
240
my $type = 'my type';
241
my $externalid = 'my external id';
240
my $externalid = 'my external id';
242
my $alert_id = C4::Letters::addalert($borrowernumber, $type, $externalid);
241
my $alert_id = C4::Letters::addalert($borrowernumber, $externalid);
243
isnt( $alert_id, undef, 'addalert does not return undef' );
242
isnt( $alert_id, undef, 'addalert does not return undef' );
244
243
245
244
Lines 249-264 is( @$alerts, 1, 'getalert should not fail without parameter' ); Link Here
249
$alerts = C4::Letters::getalert($borrowernumber);
248
$alerts = C4::Letters::getalert($borrowernumber);
250
is( @$alerts, 1, 'addalert adds an alert' );
249
is( @$alerts, 1, 'addalert adds an alert' );
251
is( $alerts->[0]->{alertid}, $alert_id, 'addalert returns the alert id correctly' );
250
is( $alerts->[0]->{alertid}, $alert_id, 'addalert returns the alert id correctly' );
252
is( $alerts->[0]->{type}, $type, 'addalert stores the type correctly' );
253
is( $alerts->[0]->{externalid}, $externalid, 'addalert stores the externalid correctly' );
251
is( $alerts->[0]->{externalid}, $externalid, 'addalert stores the externalid correctly' );
254
252
255
$alerts = C4::Letters::getalert($borrowernumber, $type);
253
$alerts = C4::Letters::getalert($borrowernumber);
256
is( @$alerts, 1, 'getalert returns the correct number of alerts' );
254
is( @$alerts, 1, 'getalert returns the correct number of alerts' );
257
$alerts = C4::Letters::getalert($borrowernumber, $type, $externalid);
255
$alerts = C4::Letters::getalert($borrowernumber, $externalid);
258
is( @$alerts, 1, 'getalert returns the correct number of alerts' );
256
is( @$alerts, 1, 'getalert returns the correct number of alerts' );
259
$alerts = C4::Letters::getalert($borrowernumber, 'another type');
257
$alerts = C4::Letters::getalert($borrowernumber, 'another external id');
260
is( @$alerts, 0, 'getalert returns the correct number of alerts' );
261
$alerts = C4::Letters::getalert($borrowernumber, $type, 'another external id');
262
is( @$alerts, 0, 'getalert returns the correct number of alerts' );
258
is( @$alerts, 0, 'getalert returns the correct number of alerts' );
263
259
264
260
Lines 513-519 my $borrowernumber = AddMember( Link Here
513
    dateofbirth  => $date,
509
    dateofbirth  => $date,
514
    email        => 'john.smith@test.de',
510
    email        => 'john.smith@test.de',
515
);
511
);
516
my $alert_id = C4::Letters::addalert($borrowernumber, 'issue', $subscriptionid);
512
my $alert_id = C4::Letters::addalert($borrowernumber, $subscriptionid);
517
513
518
514
519
my $err2;
515
my $err2;
520
- 

Return to bug 19855