#!/usr/bin/perl # Copyright 2001-2009 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; version 2 of # the License (only) # Passed values will be method - snap,sa4,sa6; date, and then all the # "studnum:period:subjsec:reason:late:date" (now with date) with value of 1 # This is common for all attendance entry methods. my %lex = ('Attendance Entry' => 'Attendance Entry', 'Main' => 'Main', 'Enter More Attendance Records (clear)' => 'Enter More Attendance Records (clear)', 'Your attendance is now stored' => 'Your attendance is now stored', 'There was an error storing your data' => 'There was an error storing your data', 'Please contact' => 'Please contact', 'Please record the following error' => 'Please record the following error', 'Enter More Attendance Records (go back)' => 'Enter More Attendance Records (go back)', 'Error' => 'Error', 'No Absences found' => 'No Absences found', 'Teacher Attendance Entry' => 'Teacher Attendance Entry', 'Saved' => 'Saved', ); use DBI; use CGI; use CGI::Session; my @tim = localtime(time); my $year = $tim[5] + 1900; my $month = $tim[4] + 1; my $day = $tim[3]; if ( length( $month ) == 1 ) { $month = '0'. $month; } if ( length( $day ) == 1 ) { $day = '0'. $day; } my $currdate = "$year-$month-$day"; my $q = new CGI; my %arr = $q->Vars; eval require "../etc/admin.conf"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } # fix incoming date value for day and month size. my ( $tempyr, $tempmon, $tempday ) = split /-/, $arr{date}; if ( length( $tempmon ) == 1 ) { $tempmon = '0'. $tempmon; } if ( length( $tempday ) == 1 ) { $tempday = '0'. $tempday; } $arr{date} = "$tempyr-$tempmon-$tempday"; my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); # Get Session my $session = new CGI::Session("driver:mysql;serializer:FreezeThaw", undef,{Handle => $dbh}) or die CGI::Session->errstr; my $userid = $session->param('userid'); print $session->header( -charset, $charset ); print "$doctype\n". $lex{'Attendance Entry'}. " \n"; print "[ ". $lex{Main}. " ]

". $lex{'Attendance Entry'}. "

\n"; # Put Entry in Teacher Attendance Table (tattend) # Updated: Change the date to the date of the record entered above. # This will allow teachers to see the last day they have entered # attendance. (ie. a tracking list) if ( $arr{method} eq 'multiday' ){ foreach my $date ( keys %multidates ) { $sth = $dbh->prepare("insert into tattend ( techid, date ) values ( ?, ?)"); $sth->execute( $userid, "$date 00:00" ); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } } } else { # normal attendance entry, (not multi). if ( $arr{date} ne $currdate ){ # We are entering for another day, not today. #print "Passed Date: $arr{date} Currdate: $currdate
\n"; $sth = $dbh->prepare("insert into tattend ( techid, date ) values ( ?, ?)"); $sth->execute( $userid, "$arr{date} 00:00" ); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } } else { $sth = $dbh->prepare("insert into tattend ( techid, date ) values ( ?, now())"); $sth->execute( $userid ); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } } } print "

". $lex{'Teacher Attendance Entry'}. q{ }. $lex{Saved}. "

\n"; my $entryflag = 0; foreach my $key ( keys %arr ) { if ( $arr{$key} == 1 ) { # We have a student entry $entryflag = 1; # there was an entry... my ($studnum,$period,$subject,$reason,$late,$date) = split /:/,$key; # if ( not $late ) { $late = 0; } # if (not $period){$period = $sql{default};} # if ( not $subject ){ $subject = undef; } # if (not $reason){$reason = $sql{default};} if ( $arr{method} eq 'multiday' ){ # use $date above not $arr{date} my $sth = $dbh->prepare("insert into attend values ( $sql{default},?,?,?,?,?,?)"); $sth->execute( $studnum, $date, $reason, $period, $subject, $late ); if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; } $multidates{$date} = 1; # needed for teacher entry dates. } else { my $sth = $dbh->prepare("insert into attend values ( $sql{default},?,?,?,?,?,?)"); $sth->execute( $studnum, $arr{date}, $reason, $period, $subject, $late ); } } } # End of ForEach loop if ( not $entryflag ) { # no attendance entries done print "

". $lex{'No Absences found'}. "

\n"; print "\n"; die; } if ( not $DBI::errstr ) { print "

". $lex{'Your attendance is now stored'}. ".

\n"; } else { print "

". $lex{'There was an error storing your data'}. ".\n"; print $lex{'Please contact'}. " $adminname \n"; print "$adminemail\n"; print $lex{'Please record the following error'}. " $DBI::errstr

\n"; } print "

[ ". $lex{Main}. " ]\n"; print "

\n"; print "\n"; print "
\n"; if ( $arr{method} eq 'multiday' ){ # 3 jumps back. print "
\n"; } else { print "
\n"; } print "

\n";