#! /usr/bin/perl # Copyright 2001-2022 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 $schooldays = 198; # change to suit. only a default. my %lex = ('Report' => 'Report', 'Main' => 'Main', 'Attendance' => 'Attendance', 'No Records Found' => 'No Records Found', 'View/Download' => 'View/Download', 'View Log File' => 'View Log File', 'Year End Attendance' => 'Year End Attendance', 'Bdate' => 'Bdate', 'Grade' => 'Grade', 'Sex' => 'Sex', 'Enrollment Changes' => 'Enrollment Changes', 'School Days' => 'School Days', 'Start Date' => 'Start Date', 'End Date' => 'End Date', 'Homeroom' => 'Homeroom', 'Select' => 'Select', 'Sort by' => 'Sort by', 'Lastname, Firstname' => 'Lastname, Firstname', 'Homeroom, Lastname, Firstname' => 'Homeroom, Lastname, Firstname', 'Grade, Lastname, Firstname' => 'Grade, Lastname, Firstname', 'Continue' => 'Continue', 'Error' => 'Error', ); my $self = 'rptattyear.pl'; use DBI; use CGI; # Read config variables eval require "../../etc/admin.conf"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } my $maxlines = 28; my $shortname = "attyear$$"; my $filename = "$shortname.tex"; my $logfile = "pdflog$$.txt"; my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); $dbh->{mysql_enable_utf8} = 1; my $q = new CGI; print $q->header( -charset, $charset ); my %arr = $q->Vars; my $sortorder = "homeroom, lastname, firstname"; if ( $arr{sortorder} eq $lex{'Lastname, Firstname'} ) { $sortorder = "s.lastname, s.firstname"; } elsif ( $arr{sortorder} eq $lex{'Grade, Lastname, Firstname'} ) { $sortorder = "grade,lastname, firstname"; } elsif ( $arr{sortorder} eq $lex{'Homeroom, Lastname, Firstname'} ) { $sortorder = "homeroom, lastname, firstname"; } if ( $arr{sortorder} ) { delete $arr{sortorder}; } my $select; if ( $arr{group} ) { if ( $arr{select} eq $lex{Grade} ) { # Find this grade; my $grp = $dbh->quote( $arr{group} ); $select = "and grade = $grp"; } elsif ( $arr{select} eq $lex{Homeroom} ) { my $grp = $dbh->quote( $arr{group} ); $select = "and homeroom = $grp"; } } my $title = qq{$lex{'Year End Attendance'} $lex{Report}}; print qq{$doctype\n$title\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{$chartype\n[ $lex{Main} |\n}; print qq{$lex{Attendance} ]\n}; if (not $arr{startflag} ) { showStartPage(); } else { delete $arr{startflag}; } # Set Date format. my ($year,$mo, $day) = split('-', $arr{startdate}); $startdate = "$month[$mo] $day, $year"; my ($eyear,$emo,$eday) = split( '-', $arr{enddate}); $enddate = "$month[$emo] $eday, $eyear"; if ($arr{schooldays}) { $schooldays = $arr{schooldays}; delete $arr{schooldays}; } my @students; my $sth = $dbh->prepare("select distinct a.studentid, s.lastname, s.firstname from attend as a, studentall as s where a.studentid = s.studnum $select order by $sortorder"); #print qq{SEL: $select
\n}; #print qq{SORT: $sortorder
\n}; $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } while ( my ($studnum, $ln, $fn) = $sth->fetchrow ) { push @students, $studnum; } if ( not @students ){ print qq{

$lex{'No Records Found'}

\n}; print qq{\n}; exit; } # Setup Tex File open(TEX,">$filename") || die "Cannot open tex file"; prTexHeader(); # print TeX file header defaults. $prevstud = -1; my $sth = $dbh->prepare("select absdate, reason, period, subjsec, late from attend where studentid = ? and to_days(absdate) >= to_days('$arr{startdate}') and to_days(absdate) <= to_days('$arr{enddate}') order by absdate"); my $sth1 = $dbh->prepare("select lastname, firstname, birthdate, grade, sex from studentall where studnum = ?"); my $first = 1; # Main Loop - once for each student. foreach my $studnum ( @students ) { $sth->execute( $studnum ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my $latetot = 0; my $absenttot = 0; my $lateu = 0; my $absentu = 0; my $totalu = 0; # end student record if (not $first) { print TEX "\\end{multicols}\\hrulefill\\\\ \n\\bigskip"; } else { $first = 0; } # Fetch Student's Info $sth1->execute($studnum); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my ($lastname, $firstname, $birthdate, $grade, $sex) = $sth1->fetchrow; # Print Student Info print TEX "{\\Large\\bf $lastname, $firstname} ($studnum) "; print TEX "{\\bf ". $lex{Bdate}. ":} $birthdate {\\bf ". $lex{Grade}; print TEX ":} $grade {\\bf ". $lex{Sex}. ":} $sex\\\\ \n"; # Fetch Enrollment/Withdrawal Changes my $sth1 = $dbh->prepare("select date, type, description from transfer where studnum = ? order by date"); $sth1->execute( $studnum ); if ($DBI::errstr) {print $DBI::errstr; die $DBI::errstr; } my $entryrecs = $sth1->rows; if ($entryrecs > 0 ) { # then print enrollment change records print TEX "\\hrulefill\n\n{\\large\\sf ". $lex{'Enrollment Changes'}; print TEX "}\n\n \\begin{tabular}{lll}\n"; for ($i=1; $i<=$entryrecs; $i++) { my ($date, $type, $description) = $sth1->fetchrow; $description =~ s/[^0-9A-Za-z ]//g; #strip nontext from desc field print TEX "$date & $type & $description\\\\ \n"; } print TEX "\\end{tabular}\n\n\\medskip \n"; } print TEX "\\hrulefill\n\n\\setlength{\\premulticols}{5pt}\n\n"; print TEX "\\setlength{\\postmulticols}{5pt}\\begin{multicols}{3}\\raggedright\n"; # Loop through all attendance records. while ( my ( $absdate, $reason, $period, $subjsec, $late ) = $sth->fetchrow ) { $reason =~ s/[^0-9A-Za-z ]//g; # strip any non text from reason field print TEX "$absdate P$period $reason\\\\ \n"; } } # End of Main Student Loop print TEX "\\end{multicols}\n\\end{center}\\end{document}\n"; close TEX; system("$pdflatex $filename >$logfile"); system("mv $shortname.pdf $downloaddir"); system("mv $logfile $downloaddir"); system("rm -f $shortname.*"); print qq{

\n}; print qq{$lex{'View/Download'} $lex{'Year End Attendance'} $lex{Report}}; print qq{

\n[ $lex{Main} |\n}; print qq{$lex{'View Log File'}}; print qq{ ]\n}; #-------------- sub prTexHeader { #-------------- my $papersize; if ( $defaultpapersize ) { $papersize = $defaultpapersize; } else { $papersize = 'letterpaper'; } print TEX "\\documentclass[12pt,$papersize]{article}\\usepackage{array,multicol,inputenc}\n"; print TEX "$a_latex_header\n\\renewcommand{\\familydefault}{\\sfdefault}\n"; print TEX "\\setlength{\\textwidth}{7.5in}\n \\setlength{\\textheight}{10in}\n"; print TEX "\\setlength{\\hoffset}{-1.2in}\n\\setlength{\\voffset}{-1.4in}\n"; print TEX "\\setlength{\\extrarowheight}{2pt}\n\\setlength{\\parindent}{0pt}\n"; print TEX "\\begin{document}\n\\begin{center}\n{\\sf\\huge $schoolname}\n\n{\\sf\\LARGE "; print TEX $lex{'Year End Attendance'}; print TEX "} \n\n\\bigskip\n"; } #---------------- sub showStartPage { #---------------- # print sortorder and selection input form. print qq{

$title

\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{\n}; print qq{\n}; print qq{
$lex{'Sort by'}
$lex{Select}\n}; print qq{
$lex{'Start Date'}\n}; print qq{\n}; print qq{
$lex{'End Date'}\n}; print qq{
$lex{'School Days'}}; print qq{
\n}; print qq{\n}; print qq{\n}; exit; }