[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Koha-cvs] koha/tools cleanborrowers.pl [rel_3_0]
From: |
Antoine Farnault |
Subject: |
[Koha-cvs] koha/tools cleanborrowers.pl [rel_3_0] |
Date: |
Thu, 16 Nov 2006 10:10:57 +0000 |
CVSROOT: /sources/koha
Module name: koha
Branch: rel_3_0
Changes by: Antoine Farnault <toins> 06/11/16 10:10:57
Added files:
tools : cleanborrowers.pl
Log message:
New script: tools/cleanborrowers.pl
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/tools/cleanborrowers.pl?cvsroot=koha&only_with_tag=rel_3_0&rev=1.1.2.1
Patches:
Index: cleanborrowers.pl
===================================================================
RCS file: cleanborrowers.pl
diff -N cleanborrowers.pl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ cleanborrowers.pl 16 Nov 2006 10:10:57 -0000 1.1.2.1
@@ -0,0 +1,232 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+#
+# Written by Antoine Farnault address@hidden on Nov. 2006.
+
+# $Id: cleanborrowers.pl,v 1.1.2.1 2006/11/16 10:10:57 toins Exp $
+
+=head1 cleanborrowers.pl
+
+This script allows to do 2 things.
+
+=over 2
+
+=item * Anonymise the borrowers' issues if issue is older than a given date.
see C<datefilter1>.
+
+=item * Delete the borrowers who has not borrowered since a given date. see
C<datefilter2>.
+
+=back
+
+=cut
+
+use strict;
+use CGI;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+use HTML::Template;
+
+use C4::Members; # bornameSearch.
+use C4::Circulation::Circ2; # AnonymiseIssueHistory.
+use Date::Calc qw/Date_to_Days Today/;
+
+my $cgi = new CGI;
+
+# Fetch the paramater list as a hash in scalar context:
+# * returns paramater list as tied hash ref
+# * we can edit the values by changing the key
+# * multivalued CGI paramaters are returned as a packaged string separated by
"\0" (null)
+my $params = $cgi->Vars;
+
+my $filterdate1; # the date which filter on issue history.
+my $filterdate2; # the date which filter on borrowers last issue.
+
+# getting the template
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+ {
+ template_name => "tools/cnil.tmpl",
+ query => $cgi,
+ type => "intranet",
+ authnotrequired => 0,
+ flagsrequired => { tools => 1, catalogue => 1 },
+ }
+);
+
+# if script has to search
+if ( $params->{'do_search'} ) {
+
+ # getting some CGI params.
+ my $query = $params->{'query'} || "%"; # the borrower name
+ my $orderby = $params->{'orderby'};
+ my $checkborrower;
+ my $checkissue;
+
+ # to know what radio is checked.
+ if ( $params->{'radio'} eq "old-borrower" ) {
+ $checkborrower = 1;
+ $checkissue = 0;
+ }
+ else {
+ $checkborrower = 0;
+ $checkissue = 1;
+ }
+
+ #getting this list of borrower LIKE $query.
+ my ( $count, $results ) =
+ BornameSearch( C4::Context->env, $query, $orderby, "advanced" );
+ my @membersloop;
+
+ my $i;
+ for ( $i = 0 ; $i < @$results ; $i++ ) { # building the results list.
+
+ # getting some infos for the current borrower.
+ my ( $od, $issue, $fines ) =
+ borrdata2( C4::Context->env, $results->[$i]{'borrowernumber'} );
+
+ next if $od; # can't delete a borrower with overdued items.
+ next if $issue; # can't delete a borrower with issued items.
+ next if $fines; # can't delete a borrower who has to pay some fines.
+
+ # if there is a radio button check.
+ if ( $checkborrower or $checkissue ) {
+
+ #getting the issues list for this borrower
+ my ( $count, $issues ) =
+ &allissues( $results->[$i]{'borrowernumber'},
+ "items.timestamp", 0 );
+
+ if ($checkborrower) {
+ $template->param( checkborrower => '1' );
+
+ #getting the date the librarian has writed to filter.
+ my $filterdate2 = $params->{'filterdate2'};
+ $template->param( filterdate2 => $filterdate2 );
+
+ # setting the date into days format to just have a simple
number.
+ $filterdate2 = Date_to_Days( ( split /-/, $filterdate2 ) );
+
+ # if this borrower has never borrowed then got him into
@membersloop.
+ if ( !$count ) {
+ $results->[$i]->{'neverborrowed'} = 1;
+ push @membersloop, $results->[$i];
+ next;
+ }
+
+ # if his last borrowed is before the $filterdate2 then got him.
+ # -1- getting his last issue
+ # the issues array is sort, so getting its last value.
+ my ($lastissue) = split / /, $issues->[-1]
+ ->{'itemstimestamp'}; # get the date and not the hours.
+ $lastissue = Date_to_Days( split /-/, $lastissue );
+
+ # -2- if his late issue is before filterdate2 then got him.
+ if ( $lastissue < $filterdate2 ) {
+ $results->[$i]->{'notborrowedsince'} = 1;
+ $results->[$i]->{'lastissued'} =
+ $issues->[-1]->{'itemstimestamp'};
+ push @membersloop, $results->[$i];
+ }
+ }
+
+ # if "reading history older than" is checked
+ if ($checkissue) {
+ $template->param( checkissue => '1' );
+ my $filterdate1 = $params->{'filterdate1'};
+ $template->param( filterdate1 => $filterdate1 );
+ $filterdate1 = Date_to_Days( split /-/, $filterdate1 );
+ my $NbIssuedBefore = 0;
+ foreach (@$issues) {
+ my ($date) = split / /, $_->{'itemstimestamp'};
+ $date = Date_to_Days( split /-/, $date );
+ if ( $date < $filterdate1 ) {
+ $NbIssuedBefore++;
+ }
+ }
+ if ($NbIssuedBefore) {
+ $results->[$i]->{'oldreadinghistory'} = $NbIssuedBefore;
+ push @membersloop, $results->[$i];
+ }
+ }
+ }
+ else {
+ @membersloop = @$results;
+ }
+ }
+ $template->param(
+ total => scalar @membersloop,
+ query => $query,
+ orderby => $orderby,
+ membersloop => address@hidden,
+ );
+
+ #writing the template
+ output_html_with_http_headers $cgi, $cookie, $template->output;
+ exit;
+} #if do_search
+
+# if script has to delete some borrowers.
+if ( $params->{'do_delete'} ) {
+ foreach my $borrowernumber ( values %$params ) {
+ next unless ( $borrowernumber =~ /^([0-9])*$/ );
+ DeleteBorrower($borrowernumber)
+ ; #FIXME :: This function don't remove complety. It's just rewrited
on deleteborrower table. So what to do ?
+ }
+
+ $template->param(
+ deleted => '1',
+ filterdate1 => $params->{'filterdate1'},
+ filterdate2 => $params->{'filterdate2'}
+ );
+
+ #writing the template
+ output_html_with_http_headers $cgi, $cookie, $template->output;
+ exit;
+} #if do_delete
+
+#if this script has to anonymise a reading history.
+if ( $params->{'do_anonym'} ) {
+ my $error;
+ $filterdate1 = $params->{'filterdate1'};
+ foreach my $borrowernumber ( values %$params ) {
+ next unless ( $borrowernumber =~ /^([0-9])*$/ );
+ $error = AnonymiseIssueHistory( $borrowernumber, $filterdate1 );
+ }
+ $template->param(
+ anonym => '1',
+ filterdate1 => $params->{'filterdate1'},
+ filterdate2 => $params->{'filterdate2'},
+ error => $error
+ );
+
+ #writing the template
+ output_html_with_http_headers $cgi, $cookie, $template->output;
+ exit;
+} #if do_anonym
+
+#default value set to the template are the 'CNIL' value.
+my ( $year, $month, $day ) = &Today();
+my $tmpyear = $year - 1;
+my $tmpmonth = $month - 3;
+$filterdate1 = $year . "-" . $tmpmonth . "-" . $day;
+$filterdate2 = $tmpyear . "-" . $month . "-" . $day;
+
+$template->param(
+ filterdate1 => $filterdate1,
+ filterdate2 => $filterdate2
+);
+
+#writing the template
+output_html_with_http_headers $cgi, $cookie, $template->output;
- [Koha-cvs] koha/tools cleanborrowers.pl [rel_3_0],
Antoine Farnault <=