#! /usr/bin/perl # Copyright 2001-2011 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. # Report student final marks - 1 page per student. my %lex = ('Cumulative' => 'Cumulative', 'Mark Report' => 'Mark Report', 'Main' => 'Main', 'View Log File' => 'View Log File', 'View/Download' => 'View/Download', 'School Year' => 'School Year', 'Grade' => 'Grade', 'Homeroom' => 'Homeroom', 'Report Card' => 'Report Card', 'Error' => 'Error', 'A4' => 'A4', 'Letter' => 'Letter', 'Legal' => 'Legal', 'Continue' => 'Continue', 'Paper Size' => 'Paper Size', 'Select by' => 'Select by', 'Sort by' => 'Sort by', 'Blank=All' => 'Blank=All', 'Name' => 'Name', 'Withdrawn Students' => 'Withdrawn Students', 'Show' => 'Show', ); my $self = 'rptstudfinalmarks.pl'; use DBI; use CGI; # 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"; } my $q = new CGI; my %arr = $q->Vars; print $q->header( -charset, $charset ); my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); $dbh->{mysql_enable_utf8} = 1; # Load the SupressSubject, AdditionalComments, MarkField data $sth = $dbh->prepare("select datavalue from conf_system where dataname = ?"); foreach my $val qw(r_SupressSubject r_MarkField r_AdditionalComments) { $sth->execute( $val ); if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; } my $dv = $sth->fetchrow; eval $dv; } 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"; my $title = "$lex{Cumulative} $lex{'Mark Report'}"; print "$doctype\n$title $chartype\n\n"; print "[ $lex{Main} |\n"; print "$lex{'Report Card'} ]\n"; print "

$title

\n"; if ( not $arr{page} ) { showStartPage(); } my $logfile = "pdflog$$.txt"; my $shortname = "studfnlmark$$"; my $fileName = "$shortname.tex"; open(TEX,">$fileName") || die "Can't open tex file"; #foreach my $key (keys %arr ) { print "K:$key V:$arr{$key}
\n"; } my $table = 'student'; if ( $arr{showwithdrawn} ) { $table = 'studentall'; } # Group and Group_value my $selection; my $group_value; if ( $arr{group_value} ) { $group_value = $arr{group_value}; my $group; if ( $arr{group} eq 'grade' ) { $group = 'grade'; } else { $group = 'homeroom'; } $selection = "where $group = ?"; } # Sorting Order my $sortorder; if ( $arr{sortorder} eq 'grade' ) { $sortorder = 'order by grade, lastname, firstname'; } elsif ( $arr{sortorder} eq 'homeroom' ) { $sortorder = 'order by homeroom, lastname, firstname'; } else { $sortorder = 'order by lastname, firstname'; } # Set paper size. my ( $papersize, $textheight, $textwidth ); if ( $arr{papersize} eq 'letter' ) { $papersize = 'letterpaper'; $textwidth = $g_letterpaper_textwidth; $textheight = $g_letterpaper_textheight; } elsif ( $arr{papersize} eq 'legal' ) { $papersize = 'legalpaper'; $textwidth = $g_legalpaper_textwidth; $textheight = $g_legalpaper_textheight; } elsif ( $arr{papersize} eq 'a4' ) { $papersize = 'a4paper'; $textwidth = $g_a4paper_textwidth; $textheight = $g_a4paper_textheight; } print TEX "\\documentclass[12pt,$papersize]{article} \\usepackage{array, inputenc} %\\usepackage[pdftex,bookmarks=false,pdfstartview=FitH]{hyperref} $a_latex_header \\renewcommand{\\familydefault}{\\sfdefault} \\setlength{\\textwidth}{$textwidth} \\setlength{\\textheight}{$textheight} \\setlength{\\hoffset}{-25mm} \\setlength{\\voffset}{-12.7mm} \\setlength{\\topmargin}{0in} \\setlength{\\extrarowheight}{4pt} \\addtolength{\\evensidemargin}{0in} \\addtolength{\\oddsidemargin}{0in}"; print TEX "\\begin{document}\n\\pagestyle{empty}\n"; print TEX "\\begin{center}\n"; my $sth = $dbh->prepare("select studnum,lastname, firstname, grade from $table $selection $sortorder"); #print "Table: $table Select: $selection Order: $sortorder Group: $group - $group_value
\n"; if ( $selection ) { # if we have any kind of selection statement. $sth->execute( $group_value ); } else { $sth->execute; } if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } # Loop through each student while ( my ( $studnum, $lastname, $firstname, $grade ) = $sth->fetchrow ) { print TEX "{\\LARGE $lex{Cumulative} $lex{'Mark Report'} }\n\n\\medskip\n\n"; print TEX "{\\Large $schoolname}\n\n"; print TEX "{$schoolyear} $lex{'School Year'}\n\n"; print TEX "$currdate\n\n\\bigskip\n\n"; print TEX "{\\Large\\it $firstname $lastname ($studnum)}\n\n"; print TEX $lex{Grade}. ": $grade\n\n\\bigskip"; print TEX "\n\\begin{tabular}{|l|l|}\\hline\n\n"; # Loop through their subjects. $sth1 = $dbh->prepare("select distinct eval.subjcode, subject.description, subject.endrptperiod from eval left outer join subject on eval.subjcode = subject.subjsec where studnum = ? order by subject.description"); $sth1->execute($studnum); if ($DBI::errstr) {print $DBI::errstr; die $DBI::errstr; } while ( my ( $subjcode, $description, $term) = $sth1->fetchrow ){ # Skip if supress or AdditionalComment subjects my ($tsubjcode, $dud) = split(/-/, $subjcode); if ( $r_SupressSubject{ $tsubjcode } or $r_SupressSubject{ $subjcode } or $r_AdditionalComments{ $tsubjcode } or $r_AdditionalComments{ $subjcode } ) { next; } ($description) = latex_filter($description); $sth2 = $dbh->prepare("select $r_MarkField from eval where eval.term = ? and studnum = ? and subjcode = ?"); $sth2->execute( $term, $studnum, $subjcode ); if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } my $mark = $sth2->fetchrow; $mark =~ s/%//; # Now print the record print TEX "$description ($subjcode) & $mark \\\\ \\hline\n"; } print TEX "\\end{tabular}\n\\newpage\n"; } # End of Student loop print TEX "\\end{center}\\end{document}"; close TEX; system("$pdflatex $fileName > $logfile"); system("mv $shortname.pdf $downloaddir"); system("mv $logfile $downloaddir"); system("rm -f $shortname.*"); print "

"; print "$lex{'View/Download'} $lex{Cumulative} $lex{'Mark Report'}

\n"; print "[ $lex{Main} |\n"; print "$lex{'View Log File'} ]\n"; print "\n"; #---------------- sub showStartPage { #---------------- print "
\n"; print "\n"; print "\n"; # Select Option print "\n"; print "\n"; # Sort Option print "\n"; print "\n"; # Paper Size print "\n"; print "\n"; # Include Withdrawn print "\n"; print "\n"; print "\n"; print "
$lex{'Select by'}\n"; print " "; print "$lex{'Blank=All'}
$lex{'Sort by'}
$lex{'Paper Size'}
$lex{Show} $lex{'Withdrawn Students'}\n"; print "
\n"; print "
\n"; print "\n"; exit; }