Moved the cardnumber generation logic out of memberentry.pl; new module
C4::Members created to hold this logic Fixed syntax error in newimember.pl Make newimember.pl use the cardnumber generation logic (bug 206) Updated newimember.pl to use get_template_and_user Other minor mods to newimember.pl; new tab size noted
This commit is contained in:
parent
ac6592a669
commit
7d7deb7b36
3 changed files with 170 additions and 70 deletions
117
C4/Members.pm
Normal file
117
C4/Members.pm
Normal file
|
@ -0,0 +1,117 @@
|
|||
# -*- tab-width: 8 -*-
|
||||
|
||||
package C4::Members;
|
||||
|
||||
# Copyright 2000-2003 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;
|
||||
require Exporter;
|
||||
use C4::Context;
|
||||
|
||||
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
|
||||
|
||||
$VERSION = 0.01;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
C4::Members - Perl Module containing convenience functions for member handling
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=over 2
|
||||
|
||||
=cut
|
||||
|
||||
@ISA = qw(Exporter);
|
||||
@EXPORT = qw();
|
||||
|
||||
@EXPORT_OK = qw(
|
||||
&fixup_cardnumber
|
||||
);
|
||||
|
||||
################################################################################
|
||||
|
||||
=item fixup_cardnumber
|
||||
|
||||
Warning: The caller is responsible for locking the members table in write
|
||||
mode, to avoid database corruption.
|
||||
|
||||
=cut
|
||||
|
||||
use vars qw( @weightings );
|
||||
my @weightings = (8,4,6,3,5,2,1);
|
||||
|
||||
sub fixup_cardnumber ($) {
|
||||
my($cardnumber) = @_;
|
||||
my $autonumber_members = C4::Context->boolean_preference('autoMemberNum');
|
||||
$autonumber_members = 0 unless defined $autonumber_members;
|
||||
|
||||
warn "autoMemberNum is $autonumber_members\n";
|
||||
|
||||
# Find out whether member numbers should be generated
|
||||
# automatically. Should be either "1" or something else.
|
||||
# Defaults to "0", which is interpreted as "no".
|
||||
|
||||
if ($cardnumber !~ /\S/ && $autonumber_members) {
|
||||
my $dbh = C4::Context->dbh;
|
||||
my $query="select max(substring(borrowers.cardnumber,2,7)) from borrowers";
|
||||
my $sth=$dbh->prepare($query);
|
||||
$sth->execute;
|
||||
|
||||
my $data=$sth->fetchrow_hashref;
|
||||
$cardnumber=$data->{'max(substring(borrowers.cardnumber,2,7))'};
|
||||
$sth->finish;
|
||||
|
||||
# purpose: generate checksum'd member numbers.
|
||||
# We'll assume we just got the max value of digits 2-8 of member #'s
|
||||
# from the database and our job is to increment that by one,
|
||||
# determine the 1st and 9th digits and return the full string.
|
||||
|
||||
if (! $cardnumber) { # If DB has no values,
|
||||
$cardnumber = 1000000; # start at 1000000
|
||||
} else {
|
||||
$cardnumber += 1;
|
||||
}
|
||||
|
||||
my $sum = 0;
|
||||
for (my $i = 0; $i < 8; $i += 1) {
|
||||
# read weightings, left to right, 1 char at a time
|
||||
my $temp1 = $weightings[$i];
|
||||
|
||||
# sequence left to right, 1 char at a time
|
||||
my $temp2 = substr($cardnumber,$i,1);
|
||||
|
||||
# mult each char 1-7 by its corresponding weighting
|
||||
$sum += $temp1 * $temp2;
|
||||
}
|
||||
|
||||
my $rem = ($sum%11);
|
||||
$rem = 'X' if $rem == 10;
|
||||
|
||||
$cardnumber="V$cardnumber$rem";
|
||||
}
|
||||
return $cardnumber;
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,4 +1,6 @@
|
|||
#!/usr/bin/perl
|
||||
# NOTE: This file uses standard 8-space tabs
|
||||
# DO NOT SET TAB SIZE TO 4
|
||||
|
||||
# $Id$
|
||||
|
||||
|
@ -30,6 +32,7 @@ use C4::Output;
|
|||
use C4::Interface::CGI::Output;
|
||||
use CGI;
|
||||
use C4::Search;
|
||||
use C4::Members;
|
||||
use C4::Koha;
|
||||
use HTML::Template;
|
||||
|
||||
|
@ -69,50 +72,7 @@ if ($delete){
|
|||
$template->param( updtype => 'M');
|
||||
}
|
||||
|
||||
my $cardnumber=$data->{'cardnumber'};
|
||||
my $autonumber_members = C4::Context->boolean_preference("autoMemberNum") || 0;
|
||||
# Find out whether member numbers should be generated
|
||||
# automatically. Should be either "1" or something else.
|
||||
# Defaults to "0", which is interpreted as "no".
|
||||
# FIXME
|
||||
# This logic should probably be moved out of the presentation code.
|
||||
# Not tonight though.
|
||||
#
|
||||
if ($cardnumber eq '' && $autonumber_members) {
|
||||
my $dbh = C4::Context->dbh;
|
||||
my $query="select max(substring(borrowers.cardnumber,2,7)) from borrowers";
|
||||
my $sth=$dbh->prepare($query);
|
||||
$sth->execute;
|
||||
my $data=$sth->fetchrow_hashref;
|
||||
$cardnumber=$data->{'max(substring(borrowers.cardnumber,2,7))'};
|
||||
$sth->finish;
|
||||
# purpose: generate checksum'd member numbers.
|
||||
# We'll assume we just got the max value of digits 2-8 of member #'s from the database and our job is to
|
||||
# increment that by one, determine the 1st and 9th digits and return the full string.
|
||||
my @weightings = (8,4,6,3,5,2,1);
|
||||
my $sum;
|
||||
my $i = 0;
|
||||
if (! $cardnumber) { # If DB has no values, start at 1000000
|
||||
$cardnumber = 1000000;
|
||||
} else {
|
||||
$cardnumber = $cardnumber + 1; # FIXME - $cardnumber++;
|
||||
}
|
||||
|
||||
while ($i <8) { # step from char 1 to 7.
|
||||
my $temp1 = $weightings[$i]; # read weightings, left to right, 1 char at a time
|
||||
my $temp2 = substr($cardnumber,$i,1); # sequence left to right, 1 char at a time
|
||||
#print "$temp2<br>";
|
||||
$sum += $temp1*$temp2; # mult each char 1-7 by its corresponding weighting
|
||||
$i++; # increment counter
|
||||
}
|
||||
my $rem = ($sum%11); # remainder of sum/11 (eg. 9999999/11, remainder=2)
|
||||
if ($rem == 10) { # if remainder is 10, use X instead
|
||||
$rem = "X";
|
||||
}
|
||||
$cardnumber="V$cardnumber$rem";
|
||||
} else {
|
||||
$cardnumber=$data->{'cardnumber'};
|
||||
}
|
||||
my $cardnumber=C4::Members::fixup_cardnumber($data->{'cardnumber'});
|
||||
|
||||
if ($data->{'sex'} eq 'F'){
|
||||
$template->param(female => 1);
|
||||
|
@ -246,3 +206,7 @@ output_html_with_http_headers $input, $cookie, $template->output;
|
|||
|
||||
|
||||
}
|
||||
|
||||
# Local Variables:
|
||||
# tab-width: 8
|
||||
# End:
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
#!/usr/bin/perl
|
||||
# Note: This file now uses standard 8-space tabs
|
||||
|
||||
# $Id$
|
||||
|
||||
#script to print confirmation screen, then if accepted calls itself to insert data
|
||||
#script to print confirmation screen,
|
||||
#then if accepted calls itself to insert data
|
||||
#modified 2002/12/16 by hdl@ifrance.com : Templating
|
||||
#the "parent" is imemberentry.pl
|
||||
|
||||
|
||||
# Copyright 2000-2002 Katipo Communications
|
||||
# Copyright 2000-2003 Katipo Communications
|
||||
#
|
||||
# This file is part of Koha.
|
||||
#
|
||||
|
@ -26,6 +29,9 @@
|
|||
use strict;
|
||||
use C4::Output;
|
||||
use C4::Input;
|
||||
use C4::Auth;
|
||||
use C4::Interface::CGI::Output;
|
||||
use C4::Members;
|
||||
use CGI;
|
||||
use Date::Manip;
|
||||
use HTML::Template;
|
||||
|
@ -36,57 +42,70 @@ my $input = new CGI;
|
|||
#or insert data
|
||||
my $insert=$input->param('insert');
|
||||
|
||||
my $template=gettemplate("newimember.tmpl");
|
||||
my ($template, $loggedinuser, $cookie) = get_template_and_user({
|
||||
template_name => "newimember.tmpl",
|
||||
query => $input,
|
||||
type => "intranet",
|
||||
authnotrequired => 0,
|
||||
flagsrequired => {borrowers => 1},
|
||||
debug => 1,
|
||||
});
|
||||
|
||||
#get rest of data
|
||||
my %data;
|
||||
my @names=$input->param;
|
||||
foreach my $key (@names){
|
||||
$data{$key}=$input->param($key);
|
||||
}
|
||||
|
||||
# FIXME: $ok means "not ok", but $valid really means "valid"
|
||||
my $ok=0;
|
||||
|
||||
my $string="The following compulsary fields have been left blank. Please push the back button
|
||||
and try again<p>";
|
||||
if ($data{'cardnumber_institution'} eq ''){
|
||||
if ($data{'cardnumber_institution'} !~ /\S/){
|
||||
$string.="Cardnumber<br>";
|
||||
$ok=1;
|
||||
}
|
||||
if ($data{'institution_name'} eq ''){
|
||||
if ($data{'institution_name'} !~ /\S/){
|
||||
$string.="Institution Name<br>";
|
||||
$ok=1;
|
||||
}
|
||||
if ($data{'address'} eq ''){
|
||||
if ($data{'address'} !~ /\S/){
|
||||
$string.="Postal Address<br>";
|
||||
$ok=1;
|
||||
}
|
||||
if ($data{'city'} eq ''){
|
||||
if ($data{'city'} !~ /\S/){
|
||||
$string.="City<br>";
|
||||
$ok=1;
|
||||
}
|
||||
if ($data{'contactname'} eq ''){
|
||||
if ($data{'contactname'} !~ /\S/){
|
||||
$string.="Contact Name";
|
||||
$ok=1;
|
||||
}
|
||||
#print $input->Dump;
|
||||
#print $string;
|
||||
#print startmenu('member');
|
||||
|
||||
$template->param( missingloop => ($ok==1));
|
||||
$template->param( string => $string);
|
||||
if ($ok !=1) {
|
||||
my $valid=checkdigit(\%env,$data{"cardnumber_institution"});
|
||||
$template->param( invalid => ($valid !=1));
|
||||
if (valid==1){
|
||||
my @inputs;
|
||||
while (my ($key, $value) = each %data) {
|
||||
$value=~ s/\"/%22/g;
|
||||
my %line;
|
||||
$line{'key'}=$key;
|
||||
$line{'value'}=$value;
|
||||
push(@inputs, \%line);
|
||||
}
|
||||
$template->param(inputsloop => \@inputs);
|
||||
}
|
||||
}
|
||||
print "Content-Type: text/html\n\n", $template->output;
|
||||
$data{'cardnumber_institution'} = C4::Members::fixup_cardnumber
|
||||
($data{'cardnumber_institution'});
|
||||
|
||||
my $valid=checkdigit(\%env,$data{"cardnumber_institution"});
|
||||
|
||||
$template->param( invalid => ($valid !=1));
|
||||
|
||||
if ($valid) {
|
||||
my @inputs;
|
||||
while (my ($key, $value) = each %data) {
|
||||
push(@inputs, { 'key' => $key,
|
||||
'value' => CGI::escapeHTML($value) });
|
||||
}
|
||||
$template->param(inputsloop => \@inputs);
|
||||
}
|
||||
}
|
||||
output_html_with_http_headers $input, $cookie, $template->output;
|
||||
|
||||
|
||||
# Local Variables:
|
||||
# tab-width: 8
|
||||
# End:
|
||||
|
|
Loading…
Reference in a new issue