Bug 25517: Look in all possible places for MO files
[koha.git] / opac / opac-patron-consent.pl
blob789def3b0a0e7a95ece92415187860b3f22c4ecc
1 #!/usr/bin/perl
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>.
20 use Modern::Perl;
21 use CGI qw/-utf8/;
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::Patron::Consents;
27 use Koha::Patrons;
29 use constant GDPR_PROCESSING => 'GDPR_PROCESSING';
31 my $query = new CGI;
32 my $op = $query->param('op') // q{};
33 my $gdpr_check = $query->param('gdpr_processing') // q{};
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user({
36 template_name => "opac-patron-consent.tt",
37 query => $query,
38 type => "opac",
39 authnotrequired => 0,
40 });
42 my $patron = Koha::Patrons->find($borrowernumber);
43 my $gdpr_proc_consent;
44 if( C4::Context->preference('GDPR_Policy') ) {
45 $gdpr_proc_consent = Koha::Patron::Consents->search({
46 borrowernumber => $borrowernumber,
47 type => GDPR_PROCESSING,
48 })->next;
49 $gdpr_proc_consent //= Koha::Patron::Consent->new({
50 borrowernumber => $borrowernumber,
51 type => GDPR_PROCESSING,
52 });
55 # Handle saves here
56 if( $op eq 'gdpr_proc_save' && $gdpr_proc_consent ) {
57 if( $gdpr_check eq 'agreed' ) {
58 $gdpr_proc_consent->given_on( dt_from_string() );
59 $gdpr_proc_consent->refused_on( undef );
60 } elsif( $gdpr_check eq 'disagreed' ) {
61 $gdpr_proc_consent->given_on( undef );
62 $gdpr_proc_consent->refused_on( dt_from_string() );
64 $gdpr_proc_consent->store;
67 # If user refused GDPR consent and we enforce GDPR, logout (when saving)
68 if( $op =~ /save/ && C4::Context->preference('GDPR_Policy') eq 'Enforced' && $gdpr_proc_consent->refused_on )
70 print $query->redirect('/cgi-bin/koha/opac-main.pl?logout.x=1');
71 exit;
74 $template->param( patron => $patron );
75 if( $gdpr_proc_consent ) {
76 $template->param(
77 gdpr_proc_consent => $gdpr_proc_consent->given_on // q{},
78 gdpr_proc_refusal => $gdpr_proc_consent->refused_on // q{},
82 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };