#!/usr/bin/perl
# Copyright 2001-2018 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 = ('Teacher' => 'Teacher',
'Error' => 'Error',
'Main' => 'Main',
'Attendance' => 'Attendance',
'Report' => 'Report',
'Entry' => 'Entry',
'Month' => 'Month',
'Start' => 'Start',
'Months' => 'Months',
'Date' => 'Date',
'Start Date' => 'Start Date',
'End Date' => 'End Date',
'Continue' => 'Continue',
'Missing' => 'Missing',
'Grade' => 'Grade',
'Student' => 'Student',
'Enrollment' => 'Enrollment',
'Absent' => 'Absent',
'Attendance' => 'Attendance',
'Absent' => 'Absent',
'Total' => 'Total',
'Week of' => 'Week of',
'School' => 'School',
'Administration' => 'Administration',
'Please Log In' => 'Please Log In',
);
my $self = 'rpttattend_tch.pl';
use DBI;
use CGI;
use CGI::Session;
use Time::JulianDay;
use Number::Format qw(:all);
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);
$dbh->{mysql_enable_utf8} = 1;
# Get Session
my $session = new CGI::Session("driver:mysql;serializer:FreezeThaw",
undef,{Handle => $dbh}) or die CGI::Session->errstr;
if ( not $session->param('logged_in') ){
my $userid = $session->param('userid');
print $session->header( -charset, $charset );
print qq{$doctype\n
\n};
print qq{
$lex{'Please Log In'}
\n};
print qq{[ $lex{Main} ]\n};
exit;
}
my $userid = $session->param('userid');
my $duration = $session->param('duration');
$session->expire('logged_in', $duration );
print $session->header( -charset, $charset );
my $q = new CGI;
my %arr = $q->Vars;
# Set 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 $title = "$lex{Teacher} $lex{Attendance} $lex{Entry} $lex{Report}";
print qq{$doctype\n$title\n};
print qq{\n};
print qq{$chartype\n\n};
print qq{[ $lex{Main} ]\n};
print qq{
$title
\n};
if ( not $arr{page} ) {
showStartPage();
} elsif ( $arr{page} == 1 ) {
delete $arr{page};
showReport();
}
#----------------
sub showStartPage {
#----------------
my @months = ();
my %months = ();
my ($sy, $sm, $sd) = split('-', $schoolstart); # schoolstart is global var from config.
my $yrmo = "$sy-$sm";
push @months, $yrmo;
$months{$yrmo} = "$s_month[$sm], $sy";
for my $i (1..10) {
my $mo = $sm + $i;
my $yr = $sy;
if ( $mo > 12 ) {
$mo = $mo - 12;
$yr++;
}
my $yrmo = "$yr-$mo";
push @months, $yrmo;
$months{$yrmo} = "$s_month[$mo], $yr";
}
print qq{\n};
print qq{\n};
exit;
}
#-------------
sub showReport {
#-------------
# foreach my $key ( sort keys %arr ) { print qq{K:$key V:$arr{$key} \n}; }
# duration(1-5), startmonth (yyyy-dd)
if ( not $arr{startmonth} or not $arr{duration} ) {
print qq{
Missing Start Month or Duration
\n};
print qq{\n};
exit;
}
# Get dow of first day of month.
my $firstday = $arr{startmonth}. '-01';
my $firstjd = julian_day( split('-',$firstday) );
my $firstdow = day_of_week( $firstjd );
my $firstmondayjd = $firstjd - ($firstdow - 1);
#print qq{$firstday DOW:$firstdow \n};
#print qq{FirstJD:$firstjd MondayJD:$firstmondayjd \n};
# Calculate the ending jd based on given duration.
my ($sy, $sm) = split('-', $arr{startmonth});
$sm += $arr{duration};
if ( $sm > 12 ) {
$sm = $sm - 12;
$sy++;
}
my $endjd = julian_day($sy, $sm, '01' );
my @mondays = ();
my %mondays = ();
push @mondays, $firstmondayjd;
$mondays{$firstmondayjd} = join('-', inverse_julian_day( $firstmondayjd ));
my $mondayjd = $firstmondayjd + 7;
while ( $mondayjd < $endjd ) {
push @mondays, $mondayjd;
$mondays{$mondayjd} = join('-', inverse_julian_day( $mondayjd ));
$mondayjd += 7;
}
# Find current teachers that do attendance, sort by name
my @teachers = ();
# my $sth = $dbh->prepare("select userid from staff
# where doatt = 'Y' or doatt = 1 order by lastname, firstname");
# $sth->execute;
# if ( DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; }
# while ( my $userid = $sth->fetchrow ) {
# push @teachers, $userid;
# }
# push @teachers, 'admin'; # user for admin site
push @teachers, $userid; # from login.
# Get Staff Name
my $sth1 = $dbh->prepare("select lastname, firstname, doatt from staff where userid = ?");
my $first = 1;
foreach my $userid ( @teachers ) {
$sth1->execute( $userid );
if ( DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; }
my ($lastname, $firstname, $doatt ) = $sth1->fetchrow;
if ( $doatt ne 'Y' or not $doatt ) {
print qq{