Lines 37-46
use strict;
Link Here
|
37 |
use CGI; |
37 |
use CGI; |
38 |
use C4::Auth; |
38 |
use C4::Auth; |
39 |
use C4::Output; |
39 |
use C4::Output; |
40 |
use C4::Dates qw/format_date format_date_in_iso/; |
|
|
41 |
use C4::Members; # GetBorrowersWhoHavexxxBorrowed. |
40 |
use C4::Members; # GetBorrowersWhoHavexxxBorrowed. |
42 |
use C4::Circulation; # AnonymiseIssueHistory. |
41 |
use C4::Circulation; # AnonymiseIssueHistory. |
43 |
use C4::VirtualShelves (); #no import |
42 |
use C4::VirtualShelves (); #no import |
|
|
43 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
44 |
use Date::Calc qw/Today Add_Delta_YM/; |
44 |
use Date::Calc qw/Today Add_Delta_YM/; |
45 |
|
45 |
|
46 |
my $cgi = new CGI; |
46 |
my $cgi = new CGI; |
Lines 51-60
my $cgi = new CGI;
Link Here
|
51 |
# * multivalued CGI paramaters are returned as a packaged string separated by "\0" (null) |
51 |
# * multivalued CGI paramaters are returned as a packaged string separated by "\0" (null) |
52 |
my $params = $cgi->Vars; |
52 |
my $params = $cgi->Vars; |
53 |
|
53 |
|
54 |
my $filterdate1; # the date which filter on issue history. |
54 |
my $step = $params->{step} || 1; |
55 |
my $filterdate2; # the date which filter on borrowers last issue. |
55 |
my $not_borrowered_since = # the date which filter on issue history. |
56 |
my $borrower_dateexpiry; |
56 |
$params->{not_borrowered_since} |
57 |
my $borrower_categorycode; |
57 |
? dt_from_string $params->{not_borrowered_since} |
|
|
58 |
: undef; |
59 |
my $last_issue_date = # the date which filter on borrowers last issue. |
60 |
$params->{last_issue_date} |
61 |
? dt_from_string $params->{last_issue_date} |
62 |
: undef; |
63 |
my $borrower_dateexpiry = |
64 |
$params->{borrower_dateexpiry} |
65 |
? dt_from_string $params->{borrower_dateexpiry} |
66 |
: undef; |
67 |
|
68 |
my $borrower_categorycode = $params->{'borrower_categorycode'} || q{}; |
58 |
|
69 |
|
59 |
# getting the template |
70 |
# getting the template |
60 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
71 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
Lines 66-84
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Link Here
|
66 |
} |
77 |
} |
67 |
); |
78 |
); |
68 |
|
79 |
|
69 |
if ( $params->{'step2'} ) { |
80 |
if ( $step == 2 ) { |
70 |
$filterdate1 = format_date_in_iso( $params->{'filterdate1'} ); |
|
|
71 |
$filterdate2 = format_date_in_iso( $params->{'filterdate2'} ); |
72 |
$borrower_dateexpiry = format_date_in_iso( $params->{'borrower_dateexpiry'} ); |
73 |
$borrower_categorycode = $params->{'borrower_categorycode'}; |
74 |
|
81 |
|
75 |
my %checkboxes = map { $_ => 1 } split /\0/, $params->{'checkbox'}; |
82 |
my %checkboxes = map { $_ => 1 } split /\0/, $params->{'checkbox'}; |
76 |
|
83 |
|
77 |
my $totalDel; |
84 |
my $totalDel; |
78 |
my $membersToDelete; |
85 |
my $membersToDelete; |
79 |
if ( $checkboxes{borrower} ) { |
86 |
if ( $checkboxes{borrower} ) { |
80 |
$membersToDelete = |
87 |
$membersToDelete = GetBorrowersToExpunge( |
81 |
GetBorrowersToExpunge( { not_borrowered_since => $filterdate1, expired_before => $borrower_dateexpiry, category_code => $borrower_categorycode } ); |
88 |
{ |
|
|
89 |
( |
90 |
$not_borrowered_since |
91 |
? ( |
92 |
not_borrowered_since => output_pref( |
93 |
{ |
94 |
dt => $not_borrowered_since, |
95 |
dateformat => 'iso', |
96 |
dateonly => 1 |
97 |
} |
98 |
) |
99 |
) |
100 |
: () |
101 |
), |
102 |
( |
103 |
$borrower_dateexpiry |
104 |
? ( |
105 |
expired_before => output_pref( |
106 |
{ |
107 |
dt => $borrower_dateexpiry, |
108 |
dateformat => 'iso', |
109 |
dateonly => 1 |
110 |
} |
111 |
) |
112 |
) |
113 |
: () |
114 |
), |
115 |
( |
116 |
$borrower_categorycode |
117 |
? ( category_code => $borrower_categorycode ) |
118 |
: () |
119 |
), |
120 |
} |
121 |
); |
82 |
_skip_borrowers_with_nonzero_balance( $membersToDelete ); |
122 |
_skip_borrowers_with_nonzero_balance( $membersToDelete ); |
83 |
$totalDel = scalar @$membersToDelete; |
123 |
$totalDel = scalar @$membersToDelete; |
84 |
|
124 |
|
Lines 86-118
if ( $params->{'step2'} ) {
Link Here
|
86 |
my $totalAno; |
126 |
my $totalAno; |
87 |
my $membersToAnonymize; |
127 |
my $membersToAnonymize; |
88 |
if ( $checkboxes{issue} ) { |
128 |
if ( $checkboxes{issue} ) { |
89 |
$membersToAnonymize = GetBorrowersWithIssuesHistoryOlderThan($filterdate2); |
129 |
$membersToAnonymize = GetBorrowersWithIssuesHistoryOlderThan($last_issue_date); |
90 |
$totalAno = scalar @$membersToAnonymize; |
130 |
$totalAno = scalar @$membersToAnonymize; |
91 |
} |
131 |
} |
92 |
|
132 |
|
93 |
$template->param( |
133 |
$template->param( |
94 |
step2 => 1, |
|
|
95 |
totalToDelete => $totalDel, |
134 |
totalToDelete => $totalDel, |
96 |
totalToAnonymize => $totalAno, |
135 |
totalToAnonymize => $totalAno, |
97 |
memberstodelete_list => $membersToDelete, |
136 |
memberstodelete_list => $membersToDelete, |
98 |
memberstoanonymize_list => $membersToAnonymize, |
137 |
memberstoanonymize_list => $membersToAnonymize, |
99 |
filterdate1 => format_date($filterdate1), |
|
|
100 |
filterdate2 => format_date($filterdate2), |
101 |
borrower_dateexpiry => format_date($borrower_dateexpiry), |
102 |
borrower_categorycode => $borrower_categorycode, |
103 |
); |
138 |
); |
104 |
|
|
|
105 |
### TODO : Use GetBorrowersNamesAndLatestIssue function in order to get the borrowers to delete or anonymize. |
106 |
output_html_with_http_headers $cgi, $cookie, $template->output; |
107 |
exit; |
108 |
} |
139 |
} |
109 |
|
140 |
|
110 |
if ( $params->{'step3'} ) { |
141 |
elsif ( $step == 3 ) { |
111 |
$filterdate1 = format_date_in_iso( $params->{'filterdate1'} ); |
|
|
112 |
$filterdate2 = format_date_in_iso( $params->{'filterdate2'} ); |
113 |
$borrower_dateexpiry = format_date_in_iso( $params->{'borrower_dateexpiry'} ); |
114 |
$borrower_categorycode = $params->{'borrower_categorycode'}; |
115 |
|
116 |
my $do_delete = $params->{'do_delete'}; |
142 |
my $do_delete = $params->{'do_delete'}; |
117 |
my $do_anonym = $params->{'do_anonym'}; |
143 |
my $do_anonym = $params->{'do_anonym'}; |
118 |
|
144 |
|
Lines 120-127
if ( $params->{'step3'} ) {
Link Here
|
120 |
|
146 |
|
121 |
# delete members |
147 |
# delete members |
122 |
if ($do_delete) { |
148 |
if ($do_delete) { |
123 |
my $membersToDelete = |
149 |
my $membersToDelete = GetBorrowersToExpunge( |
124 |
GetBorrowersToExpunge( { not_borrowered_since => $filterdate1, expired_before => $borrower_dateexpiry, category_code => $borrower_categorycode } ); |
150 |
{ |
|
|
151 |
( |
152 |
$not_borrowered_since |
153 |
? ( |
154 |
not_borrowered_since => output_pref( |
155 |
{ |
156 |
dt => $not_borrowered_since, |
157 |
dateformat => 'iso' |
158 |
} |
159 |
) |
160 |
) |
161 |
: () |
162 |
), |
163 |
( |
164 |
$borrower_dateexpiry |
165 |
? ( |
166 |
expired_before => output_pref( |
167 |
{ dt => $borrower_dateexpiry, dateformat => 'iso' } |
168 |
) |
169 |
) |
170 |
: () |
171 |
), |
172 |
( |
173 |
$borrower_categorycode |
174 |
? ( category_code => $borrower_categorycode ) |
175 |
: () |
176 |
), |
177 |
} |
178 |
); |
125 |
_skip_borrowers_with_nonzero_balance( $membersToDelete ); |
179 |
_skip_borrowers_with_nonzero_balance( $membersToDelete ); |
126 |
$totalDel = scalar(@$membersToDelete); |
180 |
$totalDel = scalar(@$membersToDelete); |
127 |
$radio = $params->{'radio'}; |
181 |
$radio = $params->{'radio'}; |
Lines 141-169
if ( $params->{'step3'} ) {
Link Here
|
141 |
# Anonymising all members |
195 |
# Anonymising all members |
142 |
if ($do_anonym) { |
196 |
if ($do_anonym) { |
143 |
#FIXME: anonymisation errors are not handled |
197 |
#FIXME: anonymisation errors are not handled |
144 |
($totalAno,my $anonymisation_error) = AnonymiseIssueHistory($filterdate2); |
198 |
($totalAno,my $anonymisation_error) = AnonymiseIssueHistory($last_issue_date); |
145 |
$template->param( |
199 |
$template->param( |
146 |
filterdate1 => $filterdate2, |
|
|
147 |
do_anonym => '1', |
200 |
do_anonym => '1', |
148 |
); |
201 |
); |
149 |
} |
202 |
} |
150 |
|
203 |
|
151 |
$template->param( |
204 |
$template->param( |
152 |
step3 => '1', |
|
|
153 |
trash => ( $radio eq "trash" ) ? (1) : (0), |
205 |
trash => ( $radio eq "trash" ) ? (1) : (0), |
154 |
testrun => ( $radio eq "testrun" ) ? 1: 0, |
206 |
testrun => ( $radio eq "testrun" ) ? 1: 0, |
155 |
); |
207 |
); |
156 |
|
|
|
157 |
#writing the template |
158 |
output_html_with_http_headers $cgi, $cookie, $template->output; |
159 |
exit; |
160 |
} |
208 |
} |
161 |
|
209 |
|
162 |
$template->param( |
210 |
$template->param( |
163 |
step1 => '1', |
211 |
step => $step, |
164 |
filterdate1 => $filterdate1, |
212 |
not_borrowered_since => $not_borrowered_since, |
165 |
filterdate2 => $filterdate2, |
213 |
borrower_dateexpiry => $borrower_dateexpiry, |
166 |
borrower_categorycodes => GetBorrowercategoryList(), |
214 |
last_issue_date => $last_issue_date, |
|
|
215 |
borrower_categorycodes => GetBorrowercategoryList(), |
216 |
borrower_categorycode => $borrower_categorycode, |
167 |
); |
217 |
); |
168 |
|
218 |
|
169 |
#writing the template |
219 |
#writing the template |
170 |
- |
|
|