--- loncom/homework/structuretags.pm 2009/06/17 15:27:20 1.452 +++ loncom/homework/structuretags.pm 2011/01/07 05:14:57 1.465.2.12 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.452 2009/06/17 15:27:20 bisitz Exp $ +# $Id: structuretags.pm,v 1.465.2.12 2011/01/07 05:14:57 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -66,7 +66,7 @@ use lib '/home/httpd/lib/perl/'; use LONCAPA; BEGIN { - &Apache::lonxml::register('Apache::structuretags',('block','languageblock','translated','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startouttext','endouttext','simpleeditbutton','definetag')); + &Apache::lonxml::register('Apache::structuretags',('block','languageblock','translated','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startpartmarker','startouttext','endpartmarker','endouttext','simpleeditbutton','definetag')); } sub start_web { @@ -128,6 +128,7 @@ sub homework_js { &setmode_javascript(). <<'JS'; JS } @@ -161,6 +162,49 @@ function setmode(form,probmode) { ENDSCRIPT } +sub file_delchk_js { + my $delfilewarn = &mt('You have indicated you wish to remove some files previously included in your submission.').'\\n'. + &mt('Continue submission with these files removed?'); + return <<"ENDSCRIPT"; + +ENDSCRIPT +} + sub page_start { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name, $extra_head)=@_; @@ -177,12 +221,17 @@ sub page_start { $parstack,$parser,$safeeval); } - $extra_head .= &homework_js(); - - if ($env{'environment.wysiwygeditor'} eq 'on') { - $extra_head .= &Apache::lonhtmlcommon::dragmath_js("FCKEditMathPopup"); - } else { - $extra_head .= &Apache::lonhtmlcommon::dragmath_js("EditMathPopup"); + $extra_head .= &homework_js(). + &Apache::lonhtmlcommon::dragmath_js("EditMathPopup"); + if (&Apache::lonhtmlcommon::htmlareabrowser()) { + my %textarea_args = ( + dragmath => 'math', + ); + $extra_head .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args); + } + my $is_task = ($env{'request.uri'} =~ /\.task$/); + if ($is_task) { + $extra_head .= &file_delchk_js(); } my %body_args; @@ -218,13 +267,15 @@ sub page_start { 'text' => 'Construction Space', 'href' => &Apache::loncommon::authorspace(), }); + # breadcrumbs (and tools) will be created + # in start_page->bodytag->innerregister + # FIXME Where are we? # &Apache::lonhtmlcommon::add_breadcrumb({ # 'text' => 'Problem Editing', # 'Problem Testing' # 'href' => '', # }); - $pageheader = &Apache::lonhtmlcommon::breadcrumbs() - .&Apache::loncommon::head_subbox( + $pageheader =&Apache::loncommon::head_subbox( &Apache::loncommon::CSTR_pageheader()); } } elsif (!defined($found{'body'})) { @@ -257,11 +308,11 @@ sub page_start { && ($target eq 'web' || $target eq 'webgrade')) { my ($symb,undef,undef,undef,$publicuser)= &Apache::lonnet::whichuser(); - if ($symb eq '' && !$publicuser) { - my $help = &Apache::loncommon::help_open_topic("Ambiguous_Reference"); - $help=&mt("Browsing resource, all submissions are temporary.")."
"; - $page_start .= $help; - } + if ($symb eq '' && !$publicuser) { + $page_start .= '

' + .&mt('Browsing resource, all submissions are temporary.') + .'

'; + } } if (!defined($found{'body'}) && $env{'request.state'} ne 'construct') { @@ -271,11 +322,16 @@ sub page_start { my $form_tag_start; if (!defined($found{'form'})) { $form_tag_start='
1)) { + my $inc = int(($curr_try-1)/$reqtries); + $rndseed += $inc; + } else { + $rndseed += $curr_try; + } + } + } + $set_safespace = 1; + } + if ($set_safespace) { + if ($safeeval) { + &Apache::lonxml::debug("Setting rndseed to $rndseed"); + &Apache::run::run('$external::randomseed="'.$rndseed.'";',$safeeval); + } + } + unless (($env{'request.state'} eq "construct") || ($symb eq '')) { + $env{'form.'.$Apache::inputtags::part.'.rndseed'}=$rndseed; } return $rndseed; } @@ -386,23 +488,21 @@ sub problem_edit_header { '.&mt('Problem Editing').&Apache::loncommon::help_open_menu('Problem Editing','Problem_Editor_XML_Index',5,'Authoring').' '. &problem_edit_buttons().' -
+
'.&Apache::lonxml::message_location().' '. - ''; + $result.=&Apache::edit::end_table(); + + } + return $result; +} + +sub end_startpartmarker { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my @result; + if ($target eq 'edit') { $result[1]='no'; } + return @result; +} + +sub start_endpartmarker { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my $result=''; + if ($target eq 'edit') { + $result=&Apache::edit::tag_start($target,$token); + $result.=&mt('Marker for the end of a part. Place start marker above to wrap in-between tags into a new part.').''; + $result.=&Apache::edit::end_table(); + + } + return $result; +} + +sub end_endpartmarker { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my @result; + if ($target eq 'edit') { $result[1]='no'; } + return @result; +} + sub start_part { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; if (!$Apache::lonxml::metamode) { @@ -1771,9 +1967,31 @@ sub start_part { '.disableexampointprint'}) eq 'yes') { $allow_print_points=0; } - if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) { $result .= '\fbox{\textit{'.$weight.' pt}}';} + if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) { + $result .= '\vskip 10mm\fbox{\textit{'.$weight.' pt}}'; + + } } elsif ($target eq 'web') { - $result.=''; + 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"); + $result .= &randomizetry_part_header($problemstatus,$reqtries,$num); + } + } + $result.=''; } } } @@ -1940,8 +2158,12 @@ sub start_problemtype { $result .=&Apache::edit::checked_arg('When used as type(s):','for', [ ['exam','Exam/Quiz Problem'], ['survey','Survey'], + ['surveycred','Survey (with credit)'], + ['anonsurvey','Anonymous Survey'], + ['anonsurveycred','Anonymous Survey (with credit)'], ['problem','Homework Problem'], - ['practice','Practice Problem'] ] + ['practice','Practice Problem'], + ['randomizetry','New Randomization Each Try'] ] ,$token); $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); } elsif ($target eq 'modified') { @@ -1980,17 +2202,15 @@ sub end_startouttext { $result.=&Apache::edit::start_table($token)."" .''; - unless ($env{'environment.wysiwygeditor'} eq 'on') { - $result .= '' - .''; - } - $result.='' + .'' + .'' + .'
'; + '
'; } sub problem_edit_footer { return '

'. - - &Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields()). "\n\n".&Apache::loncommon::end_page(); } @@ -468,7 +568,11 @@ sub problem_web_to_edit_header { ".&option('exam' ,'problemtype').&mt("Exam Problem")." ".&option('problem','problemtype').&mt("Homework Problem")." ".&option('survey' ,'problemtype').&mt("Survey Question")." + ".&option('surveycred' ,'problemtype').&mt("Survey Question (with credit)")." + ".&option('anonsurvey' ,'problemtype').&mt("Anonymous Survey Question")." + ".&option('anonsurveycred' ,'problemtype').&mt("Anonymous Survey Question (with credit)")." ".&option('practice' ,'problemtype').&mt("Practice Problem")." + ".&option('randomizetry' ,'problemtype').&mt("New Randomization Each Try")." $show_all @@ -515,7 +619,7 @@ $show_all -
+
@@ -539,7 +643,7 @@ $show_all $result.='
-
+
'; $result.=''; $result .= ''; $result.='
-
+
'.&Apache::lonxml::message_location().' '; return $result; @@ -626,9 +730,7 @@ sub finalize_storage { $result=&Apache::lonnet::cstore(\%Apache::lonhomework::results, $symb,$courseid,$domain,$name); &Apache::lonxml::debug('Store return message:'.$result); - if ($env{'request.role'} =~/^st/) { - &store_aggregates($symb,$courseid); - } + &store_aggregates($symb,$courseid); } } else { &Apache::lonxml::debug('Nothing to store'); @@ -648,7 +750,7 @@ item store_aggregates() sub store_aggregates { my ($symb,$courseid) = @_; - my %aggregate; + my (%aggregate,%anoncounter,%randtrycounter); my @parts; my $cdomain = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cname = $env{'course.'.$env{'request.course.id'}.'.num'}; @@ -658,28 +760,60 @@ sub store_aggregates { } } foreach my $part (@parts) { - if ($Apache::lonhomework::results{'resource.'.$part.'.award'} - eq 'APPROX_ANS' || - $Apache::lonhomework::results{'resource.'.$part.'.award'} - eq 'EXACT_ANS') { - $aggregate{$symb."\0".$part."\0correct"} = 1; + if ($env{'request.role'} =~/^st/) { + if ($Apache::lonhomework::results{'resource.'.$part.'.award'} + eq 'APPROX_ANS' || + $Apache::lonhomework::results{'resource.'.$part.'.award'} + eq 'EXACT_ANS') { + $aggregate{$symb."\0".$part."\0correct"} = 1; + } + if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) { + $aggregate{$symb."\0".$part."\0users"} = 1; + } else { + my (undef,$last_reset) = &Apache::grades::get_last_resets($symb,$env{'request.course.id'},[$part]); + if ($last_reset) { + if (&Apache::grades::get_num_tries(\%Apache::lonhomework::history,$last_reset,$part) == 0) { + $aggregate{$symb."\0".$part."\0users"} = 1; + } + } + } + $aggregate{$symb."\0".$part."\0attempts"} = 1; } - if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) { - $aggregate{$symb."\0".$part."\0users"} = 1; - } else { - my (undef,$last_reset) = &Apache::grades::get_last_resets($symb,$env{'request.course.id'},[$part]); - if ($last_reset) { - if (&Apache::grades::get_num_tries(\%Apache::lonhomework::history,$last_reset,$part) == 0) { - $aggregate{$symb."\0".$part."\0users"} = 1; + if (($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'anonsurvey') || + ($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'anonsurveycred') || + ($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'randomizetry')) { + if ($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'randomizetry') { + $randtrycounter{$symb."\0".$part} = 1; + } else { + $anoncounter{$symb."\0".$part} = 1; + } + my $needsrelease = $Apache::lonnet::needsrelease{'parameter:type:'.$Apache::lonhomework::results{'resource.'.$part.'.type'}}; + if ($needsrelease) { + my $curr_required = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'}; + if ($curr_required eq '') { + &Apache::lonnet::update_released_required($needsrelease); + } else { + my ($currmajor,$currminor) = split(/\./,$curr_required); + my ($needsmajor,$needsminor) = split(/\./,$needsrelease); + if (($currmajor < $needsmajor) || ($currmajor == $needsmajor && $currminor < $needsminor)) { + &Apache::lonnet::update_released_required($needsrelease); + } } } } - $aggregate{$symb."\0".$part."\0attempts"} = 1; } if (keys (%aggregate) > 0) { &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate, $cdomain,$cname); } + if (keys(%anoncounter) > 0) { + &Apache::lonnet::cput('nohist_anonsurveys',\%anoncounter, + $cdomain,$cname); + } + if (keys(%randtrycounter) > 0) { + &Apache::lonnet::cput('nohist_randomizetry',\%randtrycounter, + $cdomain,$cname); + } } sub checkout_msg { @@ -760,6 +894,7 @@ sub init_problem_globals { &Apache::lonhomework::reset_show_problem_status(); $Apache::lonhomework::ignore_response_errors=1; } + @Apache::functionplotresponse::callscripts=(); @Apache::inputtags::responselist = (); @Apache::inputtags::importlist = (); @Apache::inputtags::previous=(); @@ -787,6 +922,7 @@ sub reset_problem_globals { undef($Apache::lonhomework::type); undef($Apache::lonhomework::scantronmode); undef($Apache::lonhomework::ignore_response_errors); + undef(@Apache::functionplotresponse::callscripts); &Apache::lonhomework::reset_show_problem_status(); } @@ -887,7 +1023,7 @@ sub start_problem { if ($target eq 'tex' and $env{'request.symb'} =~ m/\.page_/) {$result='';} - if ($target eq 'analyze') { my $rndseed=&setup_rndseed($safeeval); } + if ($target eq 'analyze') { my $rndseed=&setup_rndseed($safeeval,$target); } if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') { #handle exam checkout @@ -905,9 +1041,15 @@ sub start_problem { my @interval=&Apache::lonnet::EXT("resource.0.interval"); &Apache::lonnet::set_first_access($interval[1]); } + + ($status,$accessmsg,my $slot_name,my $slot) = + &Apache::lonhomework::check_slot_access('0','problem'); + push (@Apache::inputtags::status,$status); + #handle rand seed in construction space - my $rndseed=&setup_rndseed($safeeval); + my $rndseed=&setup_rndseed($safeeval,$target); my ($symb)=&Apache::lonnet::whichuser(); + if ($env{'request.state'} ne "construct" && ($symb eq '' || $Apache::lonhomework::type eq 'practice')) { $form_tag_start.=''; } if ($env{'request.role.adv'}) { - $form_tag_start.= - ' '; } if ($Apache::lonhomework::type eq 'practice') { $form_tag_start.=&practice_problem_header(); } $form_tag_start.='
'; - } - - ($status,$accessmsg,my $slot_name,my $slot) = - &Apache::lonhomework::check_slot_access('0','problem'); - push (@Apache::inputtags::status,$status); + } 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.'";'; $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";'; @@ -1017,6 +1162,13 @@ sub start_problem { $result .= ''."\n"; } + foreach my $field ('questiontype','rndseed') { + if ($env{"form.grade_$field"} ne '') { + $result .= ''."\n"; + } + } + } } elsif ($target eq 'tex') { $result .= 'INSERTTEXFRONTMATTERHERE'; @@ -1121,7 +1273,9 @@ sub end_problem { '\textit{'.$duedate_text.'} '.$toc_line; } else { $frontmatter.= $begin_doc.$toc_line; - if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { $frontmatter .= '\fbox{\textit{'.$weight.' pt}}';} + if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { + $frontmatter .= '\fbox{\textit{'.$weight.' pt}}'; + } } } else { $frontmatter .= '\vskip 1mm\textit{'.$duedate_text.'} \\\\\\\\'.$startminipage; @@ -1129,7 +1283,9 @@ sub end_problem { } else { if (not $env{'request.symb'} =~ m/\.page_/) { $frontmatter .= $begin_doc.$toc_line; - if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { $frontmatter .= '\fbox{\textit{'.$weight.' pt}}';} + if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { + $frontmatter .= '\fbox{\textit{'.$weight.' pt}}'; + } } else { $frontmatter .= '\vskip 1mm \\\\\\\\'.$startminipage; } @@ -1165,7 +1321,6 @@ sub end_problem { if ($target ne 'tex' && $env{'form.answer_output_mode'} ne 'tex') { $result.=""; - $result.= &Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields()); } if ($target eq 'web') { $result.= &Apache::loncommon::end_page({'discussion' => 1}); @@ -1186,6 +1341,9 @@ sub end_problem { } } } + if ($target eq 'web') { + $result.=&Apache::functionplotresponse::init_script(); + } if ($target eq 'grade') { &Apache::lonhomework::showhash(%Apache::lonhomework::results); &finalize_storage(); @@ -1243,7 +1401,7 @@ sub start_library { ($result,$form_tag_start)= &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval, $name); - my $rndseed=&setup_rndseed($safeeval); + my $rndseed=&setup_rndseed($safeeval,$target); $result.=" \n $form_tag_start". ''; $result.=&problem_web_to_edit_header($rndseed); @@ -1482,7 +1640,7 @@ sub start_instructorcomment { if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { - $result=($env{'request.role'}=~/^(in|cc|au|ca|li)/); + $result=($env{'request.role'}=~/^(in|cc|co|au|ca|li)/); if ( (! $result) or ($env{'form.instructor_comments'} eq 'hide')) { my $skip=&Apache::lonxml::get_all_text("/instructorcomment", $parser,$style); @@ -1687,6 +1845,44 @@ sub ordered_show_check { return $in_order_show; } +sub start_startpartmarker { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my $result=''; + if ($target eq 'edit') { + $result=&Apache::edit::tag_start($target,$token); + $result.=&mt('Marker for the start of a part. Place end marker below to wrap in-between tags into a new part.').'
".&mt('Text Block')."'.&mt('Delete?').' ' .&Apache::edit::deletelist($target,$token) - .'' - .&Apache::lonhtmlcommon::dragmath_button($areaid,1) - .'' - .&Apache::edit::insertlist($target,$token) - .'' . - &Apache::loncommon::helpLatexCheatsheet(). + .'' + .&Apache::lonhtmlcommon::dragmath_button($areaid,1) + .'' + .&Apache::edit::insertlist($target,$token) + .'' . + &Apache::loncommon::helpLatexCheatsheet(). &Apache::edit::end_row(). &Apache::edit::start_spanning_row()."\n". &Apache::edit::editfield($token->[1],$text,"",80,8,1); @@ -2078,6 +2298,63 @@ sub practice_problem_header { ''; } +sub randomizetry_problem_header { + my ($problemstatus,$reqtries) = @_; + my ($header,$text); + if ($reqtries > 1) { + $header = &mt('New Problem Variation After Every [quant,_1,Try,Tries]',$reqtries); + if (($problemstatus eq 'no') || + ($problemstatus eq 'no_feedback_ever')) { + $text = &mt('A new variation will be generated after every [quant,_1,try,tries], until the tries limit is reached.',$reqtries); + } else { + $text = &mt('A new variation will be generated after every [quant,_1,try,tries], until correct or tries limit is reached.',$reqtries); + } + } else { + $header = &mt('New Problem Variation Each Try'); + if (($problemstatus eq 'no') || + ($problemstatus eq 'no_feedback_ever')) { + $text = &mt('A new variation will be generated after each try until the tries limit is reached.'); + + } else { + $text = &mt('A new variation will be generated after each try until correct or tries limit is reached.'); + } + } + return '

'.$header.'

'. + ''.$text.'
'; +} + +sub randomizetry_part_header { + my ($problemstatus,$reqtries,$num) = @_; + my ($header,$text); + if ($reqtries eq 'none') { + $header = &mt('No Question Variation'); + $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') || + ($problemstatus eq 'no_feedback_ever')) { + $text = &mt('For this question a new variation will be generated after every [quant,_1,try,tries], until the tries limit is reached.',$reqtries); + } else { + $text = &mt('For this question a new variation will be generated after every [quant,_1,try,tries], until correct or tries limit is reached.',$reqtries); + } + } else { + $header = &mt('New Question Variation For Each Try'); + if (($problemstatus eq 'no') || + ($problemstatus eq 'no_feedback_ever')) { + $text = &mt('For this question a new variation will be generated after each try until the tries limit is reached.'); + } else { + $text = &mt('For this question a new variation will be generated after each try until correct or tries limit is reached.'); + } + } + my $output; + if ($num > 1) { + $output .= '
'; + } + $output .= '

'.$header.'

'. + ''.$text.'

'; + return $output; +} + 1; __END__