#! /usr/bin/perl # Copyright 2001-2019 Leslie Richardson # This file is part of Open Admin for Schools. # Based on cma Rpt1a from central site. my %lex = ('Main' => 'Main', 'Continue' => 'Continue', 'Homeroom' => 'Homeroom', 'Grade' => 'Grade', 'Select by' => 'Select by', 'Error' => 'Error', 'Sort by' => 'Sort by', 'Name' => 'Name', 'Report' => 'Report', 'OR' => 'OR', 'No Selection' => 'No Selection', 'School Year' => 'School Year', 'Select' => 'Select', 'School' => 'School', ); my $self = 'ilangLocalRpt1.pl'; my $startgrade = 2; my $endgrade = 6; use DBI; use CGI; use Cwd; use Number::Format qw(:all); eval require "../../etc/admin.conf"; if ( $@ ) { print $lex{Error}. " $@
\n"; die $lex{Error}. " $@\n"; } 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 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $iddst) = localtime(time); $year = $year + 1900; $wday++; $mon++; my $currdate = "$dow[$wday], $month[$mon] $mday, $year"; # Get current dir so know what CSS to display; if ( getcwd() =~ /tcgi/ ){ # we are in tcgi $css = $tchcss; $homepage = $tchpage; } my $title = "Indigenous Languages $lex{Report} 1"; print qq{$doctype\n$title\n}; print qq{\n}; print qq{$chartype\n\n}; print qq{
[ $lex{Main} ]
\n}; print qq{

$title

\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}; } my ($totprecount, $totpostcount, $totpresum, $totpostsum); foreach my $grade ( $startgrade..$endgrade ) { # defined at top of script. my ($gprecount, $gpostcount, $gpresum, $gpostsum); $sth = $dbh->prepare("select lastname, firstname, studnum from student where grade = ? order by lastname, firstname"); $sth->execute( $grade ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my %data; # holds all data $data{studnum}{month}{prepost} = score; my @students; # provides order of students my %scoremonth; # lists the scoremonth values my %names; # store student names; my %tdates; # store test dates for scoremonth and pre/post $tdates{scoremonth}{pretest/posttest}; while ( my $ref = $sth->fetchrow_hashref ) { my %r = %$ref; my $studnum = $r{studnum}; push @students, $studnum; $names{$r{studnum}} = "$r{lastname}, $r{firstname}"; # Get this student's data my $sth1 = $dbh->prepare("select prepost, scoremonth, score, tdate from cree_scores where schoolyear = ? and studnum = ? order by tdate"); $sth1->execute( $arr{schoolyear}, $studnum ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } while ( my ($prepost, $scoremonth, $score, $tdate) = $sth1->fetchrow ) { $scoremonth{$scoremonth} = 1; $data{$studnum}{$scoremonth}{$prepost} = $score; $tdates{$scoremonth}{$prepost} = $tdate; } } if ( not %data ) { print qq{
No Data Found - Grade $grade
\n}; next; # grade } # print the data structure as a table; print qq{\n}; print qq{\n}; # header section. print qq{}; my $colcount; foreach my $scoremonth ( sort {$a <=> $b} keys %scoremonth ) { my $predate = $tdates{$scoremonth}{'pretest'}; my $postdate = $tdates{$scoremonth}{'posttest'}; print qq{}; $colcount++; } print qq{\n}; $colcount++; # due to name column print qq{\n}; foreach my $studnum ( @students ) { print qq{\n}; my ($precount, $postcount, $presum, $postsum); foreach my $scoremonth ( sort {$a <=> $b} keys %scoremonth ) { my $pretest = $data{$studnum}{$scoremonth}{'pretest'}; my $posttest = $data{$studnum}{$scoremonth}{'posttest'}; if ( $pretest ) { $precount++; $presum += $pretest; $gprecount++; $gpresum += $pretest; $totprecount++; $totpresum += $pretest; } if ( $posttest ) { $postcount++; $postsum += $posttest; $gpostcount++; $gpostsum += $posttest; $totpostcount++; $totpostsum += $posttest; } # Check for Exceptions if ( not $pretest ) { # Get Date of test to match against ssp_exceptions entry my $tdate = $tdates{$scoremonth}{'pretest'}; my $sth2 = $dbh->prepare("select * from ssp_exceptions where ssptype = 'cree' and tdate = ? and studnum = ?"); $sth2->execute($tdate, $studnum); my $ref = $sth2->fetchrow_hashref; if ( not $ref ) { $pretest = qq{M}; } else { # display the exception $pretest = qq{E}; } } if ( not $posttest ) { # Get Date of test to match against ssp_exceptions entry my $tdate = $tdates{$scoremonth}{'posttest'}; my $sth2 = $dbh->prepare("select * from ssp_exceptions where ssptype = 'cree' and tdate = ?"); $sth2->execute($tdate); my $ref = $sth2->fetchrow_hashref; if ( not $ref ) { $posttest = qq{M}; } else { # display the exception $posttest = qq{E}; } } print qq{}; } my ($preavg, $postavg); if ( $precount ) { $preavg = round($presum / $precount, 1); } if ( $postcount ) { $postavg = round($postsum / $postcount, 1); } if ( $preavg or $postavg ) { print qq{\n}; } else { print qq{\n}; } } # end of student loop # Do Grade Average my ($gpreavg, $gpostavg); if ( $gprecount ) { $gpreavg = round($gpresum / $gprecount, 1); } if ( $gpostcount ) { $gpostavg = round($gpostsum / $gpostcount, 1); } print qq{\n}; print qq{\n}; print qq{
Pretest / Posttest (Hover on Score Month to see Dates)
Grade $grade$s_month[$scoremonth]Average
$names{$studnum}$pretest/$posttest$preavg/$postavg
Grade $grade Average$gpreavg / $gpostavg
M = Missing Entry; E = Missing Entry, Exception reason added
\n}; print qq{

\n}; } #end of grade loop # Do total my ($totpreavg, $totpostavg); if ( $totprecount ) { $totpreavg = round($totpresum / $totprecount, 1); } if ( $totpostcount ) { $totpostavg = round($totpostsum / $totpostcount, 1); } print qq{

Overall Averages $totpreavg / $totpostavg

\n}; print qq{\n}; exit; } # end of showReport #---------------- sub showStartPage { #---------------- # foreach my $key ( sort keys %arr ) { print qq{K:$key V:$arr{$key}
\n}; } my (@homerooms, @grades, @schoolyears ); =head # Get Homerooms 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; # Get 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; =cut # Get School Years $sth = $dbh->prepare("select distinct schoolyear from cree_scores"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } while ( my $yr = $sth->fetchrow ) { push @schoolyears, $yr; } @schoolyears = reverse sort @schoolyears; print qq{
\n}; print qq{\n}; print qq{\n}; =head # Select Grade print qq{}; print qq{\n}; # OR print qq{\n}; # Select Homeroom print qq{}; print qq{\n}; =cut # School Year print qq{}; print qq{\n}; print qq{\n}; print qq{
$lex{'Select by'} $lex{Grade} Blank=All
$lex{OR}
$lex{'Select by'} $lex{Homeroom}Blank=All
$lex{'School Year'}
\n}; print qq{
\n}; exit; } # end of selectStudents