#! /usr/bin/perl # Copyright 2001-2019 Leslie Richardson # 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. # Check for any missing homeroom attendance up to end date. my %lex = ('Attendance Report' => 'Attendance Report', 'Main' => 'Main', 'Attendance' => 'Attendance', 'Periods Per Day' => 'Periods Per Day', 'View/Download' => 'View/Download', 'View Log File' => 'View Log File', 'Last Name' => 'Last Name', 'First' => 'First', 'Middle' => 'Middle', 'Birthdate' => 'Birthdate', 'Status' => 'Status', 'Reserve' => 'Reserve', 'Mother' => 'Mother', 'School Days' => 'School Days', 'Error' => 'Error', 'Date' => 'Date', 'Paper Size' => 'Paper Size', 'Letter' => 'Letter', 'Legal' => 'Legal', 'A4' => 'A4', 'Continue' => 'Continue', 'Records per Page' => 'Records per Page', 'Not Defined' => 'Not Defined', 'Grade' => 'Grade', 'Student' => 'Student', 'Not Found' => 'Not Found', 'Band' => 'Band', 'Font Size' => 'Font Size', 'Group' => 'Group', 'HTML' => 'HTML', 'Homeroom' => 'Homeroom', 'PDF' => 'PDF', 'Separate with Spaces' => 'Separate with Spaces', 'Report Type' => 'Report Type', 'Year End' => 'Year End', 'Total' => 'Total', 'Percent' => 'Percent', 'Days' => 'Days', 'Enrolled' => 'Enrolled', 'Show Withdrawn Students' => 'Show Withdrawn Students', 'End Date' => 'End Date', 'Missing' => 'Missing', 'Teacher' => 'Teacher', 'Course' => 'Course', 'View' => 'View', 'Details' => 'Details', 'Period' => 'Period', ); use DBI; use CGI; use Number::Format qw(:all); use Time::JulianDay; use Cwd; # Constants my $self = 'rptatttch2.pl'; # Get current dir so know what path for config files. my $configpath; my $teachermode; if ( getcwd() =~ /tcgi/ ){ # we are in tcgi $teachermode = 1; $configpath = '..'; # go back one to get to etc. } else { $configpath = '../..'; # go back two to get to etc. } # main config file eval require "$configpath/etc/admin.conf"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } eval require "$configpath/lib/libattend.pl"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } #eval require "$configpath/lib/liblatex.pl"; #if ( $@ ) { # print $lex{Error}. ": $@
\n"; # die $lex{Error}. ": $@\n"; #} my $dsn = "DBI:mysql:$dbase"; $dbh = DBI->connect($dsn,$user,$password); $dbh->{mysql_enable_utf8} = 1; my @tim = localtime(time); my $year = $tim[5] + 1900; my $month = $tim[4] + 1; my $day = $tim[3]; if (length($month) == 1){ $month = "0".$month;} if (length($day) == 1){ $day = "0".$day;} my $currsdate = "$year-$month-$day"; my $currdate = "$month[$month] $day, $year"; my $q = new CGI; my %arr = $q->Vars; print $q->header( -charset, $charset ); # Get current dir so know what CSS to display and shift to teacher settings. if ( getcwd() =~ /tcgi/ ) { # we are in tcgi $css = $tchcss; $homepage = $tchpage; $downloaddir = $tchdownloaddir; $webdownloaddir = $tchwebdownloaddir; } # HTML Header my $title = "$lex{Teacher} $lex{'Attendance Report'} 2 (Homeroom Attendance Check)"; print qq{$doctype\n$title \n}; if ( not $arr{page} ) { print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; } print qq{$chartype\n\n}; print qq{[ $lex{Main} }; if (not $teachermode ) { print qq{| $lex{Attendance} ]\n}; } else { print qq{]\n}; } print qq{

$title

\n}; if ( not $arr{page} ) { showStartPage(); } elsif ( $arr{page} == 1 ) { delete $arr{page}; showReport(); } elsif ( $arr{page} == 2 ) { delete $arr{page}; viewDetails(); } #------------ sub showReport { #------------- # foreach my $key ( sort keys %arr ) { print qq{K:$key V:$arr{$key}
\n}; } my $enddate; if ($arr{enddate}){ $enddate = $arr{enddate}; } else { $enddate = $currsdate; } print qq{

$lex{'End Date'} $enddate

\n}; # Get Homerooms my $sth = $dbh->prepare("select distinct homeroom from student where homeroom != '' and homeroom is not NULL order by homeroom"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my @homerooms; # Homeroom teacher for a particular homeroom value my $sth1 = $dbh->prepare("select userid from staff_multi where field_name = 'homeroom' and field_value = ?"); # Get grade(s) for particular homeroom my $sth2 = $dbh->prepare("select distinct grade from student where homeroom = ?"); HOMEROOM: while ( my $hr = $sth->fetchrow ) { # Do we have a teacher for this homeroom? $sth1->execute( $hr ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my $userid = $sth1->fetchrow; if ( not $userid ) { print qq{
$lex{Missing} $lex{Teacher} - $lex{Homeroom} $hr
\n}; next HOMEROOM; } # Get Grade(s) of homeroom and check that they use 'homeroom' attendance entry method $sth2->execute( $hr ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } while ( my $gr = $sth2->fetchrow ) { if ( $g_AttendanceEntryMethod{$gr} ne 'homeroom' ) { print qq{
$lex{Error} Homeroom $hr (grade $gr) not marked for homeroom attendance.
\n}; next HOMEROOM; } } push @homerooms, $hr; } # end of homeroom loop # Setup: Get Teacher Name $sth2 = $dbh->prepare("select lastname, firstname from staff where userid = ?"); # Start a table. print qq{\n}; print qq{\n}; # Loop Through All homerooms, checking attendance foreach my $homeroom ( sort {$a <=> $b} @homerooms ) { # Get Homeroom Teacher my $sth1 = $dbh->prepare("select userid from staff_multi where field_name = 'homeroom' and field_value = ?"); $sth1->execute( $homeroom ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my $userid = $sth1->fetchrow; # print qq{Homeroom:$homeroom Userid:$userid
\n}; # Get Teacher Name $sth2->execute( $userid ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my ($lastname, $firstname) = $sth2->fetchrow; print qq{\n}; # Check that Teacher attendance was done up to this date. my $res = checkAttEntry( $enddate, $homeroom ); print qq{\n}; print qq{\n}; print qq{\n}; } print qq{
$lex{Teacher}$lex{Homeroom}$lex{Missing}
$firstname $lastname$homeroom$res
\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{
\n}; print qq{\n}; exit; } # end of showReport #---------------- sub showStartPage { # get End Date for Checking. #---------------- print qq{
\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{
$lex{'End Date'}\n}; print qq{\n}; print qq{
\n}; print qq{\n}; print qq{\n}; exit; } #-------------- sub viewDetails { #-------------- # foreach my $key ( sort keys %arr ) { print qq{K:$key V:$arr{$key}
\n}; } my $userid = $arr{userid}; # Get Name my $sth = $dbh->prepare("select lastname, firstname from staff where userid = ?"); $sth->execute( $userid ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my ($lastname, $firstname) = $sth->fetchrow; print qq{

$lex{Homeroom} $arr{homeroom} - $firstname $lastname

\n}; # Check that Teacher attendance was done up to this date. my @res = checkAttEntry( $arr{enddate}, $arr{homeroom} ); print qq{

Missing Teacher Attendance

\n}; foreach my $r ( @res ) { print qq{
$r
\n}; } print qq{\n}; exit; } #---------------- sub checkAttEntry { # check attendance entry for all year to date. #---------------- my ($enddate, $homeroom) = @_; # passed end date to stop at, and homeroom my $startdate = $schoolstart; my $startjd = julian_day( split('-', $startdate )); my $endjd = julian_day( split('-', $enddate )); # Get Grade for this homeroom, and set nsd flag my $nsdflag; # non school day flag for K and PK grades; my $ppd; # periods per day for attendance. my $sth1 = $dbh->prepare("select distinct grade from student where homeroom = ? and grade != '' and grade is not NULL"); $sth1->execute( $homeroom ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } while (my $grade = $sth1->fetchrow ) { my $tmp = $g_ppd{$grade}; if ( $tmp > $ppd ) { $ppd = $tmp; } if ( $grade eq 'K' or $grade eq 'PK' ) { $nsdflag = 1; } } my $sth1 = $dbh->prepare("select period from dates_nonschool where homeroom = ? and date = ?"); my $sth = $dbh->prepare("select id, dayfraction from dates where date = ?"); my @missingdates; for my $jd ( $startjd..$endjd ) { # Check if a weekend my $dow = day_of_week( $jd ); if ( $dow == 0 or $dow == 6 ) { next; } # skip weekends. # Check if school closed, school wide my $closedflag; my $date = join('-', inverse_julian_day( $jd )); $sth->execute( $date ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my ($id, $dayfraction) = $sth->fetchrow; if ( $id and $dayfraction > 0.99 ) { # school is closed; skip # print qq{
Closed School Wide All Day - $date
\n}; next; } if ( $id and $dayfraction > 0.1 ) { # school is closed; skip # print qq{
Closed School Wide - Day Fraction:$dayfraction $date
\n}; next; } my %nsdperiods; if ( $nsdflag ) { # check for closed periods here also. my $nsd_closedallday = 1; $sth1->execute( $homeroom, $date ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } while ( my $period = $sth1->fetchrow ) { $nsdperiods{$period} = 1; } if ( %nsdperiods ) { # check if closed all day by nsd records foreach my $p (1..$ppd ) { if ( not $nsdperiods{$p} ) { # print "$date - $p - flag cleared
\n"; # we don't have a closed record for this periods, so must be open; clear flag $nsd_closedallday = 0; } } if ( $nsd_closedallday ) { #closed all periods # print "
Closed K/PK all day $date
\n"; next; # date } } } # Check if attendance done by teacher (ie. nothing for that date). my @tperiods = checkHomeroomAttEntry( $date, $homeroom, $dbh ); if ( not @tperiods ) { push @missingdates, "$date - all day"; } else { # we have some missing periods in @tperiods my @missingperiods; my %r; foreach my $p ( @tperiods ) { $r{$p} = 1; } # print "Date:$date Periods:", @tperiods, "
\n"; foreach my $period ( 1..$ppd ) { if ( $r{$period} ) { # attendance done next; } if ( $nsdperiods{$period} ) { # closed next; } # otherwise push @missingperiods, $period; } if ( @missingperiods ) { $periodtext = join(',',@missingperiods); push @missingdates, "$date - $periodtext"; } } } return @missingdates; }