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>.
22 use C4::Auth qw( get_template_and_user );
24 use C4::Output qw( output_html_with_http_headers );
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");
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
37 template_name => "opac-privacy.tt",
43 my $op = $query->param("op");
44 my $privacy = $query->param("privacy");
45 my $privacy_guarantor_checkouts = $query->param("privacy_guarantor_checkouts");
46 my $privacy_guarantor_fines = $query->param("privacy_guarantor_fines");
48 my $patron = Koha::Patrons->find( $borrowernumber );
50 if ( $op eq "update_privacy" ) {
54 privacy_guarantor_checkouts => defined $privacy_guarantor_checkouts?$privacy_guarantor_checkouts:$patron->privacy_guarantor_checkouts,
55 privacy_guarantor_fines => defined $privacy_guarantor_fines?$privacy_guarantor_fines:$patron->privacy_guarantor_fines,
57 $template->param( 'privacy_updated' => 1 );
60 elsif ( $op eq "delete_record" ) {
62 my $holds = $query->param('holds');
63 my $checkouts = $query->param('checkouts');
64 my $all = $query->param('all');
66 $template->param( delete_all_quested => 1 )
69 if ( $all or $checkouts ) {
71 # delete all reading records for items returned
72 my $rows = eval { $patron->old_checkouts->anonymize + 0 };
76 $@ ? ( error_deleting_checkouts_history => 1 )
77 : $rows ? ( deleted_checkouts => int($rows) )
78 : ( no_checkouts_to_delete => 1 )
80 delete_checkouts_requested => 1,
84 if ( $all or $holds ) {
86 my $rows = eval { $patron->old_holds->anonymize + 0 };
90 $@ ? ( error_deleting_holds_history => 1 )
91 : $rows ? ( deleted_holds => int($rows) )
92 : ( no_holds_to_delete => 1 )
94 delete_holds_requested => 1,
101 'privacy' . $patron->privacy() => 1,
103 'borrower' => $patron,
104 'surname' => $patron->surname,
105 'firstname' => $patron->firstname,
106 'has_guarantor_flag' => $patron->guarantor_relationships->guarantors->_resultset->count
109 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };