--- loncom/homework/bridgetask.pm 2006/06/01 19:20:56 1.159
+++ loncom/homework/bridgetask.pm 2006/06/12 18:57:20 1.166
@@ -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.166 2006/06/12 18:57:20 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.=<
';
+ foreach my $file (@files) {
+ my $url="/uploaded/$domain/$user/portfolio$file";
+ if (! &Apache::lonnet::stat_file($url)) {
+ $file = &mt(' Nonexistent file: '.
+ '[_1]',$file);
+ } else {
+ $file = ''.$file.'';
+ }
+ $files .= ''.$file.'';
+ }
+ $files.='';
+
+ return <$title
+ Files submitted: $files
+ You are now done with this Bridge Task
+
+ Logout
+ Change to a different course
+DONESCREEN
+
+}
+
sub start_Task {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
@@ -455,8 +502,10 @@ sub start_Task {
if ($target eq 'web' && $env{'request.state'} eq 'construct') {
$form_tag_start.=&Apache::structuretags::problem_web_to_edit_header($env{'form.rndseed'});
}
- if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
- $target eq 'tex') {
+ if ($target eq 'web'
+ || ($target eq 'grade' && !$env{'form.webgrade'})
+ || $target eq 'answer'
+ || $target eq 'tex') {
my ($version,$previous)=&get_version();
($status,$accessmsg,my $slot_name,$slot) =
&Apache::lonhomework::check_slot_access('0','Task');
@@ -493,30 +542,7 @@ sub start_Task {
} elsif ($status eq 'WAITING_FOR_GRADE') {
$msg.=''.&mt('Your submission is in the grading queue.').'
';
} elsif ($env{'form.donescreen'}) {
- my $title=&Apache::lonnet::gettitle();
- my @files=split(',',$Apache::lonhomework::history{'resource.'.$version.'.0.bridgetask.portfiles'});
- my (undef,undef,$domain,$user)=
- &Apache::lonxml::whichuser();
- my $files = '';
- foreach my $file (@files) {
- my $url="/uploaded/$domain/$user/portfolio$file";
- if (! &Apache::lonnet::stat_file($url)) {
- $file = &mt(' Nonexistant file: [_1]',$file);
- } else {
- $file = ''.$file.'';
- }
- $files .= '- '.$file.'
';
- }
- $files.='
';
-
- $result.=<$title
- Files submitted: $files
- You are now done with this Bridge Task
-
- Logout
- Change to a different course
-DONESCREEN
+ $result .= &done_screen();
} elsif ($status ne 'NOT_YET_VIEWED') {
$msg.=''.&mt('Not open to be viewed').'
';
}
@@ -592,6 +618,17 @@ DONESCREEN
&mt('Return to resource').'';
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 =~ /still_open:(.*)/) {
+ my $date = &Apache::lonlocal::locallocaltime($1);
+ $result.=''.
+ &mt("Task is still open, will close at [_1].",$date).
+ ''.$back;
} elsif ($status_code eq 'lock_failed') {
$result.=''.&mt("Failed to lock the requested record.")
.''.$back;
@@ -612,6 +649,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'})) {
@@ -654,6 +693,20 @@ DONESCREEN
return $result;
}
+sub get_task_end_time {
+ my ($queue_entry,$symb,$udom,$uname) = @_;
+
+ my $end_time;
+ if (my $slot = &slotted_access($queue_entry)) {
+ my %slot_data=&Apache::lonnet::get_slot($slot);
+ $end_time = $slot_data{'endtime'};
+ } else {
+ $end_time = &Apache::lonhomework::due_date('0',$symb,
+ $udom,$uname);
+ }
+ return $end_time;
+}
+
sub get_key_todo {
my ($target)=@_;
my $todo;
@@ -702,18 +755,34 @@ 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);
}
+ if ($queue) {
+ my $queue_entry = &get_queue_data($queue,$udom,$uname);
+
+ my $end_time = &get_task_end_time($queue_entry,$symb,
+ $udom,$uname);
+ if ($end_time > time) {
+ return (undef,"still_open:$end_time");
+ }
+ }
+
my $who=&queue_key_locked($queue,$gradingkey);
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 +809,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 +856,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 +1009,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 +1168,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");
@@ -1147,8 +1225,12 @@ sub setup_env_for_other_user {
}
sub get_queue_data {
- my ($queue)=@_;
- my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
+ my ($queue,$udom,$uname)=@_;
+ my ($symb,$cid,$other_udom,$other_uname)=&Apache::lonxml::whichuser();
+ if (!$uname || !$udom) {
+ $uname=$other_uname;
+ $udom =$other_udom;
+ }
my $cnum=$env{'course.'.$cid.'.num'};
my $cdom=$env{'course.'.$cid.'.domain'};
my $todo="$symb\0queue\0$uname:$udom";
@@ -1791,6 +1873,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 +1896,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 +1970,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 +2060,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 +2097,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 +2148,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;
}