#!/usr/bin/perl # Copyright 2001-2010 Leslie Richardson # This file is part of Outcomes use DBI; use CGI; use Number::Format qw(round); my $self = 'checkdemog.pl'; my %lex = ( 'Main' => 'Main', 'Error' => 'Error', 'Grade' => 'Grade', 'Homeroom' => 'Homeroom', 'Group' => 'Group', 'Separate with Spaces' => 'Separate with Spaces', 'Blank=All' => 'Blank=All', 'Continue' => 'Continue', ); eval require "../../etc/admin.conf"; if ( $@ ) { print $lex{Error}. " $@
\n"; die $lex{Error}. " $@\n"; } my $q = CGI->new; my %arr = $q->Vars; print $q->header( -charset, $charset ); my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); $dbh->{mysql_enable_utf8} = 1; my @tim = localtime(time); my $year = $tim[5] + 1900; $tim[4]++; for (0..4){if (length($tim[$_]) == 1){ $tim[$_] = '0'.$tim[$_];}} my $currdate = "$year-$tim[4]-$tim[3]"; my $currtime = "$tim[2]:$tim[1]:$tim[0]"; print "$doctype\nCheck Demographics Data\n"; print "$chartype\n"; print "[ Report Card |\n"; print "Export ]\n"; print "

Check Demographics Data

\n"; #if ( not $arr{page} ) { # showStartPage(); #} elsif ( $arr{page} == 1 ) { # delete $arr{page}; checkStudents(); #} #---------------- sub showStartPage { #---------------- # Setup the form and start of table. print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
". $lex{Group}. "\n"; print "\n"; print "
". $lex{Values}. "\n"; print "
\n"; print $lex{'Separate with Spaces'}. q{, }. $lex{'Blank=All'}. "
"; print ""; print "
\n"; print "\n"; exit; } #----------------- sub checkStudents { #----------------- #foreach my $key ( keys %arr ) { print "K:$key V:$arr{$key}
\n"; } # print "
\n"; # print "\n"; # print "
\n"; my $sth = $dbh->prepare("select lastname, firstname, studnum, provnum, birthdate, grade, healthid, sex, address1, prov1, pcode1 from student order by lastname, firstname"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr;} my $rows = $sth->rows; print "\n"; print "\n"; while ( my ( $lastname, $firstname, $studnum, $provnum, $birthdate, $grade, $healthid, $sex, $address1, $prov1, $pcode1 ) = $sth->fetchrow ) { # Check Provincial Number if ( $provnum ) { my $temppn = $provnum; my $tempcd = chop( $temppn ); my $checkdigit = &checkprovnum( $temppn ); if ( $checkdigit != $tempcd ) { print "\n"; #print ""; print "\n"; } } # Check Health Number $healthid =~ s/ //g; # strip spaces if ( checkHealthId( $healthid ) ) { print ""; print" \n"; } # else { # print ""; # print" \n"; # } # Check Gender Values ( M or F) and fix if necessary if ( $sex ) { # Check Gender if ( $sex ne 'M' and $sex ne 'F' ) { # Error if ( $sex eq 'm' or 'f' ) { #fix case. $sex = uc( $sex ); my $sth1 = $dbh->prepare("update student set sex = ? where studnum = ?"); # $sth1->execute( $sex, $studnum ); if ($DBI::errstr) { print $DBI::errstr; die;} } else { # not fixable. print ""; print" \n"; } } } else { print ""; print" \n"; } # Get and Check the Grade if ( $grade eq 'k' or $grade eq 'pk' or $grade eq 'p3' ) { $grade = uc( $grade ); my $sth1 = $dbh->prepare("update student set grade = ? where studnum = ?"); # $sth1->execute( $grade, $studnum ); if ($DBI::errstr) { print $DBI::errstr; die;} } else { # Do more checking. my @gradelist = qw(K PK K3 1 2 3 4 5 6 7 8 9 10 11 12 ); my $pass = 0; foreach my $gr ( @gradelist ) { if ( $grade eq $gr ) { $pass = 1; last; } } if ( not $pass ) { print ""; print" \n"; } } # Get Address Info; returns an address hash. # foreach my $key ( sort keys %sr ) { print "K:$key V:$sr{$key}
\n"; } # Check Address, Province, Postal Code. if ( not $address1 ) { print ""; print" \n"; } # Check Postal Code if ( not $pcode1 ) { print ""; print" \n"; } else { # Test the code my $testpc = $pcode1; if ( !( $testpc =~ m/^\s*([a-z]\s*\d){3}\s*$/i ) ) { # failure! print ""; print" \n"; } } # Check Province (and fix, if possible) my $fail = 0; if ( not $prov1 ) { print ""; print" \n"; } else { # test for case problems and also 'Sask' variant. my $testprov = $prov1; if ( uc($testprov) ne $prov1 ) { # we have a case error. $prov1 = uc( $testprov ); $fail = 1; } elsif ( lc( $testprov ) eq 'sask' ) { $prov1 eq 'SK'; $fail = 1; } if ( $fail ) { # rewrite update my $sth1 = $dbh->prepare("update student set prov1 = ? where studnum = ?"); # $sth1->execute( $prov1, $studentid ); if ($DBI::errstr) { print $DBI::errstr; die;} } } } # End of Student Loop print "\n"; exit; } # end of selectStudents #---------------------- # Lower Level Functions #---------------------- #---------------- sub checkprovnum { #---------------- my @pn = split(//,$_[0]); for ( my $i=1; $i<=8; $i += 2) { $pn[$i] *= 2; if ($pn[$i] > 9) { my @tmp = split(//,$pn[$i]); $pn[$i] = $tmp[0] + $tmp[1]; } } my $tempnum = 0; foreach my $pnum (@pn) { $tempnum += $pnum; } @pn = split(//,$tempnum); my $retval= pop(@pn); $retval = 9 - $retval; return $retval; } #---------------- sub checkHealthId { #---------------- my $hn = shift; my @hn = split(//,$hn); my ($i, $total); foreach my $num (reverse @hn){ $i++; $num *= $i; $total += $num; } my $remainder = $total % 11; # should be zero, if correct. return $remainder; }
ErrorName
Parity Error[ Edit]\n"; print "$lastname, $firstname"; print "($studnum/$birthdate) - Prov #: $provnum
Parity Error$lastname, $firstname"; print "($studnum) - HSN#: $healthid
No Health Services Number$lastname, $firstname ($studnum)
Gender Error$lastname, $firstname ($studnum) - Gender:$sex
Missing Gender$lastname, $firstname ($studnum)
Grade Error$lastname, $firstname ($studnum) - Grade:$grade
Missing Address$lastname, $firstname ($studnum)
Missing Postal Code$lastname, $firstname ($studnum)
Invalid Postal Code - $testpc$lastname, $firstname ($studnum)
Missing Province Code$lastname, $firstname ($studnum)