--- loncom/homework/structuretags.pm 2010/08/16 18:09:28 1.465.2.3
+++ loncom/homework/structuretags.pm 2011/01/01 21:54:08 1.465.2.10
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.465.2.3 2010/08/16 18:09:28 raeburn Exp $
+# $Id: structuretags.pm,v 1.465.2.10 2011/01/01 21:54:08 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -128,6 +128,7 @@ sub homework_js {
&setmode_javascript().
<<'JS';
JS
}
@@ -161,6 +162,50 @@ function setmode(form,probmode) {
ENDSCRIPT
}
+sub file_delchk_js {
+ my $delfilewarn = &mt('You have indicated you wish to delete some files previously included for submission.').'\\n'.
+ &mt('Deleted files will not be graded.').' '.
+ &mt('Submit Answer?');
+ return <<"ENDSCRIPT";
+
+ENDSCRIPT
+}
+
sub page_start {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name,
$extra_head)=@_;
@@ -177,12 +222,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;
@@ -280,6 +330,9 @@ sub page_start {
if ($target eq 'edit') {
$form_tag_start.=&Apache::edit::form_change_detection();
}
+ if ($is_task) {
+ $form_tag_start .= ' onsubmit="return file_deletion_check(this);"';
+ }
$form_tag_start.='>'."\n";
my $symb=&Apache::lonnet::symbread();
@@ -321,9 +374,15 @@ sub get_resource_name {
}
sub setup_rndseed {
- my ($safeeval)=@_;
- my $rndseed;
+ my ($safeeval,$target)=@_;
my ($symb)=&Apache::lonnet::whichuser();
+ my ($questiontype,$set_safespace,$rndseed);
+ if ($target eq 'analyze') {
+ $questiontype = $env{'form.grade_questiontype'};
+ }
+ unless (defined($questiontype)) {
+ $questiontype = $Apache::lonhomework::type;
+ }
if ($env{'request.state'} eq "construct"
|| $symb eq ''
|| $Apache::lonhomework::type eq 'practice'
@@ -338,6 +397,14 @@ sub setup_rndseed {
}
$env{'form.rndseed'}=$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;
+ }
+ $env{'form.'.$Apache::inputtags::part.'.rndseed'}=$rndseed;
+ }
if ( ($env{'form.resetdata'} eq &mt('New Problem Variation')
&& $env{'form.submitted'} eq 'yes') ||
$env{'form.newrandomization'} eq &mt('New Randomization')) {
@@ -353,10 +420,42 @@ sub setup_rndseed {
if ($Apache::lonhomework::history{'resource.CODE'}) {
$rndseed=&Apache::lonnet::rndseed();
}
- if ($safeeval) {
- &Apache::lonxml::debug("Setting rndseed to $rndseed");
- &Apache::run::run('$external::randomseed="'.$rndseed.'";',$safeeval);
- }
+ $set_safespace = 1;
+ } elsif ($questiontype eq 'randomizetry') {
+ if ($target eq 'analyze') {
+ if (defined($env{'form.grade_rndseed'})) {
+ $rndseed = $env{'form.grade_rndseed'};
+ }
+ }
+ unless (($target eq 'analyze') && (defined($rndseed))) {
+ $rndseed=&Apache::lonnet::rndseed();
+ my $curr_try = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.tries"};
+ if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
+ $curr_try ++;
+ }
+ if ($rndseed =~/^(\d+)[,:](\d+)$/) {
+ $rndseed = $1;
+ }
+ if ($curr_try) {
+ my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
+ if (($reqtries =~ /^\d+$/) && ($reqtries > 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;
}
@@ -405,8 +504,6 @@ sub problem_edit_footer {
'.
-
- &Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields()).
"\n\n".&Apache::loncommon::end_page();
}
@@ -476,6 +573,7 @@ sub problem_web_to_edit_header {
".&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
@@ -653,7 +751,7 @@ item store_aggregates()
sub store_aggregates {
my ($symb,$courseid) = @_;
- my (%aggregate,%anoncounter);
+ my (%aggregate,%anoncounter,%randtrycounter);
my @parts;
my $cdomain = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
@@ -683,8 +781,13 @@ sub store_aggregates {
$aggregate{$symb."\0".$part."\0attempts"} = 1;
}
if (($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'anonsurvey') ||
- ($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'anonsurveycred')) {
- $anoncounter{$symb."\0".$part} = 1;
+ ($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'};
@@ -705,8 +808,12 @@ sub store_aggregates {
$cdomain,$cname);
}
if (keys(%anoncounter) > 0) {
- &Apache::lonnet::cinc('nohist_anonsurveys',\%anoncounter,
- $cdomain,$cname);
+ &Apache::lonnet::cput('nohist_anonsurveys',\%anoncounter,
+ $cdomain,$cname);
+ }
+ if (keys(%randtrycounter) > 0) {
+ &Apache::lonnet::cput('nohist_randomizetry',\%randtrycounter,
+ $cdomain,$cname);
}
}
@@ -915,7 +1022,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
@@ -933,9 +1040,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.=' '."\n";
}
+ foreach my $field ('questiontype','rndseed') {
+ if ($env{"form.grade_$field"} ne '') {
+ $result .= ' '."\n";
+ }
+ }
+
}
} elsif ($target eq 'tex') {
$result .= 'INSERTTEXFRONTMATTERHERE';
@@ -1198,7 +1320,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});
@@ -1276,7 +1397,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);
@@ -1847,7 +1968,26 @@ sub start_part {
}
} 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.=' ';
}
}
}
@@ -2018,7 +2158,8 @@ sub start_problemtype {
['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') {
@@ -2057,17 +2198,15 @@ sub end_startouttext {
$result.=&Apache::edit::start_table($token)."".&mt('Text Block')." "
.''.&mt('Delete?').' '
.&Apache::edit::deletelist($target,$token)
- .' ';
- unless ($env{'environment.wysiwygeditor'} eq 'on') {
- $result .= ''
- .&Apache::lonhtmlcommon::dragmath_button($areaid,1)
- .' '
- .''
- .&Apache::edit::insertlist($target,$token)
- .' ';
- }
- $result.='' .
- &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);
@@ -2155,6 +2294,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__