#! /usr/bin/perl
# Copyright 2001-2009 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.
# ======= INAC (Indian Northern Affairs Canada) Attendance Report =======
# Get End date; Generate months up to end of enddate month.
# We only print out days enrolled AND that student actually attended.
# Column Format: Grade, Lastname, First, Middlename, Birthdate, Status
# Number (Treaty Number), Reserve, Parent1 Name, then single columns
# for each month (S,O,N,D,J,F,M,A,M,J).
# Sorted by Reserve, Lastname, Firstname (1 Page per Reserve).
my %lex = ('INAC Attendance Report' => 'INAC Attendance Report',
'Main' => 'Main',
'Attendance' => 'Attendance',
'Periods Per Day not defined for Grade' => 'Periods Per Day not defined for Grade',
'in global configuration for student' => 'in global configuration for student',
'View/Download' => 'View/Download',
'View Log File' => 'View Log File',
'Undefined' => 'Undefined',
'Last Name' => 'Last Name',
'First' => 'First',
'Middle' => 'Middle',
'Birthdate' => 'Birthdate',
'Status' => 'Status',
'Reserve' => 'Reserve',
'Mother' => 'Mother',
'School Days' => 'School Days',
'Error' => 'Error',
'Absent'=> 'Absent',
'Late' => 'Late',
'Date' => 'Date',
'Paper Size' => 'Paper Size',
'Letter' => 'Letter',
'Legal' => 'Legal',
'A4' => 'A4',
'Continue' => 'Continue',
'Records per Page' => 'Records per Page',
);
my $self = 'rptinac.pl';
use DBI;
use CGI;
use Date::Business;
use Number::Format qw(:all);
# Constants
my $defmaxrecords = 28; # Maximum records per PDF page.
my $group = 'band';
my $pdf = '1';
my $html;
# Read config variables
eval require "../../etc/admin.conf";
if ( $@ ) {
print $lex{Error}. ": $@
\n";
die $lex{Error}. ": $@\n";
}
eval require "../../lib/libattend.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 );
# HTML Header
print "$doctype\n
[ ". $lex{Main}. " |
". $lex{Attendance}. " |
". $lex{'View Log File'}. " ]
\n";
# ================
# Functions
# ================
#----------------------
sub print_tex_doc_start {
#----------------------
print TEX "\\documentclass[10pt,legalpaper,oneside,landscape]{article}
\\usepackage{array,colortbl,rotating,inputenc}
$a_latex_header
\\renewcommand{\\familydefault}{\\sfdefault}
\\pagestyle{empty}
\\setlength{\\textwidth}{13in}
\\setlength{\\textheight}{7.7in}
\\setlength{\\hoffset}{-4.3in}
\\setlength{\\voffset}{-0.8in}
\\setlength{\\headsep}{10pt}
\\setlength{\\headheight}{14pt}
\\setlength{\\topmargin}{0pt}
\\setlength{\\parindent}{0pt}
\\setlength{\\tabcolsep}{5pt}
\\setlength{\\extrarowheight}{3pt}
\\pagestyle{headings}
\\markright{$schoolname - $schoolyear \\hfill
{\\bf ". $lex{'INAC Attendance Report'}. "} \\hfill $currdate -- Pg }
\n\n
\\begin{document}\n";
} # End of Print Tex Doc Start
#-------------------
sub print_tex_header {
#-------------------
# Up to 18 Cols: (8 + 10 months)
# Grade, Lastname, Firstname, Middlename, Birthdate
print TEX "\\begin{tabular}{|p{1cm}|p{3cm}|p{1.6cm}|p{2cm}|p{1.8cm}";
# Treaty, Band, Parent, Up to 10 Months.
print TEX "|p{1.7cm}|p{2.2cm}|p{3.2cm}|";
for(1..$#schoolmonths){
print TEX "p{9mm}|";
}
print TEX "}\\hline\n\n";
# Now print the column header line.
print TEX "\\rowcolor[gray]{0.90}{\\bf Grade}";
print TEX "& {\\bf ". $lex{'Last Name'}. "} & {\\bf ". $lex{First}. "} &";
print TEX "{\\bf ". $lex{Middle}. "} &{\\bf ". $lex{Birthdate}. "} &";
print TEX "{\\bf ". $lex{Status}. "\\#} &{\\bf ". $lex{Reserve}. "} & \n";
print TEX "{\\bf ". $lex{Mother}. "}";
for( 1..$#schoolmonths ) {
my ($ty,$tm) = split /-/,$schoolmonths[$_];
#$tm++;
print TEX "& {\\bf $s_month[$tm]}";
}
print TEX "\\\\ \\hline\n\n";
# Now print the schooldays in month
print TEX "\\rowcolor[gray]{0.90}";
print TEX "& & & & & & & ". $lex{'School Days'};
for(1..$#schoolmonths){
print TEX "& {\\bf $schooldays{$schoolmonths[$_]} }";
}
print TEX "\\\\ \\hline\n\n";
}
#-------------------
sub print_tex_record {
#-------------------
# Grade, Lastname, Firstname, Middlename
print TEX "\\hfil $student[5]\\hfill& $student[1] & $student[2]";
print TEX "& $student[3] ";
# Birthdate, Treaty#,
print TEX "& $student[8] & $student[17] ";
# Band Name, Mother Name
print TEX "& $student[58] & $student[29] ";
my $days = $schooldays - $absentdaytot;
#Now print Monthly Records
for (1..$#schoolmonths){
print TEX "& {\\footnotesize $absent{$_}/$enrolled{$_}}";
}
print TEX " \\\\ \\hline\n";
}
#---------------
sub doAttSetup { # Version with monthly attendance info
#---------------
# Needs globals: @schoolmonths - ordering of school months.
# %schooldays - days in each month in hash.
# $periodsperday - number of periods in the school day.
# my $studnum = shift; # make local version
undef %absent;
undef %tardy;
undef %enrolled;
# calculate attendance, one for each month.
for (1..$#schoolmonths){
$absrec = calcMonthlyAttendance( $studnum, $schoolmonths[$_], $periodsperday,
$stopdate, \%lex );
($absent{$_},$tardy{$_}) = split /:/,$absrec;
$absent{$_} = format_number( $absent{$_}, 1);
#print "Num: $_ SN:$studnum MN:$schoolmonths[$_] AB:$absent{$_}
#LT:$tardy{$_}
\n";
}
# calculate enrollment, one for each month
# First find starting value for $active... was student enrolled at start
my $sth = $dbh->prepare("select type from transfer where studnum = ?
and to_days(date) >= to_days('$schoolstart')
order by date desc");
$sth->execute( $studnum );
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr;}
my $etype = $sth->fetchrow;
my $sth1 = $dbh->prepare("select lastname, firstname from studentall
where studnum = ?");
$sth1->execute( $studnum );
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr;}
my ($lastname, $firstname) = $sth1->fetchrow;
# If withdraw during year or no record, must have been enrolled at start
if ($etype eq 'withdraw' or not $etype){ $active = 1;} else { $active = 0;}
#print "$lastname, $firstname ETYPE: $etype ACT: $active
\n";
for (1..$#schoolmonths){
my $enrolrec = &calcMonthlyEnrollment($studnum, $schoolmonths[$_],
$active);
($enrolled{$_},$active) = split /:/,$enrolrec;
#print "---SN: $studnum ACT: $active
\n";
#print "SN:$studnum Month:$schoolmonths[$_] ACT: $active
\n";
}
}
#----------------
sub showStartPage {
#----------------
print "