#!/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 $self = 'evalpwrdel.pl';
my %lex = ('POWER Delete Evaluation/Subject Enrollment Records' =>
'POWER Delete Evaluation/Subject Enrollment Records',
'No Subject Found!' => 'No Subject Found!',
'Erase Checked Records' => 'Erase Checked Records',
'Main' => 'Main',
'Report Card' => 'Report Card',
'Name' => 'Name',
'Term' => 'Term',
'Delete' => 'Delete',
'Values' => 'Values',
'Withdrawn' => 'Withdrawn',
'NOTE' => 'NOTE',
'There is NO confirmation checking' => 'There is NO confirmation checking',
'These records are deleted immediately upon clicking this button!' =>
'These records are deleted immediately upon clicking this button!',
'Your selected evaluation records are now erased' =>
'Your selected evaluation records are now erased',
'Edit/Delete Enrollment/Evaluation Records' =>
'Edit/Delete Enrollment/Evaluation Records',
'withdraw' => 'withdraw',
);
use DBI;
use CGI;
my $q = new CGI;
print $q->header;
my %arr = $q->Vars;
my $subjsec = $arr{subj};
my $checked = $arr{checked};
eval require "../../etc/admin.conf";
if ( $@ ) {
print $lex{Error}. " $@ \n";
die $lex{Error}. " $@\n";
}
# HTML Header
print "$doctype\n
\n";
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
if ( $arr{flag} ) {
delete $arr{flag};
deleteRecords();
}
# Find and print subject name...
my $sth = $dbh->prepare("select description from subject where subjsec = ?");
$sth->execute( $subjsec );
if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; }
my $description = $sth->fetchrow;
if ( not $description ){ $description = $lex{'No Subject Found!'}; }
print "
$description
($subjsec)
\n";
my $sth = $dbh->prepare("select distinct e.studnum, s.lastname, s.firstname
from eval as e
left outer join studentall as s on e.studnum = s.studnum
where e.subjcode = ? group by e.studnum
order by s.lastname, s.firstname");
# Previous select to find all values for individual edits...
# my $sth = $dbh->prepare("select eval.id, eval.term, eval.comment, eval.a1,
# eval.studnum, studentall.lastname, studentall.firstname from eval
# left outer join studentall on eval.studnum = studentall.studnum
# where eval.subjcode = ?
# order by studentall.lastname, studentall.firstname, eval.term");
$sth->execute( $subjsec );
if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; }
# Table/Form start
print "\n";
print "
". $lex{'NOTE'}. ": ". $lex{'There is NO confirmation checking'}. ". \n";
print $lex{'These records are deleted immediately upon clicking this button!'}. "
\n";
print "
\n";
#----------------
sub deleteRecords {
#----------------
my $subjsec = $arr{subjsec};
delete $arr{subjsec};
#foreach my $key (keys %arr ) { print "K:$key V:$arr{$key} \n"; }
my $sth = $dbh->prepare("delete from eval where studnum = ? and subjcode = ?");
foreach my $studnum ( keys %arr ) {
$sth->execute( $studnum, $subjsec );
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
}
if ( not $DBI::errstr ) {
print "
". $lex{'Your selected evaluation records are now erased'}. ".
\n";
} else {
print "
". $lex{'There was an error storing your data'}. ". \n";
print $lex{Contact}. " $adminname $adminemail \n";
print $lex{'Please record the following error'}. ": $DBI::errstr \n";
}
print "