#!/usr/bin/perl
# Copyright 2001-2008 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',
'Report Card' => 'Report Card',
'Transcript Post' => 'Transcript Post',
'Select Posting Term' => 'Select Posting Term',
'Select Term' => 'Select Term',
'Select Subjects to Post to Transcript System' =>
'Select Subjects to Post to Transcript System',
'Select Subjects' => 'Select Subjects',
'Check Subjects' => 'Check Subjects',
'Posting to Transcript System' => 'Posting to Transcript System',
'Mark' => 'Mark',
'Student' => 'Student',
'Subject' => 'Subject',
'Post more Subjects' => 'Post more Subjects',
'Duplicate' => 'Duplicate',
'Skipping Record for' => 'Skipping Record for',
);
my $self = 'tscpost.pl';
my $idfield = 'provnum'; # change to suit the field for state/provincial id or SSN, etc.
use DBI;
use CGI;
eval require "../../etc/admin.conf";
if ( $@ ) {
print $lex{Error}. " $@ \n";
die $lex{Error}. " $@\n";
}
my $q = CGI->new;
print $q->header;
my %arr = $q->Vars;
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
# Page Header
print "$doctype\n
". $lex{'Transcript Post'}. "
$chartype\n\n";
print "[ ". $lex{Main}. " |\n";
print "". $lex{'Report Card'}. " ]\n";
if ( not $arr{flag} ) { # We have a selected student.
selectTerm();
} elsif ( $arr{flag} == 1 ) {
delete $arr{flag};
selectSubjects();
} elsif ( $arr{flag} == 2 ) {
delete $arr{flag};
postSubjects();
}
#-------------
sub selectTerm {
#-------------
# Term Selection
my $sth = $dbh->prepare("select distinct term from eval
where term != '' and term is not null order by term");
$sth->execute;
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
while ( my $trm = $sth->fetchrow ) {
push @terms, $trm;
}
# Print Start of Selection.
print "
". $lex{'Select Posting Term'}. "
\n";
print "\n";
exit;
}
#-----------------
sub selectSubjects {
#-----------------
#foreach my $key (keys %arr ) { print "K:$key V:$arr{$key} \n"; }
# Subject Selection - first subjects with this term
my $sth = $dbh->prepare("select distinct subjcode from eval
where term = ? and subjcode != '' and subjcode is not null");
$sth->execute( $arr{term} );
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
while ( my $subj = $sth->fetchrow ) {
$subjects{$subj} = 1;
}
$sth1 = $dbh->prepare("select endrptperiod, description from subject where subjsec = ?");
foreach my $subjsec ( keys %subjects ) {
$sth1->execute( $subjsec );
if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; }
my ($endrptperiod, $description) = $sth1->fetchrow;
if ( $endrptperiod == $arr{term} ) { # the subject ends this term...
$subjects{$subjsec} = $description;
} else { # no match; remove value;
delete $subjects{$subjsec};
}
}
# At this point %subjects hash only contains subjects that have
# endrptperiod in the selected term.
# Print Start of Selection.
print "
". $lex{'Select Subjects to Post to Transcript System'}. "