#!/usr/bin/perl # Copyright 2001-2009 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 = 'enrolstudview.pl'; my %lex = ('Student Subject Enrollment Search' => 'Student Subject Enrollment Search', 'No Students Found' => 'No Students Found', 'Please search again' => 'Please search again', 'not enrolled in any subjects' => 'not enrolled in any subjects', 'Search' => 'Search', 'Student (Last,First/Last/Initials/Studnum)' => 'Student (Last,First/Last/Initials/Studnum)', 'Main' => 'Main', 'Report Card' => 'Report Card', 'Error' => 'Error', 'Student Name' => 'Student Name', 'Student Number' => 'Student Number', 'Subject' => 'Subject', 'Teacher' => 'Teacher', 'Term' => 'Term', ); use DBI; use CGI; eval require "../../etc/admin.conf"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } my $q = new CGI; print $q->header; my %arr = $q->Vars; my $student = $arr{student}; $dsn = "DBI:$dbtype:dbname=$dbase"; $dbh = DBI->connect($dsn,$user,$password); # Print Html Head print "$doctype\n". $lex{'Student Subject Enrollment Search'}. "\n"; print "\n"; print "$chartype\n[ ". $lex{Main}. " | \n"; print "". $lex{'Report Card'}. " ]\n"; print "

". $lex{'Student Subject Enrollment Search'}. "

\n"; mkSearchError(); if ( not $student ) { exit; } # Setup the Search if ( $student =~ /\d+/ ) { # we have a student number $sth = $dbh->prepare("select studnum from studentall where studnum = ?"); # req'd. $sth->execute( $student ); } else { # we have words hopefully with a comma ( $lastname, $firstname ) = split /\,/, $student; $firstname =~ s/^\s*//; $lastname =~ s/^\s*//; if ( $lastname and $firstname ){ # both entered. $sth = $dbh->prepare("select studnum from studentall where lastname = ? and firstname = ?"); $sth->execute( $lastname, $firstname ); } elsif ( $lastname and not $firstname ){ # only lastname (no comma) if ( length( $lastname ) == 2){ # search by initials: fi, li. $fi = substr($lastname,0,1); $li = substr($lastname,1,1); $fi = $fi. '%'; $li = $li. '%'; $sth = $dbh->prepare("select studnum from studentall where lastname $sql{like} ? and firstname $sql{like} ?"); $sth->execute( $li, $fi ); } else { # lastname only $sth = $dbh->prepare("select studnum from studentall where lastname = ? order by firstname"); $sth->execute( $lastname ); } } else { # print an error.... mkSearchError(); print "\n"; die; } } # End of Search. if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } my $rows = $sth->rows; if ($rows < 1) { print "

". $lex{'No Students Found'}. q{. }. $lex{'Please search again'}. ".

\n"; print "\n"; die; } my @student = (); while ( my $sn = $sth->fetchrow ) { push @students, $sn; } my $first = 1; # Now loop through all students found. foreach my $studnum ( @students ) { my $sth = $dbh->prepare("select s.lastname, s.firstname, e.studnum, e.subjcode, e.term from eval as e, studentall as s where s.studnum = e.studnum and s.studnum = ? order by e.subjcode, e.term"); $sth->execute( $studnum ); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } my $rows = $sth->rows; if ( $rows < 1 ) { my $sth3 = $dbh->prepare("select lastname, firstname from studentwd where studnum = ?"); $sth3->execute( $studnum ); if ($DBI::errstr){print $DBI::errstr; die $DBI::errstr; } my ($lastname, $firstname) = $sth3->fetchrow; if ( not $lastname ){ # look in student table... $sth3 = $dbh->prepare("select lastname, firstname from student where studnum = ?"); $sth3->execute( $studnum ); if ($DBI::errstr){print $DBI::errstr; die $DBI::errstr; } my ($lastname, $firstname) = $sth3->fetchrow; $name = "$firstname $lastname"; } else { # found in studentwd $name = "$firstname $lastname"; } print "

\n"; print "\n"; print ""; print "
". $lex{'Student Name'}. "
$name ($studnum) ". $lex{'not enrolled in any subjects'}. ".

\n"; next; } # End of If Rows < 1 (not enrolled) if ( not $first ){ print "

 

\n";} else { $first = 0;} print "". $lex{'Student Number'}. ": $studnum\n"; print "\n"; print "\n"; while ( my ( $lastname, $firstname, $studnum, $subjsec, $term ) = $sth->fetchrow ) { my $sth2 = $dbh->prepare("select description, teacher from subject where subjsec = ?"); $sth2->execute( $subjsec ); if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; } my ($description, $teacher) = $sth2->fetchrow; print ""; print "\n"; print "\n"; } print "
". $lex{'Student Name'}. "". $lex{Subject}. ""; print $lex{Teacher}. "". $lex{Term}. "
$lastname, $firstname$description ($subjsec)$teacher$term

\n"; } mkSearchError(); print "\n"; #---------------- sub mkSearchError { #---------------- print "
\n"; print "". $lex{'Student Subject Enrollment Search'}. "
\n"; print "
\n"; print "\n"; print "
\n"; print $lex{'Student (Last,First/Last/Initials/Studnum)'}. "\n"; print "
\n"; }