--- loncom/homework/structuretags.pm 2018/12/26 19:40:04 1.562 +++ loncom/homework/structuretags.pm 2019/10/31 15:01:22 1.564 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.562 2018/12/26 19:40:04 raeburn Exp $ +# $Id: structuretags.pm,v 1.564 2019/10/31 15:01:22 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -366,12 +366,12 @@ var postsubmit = '$postsubmit'; submithandled = 1; \$( "#msg_"+buttonId ).css({"display": "inline","background-color": "#87cefa", "color": "black","padding": "2px"}) ; - if (( \$(this.form).id == "LC_page" ) && (\$('input[name="all_submit"]').length )) { + if (( \$(this.form).attr("id") == "LC_page" ) && (\$('input[name="all_submit"]').length )) { if (buttonId != "all_submit") { \$( ".LC_status_"+buttonId ).hide(); - if (( "#"+buttonId+"_pressed" ).length) { - \$( "#"+buttonId+"_pressed" ).val( "1" ); - } + } + if (( "#"+buttonId+"_pressed" ).length) { + \$( "#"+buttonId+"_pressed" ).val( "1" ); } } else { \$( ".LC_status_"+buttonId ).hide(); @@ -384,11 +384,9 @@ var postsubmit = '$postsubmit'; if (timeout > 0) { setTimeout(function(){ \$( "#msg_"+buttonId ).css({"display": "none"}); - if (( \$(this.form).id == "LC_page" ) && (\$('input[name="all_submit"]').length )) { - if (buttonId != "all_submit") { - if (( "#"+buttonId+"_pressed" ).length) { - \$( "#"+buttonId+"_pressed" ).val( "" ); - } + if (( \$(this.form).attr("id") == "LC_page" ) && (\$('input[name="all_submit"]').length )) { + if (( "#"+buttonId+"_pressed" ).length) { + \$( "#"+buttonId+"_pressed" ).val( "" ); } } \$( ".LC_hwk_submit" ).prop( "disabled", false); @@ -671,13 +669,23 @@ sub get_resource_name { sub setup_rndseed { my ($safeeval,$target,$probpartlist)=@_; my ($symb)=&Apache::lonnet::whichuser(); - my ($questiontype,$set_safespace,$rndseed); + my ($questiontype,$set_safespace,$rndseed,$numtries,$reqtries); if ($target eq 'analyze') { $questiontype = $env{'form.grade_questiontype'}; } unless (defined($questiontype)) { $questiontype = $Apache::lonhomework::type; } + if ($Apache::lonhomework::type eq 'randomizetry') { + my $partfortries = $Apache::inputtags::part; + if (ref($probpartlist) eq 'ARRAY') { + if ((@{$probpartlist} == 1) && ($probpartlist->[0] ne $Apache::inputtags::part)) { + $partfortries = $probpartlist->[0]; + } + } + $numtries = $Apache::lonhomework::history{"resource.$partfortries.tries"}; + $reqtries = &Apache::lonnet::EXT("resource.$partfortries.randomizeontries"); + } if (($env{'request.state'} eq "construct") || ($symb eq '') || ($Apache::lonhomework::type eq 'practice') @@ -697,9 +705,13 @@ sub setup_rndseed { } if (($env{'request.state'} eq "construct") && ($Apache::lonhomework::type eq 'randomizetry')) { - my $tries = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.tries"}; - if ($tries) { - $rndseed += $tries; + if ($numtries) { + if (($reqtries =~ /^\d+$/) && ($reqtries > 1)) { + my $inc = int($numtries/$reqtries); + $rndseed += $inc; + } else { + $rndseed += $numtries; + } } $env{'form.'.$Apache::inputtags::part.'.rndseed'}=$rndseed; } @@ -737,13 +749,7 @@ sub setup_rndseed { } unless (($target eq 'analyze') && (defined($rndseed))) { $rndseed=&Apache::lonnet::rndseed(); - my $partfortries = $Apache::inputtags::part; - if (ref($probpartlist) eq 'ARRAY') { - if ((@{$probpartlist} == 1) && ($probpartlist->[0] ne $Apache::inputtags::part)) { - $partfortries = $probpartlist->[0]; - } - } - my $curr_try = $Apache::lonhomework::history{"resource.$partfortries.tries"}; + my $curr_try = $numtries; if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { $curr_try ++; } @@ -751,7 +757,6 @@ sub setup_rndseed { $rndseed = $1; } if ($curr_try) { - my $reqtries = &Apache::lonnet::EXT("resource.$partfortries.randomizeontries"); if (($reqtries =~ /^\d+$/) && ($reqtries > 1)) { my $inc = int(($curr_try-1)/$reqtries); $rndseed += $inc; @@ -1932,6 +1937,10 @@ sub start_problem { $result.= ''. &practice_problem_header().'
'; + } elsif ($Apache::lonhomework::type eq 'randomizetry') { + my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries"); + my $problemstatus = &get_problem_status($Apache::inputtags::part); + $result.=&randomizetry_problem_header($problemstatus,$reqtries); } } # if we are viewing someone else preserve that info