#!/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 %lex=('Subject Edit' => 'Subject Edit', 'Main' => 'Main', 'Report Card' => 'Report Card', 'Codes' => 'Codes', 'Other Codes' => 'Other Codes', 'Save Subject' => 'Save Subject', 'Course Code' => 'Course Code', 'Section' => 'Section', 'Description' => 'Description', 'Short Description' => 'Short Description', 'Max' => 'Max', 'char' => 'char', 'Grade' => 'Grade', 'Start Term' => 'Start Term', 'End Term' => 'End Term', 'Teacher' => 'Teacher', 'Sequence' => 'Sequence', 'Controls printing order on report card' => 'Controls printing order on report card', 'Web Visible' => 'Web Visible', 'Y' => 'Y', 'N' => 'N', 'Instructional Mode' => 'Instructional Mode', 'Class' => 'Class', 'Distance' => 'Distance', 'Exam Mix' => 'Exam Mix', 'School' => 'School', 'Blended' => 'Blended', 'Faculty' => 'Faculty', 'Location' => 'Location', 'Mark Scheme' => 'Mark Scheme', 'Objective' => 'Objective', 'Save Subject' => 'Save Subject', 'Credit' => 'Credit', 'Difficulty' => 'Difficulty', 'Subject Area' => 'Subject Area', 'Calc Average' => 'Calc Average', 'If your subject only has marks and comments, no objective entry' => 'If your subject only has marks and comments, no objective entry', 'is required. If you have non-mark based objectives, please enter' => 'is required. If you have non-mark based objectives, please enter', 'the description that will appear on the report card. These will' => 'the description that will appear on the report card. These will', 'also appear for evaluation entry. Limit: 255 characters' => 'also appear for evaluation entry. Limit: 255 characters', 'Changing Start/End Term will require adding/removing student mark records' => 'Changing Start/End Term will require adding/removing student mark records', 'There is one mark record for every term for each student' => 'There is one mark record for every term for each student', 'There was an error storing your data' => 'There was an error storing your data', 'Please contact' => 'Please contact', 'Please record the following error' => 'Please record the following error', 'Your subject update is now stored' => 'Your subject update is now stored', 'Edit Another Subject' => 'Edit Another Subject', 'Required' => 'Required', 'Start Term cannot be larger than End Term' => 'Start Term cannot be larger than End Term', 'Terms cannot be larger than' => 'Terms cannot be larger than', 'Error' => 'Error', ); my $self = 'subjed.pl'; my $maxterms = 12; # maximum value allowed in the start and end reporting period (terms) use DBI; use CGI; eval require "../../etc/admin.conf"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } eval require "../../etc/transcript.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; # Print Page Header print "$doctype\n". $lex{'Subject Edit'}. " $chartype\n\n"; print "[ ". $lex{Main}. " |\n"; print "". $lex{'Report Card'}. " | \n"; print "SK ". $lex{Codes}. " | ". $lex{'Other Codes'}. " ]\n"; print "

". $lex{'Subject Edit'}. "

\n"; if ( $arr{flag} ) { writeRecord(); } # Load teachers into an array my $sth = $dbh->prepare("select lastname, firstname, userid from staff where userid != '' and userid is not null order by lastname, firstname"); $sth->execute; if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; } while ( my ($ln, $fn, $uid) = $sth->fetchrow ) { push @teacherarray, "$ln, $fn ($uid)"; } # Now select and load the subject $sth = $dbh->prepare("select * from subject where id = ?"); $sth->execute( $arr{id} ); my @subj = $sth->fetchrow; # Now count the eval records for this subject (to see if any exist). # Find the number of eval records depending on this... my $noeditflag; $sth = $dbh->prepare("select count(*) from eval where subjcode = ?"); $sth->execute( $subj[9] ); # subjsec field if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } my $count = $sth->fetchrow; if ( $count ){ $noeditflag = 1; } # Now print the form. print "
\n"; print "\n"; print "\n"; # Not used for updates. print "\n"; print "\n"; print "\n"; print "\n\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n\n"; print "\n"; if ( %gradRequirements ) { print "\n"; } else { print "\n"; } print "\n"; print "\n"; for (my $i=1;$i<=20;$i++){ my $j = $i + 9; print "\n"; } print "\n
\n"; print " (* = ". $lex{Required}. ")
". $lex{'Course Code'}. "*\n"; if ( $noeditflag ) { print $subj[1]; } else { print ""; } print "
". $lex{Section}. "*"; if ( $noeditflag ) { print $subj[8]; } else { print ""; } print "
". $lex{Description}. "*
". $lex{'Short Description'}. "* "; print $lex{Max}. ": 8 ". $lex{char}. "
". $lex{Grade}. "*
". $lex{'Start Term'}. "*
". $lex{'End Term'}. "*
". $lex{'Teacher'}. "*
". $lex{Sequence}. "\n"; print $lex{'Controls printing order on report card'}. ".
". $lex{'Web Visible'}. "
". $lex{'Instructional Mode'}. "
". $lex{'Exam Mix'}. "
". $lex{Faculty}. "
". $lex{Location}. "
". $lex{'Mark Scheme'}. "
". $lex{'Credit'}. ""; if ( @creditValues ) { # from transcript.conf print "\n"; } else { print ""; } print "
". $lex{'Difficulty'}. ""; print "
". $lex{'Subject Area'}. "
". $lex{'Calc Average'}; print "
\n"; print $lex{'If your subject only has marks and comments, no objective entry'}. "
\n"; print $lex{'is required. If you have non-mark based objectives, please enter'}. "
\n"; print $lex{'the description that will appear on the report card. These will'}. "
\n"; print $lex{'also appear for evaluation entry. Limit: 255 characters'}. ".
". $lex{Objective}. " $i
\n"; #-------------- sub writeRecord { #-------------- delete $arr{flag}; my $id = $arr{id}; delete $arr{id}; # record id to edit. # foreach $key ( sort keys(%arr)) { print "K:$key V:$arr{$key}
\n"} # load existing record values for subjcode, section, subjsec, periods my $sth = $dbh->prepare("select subjcode, section, subjsec, startrptperiod, endrptperiod, teacher from subject where id = ?"); $sth->execute( $id ); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } my ($subjcode, $section, $subjsec,$startterm, $endterm, $teacher) = $sth->fetchrow; # Find the number of eval records depending on this... $sth = $dbh->prepare("select count(*) from eval where subjcode = ?"); $sth->execute( $subjsec ); if ($DBI::errstr){ print $DBI::errstr; die;} my $subjcount = $sth->fetchrow; if ( ( $startterm != $arr{startrptperiod} and $subjcount ) or ( $endterm != $arr{endrptperiod} and $subjcount ) ) { print "

"; print $lex{'Changing Start/End Term will require adding/removing student mark records'}. "!\n"; print $lex{'There is one mark record for every term for each student'}. "!

\n"; } # Check for start/end term errors if ( $arr{startrptperiod} > $arr{endrptperiod} ) { print "

". $lex{'Start Term cannot be larger than End Term'}. "

\n"; exit; } if ( $arr{startrptperiod} > $maxterms or $arr{endrptperiod} > $maxterms ) { print "

". $lex{'Terms cannot be larger than'}. " $maxterms

\n"; exit; } # Join Subject and Section to make SubjSec; Add to %arr; not passed if restricted editing. if ( $arr{subjcode} and $arr{section} ) { # they have to exist $arr{subjsec} = $arr{subjcode}."-".$arr{section}; } # We'll leave full name along with bracketed UID for now. #($teachname,$teachid) = split /\(/,$arr{teacher}; #chop $teachid; # chop trailing bracket. #$teachid = $arr{teacher}; foreach my $key ( sort keys %arr ) { if ( not $arr{$key} ) { $sth = $dbh->prepare("update subject set $key = $sql{default} where id = ?"); $sth->execute( $id ); } else { $sth = $dbh->prepare("update subject set $key = ? where id = ?"); $sth->execute( $arr{$key}, $id ); } #print "K:$key V:$arr{$key}
\n"; if ($DBI::errstr ) { print "$DBI::errstr;
\n"; } } if (not $DBI::errstr ) { print "

". $lex{'Your subject update is now stored'}. ".

\n"; } else { print "

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

[ ". $lex{'Report Card'}. " | \n"; print "". $lex{'Edit Another Subject'}. " ]\n"; print "

\n"; exit; }