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

(-)a/Koha/Patron.pm (-3 / +3 lines)
Lines 2499-2510 Return a Koha::Subscriptions object containing subscriptions for which the patro Link Here
2499
=cut
2499
=cut
2500
2500
2501
sub alert_subscriptions {
2501
sub alert_subscriptions {
2502
    my ( $self ) = @_;
2502
    my ($self) = @_;
2503
2503
2504
    my @alerts = $self->_result->alerts;
2504
    my @alerts           = $self->_result->alerts;
2505
    my @subscription_ids = map { $_->externalid } @alerts;
2505
    my @subscription_ids = map { $_->externalid } @alerts;
2506
2506
2507
    return Koha::Subscriptions->search({ subscriptionid => \@subscription_ids });
2507
    return Koha::Subscriptions->search( { subscriptionid => \@subscription_ids } );
2508
}
2508
}
2509
2509
2510
=head2 Internal methods
2510
=head2 Internal methods
(-)a/members/alert-subscriptions.pl (-13 / +17 lines)
Lines 28-56 use Koha::Patrons; Link Here
28
my $input = CGI->new;
28
my $input = CGI->new;
29
29
30
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
30
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
31
    {   template_name   => "members/alert-subscriptions.tt",
31
    {
32
        query           => $input,
32
        template_name => "members/alert-subscriptions.tt",
33
        type            => "intranet",
33
        query         => $input,
34
        flagsrequired   => { serials => '*' },
34
        type          => "intranet",
35
        flagsrequired => { serials => '*' },
35
    }
36
    }
36
);
37
);
37
38
38
my $borrowernumber = $input->param('borrowernumber');
39
my $borrowernumber = $input->param('borrowernumber');
39
40
40
my $logged_in_user = Koha::Patrons->find( $loggedinuser );
41
my $logged_in_user = Koha::Patrons->find($loggedinuser);
41
my $patron         = Koha::Patrons->find( $borrowernumber );
42
my $patron         = Koha::Patrons->find($borrowernumber);
42
output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
43
output_and_exit_if_error(
44
    $input, $cookie, $template,
45
    { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron }
46
);
43
47
44
my $subscription_id = $input->param('subscription_id');
48
my $subscription_id = $input->param('subscription_id');
45
if ( $subscription_id ) {
49
if ($subscription_id) {
46
    my $subscription = Koha::Subscriptions->find( $subscription_id );
50
    my $subscription = Koha::Subscriptions->find($subscription_id);
47
    $subscription->remove_subscriber( $patron );
51
    $subscription->remove_subscriber($patron);
48
    print $input->redirect("/cgi-bin/koha/members/alert-subscriptions.pl?borrowernumber=".$borrowernumber);
52
    print $input->redirect( "/cgi-bin/koha/members/alert-subscriptions.pl?borrowernumber=" . $borrowernumber );
49
}
53
}
50
54
51
$template->param(
55
$template->param(
52
    patron => $patron,
56
    patron     => $patron,
53
    alertsview  => 1,
57
    alertsview => 1,
54
);
58
);
55
59
56
output_html_with_http_headers $input, $cookie, $template->output;
60
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/opac/opac-alert-subscribe.pl (-27 / +16 lines)
Lines 17-23 Link Here
17
# You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
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
21
use Modern::Perl;
20
use Modern::Perl;
22
use CGI qw ( -utf8 );
21
use CGI qw ( -utf8 );
23
use C4::Auth qw( get_template_and_user );
22
use C4::Auth qw( get_template_and_user );
Lines 25-92 use C4::Output qw( output_html_with_http_headers ); Link Here
25
use C4::Context;
24
use C4::Context;
26
use C4::Serials qw( GetSubscription );
25
use C4::Serials qw( GetSubscription );
27
26
28
29
my $query = CGI->new;
27
my $query = CGI->new;
30
my $op    = $query->param('op') || '';
28
my $op    = $query->param('op') || '';
31
my $dbh   = C4::Context->dbh;
29
my $dbh   = C4::Context->dbh;
32
30
33
my ( $template, $loggedinuser, $cookie );
31
my ( $template, $loggedinuser, $cookie );
34
my $subscriptionid = $query->param('subscriptionid');
32
my $subscriptionid = $query->param('subscriptionid');
35
my $referer      = $query->param('referer') || 'detail';
33
my $referer        = $query->param('referer') || 'detail';
36
my $biblionumber = $query->param('biblionumber');
34
my $biblionumber   = $query->param('biblionumber');
37
35
38
( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
( $template, $loggedinuser, $cookie ) = get_template_and_user(
39
    {
37
    {
40
        template_name   => "opac-alert-subscribe.tt",
38
        template_name   => "opac-alert-subscribe.tt",
41
        query           => $query,
39
        query           => $query,
42
        type            => "opac",
40
        type            => "opac",
43
        authnotrequired => 0, # user must logged in to request
41
        authnotrequired => 0,                           # user must logged in to request
44
                              # subscription notifications
42
                                                        # subscription notifications
45
    }
43
    }
46
);
44
);
47
45
48
my $subscription = Koha::Subscriptions->find( $subscriptionid );
46
my $subscription     = Koha::Subscriptions->find($subscriptionid);
49
my $logged_in_patron = Koha::Patrons->find( $loggedinuser );
47
my $logged_in_patron = Koha::Patrons->find($loggedinuser);
50
48
51
if ( $op eq 'alert_confirmed' ) {
49
if ( $op eq 'alert_confirmed' ) {
52
    $subscription->add_subscriber( $logged_in_patron );
50
    $subscription->add_subscriber($logged_in_patron);
53
    if ( $referer eq 'serial' ) {
51
    if ( $referer eq 'serial' ) {
54
        print $query->redirect(
52
        print $query->redirect("opac-serial-issues.pl?biblionumber=$biblionumber");
55
            "opac-serial-issues.pl?biblionumber=$biblionumber");
56
        exit;
53
        exit;
57
    } else {
54
    } else {
58
        print $query->redirect(
55
        print $query->redirect("opac-detail.pl?biblionumber=$biblionumber");
59
            "opac-detail.pl?biblionumber=$biblionumber");
60
        exit;
56
        exit;
61
    }
57
    }
62
}
58
} elsif ( $op eq 'cancel_confirmed' ) {
63
elsif ( $op eq 'cancel_confirmed' ) {
59
    $subscription->remove_subscriber($logged_in_patron);
64
    $subscription->remove_subscriber( $logged_in_patron );
65
    warn "CANCEL confirmed : $loggedinuser, $subscriptionid";
60
    warn "CANCEL confirmed : $loggedinuser, $subscriptionid";
66
    if ( $referer eq 'serial' ) {
61
    if ( $referer eq 'serial' ) {
67
        print $query->redirect(
62
        print $query->redirect("opac-serial-issues.pl?biblionumber=$biblionumber");
68
            "opac-serial-issues.pl?biblionumber=$biblionumber");
69
        exit;
63
        exit;
70
    } elsif ( $referer eq 'patron' ) {
64
    } elsif ( $referer eq 'patron' ) {
71
        print $query->redirect(
65
        print $query->redirect("/cgi-bin/koha/opac-alert-subscriptions.pl");
72
            "/cgi-bin/koha/opac-alert-subscriptions.pl"
73
        );
74
    } else {
66
    } else {
75
        print $query->redirect(
67
        print $query->redirect("opac-detail.pl?biblionumber=$biblionumber");
76
            "opac-detail.pl?biblionumber=$biblionumber");
77
        exit;
68
        exit;
78
    }
69
    }
79
70
80
71
} else {
81
}
82
else {
83
    my $subscription = &GetSubscription($subscriptionid);
72
    my $subscription = &GetSubscription($subscriptionid);
84
    $template->param(
73
    $template->param(
85
        referer        => $referer,
74
        referer        => $referer,
86
        "typeissue$op" => 1,
75
        "typeissue$op" => 1,
87
        bibliotitle    => $subscription->{bibliotitle},
76
        bibliotitle    => $subscription->{bibliotitle},
88
        notes          => $subscription->{notes},
77
        notes          => $subscription->{notes},
89
        subscriptionid     => $subscriptionid,
78
        subscriptionid => $subscriptionid,
90
        biblionumber   => $biblionumber,
79
        biblionumber   => $biblionumber,
91
    );
80
    );
92
}
81
}
(-)a/opac/opac-alert-subscriptions.pl (-9 / +11 lines)
Lines 29-53 my $query = CGI->new(); Link Here
29
29
30
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
30
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
31
    {
31
    {
32
        template_name   => 'opac-alert-subscriptions.tt',
32
        template_name => 'opac-alert-subscriptions.tt',
33
        query           => $query,
33
        query         => $query,
34
        type            => 'opac',
34
        type          => 'opac',
35
    }
35
    }
36
);
36
);
37
37
38
my $patron = Koha::Patrons->find( $borrowernumber );
38
my $patron = Koha::Patrons->find($borrowernumber);
39
39
40
$template->param(
40
$template->param(
41
    alertsview => 1,
41
    alertsview => 1,
42
    patron => $patron,
42
    patron     => $patron,
43
    referer => 'patron',
43
    referer    => 'patron',
44
);
44
);
45
45
46
my $new_session_id = $query->cookie('CGISESSID');
46
my $new_session_id = $query->cookie('CGISESSID');
47
$template->param(
47
$template->param(
48
    csrf_token => Koha::Token->new->generate_csrf({
48
    csrf_token => Koha::Token->new->generate_csrf(
49
        session_id => $new_session_id,
49
        {
50
    }),
50
            session_id => $new_session_id,
51
        }
52
    ),
51
);
53
);
52
54
53
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
55
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
(-)a/t/db_dependent/Koha/Patron.t (-6 / +5 lines)
Lines 1503-1515 subtest 'alert_subscriptions tests' => sub { Link Here
1503
1503
1504
    plan tests => 3;
1504
    plan tests => 3;
1505
1505
1506
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
1506
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
1507
1507
1508
    my $subscription1 = $builder->build_object({ class => 'Koha::Subscriptions' });
1508
    my $subscription1 = $builder->build_object( { class => 'Koha::Subscriptions' } );
1509
    $subscription1->add_subscriber( $patron );
1509
    $subscription1->add_subscriber($patron);
1510
1510
1511
    my $subscription2 = $builder->build_object({ class => 'Koha::Subscriptions' });
1511
    my $subscription2 = $builder->build_object( { class => 'Koha::Subscriptions' } );
1512
    $subscription2->add_subscriber( $patron );
1512
    $subscription2->add_subscriber($patron);
1513
1513
1514
    my @subscriptions = $patron->alert_subscriptions->as_list;
1514
    my @subscriptions = $patron->alert_subscriptions->as_list;
1515
1515
1516
- 

Return to bug 28130