#!/usr/bin/perl
# Copyright 2001-2020 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 $self = 'tattCrsEdit.pl'; # Edit attendance by subject records.
my %lex = ('Attendance Records' => 'Attendance Records',
'Main' => 'Main',
'Homeroom' => 'Homeroom',
'Please Log In' => 'Please Log In',
'Student' => 'Student',
'Date' => 'Date',
'Period' => 'Period',
'Reason' => 'Reason',
'Edit' => 'Edit',
'Delete' => 'Delete',
'Duration' => 'Duration',
'Error' => 'Error',
'Not Found' => 'Not Found',
'Subjects' => 'Subjects',
'Course' => 'Course',
'Select' => 'Select',
'Months' => 'Months',
'Continue' => 'Continue',
);
use DBI;
use CGI;
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;
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";
my $userid; # no need for session, just get userid.
if ( not defined $arr{userid} ) {
$userid = $ENV{'REMOTE_USER'};
} else {
$userid = $arr{userid};
}
print $q->header( -charset, $charset );
# Print top of page
my $title = qq{$lex{Edit}/$lex{Delete} $lex{'Attendance Records'}};
print qq{$doctype\n
\n};
if ( not $arr{page} ) {
showStartPage();
} elsif ( $arr{page} == 1 ) {
delete $arr{page};
selectRecords();
} elsif ( $arr{page} == 2 ) {
delete $arr{page};
delEditStudents(); # delete immediately, then show Edit forms.
} elsif ( $arr{page} == 3 ) {
delete $arr{page};
updateRecords(); # update any record edits.
} elsif ( $arr{page} == 4 ) {
delete $arr{page};
selectStudentRecords(); # called by attEntry.pl to edit single student/course.
}
#----------------
sub showStartPage { # Select Month or Student.
#----------------
print qq{
$currdate
\n};
# needed to load $additionalcomments subject description (in order to skip).
my $sth = $dbh->prepare("select id, datavalue from conf_system where dataname = ?");
foreach my $field (r_AdditionalComments ) {
$sth->execute( $field );
if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; }
while ( my ($id, $datavalue) = $sth->fetchrow ) {
eval $datavalue;
if ( $@ ) {
print qq{$lex{Error}: $@ \n};
die "$lex{Error}: $@\n";
}
}
}
# Get the user's courses (all).
my @courses;
$sth = $dbh->prepare("select subjsec from subject where teacher = ?
order by description");
$sth->execute( $userid );
if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; }
while ( my $subjsec = $sth->fetchrow) {
if ( $r_AdditionalComments{$subjsec} ) { next; } # skip any global, additional comments)
push @courses, $subjsec;
}
if ( not @courses ) {
print qq{
No Courses Found
\n};
print qq{\n};
exit;
}
# get distinct year-month values from attend table.
my $sth = $dbh->prepare("select distinct year(absdate), month(absdate) from attend
where subjsec = ?");
my %yrmo;
foreach my $subjsec ( @courses ) {
$sth->execute($subjsec);
if ( DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; }
while ( my ($year, $month) = $sth->fetchrow ) {
if ( length $month == 1 ) { $month = '0'. $month; }
$val = qq{$year-$month};
$yrmo{$val} = 1;
# print qq{
Subjsec:$subjsec Year:$year MO:$month
\n};
}
}
# Pass this to next script to save this calc again.
my $fullyrmo = join(',', sort keys %yrmo );
my $sth1 = $dbh->prepare("select description, startrptperiod, endrptperiod from subject where subjsec = ?");
my $courses = join(',',@courses ); # for passing to next script.
# get sorted courses and descriptions.
my (%sort, %desc, %terms);
foreach my $subjsec ( @courses ) {
# Get Description
$sth1->execute($subjsec);
my ($desc, $start,$end) = $sth1->fetchrow;
$sort{"$desc$subjsec"} = $subjsec;
$desc{$subjsec} = qq{$desc};
$terms{$subjsec} = qq{$start - $end};
}
# Notes
print qq{
If you select:
\n};
print qq{
Courses Only, you will see all records for that course.
\n};
print qq{
Months Only, you will see all of your courses records for those months.
\n};
print qq{
Both Courses and Months, you will see the students records for };
print qq{those months, split by course.