From 9ea3deb1ee592a3a0466cd018636e48b311bb3d8 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 24 Feb 2011 13:09:00 +0100 Subject: [PATCH] Squashed commit of the following: Content-Type: text/plain; charset="utf-8" commit ff1b86f6504031020964bc187d5a204cc37d05d6 Merge: 3d49ed2... efc9e3a... Author: Chris Cormack Date: Wed Jul 7 19:56:32 2010 +1200 Merge commit 'kc/master' into new_features_ptfs_lost_cards commit 3d49ed249b53c51e71d0af999941ba820788b4dc Merge: e9a3b27... b6fc0d1... Author: Chris Cormack Date: Tue May 18 19:59:21 2010 +1200 Merge branch 'new_features' into new_features_ptfs_lost_cards commit e9a3b2731b34b8a097a3c7797d8ae00aa2ab5581 Merge: fc46177... 8a1cb95... Author: Chris Cormack Date: Tue May 11 21:58:36 2010 +1200 Merge branch 'new_features' into new_features_ptfs_lost_cards commit fc461778ace4e566a19cebbe3ed4cf4abe25bdea Author: J. David Bavousett Date: Tue Nov 17 17:19:04 2009 -0500 Added granular permission check to previous cardnumber feature commit dbf71d30d0068776432f488e81d8127db0830af8 Author: PTFS Date: Fri Aug 7 08:30:33 2009 -0400 Added warnings so librarians will know that a borrower was found by searching on a previous cardnumber. commit ad395f6da7295c526dd74d21bfaa59e25b9ee4be Author: PTFS Date: Mon Jun 29 08:28:51 2009 -0400 Bugfix for non-cardnumbers being pulled as previous cardnumbers. commit 7d9326326d801a03d328b3ef7677a93f7f2e42af Author: J. David Bavousett Date: Sat Jun 20 11:36:41 2009 -0400 Removed extra "my" in routine causing warning on run. commit 157ec910c6428f0f4a408c6f6cb8eaf79c79e506 Author: PTFS Date: Sat Jun 13 15:02:47 2009 -0400 Added date to the previous cardnumber list. commit c1d6d31ac2f5713e55dc02f56c0a78bb17003d4d Author: PTFS Date: Fri May 8 17:41:42 2009 -0400 1-1 Added ability to search on previous cardnumbers. commit 8bbf70ff1b817a0bb5d452bfc59fb924bfbd9f47 Author: PTFS Date: Tue Mar 3 05:51:37 2009 -0500 Previous Cardnumber Tracking Tracks previous cardnumbers and adds to ability to quickly revert a borrower to a previous cardnumber from the borrower details page. TODO: Allow searching on previous cardnumbers --- C4/Members.pm | 45 +++++++++++++++++ C4/Stats.pm | 20 ++++++++ circ/circulation.pl | 3 +- .../prog/en/modules/circ/circulation.tmpl | 1 + .../prog/en/modules/members/member.tmpl | 52 ++++++++++++++++++++ .../prog/en/modules/members/moremember.tmpl | 25 +++++++++ members/moremember.pl | 11 ++++- members/restore_cardnumber.pl | 50 +++++++++++++++++++ 8 files changed, 205 insertions(+), 2 deletions(-) create mode 100755 members/restore_cardnumber.pl diff --git a/C4/Members.pm b/C4/Members.pm index fafc99b..20eaf46 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -242,6 +242,21 @@ sub SearchMember { my @results; $data = $sth->fetchall_arrayref({}); + $sth->finish; + + $query = "SELECT borrowers.*, categories.* FROM borrowers + LEFT JOIN categories ON borrowers.categorycode=categories.categorycode + LEFT JOIN statistics ON borrowers.borrowernumber = statistics.borrowernumber + WHERE statistics.type = 'card_replaced' AND statistics.other = ? GROUP BY statistics.other"; + $sth = $dbh->prepare( $query ); + $sth->execute( $searchstring ); + my $prevcards_data = $sth->fetchall_arrayref({}); + foreach my $row ( @$prevcards_data ) { + $row->{'PreviousCardnumber'} = 1; + } + + $data = [ @$prevcards_data, @$data ]; + return ( scalar(@$data), $data ); } @@ -705,6 +720,36 @@ true on success, or false on failure sub ModMember { my (%data) = @_; + my $dbh = C4::Context->dbh; + + my $member = GetMemberDetails( $data{'borrowernumber'} ); + + if ( $member->{'cardnumber'} ne $data{'cardnumber'} ) { + C4::Stats::UpdateStats( C4::Context->userenv->{branch}, 'card_replaced', '', $member->{'cardnumber'}, '', '', $data{'borrowernumber'} ); + } + + my $iso_re = C4::Dates->new()->regexp('iso'); + foreach (qw(dateofbirth dateexpiry dateenrolled)) { + if (my $tempdate = $data{$_}) { # assignment, not comparison + ($tempdate =~ /$iso_re/) and next; # Congatulations, you sent a valid ISO date. + warn "ModMember given $_ not in ISO format ($tempdate)"; + my $tempdate2 = format_date_in_iso($tempdate); + if (!$tempdate2 or $tempdate2 eq '0000-00-00') { + warn "ModMember cannot convert '$tempdate' (from syspref to ISO)"; + next; + } + $data{$_} = $tempdate2; + } + } + if (!$data{'dateofbirth'}){ + delete $data{'dateofbirth'}; + } + my @columns = &columns; + my %hashborrowerfields = (map {$_=>1} @columns); + my $query = "UPDATE borrowers SET \n"; + my $sth; + my @parameters; + # test to know if you must update or not the borrower password if (exists $data{password}) { if ($data{password} eq '****' or $data{password} eq '') { diff --git a/C4/Stats.pm b/C4/Stats.pm index 11710f8..f6ad16e 100644 --- a/C4/Stats.pm +++ b/C4/Stats.pm @@ -118,6 +118,26 @@ sub TotalPaid { return @{$sth->fetchall_arrayref({})}; } +sub GetPreviousCardnumbers { + my ( $borrowernumber ) = @_; + my $dbh = C4::Context->dbh; + + my $member = C4::Members::GetMember( $borrowernumber ); + my $cardnumber = $member->{'cardnumber'}; + + my $query = "SELECT DISTINCT(other) AS previous_cardnumber, DATE_FORMAT( datetime, '%m/%e/%Y') as previous_cardnumber_date FROM statistics WHERE type = 'card_replaced' AND borrowernumber = ? AND other != ? AND other !='' "; + my $sth = $dbh->prepare( $query ); + $sth->execute( $borrowernumber, $cardnumber ); + + my @results; + while ( my $data = $sth->fetchrow_hashref ) { + push( @results, $data ); + } + $sth->finish; + + return @results; +} + 1; __END__ diff --git a/circ/circulation.pl b/circ/circulation.pl index ab681f1..7364217 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -215,8 +215,9 @@ if ($findborrower) { } elsif ( $#borrowers == 0 ) { $query->param( 'borrowernumber', $borrowers[0]->{'borrowernumber'} ); - $query->param( 'barcode', '' ); + $query->param( 'barcode', '' ); $borrowernumber = $borrowers[0]->{'borrowernumber'}; + $template->param( PreviousCardnumber => $borrowers[0]->{'PreviousCardnumber'} ); } else { $borrowerslist = \@borrowers; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl index df78c54..0c37c08 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl @@ -418,6 +418,7 @@ No patron matched +
Warning: Scanned Old Card
Enter item barcode:
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tmpl index 50a73da..7102e1d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tmpl @@ -87,6 +87,58 @@
No results found
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
&orderby=cardnumber">Card&orderby=surname">Name&orderby=borrowers.categorycode">Cat&orderby=branchcode">LibraryExpires onOD/IssuesFinesCirc note 
+ +

Warning: Found With Previous Cardnumber

+
">,


()/ + &category_type=">Edit + + + &categorycode=">Edit + + &category_type=A">Edit + +
+
+ + + +No results found + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl index 2cdc13a..fe35040 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl @@ -342,6 +342,29 @@ function validate1(date) { + + +
+

Previous Cardnumbers

+
    +
    + + " /> + +
    +
    +
    +
+
+ + +

Alternate Address

@@ -376,6 +399,7 @@ function validate1(date) {
+ @@ -398,6 +422,7 @@ function validate1(date) { +
diff --git a/members/moremember.pl b/members/moremember.pl index cc2f153..9c7cff4 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -52,7 +52,7 @@ use C4::Form::MessagingPreferences; use C4::NewsChannels; #get slip news #use Smart::Comments; -#use Data::Dumper; +use Data::Dumper; use vars qw($debug); @@ -422,6 +422,15 @@ if (C4::Context->preference('EnhancedMessagingPreferences')) { $template->param(SMSnumber => defined $data->{'smsalertnumber'} ? $data->{'smsalertnumber'} : $data->{'mobile'}); } +my @previousCardnumbers = C4::Stats::GetPreviousCardnumbers( $borrowernumber ); + +if ( @previousCardnumbers ) { + $template->param( + previousCardnumbersLoop => \@previousCardnumbers, + previousCardnumbersCount => scalar( @previousCardnumbers ) + ); +} + $template->param( detailview => 1, AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"), diff --git a/members/restore_cardnumber.pl b/members/restore_cardnumber.pl new file mode 100755 index 0000000..1b3ea75 --- /dev/null +++ b/members/restore_cardnumber.pl @@ -0,0 +1,50 @@ +#!/usr/bin/perl + +#script to delete items +#written 2/5/00 +#by chris@katipo.co.nz + +# Copyright 2000-2002 Katipo Communications +# +# 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 + +use strict; + +use CGI; +use C4::Context; +use C4::Output; +use C4::Auth; +use C4::Members; + +my $input = new CGI; + +my ($template, $borrowernumber, $cookie) + = get_template_and_user({template_name => "members/deletemem.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => {borrowers => 1}, + debug => 1, + }); + +my $borrowernumber = $input->param('borrowernumber'); +my $previous_cardnumber = $input->param('previous_cardnumber'); + +ModMember( borrowernumber => $borrowernumber, cardnumber => $previous_cardnumber ); + +print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber"); + + -- 1.6.0.6