#! /usr/bin/perl # Copyright 2001-2023 Leslie Richardson # This file is part of Open Admin for Schools. use DBI; use CGI; my %lex = ( 'View/Download' => 'View/Download', 'Demographic Confirmations' => 'Demographic Confirmations', 'View Log File' => 'View Log File', 'Main' => 'Main', 'Student Confirmation' => 'Student Confirmation', 'Cannot open' => 'Cannot open', 'Error' => 'Error', 'Font Size' => 'Font Size', 'Paper Size' => 'Paper Size', 'Letter' => 'Letter', 'Legal' => 'Legal', 'A4' => 'A4', 'Use Page Break (if present)' => 'Use Page Break (if present)', 'Continue' => 'Continue', 'Grade' => 'Grade', 'Homeroom' => 'Homeroom', 'Blank=All' => 'Blank=All', 'Group' => 'Group', 'Values' => 'Values', 'Separate with Spaces' => 'Separate with Spaces', 'Lastname' => 'Lastname', 'Firstname' => 'Firstname', 'Sort by' => 'Sort by', 'Select by' => 'Select by', ); # Read config variables eval require "../etc/admin.conf"; if ( $@ ) { print $lex{Error}. " $@
\n"; die $lex{Error}. " $@\n"; } # Load Latex Filter eval require "../lib/liblatex.pl"; if ( $@ ) { print $lex{Error}. " $@
\n"; die $lex{Error}. " $@\n"; } my $q = new CGI; print $q->header( -charset, $charset ); my %arr = $q->Vars; 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"; # Page heading. my $title = $lex{'Demographic Confirmations'}; print qq{$doctype\n$title\n}; print qq{ $chartype\n\n}; print qq{[ $lex{Main} ]\n}; print qq{

$lex{'Demographic Confirmations'}

\n}; if ( not $arr{page} ) { showStartPage(); } else { delete $arr{page}; } my $fontsize = $arr{fontsize}. 'pt'; my ($papersize, $textwidth, $textheight); 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; } my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); $dbh->{mysql_enable_utf8} = 1; # Get passed group values my @values = split /\s/, $arr{groupValue}; # split into array based on spaces delete $arr{groupValue}; my $groupType; if ( $arr{groupType} eq 'grade' ) { $groupType = 'grade'; } else { $groupType = 'homeroom'; } delete $arr{groupType}; # Select students, sorted by lastname, firstname, my $select; if ( @values ) { $select = 'where '; $first = 1; foreach my $value ( @values ) { $value = $dbh->quote( $value ); if ( not $first ) { $select .= ' or '; } $select .= "$groupType = $value "; $first = 0; } } if ($select) { print qq{Select: $select
\n}; } my $sortorder = "lastname, firstname"; if ( $arr{sortorder} eq 'name' ) { $sortorder = "lastname, firstname"; } elsif ( $arr{sortorder} eq 'grade' ) { $sortorder = "grade,lastname, firstname"; } elsif ( $arr{sortorder} eq 'homeroom' ) { $sortorder = "homeroom, lastname, firstname"; } # Read in Template unless (open (FH,"<../template/democonf.tpl")) { print $lex{'Cannot open'}. " template - $!\n"; die $lex{'Cannot open'}. " template - $!\n"; } my $text; { local $/; $text = ; close FH;} if ( $arr{pagebreak} ) { $text =~ s/%\\newpage/\\newpage/g; } # Get Meta values: fieldid and fieldname (possibly translated) my %meta = (); my $sth = $dbh->prepare("select fieldid, fieldname from meta where tableid = 'student'"); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } while ( my ( $fieldid, $fieldname ) = $sth->fetchrow ) { $meta{ $fieldid } = $fieldname; } my $shortname = "democonf$$"; my $filename = "$shortname.tex"; open(TEX,">$filename") || die "Can't open tex file"; print TEX "\\documentclass[$fontsize,$papersize,oneside]{article} \\usepackage{graphicx,array,newcent,colortbl,inputenc} $a_latex_header \\renewcommand{\\familydefault}{\\sfdefault} \\usepackage[bookmarks=false,pdfstartview=FitH]{hyperref} \\setlength{\\textwidth}{$textwidth} \\setlength{\\textheight}{$textheight} \\setlength{\\hoffset}{-25mm} \\setlength{\\voffset}{-25mm} \\setlength{\\topmargin}{5mm} \\addtolength{\\evensidemargin}{0mm} \\addtolength{\\oddsidemargin}{0mm} \\setlength{\\extrarowheight}{2pt} \\setlength{\\parindent}{0mm} \\pagestyle{myheadings}"; print TEX "\\markright{$schoolname\\hfill ", $lex{'Student Confirmation'},"\\hfill $currdate -- Pg } \\begin{document}\n"; if ( not $select ) { $sortorder = 'grade, lastname, firstname'; } else { $sortorder = 'lastname, firstname'; } $sth = $dbh->prepare("select * from student $select order by $sortorder"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } while ( my $ref = $sth->fetchrow_hashref ) { my %rec = %$ref; # LaTeX Filter foreach my $val ( values %rec ) { ($val) = latex_filter( $val ); } my $template = $text; # make a new blank record to plug in... # Now put replacement text back in. $template =~ s{\<\*(.*?)\*\>} { exists($rec{$1}) ? $rec{$1} : $1 }gsex; print TEX $template,"\n"; } # End of Student For loop print TEX "\\end{document}"; close TEX; system("$pdflatex $filename >pdflog$$.txt"); system("mv $shortname.pdf $downloaddir"); system("mv pdflog$$.txt $downloaddir"); system("rm -f $shortname.*"); print qq{

}; print qq{$lex{'View/Download'} $lex{'Demographic Confirmations'}\n}; print qq{

\n

[ $lex{'View Log File'} | $lex{Main} ]

\n}; print qq{\n}; #---------------- sub showStartPage { #---------------- # Setup the form and start of table. print qq{

Report to show to parents at Parent-Teacher Interviews

\n}; print qq{
\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{\n}; print qq{}; print qq{\n}; print qq{\n}; print qq{
$lex{'Sort by'}
$lex{'Select by'}\n}; print qq{ \n}; print qq{$lex{'Separate with Spaces'}, $lex{'Blank=All'}
$lex{'Font Size'}\n}; print qq{
$lex{'Paper Size'}\n}; print qq{\n}; print qq{
$lex{'Use Page Break (if present)'}\n}; print qq{\n}; print qq{
}; print qq{}; print qq{
\n}; print qq{\n}; exit; }