#!/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 "