--- loncom/homework/inputtags.pm 2010/12/19 02:58:16 1.274
+++ loncom/homework/inputtags.pm 2011/12/08 02:59:34 1.297
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# input definitons
#
-# $Id: inputtags.pm,v 1.274 2010/12/19 02:58:16 raeburn Exp $
+# $Id: inputtags.pm,v 1.297 2011/12/08 02:59:34 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -60,7 +60,7 @@ use LONCAPA;
BEGIN {
- &Apache::lonxml::register('Apache::inputtags',('hiddenline','textfield','textline'));
+ &Apache::lonxml::register('Apache::inputtags',('hiddensubmission','hiddenline','textfield','textline'));
}
=pod
@@ -478,6 +478,49 @@ sub end_hiddenline {
return "";
}
+
+sub start_hiddensubmission {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my $result = "";
+ my $input_id = &start_input($parstack,$safeeval);
+ if ($target eq 'web') {
+ $Apache::lonxml::evaluate--;
+ if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
+ my $partid=$Apache::inputtags::part;
+ my $id=$Apache::inputtags::response[-1];
+ if ($Apache::lonhomework::type ne 'exam') {
+ my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
+ $value = &HTML::Entities::encode($value,'<>&"');
+ $result= '';
+ }
+ }
+ } elsif ($target eq 'edit') {
+ $result=&Apache::edit::tag_start($target,$token);
+ $result.=&Apache::edit::text_arg('Value:','value',$token,'15');
+ $result.=&Apache::edit::end_row();
+ $result.=&Apache::edit::end_table();
+ } elsif ($target eq 'modified') {
+ my $constructtag=&Apache::edit::get_new_args($token,$parstack,
+ $safeeval,'value');
+ if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
+ }
+
+ if ( ($target eq 'web' || $target eq 'tex')
+ && $Apache::lonhomework::type eq 'exam'
+ && &needs_exam_box($tagstack)) {
+ $result.=&exam_box($target);
+ }
+ return $result;
+}
+
+sub end_hiddensubmission {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ if ($target eq 'web') { $Apache::lonxml::evaluate++; }
+ elsif ($target eq 'edit') { return ('','no'); }
+ &end_input();
+ return "";
+}
+
=pod
=item file_selector()
@@ -528,7 +571,7 @@ sub file_selector {
if ($which eq 'uploadonly' || $which eq 'both') {
$result.=&mt('Submit a file: (only one file per submission)').
'
';
+ $jspart.'_'.$id.'" id="HWFILE'.$jspart.'_'.$id.'" />
';
}
if ( $which eq 'both') {
$result.='
'.''.&mt('OR:').'
';
@@ -595,9 +638,9 @@ sub current_file_submissions {
}
}
}
+ my $num = 0;
foreach my $name (sort(keys(%okfiles))) {
if (ref($okfiles{$name}) eq 'ARRAY') {
- my $num = 0;
foreach my $url (@{$okfiles{$name}}) {
if (ref($rows{$url}) eq 'HASH') {
my $link = $rows{$url}{link};
@@ -623,7 +666,7 @@ sub current_file_submissions {
}
$result .=
'
'.$showname.' | '."\n".
+ '" border="0" alt="" />'.$showname.''."\n".
''.$rows{$url}{size}.' | '."\n".
''.$rows{$url}{lastmodified}.' | '."\n".
&Apache::loncommon::end_data_table_row();
@@ -635,7 +678,7 @@ sub current_file_submissions {
if ($header_shown) {
$result .= &Apache::loncommon::end_data_table().
'
'.
- &mt('Items checked for deletion will not be included amongst the files evaluated when your submission is graded.').'';
+ &mt('Exclude existing file(s) from grading by checking the "Delete?" checkbox(es) and clicking "Submit Answer"').'';
}
if (@bad_file_list) {
my $bad_files = ''.
@@ -800,8 +843,28 @@ sub finalizeawards {
}
}
+sub grading_is_nonlenient {
+ my ($part) = @_;
+# Web mode: we are non-lenient unless told otherwise
+ my $defaultparm = 'off';
+ my $nonlenient = 0;
+# Grading a bubblesheet exam: we are grading lenient unless told otherwise
+ if ($Apache::lonhomework::scantronmode) {
+ $defaultparm = 'on';
+ $nonlenient = 1;
+ }
+ my $lenientparm =
+ &Apache::response::get_response_param($part,'lenient',$defaultparm);
+ if ($lenientparm=~/^0|off|no$/i) {
+ $nonlenient = 1;
+ } elsif ($lenientparm=~/^1|on|yes$/i) {
+ $nonlenient = 0;
+ }
+ return $nonlenient;
+}
+
sub decideoutput {
- my ($award,$awarded,$awardmsg,$solved,$previous,$target)=@_;
+ my ($award,$awarded,$awardmsg,$solved,$previous,$target,$nocorrect)=@_;
my $message='';
my $button=0;
@@ -819,8 +882,14 @@ sub decideoutput {
my $part = $Apache::inputtags::part;
my $tohandgrade = &Apache::lonnet::EXT("resource.$part.handgrade");
my $handgrade = ('yes' eq lc($tohandgrade));
+#
+# Should "Computer's Answer" be displayed?
+# Should not be displayed if still answerable,
+# if the problem is handgraded,
+# or if the problem does not give a correct answer
+#
- my $computer = ($handgrade)? ''
+ my $computer = ($handgrade || $nocorrect)? ''
: " ".&mt("Computer's answer now shown above.");
&Apache::lonxml::debug("handgrade has :$handgrade:");
@@ -836,8 +905,8 @@ sub decideoutput {
$message=&mt('Incorrect.');
$css_class=$possible_class{'charged_try'};
}
- if ($env{'request.filename'} =~
- m|/res/lib/templates/examupload.problem$|) {
+ if ($handgrade ||
+ ($env{'request.filename'}=~/\/res\/lib\/templates\/(examupload|DropBox).problem$/)) {
$message = &mt("A score has been assigned.");
$added_computer_text=1;
} else {
@@ -862,7 +931,13 @@ sub decideoutput {
}
}
}
- $button=0;
+ if (&grading_is_nonlenient($part)) {
+ $button=0;
+ } elsif ($awarded==1) {
+ $button=0;
+ } else {
+ $button=1;
+ }
$previousmsg='';
} elsif ($solved =~ /^excused/) {
if ($target eq 'tex') {
@@ -1088,7 +1163,6 @@ sub decideoutput {
}
$message.=&mt('Submissions to practice problems are not permanently recorded.');
}
-
return ($button,$css_class,$message,$previousmsg);
}
@@ -1141,8 +1215,7 @@ sub setgradedata {
$Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
$Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
return '';
- } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
- /^correct/
+ } elsif ( $Apache::lonhomework::history{"resource.$id.awarded"} < 1
|| $Apache::lonhomework::scantronmode
|| &Apache::lonhomework::hide_problem_status() ) {
# the student doesn't already have it correct,
@@ -1263,8 +1336,7 @@ sub setgradedata {
$Apache::lonhomework::results{"resource.$id.previous"} = '0';
}
}
- } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
- /^correct/ ) {
+ } elsif ( $Apache::lonhomework::history{"resource.$id.awarded"} == 1 ) {
#delete all data as they student already has it correct
&removealldata($id);
#and since they didn't do anything we were never here
@@ -1274,11 +1346,10 @@ sub setgradedata {
if ($award eq 'SUBMITTED') {
&Apache::response::add_to_gradingqueue();
}
- if (($Apache::lonhomework::type eq 'anonsurvey') ||
- ($Apache::lonhomework::type eq 'anonsurveycred') ||
- ($Apache::lonhomework::type eq 'randomizetry')) {
- $Apache::lonhomework::results{"resource.$id.type"} = $Apache::lonhomework::type;
- }
+ $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();
}
sub find_which_previous {
@@ -1358,8 +1429,8 @@ sub grade {
}
sub get_grade_messages {
- my ($id,$prefix,$target,$status) = @_;
-
+ my ($id,$prefix,$target,$status,$nocorrect) = @_;
+# nocorrect suppresses "Computer's answer now shown above"
my ($message,$latemessage,$trystr,$previousmsg);
my $showbutton = 1;
@@ -1373,7 +1444,7 @@ sub get_grade_messages {
&Apache::lonxml::debug('Getting message');
($showbutton,my $css_class,$message,$previousmsg) =
&decideoutput($award,$awarded,$awardmsg,$solved,$previous,
- $target);
+ $target,(($status eq 'CAN_ANSWER') || $nocorrect));
if ($target eq 'tex') {
$message='\vskip 2 mm '.$message.' ';
} else {
@@ -1391,28 +1462,30 @@ sub get_grade_messages {
if ( $tries eq '' ) { $tries = '0'; }
if ( $maxtries eq '' ) { $maxtries = '2'; }
if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
- my $tries_text= &get_tries_text();;
+ my $tries_text= &get_tries_text();
if ($showbutton) {
if ($target eq 'tex') {
if ($env{'request.state'} ne "construct"
&& $Apache::lonhomework::type ne 'exam'
&& $env{'form.suppress_tries'} ne 'yes') {
- $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.
- $tries.'/'.$maxtries.'} \vskip 2 mm ';
+ $trystr ='{\vskip 1 mm \small '
+ .&mt('[_1]'.$tries_text.'[_2] [_3]'
+ ,'\textit{','}',$tries.'/'.$maxtries )
+ .'} \vskip 2 mm';
} else {
$trystr = '\vskip 0 mm ';
}
} else {
- $trystr = ''.&mt($tries_text)." $tries";
+ my $trial =$tries;
if ($Apache::lonhomework::parsing_a_task) {
} elsif($env{'request.state'} ne 'construct') {
- $trystr.="/$maxtries";
+ $trial.="/".&Apache::lonhtmlcommon::direct_parm_link($maxtries,$env{'request.symb'},'maxtries',$id,$target);
} else {
if (defined($Apache::inputtags::params{'maxtries'})) {
- $trystr.="/".$Apache::inputtags::params{'maxtries'};
+ $trial.="/".$Apache::inputtags::params{'maxtries'};
}
}
- $trystr.=" | ";
+ $trystr = ''.&mt($tries_text.' [_1]',$trial).' | ';
}
}
@@ -1519,11 +1592,21 @@ sub previous_tries {
) {
my $txt_correct = &mt('Correct');
+ my $awarded = $Apache::lonhomework::history{"$prefix.awarded"};
+ if ($awarded < 1 && $awarded > 0) {
+ $txt_correct=&mt('Partially Correct');
+ } elsif ($awarded < 1) {
+ if ($awarded eq '') {
+ $txt_correct='';
+ } else {
+ $txt_correct=&mt('Incorrect');
+ }
+ }
$message =~ s{()(.*?)()}
{$1 $txt_correct. $3}s;
}
my $trystr = "(".&mt('Try [_1]',$Apache::lonhomework::history{"$prefix.tries"}).")";
- if ($curr_rndseed || $lastrndseed) {
+ if (($curr_rndseed || $lastrndseed) && ($i > 1)) {
if ($curr_rndseed ne $lastrndseed) {
$trystr .= '
'.&mt('New problem variation this try.').'';
}
@@ -1564,12 +1647,12 @@ sub previous_tries {
''.''.&mt('Submission #').' | '.&mt('Try').
' | '.
&mt('Submitted Answer').' | ';
- $output ='';
+ $output =&Apache::loncommon::start_scrollbox('420px','400px','400px').
+ ''.
+ &Apache::loncommon::end_scrollbox();
#return $output;
$output = &Apache::loncommon::js_ready($output);
- $output.='
';
- my $windowopen=&Apache::lonhtmlcommon::javascript_docopen();
my $tries_text = &get_tries_text('link');
my $start_page =
&Apache::loncommon::start_page($tries_text, undef,
@@ -1583,13 +1666,8 @@ sub previous_tries {
$prefix =~ tr{.}{_};
my $function_name = "LONCAPA_previous_tries_".$prefix.
$Apache::lonxml::curdepth.'_'.$env{'form.counter'};
- my $result ="".&mt($tries_text)."
";
- #use Data::Dumper;
- #&Apache::lonnet::logthis(&Dumper(\%Apache::inputtags::submission_display));
+ my $result = &Apache::loncommon::modal_adhoc_script($function_name,420,410,$start_page.$output.$end_page).
+ "".&mt($tries_text)."
";
return $result;
}