#!/usr/bin/perl # Copyright 2001-2006 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 Medical Report' => 'Student Medical Report', 'Main' => 'Main', 'Name' => 'Name', 'Med' => 'Med', 'Medical' => 'Medical', 'Address' => 'Address', 'Parent 1' => 'Parent 1', 'Parent 2' => 'Parent 2', 'Hr' => 'Hr', 'Gr' => 'Gr', 'Bdate' => 'Bdate', 'Health' => 'Health', 'Print/View Medical Report' => 'Print/View Medical Report', 'View Log File' => 'View Log File', 'Room' => 'Room', ); my @month = ('January','February','March','April','May','June','July', 'August','September','October','November','December'); my @dow = ('Sunday','Monday','Tuesday','Wednesday','Thursday', 'Friday','Saturday'); my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $iddst) = localtime(time); $year = $year + 1900; my $currdate = "$dow[$wday], $month[$mon] $mday, $year"; my $q = new CGI; print $q->header; my %arr = $q->Vars; # Read config variables require "../etc/admin.conf" || die "Cannot read admin.conf!"; my $type = $arr{type}; # Type of Report: 'Web' or 'Pdf' my $search = $arr{search}; # Word(s) to search for in medical field. my @search = split /\s/,$search; my $select; if ($search){ $select = " where "; foreach my $key (@search){ # add each word into search $select .= " medical $sql{like} '%$key%' or "; } $select =~ s/or $//; # remove trailing 'or' } my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); my $sortorder = "homeroom, lastname, firstname"; my $sth = $dbh->prepare("select * from student $select order by $sortorder"); $sth->execute; if ($DBI::errstr){ print $DBI::errstr; die "$DBI::errstr: $! \n";} print "$doctype\n". $lex{'Student Medical Report'}; print "\n $chartype\n[ ". $lex{Main}. " ]

". $lex{'Student Medical Report'}. "

$schoolname - $currdate

\n"; if ($type eq 'Web'){ prWeb(); } else { # Pdf Report prPDFhead(); my $count = 0; my $curroom = -1; while (my @arr = $sth->fetchrow){ $count++; foreach my $field (@arr){ $field =~ s/&/\\&/g; $field =~ s/#/\\#/g; } $oldroom = $curroom; $curroom = $arr[6]; if ($curroom ne $oldroom) { $sth1 = $dbh->prepare("select lastname, firstname from staff where homeroom = '$curroom'"); $sth1->execute; if ($DBI::errstr){ print $DBI::errstr; die "$DBI::errstr: $! \n";} ($tlname, $tfname) = $sth1->fetchrow; if ($notfirst){ print TEX "\\end{tabular}\\newpage\n\n"; } else { $notfirst = 1; } print TEX "\\hfil {\\large\\sf $lex{Room}: $tfname $tlname "; print TEX "($curroom)}\\hfil\n\n"; print TEX "\\begin{tabular}{p{2.4in}p{1.5in}p{1.7in}p{1.7in}}"; print TEX "\\hline\n"; } print TEX "{\\bf $arr[1]}, $arr[2]~$arr[3] &"; print TEX "$arr[34] & $arr[29] & $arr[40] \\\\"; print TEX "{\\it Hr:}~$arr[6] {\\it Gr:}~$arr[5] "; print TEX "{\\it Bdate:}~$arr[8] &"; print TEX "$arr[35] &($arr[27]) H:~$arr[30] &($arr[38]) "; print TEX "H:~$arr[41]\\\\\n"; print TEX "{\\it $lex{Health}:}~$arr[10] {\\it $lex{Med}:}~$arr[18] &"; print TEX "$arr[36] & W:~$arr[31] & W:~$arr[42] \\\\ \\hline\n"; if (not ($count % 2)){ # put in space for line splits print TEX "\\end{tabular}\n\n"; print TEX "\\begin{tabular}{p{2.4in}p{1.5in}p{1.7in}p{1.7in}}"; print TEX "\\hline\n"; } } # End of While loop print TEX "\\end{tabular}"; # complete table. prPDFfoot(); # print rest of PDF web page. } print "
\n"; #### Functions ############# #-------- sub prWeb { # print Web/HTML version #-------- my $notfirst = 0; my $curroom = "-1"; while (@arr = $sth->fetchrow){ $oldroom = $curroom; $curroom = $arr[6]; if ($curroom ne $oldroom) { if ($notfirst){ print "\n"; } else { $notfirst = 1;} print "

Room: $curroom

\n"; print ""; print '"; } print "\n"; print "\n"; print "\n"; } # End of While loop print "
'. $lex{'Name'}. ' / '.$lex{Medical}. ''; print $lex{Address}; print ''. $lex{'Parent 1'}. ''. $lex{'Parent 2'}; print "
$arr[1], $arr[2] $arr[3]
\n"; print ''. $lex{Hr}. ": $arr[6] ". $lex{Gr}; print ":$arr[5] ". $lex{Bdate}. ": $arr[8]
\n"; print "". $lex{Health}. ": $arr[10] ". $lex{Med}; print ": $arr[18]
$arr[34]
$arr[35]
$arr[36]
Rel: $arr[27]
$arr[29]
H: $arr[30]
\n"; print "W: $arr[31]
Rel: $arr[38]
\n"; print "$arr[40]
H: $arr[41]
W: $arr[42]
\n"; # complete table. } # end of prWeb function. #------------ sub prPDFhead { #------------ $shortname = "medrep$$"; $fileName = "$shortname.tex"; open(TEX,">$fileName") || die "Can't open tex file"; print TEX "\\documentclass[10pt,letterpaper,oneside]{article}\n"; print TEX "\\usepackage{isolatin1,graphicx,array,newcent,colortbl} \\usepackage[pdftex,bookmarks=false,pdfstartview=FitH]{hyperref} \\setlength{\\textwidth}{7.50in} \\setlength{\\textheight}{10in} \\setlength{\\hoffset}{-0.6in} \\setlength{\\voffset}{-1in} \\setlength{\\topmargin}{0.2in} \\addtolength{\\evensidemargin}{-1in} \\addtolength{\\oddsidemargin}{-1in} \\setlength{\\extrarowheight}{2pt} \\setlength{\\parindent}{0in} \\pagestyle{myheadings}\n"; print TEX "\\markright{$schoolname\\hfill "; print TEX $lex{'Student Medical Report'}; print TEX "\\hfill $currdate -- Pg }\n\\begin{document}\n"; } #------------ sub prPDFfoot { #------------ print TEX "\\end{document}"; close TEX; system("$pdflatex $fileName > pdflog$$.txt"); system("mv $shortname.pdf $downloaddir"); system("mv pdflog$$.txt $downloaddir"); system("rm $shortname.*"); print "

"; print $lex{'Print/View Medical Report'}. "

\n"; print "

[ ". $lex{Main}. " |\n"; print ""; print $lex{'View Log File'}. " ]

\n"; } # end of pfPDFfoot