#!/usr/bin/perl
# Copyright Les Richardson 2001-2008
my %lex = ('Homeroom Assignment' => 'Homeroom Assignment',
'Update Homerooms' => 'Update Homerooms',
'Student' => 'Student',
'Hroom:Teacher' => 'Hroom:Teacher',
'Not Defined' => 'Not Defined',
'Not Found' => 'Not Found',
'Grade' => 'Grade',
'Main' => 'Main',
'Eoy' => 'Eoy',
'There was an error storing your data.' => 'There was an error storing your data.',
'Contact' => 'Contact',
'Record the following error' => 'Record the following error',
'Error' => 'Error',
'Your homeroom update is now stored.' => 'Your homeroom update is now stored.',
);
my $self = 'resethroom.pl';
use DBI;
use CGI;
my $q = new CGI;
print $q->header;
my %arr = $q->Vars;
eval require "../../etc/admin.conf";
if ( $@ ) {
print $lex{Error}. " $@
\n";
die $lex{Error}. " $@\n";
}
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
# Start Page Head
print "$doctype\n
". $lex{'Homeroom Assignment'}. "
$chartype\n\n";
print "[ ". $lex{Main}. " | \n";
print "". $lex{Eoy}. " ]\n";
print "". $lex{'Homeroom Assignment'}. "
\n";
# update records if necessary.
if ( $arr{flag} ) {
delete $arr{flag};
resetRecords();
}
# Read teachers into a list.
my $sth = $dbh->prepare("select id, lastname, firstname, grade, homeroom
from staff where homeroom != ''");
$sth->execute;
if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; }
# Put Teachers into Hash
while ( my ($id, $lastname, $firstname, $grade, $homeroom ) = $sth->fetchrow ){
my $tch = "$homeroom:$firstname $lastname:$grade:$id";
# homeroom : name : grade : teachid
$teacher{"$grade-$homeroom"} = $tch;
# Grade-Homeroom is the selector.
}
#foreach my $key (keys %teacher) { print "K:$key V:$teacher{$key}
\n"; }
$sth = $dbh->prepare("select studid, lastname, firstname, grade, homeroom from student
order by grade, lastname, firstname");
$sth->execute;
$rows = $sth->rows;
print "\n";
#---------------
sub resetRecords {
#---------------
#foreach my $key ( keys %arr ) { print "K:$key V:$arr{$key}
\n"; }
foreach my $key ( keys %arr ) {
my ($rmnum, $teacher) = split /:/,$arr{$key};
$rmnum =~ s/://;
#print "Room: $rmnum Snum: $key \n
" ;
$sth = $dbh->prepare("update student set homeroom = ? where studid = ?");
$sth->execute( $rmnum, $key );
if ($DBI::errstr ) { print $DBI::errstr; }
}
if ( not $DBI::errstr ) {
print ''. $lex{'Your homeroom update is now stored.'}. "
";
} else {
print "". $lex{'There was an error storing your data.'}. "\n";
print $lex{Contact}. " $adminname at $adminemail\n";
print $lex{'Record the following error'}. ": $DBI::errstr \n";
}
print "[ ". $lex{Main}. " | ". $lex{Eoy};
print " ]