--- loncom/homework/bridgetask.pm 2005/11/15 19:50:22 1.77 +++ loncom/homework/bridgetask.pm 2006/01/30 21:01:46 1.99 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: bridgetask.pm,v 1.77 2005/11/15 19:50:22 albertel Exp $ +# $Id: bridgetask.pm,v 1.99 2006/01/30 21:01:46 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -60,7 +60,7 @@ sub initialize_bridgetask { } sub proctor_check_auth { - my ($slot_name,$slot)=@_; + my ($slot_name,$slot,$type)=@_; my $user=$env{'form.proctorname'}; my $domain=$env{'form.proctordomain'}; @@ -79,20 +79,33 @@ sub proctor_check_auth { $authenticated=1; } } - if ($authenticated) { + if ($authenticated && $type eq 'Task') { + # increment version my $version= - $Apache::lonhomework::results{'resource.version'}= - ++$Apache::lonhomework::history{'resource.version'}; - $Apache::lonhomework::results{"resource.$version.checkedin"}= - $user.'@'.$domain; - $Apache::lonhomework::results{"resource.$version.checkedin.slot"}= - $slot_name; + $Apache::lonhomework::history{'resource.0.version'}; + $version++; + + #clean out all current results foreach my $key (keys(%Apache::lonhomework::history)) { if ($key=~/^resource\.0\./) { $Apache::lonhomework::results{$key}=''; } } + + #setup new version and who did it + $Apache::lonhomework::results{'resource.0.version'}=$version; + $Apache::lonhomework::results{"resource.$version.0.checkedin"}= + $user.'@'.$domain; + $Apache::lonhomework::results{"resource.$version.0.checkedin.slot"}= + $slot_name; + return 1; + } elsif ($authenticated && $type eq 'problem') { + &Apache::lonxml::debug("authed $slot_name"); + $Apache::lonhomework::results{"resource.0.checkedin"}= + $user.'@'.$domain; + $Apache::lonhomework::results{"resource.0.checkedin.slot"}= + $slot_name; } } } @@ -103,11 +116,11 @@ sub get_version { my ($version,$previous); if ($env{'form.previousversion'} && $env{'form.previousversion'} ne 'current' && - defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) { + defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.0.status'})) { $version=$env{'form.previousversion'}; $previous=1; } else { - $version=$Apache::lonhomework::history{'resource.version'}; + $version=$Apache::lonhomework::history{'resource.0.version'}; $previous=0; } if (wantarray) { @@ -119,10 +132,10 @@ sub get_version { sub add_previous_version_button { my ($status)=@_; my $result; - if ($Apache::lonhomework::history{'resource.version'} eq '') { + if ($Apache::lonhomework::history{'resource.0.version'} eq '') { return ''; } - if ($Apache::lonhomework::history{'resource.version'} < 2 && + if ($Apache::lonhomework::history{'resource.0.version'} < 2 && $status ne 'NEEDS_CHECKIN') { return ''; } @@ -133,8 +146,8 @@ sub add_previous_version_button { "\n"; } my @to_show; - foreach my $test_version (1..$Apache::lonhomework::history{'resource.version'}) { - if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.status'})) { + foreach my $test_version (1..$Apache::lonhomework::history{'resource.0.version'}) { + if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.0.status'})) { push(@to_show,$test_version); } } @@ -316,7 +329,7 @@ sub internal_location { sub submission_time_stamp { my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser(); my $submissiontime; - my $version=$Apache::lonhomework::history{'resource.version'}; + 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'})) { $submissiontime=$Apache::lonhomework::history{$v.':timestamp'}; @@ -324,7 +337,7 @@ sub submission_time_stamp { } my $result; if ($submissiontime) { - my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.checkedin.slot'}; + my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.0.checkedin.slot'}; my %slot=&Apache::lonnet::get_slot($slot_name); my $diff = $slot{'endtime'} - $submissiontime; my ($color,$when)=('#FF6666','after'); @@ -375,7 +388,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') { @@ -416,16 +429,16 @@ sub start_Task { $target eq 'tex') { my ($version,$previous)=&get_version(); ($status,$accessmsg,my $slot_name,$slot) = - &Apache::lonhomework::check_task_access('0'); + &Apache::lonhomework::check_slot_access('0','Task'); push(@Apache::inputtags::status,$status); $Apache::inputtags::slot_name=$slot_name; my $expression='$external::datestatus="'.$status.'";'; - $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.solved"}.'";'; + $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.0.solved"}.'";'; &Apache::run::run($expression,$safeeval); &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') { @@ -470,9 +483,10 @@ DONESCREEN } } elsif ($target eq 'grade' && !$env{'form.webgrade'}) { if ($status eq 'NEEDS_CHECKIN') { - if(&proctor_check_auth($slot_name,$slot)) { + if(&proctor_check_auth($slot_name,$slot,'Task') + && defined($Apache::inputtags::slot_name)) { my $result=&add_to_queue('gradingqueue', - $Apache::inputtags::slot_name); + [$Apache::inputtags::slot_name]); &Apache::lonxml::debug("add_to_queue said $result"); } } @@ -525,23 +539,29 @@ DONESCREEN } else { if ($target eq 'webgrade') { $result.="\n"; + my $back='

'. + &mt('Return to resource').'

'; if ($status_code eq 'stop') { - $result.=''.&mt("Stopped grading.").''; + $result.=''.&mt("Stopped grading.").''.$back; } elsif ($status_code eq 'lock_failed') { - $result.=''.&mt("Failed to lock the request record.").''; + $result.=''.&mt("Failed to lock the request record.") + .''.$back; } elsif ($status_code eq 'unlock') { - $result.=''.&mt("Unlocked the requested record.").''; + $result.=''.&mt("Unlocked the requested record.") + .''.$back; $result.=&show_queue($env{'form.queue'},1); } elsif ($status_code eq 'show_list') { $result.=&show_queue($env{'form.queue'},1); } elsif ($status_code eq 'select_user') { $result.=&select_user(); + } elsif ($status_code eq 'unable') { + $result.=''.&mt("Unable to aqcuire a user to grade.").''.$back; } else { - $result.=''.&mt("No user to be graded.").''; + $result.=''.&mt("No user to be graded.").''.$back; } } $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') { @@ -672,6 +692,16 @@ sub get_key_todo { return (undef,undef) } +sub minimize_storage { + foreach my $key (keys(%Apache::lonhomework::results)) { + if ($key =~ /regrader$/) { next; } + if ($Apache::lonhomework::results{$key} eq + $Apache::lonhomework::history{$key}) { + delete($Apache::lonhomework::results{$key}); + } + } +} + sub end_Task { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result=''; @@ -695,7 +725,8 @@ sub end_Task {

'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'

'). ""; } - if (!$previous && !$env{'form.donescreen'}) { + if (!$previous && $status ne 'SHOW_ANSWER' && + &show_task($status,$previous)) { $result.=&Apache::inputtags::gradestatus('0'); $result.=''; $result.=<'; + $start_time.''; } if ($bt_status eq 'fail') { $status.='

You did not pass the '.$title.' given on '. - $start_time.'.

'; + $start_time.''; if (!$previous) { $status.=&add_request_another_attempt_button(); } @@ -734,7 +767,7 @@ DONEBUTTON if ($Apache::bridgetask::dimensionmandatory{$dim_id} eq 'N') { $opt_count++; - if ($Apache::lonhomework::history{"resource.$version.$dim_id.status"} eq 'pass') { + if ($Apache::lonhomework::history{"resource.$version.0.$dim_id.status"} eq 'pass') { $opt_passed++; } } else { @@ -744,7 +777,7 @@ DONEBUTTON my $opt_req=&Apache::lonxml::get_param('OptionalRequired', $parstack,$safeeval); if ($opt_req !~ /\S/) { $opt_req='0'; } - $status.="\n

".&mt('You needed to pass all of the [_1] mandatory components and [_2] of the [_3] optional components on the bridge task.',$man_count,$opt_req,$opt_count)."

\n"; + $status.="\n

".&mt('You needed to pass all of the [_1] mandatory components and [_2] of the [_3] optional components, of which you passed [_4].',$man_count,$opt_req,$opt_count,$opt_passed)."

\n"; my $internal_location=&internal_location(); $result=~s/\Q$internal_location\E/$status/; @@ -775,9 +808,12 @@ DONEBUTTON } &Apache::lonhomework::showhash(%Apache::lonhomework::results); &Apache::structuretags::finalize_storage(); - if ($award eq 'SUBMITTED') { - &add_to_queue('gradingqueue',$Apache::inputtags::slot_name); + if ($award eq 'SUBMITTED' + && defined($Apache::inputtags::slot_name)) { + &add_to_queue('gradingqueue',[$Apache::inputtags::slot_name]); } + } elsif ($Apache::lonhomework::results{'INTERNAL_store'}) { + &Apache::structuretags::finalize_storage(); } if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') { my $optional_required= @@ -790,7 +826,7 @@ DONEBUTTON &Apache::lonhomework::showhash(%Apache::lonhomework::results); foreach my $dim_id (@Apache::bridgetask::dimensionlist) { my $status= - $Apache::lonhomework::results{"resource.$version.$dim_id.status"}; + $Apache::lonhomework::results{"resource.$version.0.$dim_id.status"}; my $mandatory= ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N'); if ($status eq 'pass') { @@ -809,10 +845,10 @@ DONEBUTTON $mandatory_failed++; } &Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review"); - $Apache::lonhomework::results{'resource.grader'}= + $Apache::lonhomework::results{'resource.0.regrader'}= $env{'user.name'}.'@'.$env{'user.domain'}; if ($review) { - $Apache::lonhomework::results{"resource.$version.status"}='review'; + $Apache::lonhomework::results{"resource.$version.0.status"}='review'; if ($env{'form.queue'} eq 'reviewqueue') { &check_queue_unlock($env{'form.queue'}); &Apache::lonxml::debug(" still needs review not changing status."); @@ -820,7 +856,7 @@ DONEBUTTON &move_between_queues($env{'form.queue'},'reviewqueue'); } } elsif ($ungraded) { - $Apache::lonhomework::results{"resource.$version.status"}='ungraded'; + $Apache::lonhomework::results{"resource.$version.0.status"}='ungraded'; if ($env{'form.queue'} eq 'reviewqueue' || $env{'form.queue'} eq 'none' ) { &Apache::lonxml::debug("moving back."); @@ -829,7 +865,7 @@ DONEBUTTON &check_queue_unlock($env{'form.queue'}); } } elsif ($mandatory_failed) { - $Apache::lonhomework::results{"resource.$version.status"}='fail'; + $Apache::lonhomework::results{"resource.$version.0.status"}='fail'; $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override'; $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT'; $Apache::lonhomework::results{"resource.$version.0.awarded"}='0'; @@ -847,7 +883,7 @@ DONEBUTTON ["$version.0.bridgetask"]); } } else { - $Apache::lonhomework::results{"resource.$version.status"}='pass'; + $Apache::lonhomework::results{"resource.$version.0.status"}='pass'; $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override'; $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS'; $Apache::lonhomework::results{"resource.$version.0.awarded"}='1'; @@ -864,8 +900,8 @@ DONEBUTTON ["$version.0.bridgetask"]); } } - $Apache::lonhomework::results{"resource.status"}= - $Apache::lonhomework::results{"resource.$version.status"}; + $Apache::lonhomework::results{"resource.0.status"}= + $Apache::lonhomework::results{"resource.$version.0.status"}; if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) { $Apache::lonhomework::results{"resource.0.award"}= $Apache::lonhomework::results{"resource.$version.0.award"}; @@ -874,6 +910,7 @@ DONEBUTTON $Apache::lonhomework::results{"resource.0.solved"}= $Apache::lonhomework::results{"resource.$version.0.solved"}; } + &minimize_storage(); &Apache::structuretags::finalize_storage(); } } elsif ($target eq 'webgrade') { @@ -911,7 +948,7 @@ sub move_between_queues { } else { $cur_data = ['none']; } - my $result=&add_to_queue($dest_queue,$cur_data->[0]); + my $result=&add_to_queue($dest_queue,[$cur_data->[0]]); if ($result ne 'ok') { return $result; } @@ -939,13 +976,38 @@ sub check_queue_unlock { return 'not_owner'; } +sub in_queue { + my ($queue,$symb,$cdom,$cnum,$udom,$uname)=@_; + if ($queue eq 'none') { return 0; } + 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 %results = &Apache::lonnet::get($queue,[$key],$cdom,$cnum); + + if (defined($results{$key})) { + return 1; + } + return 0; +} + 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'}; + } + if (!&in_queue($queue,$symb,$cdom,$cnum,$udom,$uname)) { + return 'ok'; + } + my $key=&encode_queue_key($symb,$udom,$uname); my @keys=($key,"$key\0locked"); return &Apache::lonnet::del($queue,\@keys,$cdom,$cnum); } @@ -974,10 +1036,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); @@ -985,10 +1047,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'; } @@ -996,14 +1065,17 @@ sub check_queue_for_key { } sub add_to_queue { - my ($queue,$slot_name)=@_; + my ($queue,$user_data)=@_; if ($queue eq 'none') { return 'ok'; } my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser(); + if (!$cid || $env{'request.state'} eq 'construct') { + return 'no_queue'; + } my $cnum=$env{'course.'.$cid.'.num'}; my $cdom=$env{'course.'.$cid.'.domain'}; my %data; - $data{"$symb\0queue\0$uname\@$udom"}=[$slot_name]; - return &Apache::lonnet::newput($queue,\%data,$cdom,$cnum); + $data{"$symb\0queue\0$uname\@$udom"}=$user_data; + return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum); } sub show_queue { @@ -1029,7 +1101,7 @@ sub show_queue { if ($tmp=~/^error: 2 /) { return "\n

Current Queue - $queue

Empty
"; } - $result.="\n

Current Queue - $queue

"; + $result.="\n

Current Queue - $symb $queue

"; if ($with_selects) { $result.=""; } $result.=""; foreach my $key (sort(keys(%queue))) { @@ -1108,6 +1180,7 @@ sub get_queue_counts { return (0,0,0); } my ($entries,$ready_to_grade,$locks)=(0,0,0); + my %slot_cache; foreach my $key (sort(keys(%queue))) { if ($key=~/locked$/) { $locks++; @@ -1117,8 +1190,11 @@ sub get_queue_counts { my ($symb,$uname,$udom) = &decode_queue_key($key); $entries++; my $slot=$queue{$key}->[0]; - my %slot_data=&Apache::lonnet::get_slot($slot); - if (time > $slot_data{'endtime'}) { + if (!exists($slot_cache{$slot})) { + my %slot_data=&Apache::lonnet::get_slot($slot); + $slot_cache{$slot} = \%slot_data; + } + if (time > $slot_cache{$slot}{'endtime'}) { $ready_to_grade++; } } @@ -1155,6 +1231,7 @@ sub queue_key_locked { sub pick_from_queue_data { my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_; + my @possible; # will hold queue entries that are valid to be selected foreach my $key (keys(%$queuedata)) { if ($key =~ /\0locked$/) { next; } if ($key =~ /\0timestamp$/) { next; } @@ -1172,11 +1249,18 @@ sub pick_from_queue_data { &Apache::lonxml::debug("not time"); next; } - if (&queue_key_locked($queue,$key,$cdom,$cnum)) { + if (exists($queuedata->{"$key\0locked"})) { &Apache::lonxml::debug("someone already has um."); next; } - return $key; + push(@possible,[$key,$slot_data{'endtime'}]); + } + if (@possible) { + # sort entries in order by slot end time + @possible = sort { $a->[1] <=> $b->[1] } @possible; + # pick one of the first ten entries + my $max=($#possible < 10) ? $#possible : 10; + return $possible[int(rand($max))][0]; } return undef; } @@ -1217,6 +1301,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; @@ -1226,12 +1331,19 @@ sub get_from_queue { my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum); &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo))); if ($todo) { return $todo; } + my $attempts=0; while (1) { + if ($attempts > 2) { + # tried twice to get a queue entry, giving up + return (undef,'unable'); + } 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 $range= ($attempts < 1 ) ? '0-100' : '0-400'; + my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp); #make a pass looking for a user _not_ in my section if ($env{'request.course.sec'}) { @@ -1244,8 +1356,7 @@ sub get_from_queue { # ready for grading if (!$todo) { &Apache::lonxml::debug("no sce"); - $todo=&pick_from_queue_data($queue,$env{'request.course.sec'}, - \%queue,$cdom,$cnum); + $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum); &Apache::lonxml::debug("no sce $todo"); } # no user to grade @@ -1253,7 +1364,10 @@ sub get_from_queue { &Apache::lonxml::debug("got $todo"); # otherwise found someone so lets try to lock them # unless someone else already picked them - if (!&lock_key($queue,$todo)) { next; } + if (!&lock_key($queue,$todo)) { + $attempts++; + next; + } my (undef,$endtime)= &Apache::lonnet::get($queue,["$symb\0timestamp"], $cdom,$cnum); @@ -1272,6 +1386,7 @@ sub get_from_queue { &Apache::lonnet::del($queue,["$todo\0locked"], $cdom,$cnum); &Apache::lonxml::debug("del"); + $attempts++; next; } } @@ -1300,7 +1415,10 @@ 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, + 'Task'); my $queue = 'none'; my $cannot_grade; if ($status{'reviewqueue'} =~ /^(in_progress|enqueue)$/) { @@ -1379,17 +1497,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.0.status'}; + $status{'version'}=$record{'resource.0.version'}; + $status{'grader'}=$record{'resource.0.regrader'}; + } + $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; } @@ -1465,6 +1589,7 @@ sub get_instance { $instance = $instances[($version-1)%scalar(@instances)]; $Apache::lonhomework::results{"resource.$version.0.$dim.instance"} = $instance; + $Apache::lonhomework::results{'INTERNAL_store'} = 1; &Apache::response::poprandomnumber(); return $instance; } @@ -1488,10 +1613,10 @@ sub get_instance { foreach my $instance (@instances) { @Apache::scripttag::parser_env = @_; $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'}); - if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' || - $Apache::lonhomework::history{"resource.$version.status"} eq 'fail') { + if ($Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass' || + $Apache::lonhomework::history{"resource.$version.0.status"} eq 'fail') { - my $dim_status=$Apache::lonhomework::history{"resource.$version.$dim.status"}; + my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"}; my $mandatory='Mandatory'; if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') { $mandatory='Optional'; @@ -1511,12 +1636,12 @@ sub get_instance { if ($dimension{$instance.'.criteria.'.$id.'.mandatory'} eq 'N') { $opt_count++; - if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"} eq 'pass') { + if ($Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.status"} eq 'pass') { $opt_passed++; } } else { $man_count++; - if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"} eq 'pass') { + if ($Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.status"} eq 'pass') { $man_passed++; } } @@ -1530,8 +1655,8 @@ sub get_instance { $result=~s/\Q$internal_location\E/$dim_info/; foreach my $id (@{$dimension{$instance.'.criterias'}}) { - my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"}; - my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}; + my $status=$Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.status"}; + my $comment=$Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.comment"}; my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N'); if ($mandatory) { $mandatory='Mandatory'; @@ -1551,8 +1676,8 @@ sub get_instance { @Apache::scripttag::parser_env = @_; $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id}); $result.='

'.$status_display.'

'; - if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) { - $result.='

'.$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'

'; + if ($Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.comment"}) { + $result.='

'.$Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.comment"}.'

'; } $result.=''; } @@ -1566,7 +1691,7 @@ sub get_instance { &Apache::scripttag::xmlparse($dimension{$instance.'.text'}); foreach my $id (@{$dimension{$instance.'.criterias'}}) { my $link='criteria_'.$instance.'_'.$id; - my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"}; + my $status=$Apache::lonhomework::history{"resource.$version.0.$dim.$instance.$id.status"}; $result.=''. ''. '
resourceusertypedata
'. ''. ''. @@ -1577,7 +1702,7 @@ sub get_instance { #$dimension{$instance.'.criteria.'.$id}. 'Additional Comment for Student
'. - ''. + ''. '
'. '
'. @@ -1597,8 +1722,8 @@ sub get_instance { my $ungraded=0; my $review=0; foreach my $id (@{$dimension{$instance.'.criterias'}}) { - my $status=$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id}; - $Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id}; + my $status=$Apache::lonhomework::results{"resource.$version.0.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id}; + $Apache::lonhomework::results{"resource.$version.0.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id}; my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N'); if ($status eq 'pass') { if (!$mandatory) { $optional_passed++; } @@ -1617,16 +1742,16 @@ sub get_instance { } &Apache::lonxml::debug("all instance ".join(':',@{$dimension{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review"); if ($review) { - $Apache::lonhomework::results{"resource.$version.$dim.status"}= + $Apache::lonhomework::results{"resource.$version.0.$dim.status"}= 'review'; } elsif ($ungraded) { - $Apache::lonhomework::results{"resource.$version.$dim.status"}= + $Apache::lonhomework::results{"resource.$version.0.$dim.status"}= 'ungraded'; } elsif ($mandatory_failed) { - $Apache::lonhomework::results{"resource.$version.$dim.status"}= + $Apache::lonhomework::results{"resource.$version.0.$dim.status"}= 'fail'; } else { - $Apache::lonhomework::results{"resource.$version.$dim.status"}= + $Apache::lonhomework::results{"resource.$version.0.$dim.status"}= 'pass'; } } else { @@ -1638,14 +1763,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); } } @@ -1674,9 +1799,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; } @@ -1688,9 +1813,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;