#!/usr/bin/perl # Copyright 2001-2010 Leslie Richardson # This file is part of Open Admin for Schools. # Open Admin for Schools 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. my %lex = ('Track Report' => 'Track Report', 'Main' => 'Main', 'Date format Error' => 'Date format Error', 'Aging Date' => 'Aging Date', 'Name' => 'Name', 'Birthdate' => 'Birthdate', 'Sex' => 'Sex', 'House' => 'House', 'Homeroom' => 'Homeroom', 'Month' => 'Month', 'Day' => 'Day', 'Age' => 'Age', 'Error' => 'Error', 'Continue' => 'Continue', 'Blank=Today' => 'Blank=Today', ); use DBI; use CGI; eval require "../etc/admin.conf"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } # Get Date my @tim = localtime(time); my $year = @tim[5] + 1900; my $month = @tim[4] + 1; if (length($month) == 1) { $month = '0'.$month; } my $day = @tim[3]; if (length($day) == 1) { $day = '0'.$day; } my $currdate = "$year-$month-$day"; my $currdate1 = "@month[$month] $day, $year"; my $q = new CGI; my %arr = $q->Vars; print $q->header( -charset, $charset ); print "$doctype\n". $lex{'Track Report'}. " $chartype\n[ ". $lex{Main}. " ]\n"; if ( not $arr{page} ) { showStartPage(); } else { delete $arr{page}; } my $agingdate; if ($arr{agingdate}){ $agingdate = $arr{agingdate}; if (length($agingdate) == 10) { # ie. is: YYYY-MM-DD format (my $yr,$mo,$da) = split /-/,$agingdate; if (length($mo) == 1) { $mo = '0'.$mo; } if (length($da) == 1) { $da = '0'.$da; } if (length($yr) == 2) { $yr = '20'.$yr; } $agingdate = "$yr-$mo-$da"; $splitdate = $mo.$da; } else { # Date format error! print $lex{'Date format Error'}. "!
\n"; print "\n"; exit; } } else { # Blank value, use today, set above... along with $month,$day. $agingdate = $currdate; $splitdate = $month.$day; } my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); $dbh->{mysql_enable_utf8} = 1; $sth = $dbh->prepare("select lastname, firstname, initial, grade, homeroom, sex, birthdate, house from student order by birthdate"); $sth->execute; if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr;} $rows = $sth->rows; print "

". $lex{'Track Report'}. "

$currdate

\n"; print '

'. $lex{'Aging Date'}. ": $agingdate Split Date: $splitdate

\n"; my $first = 1; my ($prevmonthday, $currmonthday); while (my ($lastname, $firstname, $initial, $grade, $homeroom, $sex, $birthdate, $house) = $sth->fetchrow) { my ($yr,$mon,$day) = split /-/, $birthdate; my $student = "$sex$lastname$firstname:$lastname, $firstname $initial:$birthdate:$sex:$house:$homeroom"; $prevmonthday = $currmonthday; $prevyear = $curryear; $currmonthday = $mon.$day; $curryear = $yr; if ($first) { # for setup... loop after getting @rec started and dates set. $first = 0; push @rec, $student; next; } #print "P:$prevmonthday S:$splitdate C:$currmonthday PY:$prevyear CY:$curryear
\n"; if (($prevmonthday <= $splitdate and $currmonthday > $splitdate and $curryear == $prevyear) or ( $currmonthday > $splitdate and $curryear > $prevyear) or ( $prevmonthday <= $splitdate and $curryear > $prevyear) ) { prRec(@rec); # print the table of this age group. @rec = (); } # End of Loop for printing push @rec, $student; # whether it is zeroed by func above. } # End of loop counter prRec(@rec); print "\n"; ########## Functions ################## #-------- sub prRec { # print the records in @rec array #-------- my @rec = @_; ($blank,$name,$bday,$sex,$house,$homeroom) = split /:/, @rec[0]; ($yr,$mon,$day) = split /-/, $bday; my $age = &calcAge($bday,$agingdate); ($ageyear,$agemonth) = split /:/,$age; $ageyear = $ageyear." Year Olds"; print "\n"; print "\n"; print '\n"; print '\n"; print '\n"; my @sortedrec = sort @rec; foreach my $arrayref (@sortedrec) { ($blank,$name,$bday,$sex,$house,$homeroom) = split /:/, $arrayref; ($yr,$mon,$day) = split /-/, $bday; my $age = &calcAge($bday,$agingdate); my ($ageyear,$agemonth) = split /:/,$age; $age = $ageyear."y ".$agemonth."m"; print "\n"; print "\n"; print "\n"; print "\n"; } print "
$ageyear
'. $lex{Name}. ''. $lex{Birthdate}. "'. $lex{Sex}. ''. $lex{House}. ''. $lex{Homeroom}. "'. $lex{Month}. ''. $lex{Day}. ''. $lex{Age}. "
$name$bday$sex$house$homeroom@month[$mon]$day$age
\n

 

\n"; } #---------- sub calcAge { #---------- # Passed (birthdate, $currdate) my $birthDate = shift; my $currentDate = shift; my ($byear,$bmonth,$bday) = split /-/,$birthDate; my ($cyear,$cmonth,$cday) = split /-/,$currentDate; my $age = $cyear - $byear; my $month = $cmonth - $bmonth; if ($cmonth < $bmonth){ $month = $month + 12; if ($cday < $bday){ $month--;} $age--; } elsif ($cmonth == $bmonth and $cday < $bday){ $age--; $month = 11; } elsif ($cmonth > $bmonth and $cday < $bday) { $month--; } return "$age:$month"; } #---------------- sub showStartPage { #---------------- print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "

". $lex{'Aging Date'}. " \n"; print " ". $lex{'Blank=Today'}; print "
\n"; print "

\n"; print "\n"; print "\n"; exit; }