#!/usr/bin/perl # Copyright 2001-2007 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', ); # show Principal Signature Line; set to 0 to turn off my $principalSign = 1; use DBI; use CGI; # Used for the category titles my $shortname = "rpttransfer$$"; my $fileName = "$shortname.tex"; my @month = ('','January','February','March','April','May','June','July', 'August','September','October','November','December'); my @dow = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); 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; my %arr = $q->Vars; # Read config variables require "../etc/admin.conf" || die "Cannot read admin.conf!"; # Print Page Head. print "$doctype\n". $lex{'Monthly Transfer Report'}. " $chartype\n[ ". $lex{Main}. " ]\n"; my $dsn = "DBI:$dbtype:dbname=$dbase"; $dbh = DBI->connect($dsn,$user,$password); # No date defined. if (not $arr{date}) { # We'll go back 1 month. if ($mon > 1){ #Jan is zero in localtime function. $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. $date = $arr{date}; $yr = 2000 + substr($date,0,2); $mo = substr($date,2,2); #$da = substr($date,4,2); # Change date to the first of the month. $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"; print TEX "\\documentclass[12pt,letterpaper]{article} \\usepackage{isolatin1,array,colortbl,helvet} \\pagestyle{empty} \\setlength{\\textwidth}{6.5in} \\setlength{\\textheight}{9.5in} \\setlength{\\hoffset}{-0.5in} \\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 $currcat = 0; my $lc = 0; for ($i=1; $i <= $rows; ++$i) { my ($studnum, $date, $type, $description, $lastname, $firstname) = $sth->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{8cm}|p{2.5cm}|}\n\\hline\n"; print TEX "\\rowcolor[gray]{0.90}{\\bf ". $lex{Student}. "} & \\bf ". $lex{Reason}. " & {\\bf Date}\\\\ \\hline\n"; $lc = 0; # reset line counter; } # Now print the row print TEX "{\\bf $lastname}, $firstname & $description & $date \\\\ \\hline\n"; $lc++; #increment line counting. if ( $lc % 5 == 0) { print TEX "\\end{tabular}\n"; print TEX "\\begin{tabular}{|p{6cm}|p{8cm}|p{2.5cm}|}\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";