--- loncom/homework/bridgetask.pm 2005/11/21 22:28:13 1.82
+++ loncom/homework/bridgetask.pm 2005/12/01 18:46:31 1.87
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.82 2005/11/21 22:28:13 albertel Exp $
+# $Id: bridgetask.pm,v 1.87 2005/12/01 18:46:31 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -381,7 +381,7 @@ INFO
}
sub start_Task {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my ($status,$accessmsg,$slot);
if ($target ne 'webgrade') {
@@ -431,7 +431,7 @@ sub start_Task {
&Apache::lonxml::debug("Got $status");
$body_tag_start.=&add_previous_version_button($status);
if (!&show_task($status,$previous)) {
- my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
+ my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
if ( $target eq "web" ) {
$result.= $head_tag_start.''.$body_tag_start;
if ($env{'request.state'} eq 'construct') {
@@ -476,7 +476,8 @@ DONESCREEN
}
} elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
if ($status eq 'NEEDS_CHECKIN') {
- if(&proctor_check_auth($slot_name,$slot,'Task')) {
+ if(&proctor_check_auth($slot_name,$slot,'Task')
+ && defined($Apache::inputtags::slot_name)) {
my $result=&add_to_queue('gradingqueue',
[$Apache::inputtags::slot_name]);
&Apache::lonxml::debug("add_to_queue said $result");
@@ -551,7 +552,7 @@ DONESCREEN
}
}
$webgrade='no';
- my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
+ my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
}
if ($target eq 'webgrade' && defined($env{'form.queue'})) {
if ($webgrade eq 'yes') {
@@ -787,7 +788,8 @@ DONEBUTTON
}
&Apache::lonhomework::showhash(%Apache::lonhomework::results);
&Apache::structuretags::finalize_storage();
- if ($award eq 'SUBMITTED') {
+ if ($award eq 'SUBMITTED'
+ && defined($Apache::inputtags::slot_name)) {
&add_to_queue('gradingqueue',[$Apache::inputtags::slot_name]);
}
} elsif ($Apache::lonhomework::results{'INTERNAL_store'}) {
@@ -954,13 +956,17 @@ sub check_queue_unlock {
}
sub remove_from_queue {
- my ($queue)=@_;
+ my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_;
if ($queue eq 'none') { return 'ok'; }
- my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
- my $cnum=$env{'course.'.$cid.'.num'};
- my $cdom=$env{'course.'.$cid.'.domain'};
- my $key="$symb\0queue\0$uname\@$udom";
+ if (!defined($symb) || !defined($cdom) || !defined($cnum)
+ || !defined($udom) || !defined($uname)) {
+ ($symb,my $cid,$udom,$uname)=&Apache::lonxml::whichuser();
+ $cnum=$env{'course.'.$cid.'.num'};
+ $cdom=$env{'course.'.$cid.'.domain'};
+ }
+ my $key=&encode_queue_key($symb,$udom,$uname);
my @keys=($key,"$key\0locked");
+ &Apache::lonnet::logthis("removing @keys");
return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum);
}
@@ -988,10 +994,10 @@ sub get_queue_data {
return undef;
}
+
sub check_queue_for_key {
- my ($cid,$queue,$todo)=@_;
- my $cnum=$env{'course.'.$cid.'.num'};
- my $cdom=$env{'course.'.$cid.'.domain'};
+ my ($cdom,$cnum,$queue,$todo)=@_;
+
my %results=
&Apache::lonnet::get($queue,[$todo,"$todo\0locked"],$cdom,$cnum);
@@ -999,10 +1005,17 @@ sub check_queue_for_key {
if (defined($results{"$todo\0locked"})) {
return 'locked';
}
- my $slot=$results{$todo}->[0];
- my %slot_data=&Apache::lonnet::get_slot($slot);
- if ($slot_data{'endtime'} > time) {
- return 'in_progress';
+ my $slot;
+ if (ref($results{$todo}) eq 'ARRAY') {
+ $slot = $results{$todo}[0];
+ } elsif (ref($results{$todo}) eq 'HASH') {
+ $slot = $results{$todo}{'slot'};
+ }
+ if (defined($slot)) {
+ my %slot_data=&Apache::lonnet::get_slot($slot);
+ if ($slot_data{'endtime'} > time) {
+ return 'in_progress';
+ }
}
return 'enqueued';
}
@@ -1020,7 +1033,7 @@ sub add_to_queue {
my $cdom=$env{'course.'.$cid.'.domain'};
my %data;
$data{"$symb\0queue\0$uname\@$udom"}=$user_data;
- return &Apache::lonnet::newput($queue,\%data,$cdom,$cnum);
+ return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum);
}
sub show_queue {
@@ -1046,7 +1059,7 @@ sub show_queue {
if ($tmp=~/^error: 2 /) {
return "\n
Current Queue - $queue
";
}
- $result.="\nCurrent Queue - $queue
";
+ $result.="\nCurrent Queue - $symb $queue
";
if ($with_selects) { $result.=" | "; }
$result.="resource | user | type | data |
";
foreach my $key (sort(keys(%queue))) {
@@ -1234,6 +1247,27 @@ sub lock_key {
return 0;
}
+sub get_queue_symb_status {
+ my ($queue,$symb,$cdom,$cnum) = @_;
+ if (!defined($cdom) || !defined($cnum)) {
+ my (undef,$cid)=&Apache::lonxml::whichuser();
+ $cnum=$env{'course.'.$cid.'.num'};
+ $cdom=$env{'course.'.$cid.'.domain'};
+ }
+ my $regexp="^$symb\0";
+ my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
+ my ($tmp)=%queue;
+ if ($tmp=~/^error: 2 /) { return; }
+ my @users;
+ foreach my $key (sort(keys(%queue))) {
+ next if ($key=~/locked$/);
+ next if ($key=~/timestamp$/);
+ my ($symb,$uname,$udom) = &decode_queue_key($key);
+ push(@users,"$uname:$udom");
+ }
+ return @users;
+}
+
sub get_from_queue {
my ($queue)=@_;
my $result;
@@ -1245,8 +1279,8 @@ sub get_from_queue {
if ($todo) { return $todo; }
while (1) {
my $starttime=time;
- &Apache::lonnet::put($queue,{"$symb\0timestamp"=>$starttime},
- $cdom,$cnum);
+ &Apache::lonnet::cput($queue,{"$symb\0timestamp"=>$starttime},
+ $cdom,$cnum);
&Apache::lonxml::debug("$starttime");
my $regexp="^$symb\0queue\0";
my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
@@ -1317,7 +1351,9 @@ sub select_user {
foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
my ($uname,$udom) = split(/:/,$student);
- my %status = &get_student_status($symb,$cid,$udom,$uname);
+ my $cnum=$env{'course.'.$cid.'.num'};
+ my $cdom=$env{'course.'.$cid.'.domain'};
+ my %status = &get_student_status($symb,$cdom,$cnum,$udom,$uname);
my $queue = 'none';
my $cannot_grade;
if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) {
@@ -1396,17 +1432,23 @@ RESULT
}
sub get_student_status {
- my ($symb,$cid,$udom,$uname)=@_;
- my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
- $udom,$uname);
+ my ($symb,$cdom,$cnum,$udom,$uname,$type)=@_;
+
my %status;
- $status{'status'}=$record{'resource.status'};
- $status{'version'}=$record{'resource.version'};
- $status{'grader'}=$record{'resource.grader'};
- $status{'reviewqueue'}=&check_queue_for_key($cid,'reviewqueue',
- &encode_queue_key($symb,$udom,$uname));
- $status{'gradingqueue'}=&check_queue_for_key($cid,'gradingqueue',
- &encode_queue_key($symb,$udom,$uname));
+
+ if ($type eq 'Task') {
+ my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
+ $udom,$uname);
+ $status{'status'}=$record{'resource.status'};
+ $status{'version'}=$record{'resource.version'};
+ $status{'grader'}=$record{'resource.grader'};
+ }
+ $status{'reviewqueue'}=
+ &check_queue_for_key($cdom,$cnum,'reviewqueue',
+ &encode_queue_key($symb,$udom,$uname));
+ $status{'gradingqueue'}=
+ &check_queue_for_key($cdom,$cnum,'gradingqueue',
+ &encode_queue_key($symb,$udom,$uname));
return %status;
}
@@ -1656,14 +1698,14 @@ sub get_instance {
}
sub start_IntroParagraph {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result;
if ($target eq 'web' || $target eq 'webgrade') {
if ($tagstack->[-2] eq 'Dimension') {
- $dimension{'intro'}=&Apache::lonxml::get_all_text('/introparagraph',$parser);
+ $dimension{'intro'}=&Apache::lonxml::get_all_text('/introparagraph',$parser,$style);
} elsif ($target eq 'webgrade') {
- &Apache::lonxml::get_all_text('/introparagraph',$parser);
+ &Apache::lonxml::get_all_text('/introparagraph',$parser,$style);
}
}
@@ -1692,9 +1734,9 @@ sub end_Instance {
}
sub start_InstanceText {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $instance_id=$Apache::bridgetask::instance[-1];
- my $text=&Apache::lonxml::get_all_text('/instancetext',$parser);
+ my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
if ($target eq 'web' || $target eq 'webgrade') {
$dimension{$instance_id.'.text'}=$text;
}
@@ -1706,9 +1748,9 @@ sub end_InstanceText {
}
sub start_Criteria {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $instance_id=$Apache::bridgetask::instance[-1];
- my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser);
+ my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
my $id=&get_id($parstack,$safeeval);
$dimension{$instance_id.'.criteria.'.$id}=$criteria;