#!/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". $lex{'POWER Delete Evaluation/Subject Enrollment Records'}. "\n"; print " $chartype\n\n"; print "[ ". $lex{Main}. " |\n"; print "". $lex{'Report Card'}. " ]\n"; print "

". $lex{'POWER Delete Evaluation/Subject Enrollment Records'}. "

\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 "
"; print "\n"; print "\n"; print "\n"; print "\n"; while (my ($id,$term,$comment,$a1, $studnum, $lastname,$firstname ) = $sth->fetchrow){ # Get the Name to check which table student is in... $sth1 = $dbh->prepare("select lastname,firstname from student where studnum = '$studnum'"); $sth1->execute; if ($DBI::errstr){ print $DBI::errstr; die;} my ($currlastname, $currfirstname) = $sth1->fetchrow; my $name; # combined name if (not $currlastname){ $name = "". $lex{Withdrawn}. "$lastname, $firstname"; } else { $name = "$lastname, $firstname"; } print "\n"; } print "
". $lex{Name}. "". $lex{Term}. "". $lex{Delete}; print "". $lex{Values}. "
$name ($studnum)$term $a1 $comment
\n"; 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 "

[ "; print $lex{'Edit/Delete Enrollment/Evaluation Records'}. " | \n"; print "". $lex{'Report Card'}. " ]

\n"; print "\n"; } #------------ sub wrEvalJrl { # write subject enrollment recs into eval journal (evaljrl table) #------------ # Passed subject-section number (unique for a subject), and student number. my $subjsec = shift; my $studnum = shift; # Get Student Information my $sth = $dbh->prepare("select lastname, firstname, initial, birthdate, provnum from studentall where studnum = ?"); $sth->execute( $studnum ); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } my ($lastname, $firstname, $initial, $birthdate, $provnum) = $sth->fetchrow; # Add a single record for this student in this subject to evaljrl table. $lastname = $dbh->quote( $lastname ); $firstname = $dbh->quote( $firstname ); $initial = $dbh->quote( $initial ); $withdraw = $dbh->quote( $lex{withdraw} ); $sth = $dbh->prepare("insert into evaljrl values ( $sql{default},'$subjsec','$studnum', now(), $withdraw, 'Y', $lastname, $firstname, $initial, '$birthdate','$provnum')"); $sth->execute; if ($DBI::errstr){ print $DBI::errstr; die; } }