#!/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 = ('View Student Subject Enrollment' => 'View Student Subject Enrollment', 'Report Card' => 'Report Card', 'Grade' => 'Grade', 'Withdrawn' => 'Withdrawn', 'Error' => 'Error', ); my $self = 'rptenrolgrade.pl'; use DBI; use CGI; eval require "../../etc/admin.conf"; if ( $@ ) { print $lex{Error}. " $self: $@
\n"; die $lex{Error}. " $self: $@\n"; } my $q = new CGI; print $q->header; my %arr = $q->Vars; my $grade = $arr{grade}; my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); # Step 1: Find all of the distinct subject-sections in enrollment # and lookup name and grade. Sort by grade and description. my $sth = $dbh->prepare("select distinct eval.subjcode from eval left outer join subject on eval.subjcode = subject.subjsec where subject.grade = '$grade' order by subject.description"); $sth->execute; if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } # put all subjects into an array. my $sth1 = $dbh->prepare("select description, grade from subject where subjsec = ?"); my @subjarray; while ( my $subjsec = $sth->fetchrow ) { $sth1->execute($subjsec); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; }; my ($description,$grade) = $sth1->fetchrow; push @subjarray,"$grade:$description:$subjsec"; } @subjarray = sort @subjarray; # Print HTML Page Header print "$doctype\n $lex{'View Student Subject Enrollment'} $chartype\n\n"; print "[ $lex{'Report Card'} ]

$lex{'View Student Subject Enrollment'}

\n"; foreach $subject ( @subjarray ){ my ($grade,$description,$subjsec) = split /:/,$subject; # print the subject heading print "\n"; print "\n"; # Step 2: Get all of the kids enrolled in each subject in # turn, sort them, and then load and display records. (different terms) my $sth=$dbh->prepare("select distinct studnum from eval where subjcode = ?"); $sth->execute($subjsec); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } my $sth1=$dbh->prepare("select lastname,firstname from student where studnum = ?"); while (my $studnum = $sth->fetchrow) { # Get the Name $sth1->execute($studnum); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } my ($lastname,$firstname) = $sth1->fetchrow; # Look in withdrawn for lastname if (not $lastname){ my $sth4 = $dbh->prepare("select lastname,firstname from studentall where studnum = ?"); $sth4->execute($studnum); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } ($lastname,$firstname) = $sth4->fetchrow; $lastname = "(". $lex{'Withdrawn'}. ") $lastname"; } # Get the terms for this subject my $sth2 = $dbh->prepare("select term from eval where studnum = ? and subjcode = ? order by term"); $sth2->execute($studnum, $subjsec); if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; } my $termrows = $sth2->rows; my $terms; for (1..$termrows){ $term = $sth2->fetchrow; $terms = $terms." $term"; } push @studarray,"$lastname, $firstname\t$terms"; } @studarray = sort @studarray; foreach $student (@studarray){ my ($name,$terms) = split /\t/,$student; print "\n"; } @studarray = (); print "
$description ($subjsec) $lex{Grade}: $grade
$name$terms

\n"; } # End of Subject Loop print "\n";