#!/usr/bin/perl # Copyright 2001-2008 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. # Dual Run Script: cgi and tcgi %lex = ('View Students' => 'View Students', 'View Withdrawn Students' => 'View Withdrawn Students', 'Main' => 'Main', 'Top' => 'Top', 'No Records Found' => 'No Records Found', 'All Records' => 'All Records', 'Error' => 'Error', 'Continue' => 'Continue', 'Lastname' => 'Lastname', 'Birthdate' => 'Birthdate', 'Grade' => 'Grade', 'Homeroom' => 'Homeroom', 'Select' => 'Select', 'Sort by' => 'Sort by', 'Select by' => 'Select by', ); use DBI; use CGI; use Cwd; my $q = new CGI; print $q->header; my %arr = $q->Vars; my $mode; # normal or withdrawn mode my $table = 'student'; if ($arr{table} eq 'wd') { $mode = 'wd'; $table = 'studentwd'; } # Read config variables eval require "../etc/admin.conf"; if ( $@ ) { print $lex{Error}. " $@
\n"; die $lex{Error}. " $@\n"; } eval require "../lib/libmeta.pl"; if ( $@ ) { print $lex{Error}. " $@
\n"; die $lex{Error}. " $@\n"; } 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"; # Get current dir so know what CSS to display; if ( getcwd() =~ /tcgi/ ){ # we are in tcgi $css = $tchcss; $homepage = $tchpage; } # Display top of page print "$doctype\n",$lex{'View Students'}," \n"; if ($mode eq 'wd') { print "\n"; } print "$chartype\n\n"; print "[ ". $lex{Main}. " ]\n"; # Show start page if only beginning. if ( not $arr{page} ) { showStartPage(); } else { delete $arr{page}; } my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); # Passed: groupType, groupValue, sortorder. my ($group, $groupDisplay, $select); if ( $arr{groupType} eq $lex{Grade} ) { $group = 'grade'; } else { $group = 'homeroom'; } if ( $arr{groupValue} ) { my $grpval = $dbh->quote( $arr{groupValue} ); $select = "where $group = $grpval"; $groupDisplay = ucfirst( $arr{groupType} ). " $arr{groupValue}"; } else { # no select; reset groupValue $groupDisplay = $lex{'All Records'}; } my $sortorder = "lastname, firstname"; if ( $arr{sortorder} eq $lex{Birthdate} ) { $sortorder = "birthdate"; } my $sth = $dbh->prepare("select * from $table $select order by $sortorder"); $sth->execute; if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } my $rows = $sth->rows; print "

"; if ($mode eq 'wd') { print $lex{'View Withdrawn Students'}; } else { print $lex{'View Students'}; } print " - $groupDisplay

$currdate

\n"; if ($rows < 1){ print "

",$lex{'No Records Found'},".

\n"; die; } # Read in Template eval open (FH,"<../template/studentview.tpl"); if ( $@ ) { print $lex{Error}. " $@
\n"; die $lex{Error}. " $@\n"; } my $text; { local $/; $text = ; close FH;} my $sth1 = $dbh->prepare("select fieldid,arrayidx from meta where tableid = 'student'"); $sth1->execute; if ($DBI::errstr){ print $DBI::errstr; die;} while (my ($fieldid,$arrayidx) = $sth1->fetchrow){ $values{$fieldid} = '$arr['.$arrayidx.']'; } # Parse for simple field replacement / highlighting **name** elements #while ( $text =~ m/\*\*([a-zA-Z]*)\*\*/g){ # push @replace, $1; #} # Create Hash to hold replacement text. #foreach my $val (@replace){ # $replacement{$val} = &metaReplace('student',$val); #} # Now put replacement text back in. $text =~ s{\<\#(.*?)\#\>} { exists($values{$1}) ? $values{$1} : $1 }gsex; $result = 'print <<"EOF";'."\n".$text."\n".'EOF'; while (my @arr = $sth->fetchrow ){ eval $result; } print "[ $lex{'Top'} ] \n"; #---------------- sub showStartPage { #---------------- # print sortorder and selection input form. print "

". $lex{'View Students'}. "

\n"; print "
\n"; print "\n"; if ( $arr{table} ) { # for withdrawn mode. print "\n"; } print "\n"; print "\n"; print "\n"; print "\n"; print "
". $lex{'Sort by'}. "\n"; print "
". $lex{'Select by'}. "\n"; print "\n"; print "
\n"; print "
\n"; print "\n"; exit 0; }