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>.
39 use C4
::Dates qw
/format_date format_date_in_iso/;
40 use C4
::Members
; # GetBorrowersWhoHavexxxBorrowed.
41 use C4
::Circulation
; # AnonymiseIssueHistory.
42 use Date
::Calc qw
/Today Add_Delta_YM/;
46 # Fetch the paramater list as a hash in scalar context:
47 # * returns paramater list as tied hash ref
48 # * we can edit the values by changing the key
49 # * multivalued CGI paramaters are returned as a packaged string separated by "\0" (null)
50 my $params = $cgi->Vars;
52 my $filterdate1; # the date which filter on issue history.
53 my $filterdate2; # the date which filter on borrowers last issue.
55 # getting the template
56 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
58 template_name
=> "tools/cleanborrowers.tmpl",
62 flagsrequired
=> { tools
=> 'delete_anonymize_patrons', catalogue
=> 1 },
66 if ( $params->{'step2'} ) {
67 $filterdate1 = format_date_in_iso
($params->{'filterdate1'});
68 $filterdate2 = format_date_in_iso
($params->{'filterdate2'});
69 my %checkboxes = map { $_ => 1 } split /\0/, $params->{'checkbox'};
73 if ($checkboxes{borrower
}) {
74 $membersToDelete = GetBorrowersWhoHaveNotBorrowedSince
($filterdate1, 1);
75 $totalDel = scalar @
$membersToDelete;
79 my $membersToAnonymize;
80 if ($checkboxes{issue
}) {
82 GetBorrowersWithIssuesHistoryOlderThan
($filterdate2);
83 $totalAno = scalar @
$membersToAnonymize;
88 totalToDelete
=> $totalDel,
89 totalToAnonymize
=> $totalAno,
90 memberstodelete_list
=> $membersToDelete,
91 memberstoanonymize_list
=> $membersToAnonymize,
92 filterdate1
=> format_date
($filterdate1),
93 filterdate2
=> format_date
($filterdate2),
95 ### TODO : Use GetBorrowersNamesAndLatestIssue function in order to get the borrowers to delete or anonymize.
96 ### Now, we are only using total, which is not enough imlo
98 output_html_with_http_headers
$cgi, $cookie, $template->output;
102 if ( $params->{'step3'} ) {
103 $filterdate1 = format_date_in_iso
($params->{'filterdate1'});
104 $filterdate2 = format_date_in_iso
($params->{'filterdate2'});
105 my $do_delete = $params->{'do_delete'};
106 my $do_anonym = $params->{'do_anonym'};
108 my ( $totalDel, $totalAno, $radio ) = ( 0, 0, 0 );
112 my $membersToDelete = GetBorrowersWhoHaveNotBorrowedSince
($filterdate1, 1);
113 $totalDel = scalar(@
$membersToDelete);
114 $radio = $params->{'radio'};
115 if ( $radio eq 'trash' ) {
117 for ( $i = 0 ; $i < $totalDel ; $i++ ) {
118 MoveMemberToDeleted
( $membersToDelete->[$i]->{'borrowernumber'} );
119 DelMember
( $membersToDelete->[$i]->{'borrowernumber'} );
122 else { # delete completly.
124 for ( $i = 0 ; $i < $totalDel ; $i++ ) {
125 DelMember
($membersToDelete->[$i]->{'borrowernumber'});
130 TotalDel
=> $totalDel
134 # Anonymising all members
136 $totalAno = AnonymiseIssueHistory
($filterdate2);
138 filterdate1
=> $filterdate2,
145 trash
=> ( $radio eq "trash" ) ?
(1) : (0),
148 #writing the template
149 output_html_with_http_headers
$cgi, $cookie, $template->output;
153 #default value set to the template are the 'CNIL' value.
154 my ( $year, $month, $day ) = &Today
();
155 $filterdate1 = format_date
(sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YM
($year, $month, $day, -1, 0)));
156 $filterdate2 = format_date
(sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YM
($year, $month, $day, 0, -3)));
160 filterdate1
=> $filterdate1,
161 filterdate2
=> $filterdate2,
162 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(),
165 #writing the template
166 output_html_with_http_headers
$cgi, $cookie, $template->output;