#! /usr/bin/perl # Copyright 2001-2022 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. use DBI; use CGI; my %lex = ('Attendance' => 'Attendance', 'Perfect Attendance' => 'Perfect Attendance', 'Report' => 'Report', 'Not Found' => 'Not Found', 'Name' => 'Name', 'Start Date' => 'Start Date', 'End Date' => 'End Date', 'Error' => 'Error', 'Grade' => 'Grade', 'Homeroom' => 'Homeroom', 'Main' => 'Main', 'Unexcused' => 'Unexcused', ); my $self = 'rptAttPerf.pl'; # Get passed date for perfect attendance (inclusive) # Read config variables eval require "../../etc/admin.conf"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } # Get Current Date my @tim = localtime(time); my $year = @tim[5] + 1900; my $month = @tim[4] + 1; my $day = @tim[3]; my $currdate = "$year-$month-$day"; my $currdate1 = "@month[$month] $day, $year"; my $q = new CGI; my %arr = $q->Vars; print $q->header( -charset, $charset ); my $startdate = $arr{startdate}; my $enddate = $arr{enddate}; my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); $dbh->{mysql_enable_utf8} = 1; # Print Page Header my $title = qq{$lex{'Perfect Attendance'} $lex{Report}}; print qq{$doctype\n$title\n}; print qq{}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{$chartype\n\n}; print qq{[ $lex{Main} | $lex{Attendance} ]\n}; print qq{

$title

\n}; if ( not $arr{page} ) { showStartPage(); } elsif ( $arr{page} == 1 ) { delete $arr{page}; showPerfect(); } #---------------- sub showStartPage { #---------------- # Get start/end dates, and reasons to skip # Start Form. print qq{
\n}; print qq{\n}; # Table and Heading print qq{\n\n}; print qq{\n}; # Start Date print qq{\n\n}; # End Dates print qq{\n\n}; my %skip; # most have the configuration of @ignore_reason wrong, so turning this OFF. foreach my $idx ( @ignore_reason ) { # from configuration my $rsn = $attend[$idx]; $skip{$rsn} = 1; } # Reasons to Skip print qq{\n}; my $sth = $dbh->prepare("select distinct reason from attend order by reason"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } while ( my $rsn = $sth->fetchrow ) { if ( $rsn =~ m/Unexcused/ ) { $skip{$rsn} = 1; } # skip this one, too. my $val = qq{R:$rsn}; my $checked; if ( $skip{$rsn} ) { $checked = qq{checked="checked"}; } print qq{\n}; } print qq{
Dates / Reasons to Skip
Start Date \n}; print qq{\n}; print qq{
End Date \n}; print qq{\n}; print qq{
Select Reasons to Skip
$rsn
\n}; print qq{
\n}; print qq{
\n}; print qq{\n}; print qq{\n}; print qq{\n}; exit; } #-------------- sub showPerfect { #-------------- # foreach my $key ( sort keys %arr ) { print "K:$key V:$arr{$key}
\n"; } if ( not $arr{sdate} or not $arr{edate} ) { print qq{

Missing Date

\n}; print qq{\n}; exit; } my $startdate = $arr{sdate}; delete $arr{sdate}; my $enddate = $arr{edate}; delete $arr{edate}; # Now only reasons to skip are left; my %skip; foreach my $key ( keys %arr ) { my ($dud,$reason) = split(':',$key); $skip{$reason} = 1; } print qq{

$lex{'Start Date'}: $startdate }; print qq{$lex{'End Date'}: $enddate\n}; my $reason_string; print qq{

Reasons ignored - \n}; foreach my $reason ( sort keys %skip ) { print qq{$reason, }; $reason_string .= "and reason != '$reason' "; } print qq{

\n}; my $first = 1; my $sth = $dbh->prepare("select lastname, firstname, studnum, grade, homeroom from student order by lastname, firstname"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my $noperfect = 1; # flag in case no perfect attendance my %studname; # studname{studnum} = "lastname, firstname"; my %students; # students{grade}{homeroom}{studnum} = 1; while ( my ($lastname, $firstname, $studnum, $grade, $homeroom ) = $sth->fetchrow ) { # Now do the query to find student numbers. $sth1 = $dbh->prepare("select count(*) from attend where studentid = ? and to_days(attend.absdate) >= to_days('$startdate') and to_days(attend.absdate) <= to_days('$enddate') $reason_string"); $sth1->execute( $studnum ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my $count = $sth1->fetchrow; if ( $count < 1) { $noperfect = 0; if (not $homeroom) { $homeroom = 'None'; } if ( not $grade) { $grade = 'Missing!'; } $students{$grade}{$homeroom}{$studnum} = 1; $studname{$studnum} = qq{$lastname, $firstname}; } } # Loop over students hash. foreach my $grade ( sort {$a <=> $b} keys %students ) { if ( not $first ) { print qq{\n}; } print qq{\n}; print qq{\n}; foreach my $hr ( sort {$a cmp $b} keys %{ $students{$grade}} ) { my %sort; foreach my $studnum ( keys %{ $students{$grade}{$hr}} ) { $sort{"$studname{$studnum}$studnum"} = $studnum; } foreach my $key ( sort keys %sort ) { my $studnum = $sort{$key}; print qq{\n}; } } print qq{
$lex{Name}$lex{Grade}$lex{Homeroom}
$studname{$studnum} / $studnum$grade$hr
\n}; } # In case of no perfect attendance... if ( $noperfect ) { print qq{$lex{'Perfect Attendance'} $lex{'Not Found'}\n}; } print qq{

[ $lex{Attendance} ]

\n}; print qq{\n}; exit; } # end of showPerfect;