#!/usr/bin/perl
# Copyright 2001-2021 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 = ('Main' => 'Main',
'Error' => 'Error',
'Class Reading Report' => 'Class Reading Report',
'Reading Level' => 'Reading Level',
'Name' => 'Name',
'Date' => 'Date',
'Continue' => 'Continue',
'Select' => 'Select',
'Student' => 'Student',
'Homeroom' => 'Homeroom',
'Grade' => 'Grade',
'Blank=All' => 'Blank=All',
'No Students Found' => 'No Students Found',
'Show Only Latest Test' => 'Show Only Latest Test',
'Gr' => 'Gr',
'Levels' => 'Levels',
'Score' => 'Score',
'Start Date' => 'Start Date',
'End Date' => 'End Date',
'EGr' => 'EGr',
'Students' => 'Students',
'Starting Season' => 'Starting Season',
'Ending Season' => 'Ending Season',
);
# Grade => Start:End Reading Level
my %levelExpect = ( K => '0:3', 1 => '3:16', 2 => '16:28', 3 => '28:38', 4 => '40:50',
5 => '50:60', 6 => '60:70', 7 => '70:80', 8 => '80:80' );
my %shortCategory = ( 'Oral Fluency' => 'OrFlu', 'Reading Engagement' =>'RdEg',
'Comprehension' => 'Comp', 'Printed Language Concepts' => 'pLgCcp',
'Oral Reading Fluency' => 'OrFlu');
my %seasondates = ('Spring' => {'start' => '01-01', 'end' => '03-31' },
'Summer' => {'start' => '05-15', 'end' => '06-30' },
'Fall' => {'start' => '09-01', 'end' => '10-31' }
);
use DBI;
use CGI;
use Number::Format qw(:all);
use Cwd;
use Time::JulianDay;
my $self = 'readRptClass.pl';
my @time = localtime(time);
my $year = $time[5] + 1900;
my $month = $time[4] + 1;
my $currdate = "$year-$month-$time[3]";
my $schyear = $year;
if ( $month < 7 ){ $schyear = $schyear - 1; }
my $prevyear = $schyear - 1;
my $currstartdate = "$schyear-08-01"; # Aug 1 of this school year
my $prevstartdate = "$prevyear-08-01"; # August 1 of prev year.
eval require "../../etc/admin.conf";
if ( $@ ) {
print $lex{Error}. " $self: $@ \n";
die $lex{Error}. "$self: $@\n";
}
# Get current dir so know what CSS to display and shift to teacher settings.
my $tcgiurl = 'tcgi-bin'; # not correctly set in configuration?
if ( getcwd() !~ /tcgi/ ) { # we are in cgi
$tchcss = $css;
$tchpage = $homepage;
$tchdownloaddir = $downloaddir;
$tchwebdownloaddir = $webdownloaddir;
$tcgiurl = 'cgi-bin';
}
my $q = new CGI;
print $q->header;
my %arr = $q->Vars;
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
# Page Header
my $title = qq{$lex{'Class Reading Report'} - $schoolname};
print qq{$doctype\n
$title\n};
print qq{
\n};
if ( not $arr{page} ) { # calendar popup.
print qq{\n};
print qq{\n};
print qq{\n};
print qq{\n};
}
print qq{
$chartype\n\n};
# Show Grade and Reading Levels Expected.
print qq{
\n};
print qq{[ $lex{Main} ]\n};
if ( getcwd() !~ /tcgi/ ) { # we are in cgi
print qq{[ SSP ]\n};
}
print qq{
$title
\n};
if ( not $arr{page} ) {
showStartPage();
} elsif ( $arr{page} == 1 ) {
delete $arr{page};
showReport();
}
#----------
sub fmtDate {
#----------
my ( $year, $mon, $day ) = split '-', shift;
return "$year-$s_month[$mon]-$day";
}
#----------------
sub showStartPage {
#----------------
# Get grades and homerooms
my (@homerooms, @grades );
my $sth = $dbh->prepare("select distinct homeroom from student
where homeroom is not NULL and homeroom != ''");
$sth->execute;
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
while ( my $hr = $sth->fetchrow ) {
push @homerooms, $hr;
}
@homerooms = sort {$a <=> $b} @homerooms;
# Grades
$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 $gr = $sth->fetchrow ) {
push @grades, $gr;
}
@grades = sort {$a <=> $b} @grades;
=head
# Distinct Seasons
my (@seasons, %seasons);
$sth = $dbh->prepare("select distinct season from read_test where season is not NULL");
$sth->execute;
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
my %seasons;
while ( my $season = $sth->fetchrow ) {
my ($y,$s) = split('-',$season);
if ( $s eq 'Fall' ) { $season = "$y-ZZZ"; } # fix sorting order.
$seasons{$season} = 1; # Spring, Summer or Fall
}
@seasons = sort {$b cmp $a} keys %seasons; # with 'aaa' rather than 'Spring'.
@revseasons = sort {$a cmp $b} keys %seasons; # with 'aaa' rather than 'Spring'.
=cut
# Form Start - Student Group
print qq{\n};
print qq{\n};
print qq{\n};
exit;
} # end of showStartPage
#-------------
sub showReport {
#-------------
# foreach my $key ( sort keys %arr ) { print qq{K:$key V:$arr{$key} \n}; }
# Passed: startdate, enddate, season, grade or homeroom, onlylatest(always).
# Previously I was using starting and ending season without any date ranges.
# Load the reading library containing the scoreToGrade function.
eval require "../../lib/libreading.pl";
if ( $@ ) {
print $lex{Error}. " $self: $@ \n";
die $lex{Error}. "$self: $@\n";
}
my $sdate = fmtDate( $arr{startdate} );
my $startdate = $arr{startdate};
delete $arr{startdate};
my $edate = fmtDate( $arr{enddate} );
my $enddate = $arr{enddate};
delete $arr{enddate};
if ( $arr{season} ) { # override start and end dates. Only use those dates below (no season)
# Passed "Year-Season" values; convert into dates
# Spring = 1, Summer = 2, Fall = 3
my %seasonText2Num = ('Spring' => 1, 'Summer' => 2, 'Fall' => 3 );
my %seasonNum2Text = reverse %seasonText2Num;
my ($yr,$ss) = split('-', $season );
$startdate = $seasondates{$ss}{start};
$startdate = qq{$yr-$startdate};
$enddate = $seasondates{$ss}{end};
$enddate = qq{$yr-$enddate};
}
delete $arr{season};
# remove season.
my $studtable = 'student';
if ( $arr{showwithdrawn} ) {
$studtable = 'studentall';
};
# Get Students with this season / dates (all school) subselect for homeroom/grade below
my $sth;
if ( $season ) {
$sth = $dbh->prepare("select studnum from read_test
where season = '$season' order by tdate desc");
} else {
$sth = $dbh->prepare("select studnum from read_test
where to_days(tdate) >= to_days('$startdate') and
to_days(tdate) <= to_days('$enddate') order by tdate desc");
}
$sth->execute;
if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; }
my %studtest; # students with tests in this date range (all school)
while ( my $studnum = $sth->fetchrow ) {
$studtest{$studnum} = 1;
}
# Display Dates;
print qq{