#!/usr/bin/perl
# Copyright 2001-2019 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 = ('Enrollment Summary' => 'Enrollment Summary',
'Main' => 'Main',
'Room' => 'Room',
'Teacher' => 'Teacher',
'Grade' => 'Grade',
'Male' => 'Male',
'Female' => 'Female',
'Young' => 'Young',
'HRm' => 'HRm',
'Total' => 'Total',
'Gr' => 'Gr',
'Totals' => 'Totals',
'Error' => 'Error',
);
my $self = 'rptenrolhroom.pl';
use DBI;
use CGI;
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 $currdate = "$dow[$wday], $month[$mon] $mday, $year";
my $q = new CGI;
print $q->header( -charset, $charset );
my %arr = $q->Vars;
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
$dbh->{mysql_enable_utf8} = 1;
# Get the Grades
my %grades = ();
my $sth = $dbh->prepare("select distinct grade from student
where grade is not NULL and grade != ''");
$sth->execute;
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
while ( my $grade = $sth->fetchrow ) {
$grades{$grade} = 1;
}
my @grades = ( sort { $a <=> $b } keys %grades );
# foreach my $gr ( @grades ) { print "G:$gr \n"; }
$sth = $dbh->prepare("select homeroom, grade, sex, youngest from student where grade = ?
order by homeroom, lastname,firstname");
print qq{$doctype\n
\n};
my $youngest = 0;
my $youngtot = 0;
my $boytotal = 0;
my $girltotal = 0;
my $boycount = 0;
my $girlcount = 0;
my $boygrade = 0;
my $girlgrade = 0;
my $curroom = -1; $currgrade = -1;
my $first = 1;
foreach my $grade ( @grades ) {
$sth->execute( $grade );
if ($DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; }
while ( my ( $hroom, $gr, $sex, $young ) = $sth->fetchrow ) {
$oldroom = $curroom;
$oldgrade = $currgrade;
$curroom = $hroom;
$currgrade = $gr;
if (($oldroom ne $curroom and not $first ) or
( $oldroom eq $curroom and $oldgrade ne $currgrade and not $first )) {
# we have a new room (or same room but different grade)
$hrtotal = $boycount + $girlcount;
my ($sal, $firstname, $lastname, @teachers, $teachername);
if ( $oldroom ){ # If oldroom present, find it's teacher.
my $sth1 = $dbh->prepare("select sal, firstname, lastname
from staff as s, staff_multi as sm
where s.userid = sm.userid and sm.field_name = ? and sm.field_value = ?");
$sth1->execute('homeroom', $oldroom );
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
while ( ($sal, $firstname, $lastname) = $sth1->fetchrow ) {
push @teachers, "$sal $firstname $lastname";
}
$teachername = join(' ', @teachers);
}
# Print out teacher name, totals for this room and then reset the variables.
print qq{
$oldroom - $teachername
$oldgrade
$boycount
\n};
print qq{
$girlcount
$youngest
$hrtotal
\n};
$girlcount = 0;
$boycount = 0;
$youngest = 0;
}
if ( $oldgrade ne $currgrade and not $first ) { # we have a new grade also
$grtotal = $boygrade + $girlgrade;
print qq{
$oldgrade
\n};
print qq{
$boygrade
$girlgrade
\n};
print qq{
$grtotal
\n};
$girlgrade = 0;
$boygrade = 0;
}
$first = 0;
if ( "\U$sex" eq "F") {
$girlcount++;
$girltotal++;
$girlgrade++;
} else {
$boycount++;
$boytotal++;
$boygrade++;
}
if ( $young ) { # if has any value.
$youngest++;
$youngtot++;
}
} # End of Main Loop
}
my $total = $boycount + $girlcount;
if ( $curroom ) {
my (@teachers, $teachername);
my $sth1 = $dbh->prepare("select sal, firstname, lastname
from staff as s, staff_multi as sm
where s.userid = sm.userid and sm.field_name = ? and sm.field_value = ?");
$sth1->execute( 'homeroom', $curroom );
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
# my ($sal, $firstname, $lastname) = $sth1->fetchrow;
while ( my ($sal, $firstname, $lastname) = $sth1->fetchrow ) {
push @teachers, "$sal $firstname $lastname";
}
$teachername = join(' ', @teachers);
print qq{
$curroom - $teachername
\n};
print qq{
$currgrade
$boycount
\n};
print qq{
$girlcount
$youngest
$total
\n};
}
my $grtotal = $boygrade + $girlgrade;
print qq{
$currgrade
$boygrade
\n};
print qq{
$girlgrade
$grtotal
\n};
my $grandtotal = $boytotal + $girltotal;
print qq{