--- loncom/homework/inputtags.pm 2013/06/07 20:31:50 1.318
+++ loncom/homework/inputtags.pm 2015/10/30 11:33:07 1.333.2.3
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# input definitons
#
-# $Id: inputtags.pm,v 1.318 2013/06/07 20:31:50 raeburn Exp $
+# $Id: inputtags.pm,v 1.333.2.3 2015/10/30 11:33:07 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -222,7 +222,7 @@ sub start_textfield {
$oldresponse = $Apache::lonhomework::history{"resource.$partid.$resid.submission"};
} elsif (($Apache::lonhomework::history{"resource.$partid.type"} eq 'anonsurvey') ||
($Apache::lonhomework::history{"resource.$partid.type"} eq 'anonsurveycred')) {
- $oldresponse = '* '.&mt('only shown to submitter').' *';
+ $oldresponse = '* '.&mt('(only shown to submitter)').' *';
} else {
$oldresponse = $Apache::lonhomework::history{"resource.$partid.$resid.submission"};
}
@@ -235,11 +235,16 @@ sub start_textfield {
my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
$result='';
my $tagident = 'HWVAL_' . $resid;
+ my $itemid = 'HWVAL_'.$partid.'_'.$resid;
if ($addchars) {
$result.=&addchars($tagident, $addchars);
}
- my $textareaclass = 'class="LC_richDetectHtml spellchecked"';
- $result.= '";
- $result .= &spellcheck_onblur($tagident, $spellcheck);
+ $result .= &spellcheck_onblur($itemid, $spellcheck);
return $result;
}
} elsif ($target eq 'edit') {
@@ -424,7 +431,7 @@ sub start_textline {
($Apache::lonhomework::history{"resource.$partid.type"} eq 'anonsurveycred') ||
($Apache::lonhomework::type eq 'anonsurvey') ||
($Apache::lonhomework::type eq 'anonsurveycred')) {
- $oldresponse = '* '.&mt('only shown to submitter').' *';
+ $oldresponse = '* '.&mt('(only shown to submitter)').' *';
} else {
$oldresponse = $Apache::lonhomework::history{"resource.$partid.$id.submission"};
}
@@ -452,18 +459,24 @@ sub start_textline {
$readonly='';
}
my $name = 'HWVAL_'.$id;
+ my $itemid = 'HWVAL_'.$partid.'_'.$id;
+ my $input_tag_id = $itemid.'_'.$input_id;
if ($Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') {
$name = "none";
}
$result.= ' ';
+ . ' class="LC_textline spellchecked" size="'.$size.'"'.$maxlength.' />';
- $result .= &spellcheck_onblur($name, $spellcheck);
+ $result .= &spellcheck_onblur($itemid, $spellcheck);
+ if (($Apache::inputtags::status['-1'] eq 'CAN_ANSWER') &&
+ (($tagstack->[-2] eq 'formularesponse') || ($tagstack->[-2] eq 'mathresponse')) &&
+ (&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffeditor') ne 'yes')) {
+ $result.=&edit_mathresponse_button($input_tag_id);
+ }
}
if ($Apache::lonhomework::type eq 'exam'
&& &needs_exam_box($tagstack)) {
@@ -647,7 +660,7 @@ sub file_selector {
&mt('Allowed filetypes: [_1]',''.$uploadedfiletypes.' ').' ';
}
if ($maxfilesize) {
- $constraints .= &mt('Combined size of all files not to exceed: [_1] MB[_2].',
+ $constraints .= &mt('Combined size of all files not to exceed: [_1] MB.',
''.$maxfilesize.' ').' ';
}
if ($constraints) {
@@ -691,7 +704,8 @@ sub current_file_submissions {
my $uploadedfile=$Apache::lonhomework::history{"resource.$part.$id.uploadedfile"};
my $portfiles=$Apache::lonhomework::history{"resource.$part.$id.portfiles"};
return if (($uploadedfile eq '') && ($portfiles !~/[^\s]/));
- my $header = &Apache::loncommon::start_data_table().
+ my $header = &portpath_popup_js().
+ &Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row();
if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
$header .= '
'.&mt('Delete?').' ';
@@ -757,13 +771,24 @@ sub current_file_submissions {
' value="'.$portfile.'" id="HWFILE'.$jspart.'_'.$id.'_'.$num.'_delete" />'."\n";
$num ++;
}
- my $showname = $rows{$url}{path}.$name;
+ my $pathid = 'HWFILE'.$jspart.'_'.$id.'_'.$num.'_path';
+ my $pathidtext = $pathid.'text';
+ my ($showname,$showpath);
if ($legacy{$url}) {
$showname = $name.' '.&mt('not in portfolio');
+ } else {
+ $showname = $name;
+ $showpath = ' '.
+ ''.
+ ''.
+ &mt('(Show path)').' '.
+ ''.$rows{$url}{path}.$name.
+'
';
}
$result .=
' '.$showname.' '."\n".
+ '" border="0" alt="" />'.$showname.''.$showpath.''."\n".
''.$rows{$url}{size}.' '."\n".
''.$rows{$url}{lastmodified}.' '."\n".
&Apache::loncommon::end_data_table_row();
@@ -818,10 +843,47 @@ sub current_file_info {
return ($status,\%info,$error);
}
+sub portpath_popup_js {
+ my %lt = &Apache::lonlocal::texthash(
+ show => '(Show path)',
+ hide => '(Hide)',
+ );
+ return <<"END";
+
+
+END
+}
+
sub valid_award {
my ($award) =@_;
foreach my $possibleaward ('EXTRA_ANSWER','MISSING_ANSWER', 'ERROR',
- 'NO_RESPONSE',
+ 'NO_RESPONSE','WRONG_NUMBOXESCHECKED',
'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR',
'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',
'UNIT_FAIL', 'NO_UNIT',
@@ -841,7 +903,7 @@ sub valid_award {
{
my @awards = ('EXTRA_ANSWER', 'MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',
- 'TOO_LONG',
+ 'WRONG_NUMBOXESCHECKED','TOO_LONG',
'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT',
'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT',
'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA', 'NOT_FUNCTION',
@@ -931,6 +993,23 @@ sub finalizeawards {
$j++;
}
+ # if at least one response item is set to include lenient grading
+ # and that item is partially correct then overall award reflects
+ # that, unless an award for one of the other response items does
+ # not fall within the basic awards for correct or incorrect.
+ if ($Apache::inputtags::leniency) {
+ if (($$awardref[$which] eq 'INCORRECT')
+ && (grep { $_ eq 'EXACT_ANS' ||
+ $_ eq 'APPROX_ANS' ||
+ $_ eq 'ASSIGNED_SCORE' } (@$awardref))
+ && !((grep { $_ ne 'INCORRECT' &&
+ $_ ne 'EXACT_ANS' &&
+ $_ ne 'APPROX_ANS' &&
+ $_ ne 'ASSIGNED_SCORE' } (@$awardref)))) {
+ return ('ASSIGNED_SCORE');
+ }
+ }
+
if (defined($which)) {
if (ref($nameref)) {
return ($$awardref[$which],$$msgref[$which],$$nameref[$which]);
@@ -943,7 +1022,7 @@ sub finalizeawards {
}
sub decideoutput {
- my ($award,$awarded,$awardmsg,$solved,$previous,$target,$nocorrect)=@_;
+ my ($award,$awarded,$awardmsg,$solved,$previous,$target,$nocorrect,$tdclass)=@_;
my $message='';
my $button=0;
@@ -1068,6 +1147,13 @@ sub decideoutput {
}
$css_class=$possible_class{'not_charged_try'};
$button = 1;
+ } elsif ($award eq 'WRONG_NUMBOXESCHECKED') {
+ $message = &mt('Number of boxes checked outside permissible range (either too few or too many).');
+ if ($target ne 'tex') {
+ $message .= &Apache::loncommon::help_open_topic('Wrong_Num_Boxes_Checked');
+ }
+ $css_class=$possible_class{'not_charged_try'};
+ $button = 1;
} elsif ($award eq 'ERROR') {
$message = &mt('An error occurred while grading your answer.');
$css_class=$possible_class{'not_charged_try'};
@@ -1088,7 +1174,7 @@ sub decideoutput {
$css_class=$possible_class{'not_charged_try'};
$button=1;
} elsif ($award eq 'EXCESS_FILESIZE') {
- $message = &mt('Submission won\'t be graded. The combined size of submitted files exceeded the amount allowed.');
+ $message = &mt("Submission won't be graded. The combined size of submitted files exceeded the amount allowed.");
$css_class=$possible_class{'not_charged_try'};
$button=1;
} elsif ($award eq 'FILENAME_INUSE') {
@@ -1439,7 +1525,8 @@ sub setgradedata {
$Apache::lonhomework::results{"resource.$id.type"} = $Apache::lonhomework::type;
$Apache::lonhomework::results{"resource.$id.duedate"} = &Apache::lonnet::EXT("resource.$id.duedate");
$Apache::lonhomework::results{"resource.$id.hinttries"} = &Apache::lonnet::EXT("resource.$id.hinttries");
- $Apache::lonhomework::results{"resourse.$id.version"} = &Apache::lonnet::usedversion();
+ $Apache::lonhomework::results{"resource.$id.version"} = &Apache::lonnet::usedversion();
+ $Apache::lonhomework::results{"resource.$id.maxtries"} = &Apache::lonnet::EXT("resource.$id.maxtries");
}
sub find_which_previous {
@@ -1519,7 +1606,7 @@ sub grade {
}
sub get_grade_messages {
- my ($id,$prefix,$target,$status,$nocorrect) = @_;
+ my ($id,$prefix,$target,$status,$nocorrect,$tdclass) = @_;
# nocorrect suppresses "Computer's answer now shown above"
my ($message,$latemessage,$trystr,$previousmsg);
my $showbutton = 1;
@@ -1534,13 +1621,13 @@ sub get_grade_messages {
&Apache::lonxml::debug('Getting message');
($showbutton,my $css_class,$message,$previousmsg) =
&decideoutput($award,$awarded,$awardmsg,$solved,$previous,
- $target,(($status eq 'CAN_ANSWER') || $nocorrect));
+ $target,(($status eq 'CAN_ANSWER') || $nocorrect),$tdclass);
if ($target eq 'tex') {
$message='\vskip 2 mm '.$message.' ';
} else {
- $message="$message ";
+ $message="$message ";
if ($previousmsg) {
- $previousmsg="$previousmsg ";
+ $previousmsg="$previousmsg ";
}
}
}
@@ -1575,7 +1662,7 @@ sub get_grade_messages {
$trial.="/".$Apache::inputtags::params{'maxtries'};
}
}
- $trystr = ''.&mt($tries_text.' [_1]',$trial).' ';
+ $trystr = ''.&mt($tries_text.' [_1]',$trial).' ';
}
}
@@ -1583,7 +1670,7 @@ sub get_grade_messages {
#last submissions was after due date
$latemessage=&mt(' The last submission was after the Due Date ');;
if ($target eq 'web') {
- $latemessage=''.$latemessage.' ';
+ $latemessage=''.$latemessage.' ';
}
}
return ($previousmsg,$latemessage,$message,$trystr,$showbutton);
@@ -1597,6 +1684,7 @@ sub gradestatus {
my $trystr='';
my $button='';
my $previousmsg='';
+ my $tdclass='';
my $status = $Apache::inputtags::status['-1'];
&Apache::lonxml::debug("gradestatus has :$status:");
@@ -1613,21 +1701,29 @@ sub gradestatus {
$showbutton = 0;
}
+ unless (($status eq 'SHOW_ANSWER') || ($status eq 'CANNOT_ANSWER')) {
+ if ($target ne 'tex') {
+ $tdclass = 'LC_status_submit_'.$id;
+ }
+ }
+
($previousmsg,$latemessage,$message,$trystr) =
&get_grade_messages($id,"resource.$id",$target,$status,
- $showbutton);
+ $showbutton,$tdclass);
if ($status eq 'CANNOT_ANSWER') {
$showbutton = 0;
}
if ( $status eq 'SHOW_ANSWER') {
undef($previousmsg);
}
- if ( $showbutton ) {
+ if ( $showbutton ) {
if ($target ne 'tex') {
$button =
' ';
+ type="submit" name="submit_'.$id.'" id="submit_'.$id.'" class="LC_hwk_submit"
+ value="'.&mt('Submit Answer').'" /> '.
+ ''.
+ &mt('Processing your submission ...').'
';
}
}
@@ -1642,7 +1738,7 @@ sub gradestatus {
$output =
''.$button.' '.$output;
if (!$no_previous) {
- $output.=''.&previous_tries($id,$target).' ';
+ $output.=''.&previous_tries($id,$target).' ';
}
$output.= '
';
return $output;
@@ -1657,15 +1753,15 @@ sub previous_tries {
my $count;
my %count_lookup;
- my $lastrndseed;
+ my ($lastrndseed,$lasttype);
my $numstamps = 0;
foreach my $i (1..$Apache::lonhomework::history{'version'}) {
my $prefix = $i.":resource.$id";
- my $is_anon;
+ my $is_anon;
+ my $curr_type = $Apache::lonhomework::history{"$prefix.type"};
if (defined($env{'form.grade_symb'})) {
- if (($Apache::lonhomework::history{"$prefix.type"} eq 'anonsurvey') ||
- ($Apache::lonhomework::history{"$prefix.type"} eq 'anonsurveycred')) {
+ if (($curr_type eq 'anonsurvey') || ($curr_type eq 'anonsurveycred')) {
$is_anon = 1;
}
}
@@ -1704,8 +1800,9 @@ sub previous_tries {
{$1 $txt_correct . $3}s;
}
my $trystr = "(".&mt('Try [_1]',$Apache::lonhomework::history{"$prefix.tries"}).")";
- if (($curr_rndseed || $lastrndseed) && ($i > 1)) {
- if ($curr_rndseed ne $lastrndseed) {
+ if (($curr_rndseed ne '') && ($lastrndseed ne '')) {
+ if (($curr_rndseed ne $lastrndseed) &&
+ (($curr_type eq 'randomizetry') || ($lasttype eq 'randomizetry'))) {
$trystr .= ''.&mt('New problem variation this try.').' ';
}
}
@@ -1746,6 +1843,7 @@ sub previous_tries {
}
$output.=&Apache::loncommon::end_data_table_row()."\n";
$lastrndseed = $curr_rndseed;
+ $lasttype = $curr_type;
}
return if ($output eq '');
my $headers = ''.
@@ -1810,6 +1908,118 @@ sub spelling_languages {
return \@spelllangs;
}
+sub edit_mathresponse_button {
+ my ($field) = @_;
+ my $eqneditor = 'lcmath';
+ if ($env{'browser.type'} eq 'safari') {
+ if ($env{'browser.os'} eq 'mac') {
+ my ($prefix,$version) = ($env{'browser.version'} =~ /^(\d*)(\d{3})\./);
+ if ($env{'browser.mobile'}) {
+ if (($version < 531) || (($prefix eq '') && ($version < 533))) {
+ $eqneditor = '';
+ }
+ } elsif ($version < 533) {
+ $eqneditor = 'dragmath';
+ }
+ } elsif ($env{'browser.os'} eq 'win') {
+ if ($env{'browser.version'} < 533) {
+ $eqneditor = 'dragmath';
+ }
+ }
+ } elsif ($env{'browser.type'} eq 'explorer') {
+ if ($env{'browser.version'} < 9) {
+ $eqneditor = 'dragmath';
+ }
+ } elsif ($env{'browser.type'} eq 'mozilla') {
+ if ($env{'browser.version'} < 5) {
+ $eqneditor = 'dragmath';
+ } else {
+ if ($env{'browser.info'} =~ /^firefox\-([\d\.]+)/) {
+ my $firefox = $1;
+ if ($firefox < 4) {
+ $eqneditor = 'dragmath';
+ }
+ }
+ }
+ } elsif ($env{'browser.type'} eq 'chrome') {
+ if ($env{'browser.version'} < 5) {
+ $eqneditor = 'dragmath';
+ }
+ } elsif ($env{'browser.type'} eq 'opera') {
+ if ($env{'browser.version'} < 12) {
+ $eqneditor = 'dragmath';
+ }
+ }
+ if ($eqneditor eq 'lcmath') {
+ if (($env{'request.course.id'}) && ($env{'request.state'} ne 'construct')) {
+ if (exists($env{'course.'.$env{'request.course.id'}.'.uselcmath'})) {
+ if ($env{'course.'.$env{'request.course.id'}.'.uselcmath'} eq '0') {
+ $eqneditor = 'dragmath';
+ }
+ } else {
+ my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
+ if ($domdefs{'uselcmath'} eq '0') {
+ $eqneditor = 'dragmath';
+ }
+ }
+ } else {
+ my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
+ if ($domdefs{'uselcmath'} eq '0') {
+ $eqneditor = 'dragmath';
+ }
+ }
+ }
+ if ($eqneditor eq 'dragmath') {
+ # DragMath applet
+ my $button=&mt('Edit Answer');
+# my $helplink=&Apache::loncommon::help_open_topic('Formula_Editor');
+ my $iconpath=$Apache::lonnet::perlvar{'lonIconsURL'};
+ return(<
+function LC_mathedit_${field} (LCtextline) {
+ thenumber = LCtextline;
+ var thedata = '';
+ if (document.getElementById(LCtextline)) {
+ thedata = document.getElementById(LCtextline).value;
+ }
+ newwin = window.open("/adm/dragmath/MaximaPopup.html","","width=565,height=400,resizable");
+}
+
+
+ENDFORMULABUTTON
+ } elsif ($eqneditor eq 'lcmath') {
+ # LON-CAPA math equation editor
+ my $mathjaxjs;
+ unless (lc(&Apache::lontexconvert::tex_engine()) eq 'mathjax') {
+ $mathjaxjs = <<"MATHJAX_SCRIPT";
+var mathjaxscript = document.createElement("script");
+ mathjaxscript.type = "text/javascript";
+ mathjaxscript.src = "/adm/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
+ document.body.appendChild(mathjaxscript);
+MATHJAX_SCRIPT
+ }
+ return(<
+ var LCmathField = document.getElementById('${field}');
+ LCmathField.className += ' math'; // note the space
+ LCmathField.setAttribute('data-implicit_operators', 'true');
+ var LCMATH_started;
+ if (typeof LCMATH_started === 'undefined') {
+ $mathjaxjs
+ LCMATH_started = true;
+ var script = document.createElement("script");
+ script.type = "text/javascript";
+ script.src = "/adm/LC_math_editor/LC_math_editor.min.js";
+ document.body.appendChild(script);
+ window.addEventListener('load', function(e) {
+ LCMATH.initEditors();
+ }, false);
+ }
+
+EQ_EDITOR_SCRIPT
+ }
+}
+
1;
__END__