#!/usr/bin/perl
# Copyright 2001-2019 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.
use DBI;
use CGI;
use Time::JulianDay;
my %lex = ('Main' => 'Main',
'Grade' => 'Grade',
'Continue' => 'Continue',
'Section' => 'Section',
'Course' => 'Course',
'Teacher' => 'Teacher',
'Error' => 'Error',
);
my $self = 'preplancoursemaster.pl';
# Read Config
eval require "../../etc/admin.conf";
if ( $@ ) {
print $lex{Error}. ": $@
\n";
die $lex{Error}. ": $@\n";
}
my $passingaverage = $pp_Grade9PassingAverage; # from configuration
my $q = new CGI;
print $q->header( -charset, $charset );
my %arr = $q->Vars;
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
$dbh->{mysql_enable_utf8} = 1;
# load the sasked ed courses (they have a grade field).
my (%saskedgrade, %saskedname);
my $sth = $dbh->prepare("select * from sasked_courses");
$sth->execute;
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr;}
while ( $ref = $sth->fetchrow_hashref ) {
my %r = %$ref;
$saskedgrade{$r{code}} = $r{grade};
$saskedname{$r{code}} = $r{title};
}
my $title = "Preplan Course Offerings for Upcoming Year";
print qq{$doctype\n
Semester $semester | Code | }; print qq{Periods | }; } print qq{||
---|---|---|---|---|
$saskedname{$code}$backed | $subjsec | }; # print qq{$teacher | }; # Get Periods for this course, this semester if ( $subjsec ) { # could be blank $sth1->execute($subjsec, $semester); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } my $periods = $sth1->fetchrow; print qq{$periods | \n}; $totals{$semester} += $periods; } else { # empty cell print qq{\n}; } } # end of semester loop print qq{ |
$saskedname{$code} | $subjsec | }; # print qq{$teacher | }; # Get Periods for this course, this semester if ( $subjsec ) { # could be blank $sth1->execute($subjsec, $semester); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } my $periods = $sth1->fetchrow; print qq{$periods | }; $totals{$semester}+= $periods; } else { print qq{}; } } print qq{ |
}; print qq{Semester $semester Totals | $totals{$semester} | }; } print qq{
Semester $semester | Code | }; print qq{Teacher | Periods | }; } print qq{|
---|---|---|---|---|
$saskedname{$code}$backed | $subjsec | }; print qq{$teacher | }; # Get Periods for this course, this semester if ( $subjsec ) { # could be blank $sth1->execute($subjsec, $semester); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } my $periods = $sth1->fetchrow; print qq{$periods | \n}; $totals{$semester} += $periods; } else { # empty cell print qq{\n}; } } # end of semester loop print qq{ |
$saskedname{$code} | $subjsec | }; print qq{$teacher | }; # Get Periods for this course, this semester if ( $subjsec ) { # could be blank $sth1->execute($subjsec, $semester); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } my $periods = $sth1->fetchrow; print qq{$periods | }; $totals{$semester}+= $periods; } else { print qq{}; } } print qq{ |
}; print qq{Semester $semester Totals | $totals{$semester} | }; } print qq{
$lex{Course} A | $lex{Course} B |
---|---|
$saskedname{$code} ($subjsec) | }; print qq{$saskedname{$bcode} ($backedwith) |
\n\n};
#====================================
print qq{Page 4 - Set Course Periods\n}; my $dayspercycle = $pp_DaysPerCycle; my $teachingperiods = $pp_PeriodsPerDay; my $defppc = $pp_DefaultPeriodsPerCycle; print qq{
Backed Courses: $saskedname{$codeA}
# ($crsA) / $saskedname{$codeB} ($crsB) \n};
}
}
}
# Now do the course Information.
my (%courses, %periods);
foreach my $key ( sort keys %arr ) {
my ($id, $field) = split(':', $key);
if ( $id =~ m/\d/ ) {
if ( $arr{$key} ) { # if we have a value
if ( $field eq 'periods') {
$periods{$id} = $arr{$key};
} else {
$courses{$id}{$field} = $arr{$key};
}
}
delete $arr{$key};
}
}
# foreach my $key ( sort keys %arr ) { print qq{K:$key V:$arr{$key}\n}; } # %arr should now be empty. # Write Updated Values to the preplan course master. foreach my $id ( sort keys %courses ) { # print qq{ ID:$id - };
foreach my $field ( sort keys %{ $courses{$id}} ) {
my $sth = $dbh->prepare("update preplan_coursemaster set $field = ? where id = ?");
$sth->execute($courses{$id}{$field}, $id);
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
# print qq{ $field $courses{$id}{$field}/ };
}
}
print qq{ };
print qq{Preplan Course Master Updated - Semester, Teacher, Grade Offered, and Backings \n};
# Passed Updates now done: teacher, semester, offeredto, backings.
#-----------------------------------------------------------------------------------
#----------------------------------------------
# Now get the periods for the courses - page 4
#----------------------------------------------
# Get Number of Semesters; not using configuration since we need to use set values.
my $sth = $dbh->prepare("select max(semester) from preplan_coursemaster
where semester != 'allyear'");
$sth->execute;
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }
my $semestercount = $sth->fetchrow;
# print qq{Semesters:$semestercount \n};
# Get PERIODS for each course, each semester.
my $sth1 = $dbh->prepare("select periods from preplan_courseperiods
where subjsec = ? and semester = ?");
# Display Courses by Grade
my $sth = $dbh->prepare("select c.* from preplan_coursemaster c, sasked_courses s
where c.subjcode = s.code and offeredto = ? order by s.title, c.subjsec");
# Form Start
print qq{\n};
#=========================
print qq{\n | \n}; # next column
print qq{ };
print qq{[ * = Backed ] \n};
print qq{};
print qq{Current Teacher Load \n};
showTeacherSummary();
showTeacher(); # show current loading.
print qq{ |