3 # Copyright 2018 Rijksmuseum
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
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>.
23 use C4::Auth qw( get_template_and_user );
24 use C4::Output qw( output_html_with_http_headers );
25 use Koha::DateUtils qw( dt_from_string );
26 use Koha::Exceptions::Patron;
30 my $op = $query->param('op') // q{};
31 my $vars = $query->Vars;
33 my ( $template, $borrowernumber, $cookie ) = get_template_and_user({
34 template_name => "opac-patron-consent.tt",
39 my $patron = Koha::Patrons->find($borrowernumber)
40 or Koha::Exceptions::Patron->throw("Patron id $borrowernumber not found");
42 # Get consent types and values
44 my $consent_types = Koha::Patron::Consents->available_types;
45 foreach my $consent_type ( sort keys %$consent_types) {
46 push @consents, $patron->consent($consent_type);
51 foreach my $consent ( @consents ) {
52 my $check = $vars->{ "check_".$consent->type };
53 next if !defined($check); # no choice made
55 if $consent->type eq q/GDPR_PROCESSING/ && !$check && C4::Context->preference('PrivacyPolicyConsent') eq 'Enforced';
56 next if $consent->given_on && $check || $consent->refused_on && !$check;
57 # No update if no consent change
59 given_on => $check ? dt_from_string() : undef,
60 refused_on => $check ? undef : dt_from_string(),
64 # If user refused GDPR consent and we enforce GDPR, logout (when saving)
65 if( $needs_redirect ) {
66 print $query->redirect('/cgi-bin/koha/opac-main.pl?logout.x=1');
70 $template->param( patron => $patron, consents => \@consents, consent_types => $consent_types );
72 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };