--- loncom/homework/structuretags.pm 2019/10/31 16:14:09 1.512.2.19
+++ loncom/homework/structuretags.pm 2019/11/04 20:50:57 1.512.2.21
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.512.2.19 2019/10/31 16:14:09 raeburn Exp $
+# $Id: structuretags.pm,v 1.512.2.21 2019/11/04 20:50:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -655,10 +655,17 @@ sub setup_rndseed {
if (ref($probpartlist) eq 'ARRAY') {
if ((@{$probpartlist} == 1) && ($probpartlist->[0] ne $Apache::inputtags::part)) {
$partfortries = $probpartlist->[0];
+ if (&Apache::lonnet::EXT("resource.$partfortries.questiontype") eq 'randomizetry') {
+ $partfortries = $probpartlist->[0];
+ } else {
+ $partfortries = '';
+ }
}
}
- $numtries = $Apache::lonhomework::history{"resource.$partfortries.tries"};
- $reqtries = &Apache::lonnet::EXT("resource.$partfortries.randomizeontries");
+ if ($partfortries ne '') {
+ $numtries = $Apache::lonhomework::history{"resource.$partfortries.tries"};
+ $reqtries = &Apache::lonnet::EXT("resource.$partfortries.randomizeontries");
+ }
}
if (($env{'request.state'} eq "construct")
|| ($symb eq '')
@@ -677,7 +684,7 @@ sub setup_rndseed {
$env{'form.rndseed'}=$rndseed;
}
}
- if (($env{'request.state'} eq "construct") &&
+ if ((($env{'request.state'} eq "construct") || ($symb eq '')) &&
($Apache::lonhomework::type eq 'randomizetry')) {
if ($numtries) {
if (($reqtries =~ /^\d+$/) && ($reqtries > 1)) {
@@ -1417,6 +1424,7 @@ sub init_problem_globals {
@Apache::structuretags::whilebody=();
@Apache::structuretags::whileline=();
$Apache::lonhomework::scantronmode=0;
+ $Apache::lonhomework::randomizetrypart=0;
undef($Apache::lonhomework::name);
undef($Apache::lonhomework::default_type);
undef($Apache::lonhomework::type);
@@ -1440,6 +1448,7 @@ sub reset_problem_globals {
undef($Apache::lonhomework::default_type);
undef($Apache::lonhomework::type);
undef($Apache::lonhomework::scantronmode);
+ undef($Apache::inputtags::randomizetrypart);
undef($Apache::lonhomework::ignore_response_errors);
undef(@Apache::functionplotresponse::callscripts);
&Apache::lonhomework::reset_show_problem_status();
@@ -1591,8 +1600,12 @@ sub start_problem {
if ($env{'request.state'} ne "construct" &&
($symb eq '' || $Apache::lonhomework::type eq 'practice')) {
+ my $rndseedval = $rndseed;
+ if (($symb eq '') && ($Apache::lonhomework::type eq 'randomizetry')) {
+ $rndseedval = $env{'form.rndseed'};
+ }
$form_tag_start.=''.
+ $rndseedval.'" />'.
'';
if (exists($env{'form.username'})) {
@@ -1614,12 +1627,19 @@ sub start_problem {
$form_tag_start.=&practice_problem_header();
}
$form_tag_start.='
';
- } elsif (($env{'request.state'} ne "construct") &&
- ($Apache::lonhomework::type eq 'randomizetry') &&
- ($status eq 'CAN_ANSWER')) {
- my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
- my $problemstatus = &get_problem_status($Apache::inputtags::part);
- $form_tag_start.=&randomizetry_problem_header($problemstatus,$reqtries);
+ }
+ if (($env{'request.state'} ne "construct") &&
+ ($Apache::lonhomework::type eq 'randomizetry') &&
+ ($status eq 'CAN_ANSWER')) {
+ my @parts;
+ if (ref($probpartlist) eq 'ARRAY') {
+ @parts = @{$probpartlist};
+ }
+ unless (@parts) {
+ my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
+ my $problemstatus = &get_problem_status($Apache::inputtags::part);
+ $form_tag_start.=&randomizetry_problem_header($problemstatus,$reqtries,$symb);
+ }
}
my $expression='$external::datestatus="'.$status.'";';
@@ -1940,7 +1960,24 @@ sub end_problem {
}
}
if ($target eq 'web') {
- $result.=&Apache::functionplotresponse::init_script();
+ $result.=&Apache::functionplotresponse::init_script();
+ if ($Apache::lonhomework::default_type eq 'randomizetry') {
+ my ($symb) = &Apache::lonnet::whichuser();
+ if ((($env{'request.state'} eq 'construct') || ($symb eq '')) &&
+ ($status eq 'CAN_ANSWER')) {
+ unless (@Apache::inputtags::partlist > 1) {
+ $result.= <<"ENDJS";
+
+ENDJS
+ }
+ }
+ }
}
if ($target eq 'grade') {
&Apache::lonhomework::showhash(%Apache::lonhomework::results);
@@ -2739,20 +2776,14 @@ sub start_part {
} elsif ($target eq 'web') {
if ($status eq 'CAN_ANSWER') {
my $problemstatus = &get_problem_status($Apache::inputtags::part);
- my $probrandomize = &Apache::lonnet::EXT("resource.$Apache::inputtags::partlist[0].type");
- my $probrandtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::partlist[0].randomizeontries");
my $num = scalar(@Apache::inputtags::partlist)-1;
- if ($probrandomize eq 'randomizetry') {
- if (&Apache::lonnet::EXT("resource.$Apache::inputtags::part.type") ne 'randomizetry') {
- $result .= &randomizetry_part_header($problemstatus,'none',$num);
- } else {
- my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
- if ($probrandtries ne $reqtries) {
- $result .= &randomizetry_part_header($problemstatus,$reqtries,$num);
- }
- }
- } elsif (&Apache::lonnet::EXT("resource.$Apache::inputtags::part.type") eq 'randomizetry') {
- my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
+ if ((($Apache::lonhomework::default_type eq 'randomizetry') ||
+ ($Apache::lonhomework::randomizetrypart)) &&
+ ($Apache::lonhomework::type ne 'randomizetry')) {
+ $result .= &randomizetry_part_header($problemstatus,'none',$num);
+ } elsif ($Apache::lonhomework::type eq 'randomizetry') {
+ $Apache::lonhomework::randomizetrypart = 1;
+ my $reqtries = &Apache::lonnet::EXT("resource.$id.randomizeontries");
$result .= &randomizetry_part_header($problemstatus,$reqtries,$num);
}
}
@@ -3072,7 +3103,7 @@ sub practice_problem_header {
}
sub randomizetry_problem_header {
- my ($problemstatus,$reqtries) = @_;
+ my ($problemstatus,$reqtries,$symb) = @_;
my ($header,$text);
if ($reqtries > 1) {
$header = &mt('New Problem Variation After Every [quant,_1,Try,Tries]',$reqtries);
@@ -3092,8 +3123,13 @@ sub randomizetry_problem_header {
$text = &mt('A new variation will be generated after each try until correct or tries limit is reached.');
}
}
- return ''.$header.'
'.
- ''.$text.'
';
+ if (($env{'request.state'} eq "construct") || ($symb eq '')) {
+ return ''.
+ '
'.$header.'
'.$text.'
';
+ } else {
+ return ''.$header.'
'.
+ ''.$text.'
';
+ }
}
sub randomizetry_part_header {