\n";
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 $currdate = "$year-$month-$day";
$currsdate = "$year$month$day";
$currdate = "$month[$month] $day, $year";
# Get Meta values: fieldid and arrayidx
my $sth;
$sth = $dbh->prepare("select fieldid, arrayidx from meta
where tableid = 'staff' order by arrayidx");
$sth->execute;
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
while (my ($fieldid, $arrayidx) = $sth->fetchrow) {
$meta[$arrayidx] = $fieldid;
}
# Get the report template...
unless (open (FH,"<", "../../template/staffrpt.tpl")) {
print $lex{'Unable to open template file'},": $!\n";
die $lex{'Unable to open template file'},": $!\n";
}
my $text;
{ local $/; $text = ; close FH;}
# Open a TeX file for creation; use a template...
my $logfile = "pdflog$$.txt";
my $shortname = "staffrpt$$";
my $filename = "$shortname.tex";
open(TEX,">$filename") || die "Can't open tex file";
printTeXStart(); # Setup the start of the file.
# Print Heading.
if ( $arr{tbl} ) {
print TEX $lex{Preregistration}. q{ }. $lex{Staff}. q{ }. $lex{Report};
} else {
print TEX $lex{Staff}. q{ }. $lex{Report};
}
print TEX "\\hfill{\\LARGE $schoolname} ";
print TEX " \\hfill $currdate \n\\smallskip\n\n";
# Find each staff record (staff or prereg_staff)
$sth = $dbh->prepare("select * from $table order by lastname, firstname");
$sth->execute;
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
while ( my @st = $sth->fetchrow ) {
# Note: entire record loaded....
@st = latex_filter( @st );
my %rec;
# populate rec hash with rec{fieldid} = fieldvalue
# @meta holds the fieldid's and @st holds current record vals.
for (0..$#st) {
$rec{$meta[$_]} = $st[$_];
}
my $template = $text; # make a new blank record to plug in...
# Now put replacement text back in.
$template =~ s{\<\#(.*?)\#\>}
{ exists($rec{$1})
? $rec{$1}
: ' '
}gsex;
print TEX $template,"\n";
}
print TEX "\\end{document}";
close TEX;
system("$pdflatex $filename > $logfile");
system("mv $shortname.pdf $downloaddir");
system("mv $logfile $downloaddir");
system("rm $shortname.*");
print "