#! /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 = ('Assessment Entry' => 'Assessment Entry', 'No Subject Enrollment records found!' => 'No Subject Enrollment records found!', 'Main' => 'Main', 'System Disabled. Please contact the secretary.' => 'System Disabled. Please contact the secretary.', 'Mark' => 'Mark', 'Move between fields using the Tab and Shift-Tab keys' => 'Move between fields using the Tab and Shift-Tab keys', 'It is faster!' => 'It is faster!', 'Term' => 'Term', 'Save Assessments' => 'Save Assessments', 'Trm' => 'Trm', 'Objective' => 'Objective', 'Comment' => 'Comment', 'Previous' => 'Previous', 'Your assessments are now stored in the database' => 'Your assessments are now stored in the database', 'There was an error storing your data' => 'There was an error storing your data', 'Please contact' => 'Please contact', 'Please record' => 'Please record', 'Enter More Assessments' => 'Enter More Assessments', 'Please Log In' => 'Please Log In', 'Error' => 'Error', 'Current Evaluation' => 'Current Evaluation', ); my $self = 'markadd1.pl'; use DBI; use CGI; use CGI::Session; eval require "../../etc/admin.conf"; if ( $@ ) { print $lex{Error}. " $@
\n"; die $lex{Error}. " $@\n"; } eval require "../../etc/repcard.conf"; if ( $@ ) { print $lex{Error}. " $@
\n"; die $lex{Error}. " $@\n"; } my $q = new CGI; my %arr = $q->Vars; my $subjsec = $arr{subjsec}; # passed in... my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$user,$password); # Get Session Information... my $session = new CGI::Session("driver:mysql;serializer:FreezeThaw", undef,{Handle => $dbh}) or die CGI::Session->errstr; my $userid; if ( not $session->param('logged_in') ){ $userid = $session->param('userid'); print $q->header; print "$doctype\n". $lex{'Assessment Entry'}. "\n"; print "\n"; print "[ ". $lex{Main}. " ]\n

\n"; if ( $userid and $arr{writeflag} ) { # update records if user exists and writeflag set. delete $arr{writeflag}; updateRecords(); print $lex{'Please Log In'}; die; } else { print $lex{'Please Log In'}; print "

\n"; die; } } # Ok, we have a login. Values below we have in environment. $userid = $session->param('userid'); $duration = $session->param('duration'); if (not ($duration =~ m/\+/)) { $duration = '+'. $duration. 'm'; } $session->expire('logged_in',$duration); print $session->header; print "$doctype\n". $lex{'Assessment Entry'}. "\n"; print "\n"; print "\n"; # Some Javascript here for resizing... print "\n"; print "$chartype\n\n"; # End of HTML Head section. # Get Subject Info: Description, Grade my $sth = $dbh->prepare("select description, grade from subject where subjsec = ?"); $sth->execute($subjsec); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr;} my ($description, $grade) = $sth->fetchrow; my $acMode = 0; # Additional Comments don't have any values but a comment... if ( $description eq $additionalcomments ) { # $additionalcomments set in admin.conf $acMode = 1; } my $subjectname; if ($description =~ m/$grade/) { $subjectname = $description; } else { $subjectname = "$description $grade"; } # Get Subject Objectives and Put in @qstarray $sth = $dbh->prepare("select * from subject where subjsec = ?"); $sth->execute($subjsec); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr;} my @subject = $sth->fetchrow; my @qstarray; # Stuff questions into the array. for ($a = 10;$a<=29; $a++) { if ($subject[$a]) { push @qstarray, $subject[$a]; } } if ( not $subject[10] ) { # blank qstarray # We must put in one question. push @qstarray, $lex{Mark}; } # Read in the term(s) my ($term, @terms, %terms); open(TERM, "../../etc/term") || die "Can't open the term file!"; # slurp file my $data; { local $/; $data = ; close FH;} my @terms = split /\n/, $data; $term = $terms[0]; # multiTrack variable is set in the admin.conf file. if ($multiTrack) { # Are we in multiTrack mode? If so, reset term. for my $t (1..$#terms) { my ($key, $val) = split /:/, $terms[$t]; $terms{$key} = $val; # Form is e:3 (elementary: term 3) } my $grp = $g_termtype{$grade}; if ( $terms{$grp} ) { $term = $terms{$grp}; } } # Check if disabled... if ($term == 0) { print "
". $lex{'System Disabled. Please contact the secretary.'}. "\n"; print "\n"; die; } # Update Records if ( $arr{writeflag} ) { delete $arr{writeflag}; updateRecords(); } # Get the students in this subjsect, in name order. $sth = $dbh->prepare("select distinct eval.studnum from eval, student where eval.subjcode = ? and eval.studnum = student.studnum and eval.term = ? order by student.lastname, student.firstname "); $sth->execute($subjsec, $term); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } my @students; while (my $studnum = $sth->fetchrow ) { push @students, $studnum; } if ( not @students ) { print "

". $lex{'No Subject Enrollment records found!'}. "

"; print "\n"; die; } # Print Evaluation Keys # Now figure out the key scheme...used to print eval schemes my $scheme = $g_evalsch{$grade}; # Print Assessment Table at top print "
\n"; print "\n"; # Print the Hint. print "\n"; my $itemcount; foreach $item ( @{ $g_eval{$scheme} } ){ if ($item =~ /[^~+]/){ print ""; $itemcount++;} if ($itemcount % 4 == 0){ print "\n";} # 4-3 one less (3-2 works) } $remainder = 4 - $itemcount %4; for (1..$remainder){ print "\n";} print "
\n"; print "[ ". $lex{'Main'}. " ]  "; print $lex{'Move between fields using the Tab and Shift-Tab keys'}. ".\n"; print $lex{'It is faster!'}. "
$item
\n\n"; # print Spacer div behind absolutely positioned assessment key div print "
\n"; # Remove after testing.... June / 07 latest... #---------------------- #print "The terms are "; #print "Main Term: $term
\n"; #foreach my $key (sort keys %terms) { # print "K:$key V:$terms{$key}
\n"; #} #print "Actual group is ", $g_termtype{$grade}, "
\n"; #print "New Term: ", $terms{ $g_termtype{$grade} }, "
\n"; # $g_termstart{val}[term] = #---------------------- # Print Top Section / Start of Form print "

". $lex{'Assessment Entry'}. " – "; print $lex{Term}. " $term

\n"; print "

$subjectname

\n"; print "
\n"; print "\n"; print "\n"; my $sth = $dbh->prepare("select * from eval where studnum = ? and subjcode = ? order by term"); my $sth1 = $dbh->prepare("select lastname, firstname from studentall where studnum = ?"); foreach my $studnum ( @students ) { # Loop through all students in this class. # Get Student Name $sth1->execute($studnum); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } my ($lastname, $firstname) = $sth1->fetchrow; # Load all eval records for this student in this subject (ie. all terms) # structure is a hash pointing to an array. (full eval record) my %evals; $sth->execute($studnum, $subjsec); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } while ( my @eval = $sth->fetchrow ) { # put into %evals hash $evals{$eval[4]} = [ @eval ]; } print"\n\n"; print "\n"; print "
$firstname $lastname   "; print ""; print $lex{'Current Evaluation'}. "
\n"; my $id = $evals{$term}->[0]; if ( not $acMode ) { print "\n"; print "\n"; # Print Terms row... foreach my $trm ( sort keys %evals ) { if ( $trm <= $term ) { print "\n"; } else { last; # just out if hit current term } } print "\n"; my $count = 1; my $qst = 7; foreach my $question ( @qstarray ){ print ""; # print previous term values foreach my $trm ( sort keys %evals ) { if ( $trm < $term ) { print "\n"; } else { last; # just out if hit current term } } # print current term. print "\n"; $count++; $qst++; } print "
"; print $lex{Objective}. "". $lex{Trm}. " $trm
$count. $question". $evals{$trm}->[$qst]. ""; print "[$qst]. "\">
\n"; } print "
\n"; # Print Previous Comments... foreach my $trm ( sort keys %evals ) { if ( $trm < $term and $evals{$trm}->[6] ) { print "". $lex{Term}. " $trm: ". $evals{$trm}->[6]. "
\n"; } } print "". $lex{Term}. " $term ". $lex{Comment}. ":
\n"; print "
\n"; print "

\n"; } print "\n"; print "
\n"; #---------------- sub updateRecords { #---------------- #foreach my $key (keys %arr ) { print "K:$key V:$arr{$key}
\n"; } foreach my $key ( keys %arr ) { my ( $evalrec, $studnum, $qst) = split /:/, $key; # check field type and quote. if ($qst eq "comment"){ $fieldid = "comment"; $arr{$key} = $dbh->quote( $arr{$key} ); } else { $fieldid = "a$qst"; $arr{$key} = "\U$arr{$key}"; $arr{$key} = $dbh->quote($arr{$key}); } $evalrec = $dbh->quote( $evalrec ); $sth = $dbh->prepare("update eval set $fieldid = $arr{$key} where id = $evalrec"); # Note: Mysql fails if single quotes used with bind vars. So using older method. $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } } if (not $DBI::errstr ) { print "

". $lex{'Your assessments are now stored in the database'}. ".

\n"; } else { print "

". $lex{'There was an error storing your data'}. ". \n"; print $lex{'Please contact'}; print " $adminname $adminemail\n"; print $lex{'Please record'}. ": $DBI::errstr

"; } print " "; print $lex{Main}. "  \n"; print "". $lex{'Enter More Assessments'}. " \n"; print "
\n"; exit 0; } # End of Update Record.