View | Details | Raw Unified | Return to bug 11975
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tt (-14 / +19 lines)
Lines 1-5 Link Here
1
[% USE KohaDates %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; Batch patron deletion/anonymization [% IF ( step2 ) %]&rsaquo; Confirm[% END %][% IF ( step3 ) %]&rsaquo; Finished[% END %]</title>
3
<title>Koha &rsaquo; Tools &rsaquo; Batch patron deletion/anonymization [% IF step == 2 %]&rsaquo; Confirm[% END %][% IF step == 3 %]&rsaquo; Finished[% END %]</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'calendar.inc' %]
5
[% INCLUDE 'calendar.inc' %]
5
<script type="text/javascript">
6
<script type="text/javascript">
Lines 21-29 Link Here
21
                      return false;
22
                      return false;
22
                  }
23
                  }
23
              }
24
              }
25
              if(!form.checkbox[0].checked && !form.checkbox[1].checked) {
26
                alert( _("Please check at least one action") );
27
                return false;
28
              }
24
              return true;
29
              return true;
25
          }
30
          }
26
          
31
27
        /**
32
        /**
28
         *  checkForm2(form)
33
         *  checkForm2(form)
29
         *  This function check the form2 is correctly filled.
34
         *  This function check the form2 is correctly filled.
Lines 39-45 Link Here
39
[% INCLUDE 'header.inc' %]
44
[% INCLUDE 'header.inc' %]
40
[% INCLUDE 'cat-search.inc' %]
45
[% INCLUDE 'cat-search.inc' %]
41
46
42
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>  &rsaquo; [% IF ( step1 ) %]Clean Patron Records[% ELSE %]<a href="/cgi-bin/koha/tools/cleanborrowers.pl">Clean patron records</a> &rsaquo; [% END %][% IF ( step2 ) %]Confirm[% END %][% IF ( step3 ) %]Finished[% END %]</div>
47
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>  &rsaquo; [% IF step == 1 %]Clean Patron Records[% ELSE %]<a href="/cgi-bin/koha/tools/cleanborrowers.pl">Clean patron records</a> &rsaquo; [% END %][% IF step == 2 %]Confirm[% END %][% IF step == 3 %]Finished[% END %]</div>
43
48
44
<div id="doc3" class="yui-t2">
49
<div id="doc3" class="yui-t2">
45
50
Lines 51-57 Link Here
51
<div class="help">
56
<div class="help">
52
    <p>This tool allows you to delete patrons and anonymize checkout history. For deleting patrons, any combination of limits can be used.</p>
57
    <p>This tool allows you to delete patrons and anonymize checkout history. For deleting patrons, any combination of limits can be used.</p>
53
</div>
58
</div>
54
[% IF ( step1 ) %]
59
[% IF step == 1 %]
55
<!-- step 1 START -->
60
<!-- step 1 START -->
56
<div id="step1">
61
<div id="step1">
57
    <form name="f1" onsubmit="return checkForm(this);" action="/cgi-bin/koha/tools/cleanborrowers.pl" method="post">
62
    <form name="f1" onsubmit="return checkForm(this);" action="/cgi-bin/koha/tools/cleanborrowers.pl" method="post">
Lines 63-69 Link Here
63
        <ul>
68
        <ul>
64
                <li>
69
                <li>
65
                    <label for="date1">who have not borrowed since:</label>
70
                    <label for="date1">who have not borrowed since:</label>
66
                    <input size="10" id="date1" name="filterdate1" type="text" class="datepicker" />
71
                    <input size="10" id="date1" name="not_borrowed_since" type="text" class="datepicker" />
67
                    <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
72
                    <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
68
                </li>
73
                </li>
69
                <li>
74
                <li>
Lines 91-103 Link Here
91
        <ul>
96
        <ul>
92
            <li>
97
            <li>
93
                <label for="date2">Permanently delete checkout history older than</label>
98
                <label for="date2">Permanently delete checkout history older than</label>
94
                <input size="10" id="date2" name="filterdate2" type="text" class="datepicker" />
99
                <input size="10" id="date2" name="last_issue_date" type="text" class="datepicker" />
95
                <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
100
                <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
96
            </li>
101
            </li>
97
        </ul>
102
        </ul>
98
103
99
            <!-- hidden here -->
104
            <!-- hidden here -->
100
            <input type="hidden" name="step2" value="1" />
105
            <input type="hidden" name="step" value="2" />
101
            </fieldset>
106
            </fieldset>
102
            <fieldset class="action"><input type="submit" value="Next &gt;&gt;" /></fieldset>
107
            <fieldset class="action"><input type="submit" value="Next &gt;&gt;" /></fieldset>
103
    </form>
108
    </form>
Lines 105-111 Link Here
105
<!-- step 1 END -->
110
<!-- step 1 END -->
106
[% END %]
111
[% END %]
107
112
108
[% IF ( step2 ) %]
113
[% IF step == 2 %]
109
<!-- STEP 2 START -->
114
<!-- STEP 2 START -->
110
<div id="step2">
115
<div id="step2">
111
        <form name="f2" action="/cgi-bin/koha/tools/cleanborrowers.pl" method="post" onsubmit="return checkForm2(this);">
116
        <form name="f2" action="/cgi-bin/koha/tools/cleanborrowers.pl" method="post" onsubmit="return checkForm2(this);">
Lines 135-144 Link Here
135
                <input type="hidden" name="do_anonym" value="[% totalToAnonymize %]" />
140
                <input type="hidden" name="do_anonym" value="[% totalToAnonymize %]" />
136
            [% END %]
141
            [% END %]
137
142
138
            <input type="hidden" name="step3" value="1" />
143
            <input type="hidden" name="step" value="3" />
139
            <input type="hidden" name="filterdate1" value="[% filterdate1 %]" />
144
            <input type="hidden" name="not_borrowed_since" value="[% not_borrowed_since | $KohaDates %]" />
140
            <input type="hidden" name="filterdate2" value="[% filterdate2 %]" />
145
            <input type="hidden" name="last_issue_date" value="[% last_issue_date | $KohaDates %]" />
141
            <input type="hidden" name="borrower_dateexpiry" value="[% borrower_dateexpiry %]" />
146
            <input type="hidden" name="borrower_dateexpiry" value="[% borrower_dateexpiry | $KohaDates %]" />
142
            <input type="hidden" name="borrower_categorycode" value="[% borrower_categorycode %]" />
147
            <input type="hidden" name="borrower_categorycode" value="[% borrower_categorycode %]" />
143
    </fieldset>
148
    </fieldset>
144
    <fieldset class="action"><input type="submit" value="Finish" /> <a class="cancel" href="/cgi-bin/koha/tools/cleanborrowers.pl">Cancel</a></fieldset>
149
    <fieldset class="action"><input type="submit" value="Finish" /> <a class="cancel" href="/cgi-bin/koha/tools/cleanborrowers.pl">Cancel</a></fieldset>
Lines 147-153 Link Here
147
<!-- STEP 2 END -->
152
<!-- STEP 2 END -->
148
[% END %]
153
[% END %]
149
154
150
[% IF ( step3 ) %]
155
[% IF step == 3 %]
151
<!-- Step 3 START -->
156
<!-- Step 3 START -->
152
157
153
    <div id="step3">
158
    <div id="step3">
Lines 166-172 Link Here
166
            [% END %]
171
            [% END %]
167
        [% END %]
172
        [% END %]
168
        [% IF ( do_anonym ) %]
173
        [% IF ( do_anonym ) %]
169
            <h4>All patrons with checkouts older than [% filterdate1 %] have been anonymized</h4>
174
            <h4>All patrons with checkouts older than [% last_issue_date | $KohaDates %] have been anonymized</h4>
170
        [% ELSE %]
175
        [% ELSE %]
171
            <h4>No patron records have been anonymized</h4>
176
            <h4>No patron records have been anonymized</h4>
172
        [% END %]
177
        [% END %]
(-)a/tools/cleanborrowers.pl (-42 / +91 lines)
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
- 

Return to bug 11975