3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
18 # Written by Antoine Farnault antoine@koha-fr.org on Nov. 2006.
21 =head1 cleanborrowers.pl
23 This script allows to do 2 things.
27 =item * Anonymise the borrowers' issues if issue is older than a given date. see C<datefilter1>.
29 =item * Delete the borrowers who has not borrowered since a given date. see C<datefilter2>.
36 #use warnings; FIXME - Bug 2505
40 use C4
::Dates qw
/format_date format_date_in_iso/;
41 use C4
::Members
; # GetBorrowersWhoHavexxxBorrowed.
42 use C4
::Circulation
; # AnonymiseIssueHistory.
43 use Date
::Calc qw
/Today Add_Delta_YM/;
47 # Fetch the paramater list as a hash in scalar context:
48 # * returns paramater list as tied hash ref
49 # * we can edit the values by changing the key
50 # * multivalued CGI paramaters are returned as a packaged string separated by "\0" (null)
51 my $params = $cgi->Vars;
53 my $filterdate1; # the date which filter on issue history.
54 my $filterdate2; # the date which filter on borrowers last issue.
56 # getting the template
57 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
59 template_name
=> "tools/cleanborrowers.tmpl",
63 flagsrequired
=> { tools
=> 'delete_anonymize_patrons', catalogue
=> 1 },
67 if ( $params->{'step2'} ) {
68 $filterdate1 = format_date_in_iso
($params->{'filterdate1'});
69 $filterdate2 = format_date_in_iso
($params->{'filterdate2'});
70 my %checkboxes = map { $_ => 1 } split /\0/, $params->{'checkbox'};
74 if ($checkboxes{borrower
}) {
75 $membersToDelete = GetBorrowersWhoHaveNotBorrowedSince
($filterdate1, 1);
76 $totalDel = scalar @
$membersToDelete;
80 my $membersToAnonymize;
81 if ($checkboxes{issue
}) {
83 GetBorrowersWithIssuesHistoryOlderThan
($filterdate2);
84 $totalAno = scalar @
$membersToAnonymize;
89 totalToDelete
=> $totalDel,
90 totalToAnonymize
=> $totalAno,
91 memberstodelete_list
=> $membersToDelete,
92 memberstoanonymize_list
=> $membersToAnonymize,
93 filterdate1
=> format_date
($filterdate1),
94 filterdate2
=> format_date
($filterdate2),
96 ### TODO : Use GetBorrowersNamesAndLatestIssue function in order to get the borrowers to delete or anonymize.
97 ### Now, we are only using total, which is not enough imlo
99 output_html_with_http_headers
$cgi, $cookie, $template->output;
103 if ( $params->{'step3'} ) {
104 $filterdate1 = format_date_in_iso
($params->{'filterdate1'});
105 $filterdate2 = format_date_in_iso
($params->{'filterdate2'});
106 my $do_delete = $params->{'do_delete'};
107 my $do_anonym = $params->{'do_anonym'};
109 my ( $totalDel, $totalAno, $radio ) = ( 0, 0, 0 );
113 my $membersToDelete = GetBorrowersWhoHaveNotBorrowedSince
($filterdate1, 1);
114 $totalDel = scalar(@
$membersToDelete);
115 $radio = $params->{'radio'};
116 if ( $radio eq 'trash' ) {
118 for ( $i = 0 ; $i < $totalDel ; $i++ ) {
119 MoveMemberToDeleted
( $membersToDelete->[$i]->{'borrowernumber'} );
120 DelMember
( $membersToDelete->[$i]->{'borrowernumber'} );
123 else { # delete completly.
125 for ( $i = 0 ; $i < $totalDel ; $i++ ) {
126 DelMember
($membersToDelete->[$i]->{'borrowernumber'});
131 TotalDel
=> $totalDel
135 # Anonymising all members
137 $totalAno = AnonymiseIssueHistory
($filterdate2);
139 filterdate1
=> $filterdate2,
146 trash
=> ( $radio eq "trash" ) ?
(1) : (0),
149 #writing the template
150 output_html_with_http_headers
$cgi, $cookie, $template->output;
154 #default value set to the template are the 'CNIL' value.
155 my ( $year, $month, $day ) = &Today
();
156 $filterdate1 = format_date
(sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YM
($year, $month, $day, -1, 0)));
157 $filterdate2 = format_date
(sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YM
($year, $month, $day, 0, -3)));
161 filterdate1
=> $filterdate1,
162 filterdate2
=> $filterdate2,
163 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(),
166 #writing the template
167 output_html_with_http_headers
$cgi, $cookie, $template->output;