--- loncom/homework/structuretags.pm 2020/01/15 13:57:36 1.512.2.23.2.1 +++ loncom/homework/structuretags.pm 2015/09/14 13:45:19 1.539 @@ -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.23.2.1 2020/01/15 13:57:36 raeburn Exp $ +# $Id: structuretags.pm,v 1.539 2015/09/14 13:45:19 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -270,7 +270,7 @@ sub homework_js { $jstimeout = 1000 * $timeout; } return &Apache::loncommon::resize_textarea_js(). - &Apache::loncommon::colorfuleditor_js(). + &Apache::loncommon::colorfuleditor_js(). &setmode_javascript(). <<"JS"; @@ -417,13 +417,9 @@ sub page_start { $extra_head .= &homework_js(). &Apache::lonhtmlcommon::dragmath_js("EditMathPopup"); if (&Apache::lonhtmlcommon::htmlareabrowser()) { - my %textarea_args; - if (($env{'request.state'} ne 'construct') || - ($env{'environment.nocodemirror'})) { - %textarea_args = ( + my %textarea_args = ( dragmath => 'math', ); - } $extra_head .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args); } my $is_task = ($env{'request.uri'} =~ /\.task$/); @@ -494,9 +490,9 @@ sub page_start { } } if ($needs_upload) { - $extra_head .= &Apache::lonhtmlcommon::file_submissionchk_js(). - ''; + $extra_head .= &Apache::lonhtmlcommon::file_submissionchk_js() + .''; } } @@ -643,43 +639,17 @@ sub get_resource_name { sub setup_rndseed { my ($safeeval,$target,$probpartlist)=@_; my ($symb)=&Apache::lonnet::whichuser(); - my ($questiontype,$set_safespace,$rndseed,$numtries,$reqtries); + my ($questiontype,$set_safespace,$rndseed); 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; -# -# Where question type is "randomizetry" for a problem containing -# a single part (and unless type is explicitly set to not be -# "randomizetry" for that part), the number of tries used to -# determine randomization will be for that part, and randomization -# from calls to &random() in a perl script block before the part tag, -# will change based on the number of tries, and value of the -# "randomizeontries" parameter in effect for the single part. -# - if (ref($probpartlist) eq 'ARRAY') { - if ((@{$probpartlist} == 1) && ($probpartlist->[0] ne $partfortries)) { - if (&Apache::lonnet::EXT('resource.'.$probpartlist->[0].'.type') eq 'randomizetry') { - $partfortries = $probpartlist->[0]; - } else { - $partfortries = ''; - } - } - } - 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 '') - || ($Apache::lonhomework::type eq 'practice') - || ($Apache::lonhomework::history{'resource.CODE'}) - || (($env{'form.code_for_randomlist'}) && ($target eq 'analyze'))) { + if ($env{'request.state'} eq "construct" + || $symb eq '' + || $Apache::lonhomework::type eq 'practice' + || $Apache::lonhomework::history{'resource.CODE'}) { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['rndseed']); $rndseed=$env{'form.rndseed'}; @@ -688,19 +658,13 @@ sub setup_rndseed { if (!$rndseed) { $rndseed=time; } - unless ($env{'form.code_for_randomlist'}) { - $env{'form.rndseed'}=$rndseed; - } + $env{'form.rndseed'}=$rndseed; } - if ((($env{'request.state'} eq "construct") || ($symb eq '')) && + if (($env{'request.state'} eq "construct") && ($Apache::lonhomework::type eq 'randomizetry')) { - if ($numtries) { - if (($reqtries =~ /^\d+$/) && ($reqtries > 1)) { - my $inc = int($numtries/$reqtries); - $rndseed += $inc; - } else { - $rndseed += $numtries; - } + my $tries = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.tries"}; + if ($tries) { + $rndseed += $tries; } $env{'form.'.$Apache::inputtags::part.'.rndseed'}=$rndseed; } @@ -722,11 +686,7 @@ sub setup_rndseed { $rndseed=join(':',&Apache::lonnet::digest($rndseed)); } } - if (($env{'form.code_for_randomlist'}) && ($target eq 'analyze')) { - $env{'form.CODE'} = $env{'form.code_for_randomlist'}; - $rndseed=&Apache::lonnet::rndseed(); - undef($env{'form.CODE'}); - } elsif ($Apache::lonhomework::history{'resource.CODE'}) { + if ($Apache::lonhomework::history{'resource.CODE'}) { $rndseed=&Apache::lonnet::rndseed(); } $set_safespace = 1; @@ -738,7 +698,13 @@ sub setup_rndseed { } unless (($target eq 'analyze') && (defined($rndseed))) { $rndseed=&Apache::lonnet::rndseed(); - my $curr_try = $numtries; + 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"}; if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { $curr_try ++; } @@ -746,6 +712,7 @@ 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; @@ -803,9 +770,7 @@ sub problem_edit_buttons { if ($mode eq 'editxml') { $result.=&problem_edit_action_button('subedit','edit','e','Edit',1); $result.=&problem_edit_action_button('subundo','undoxml','u','Undo',1); - if ($env{'environment.nocodemirror'}) { - $result.=&Apache::lonhtmlcommon::dragmath_button("LC_editxmltext",1); - } + $result.=&Apache::lonhtmlcommon::dragmath_button("LC_editxmltext",1); } else { $result.=&problem_edit_action_button('subeditxml','editxml','x','EditXML',1); $result.=&problem_edit_action_button('subundo','undo','u','Undo',1); @@ -821,9 +786,9 @@ sub problem_edit_header {
'.&mt('Problem Editing').$mode.&Apache::loncommon::help_open_menu('Problem Editing','Problem_Editor_XML_Index',5,'Authoring').' -
'. - ''. - &problem_edit_buttons(); +
'. + ''. + &problem_edit_buttons(); $return .= '
' . &Apache::lonxml::message_location(); $return .= ' @@ -851,7 +816,6 @@ sub problem_edit_header { return $return; } - sub problem_edit_footer { my $resource = $env{'request.ambiguous'}; return '
@@ -927,7 +891,7 @@ sub problem_web_to_edit_header { ".&mt("Problem Type:")." '. + $rndseed.'" />'. ''; if (exists($env{'form.username'})) { @@ -1644,19 +1591,12 @@ sub start_problem { $form_tag_start.=&practice_problem_header(); } $form_tag_start.='
'; - } - 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); - } + } 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); } my $expression='$external::datestatus="'.$status.'";'; @@ -1693,10 +1633,6 @@ sub start_problem { } elsif ($status eq 'UNCHECKEDOUT') { $msg.=&checkout_msg(); } elsif ($status eq 'NOT_YET_VIEWED') { - if ($firstaccres) { - $msg .= '

'. - &mt('A problem occurred when trying to start the timer.').'

'; - } $msg.=&firstaccess_msg($accessmsg,$symb); } elsif ($status eq 'NOT_IN_A_SLOT') { $msg.=&Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work"); @@ -1772,10 +1708,6 @@ 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 @@ -1977,24 +1909,7 @@ sub end_problem { } } if ($target eq 'web') { - $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 - } - } - } + $result.=&Apache::functionplotresponse::init_script(); } if ($target eq 'grade') { &Apache::lonhomework::showhash(%Apache::lonhomework::results); @@ -2088,8 +2003,6 @@ sub end_library { && ($#$tagstack eq 0 && $$tagstack[0] eq 'library') && $env{'request.state'} eq "construct") { $result.=''.&Apache::loncommon::end_page({'discussion' => 1}); - } elsif ($target eq 'meta') { - $result.=&Apache::response::meta_response_order(); } if ( $#$tagstack eq 0 && $$tagstack[0] eq 'library') { &reset_problem_globals('library'); @@ -2572,12 +2485,7 @@ sub start_randomlist { } if (@randomlist) { my @idx_arr = (0 .. $#randomlist); - if ($env{'form.code_for_randomlist'}) { - &Apache::structuretags::shuffle(\@idx_arr,$target); - undef($env{'form.code_for_randomlist'}); - } else { - &Apache::structuretags::shuffle(\@idx_arr); - } + &Apache::structuretags::shuffle(\@idx_arr); my $bodytext = ''; my $show=$#randomlist; my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval); @@ -2616,10 +2524,10 @@ sub start_randomlist { } sub shuffle { - my ($a,$target) = @_; + my $a=shift; my $i; if (ref($a) eq 'ARRAY' && @$a) { - &Apache::response::pushrandomnumber(undef,$target); + &Apache::response::pushrandomnumber(); for($i=@$a;--$i;) { my $j=int(&Math::Random::random_uniform() * ($i+1)); next if $i == $j; @@ -2793,14 +2701,20 @@ 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 ((($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"); + 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"); $result .= &randomizetry_part_header($problemstatus,$reqtries,$num); } } @@ -2971,7 +2885,7 @@ sub start_problemtype { ['hide','Hide']] ,$token); $result .=&Apache::edit::checked_arg('When used as type(s):','for', - [ ['exam','Exam/Quiz Problem'], + [ ['exam','Bubblesheet Exam/Quiz Problem'], ['survey','Survey'], ['surveycred','Survey (with credit)'], ['anonsurvey','Anonymous Survey'], @@ -3019,13 +2933,9 @@ sub end_startouttext { .''.&mt('Delete?').' ' .&Apache::edit::deletelist($target,$token) .'' - .''; - if ($env{'environment.nocodemirror'}) { - $result.=&Apache::lonhtmlcommon::dragmath_button($areaid,1); - } else { - $result.=' '; - } - $result.='' + .'' + .&Apache::lonhtmlcommon::dragmath_button($areaid,1) + .'' .'' .&Apache::edit::insertlist($target,$token) .'' @@ -3120,7 +3030,7 @@ sub practice_problem_header { } sub randomizetry_problem_header { - my ($problemstatus,$reqtries,$symb) = @_; + my ($problemstatus,$reqtries) = @_; my ($header,$text); if ($reqtries > 1) { $header = &mt('New Problem Variation After Every [quant,_1,Try,Tries]',$reqtries); @@ -3140,13 +3050,8 @@ sub randomizetry_problem_header { $text = &mt('A new variation will be generated after each try until correct or tries limit is reached.'); } } - if (($env{'request.state'} eq "construct") || ($symb eq '')) { - return ''; - } else { - return '

'.$header.'

'. - ''.$text.'
'; - } + return '

'.$header.'

'. + ''.$text.'
'; } sub randomizetry_part_header { @@ -3154,7 +3059,7 @@ sub randomizetry_part_header { my ($header,$text); if ($reqtries eq 'none') { $header = &mt('No Question Variation'); - $text = &mt('For this question there will be no new variation after a try.'); + $text = &mt('For this question there will no new variation after a try.'); } elsif ($reqtries > 1) { $header = &mt('New Question Variation After Every [quant,_1,Try,Tries]',$reqtries); if (($problemstatus eq 'no') ||