#!/usr/bin/perl # Copyright 2001-2008 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. # File: rpttransmon.pl # Monthly report for Enrollment change. # PDF Output my %lex = ('Monthly Transfer Report' => 'Monthly Transfer Report', 'Date format Error' => 'Date format Error', 'View/Download' => 'View/Download', 'View Log File' => 'View Log File', 'Main' => 'Main', 'Current Date' => 'Current Date', 'Aging Date' => 'Aging Date', 'Month of' => 'Month of', 'No Enrollment Changes in Current Enrollment' => 'No Enrollment Changes in Current Enrollment', 'enrol' => 'New Enrollments', 'reenrol' => 'Reenrollments', 're-enrol' => 'Reenrollments', 'withdraw' => 'Withdrawals', 'Student' => 'Student', 'Reason' => 'Reason', 'Go Back' => 'Go Back', 'Date' => 'Date', 'Principal' => 'Principal', 'Grade' => 'Grade', 'Error' => 'Error', ); # show Principal Signature Line; set to 0 to turn off my $principalSign = 1; my $self = 'rpttransmon.pl'; use DBI; use CGI; # Used for the category titles my $shortname = "rpttransfer$$"; my $fileName = "$shortname.tex"; my $q = new CGI; print $q->header; my %arr = $q->Vars; # Read config variables eval require "../etc/admin.conf"; if ( $@ ) { print $lex{Error}. " $@
\n"; die $lex{Error}. " $@
\n"; } eval require "../lib/liblatex.pl"; if ( $@ ) { print $lex{Error}. " $@
\n"; die $lex{Error}. " $@
\n"; } # Set Dates my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $iddst) = localtime(time); $year = $year + 1900; $mon++; $wday++; my $currdate = "$dow[$wday], $month[$mon] $mday, $year"; # Print Page Head. print "$doctype\n". $lex{'Monthly Transfer Report'}. " $chartype\n[ ". $lex{Main}. " ]\n"; my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); # No date defined. my ($yr, $mo, $da); if ( not $arr{date} ) { # We'll go back 1 month. if ( $mon > 1 ){ # if not January (ie. 1) $mo = $mon - 1; $yr = $year; } else { # month is 1, go to prev dec. $mo = 12; $yr = $year - 1; } $da = "01"; } else { # We have been passed a date. ($yr, $mo, $da) = split /-/, $arr{date}; $da = "01"; } my $agingdate = "$yr-$mo-$da"; if ($yr == 0 or $mo == 0 or $da == 0) { print '

'. $lex{'Date format Error'}; print " (yymmdd)!

\n"; print "
\n"; print "\n"; die; } print "

$schoolname ". $lex{'Monthly Transfer Report'}. "

\n"; print "

". $lex{'Current Date'}. ": $currdate
"; print $lex{'Aging Date'}. ": $agingdate

\n"; open(TEX,">$fileName") || die "Failed tex file open"; my $papersize; if ($defaultpapersize) { $papersize = $defaultpapersize; } else { $papersize = 'letterpaper'; # default to letter paper. } print TEX "\\documentclass[12pt,$papersize]{article} \\usepackage{array,colortbl,helvet,inputenc} \\inputencoding{latin1} \\renewcommand{\\familydefault}{\\sfdefault} \\pagestyle{empty} \\setlength{\\textwidth}{7in} \\setlength{\\textheight}{9.5in} \\setlength{\\hoffset}{-1in} \\setlength{\\voffset}{-1in} \\setlength{\\parindent}{0pt} \\setlength{\\tabcolsep}{5pt} \\renewcommand{\\familydefault}{\\sfdefault} \\setlength{\\extrarowheight}{6pt}\n"; print TEX "\\begin{document}\\begin{center}\n"; print TEX "{\\LARGE\\sf $schoolname ". $lex{'Monthly Transfer Report'}; print TEX "}\n\n\\medskip\n{\\Large\\sf ". $lex{'Month of'}. " $month[$mo], $yr}\n\n"; print TEX "\\hrulefill\n\\medskip\n\n"; # Now select transfer records in month of interest my $sth = $dbh->prepare("select studnum, date, type, description, lastname, firstname from transfer where month(date) = month(?) and year(date) = year(?) order by type, date desc"); $sth->execute( $agingdate, $agingdate ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my $rows = $sth->rows; my $sth1 = $dbh->prepare("select grade from studentall where studnum = ?"); my $currcat = 0; my $lc = 0; for ( my $i=1; $i <= $rows; ++$i ) { my ($studnum, $date, $type, $description, $lastname, $firstname) = $sth->fetchrow; ($description, $lastname, $firstname) = latex_filter( $description, $lastname, $firstname ); $sth1->execute( $studnum ); if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } my $grade = $sth1->fetchrow; $oldcat = $currcat; $currcat = $type; if ($currcat ne $oldcat) { # We have a new category; print head/tabular if ($i != 1){ # close up previous tabular print TEX "\\end{tabular}\n\\bigskip\n\n"; } my $currcat =~ s/\-//; my $title = $lex{$type}; print TEX "{\\Large\\sf $title}\n\n \\medskip\n\n"; # Row format: Lastname,firstname | Reason | Date print TEX "\\begin{tabular}{|p{6cm}|p{1.4cm}|p{8cm}|p{2.2cm}|}\n\\hline\n"; print TEX "\\rowcolor[gray]{0.90}{\\bf ". $lex{Student}. "} & {\\bf "; print TEX $lex{Grade}. "} & {\\bf ". $lex{Reason}. "} & {\\bf Date}\\\\ \\hline\n"; $lc = 0; # reset line counter; } # Now print the row print TEX "{\\bf $lastname}, $firstname & $grade & $description & $date \\\\ \\hline\n"; $lc++; #increment line counting. if ( $lc % 5 == 0) { print TEX "\\end{tabular}\n"; print TEX "\\begin{tabular}{|p{6cm}|p{1.4cm}|p{8cm}|p{2.2cm}|}\n\\hline\n"; } } if ( $rows > 0 ){ # If we have some records... print TEX "\\end{tabular} \\\\ \n"; } else { print TEX $lex{'No Enrollment Changes in Current Enrollment'}. "\n\n"; } print TEX "\\end{center}\n"; if ( $principalSign ) { print TEX "\n\\bigskip\n\\medskip\n\\underline{\\hspace{3in}}\n\n"; print TEX "{\\footnotesize ". $lex{Principal}. " }\n\n"; } print TEX "\\end{document}\n"; close TEX; system("$pdflatex $fileName >pdflog$$.txt"); system("mv $shortname.pdf $downloaddir"); system("mv pdflog$$.txt $downloaddir"); system("rm -f $shortname.*"); print "

\n"; print $lex{'View/Download'}. ' '. $lex{'Monthly Transfer Report'}; print "

\n[ ". $lex{'View Log File'}. " | ". $lex{Main}. " ]\n";