#!/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; either version 2 of # the License, or (at your option) any later version. my %lex = ('Attendance Records' => 'Attendance Records', 'Main' => 'Main', 'Home Room' => 'Home Room', 'Please Log In' => 'Please Log In', 'Student' => 'Student', 'Date' => 'Date', 'Period' => 'Period', 'Reason' => 'Reason', 'Edit' => 'Edit', 'Delete' => 'Delete', 'Duration' => 'Duration', 'Error' => 'Error', ); use DBI; use CGI qw/escape unescape/; use CGI::Session; eval require "../etc/admin.conf"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); my $q = CGI->new; my %arr = $q->Vars; # Get passed values my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $iddst) = localtime(time); $year = $year + 1900; $mon++; $wday++; my $currdate = "$dow[$wday], $month[$mon] $mday, $year"; # Setup Session my $session = new CGI::Session("driver:$dbtype;serializer:FreezeThaw", undef,{Handle => $dbh}) or die CGI::Session->errstr; # Get Session Values (a defined userid means it was passed) my $userid; if ( not $session->param('logged_in') ){ $userid = $session->param('userid'); print $q->header( -charset, $charset ); printHtmlHeader(); print "

". $lex{'Please Log In'}. "

\n"; print "\n"; die; } # Ok, we have a login. Values below we have in environment. $userid = $session->param('userid'); my $duration = $session->param('duration'); if (not ($duration =~ m/\+/) ) { $duration = '+'. $duration. 'm'; } $session->expire('logged_in',$duration); # duration is already in +20m format; print $session->header( -charset, $charset ); # Get the users homeroom(s) $sth = $dbh->prepare("select distinct homeroom from staff where userid = ?"); $sth->execute( $userid ); if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } while ( my $hr = $sth->fetchrow ) { push @homerooms, $hr; } # Print top of page printHtmlHeader(); print $lex{Duration}. ": $duration\n"; print "

". $lex{Edit}. '/'. $lex{Delete}. q{ }. $lex{'Attendance Records'}; print "

$currdate "; for my $hr ( @homerooms ) { print "| $hr\n"; }; print "]

\n"; # Now select the student attendance records for this room my $fieldlist = "a.attid, a.studentid, a.absdate, a.reason, ". "a.period, s.lastname, s.firstname"; my $sth = $dbh->prepare("select $fieldlist from attend as a, studentall as s where a.studentid = s.studnum and s.homeroom = ? order by a.absdate desc, s.lastname, s.firstname"); # Do all homerooms for my $hr ( @homerooms ) { print "\n"; print "
". $lex{'Home Room'}; print " $hr
"; print "\n"; print '\n"; $sth->execute( $hr ); if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } while ( my ( $attid, $studentid, $absdate, $reason, $period, $lastname, $firstname) = $sth->fetchrow ) { print ""; print "\n"; print "\n"; print "\n"; } print "
'. $lex{Student}. ''. $lex{Date}. ''; print $lex{Period}. ' – '. $lex{Reason}. ''. $lex{Edit}; print ''. $lex{Delete}. "
$lastname $firstname$absdate$period - $reason
\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "

\n\n"; } print "
\n"; #------------------ sub printHtmlHeader { #------------------ print "$doctype\n". $lex{Edit}. '/'. $lex{Delete}; print q{ }. $lex{'Attendance Records'}. "\n"; print "\n"; print "$chartype\n\n"; print "[ ". $lex{Main}. " ]\n"; }