#! /usr/bin/perl # Copyright 2001-2022 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. $parpage = '/index.html'; my %lex = ('Main' => 'Main', 'Homework' => 'Homework', 'No Courses Found' => 'No Courses Found', 'View' => 'View', 'Continue' => 'Continue', 'Grade' => 'Grade', 'Error' => 'Error', 'by' => 'by', 'Teacher' => 'Teacher', 'Start Date' => 'Start Date', 'Date' => 'Date', 'Topic' => 'Topic', 'Description' => 'Description', 'Or' => 'Or', 'Not Found' => 'Not Found', 'Courses' => 'Courses', ); my $self = 'viewhomework.pl'; use DBI; use CGI; # The location where to load the config file from. my $configlocation = '../etc'; eval require "$configlocation/admin.conf"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } my $q = new CGI; print $q->header( -charset, $charset ); my %arr = $q->Vars; # Get Current Date my @tim = localtime(time); my $year = $tim[5] + 1900; my $month = $tim[4] + 1; my $currdate = "$year-$month-$tim[3]"; my $dsn = "DBI:$dbtype:dbname=$dbase"; my $dbh = DBI->connect($dsn,$rouser,$ropassword); $dbh->{mysql_enable_utf8} = 1; # Read in values from conf_system; my $sth = $dbh->prepare("select datavalue from conf_system where dataname = ?"); foreach my $dataname ( qw( r_SupressSubject r_AdditionalComments )) { $sth->execute( $dataname ); if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } my $datavalue = $sth->fetchrow; eval $datavalue; if ( $@ ) { print $lex{Error}. " $@
\n"; die $lex{Error}. " $@\n"; } } my $title = "$lex{View} $lex{Homework}"; print qq{$doctype\n$title\n}; print qq{\n}; print qq{\n}; print qq{$chartype\n\n}; print qq{[ $lex{Main} ]\n}; print qq{

$title

\n}; if ( not $arr{page} ) { showStartPage(); } elsif ( $arr{page} == 1 ) { delete $arr{page}; showHomework(); } #---------------- sub showStartPage { #---------------- # Read grades my $sth = $dbh->prepare("select distinct grade from student where grade is not NULL and grade != ''"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my @grades = (); while ( my $grade = $sth->fetchrow ) { push @grades, $grade; } @grades = sort {$a <=> $b} @grades; # Read Teachers $sth = $dbh->prepare("select distinct s.teacher, st.lastname, st.firstname from subject s, staff st where s.teacher = st.userid and (s.teacher is not NULL ) and ( s.teacher != '' ) order by st.lastname, st.firstname, st.userid"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my %teacher = (); while ( my ( $userid, $lastname, $firstname ) = $sth->fetchrow ) { $teacher{"$lastname, $firstname ($userid)"} = $userid; } print qq{
\n}; print qq{\n}; print qq{\n}; print qq{\n}; # Start Date print qq{\n}; # Or print qq{\n}; # Select by Teacher print qq{\n}; print qq{\n}; print qq{
\n}; print qq{
$lex{'Start Date'}\n}; print qq{\n}; # Select by Grade print qq{
$lex{View} $lex{by} $lex{Grade}\n}; print qq{
$lex{Or}
$lex{View} $lex{by} $lex{Teacher}\n}; print qq{
\n}; print qq{
\n}; exit; } #--------------- sub showHomework { #--------------- # foreach my $key ( sort keys %arr ) { print qq{K:$key V:$arr{$key}
\n}; } if ( $arr{grade} ) { # find homework by grade # Read grades to verify my $sth = $dbh->prepare("select distinct grade from student where (grade is not NULL ) and (grade != '' )"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my %grades = (); while ( my $grade = $sth->fetchrow ) { $grades{$grade} = 1; } if ( not $grades{ "$arr{grade}" } ) { # no grade match; crack attempt print qq{

$lex{Grade} $lex{'Not Found'}:$arr{grade}

\n}; print qq{\n}; exit; } else { # print grade print qq{

$lex{Grade} $arr{grade} $lex{Courses}

\n}; } # Find subjects in this grade. my $sth = $dbh->prepare("select subjsec, description from subject where grade = ?"); $sth->execute( $arr{grade} ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my %subjects = (); while ( my ($subjsec, $description) = $sth->fetchrow ) { my ($subjcode, $dud) = split(/-/, $subjsec ); # skip supressed subjects if ( $r_SupressSubject{$subjcode} or $r_SupressSubject{$subjsec} ) { next; } #skip # skip if member of %r_AdditionalComments if ( $r_AdditionalComments{$subjsec} or $r_AdditionalComments{$subjcode} ) { next; } $subjects{"$description ($subjsec)"} = $subjsec; } if ( not %subjects ) { print qq{

$lex{'No Courses Found'}

\n}; print qq{\n}; exit; } # Prepare to get homework info my $sth1 = $dbh->prepare("select * from plan_homework where subjsec = ? and to_days(duedatetime) >= to_days('$arr{date}') order by id"); my $sth2 = $dbh->prepare("select st.lastname, st.firstname, st.sal, s.teacher from staff st, subject s where st.userid = s.teacher and s.subjsec = ?"); # Loop through all subjects in this grade. foreach my $desc ( sort keys %subjects ) { my $subjsec = $subjects{$desc}; # Get Teacher Information $sth2->execute( $subjsec ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my ( $lastname, $firstname, $sal, $userid ) = $sth2->fetchrow; if ( not $sal ) { $sal = $firstname; } # if not Mr. Smith, Fred Smith my $first = 1; print qq{

$desc - $sal $lastname

\n}; # Get Homework info, if any. $sth1->execute( $subjsec ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } while ( my $ref = $sth1->fetchrow_hashref ) { if ( $ref ) { if ( $first ) { print qq{\n}; print qq{}; print qq{\n}; $first = 0; } print qq{}; print qq{\n}; } } if ( $first ) { print qq{

$lex{Homework} $lex{'Not Found'}

\n}; } else { print qq{
$lex{Date}$lex{Topic}$lex{Description}
$ref->{duedatetime}$ref->{topic}$ref->{description}

\n}; } } # loop through all subjects. } # end of homework by Grade print qq{
\n}; if ( $arr{teacher} ) { # find homework by teacher # Read Teachers to verify my $sth = $dbh->prepare("select distinct teacher from subject"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my %teacher = (); while ( my $userid = $sth->fetchrow ) { $teacher{$userid} = 1; } # Verify teacher if ( not $teacher{ $arr{teacher} } ) { # no teacher match; crack attempt print qq{

$lex{Teacher} $lex{'Not Found'}:$arr{teacher}

\n}; print qq{\n}; exit; } else { # print teacher name my $sth = $dbh->prepare("select lastname, firstname, sal from staff where userid = ?"); $sth->execute( $arr{teacher} ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my ($lastname, $firstname, $sal ) = $sth->fetchrow; print qq{

$sal $firstname $lastname

\n}; } # Find subjects of this teacher $sth = $dbh->prepare("select subjsec, description from subject where teacher = ?"); $sth->execute( $arr{teacher} ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my %subjects = (); while ( my ($subjsec, $description) = $sth->fetchrow ) { my ($subjcode, $dud) = split(/-/, $subjsec ); # skip supressed subjects if ( $r_SupressSubject{$subjcode} or $r_SupressSubject{$subjsec} ) { next; } #skip # skip if member of %r_AdditionalComments if ( $r_AdditionalComments{$subjsec} or $r_AdditionalComments{$subjcode} ) { next; } $subjects{"$description ($subjsec)"} = $subjsec; } if ( not %subjects ) { print qq{

$lex{'No Courses Found'}

\n}; print qq{\n}; exit; } # Prepare to get homework info my $sth1 = $dbh->prepare("select * from plan_homework where subjsec = ? and to_days(duedatetime) >= to_days('$arr{date}') order by id"); # Loop through all subjects in this grade. foreach my $desc ( sort keys %subjects ) { my $subjsec = $subjects{$desc}; my $first = 1; # Get Homework info, if any. $sth1->execute( $subjsec ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } while ( my $ref = $sth1->fetchrow_hashref ) { if ( $ref ) { if ( $first ) { print qq{

$desc

\n}; print qq{\n}; print qq{}; print qq{\n}; $first = 0; } print qq{}; print qq{\n}; } } if ( $first ) { print qq{

$desc - $lex{Homework} $lex{'Not Found'}

\n}; } else { print qq{
$lex{Date}$lex{Topic}$lex{Description}
$ref->{duedatetime}$ref->{topic}$ref->{description}

\n}; } } # loop through all subjects. } # end of homework by Teacher print qq{\n}; } # end of showHomework