#!/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. my %lex = ('Reset Attendance Reasons' => 'Reset Attendance Reasons', 'Name' => 'Name', 'Reason' => 'Reason', 'Period' => 'Period', 'Date' => 'Date', 'Continue' => 'Continue', 'Your selected records are now updated' => 'Your selected records are now updated', 'There was an error updating your data' => 'There was an error updating your data', 'Attendance' => 'Attendance', 'Records' => 'Records', 'Red = Withdrawn' => 'Red = Withdrawn', ); use DBI; use CGI; my @month = ('','January','February','March','April','May','June','July', 'August','September','October','November','December'); # 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"; my $q = new CGI; print $q->header; my %arr = $q->Vars; require "../etc/admin.conf" or die "Cannot open admin.conf!"; my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); my $date; if ($arr{date}){ $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 = $currdate; } # Main Page Header. print "$doctype\n". $lex{'Reset Attendance Reasons'}. " $chartype\n[ Attendance Page ]\n"; # Start of Page print "

". $lex{'Reset Attendance Reasons'}. "

Reset Date: $date

\n"; if ($arr{updateflag}) { delete $arr{updateflag}; updateReason(); } # Start of form setup. print "
\n"; print "\n"; print "\n\n"; my $sth = $dbh->prepare("select a.* from attend as a, studentall as s where s.studnum = a.studentid and a.absdate = ? order by s.lastname, s.firstname, a.period"); $sth->execute( $date ); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr;} my $rows = $sth->rows; print "\n"; my $sth1 = $dbh->prepare("select lastname,firstname from student where studnum = ?"); 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\n"; } print "
". $lex{Name}. "". $lex{Reason}. ""; print $lex{Period}. "". $lex{Date}. "
". $lex{Records}. ": $rows  "; print $lex{'Red = Withdrawn'}. "
$name ($studnum)$period$date
\n"; print "
\n"; #--------------- sub updateReason { #--------------- foreach $key (keys(%arr)) { #print "Key: $key Value:$arr{$key}\n
" ; $sth = $dbh->prepare("update attend set reason = ? where attid = ?"); $sth->execute( $arr{$key}, $key ); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } } if (not $DBI::errstr ) { print "

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

"; } else { print "

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

\n"; } print "

[ ". $lex{Attendance}. " ]

\n"; exit; }