#!/usr/local/bin/webwork-perl
## $Id$
# This file is studentSummary.pl
#
# It is called from a form with inputs
# 'user',
#^'key'
# 'course'
# and possibly :
# 'studentLogin' (this means the script was called from the utility page by an instructor
# #######################################################################
# Copyright @1996, 1997 by Michael E. Gage and WeBWorK. All rights reserved.
# #######################################################################
use lib '.'; use webworkInit; # WeBWorKInitLine
#use CGI_Lite;
use CGI qw(:standard);
use Global;
use Auth;
require 5.003;
use strict;
# begin Timing code
use Benchmark;
my $beginTime = new Benchmark;
# end Timing code
&CGI::ReadParse;
my %inputs = %main::in;
# my %bitbucket = %main::in; # gets rid of -w "used once" error
# log access
&Global::log_info('', query_string);
# establish environment for this script
&Global::getCourseEnvironment($inputs{'course'});
my $scriptDirectory = $Global::scriptDirectory;
my $databaseDirectory = $Global::databaseDirectory;
my $htmlURL = $Global::htmlURL;
my $cgiURL = $Global::cgiWebworkURL;
my $keyFile = &Global::getCourseKeyFile($inputs{'course'});
&verify_key($inputs{'user'}, $inputs{'key'}, "$keyFile", $inputs{'course'});
require "${scriptDirectory}$Global::DBglue_pl";
require "${scriptDirectory}HTMLglue.pl";
require "${scriptDirectory}$Global::FILE_pl";
# Determine the effective user for this script
my $User = $inputs{'user'}; #default
# if this was called from the utilities page
# replace the instructor's login with the desired student's login
my $permissionsFile = &Global::getCoursePermissionsFile($inputs{'course'});
my $permissions = &get_permissions($inputs{'user'}, $permissionsFile);
if ( defined($inputs{'studentLogin'}) ) { # this means the script is called from the utility page.
# make sure the user is really an instructor!
if ($permissions != $Global::instructor_permissions ) {
print "permissions = $permissions instructor_permissions = $Global::instructor_permissions\n";
print &html_NO_PERMISSION;
exit(0);
}
else {
$User = $inputs{'studentLogin'};
}
}
my %setNumberHash = &getAllSetNumbersForStudentLoginHash($User);
# get information on open/due/answer dates for each problem and prepare
# HTML output;
my @SetNumberKeys = keys(%setNumberHash);
my @problemDates = ();
my $problemDateLine;
my ($probSetKey,$odts,$ddts,$adts,$timeNow,$DueDate,$AnswerDate,$OpenDate);
my $sortedSetNumber;
my $SetNumber;
my %dueTimes =();
my %openTimes =();
my %noOfProbs =();
foreach $SetNumber(@SetNumberKeys) {
$probSetKey=$setNumberHash{$SetNumber};
&attachProbSetRecord($probSetKey);
$odts=&getOpenDate($probSetKey);
$ddts=&getDueDate($probSetKey);
$dueTimes{$SetNumber} = $ddts;
$openTimes{$SetNumber} = $odts;
$noOfProbs{$SetNumber} = &getAllProblemsForProbSetRecord($probSetKey); ##scalar mode gives length of array
}
## Sort setnumbers by due date
sub by_due_date
{
$timeNow = time;
if ( ($dueTimes{$a} <= $timeNow) and ($dueTimes{$b} <= $timeNow) )
{
($dueTimes{$a} <=> $dueTimes{$b})
or
($a cmp $b)
}
elsif ( ($dueTimes{$a} > $timeNow) and ($dueTimes{$b} > $timeNow) )
{
($dueTimes{$a} <=> $dueTimes{$b})
or
($a cmp $b)
}
else
{
$dueTimes{$b} <=> $dueTimes{$a}
}
}
## Find max number of problems in sets
my $maxNoOfProbs = max(values %noOfProbs);
print &htmlTOP("Homework summary for $User");
print qq!
$twoString
$string