--- loncom/homework/bridgetask.pm 2005/05/19 21:28:06 1.26
+++ loncom/homework/bridgetask.pm 2005/05/27 17:08:03 1.32
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.26 2005/05/19 21:28:06 albertel Exp $
+# $Id: bridgetask.pm,v 1.32 2005/05/27 17:08:03 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -71,11 +71,16 @@ sub proctor_check_auth {
if ($authhost ne 'no_host') {
my $version=
$Apache::lonhomework::results{'resource.version'}=
- $Apache::lonhomework::history{'resource.version'}++;
+ ++$Apache::lonhomework::history{'resource.version'};
$Apache::lonhomework::results{"resource.$version.checkedin"}=
$user.'@'.$domain;
$Apache::lonhomework::results{"resource.$version.checkedin.slot"}=
$slot_name;
+ foreach my $key (keys(%Apache::lonhomework::history)) {
+ if ($key=~/^resource\.0\./) {
+ $Apache::lonhomework::results{$key}='';
+ }
+ }
return 1;
}
}
@@ -84,35 +89,67 @@ sub proctor_check_auth {
}
sub get_version {
+ my ($version,$previous);
if ($env{'form.previousversion'} &&
defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) {
- return $env{'form.previousversion'};
+ $version=$env{'form.previousversion'};
+ $previous=1;
+ } else {
+ $version=$Apache::lonhomework::history{'resource.version'};
+ $previous=0;
}
- return $Apache::lonhomework::history{'resource.version'};
+ if (wantarray) {
+ return ($version,$previous);
+ }
+ return $version;
}
sub add_previous_version_button {
my ($status)=@_;
my $result;
- if ($Apache::lonhomework::history{'resource.version'} eq '0') {
+ if ($Apache::lonhomework::history{'resource.version'} eq '') {
return '';
}
- my $version=&get_version();
- if ($version ne $Apache::lonhomework::history{'resource.version'}) {
+ if ($Apache::lonhomework::history{'resource.version'} < 2 &&
+ $status ne 'NEEDS_CHECKIN') {
return '';
}
-
- $result.=&mt(' Show a previously done version: [_1]','
-Pick one
- ');
+ my $version=&get_version();
+ if ($env{'form.previousversion'} ne '' &&
+ $env{'form.previousversion'} eq $version) {
+ $result.="
".&mt("Showing previous version [_1]",$version).
+ " \n";
+ }
+ my @to_show;
+ foreach my $test_version (1..$Apache::lonhomework::history{'resource.version'}) {
+ if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.status'})) {
+ push(@to_show,$test_version);
+ }
+ }
+ my $list=''.
+ join(" \n",@to_show).
+ " \n";
+ $result.='";
return $result;
}
sub add_grading_button {
- my $result;
- $result.=' ';
$result.=' ';
+ if ( 1) {
+ #need a permissions for limitng this to 'powerful users'
+ #check if review queue has items
+ $result.=' ';
+ }
return $result;
}
@@ -123,6 +160,18 @@ sub add_request_another_attempt_button {
return $result;
}
+sub preserve_grade_info {
+ my $result;
+ # if we are viewing someone else preserve that info
+ if (defined $env{'form.grade_symb'}) {
+ foreach my $field ('symb','courseid','domain','username') {
+ $result .= ' '."\n";
+ }
+ }
+ return $result;
+}
+
sub start_Task {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
@@ -147,7 +196,7 @@ sub start_Task {
}
if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
$target eq 'tex') {
- my $version=&get_version();
+ my ($version,$previous)=&get_version();
($status,$accessmsg,my $slot_name,$slot) =
&Apache::lonhomework::check_task_access('0');
push(@Apache::inputtags::status,$status);
@@ -157,13 +206,14 @@ sub start_Task {
&Apache::run::run($expression,$safeeval);
&Apache::lonxml::debug("Got $status");
$body_tag_start.=&add_previous_version_button($status);
- if (( $status eq 'CLOSED' ) ||
- ( $status eq 'BANNED') ||
- ( $status eq 'UNAVAILABLE') ||
- ( $status eq 'NOT_IN_A_SLOT') ||
- ( $status eq 'NEEDS_CHECKIN') ||
- ( $status eq 'WAITING_FOR_GRADE') ||
- ( $status eq 'INVALID_ACCESS')) {
+ if (!$previous && (
+ ( $status eq 'CLOSED' ) ||
+ ( $status eq 'BANNED') ||
+ ( $status eq 'UNAVAILABLE') ||
+ ( $status eq 'NOT_IN_A_SLOT') ||
+ ( $status eq 'NEEDS_CHECKIN') ||
+ ( $status eq 'WAITING_FOR_GRADE') ||
+ ( $status eq 'INVALID_ACCESS') )) {
my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
if ( $target eq "web" ) {
$result.= $head_tag_start.''.$body_tag_start;
@@ -208,17 +258,13 @@ sub start_Task {
$result.="$head_tag_start$name
$body_tag_start \n $form_tag_start".
' ';
- # if we are viewing someone else preserve that info
- if (defined $env{'form.grade_symb'}) {
- foreach my $field ('symb','courseid','domain','username') {
- $result .= ' '."\n";
- }
- }
- my $version=&get_version();
+ $result.=&preserve_grade_info();
+ my ($version,$previous)=&get_version();
if ($Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
$result.=''.&mt('Did not pass').' ';
- $result.=&add_request_another_attempt_button();
+ if (!$previous) {
+ $result.=&add_request_another_attempt_button();
+ }
}
if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass') {
$result.=''.&mt('Passed').' ';
@@ -226,29 +272,56 @@ sub start_Task {
}
} elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
$target eq 'webgrade') {
+ my $webgrade='yes';
if ($target eq 'webgrade') {
- $result.=$head_tag_start.$body_tag_start.$form_tag_start;
- $result.=' ';
- $result.=&show_queue();
- }
- my $todo=&get_from_queue();
- if ($todo) {
- &setup_env_for_other_user($todo,$safeeval);
- my ($symb,$uname,$udom)=&decode_queue_key($todo);
- $result.="\n".'Found '.
- &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'
';
- $result.=' ';
- $Apache::bridgetask::queue_key=$todo;
- &Apache::structuretags::initialize_storage();
- &Apache::lonhomework::showhash(%Apache::lonhomework::history);
- $result.="\n".'';
+ #FIXME FORM conflcit with the 'show queue',1
+ $result.=$head_tag_start.$body_tag_start;
+ $result.=' Review'.&show_queue('reviewqueue');
+ $result.=' Before'.&show_queue('gradingqueue');
+ }
+ if (defined($env{'form.reviewasubmission'})) {
+ $result.=&show_queue('reviewqueue',1);
+ my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
} else {
- if ($target eq 'webgrade') {
- $result.="\n".
- '';
+ my ($todo,$status_code)=&get_key_todo($target);
+ if ($todo) {
+ &setup_env_for_other_user($todo,$safeeval);
+ my ($symb,$uname,$udom)=&decode_queue_key($todo);
+ $result.="\n".'Found '.
+ &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'
';
+ $result.=' ';
+ $Apache::bridgetask::queue_key=$todo;
+ &Apache::structuretags::initialize_storage();
+ &Apache::lonhomework::showhash(%Apache::lonhomework::history);
+ if ($target eq 'webgrade') {
+ $result.=' After'.&show_queue('gradingqueue');
+ $result.="\n".'';
+ }
+ } else {
+ if ($target eq 'webgrade') {
+ $result.="\n".'';
+ if ($status_code eq 'stop') {
+ $result.=&mt("Stopped grading.");
+ } elsif ($status_code eq 'lock_failed') {
+ $result.=&mt("Failed to lock the request record.");
+ } elsif ($status_code eq 'unlock') {
+ $result.=&mt("Unlocked the requested user.");
+ } else {
+ $result.=&mt("No user to be graded.");
+ }
+ $result.='
';
+ }
+ $webgrade='no';
+ my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
}
- my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
+ }
+ if ($target eq 'webgrade' && defined($env{'form.queue'})) {
+ $result.=$form_tag_start;
+ $result.=' ';
+ $result.=' ';
}
} else {
# page_start returned a starting result, delete it if we don't need it
@@ -257,11 +330,46 @@ sub start_Task {
return $result;
}
+sub get_key_todo {
+ my ($target)=@_;
+ my $todo;
+ my $queue=$env{'form.queue'};
+ if (!defined($queue)) {
+ $env{'form.queue'}=$queue='gradingqueue';
+ }
+ my $gradingkey=&Apache::lonnet::unescape($env{'form.gradingkey'});
+ if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
+ && !defined($env{'form.action'})) {
+ #FIXME probably need to do some cheking here for more validity
+ &Apache::lonnet::logthis("Found a key was given to me");
+ return ($gradingkey);
+ }
+ if ($env{'form.action'} eq 'resume') {
+ &Apache::lonnet::logthis("Resuming a key");
+ return ($gradingkey);
+ } elsif ($env{'form.action'} eq 'unlock') {
+ &Apache::lonnet::logthis("Unlocking a key ".
+ &check_queue_unlock($queue,$gradingkey,1));
+ return (undef,'unlock');
+ } elsif ($env{'form.action'} eq 'select') {
+ if (&lock_key($queue,$gradingkey)) {
+ return ($gradingkey);
+ }
+ return (undef,'lock_failed');
+ }
+ # don't get something new from the queue if they hit the stop button
+ if (!($env{'form.stop'} && $target eq 'webgrade')) {
+ return (&get_from_queue($queue));
+ } else {
+ return (undef,'stop');
+ }
+}
+
sub end_Task {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $result='';
my $status=$Apache::inputtags::status['-1'];
- my $version=&get_version();
+ my ($version,$previous)=&get_version();
if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
$target eq 'tex') {
if (
@@ -269,9 +377,9 @@ sub end_Task {
($target eq 'answer') || ($target eq 'tex')
) {
if ($target eq 'web') {
- if ($status eq 'CAN_ANSWER') {
+ if ($status eq 'CAN_ANSWER' && !$previous) {
$result.="\n".''.
- &Apache::inputtags::file_selector($version,
+ &Apache::inputtags::file_selector("$version.0",
"bridgetask","*",
'portfolioonly').
"
";
@@ -282,23 +390,27 @@ sub end_Task {
$result.=&Apache::lonxml::xmlend().'