[Koha-cvs] CVS: koha memberentry.pl,1.22,1.23 newimember.pl,1.4,1.5

Ambrose Li acli at users.sourceforge.net
Mon Feb 10 08:14:19 CET 2003


Update of /cvsroot/koha/koha
In directory sc8-pr-cvs1:/tmp/cvs-serv17906

Modified Files:
	memberentry.pl newimember.pl 
Log Message:
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


Index: memberentry.pl
===================================================================
RCS file: /cvsroot/koha/koha/memberentry.pl,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** memberentry.pl	6 Feb 2003 06:39:02 -0000	1.22
--- memberentry.pl	10 Feb 2003 07:14:16 -0000	1.23
***************
*** 1,3 ****
--- 1,5 ----
  #!/usr/bin/perl
+ # NOTE: This file uses standard 8-space tabs
+ #       DO NOT SET TAB SIZE TO 4
  
  # $Id$
***************
*** 31,34 ****
--- 33,37 ----
  use CGI;
  use C4::Search;
+ use C4::Members;
  use C4::Koha;
  use HTML::Template;
***************
*** 70,117 ****
    }
  
!   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'};
!   }
  
    if ($data->{'sex'} eq 'F'){
--- 73,77 ----
    }
  
!   my $cardnumber=C4::Members::fixup_cardnumber($data->{'cardnumber'});
  
    if ($data->{'sex'} eq 'F'){
***************
*** 247,248 ****
--- 207,212 ----
  
  }
+ 
+ # Local Variables:
+ # tab-width: 8
+ # End:

Index: newimember.pl
===================================================================
RCS file: /cvsroot/koha/koha/newimember.pl,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** newimember.pl	16 Dec 2002 00:26:18 -0000	1.4
--- newimember.pl	10 Feb 2003 07:14:17 -0000	1.5
***************
*** 1,11 ****
  #!/usr/bin/perl
  
  # $Id$
  
! #script to print confirmation screen, then if accepted calls itself to insert data
  #modified 2002/12/16 by hdl at ifrance.com : Templating
  
  
! # Copyright 2000-2002 Katipo Communications
  #
  # This file is part of Koha.
--- 1,14 ----
  #!/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
  #modified 2002/12/16 by hdl at ifrance.com : Templating
+ #the "parent" is imemberentry.pl
  
  
! # Copyright 2000-2003 Katipo Communications
  #
  # This file is part of Koha.
***************
*** 27,30 ****
--- 30,36 ----
  use C4::Output;
  use C4::Input;
+ use C4::Auth;
+ use C4::Interface::CGI::Output;
+ use C4::Members;
  use CGI;
  use Date::Manip;
***************
*** 37,41 ****
  my $insert=$input->param('insert');
  
! my $template=gettemplate("newimember.tmpl");
  #get rest of data
  my %data;
--- 43,55 ----
  my $insert=$input->param('insert');
  
! 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;
***************
*** 44,92 ****
    $data{$key}=$input->param($key);
  }
  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 ''){
    $string.="Cardnumber<br>";
    $ok=1;
  }
! if ($data{'institution_name'} eq ''){
    $string.="Institution Name<br>";
    $ok=1;
  }
! if ($data{'address'} eq ''){
    $string.="Postal Address<br>";
    $ok=1;
  }
! if ($data{'city'} eq ''){
    $string.="City<br>";
    $ok=1;
  }
! if ($data{'contactname'} eq ''){
    $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;
  
--- 58,111 ----
    $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'} !~ /\S/){
    $string.="Cardnumber<br>";
    $ok=1;
  }
! if ($data{'institution_name'} !~ /\S/){
    $string.="Institution Name<br>";
    $ok=1;
  }
! if ($data{'address'} !~ /\S/){
    $string.="Postal Address<br>";
    $ok=1;
  }
! if ($data{'city'} !~ /\S/){
    $string.="City<br>";
    $ok=1;
  }
! if ($data{'contactname'} !~ /\S/){
    $string.="Contact Name";
    $ok=1;
  }
  
  $template->param( missingloop => ($ok==1));
  $template->param( string => $string);
  if ($ok !=1) {
!     $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:





More information about the Koha-cvs mailing list