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

(-)a/C4/Letters.pm (-19 / +13 lines)
Lines 265-288 sub DelLetter { Link Here
265
    , undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) );
265
    , undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) );
266
}
266
}
267
267
268
=head2 addalert ($borrowernumber, $type, $externalid)
268
=head2 addalert ($borrowernumber, $subscriptionid)
269
269
270
    parameters : 
270
    parameters : 
271
    - $borrowernumber : the number of the borrower subscribing to the alert
271
    - $borrowernumber : the number of the borrower subscribing to the alert
272
    - $type : the type of alert.
272
    - $subscriptionid
273
    - $externalid : the primary key of the object to put alert on. For issues, the alert is made on subscriptionid.
273
274
    
275
    create an alert and return the alertid (primary key)
274
    create an alert and return the alertid (primary key)
276
275
277
=cut
276
=cut
278
277
279
sub addalert {
278
sub addalert {
280
    my ( $borrowernumber, $type, $externalid ) = @_;
279
    my ( $borrowernumber, $subscriptionid) = @_;
281
    my $dbh = C4::Context->dbh;
280
    my $dbh = C4::Context->dbh;
282
    my $sth =
281
    my $sth =
283
      $dbh->prepare(
282
      $dbh->prepare(
284
        "insert into alert (borrowernumber, type, externalid) values (?,?,?)");
283
        "insert into alert (borrowernumber, externalid) values (?,?)");
285
    $sth->execute( $borrowernumber, $type, $externalid );
284
    $sth->execute( $borrowernumber, $subscriptionid );
286
285
287
    # get the alert number newly created and return it
286
    # get the alert number newly created and return it
288
    my $alertid = $dbh->{'mysql_insertid'};
287
    my $alertid = $dbh->{'mysql_insertid'};
Lines 304-321 sub delalert { Link Here
304
    $sth->execute($alertid);
303
    $sth->execute($alertid);
305
}
304
}
306
305
307
=head2 getalert ([$borrowernumber], [$type], [$externalid])
306
=head2 getalert ([$borrowernumber], [$subscriptionid])
308
307
309
    parameters :
308
    parameters :
310
    - $borrowernumber : the number of the borrower subscribing to the alert
309
    - $borrowernumber : the number of the borrower subscribing to the alert
311
    - $type : the type of alert.
310
    - $subscriptionid
312
    - $externalid : the primary key of the object to put alert on. For issues, the alert is made on subscriptionid.
311
    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.
313
    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.
314
312
315
=cut
313
=cut
316
314
317
sub getalert {
315
sub getalert {
318
    my ( $borrowernumber, $type, $externalid ) = @_;
316
    my ( $borrowernumber, $subscriptionid ) = @_;
319
    my $dbh   = C4::Context->dbh;
317
    my $dbh   = C4::Context->dbh;
320
    my $query = "SELECT a.*, b.branchcode FROM alert a JOIN borrowers b USING(borrowernumber) WHERE 1";
318
    my $query = "SELECT a.*, b.branchcode FROM alert a JOIN borrowers b USING(borrowernumber) WHERE 1";
321
    my @bind;
319
    my @bind;
Lines 323-335 sub getalert { Link Here
323
        $query .= " AND borrowernumber=?";
321
        $query .= " AND borrowernumber=?";
324
        push @bind, $borrowernumber;
322
        push @bind, $borrowernumber;
325
    }
323
    }
326
    if ($type) {
324
    if ($subscriptionid) {
327
        $query .= " AND type=?";
328
        push @bind, $type;
329
    }
330
    if ($externalid) {
331
        $query .= " AND externalid=?";
325
        $query .= " AND externalid=?";
332
        push @bind, $externalid;
326
        push @bind, $subscriptionid;
333
    }
327
    }
334
    my $sth = $dbh->prepare($query);
328
    my $sth = $dbh->prepare($query);
335
    $sth->execute(@bind);
329
    $sth->execute(@bind);
Lines 385-391 sub SendAlerts { Link Here
385
379
386
        my %letter;
380
        my %letter;
387
        # find the list of borrowers to alert
381
        # find the list of borrowers to alert
388
        my $alerts = getalert( '', 'issue', $subscriptionid );
382
        my $alerts = getalert( '', $subscriptionid );
389
        foreach (@$alerts) {
383
        foreach (@$alerts) {
390
            my $patron = Koha::Patrons->find( $_->{borrowernumber} );
384
            my $patron = Koha::Patrons->find( $_->{borrowernumber} );
391
            next unless $patron; # Just in case
385
            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 833-841 Link Here
833
                                [% IF ( subscription.letter ) %]<span class="email_notifications">
833
                                [% IF ( subscription.letter ) %]<span class="email_notifications">
834
                                    [% IF ( loggedinusername ) %]
834
                                    [% IF ( loggedinusername ) %]
835
                                        [% IF ( subscription.hasalert ) %]
835
                                        [% IF ( subscription.hasalert ) %]
836
                                            <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>
836
                                            <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>
837
                                        [% ELSE %]
837
                                        [% ELSE %]
838
                                            <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>
838
                                            <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>
839
                                        [% END %]
839
                                        [% END %]
840
                                    [% ELSE %]
840
                                    [% ELSE %]
841
                                        <span>You must log in if you want to subscribe to email notification on new issues</span>
841
                                        <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