#!/usr/bin/perl # Copyright 2001-2006 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. use DBI; use CGI; my @month = ('','January','February','March','April','May','June','July', 'August','September','October','November','December'); my %lex = ('Power Delete Attendance' => 'Power Delete Attendance', 'Name' => 'Name', 'Subject' => 'Subject', 'Period' => 'Period', 'Reason' => 'Reason', 'Date' => 'Date', 'Delete' => 'Delete', 'Selected Records' => 'Selected Records', 'There will be no confirmation of deletion.' => 'There will be no confirmation of deletion.', 'Your selected records are now deleted' => 'Your selected records are now deleted', 'There was an error deleting your data' => 'There was an error deleting your data', 'Attendance' => 'Attendance', 'Records' => 'Records' ); # Get Date my @tim = localtime(time); my $year = @tim[5] + 1900; my $month = @tim[4] + 1; my $day = @tim[3]; my $currdate = "$year-$month-$day"; my $currdate1 = "@month[$month] $day, $year"; require "../etc/admin.conf" or die "Cannot open admin.conf!"; $dsn = "DBI:$dbtype:dbname=$dbase"; $dbh = DBI->connect($dsn,$user,$password); $q = new CGI; print $q->header; %arr = $q->Vars; # Print Page Head print "$doctype\n". $lex{'Power Delete Attendance'}. " $chartype\n[ Main | Attendance ]\n"; if (not $arr{date}){ $date = $currdate; } elsif (not ($arr{date} =~ m/[-]/)){ #We have a date, check for "-" presence $day = substr($arr{date},4,2); $month = substr($arr{date},2,2); $year = "20".substr($arr{date},0,2); $date = "$year-$month-$day"; # Date to reset } else { $date = $arr{date}; } print "

". $lex{'Power Delete Attendance'}. "

Date: $date\n"; if ($arr{deleteflag}) { deleteRecord(); die; } # Setup Form print "
\n"; print "\n"; $sth = $dbh->prepare("select * from attend where absdate = '$date' order by studentid, period"); $sth->execute; if ($DBI::errstr){ print $DBI::errstr; die;} $rows = $sth->rows; print "\n"; print "\n\n"; my $sth1 = $dbh->prepare("select lastname,firstname from student where studnum = ?"); $currstud = -1; for (1..$rows){ my ($attid, $studnum, $absdate, $reason, $period, $subjsec,$late) = $sth->fetchrow; my ($lastname, $firstname, $name); # setup these vars... # Get the Name from Student $sth1->execute($studnum); if ($DBI::errstr){ print $DBI::errstr; die;} ($lastname, $firstname) = $sth1->fetchrow; if (not $lastname){ my $sth2 = $dbh->prepare("select lastname,firstname from studentall where studnum = '$studnum'"); $sth2->execute; if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr;} ($lastname, $firstname) = $sth2->fetchrow; if (not $lastname) { $lastname = 'Not Found'; } $name = "$lastname, $firstname"; } else { $name = "$lastname, $firstname"; } $oldstud = $currstud; $currstud = $studnum; if ($currstud != $oldstud){ # reset color if ($color eq 'blue'){ $color = 'gray'; } else { $color = 'blue';} } print "\n"; print "\n"; print "\n"; } print "
". $lex{Records}. ": $rows  Red = Withdrawn"; print "
". $lex{Name}. "". $lex{Subject}. ""; print $lex{Period}. "". $lex{Reason}. ""; print $lex{Date}. "". $lex{Delete}. "
$name ($studnum)$subjsec$period$reason$absdate"; print "
\n"; print "

\n"; print "

". $lex{'There will be no confirmation of deletion.'}. "
\n"; print "\n

\n"; #--------------- sub deleteRecord { #--------------- delete $arr{deleteflag}; foreach my $key (keys %arr) { print "Key: $key Value: $arr{$key}
\n" ; $sth = $dbh->prepare("delete from attend where attid = '$key'"); $sth->execute; if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } } if (not $DBI::errstr ) { print "

". $lex{'Your selected records are now deleted'}."

"; } else { print "

". $lex{'There was an error deleting your data'}; print $DBI::errstr, "

\n"; } print "

[ ". $lex{Attendance}. " ]

\n"; }