#!/usr/bin/perl
# Copyright 2001-2020 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 = ('School Enrollment' => 'School Enrollment',
'Main' => 'Main',
'Enrollment' => 'Enrollment',
'Current Date' => 'Current Date',
'Aging Date' => 'Aging Date',
'Current Enrollment' => 'Current Enrollment',
'Student' => 'Student',
'Grade' => 'Grade',
'Date' => 'Date',
'Type' => 'Type',
'Description' => 'Description',
'Enrolled' => 'Enrolled',
'Not Found' => 'Not Found',
'Error' => 'Error',
'Continue' => 'Continue',
);
use DBI;
use CGI;
my $self = 'rptenroldate.pl';
eval require "../etc/admin.conf";
if ( $@ ) {
print $lex{Error}. ": $@ \n";
die $lex{Error}. ": $@\n";
}
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday,
$iddst) = localtime(time);
$year = $year + 1900;
$mon++;
$wday++;
#my $currsdate = "$year-$mon-$mday";
my $currdate = "$dow[$wday], $month[$mon] $mday, $year";
my $q = new CGI;
print $q->header( -charset, $charset );
my %arr = $q->Vars;
my $title = "$lex{Enrollment} at $lex{Date}";
print qq{$doctype\n
\n};
if ( not $arr{page} ) {
showStartPage();
}
#foreach my $key ( sort keys %arr ) { print qq{K:$key V:$arr{$key} \n}; }
my $date = $arr{date};
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
$dbh->{mysql_enable_utf8} = 1;
# First count how many currently enrolled (in student table)
my %enrollments;
my $sth = $dbh->prepare("select distinct grade, count(grade) from student
where grade is not NULL and grade != '' group by grade");
if ($DBI::errstr) {print $DBI::errstr; die $DBI::errstr; }
$sth->execute;
if ($DBI::errstr) {print $DBI::errstr; die $DBI::errstr; }
while ( my ($grade, $gcount) = $sth->fetchrow ) {
$enrollments{$grade} = $gcount;
}
print qq{
Current $lex{Enrollment}
\n};
print qq{
\n};
print qq{
$lex{Grade}
$lex{Enrollment}
\n};
my $enroltotal;
foreach my $grade ( sort {$a <=> $b} keys %enrollments ) {
print qq{
\n};
my %currenrol = %enrollments;
# Now count backwards through entry records until we reach date of interest
my $sth1 = $dbh->prepare("select * from transfer where to_days(date) >= to_days('$date')
order by date desc");
$sth1->execute;
if ($DBI::errstr) {print $DBI::errstr; die $DBI::errstr; }
# Setup query to get grade
my $sth2 = $dbh->prepare("select lastname, firstname, grade from studentall where studnum = ?");
while ( my $ref = $sth1->fetchrow_hashref ) {
my %tr = %$ref;
# Find student grade
$sth2->execute( $tr{studnum} );
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
my ($ln, $fn, $grade) = $sth2->fetchrow;
if ( not $grade ) {
print qq{