#! /usr/bin/perl # Copyright 2001-2020 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. 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 = 'rptatttch3.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"; } # Needs findDayInCycle function eval require "$configpath/lib/libschedule.pl"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } eval require "$configpath/lib/libDate.pl"; # functions to check partial day closure vals; grades field. 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 ); # Find partial day closures from dates_periods for entire year. my %pclosed; my $sth = $dbh->prepare("select * from dates_periods"); $sth->execute; if ( DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } while ( my $ref = $sth->fetchrow_hashref ) { my %r = %$ref; # date, grades, period my $cref = parseGradesPeriod( $r{date}, $dbh); %cl = %$cref; # periods closed for this date cl{grade}{period} = 1 foreach my $gr ( keys %cl ) { foreach my $per ( sort keys %{ $cl{$gr} } ) { # if we have a value. $pclosed{ $r{date} }{ $gr }{$per} = 1; } } } # we now have %pclosed{date}{grade}{period} = 1; # Test %pclosed; =head foreach my $date ( sort keys %pclosed ) { foreach my $grade ( sort keys %{ $pclosed{$date} } ) { foreach my $period ( sort keys %{ $pclosed{$date}{$grade} } ) { print qq{Date:$date Grade:$grade Period:$period
\n}; } } } =cut # 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 (Course Attendance Entry)"; print qq{$doctype\n$title $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} == 2 ) { delete $arr{page}; viewDetails(); } delete $arr{page}; #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; } # Get Courses, Teachers. my @grades; foreach my $gr ( sort {$a <=> $b} keys %g_AttendanceEntryMethod ) { if ( $g_AttendanceEntryMethod{$gr} eq 'subject' ) { push @grades, $gr; } } if ( not @grades ) { print qq{

No Grades with Course Attendance

\n}; print qq{\n}; exit; } my $select = 'where '; my $first = 1; foreach my $gr ( @grades ) { if ( not $first ) { $select .= ' or '; } $select .= "grade = '$gr'"; $first = 0; } #print qq{Select:$select
\ my $sth = $dbh->prepare("select subjsec, teacher, description from subject $select order by teacher, description"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } # Setup check for actual enrollments my $sth1 = $dbh->prepare("select count(*) from eval where subjcode = ?"); my $sth2 = $dbh->prepare("select lastname, firstname from staff where userid = ?"); print qq{\n}; print qq{\n}; while ( my ($subjsec, $userid, $desc) = $sth->fetchrow ) { # Check for Enrollments $sth1->execute( $subjsec ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my $count = $sth1->fetchrow; if ( $count < 1 ) { next; } # skip this subject; no enrollments. # Get Name $sth2->execute( $userid ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my ($lastname, $firstname) = $sth2->fetchrow; print qq{}; # Check attendance # my @res = checkCourseAttEntry( $enddate, $subjsec, $dbh ); # foreach my $res ( @res ) { print qq{ $res}; } my $res = checkCourseAttEntry( $enddate, $subjsec, \%pclosed, $dbh ); # from libAttend.pl print qq{\n}; print qq{\n}; } #---------------- sub showStartPage { #---------------- print qq{\n}; print qq{\n}; print qq{
$lex{Teacher}$lex{Course}Periods
Missed
$firstname $lastname$desc ($subjsec)$res}; print qq{
\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; 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{
So we don't search all year....
\n}; print qq{\n}; print qq{\n}; exit; } #-------------- sub viewDetails { #-------------- # foreach my $key ( sort keys %arr ) { print qq{K:$key V:$arr{$key}
\n}; } # Passed: enddate, subjsec # Load Course Info my $sth = $dbh->prepare("select * from subject where subjsec = ?"); $sth->execute( $arr{subjsec} ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my $ref = $sth->fetchrow_hashref; my %sr = %$ref; # Get Name of Teacher for this Course my $sth2 = $dbh->prepare("select lastname, firstname from staff where userid = ?"); $sth2->execute( $sr{teacher} ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my ($lastname, $firstname) = $sth2->fetchrow; print qq{

$sr{description} ($sr{subjsec}) - $firstname $lastname

\n}; # Check attendance my @res = checkCourseAttEntry( $arr{enddate}, $sr{subjsec}, \%pclosed, $dbh ); my $first = 1; my $count; foreach my $res ( sort @res ) { if ( $first ) { print qq{\n}; print qq{}; print qq{\n}; $first = 0; } $count++; my ( $date, $period ) = split(':', $res); my $dayincycle = findDayInCycle( $date ); my $dow = day_of_week( julian_day( split('-', $date))) + 1; print qq{}; print qq{\n}; } if ( $first ) { print qq{

No Records Found

\n}; } else { print qq{
$lex{Missing}
$lex{Date}
$lex{Period}Cycle Day
$count. $date ($s_dow[$dow])$period$dayincycle
\n}; } print qq{\n}; exit; }