#! /usr/bin/perl
# Copyright 2001-2020 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.
use DBI;
use CGI;
my %lex = ('Student Timetables' => 'Student Timetables',
'Main' => 'Main',
'Timetable' => 'Timetable',
'Cannot open tex file' => 'Cannot open tex file',
'View/Download' => 'View/Download',
'View Log File' => 'View Log File',
'Select' => 'Select',
'Lastname, Firstname' => 'Lastname, Firstname',
'Homeroom, Lastname, Firstname' => 'Homeroom, Lastname, Firstname',
'Grade, Lastname, Firstname' => 'Grade, Lastname, Firstname',
'Band, Lastname, Firstname' => 'Band, Lastname, Firstname',
'Sort by' => 'Sort by',
'Grade' => 'Grade',
'Homeroom' => 'Homeroom',
'Continue' => 'Continue',
'No Student(s) Found' => 'No Student(s) Found',
'Error' => 'Error',
'Blank=All' => 'Blank=All',
'Band' => 'Band',
'Term' => 'Term',
'Period' => 'Period',
'Day' => 'Day',
'Separate with Spaces' => 'Separate with Spaces',
'Term(s)' => 'Term(s)',
'Font Size' => 'Font Size',
'Paper Size' => 'Paper Size',
'Letter' => 'Letter',
'Legal' => 'Legal',
'A4' => 'A4',
'Student Number' => 'Student Number',
);
my $grayshade = '0.80';
my $maxchars = 10; # maximum characters for subject description (if not small desc field)
my $logowidth = '20mm';
my $logofile = 'schoollogo.jpg';
my $self = "rptstudenttimetable.pl"; # previously called 'rptschedule.pl'.
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 $maxlines = 28;
my $shortname = "schedrpt$$";
my $filename = "$shortname.tex";
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
$dbh->{mysql_enable_utf8} = 1;
my $q = new CGI;
print $q->header( -charset, $charset );
my %arr = $q->Vars;
# print page header
my $title = $lex{'Student Timetables'};
print qq{$doctype\n
$title\n};
print qq{\n};
print qq{$chartype\n\n};
print qq{[ $lex{Main} | \n};
print qq{$lex{Timetable} ]\n};
if ( not $arr{page} ) {
showStartPage();
}
my %staffnames; # global
my $sortorder = "lastname, firstname";
if ( $arr{sortorder} eq 'grade' ) {
$sortorder = "grade, lastname, firstname";
} elsif ( $arr{sortorder} eq 'band' ) {
$sortorder = "band, lastname, firstname";
} elsif ( $arr{sortorder} eq 'homeroom' ) {
$sortorder = "homeroom, lastname, firstname";
}
delete $arr{sortorder};
my $includelocation;
if ( $arr{includelocation} ) {
$includelocation = 1;
}
delete $arr{includelocation};
my @terms = split /\s/, $arr{term};
delete $arr{term};
if ( not @terms ) {
print qq{No Terms Found
\n};
print qq{\n};
exit;
}
my $select;
if ( $arr{group} ) {
if ( $arr{select} eq $lex{Grade} ) { # Find this grade;
my $grp = $dbh->quote( $arr{group} );
$select = "where grade = $grp";
} elsif ( $arr{select} eq $lex{Homeroom} ) {
my $grp = $dbh->quote( $arr{group} );
$select = "where homeroom = $grp";
} elsif ( $arr{select} eq $lex{Band} ) {
my $grp = $dbh->quote( $arr{group} );
$select = "where band = $grp";
} elsif ( $arr{select} eq $lex{'Student Number'} ) {
my $val = $dbh->quote( $arr{group} );
$select = "where studnum = $val";
}
}
# foreach my $key (sort keys %arr ) { print qq{K:$key V:$arr{$key}
\n}; }
# print qq{Sortorder: $sortorder Select: $select
\n};
# Now create an array, @students, to store student numbers of students to print
my $sth = $dbh->prepare("select studnum from student $select
order by $sortorder");
$sth->execute;
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
while ( my $studnum = $sth->fetchrow ) {
push @students, $studnum;
}
if ( @students ) { # We have students to print; setup LaTeX file.
open(TEX,">$filename") || die $lex{'Cannot open tex file'};
my ( $papersize, $textwidth, $textheight );
if ( $arr{papersize} eq $lex{Letter} ) {
$papersize = 'letterpaper';
$textwidth = $g_letterpaper_textwidth;
$textheight = $g_letterpaper_textheight;
} elsif ( $arr{papersize} eq $lex{Legal} ) {
$papersize = 'legalpaper';
$textwidth = $g_legalpaper_textwidth;
$textheight = $g_legalpaper_textheight;
} elsif ( $arr{papersize} eq $lex{A4} ) {
$papersize = 'a4paper';
$textwidth = $g_a4paper_textwidth;
$textheight = $g_a4paper_textheight;
}
print TEX "\\documentclass[$arr{fontsize},$papersize, landscape]{article}
\\usepackage{array,colortbl,multicol,inputenc,graphicx,helvet}
$a_latex_header
\\pagestyle{empty}
\\setlength{\\textwidth}{$textwidth}
\\setlength{\\textheight}{$textheight}
\\setlength{\\evensidemargin}{0mm}
\\setlength{\\oddsidemargin}{0mm}
\\setlength{\\hoffset}{-10mm}
\\setlength{\\voffset}{-25mm}
\\setlength{\\extrarowheight}{2pt}
\\setlength{\\parindent}{0pt}\n";
print TEX "\\begin{document}\n";
} else {
print qq{$lex{'No Student(s) Found'}
\n};
print qq{