#! /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.
my %lex = ('Empty Subjects List' => 'Empty Subjects List',
'Main' => 'Main',
'Report Card' => 'Report Card',
'View Log File' => 'View Log File',
'Students' => 'Students',
'View/Download Empty Teacher Class/Subject Lists' =>
'View/Download Empty Teacher Class/Subject Lists',
);
use DBI;
use CGI;
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;
my $currdate = "$dow[$wday], $month[$mon] $mday, $year";
my $q = new CGI;
print $q->header;
%arr = $q->Vars;
my $term = $arr{term}; # selected term (if any).
require "../../etc/admin.conf" || die "Cannot open admin.conf!";
require "../../lib/liblatex.pl" || die "Cannot open liblatex.pl!";
print "$doctype\n
". $lex{'Empty Subjects List'}. "
$chartype\n\n";
print "[ ". $lex{Main}. " |\n";
print " ". $lex{'Report Card'}. " ]\n";
if ($arr{maxstudents}) {
$maxlines = $arr{maxstudents};
} else {
$maxlines = 32;
}
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
# First get all the enrolled subjects.
my $sth = $dbh->prepare("select distinct subjcode from eval");
$sth->execute;
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
$rows = $sth->rows;
for (1..$rows){
$subjsec = $sth->fetchrow;
push @subjsec,$subjsec;
}
my $select;
if ($term){
$select = " and $term >= startrptperiod and $term <= endrptperiod ";
}
# Next get the name,teacher from subject table.
foreach my $subjsec (@subjsec){
# Get Subject Information
$sth = $dbh->prepare("select * from subject
where subjsec = ? $select");
$sth->execute($subjsec);
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
while ( my @subj = $sth->fetchrow ) {
@subj = &latex_filter(@subj);
push @subject,"$subj[4]:$subj[2]:$subjsec";
#teacher: name(id) description subject-section code
}
}
# @subject contains all enrolled subjects (plus teacher,description)
my @subject = sort @subject;
# Setup TEX Code
my $shortname = "esubjlist$$";
my $fileName = "$shortname.tex";
open(TEX,">$fileName") || die "Can't open tex file";
print TEX "\\documentclass[12pt,letterpaper]{article}
\\usepackage{isolatin1,array}
\\pagestyle{empty}
\\setlength{\\textwidth}{7.8in}
\\setlength{\\textheight}{10.6in}
\\setlength{\\hoffset}{-0.6in}
\\setlength{\\voffset}{-1.4in}
\\addtolength{\\evensidemargin}{-1in}
\\addtolength{\\oddsidemargin}{-1in}
\\setlength{\\tabcolsep}{3.5pt}
\\setlength{\\extrarowheight}{6pt}\n";
print TEX "\\begin{document}\n";
foreach $subject (@subject) {
($teacher,$description,$subjsec) = split /:/,$subject;
($teacher,$teachid) = split /\(/,$teacher;
chop $teachid; # chop trailing )
# Get all the kids for this class, get names, sort, print
$sth = $dbh->prepare("select distinct studnum from eval
where subjcode = ? and studnum > 0");
$sth->execute($subjsec);
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
my @student;
while (my $studnum = $sth->fetchrow ) {
push @student,$studnum;
}
# Next get their names
my @studentunsort;
my $sth = $dbh->prepare("select lastname,firstname from student
where studnum = ?");
foreach my $studnum (@student){
$sth->execute($studnum);
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
my ($lastname,$firstname) = $sth->fetchrow;
if ($lastname){ # If still enrolled (otherwise in withdrawn table)
push @studentunsort,"$lastname:$firstname:$studnum";
}
}
my @student;
@student = sort @studentunsort;
# We now have the student array all sorted out.
foreach my $element (@student) { # Filter out any funny stuff to LaTeX
$element =~ s/\\/\//g; # replace backslash with forward slash.
$element =~ s/#/\\#/g;
$element =~ s/&/\\&/g;
}
print_header(); # print header to tex file.
my $studcount = @student;
$linecount = 0;
# Loop through and print each student
foreach $student (@student){
my ($lastname,$firstname,$studnum) = split /:/,$student;
$linecount++;
if ($linecount > $maxlines) { # We'll print a new page header here
$linecount = 0;
print TEX "\\end{tabular}\\\\ \\newpage\n";
print_header();
}
print_record($lastname, $firstname, $studnum);
} # End of Student For
print TEX $lex{'Students'}. ": $studcount & & & & & & & & & & & & & & & & \\\\
\\hline \\end{tabular}\\\\ \\newpage\n";
} # End of Each Subject
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 "