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
/Date_to_Days Today/;
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
=> 1, catalogue
=> 1 },
66 if ( $params->{'step2'} ) {
67 $filterdate1 = format_date_in_iso
($params->{'filterdate1'});
68 $filterdate2 = format_date_in_iso
($params->{'filterdate2'});
69 my $checkbox = $params->{'checkbox'};
72 if ($checkbox eq "borrower") {
73 my $membersToDelete = GetBorrowersWhoHaveNotBorrowedSince
($filterdate1);
74 $totalDel = scalar @
$membersToDelete;
78 if ($checkbox eq "issue") {
79 my $membersToAnonymize =
80 GetBorrowersWithIssuesHistoryOlderThan
($filterdate2);
81 $totalAno = scalar @
$membersToAnonymize;
86 totalToDelete
=> $totalDel,
87 totalToAnonymize
=> $totalAno,
88 filterdate1
=> format_date
($filterdate1),
89 filterdate2
=> format_date
($filterdate2),
93 output_html_with_http_headers
$cgi, $cookie, $template->output;
97 if ( $params->{'step3'} ) {
98 $filterdate1 = format_date_in_iso
($params->{'filterdate1'});
99 $filterdate2 = format_date_in_iso
($params->{'filterdate2'});
100 my $do_delete = $params->{'do_delete'};
101 my $do_anonym = $params->{'do_anonym'};
103 my ( $totalDel, $totalAno, $radio ) = ( 0, 0, 0 );
107 my $membersToDelete = GetBorrowersWhoHaveNotBorrowedSince
($filterdate1);
108 $totalDel = scalar(@
$membersToDelete);
109 $radio = $params->{'radio'};
110 if ( $radio eq 'trash' ) {
112 for ( $i = 0 ; $i < $totalDel ; $i++ ) {
113 MoveMemberToDeleted
( $membersToDelete->[$i]->{'borrowernumber'} );
114 DelMember
( $membersToDelete->[$i]->{'borrowernumber'} );
117 else { # delete completly.
119 for ( $i = 0 ; $i < $totalDel ; $i++ ) {
120 DelMember
($membersToDelete->[$i]->{'borrowernumber'});
125 TotalDel
=> $totalDel
129 # Anonymising all members
131 $totalAno = AnonymiseIssueHistory
($filterdate2);
133 filterdate1
=> $filterdate2,
140 trash
=> ( $radio eq "trash" ) ?
(1) : (0),
143 #writing the template
144 output_html_with_http_headers
$cgi, $cookie, $template->output;
148 #default value set to the template are the 'CNIL' value.
149 my ( $year, $month, $day ) = &Today
();
150 my $tmpyear = $year - 1;
151 my $tmpmonth = $month - 3;
152 $filterdate1 = format_date
($tmpyear . "-" . $month . "-" . $day);
153 $filterdate2 = format_date
($year . "-" . $tmpmonth . "-" . $day);
157 filterdate1
=> $filterdate1,
158 filterdate2
=> $filterdate2,
159 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(),
162 #writing the template
163 output_html_with_http_headers
$cgi, $cookie, $template->output;