#! /usr/bin/perl # Copyright 2001-2009 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. # ======= INAC (Indian Northern Affairs Canada) Attendance Report ======= # Get End date; Generate months up to end of enddate month. # We only print out days enrolled AND that student actually attended. # Column Format: Grade, Lastname, First, Middlename, Birthdate, Status # Number (Treaty Number), Reserve, Parent1 Name, then single columns # for each month (S,O,N,D,J,F,M,A,M,J). # Sorted by Reserve, Lastname, Firstname (1 Page per Reserve). my %lex = ('INAC Attendance Report' => 'INAC Attendance Report', 'Main' => 'Main', 'Attendance' => 'Attendance', 'Periods Per Day not defined for Grade' => 'Periods Per Day not defined for Grade', 'in global configuration for student' => 'in global configuration for student', 'View/Download' => 'View/Download', 'View Log File' => 'View Log File', 'Undefined' => 'Undefined', 'Last Name' => 'Last Name', 'First' => 'First', 'Middle' => 'Middle', 'Birthdate' => 'Birthdate', 'Status' => 'Status', 'Reserve' => 'Reserve', 'Mother' => 'Mother', 'School Days' => 'School Days', 'Error' => 'Error', 'Absent'=> 'Absent', 'Late' => 'Late', 'Date' => 'Date', 'Paper Size' => 'Paper Size', 'Letter' => 'Letter', 'Legal' => 'Legal', 'A4' => 'A4', 'Continue' => 'Continue', 'Records per Page' => 'Records per Page', ); my $self = 'rptinac.pl'; use DBI; use CGI; use Date::Business; use Number::Format qw(:all); # Constants my $defmaxrecords = 28; # Maximum records per PDF page. my $group = 'band'; my $pdf = '1'; my $html; # Read config variables eval require "../../etc/admin.conf"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } eval require "../../lib/libattend.pl"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } my $dsn = "DBI:mysql:$dbase"; $dbh = DBI->connect($dsn,$user,$password); $dbh->{mysql_enable_utf8} = 1; my @tim = localtime(time); my $year = $tim[5] + 1900; my $month = $tim[4] + 1; my $day = $tim[3]; if (length($month) == 1){ $month = "0".$month;} if (length($day) == 1){ $day = "0".$day;} my $currsdate = "$year-$month-$day"; my $currdate = "$month[$month] $day, $year"; my $q = new CGI; my %arr = $q->Vars; print $q->header( -charset, $charset ); # HTML Header print "$doctype\n". $lex{'INAC Attendance Report'}. " $chartype\n[ ". $lex{Main}. " | ". $lex{Attendance}. " ]
\n"; print "

". $lex{'INAC Attendance Report'}. "

\n"; if ( not $arr{page} ) { showStartPage(); } my $stopdate; if ($arr{date}){ $stopdate = $arr{date}; } else { $stopdate = $currsdate; } my $startdate = $schoolstart; # Functions from LibAttend @schoolmonths = mkSchoolMonths( $stopdate ); # Uses $schoolstartdate for starting date. # Returns array listing yyyy-mm months in order starting from 1 (zeroth is # blank) Extracting the mm component and using this as index on @month # or @shortmonth will give the month name. %schooldays = mkSchoolDays( $startdate, $stopdate ); # returns hash of schooldays in month. key is yyyy-mm and value is schooldays in month if ( $pdf ) { # Open TEX file, and print Header $logfile = "pdflog$$.txt"; $shortname = "inac$$"; $filename = "$shortname.tex"; open(TEX,">$filename") || die "Can't open tex file"; print_tex_doc_start(); # Setup the start of the file. } my $select; my $sth = $dbh->prepare("select * from student $select order by band, lastname, firstname"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my $studrows = $sth->rows; # Setup statement handle to find which table student is in. $sth5 = $dbh->prepare("select studnum from student where studnum = ?"); $curroom = -1; # Watch! Not a value entered for a reason...hopefully. $firstflag = 1; # Flag to watch for first "real" person (not withdrawn) while ( @student = $sth->fetchrow ){ $student[1] =~ s/\\/\//g; $studentname = "$student[1], $student[2] $student[3]"; $studnum = $student[4]; # Now let's find which table student from: student or studentwd $sth5->execute($student[4]); if ($DBI::errstr) { print $DBI::errstr; die;} my $active = $sth5->rows; # returns 1 if in student, 0 if not. if (not $active and $html){ $studentname = "$studentname"; } $oldroom = $curroom; $curroom = $student[58]; # band if ( $curroom ne $oldroom ) { # New Page Heading (band or group changes) if (not $firstflag) { print TEX "\n\\end{tabular}\n\n"; $linecount = 0; } else { $firstflag = 0;} print TEX "\\newpage\n\n"; &print_tex_header; # includes a begin{tabular} # Recalc the number of periods per day when class changes. $periodsperday = $g_ppd{$student[5]}; # student[5] is grade. if (not $periodsperday){ if ( not $student[5] ){ $student[5] = $lex{Undefined}. '!'; } print "

". $lex{'Periods Per Day not defined for Grade'}. "# $student[5] "; print $lex{'in global configuration for student'}; print " $student[2] $student[1].

\n"; die; } } # End of Header printing section # Print this student's record doAttSetup(); print_tex_record(); $linecount++; if ( $linecount >= $arr{maxrecords} ){ # New page. print TEX "\\end{tabular}\\newpage\n\n"; &print_tex_header; $linecount = 0; } } # End of main loop print TEX "% print_tex_end here\n"; print TEX "\\end{tabular}\n\n\\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{'INAC Attendance Report'}. "

[ ". $lex{Main}. " | ". $lex{Attendance}. " | ". $lex{'View Log File'}. " ] \n"; # ================ # Functions # ================ #---------------------- sub print_tex_doc_start { #---------------------- print TEX "\\documentclass[10pt,legalpaper,oneside,landscape]{article} \\usepackage{array,colortbl,rotating,inputenc} $a_latex_header \\renewcommand{\\familydefault}{\\sfdefault} \\pagestyle{empty} \\setlength{\\textwidth}{13in} \\setlength{\\textheight}{7.7in} \\setlength{\\hoffset}{-4.3in} \\setlength{\\voffset}{-0.8in} \\setlength{\\headsep}{10pt} \\setlength{\\headheight}{14pt} \\setlength{\\topmargin}{0pt} \\setlength{\\parindent}{0pt} \\setlength{\\tabcolsep}{5pt} \\setlength{\\extrarowheight}{3pt} \\pagestyle{headings} \\markright{$schoolname - $schoolyear \\hfill {\\bf ". $lex{'INAC Attendance Report'}. "} \\hfill $currdate -- Pg } \n\n \\begin{document}\n"; } # End of Print Tex Doc Start #------------------- sub print_tex_header { #------------------- # Up to 18 Cols: (8 + 10 months) # Grade, Lastname, Firstname, Middlename, Birthdate print TEX "\\begin{tabular}{|p{1cm}|p{3cm}|p{1.6cm}|p{2cm}|p{1.8cm}"; # Treaty, Band, Parent, Up to 10 Months. print TEX "|p{1.7cm}|p{2.2cm}|p{3.2cm}|"; for(1..$#schoolmonths){ print TEX "p{9mm}|"; } print TEX "}\\hline\n\n"; # Now print the column header line. print TEX "\\rowcolor[gray]{0.90}{\\bf Grade}"; print TEX "& {\\bf ". $lex{'Last Name'}. "} & {\\bf ". $lex{First}. "} &"; print TEX "{\\bf ". $lex{Middle}. "} &{\\bf ". $lex{Birthdate}. "} &"; print TEX "{\\bf ". $lex{Status}. "\\#} &{\\bf ". $lex{Reserve}. "} & \n"; print TEX "{\\bf ". $lex{Mother}. "}"; for( 1..$#schoolmonths ) { my ($ty,$tm) = split /-/,$schoolmonths[$_]; #$tm++; print TEX "& {\\bf $s_month[$tm]}"; } print TEX "\\\\ \\hline\n\n"; # Now print the schooldays in month print TEX "\\rowcolor[gray]{0.90}"; print TEX "& & & & & & & ". $lex{'School Days'}; for(1..$#schoolmonths){ print TEX "& {\\bf $schooldays{$schoolmonths[$_]} }"; } print TEX "\\\\ \\hline\n\n"; } #------------------- sub print_tex_record { #------------------- # Grade, Lastname, Firstname, Middlename print TEX "\\hfil $student[5]\\hfill& $student[1] & $student[2]"; print TEX "& $student[3] "; # Birthdate, Treaty#, print TEX "& $student[8] & $student[17] "; # Band Name, Mother Name print TEX "& $student[58] & $student[29] "; my $days = $schooldays - $absentdaytot; #Now print Monthly Records for (1..$#schoolmonths){ print TEX "& {\\footnotesize $absent{$_}/$enrolled{$_}}"; } print TEX " \\\\ \\hline\n"; } #--------------- sub doAttSetup { # Version with monthly attendance info #--------------- # Needs globals: @schoolmonths - ordering of school months. # %schooldays - days in each month in hash. # $periodsperday - number of periods in the school day. # my $studnum = shift; # make local version undef %absent; undef %tardy; undef %enrolled; # calculate attendance, one for each month. for (1..$#schoolmonths){ $absrec = calcMonthlyAttendance( $studnum, $schoolmonths[$_], $periodsperday, $stopdate, \%lex ); ($absent{$_},$tardy{$_}) = split /:/,$absrec; $absent{$_} = format_number( $absent{$_}, 1); #print "Num: $_ SN:$studnum MN:$schoolmonths[$_] AB:$absent{$_} #LT:$tardy{$_}
\n"; } # calculate enrollment, one for each month # First find starting value for $active... was student enrolled at start my $sth = $dbh->prepare("select type from transfer where studnum = ? and to_days(date) >= to_days('$schoolstart') order by date desc"); $sth->execute( $studnum ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr;} my $etype = $sth->fetchrow; my $sth1 = $dbh->prepare("select lastname, firstname from studentall where studnum = ?"); $sth1->execute( $studnum ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr;} my ($lastname, $firstname) = $sth1->fetchrow; # If withdraw during year or no record, must have been enrolled at start if ($etype eq 'withdraw' or not $etype){ $active = 1;} else { $active = 0;} #print "$lastname, $firstname ETYPE: $etype ACT: $active
\n"; for (1..$#schoolmonths){ my $enrolrec = &calcMonthlyEnrollment($studnum, $schoolmonths[$_], $active); ($enrolled{$_},$active) = split /:/,$enrolrec; #print "---SN: $studnum ACT: $active
\n"; #print "SN:$studnum Month:$schoolmonths[$_] ACT: $active
\n"; } } #---------------- sub showStartPage { #---------------- print "

\n"; print "\n"; print "\n"; # print "\n"; # print "\n"; print "\n"; # print "\n\n"; # Paper Size # $defaultpapersize =~ s/paper//; # strip out word paper so lex works; from admin.conf # my $defpaper = ucfirst( $defaultpapersize ); print "\n\n"; # print "\n "; # print "\n\n "; print "\n\n"; print "\n"; print "
". $lex{'Report Type'}. "
". $lex{Date}. "\n"; print "\n"; print "
". $lex{Group}. ""; # print "\n "; # print $lex{'Separate with Spaces'}. "
". $lex{'Paper Size'}. ""; print $lex{Legal}. "
". $lex{'Font Size'}. ""; # print "
". $lex{'Records per Page'}. ""; print "
\n"; print "\n"; print "\n"; exit; }