#!/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. my %lex = ('You cannot set both promote and demote!' => 'You cannot set both promote and demote!', 'Main' => 'Main', 'Eoy' => 'Eoy', 'Reset Grade Assignment' => 'Reset Grade Assignment', 'Student' => 'Student', 'New Grade' => 'New Grade', 'Hr/Gr' => 'Hr/Gr', 'Update Grades' => 'Update Grades', 'Hrm' => 'Hrm', 'Gr' => 'Gr', 'Your update to student grades is now stored.' => 'Your update to student grades is now stored.', 'There was an error storing your data.' => 'There was an error storing your data.', 'Contact' => 'Contact', 'Record the following error' => 'Record the following error', ); my $self = 'resetgrade.pl'; use DBI; use CGI; $q = new CGI; print $q->header; my %arr = $q->Vars; my $promote = $arr{promote}; my $demote = $arr{demote}; if ($demote and $promote){ print $lex{'You cannot set both promote and demote!'}. "\n"; die; } 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); # Print Page Header print "$doctype\n". $lex{'Reset Grade Assignment'}. " $chartype\n\n"; print "[ ". $lex{Main}. " | \n"; print "". $lex{Eoy}. " ]\n"; print "

$schoolname ". $lex{'Reset Grade Assignment'}. "

\n"; if ( $arr{writeflag} ) { delete $arr{writeflag}; resetGrades(); } # Stuff all grades into an array; my $sth = $dbh->prepare("select distinct grade from student"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die;} my $rows = $sth->rows; my @gradearray; for ( 1..$rows ){ $grade = $sth->fetchrow; push @gradearray,$grade; } @gradearray = sort @gradearray; # Start Form print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; my $sth = $dbh->prepare("select studid, lastname, firstname, grade, homeroom from student order by homeroom,lastname,firstname"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } while ( my ($studid, $lastname, $firstname, $grade, $homeroom) = $sth->fetchrow ) { if ( $promote ){ if ($grade eq 'PPK'){ $grade = 'PK'; } elsif ( $grade eq 'PK'){ $grade = 'K'; } elsif ( $grade eq 'K'){ $grade = '1'; } else { $grade++; } } if ( $demote ){ if ($grade eq 'PK'){ $grade = 'PPK';} elsif ($grade eq 'K'){ $grade = 'PK';} elsif ($grade == '1'){ $grade = 'K';} else {$grade--;} } print "\n"; print "\n\n"; } # End of loop print "\n"; print "
". $lex{Student}. "". $lex{'Hr/Gr'}. ""; print $lex{'New Grade'}. "
\n"; print "
$lastname, $firstname". $lex{Hrm}; print ":$homeroom / ". $lex{Gr}. ":$grade
\n"; print "
\n"; #-------------- sub resetGrades { #-------------- #foreach my $key (keys %arr ) { print "K:$key V:$arr{$key}
\n"; } $sth = $dbh->prepare("select grade from student where studid = ?"); $sth1 = $dbh->prepare("update student set grade = ? where studid = ?"); foreach my $key ( keys %arr ) { # Get Current Grade $sth->execute( $key ); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } my $grade = $sth->fetchrow; # Update if necessary if ( $grade ne $arr{$key} ){ # different; do an update $sth1->execute( $arr{$key}, $key ); #print "K:$key V:$arr{$key}
\n"; if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } } } if (not $DBI::errstr ) { print "

". $lex{'Your update to student grades is now stored.'}. "

\n"; } 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 " ]

\n"; exit; }