#!/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 = ('Check Days Missing' => 'Check Days Missing',
'Main' => 'Main',
'Attendance' => 'Attendance',
'Attendance Check' => 'Attendance Check',
'Name' => 'Name',
'Days' => 'Days',
'HRm' => 'HRm',
'Grade' => 'Grade',
'Start Date' => 'Start Date',
'End Date' => 'End Date',
'Periods Per Day' => 'Periods per Day',
'Error' => 'Error',
'Not Found' => 'Not Found',
'Continue' => 'Continue',
'Maximum Days Missing' => 'Maximum Days Missing',
'Reason' => 'Reason',
);
use DBI;
use CGI;
use Number::Format qw(:all);
my $self = 'rptCreditsEarned.pl';
my @grades = (10,11,12);
eval require "../../etc/admin.conf";
if ( $@ ) {
print $lex{Error}. ": $@ \n";
die $lex{Error}. ": $@\n";
}
eval require "../../lib/libattend.pl";
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++;
if ( length( $mon ) == 1 ) { $mon = '0'. $mon; }
if ( length( $mday ) == 1 ) { $mday = '0'. $mday; }
my $currdate = "$year-$mon-$mday";
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;
my $title = qq{Attendance vs Credits Earned Report\n};
print qq{$doctype\n
\n};
if ( not $arr{page} ) {
showStartPage();
} elsif ( $arr{page} == 1 ) {
delete $arr{page};
showReport();
}
#-------------
sub showReport {
#-------------
# foreach my $key ( sort keys %arr ) { print qq{K:$key V:$arr{$key} \n}; }
# passed a single start:end value
my ( $startterm, $endterm ) = split(':', $arr{terms});
print qq{
Terms $startterm - $endterm
\n};
# Passed Start and End term; verify they are in the correct
# order. then get the dates based on the track they are in. Using
# those dates, loop through each grade in turn, and get their
# enrollments and attendance values and classify into one of the
# %attendance blocks.
if ( not $startterm ) {
print qq{
Term Error
\n};
print qq{\n};
exit;
}
# Get the term dates for each grade; getTermDates is in libattend
my %termdates;
foreach my $gr ( @grades ) {
my ($ss,$se) = getTermDates($gr, $startterm );
my ($es,$ee) = getTermDates($gr, $endterm );
$termdates{$gr} = {'start' => $ss, 'end' => $ee };
}
# Get the end term date for grade 12 (should be same as 10,11)
my ($ey,$em,$ed) = split('-', $termdates{12}{end} );
# Get the Completed courses for this reporting period.
my %completed; # completed courses in this month.
my $sth = $dbh->prepare("select * from sasked_completedcourses
where year(courseenddate) = '$ey' and month(courseenddate) = '$em' order by courseenddate");
$sth->execute;
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
while ( my $ref = $sth->fetchrow_hashref ) {
my %r = %$ref;
$completed{$r{provnum}}{ $r{courseid} } = $r{creditsearned};
# print "
$r{courseenddate} - $r{provnum} - $r{courseid}
\n";
}
my $sth = $dbh->prepare("select studnum from student where grade = ?");
my %attlex = ('Absent' => 'Absent', 'Late' => 'Late');
# print qq{
\n};
# print qq{
Grade
Student-Days Enrolled
Student-Days Absent
};
# print qq{
Student-Days Present
% Present
\n};
my %attgroup; # $attgroup{grade}{group} = @studnums group is 70,50,49
foreach my $grade ( @grades ) {
# term dates
my ($startdate,$se) = getTermDates($grade, $startterm);
my ($es,$enddate) = getTermDates($grade, $endterm);
# ppd for this grade; periods per day (ppd) allows us to convert to days absent;
my $ppd = $g_ppd{$grade};
if ( not $ppd ) {
print qq{
Attendance Periods Per Day not found for grade $grade<