#!/usr/bin/perl
# Copyright 2001-2010 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.
my %lex = ('Check Student Attendance' => 'Check Student Attendance',
'Main' => 'Main',
'Attendance' => 'Attendance',
'Attendance Check' => 'Attendance Check',
'Name' => 'Name',
'Days' => 'Days',
'HRm' => 'HRm',
'Grade' => 'Grade',
'Start' => 'Start',
'End' => 'End',
'Periods Per Day or Grade not correctly set for' =>
'Periods Per Day or Grade not correctly set for',
'Error' => 'Error',
);
use DBI;
use CGI;
# This script looks for student attendance records with a reason field
# containing "Absent Unexcused". If you change the reason types, this
# script won't work. Change the value of the variable below.
eval require "../../etc/admin.conf";
if ( $@ ) {
print $lex{Error}. ": $@
\n";
die $lex{Error}. ": $@\n";
}
my $absreason = $absentUnexcused; # comes from admin.conf
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday,
$iddst) = localtime(time);
$year = $year + 1900;
$mon++;
my $currdate = "$dow[$wday], $month[$mon] $mday, $year";
my $q = new CGI;
print $q->header( -charset, $charset );
my %arr = $q->Vars;
# Passed in days to start flagging at
my $days = $arr{days};
my ($sy,$sm,$sd) = split /-/, $arr{startdate};
my $startdate = $month[$sm]. " $sd, $sy";
my ($ey,$em,$ed) = split /-/, $arr{enddate};
my $enddate = $month[$em]. " $ed, $ey";
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
$dbh->{mysql_enable_utf8} = 1;
my $select;
if ( $arr{startdate} ) {
$select = "and to_days(attend.absdate) >= to_days('$arr{startdate}')".
" and to_days(attend.absdate) <= to_days('$arr{enddate}')";
}
my $sth = $dbh->prepare("select student.studnum, count(*) as missed,
student.firstname, student.lastname, student.homeroom,
student.grade from attend, student
where attend.studentid = student.studnum and
attend.reason = '$absreason' $select group by attend.studentid
order by missed desc, student.lastname, student.firstname");
$sth->execute;
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
my $rows = $sth->rows;
print "$doctype\n
| '. $lex{Name}. ' | '. $lex{Days}. ' | '. $lex{HRm}; print ' | '. $lex{Grade}. " |
|---|---|---|---|
| $lastname, $firstname | $absent | "; print "$homeroom | $grade |