--- loncom/homework/lonhomework.pm 2004/12/22 22:08:17 1.191
+++ loncom/homework/lonhomework.pm 2005/04/04 18:13:16 1.203
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Homework handler
#
-# $Id: lonhomework.pm,v 1.191 2004/12/22 22:08:17 albertel Exp $
+# $Id: lonhomework.pm,v 1.203 2005/04/04 18:13:16 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -162,8 +162,18 @@ sub send_footer {
$request->print(&Apache::lontexconvert::footer());
}
-$Apache::lonxml::browse='';
+sub proctor_checked_in {
+ my ($slot)=@_;
+ my @allowed=split(",",$slot->{'proctor'});
+ foreach my $possible (@allowed) {
+ if ($Apache::lonhomework::history{'resource.checkedin'} eq $possible) {
+ return 1;
+ }
+ }
+ return 0;
+}
+$Apache::lonxml::browse='';
sub check_ip_acc {
my ($acc)=@_;
if (!defined($acc) || $acc =~ /^\s*$/) { return 1; }
@@ -209,6 +219,49 @@ sub check_ip_acc {
}
return $allowed;
}
+
+sub check_task_access {
+ #does it pass normal muster
+ my ($status,$datemsg)=&check_access;
+ if ($status eq 'SHOW_ANSWER' ||
+ $status eq 'CLOSED' ||
+ $status eq 'CANNOT_ANSWER' ||
+ $status eq 'INVALID_ACCESS' ||
+ $status eq 'UNAVAILABLE') {
+ return ($status,$datemsg);
+ }
+ if ($ENV{'request.state'} eq "construct") {
+ return ($status,$datemsg);
+ }
+
+ my ($id)=@_;
+ my @slots=split(':',&Apache::lonnet::EXT("resource.$id.available"));
+# if (!@slots) {
+# return ($status,$datemsg);
+# }
+ my $slotstatus='NOT_IN_A_SLOT';
+ my $returned_slot;
+ foreach my $slot (@slots) {
+ &Apache::lonxml::debug("getting $slot");
+ my %slot=&Apache::lonnet::get_slot($slot);
+ &Apache::lonhomework::showhash(%slot);
+ if ($slot{'starttime'} < time &&
+ $slot{'endtime'} > time &&
+ &check_ip_acc($slot{'ip'})) {
+ &Apache::lonxml::debug("$slot is good");
+ $slotstatus='NEEDS_CHECKIN';
+ $returned_slot=\%slot;
+ last;
+ }
+ }
+ if ($slotstatus eq 'NEEDS_CHECKIN' &&
+ &proctor_checked_in($returned_slot)) {
+ &Apache::lonxml::debug("protoctor checked in");
+ $slotstatus='CAN_ANSWER';
+ }
+ return ($slotstatus,$datemsg,$returned_slot);
+}
+
# JB, 9/24/2002: Any changes in this function may require a change
# in lonnavmaps::resource::getDateStatus.
sub check_access {
@@ -320,7 +373,7 @@ sub check_access {
&Apache::lonxml::debug("looking for accesstime $first_access");
if (!$first_access) {
$status='NOT_YET_VIEWED';
- $datemsg=' '.$interval.' seconds';
+ $datemsg=&seconds_to_human_length($interval);
} else {
my $newdate=localtime($first_access+$interval);
if (time > ($first_access+$interval)) {
@@ -348,6 +401,25 @@ sub check_access {
return ($status,$datemsg);
}
+sub seconds_to_human_length {
+ my ($length)=@_;
+
+ my $seconds=$length%60; $length=int($length/60);
+ my $minutes=$length%60; $length=int($length/60);
+ my $hours=$length%24; $length=int($length/24);
+ my $days=$length;
+
+ my $timestr;
+ if ($days > 0) { $timestr.=&mt('[quant,_1,day]',$days); }
+ if ($hours > 0) { $timestr.=($timestr?", ":"").
+ &mt('[quant,_1,hour]',$hours); }
+ if ($minutes > 0) { $timestr.=($timestr?", ":"").
+ &mt('[quant,_1,minute]',$minutes); }
+ if ($seconds > 0) { $timestr.=($timestr?", ":"").
+ &mt('[quant,_1,second]',$seconds); }
+ return $timestr;
+}
+
sub showhash {
my (%hash) = @_;
&showhashsubset(\%hash,'.');
@@ -358,10 +430,11 @@ sub showarray {
my ($array)=@_;
my $string="(";
foreach my $elm (@{ $array }) {
- if (ref($elm)) {
- if ($elm =~ /ARRAY/ ) {
- $string.=&showarray($elm);
- }
+ if (ref($elm) eq 'ARRAY') {
+ $string.=&showarray($elm);
+ } elsif (ref($elm) eq 'HASH') {
+ $string.= "HASH --- \n
";
+ $string.= &showhashsubset($elm,'.');
} else {
$string.="$elm,"
}
@@ -375,20 +448,15 @@ sub showhashsubset {
my ($hash,$keyre) = @_;
my $resultkey;
foreach $resultkey (sort keys %$hash) {
- if ($resultkey =~ /$keyre/) {
- if (ref($$hash{$resultkey})) {
- if ($$hash{$resultkey} =~ /ARRAY/ ) {
- &Apache::lonxml::debug("$resultkey ---- ".
- &showarray($$hash{$resultkey}));
- } elsif ($$hash{$resultkey} =~ /HASH/ ) {
- &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
- &showhashsubset($$hash{$resultkey},'.');
- } else {
- &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
- }
- } else {
- &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
- }
+ if ($resultkey !~ /$keyre/) { next; }
+ if (ref($$hash{$resultkey}) eq 'ARRAY' ) {
+ &Apache::lonxml::debug("$resultkey ---- ".
+ &showarray($$hash{$resultkey}));
+ } elsif (ref($$hash{$resultkey}) eq 'HASH' ) {
+ &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
+ &showhashsubset($$hash{$resultkey},'.');
+ } else {
+ &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
}
}
&Apache::lonxml::debug("\n
restored values^\n");
@@ -416,14 +484,12 @@ sub setuppermissions {
sub setupheader {
my $request=$_[0];
- if ($ENV{'browser.mathml'}) {
- &Apache::loncommon::content_type($request,'text/xml');
- } else {
- &Apache::loncommon::content_type($request,'text/html');
- }
+ &Apache::loncommon::content_type($request,'text/html');
if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) {
&Apache::loncommon::no_cache($request);
}
+# $request->set_last_modified(&Apache::lonnet::metadata($request->uri,
+# 'lastrevisiondate'));
$request->send_http_header;
return OK if $request->header_only;
return ''
@@ -479,7 +545,8 @@ sub analyze_header {
if ($ENV{'environment.remote'} eq 'off') {
$bodytag=&Apache::loncommon::bodytag();
}
- my $result.='
+ my $html=&Apache::lonxml::xmlbegin();
+ my $result.=$html.'