Bug 24759: DBRev 19.12.00.051
[koha.git] / opac / opac-privacy.pl
blob7d7f445c394cdb50682c4f289cf9dc208adac442
1 #!/usr/bin/perl
2 # This script lets the users change their privacy rules
4 # copyright 2009, BibLibre, paul.poulain@biblibre.com
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 use Modern::Perl;
20 use CGI qw ( -utf8 );
22 use C4::Auth; # checkauth, getborrowernumber.
23 use C4::Context;
24 use C4::Output;
25 use Koha::Patrons;
27 my $query = new CGI;
29 # if OPACPrivacy is disabled, leave immediately
30 if ( ! C4::Context->preference('OPACPrivacy') || ! C4::Context->preference('opacreadinghistory') ) {
31 print $query->redirect("/cgi-bin/koha/errors/404.pl");
32 exit;
35 my $dbh = C4::Context->dbh;
37 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
39 template_name => "opac-privacy.tt",
40 query => $query,
41 type => "opac",
42 authnotrequired => 0,
43 debug => 1,
47 my $op = $query->param("op");
48 my $privacy = $query->param("privacy");
49 my $privacy_guarantor_checkouts = $query->param("privacy_guarantor_checkouts");
50 my $privacy_guarantor_fines = $query->param("privacy_guarantor_fines");
52 if ( $op eq "update_privacy" ) {
53 my $patron = Koha::Patrons->find( $borrowernumber );
54 if ( $patron ) {
55 $patron->set({
56 privacy => $privacy,
57 privacy_guarantor_checkouts => defined $privacy_guarantor_checkouts?$privacy_guarantor_checkouts:$patron->privacy_guarantor_checkouts,
58 privacy_guarantor_fines => defined $privacy_guarantor_fines?$privacy_guarantor_fines:$patron->privacy_guarantor_fines,
59 })->store;
60 $template->param( 'privacy_updated' => 1 );
63 elsif ( $op eq "delete_record" ) {
65 # delete all reading records for items returned
66 my $rows = eval {
67 Koha::Patrons->search({ 'me.borrowernumber' => $borrowernumber })->anonymise_issue_history;
69 $template->param(
71 $@ ? ( history_not_deleted => 1 )
72 : $rows ? ( deleted => int($rows) )
73 : ( nothing_to_delete => 1 )
78 # get borrower privacy ....
79 my $borrower = Koha::Patrons->find( $borrowernumber );;
81 $template->param(
82 'Ask_data' => 1,
83 'privacy' . $borrower->privacy() => 1,
84 'privacyview' => 1,
85 'borrower' => $borrower,
86 'surname' => $borrower->surname,
87 'firstname' => $borrower->firstname,
88 'has_guarantor_flag' => $borrower->guarantor_relationships->guarantors->_resultset->count
91 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };