#!/usr/bin/perl
# Copyright 2001-2022 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 = ('Main' => 'Main',
'Error' => 'Error',
'Timetable Entry' => 'Timetable Entry',
'Timetable' => 'Timetable',
'Grade' => 'Grade',
'Term' => 'Term',
'Terms' => 'Terms',
'Day' => 'Day',
'Save' => 'Save',
'Period' => 'Period',
'Add Backings' => 'Add Backings',
'Records Stored' => 'Records Stored',
'Contact' => 'Contact',
'Separate with Spaces' => 'Separate with Spaces',
'Additional Courses' => 'Additional Courses',
'Add Timetable Entries' => 'Add Timetable Entries',
'Continue' => 'Continue',
'Teacher' => 'Teacher',
'Or' => 'Or',
'Either' => 'Either',
'No Terms Found' => 'No Terms Found',
'Number of Periods' => 'Number of Periods',
'Same Day/Period; More Than 1 Course' => 'Same Day/Period; More Than 1 Course',
'No Terms' => 'No Terms',
'Course' => 'Course',
'Exists' => 'Exists',
'Skipping' => 'Skipping',
'Per' => 'Per',
'Current' => 'Current',
);
use DBI;
use CGI;
my $self = "ttAdd.pl";
my $maxbackings = 12; # maximum number of backed classes per cycle.
eval require "../../etc/admin.conf";
if ( $@ ) {
print $lex{Error}. " $@
\n";
die $lex{Error}. " $@\n";
}
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;
# Set a starting maxppd value. (Max Periods per Day)
my $maxppd;
foreach my $key ( keys %g_ppd ) { # from admin.conf
if ( $g_ppd{ $key } > $maxppd ) { $maxppd = $g_ppd{ $key }; }
}
# print page header.
my $title = "$lex{Add} $lex{'Timetable Entry'}";
print qq{$doctype\n
$lex{'No Terms'}
\n}; print qq{\n}; exit; } # Load All Courses from these terms/grade/teacher into hash. Used to set new timetable entries my (%courses,%sort); if ( $arr{grade} ) { my $sth = $dbh->prepare("select description, subjsec from subject where grade = ? and startrptperiod <= ? and endrptperiod >= ? order by description"); foreach my $term ( @terms ) { $sth->execute($arr{grade},$term,$term); if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } while ( my ( $description, $subjsec ) = $sth->fetchrow ){ $sort{"$description$subjsec"} = $subjsec; $courses{$subjsec} = $description; } } } else { # teacher; my $sth = $dbh->prepare("select description, subjsec from subject where teacher = ? and startrptperiod <= ? and endrptperiod >= ? order by description"); foreach my $term ( @terms ) { $sth->execute($arr{teacher},$term,$term); if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } while ( my ( $description, $subjsec ) = $sth->fetchrow ){ $sort{"$description$subjsec"} = $subjsec; $courses{$subjsec} = $description; } } } my (%altcourses, %altsort); # hold alternate grade courses, if necessary for entry. if ( $arr{additionalgrades} and $arr{grade} ){ @addgrades = split(/\s/,$arr{additionalgrades}); my $sth = $dbh->prepare("select description, subjsec from subject where grade = ? and startrptperiod <= ? and endrptperiod >= ? order by description"); foreach my $grade ( @addgrades ) { foreach my $term ( @terms ) { $sth->execute($grade,$term,$term); if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } while ( my ( $description, $subjsec ) = $sth->fetchrow ){ $altsort{"$description$subjsec"} = $subjsec; $altcourses{$subjsec} = $description; } } } } # we now have %courses,%sort populated for timetable entry. Also # possibly %altcourses,%alsort # Now Display # Print Teacher or Grade print qq{$lex{Grade} | $arr{grade} | \n}; } else { # teacher my $sth = $dbh->prepare("select lastname, firstname from staff where userid = ?"); $sth->execute( $arr{teacher} ); if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } my ( $lastname, $firstname ) = $sth->fetchrow; print qq{$lex{Teacher} | }; print qq{$firstname $lastname | \n}; } # Print Terms my $terms = join(',',@terms); print qq{$lex{Terms} | $terms |