--- loncom/homework/bridgetask.pm 2006/06/01 19:31:12 1.161
+++ loncom/homework/bridgetask.pm 2006/10/31 21:29:38 1.188
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.161 2006/06/01 19:31:12 albertel Exp $
+# $Id: bridgetask.pm,v 1.188 2006/10/31 21:29:38 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -43,23 +43,23 @@ use LONCAPA;
BEGIN {
- &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Instance','InstanceText','Criteria','ClosingParagraph'));
+ &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','GraderNote','ClosingParagraph'));
}
+my %dimension;
sub initialize_bridgetask {
# id of current Dimension, 0 means that no dimension is current
# (inside only)
- $Apache::bridgetask::dimension='';
+ @Apache::bridgetask::dimension=();
# list of all Dimension ids seen
- @Apache::bridgetask::dimensionlist=();
- # mandatory attribute of all Dimensions seen
- %Apache::bridgetask::dimensionmandatory=();
+ %Apache::bridgetask::top_dimensionlist=();
# list of all current Instance ids
- @Apache::bridgetask::instance=();
+ %Apache::bridgetask::instance=();
# list of all Instance ids seen in this problem
@Apache::bridgetask::instancelist=();
# key of queud user data that we are currently grading
$Apache::bridgetask::queue_key='';
+ undef(%dimension);
}
sub proctor_check_auth {
@@ -83,7 +83,7 @@ sub proctor_check_auth {
}
}
if ($authenticated) {
- &create_new_version($type,$user,$domain,$slot_name);
+ &check_in($type,$user,$domain,$slot_name);
return 1;
}
}
@@ -91,8 +91,43 @@ sub proctor_check_auth {
return 0;
}
+sub check_in {
+ my ($type,$user,$domain,$slot_name) = @_;
+ my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
+ if ( $useslots eq 'map_map') {
+ &check_in_sequence($user,$domain,$slot_name);
+ } else {
+ &create_new_version($type,$user,$domain,$slot_name);
+ }
+ return 1;
+}
+
+sub check_in_sequence {
+ my ($user,$domain,$slot_name) = @_;
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ my ($symb) = &Apache::lonnet::whichuser();
+ my ($map) = &Apache::lonnet::decode_symb($symb);
+ my @resources =
+ $navmap->retrieveResources($map, sub { $_[0]->is_problem() },0,0);
+ my %old_history = %Apache::lonhomework::history;
+ my %old_results = %Apache::lonhomework::results;
+
+ foreach my $res (@resources) {
+ &Apache::lonxml::debug("doing ".$res->src);
+ &Apache::structuretags::initialize_storage($res->symb);
+ my $type = ($res->is_task()) ? 'Task' : 'problem';
+ &create_new_version($type,$user,$domain,$slot_name);
+ &Apache::structuretags::finalize_storage($res->symb);
+ }
+
+ %Apache::lonhomework::history = %old_history;
+ %Apache::lonhomework::results = %old_results;
+}
+
sub create_new_version {
my ($type,$user,$domain,$slot_name) = @_;
+
+ my $id = '0';
if ($type eq 'Task') {
# increment version
my $version=
@@ -107,28 +142,27 @@ sub create_new_version {
}
#setup new version and who did it
- $Apache::lonhomework::results{'resource.0.version'}=$version;
- if (defined($user) && defined($domain)) {
- $Apache::lonhomework::results{"resource.$version.0.checkedin"}=
- $user.':'.$domain;
- } else {
- $Apache::lonhomework::results{"resource.$version.0.checkedin"}=
- $env{'user.name'}.':'.$env{'user.domain'};
- }
- if (defined($slot_name)) {
- $Apache::lonhomework::results{"resource.$version.0.checkedin.slot"}=
- $slot_name;
+ $Apache::lonhomework::results{'resource.0.version'}=$version;
+ $id = "$version.0";
+ if (!defined($user) || !defined($domain)) {
+ $user = $env{'user.name'};
+ $domain = $env{'user.domain'};
}
+
} elsif ($type eq 'problem') {
&Apache::lonxml::debug("authed $slot_name");
- if (defined($user) && defined($domain)) {
- $Apache::lonhomework::results{"resource.0.checkedin"}=
- $user.':'.$domain;
- }
- if (defined($slot_name)) {
- $Apache::lonhomework::results{"resource.0.checkedin.slot"}=
- $slot_name;
- }
+ }
+ if (!defined($user) || !defined($domain)) {
+ $user = $env{'user.name'};
+ $domain = $env{'user.domain'};
+ }
+
+ $Apache::lonhomework::results{"resource.$id.checkedin"}=
+ $user.':'.$domain;
+
+ if (defined($slot_name)) {
+ $Apache::lonhomework::results{"resource.$id.checkedin.slot"}=
+ $slot_name;
}
}
@@ -191,7 +225,7 @@ sub add_previous_version_button {
}
sub add_grading_button {
- my (undef,$cid)=&Apache::lonxml::whichuser();
+ my (undef,$cid)=&Apache::lonnet::whichuser();
my $cnum=$env{'course.'.$cid.'.num'};
my $cdom=$env{'course.'.$cid.'.domain'};
my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
@@ -316,18 +350,52 @@ sub show_task {
return 1;
}
+my @delay;
+sub nest {
+ if (@delay) {
+ return $delay[-1];
+ } else {
+ return;
+ }
+}
+
+sub nested_parse {
+ my ($str,$env,$args) = @_;
+ my @old_env = @Apache::scripttag::parser_env;
+ @Apache::scripttag::parser_env = @$env;
+ if (exists($args->{'set_dim_id'})) {
+ &enable_dimension_parsing($args->{'set_dim_id'});
+ }
+ push(@delay,(($args->{'delayed_dim_results'})? 1 : 0));
+ my $result = &Apache::scripttag::xmlparse($$str);
+ pop(@delay);
+ if (exists($args->{'set_dim_id'})) {
+ &disable_dimension_parsing();
+ }
+ @Apache::scripttag::parser_env = @old_env;
+ if ($args->{'delayed_dim_results'}) {
+ my $dim = &get_dim_id();
+ &Apache::lonxml::debug(" tossing out $result ");
+ &Apache::lonxml::debug(" usining out $dim 's ". $dimension{$dim}{'result'});
+ return $dimension{$dim}{'result'};
+ }
+ return $result;
+}
+
sub internal_location {
my ($id)=@_;
return '';
}
sub submission_time_stamp {
- my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
+ my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
my $submissiontime;
my $version=$Apache::lonhomework::history{'resource.0.version'};
for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) {
- if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})) {
+ if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})
+ && defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.tries'})) {
$submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
+ last;
}
}
my $result;
@@ -338,16 +406,18 @@ sub submission_time_stamp {
my ($color,$when)=('#FF6666','after');
if ($diff > 0) { ($color,$when)=('#336600','before'); }
my $info;
+ $diff = abs($diff);
if ($diff%60) { $info=($diff%60).' seconds'; }
$diff=int($diff/60);
if ($diff%60) { $info=($diff%60).' minutes '.$info; }
$diff=int($diff/60);
if ($diff) { $info=$diff.' hours '.$info; }
$result='
'.
- &mt('Student submitted [_1] [_2] the deadline.
- (Submission was at [_3], end of period was [_4].)',
- $info,$when,scalar(localtime($submissiontime)),
- scalar(localtime($slot{'endtime'}))).
+ &mt('Student submitted [_1] [_2] the deadline. '.
+ '(Submission was at [_3], end of period was [_4].)',
+ $info,$when,
+ &Apache::lonlocal::locallocaltime($submissiontime),
+ &Apache::lonlocal::locallocaltime($slot{'endtime'})).
'
';
}
return $result;
@@ -356,7 +426,7 @@ sub submission_time_stamp {
sub file_list {
my ($files,$uname,$udom) = @_;
if (!defined($uname) || !defined($udom)) {
- (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
+ (undef,undef,$udom,$uname) = &Apache::lonnet::whichuser();
}
my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
@@ -373,18 +443,36 @@ sub file_list {
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',
+ );
+ %lt=&Apache::lonlocal::texthash(%lt);
+
my $result=<
+INFO
+
+ if (&grade_mode() eq 'regrade') {
+ $result.=<
+INFO
+ }
+
+ $result.=<
';
+ my $msg;
+ foreach my $file (@files) {
+ my $url="/uploaded/$domain/$user/portfolio$file";
+ if (! &Apache::lonnet::stat_file($url)) {
+ $file = &mt(' Nonexistent file: '.
+ '[_1]',$file);
+ $msg .= "
'."\n".
@@ -1998,25 +2285,40 @@ sub get_instance {
$result.=&grading_history($version,$dim,$id);
$last_link=$link;
}
+ if (&nest()) {
+ &Apache::lonxml::debug(" for $dim stashing results into ".$dimension{$dim}{'nested'});
+ $dimension{$dimension{$dim}{'nested'}}{'result'}.=$result;
+ undef($result);
+ }
} elsif ($target eq 'grade' && $env{'form.webgrade'}) {
my $optional_passed=0;
my $mandatory_failed=0;
my $ungraded=0;
my $review=0;
- @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'});
+ $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]);
+ $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'},
+ [@_]);
+ $result .= &nested_parse(\$dimension{$dim}{'questiontext'},
+ [@_],{'set_dim_id' => undef});
- foreach my $id (@{$dimension{$instance.'.criterias'}},
- @{$dimension{'criterias'}}) {
+ foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}},
+ @{$dimension{$dim}{'criterias'}}) {
my $link=&link($id);
- 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');
+
+ my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
+ if ($type eq 'criteria') {
+ # dimensional 'criteria' don't get assigned grades
+ $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};
+ } else {
+ $result .=
+ &nested_parse(\$dimension{$dim}{'criteria.'.$id},
+ [@_],{'set_dim_id' => $id});
+ }
+ my $status= &get_criteria('status',$version,$dim,$id);
+
+ my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N');
if ($status eq 'pass') {
if (!$mandatory) { $optional_passed++; }
} elsif ($status eq 'fail') {
@@ -2030,7 +2332,7 @@ sub get_instance {
}
}
# FIXME optional required can apply to only right now...
- my $opt_req=$dimension{$instance.'.optionalrequired'};
+ my $opt_req=$dimension{$dim}{$instance.'.optionalrequired'};
if ($opt_req !~ /\S/) {
$opt_req=
&Apache::lonxml::get_param('OptionalRequired',
@@ -2040,7 +2342,7 @@ sub get_instance {
if ($optional_passed < $opt_req) {
$mandatory_failed++;
}
- &Apache::lonxml::debug("all instance ".join(':',@{$dimension{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
+ &Apache::lonxml::debug("all instance ".join(':',@{$dimension{$dim}{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
if ($review) {
$Apache::lonhomework::results{"resource.$version.0.$dim.status"}=
'review';
@@ -2058,6 +2360,44 @@ sub get_instance {
# any other targets no output
undef($result);
}
+ &disable_dimension_parsing();
+ pop(@Apache::bridgetask::dimension);
+ 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{$dim}{'intro'});
+ my @instances = $instance;
+ if (&Apache::response::showallfoils()) {
+ @instances = @{$dimension{$dim}{'instances'}};
+ }
+ foreach my $instance (@instances) {
+ @Apache::scripttag::parser_env = @_;
+ $result.=&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
+ @Apache::scripttag::parser_env = @_;
+ $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'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{$dim}{'intro'});
+ @Apache::scripttag::parser_env = @_;
+ &Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'});
+ @Apache::scripttag::parser_env = @_;
+ &Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'});
+ } else {
+ # any other targets no output
+ undef($result);
+ }
+ pop(@Apache::bridgetask::dimension);
return $result;
}
}
@@ -2097,9 +2437,10 @@ sub grading_history {
sub start_IntroParagraph {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result;
+ my $dim = &get_dim_id();
if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
if ($tagstack->[-2] eq 'Dimension' || $tagstack->[-2] eq 'Question' ) {
- $dimension{'intro'}=
+ $dimension{$dim}{'intro'}=
&Apache::lonxml::get_all_text('/introparagraph',
$parser,$style);
} elsif ($tagstack->[-2] eq 'Task' && $target eq 'webgrade') {
@@ -2119,15 +2460,16 @@ sub end_IntroParagraph {
sub start_Instance {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
- my $id=&get_id($parstack,$safeeval);
- push(@{$dimension{'instances'}},$id);
- push(@Apache::bridgetask::instance,$id);
+ my $dim = &get_dim_id();
+ my $id = &get_id($parstack,$safeeval);
+ push(@{$dimension{$dim}{'instances'}},$id);
+ push(@{$Apache::bridgetask::instance{$dim}},$id);
push(@Apache::bridgetask::instancelist,$id);
- $dimension{$id.'.optionalrequired'}=
+ $dimension{$dim}{$id.'.optionalrequired'}=
&Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
if (lc($disabled) eq 'yes') {
- $dimension{$id.'.disabled'}='1';
+ $dimension{$dim}{$id.'.disabled'}='1';
}
return '';
}
@@ -2137,10 +2479,11 @@ sub end_Instance {
sub start_InstanceText {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
- my $instance_id=$Apache::bridgetask::instance[-1];
+ my $dim = &get_dim_id();
+ my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
my $text=&Apache::lonxml::get_all_text('/instancetext',$parser,$style);
if ($target eq 'grade' || $target eq 'web' || $target eq 'webgrade') {
- $dimension{$instance_id.'.text'}=$text;
+ $dimension{$dim}{$instance_id.'.text'}=$text;
}
return '';
}
@@ -2153,18 +2496,22 @@ sub start_Criteria {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style);
if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') {
+ my $dim = &get_dim_id();
my $id=&get_id($parstack,$safeeval);
+ &Apache::lonxml::debug("Criteria $id with $dim");
if (&Apache::londefdef::is_inside_of($tagstack,'Instance')) {
- my $instance_id=$Apache::bridgetask::instance[-1];
- $dimension{"criteria.$instance_id.$id"}=$criteria;
- $dimension{"criteria.$instance_id.$id.mandatory"}=
+ my $instance_id=$Apache::bridgetask::instance{$dim}[-1];
+ $dimension{$dim}{"criteria.$instance_id.$id"}=$criteria;
+ $dimension{$dim}{"criteria.$instance_id.$id.type"}='criteria';
+ $dimension{$dim}{"criteria.$instance_id.$id.mandatory"}=
&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
- push(@{$dimension{$instance_id.'.criterias'}},"$instance_id.$id");
+ push(@{$dimension{$dim}{$instance_id.'.criterias'}},"$instance_id.$id");
} else {
- $dimension{'criteria.'.$id}=$criteria;
- $dimension{'criteria.'.$id.'.mandatory'}=
+ $dimension{$dim}{'criteria.'.$id}=$criteria;
+ $dimension{$dim}{'criteria.'.$id.'.type'}='criteria';
+ $dimension{$dim}{'criteria.'.$id.'.mandatory'}=
&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval);
- push(@{$dimension{'criterias'}},$id);
+ push(@{$dimension{$dim}{'criterias'}},$id);
}
}
return '';
@@ -2173,9 +2520,31 @@ sub start_Criteria {
sub end_Criteria {
}
+sub start_GraderNote {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+ if ($target eq 'webgrade') {
+ return '
'.
+ &mt('Note to graders:').'';
+ }
+ my $note=&Apache::lonxml::get_all_text('/gradernote',$parser,$style);
+ return;
+}
+
+sub end_GraderNote {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+ if ($target eq 'webgrade') {
+ return '
';
+ }
+ return;
+}
+
+
+
sub proctor_validation_screen {
my ($slot) = @_;
- my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
+ my (undef,undef,$domain,$user) = &Apache::lonnet::whichuser();
my $url=&Apache::lonnet::studentphoto($domain,$user,'jpg');
my $name=&Apache::loncommon::plainname($user,$domain);