\n};
if ( not $arr{page} ) {
showStartPage();
} else {
delete $arr{page};
}
my $enddate;
if ($arr{date}){
$enddate = $arr{date};
} else {
$enddate = $currsdate;
}
my $startdate = $schoolstart;
# Function from LibAttend
my %schooldays = mkSchoolDays( $startdate, $enddate, $dbh );
# returns hash of schooldays in month. key is yyyy-mm and value is schooldays in month
if ( not $arr{homeroom} ) {
print qq{
$lex{Missing} $lex{Homeroom}
\n};
print qq{\n};
exit;
}
my $table = 'student';
if ( $arr{showwithdrawn} ) {
$table = 'studentall';
}
my $select = qq{where homeroom = ?};
my $sth = $dbh->prepare("select * from $table $select order by lastname, firstname");
$sth->execute( $arr{homeroom} );
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
my $studrows = $sth->rows;
# Get Homeroom Teacher Name
my $sth1 = $dbh->prepare("select userid from staff_multi
where field_name = 'homeroom' and field_value = ?");
$sth1->execute( $arr{homeroom} );
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
my $userid = $sth1->fetchrow;
$sth1 = $dbh->prepare("select lastname, firstname from staff where userid = ?");
$sth1->execute( $userid );
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
my ($lastname, $firstname) = $sth1->fetchrow;
# Check that Teacher attendance was done up to this date.
checkAttEntry( $enddate, $arr{homeroom} );
# Open TEX file, and print Header
if ( $pdf ) {
$logfile = "pdflog$$.txt";
$shortname = "rptattyear2-$$";
$filename = "$shortname.tex";
open(TEX,">$filename") || die "Can't open tex file";
print_tex_doc_start(); # Setup the start of the file.
}
# Setup statements
my $sth5 = $dbh->prepare("select count(*) from student where studnum = ?");
my $sth4 = $dbh->prepare("select count(*) from attend where studentid = ?");
print_tex_header();
while ( $sref = $sth->fetchrow_hashref ){
# Check that they have some attendance records, to verify withdrawn students enrolled this year.
if ( $arr{showwithdrawn} ) {
$sth4->execute( $sref->{studnum} ); # count attendance records
if ($DBI::errstr) { print $DBI::errstr; die;}
my $attcount = $sth4->fetchrow;
if ( $attcount < 1 ) { next; }
}
# LaTeX filter the student record
foreach my $key ( keys %$sref ) {
( $sref->{$key} ) = latex_filter( $sref->{$key} );
}
my %sr = %$sref;
$studentname = "$sr{lastname}, $sr{firstname} $sr{initial}";
$studnum = $sr{studnum};
# Now let's find which table student from: student or studentwd
if ( $html ) {
$sth5->execute( $studnum );
if ($DBI::errstr) { print $DBI::errstr; die;}
my $active = $sth5->rows; # returns 1 if in student, 0 if not.
if ( not $active ){
$studentname = qq{$studentname};
}
}
# Print this student's record
doAttSetup( $sref );
print_tex_record( $sref );
$linecount++;
if ( $linecount >= $arr{maxrecords} ){ # New page.
print TEX "\\end{tabular}\\newpage\n\n";
print_tex_header();
$linecount = 0;
}
} # End of student loop
# Attendance Row
print TEX "\\rowcolor[gray]{0.90}";
print TEX "\\multicolumn{2}{|r|}{\\bf $lex{Student}-$lex{Days} $lex{Attendance} }";
my $asum;
foreach my $yrmo ( sort keys %schooldays ){
print TEX "& \\bf $globAtt{$yrmo} ";
$asum += $globAtt{$yrmo};
}
print TEX "& $asum & \\\\ \\hline\n\n";
# Enrollment Row
print TEX "\\rowcolor[gray]{0.90}";
print TEX "\\multicolumn{2}{|r|}{\\bf $lex{Student}-$lex{Days} $lex{Enrolled} }";
my $esum;
foreach my $yrmo ( sort keys %schooldays ){
print TEX "& \\bf $globEnrol{$yrmo} ";
$esum += $globEnrol{$yrmo};
}
print TEX "& $esum & \\\\ \\hline\n\n";
# Percent Attendance Row
print TEX "\\rowcolor[gray]{0.90}";
print TEX "\\multicolumn{2}{|r|}{\\bf $lex{Percent} $lex{Attendance}}";
foreach my $yrmo ( sort keys %schooldays ){
my $percent;
if ( $globEnrol{$yrmo} ) {
$percent = format_number($globAtt{$yrmo} / $globEnrol{$yrmo} * 100, 1);
} else { $percent = 0; }
print TEX "& \\bf $percent\\% ";
}
my $globPercent;
if ( $esum ) {
$globPercent = format_number($asum / $esum * 100, 1);
} else {
$globPercent = 0;
}
print TEX "& \\bf\\large $globPercent\\% & \\\\ \\hline\n\n";
print TEX "% print_tex_end here\n";
print TEX "\\end{tabular}\n\n\\end{document}";
close TEX;
system("$pdflatex $filename > $logfile");
system("mv $shortname.pdf $downloaddir");
system("mv $logfile $downloaddir");
system("rm -f $shortname.*");
print qq{