#! /usr/bin/perl # Copyright 2001-2023 Leslie Richardson # This file is part of Open Admin for Schools. use DBI; use CGI; my %lex = ( 'View' => 'View', 'Download' => 'Download', 'Log File' => '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, Firstname' => 'Lastname, Firstname', 'Homeroom, Lastname, Firstname' => 'Homeroom, Lastname, Firstname', 'Grade, Lastname, Firstname' => 'Grade, Lastname, Firstname', 'Sort by' => 'Sort by', 'Record' => 'Record', 'Not Found' => 'Not Found', 'Nominal Roll' => 'Nominal Roll', 'Records' => 'Records', 'Report' => 'Report', ); my $self = 'rptnomrollconf.pl'; # 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 $sort = $arr{sortorder}; # Do we sort by any order but Lastname, firstname? 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{'Nominal Roll'} $lex{Report}"; print qq{$doctype\n$title $chartype\n\n}; print qq{[ $lex{Main} ]\n}; print qq{

$title

\n}; if ( not $arr{page} ) { showStartPage(); } else { delete $arr{page}; } my $fontsize = $arr{fontsize}. 'pt'; 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; } delete $arr{papersize}; # no longer needed. 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}; #print qq{Group", @group, "
\n}; my $groupType; if ( $arr{groupType} eq $lex{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 $lex{'Lastname, Firstname'} ) { $sortorder = "lastname, firstname"; } elsif ( $arr{sortorder} eq $lex{'Grade, Lastname, Firstname'} ) { $sortorder = "grade,lastname, firstname"; } elsif ( $arr{sortorder} eq $lex{'Homeroom, Lastname, Firstname'} ) { $sortorder = "homeroom, lastname, firstname"; } # Read in Template unless (open (FH,"<../../template/inacconf.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; } my %fieldname = (); my @meta = (); # Get Meta values: fieldid and arrayidx $sth = $dbh->prepare("select fieldid, arrayidx, fieldname from meta where tableid = 'student_inac' order by arrayidx"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } while ( my ($fieldid, $arrayidx, $fieldname) = $sth->fetchrow ) { $meta[$arrayidx] = $fieldid; $fieldname{$fieldid} = $fieldname; } # If using newer tablename:fieldname format.... do that here before # replacement process # Parse and put in Fieldnames (descriptors) $text =~ s{\<\*(.*?)\*\>} { exists( $fieldname{$1} ) ? $fieldname{$1} : $1 }gsex; my $shortname = "nomrollconf$$"; 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}{-1.5in} \\setlength{\\voffset}{-1in} \\setlength{\\topmargin}{0.2in} \\addtolength{\\evensidemargin}{0in} \\addtolength{\\oddsidemargin}{0in} \\setlength{\\extrarowheight}{2pt} \\setlength{\\parindent}{0in} \\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 lastname, firstname, studnum from student $select order by $sortorder"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my $sth1 = $dbh->prepare("select * from student_inac where studnum = ?"); while ( my @stud = $sth->fetchrow ) { my $studnum = $stud[2]; @stud = latex_filter( @stud ); my %rec = (); $rec{'student:lastname'} = $stud[0]; $rec{'student:firstname'} = $stud[1]; # now load the student_inac data for this student. $sth1->execute( $studnum ); if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } my @arr = $sth1->fetchrow; if ( not @arr ) { #print TEX "\n\\medskip\n"; # print TEX "INAC $lex{Record} $lex{'Not Found'}: $stud[1] $stud[0] ($stud[0])\\medskip\n\n"; print qq{
INAC $lex{Record} $lex{'Not Found'}: $stud[1] $stud[0] ($stud[0]
\n}; next; }; # no record if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } @arr = latex_filter( @arr ); # populate rec hash with rec{fieldid} = fieldvalue # @meta holds the fieldid's and @arr holds current record vals. for (0..$#arr) { $rec{$meta[$_]} = $arr[$_]; } #print qq{\n}; #print qq{TEXT is:", $text, "

\n}; #print qq{REC is: ", %rec, "

\n}; #print qq{META: ", @meta, "

\n}; #print qq{ARR is: ", @arr, "

\n}; #print qq{
\n}; 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"; print TEX "\n\\medskip\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}/$lex{Download} $lex{'Nominal Roll'} $lex{Records}

\n}; print qq{

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

\n}; print qq{\n}; #---------------- sub showStartPage { #---------------- # Setup the form and start of table. 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{Group}\n}; print qq{\n}; print qq{
$lex{Values}\n}; print qq{\n}; print qq{$lex{'Separate with Spaces'}, $lex{'Blank=All'}
$lex{'Sort by'}\n}; print qq{
$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; }