#! /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. # Student Daily Attendance Report # Get students absent on current date (or entered date) my %lex = ('Student' => 'Student', 'Daily Attendance Report' => 'Daily Attendance Report', 'Attendance' => 'Attendance', 'Date format Error' => 'Date format Error', 'Student' => 'Student', 'Today' => 'Today', 'Weeks' => 'Weeks', 'Discipline' => 'Discipline', 'Error' => 'Error', 'Selected' => 'Selected', 'Continue' => 'Continue', 'Date' => 'Date', 'Week' => 'Week', 'Main' => 'Main', ); use DBI; use CGI; use Time::JulianDay; my $self = 'rptattstuday.pl'; # Read config variables eval require "../../etc/admin.conf"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } my @tim = localtime(time); my $year = @tim[5] + 1900; my $month = @tim[4] + 1; my $day = @tim[3]; if (length($day) == 1){ $day = '0'.$day;} if (length($month) == 1){ $month = '0'.$month;} 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 $title = qq{$lex{Student} $lex{'Daily Attendance Report'}}; print qq{$doctype\n$title\n}; print qq{\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} |\n}; print qq{ $lex{Attendance} ]\n}; print qq{

$title

\n}; my $date = $arr{date}; if ( not $date ){ $date = $currdate;} if ( length($date) < 6){ print qq{

$lex{'Date format Error'}: (yy-mm-dd)

\n}; exit; } if ( not $arr{page} ) { showStartPage(); } elsif ( $arr{page} == 1 ) { delete $arr{page}; showReport(); } #---------------- sub showStartPage { #---------------- print qq{
\n}; print qq{\n}; print qq{}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{
$lex{Attendance} $lex{Date}\n}; print qq{
\n}; print qq{
\n}; print qq{\n}; print qq{\n}; exit; } # end of showStartPage #------------- sub showReport { #------------- my $datejd = julian_day( split('-', $date)); # Get Previous Weeks my $prevjd1wk = $datejd - 7; my $prev1wk = join('-', inverse_julian_day($prevjd1wk)); my $prevjd2wk = $datejd - 14; my $prev2wk = join('-', inverse_julian_day($prevjd2wk)); my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); $dbh->{mysql_enable_utf8} = 1; # Find the kids that are away today; $sth=$dbh->prepare("select distinct attend.studentid from attend left outer join student on attend.studentid = student.studnum where absdate = ? order by student.lastname,student.firstname"); $sth->execute( $date ); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } $studary = $sth->fetchall_arrayref; print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; my $sth1 = $dbh->prepare("select lastname,firstname from studentall where studnum = ?"); my $sth2 = $dbh->prepare("select distinct reason, count(reason) from attend where absdate = ? and studentid = ? group by reason"); my $sth3 = $dbh->prepare("select distinct reason, count(reason) from attend where to_days(absdate) <= to_days('$date') and to_days(absdate) >= to_days('$prev1wk') and studentid = ? group by reason"); my $sth4 = $dbh->prepare("select distinct reason, count(reason) from attend where to_days(absdate) <= to_days('$date') and to_days(absdate) >= to_days('$prev2wk') and studentid = ? group by reason"); my $sth5 = $dbh->prepare("select e.date,e.infraction from disc_event e, disc_ident i where i.studnum = ? and i.eventid = e.id and infraction $sql{like} '%unexcused%' order by date desc"); my $sth6 = $dbh->prepare("select count(*) from studentwd where studnum = ?"); foreach my $rowary ( @$studary ) { my $studnum = $$rowary[0]; # Get Student Name $sth1->execute( $studnum ); if ($DBI::errstr){ print $DBI::errstr; die;} my ($lastname,$firstname) = $sth1->fetchrow; # Check for withdrawn my $wd; $sth6->execute( $studnum ); if ($DBI::errstr){ print $DBI::errstr; die;} my $wdcheck = $sth6->fetchrow; if ( $wdcheck ) { $wd = qq{WD}; } # Get Today's Data $sth2->execute( $date, $studnum ); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } $reasonary = $sth2->fetchall_arrayref; my $currentabs = ""; foreach my $reasonrow ( @$reasonary ) { $currentabs .= ""; } # Get 1 week prev Data $sth3->execute( $studnum ); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } $fivereasonary = $sth3->fetchall_arrayref; my $oneWeekAbs; foreach $reasonrow ( @$fivereasonary ){ $oneWeekAbs .= ""; } # Get 2 weeks prev Data $sth4->execute( $studnum ); if ($DBI::errstr){ print $DBI::errstr; die;} $tenreasonary = $sth4->fetchall_arrayref; my $twoWeekAbs; foreach my $reasonrow ( @$tenreasonary ) { $twoWeekAbs .= ""; } # Get Discipline Data $sth5->execute( $studnum ); if ($DBI::errstr){ print $DBI::errstr; die;} $discary = $sth5->fetchall_arrayref; my $discTable; foreach $infract (@$discary){ $discTable .= ""; } # print stuff print qq{\n}; print qq{\n}; } print qq{
}; print qq{$lex{Date} $lex{Selected}: $date
$lex{Student}$lex{Today}
($date)
Previous $lex{'Week'} PeriodsPrevious 2 $lex{'Weeks'} Periods$lex{Discipline}
$$reasonrow[0]$$reasonrow[1]
$$reasonrow[0]$$reasonrow[1]
$$reasonrow[0]$$reasonrow[1]
$$infract[0]$$infract[1]
$wd $lastname, $firstname ($studnum)\n}; print qq{$currentabs
$oneWeekAbs
$twoWeekAbs
$discTable
\n}; exit; } # end of showReport