#!/usr/bin/perl
# Copyright 2001-2007 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;
$q = new CGI;
print $q->header;
my %arr = $q->Vars;
my $subjsec = $arr{subj};
my $checked = $arr{checked};
require "../../etc/admin.conf" or die "Cannot open admin.conf!";
# HTML Header
print "$doctype\n
\n";
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
if ( $arr{flag} ) {
deleteRecords();
die;
}
# 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";
$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 {
#----------------
delete $arr{flag};
#foreach my $key (keys %arr ) { print "K:$key V:$arr{$key} \n"; }
foreach my $key ( keys %arr ) {
#print "Key: $key Value:$arr{$key}\n " ;
# Get studnum and subjsec
$sth = $dbh->prepare("select studnum, subjcode from eval where id = ?");
$sth->execute( $key );
my ( $studnum, $subjsec ) = $sth->fetchrow;
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
$sth = $dbh->prepare("delete from eval where id = ?");
$sth->execute( $key );
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
# Now check if this is all records for this student in this subject. If so,
# then put in a journal entry for withdrawal
$sth = $dbh->prepare("select count(*) from eval where
subjcode = ? and studnum = ?");
$sth->execute( $subjsec, $studnum );
my $evalcount = $sth->fetchrow;
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
if ($evalcount < 1){ # no records left....so write a record...
wrEvalJrl( $subjsec, $studnum);
}
}
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{'Please contact'}. " $adminname $adminemail";
print $lex{'Please record the following error'}. ": $DBI::errstr \n";
}
print "