--- loncom/homework/bridgetask.pm 2006/06/01 19:20:56 1.159
+++ loncom/homework/bridgetask.pm 2006/06/09 23:09:01 1.164
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.159 2006/06/01 19:20:56 albertel Exp $
+# $Id: bridgetask.pm,v 1.164 2006/06/09 23:09:01 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -43,7 +43,7 @@ use LONCAPA;
BEGIN {
- &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','Instance','InstanceText','Criteria','ClosingParagraph'));
+ &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','ClosingParagraph'));
}
sub initialize_bridgetask {
@@ -365,26 +365,44 @@ sub file_list {
my $file=$file_url.$partial_file;
$file=~s|/+|/|g;
&Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
- $file_list.='
'.$file.
- ''."\n";
+ $file_list.='
'.$file.
+ ''."\n";
}
$file_list.="\n";
return $file_list;
}
+sub grade_mode {
+ if ($env{'form.regrade'} || $env{'form.regradeaspecificsubmission'}) {
+ return 'regrade';
+ }
+ return 'queue_grade';
+}
+
sub webgrade_standard_info {
my ($version)=&get_version();
my $file_list = &file_list($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"});
- my %lt=&Apache::lonlocal::texthash('done' => 'Next Item',
- 'stop' => 'Quit Grading',
- 'fail' => 'Fail Rest',
- );
-
+ my %lt=('done' => 'Next Item',
+ 'stop' => 'Quit Grading',
+ 'fail' => 'Fail Rest',
+ 'cancel' => 'Cancel',
+ );
+ my %lt=&Apache::lonlocal::texthash(%lt);
+
my $result=<
+INFO
+
+ if (&grade_mode() eq 'regrade') {
+ $result.=<
+INFO
+ }
+
+ $result.=<
';
if ($status_code eq 'stop') {
$result.=''.&mt("Stopped grading.").''.$back;
+ } elsif ($status_code eq 'cancel') {
+ $result.=''.&mt("Cancelled grading.").''.$back;
+ } elsif ($status_code eq 'never_versioned') {
+ $result.=''.
+ &mt("Requested user has never accessed the task.").
+ ''.$back;
} elsif ($status_code eq 'lock_failed') {
$result.=''.&mt("Failed to lock the requested record.")
.''.$back;
@@ -612,6 +638,8 @@ DONESCREEN
}
}
$webgrade='no';
+ }
+ if (!$todo || $env{'form.cancel'}) {
my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
}
if ($target eq 'webgrade' && defined($env{'form.queue'})) {
@@ -702,6 +730,10 @@ sub get_key_todo {
if (!$queue) {
$env{'form.queue'} = $queue = 'none';
#not queued so doing either a re or pre grade
+ my %status = &Apache::lonnet::restore($symb,$cid,$udom,$uname);
+ if ($status{'resource.0.version'} < 1) {
+ return (undef,'never_versioned');
+ }
return ($gradingkey);
}
@@ -709,11 +741,13 @@ sub get_key_todo {
if ($who eq $me) {
#already have the lock
$env{'form.gradingkey'}=&escape($gradingkey);
+ &Apache::lonxml::debug("already locked");
return ($gradingkey);
}
if (!defined($who)) {
if (&lock_key($queue,$gradingkey)) {
+ &Apache::lonxml::debug("newly locked");
return ($gradingkey);
} else {
return (undef,'lock_failed');
@@ -740,6 +774,8 @@ sub get_key_todo {
if ($target eq 'webgrade') {
if ($env{'form.stop'}) {
return (undef,'stop');
+ } elsif ($env{'form.cancel'}) {
+ return (undef,'cancel');
} elsif ($env{'form.next'}) {
return (undef,'select_user');
}
@@ -785,7 +821,8 @@ sub get_key_todo {
if ($env{'form.queuemode'} ne 'selected') {
# don't get something new from the queue if they hit the stop button
- if (!($env{'form.stop'} && $target eq 'webgrade')
+ if (!(($env{'form.cancel'} || $env{'form.stop'})
+ && $target eq 'webgrade')
&& !$env{'form.gradingaction'}) {
&Apache::lonxml::debug("Getting anew $queue");
return (&get_from_queue($queue));
@@ -937,7 +974,12 @@ DONEBUTTON
} elsif ($Apache::lonhomework::results{'INTERNAL_store'}) {
&Apache::structuretags::finalize_storage();
}
- if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
+ if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes'
+ && exists($env{'form.cancel'})) {
+ &check_queue_unlock($env{'form.queue'});
+ &Apache::lonxml::debug(" cancelled grading .".$env{'form.queue'});
+ } elsif ($target eq 'grade' && $env{'form.webgrade'} eq 'yes'
+ && !exists($env{'form.cancel'})) {
my $optional_required=
&Apache::lonxml::get_param('OptionalRequired',$parstack,
$safeeval);
@@ -1091,6 +1133,7 @@ sub check_queue_unlock {
my $me=$env{'user.name'}.':'.$env{'user.domain'};
my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
if ($who eq $me) {
+ &Apache::lonxml::debug("unlocking my own $who");
return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
} elsif ($allow_not_me) {
&Apache::lonxml::debug("unlocking $who by $me");
@@ -1791,6 +1834,15 @@ sub get_id {
}
my %dimension;
+sub start_Setup {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ undef(%dimension);
+ my $dim_id=&get_id($parstack,$safeeval);
+ $Apache::bridgetask::dimension=$dim_id;
+ undef(@Apache::bridgetask::instance);
+ &Apache::lonxml::startredirection();
+ return &internal_location($dim_id);
+}
sub start_Question { return &start_Dimension(@_); }
sub start_Dimension {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
@@ -1805,6 +1857,20 @@ sub start_Dimension {
return &internal_location($dim_id);
}
+sub start_QuestionText {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ my $dim_id=$Apache::bridgetask::dimension;
+ my $text=&Apache::lonxml::get_all_text('/questiontext',$parser,$style);
+ if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
+ $dimension{'questiontext'}=$text;
+ }
+ return '';
+}
+
+sub end_QuestionText {
+ return '';
+}
+
sub get_instance {
my ($dim)=@_;
my $rand_alg=&Apache::lonnet::get_rand_alg();
@@ -1865,9 +1931,12 @@ sub get_instance {
if (&Apache::response::showallfoils()) {
@instances = @{$dimension{'instances'}};
}
+ my $shown_question_text;
foreach my $instance (@instances) {
@Apache::scripttag::parser_env = @_;
$result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
+ @Apache::scripttag::parser_env = @_;
+ $result.=&Apache::scripttag::xmlparse($dimension{'questiontext'});
if ($Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass' ||
$Apache::lonhomework::history{"resource.$version.0.status"} eq 'fail') {
@@ -1952,6 +2021,8 @@ sub get_instance {
&Apache::scripttag::xmlparse($dimension{'intro'});
@Apache::scripttag::parser_env = @_;
&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
+ @Apache::scripttag::parser_env = @_;
+ &Apache::scripttag::xmlparse($dimension{'questiontext'});
foreach my $id (@{$dimension{$instance.'.criterias'}},
@{$dimension{'criterias'}} ) {
my $link=&link($id);
@@ -1987,11 +2058,14 @@ sub get_instance {
@Apache::scripttag::parser_env = @_;
$result.=&Apache::scripttag::xmlparse($dimension{'intro'});
+ @Apache::scripttag::parser_env = @_;
+ $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
+ @Apache::scripttag::parser_env = @_;
+ &Apache::scripttag::xmlparse($dimension{'questiontext'});
+
foreach my $id (@{$dimension{$instance.'.criterias'}},
@{$dimension{'criterias'}}) {
my $link=&link($id);
- @Apache::scripttag::parser_env = @_;
- $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
my $status=$Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link};
$Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link};
my $mandatory=($dimension{'criteria.'.$id.'.mandatory'} ne 'N');
@@ -2035,6 +2109,41 @@ sub get_instance {
} else {
# any other targets no output
undef($result);
+ }
+ return $result;
+ }
+
+ sub end_Setup {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my $result=&Apache::lonxml::endredirection();
+ my $dim=&get_id($parstack,$safeeval);
+ my $instance=&get_instance($dim);
+ my $version=&get_version();
+ if ($target eq 'web') {
+ @Apache::scripttag::parser_env = @_;
+ $result.=&Apache::scripttag::xmlparse($dimension{'intro'});
+ my @instances = $instance;
+ if (&Apache::response::showallfoils()) {
+ @instances = @{$dimension{'instances'}};
+ }
+ foreach my $instance (@instances) {
+ @Apache::scripttag::parser_env = @_;
+ $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
+ @Apache::scripttag::parser_env = @_;
+ $result.=&Apache::scripttag::xmlparse($dimension{'questiontext'});
+ }
+ } elsif ($target eq 'webgrade'
+ || $target eq 'grade' && $env{'form.webgrade'}) {
+ # in case of any side effects that we need
+ @Apache::scripttag::parser_env = @_;
+ &Apache::scripttag::xmlparse($dimension{'intro'});
+ @Apache::scripttag::parser_env = @_;
+ &Apache::scripttag::xmlparse($dimension{$instance.'.text'});
+ @Apache::scripttag::parser_env = @_;
+ &Apache::scripttag::xmlparse($dimension{'questiontext'});
+ } else {
+ # any other targets no output
+ undef($result);
}
return $result;
}