--- loncom/homework/inputtags.pm 2008/01/14 14:32:14 1.236 +++ loncom/homework/inputtags.pm 2009/09/14 17:03:42 1.248.4.2 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # input definitons # -# $Id: inputtags.pm,v 1.236 2008/01/14 14:32:14 raeburn Exp $ +# $Id: inputtags.pm,v 1.248.4.2 2009/09/14 17:03:42 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -306,7 +306,9 @@ sub start_textline { $oldresponse = $oldresponse->[$#Apache::inputtags::inputlist]; } $oldresponse = &HTML::Entities::encode($oldresponse,'<>&"'); - + $oldresponse =~ s/^\s+//; + $oldresponse =~ s/\s+$//; + $oldresponse =~ s/\s+/ /g; if ($Apache::lonhomework::type ne 'exam') { my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval); $result=''; @@ -356,8 +358,15 @@ sub start_textline { && $Apache::lonhomework::type ne 'exam') { my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval); if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';} - $result='\framebox['.$size.'][s]{\tiny\strut}'; - + if ($env{'form.pdfFormFields'} eq 'yes') { + my $fieldname = $env{'request.symb'}. + '&part_'. $Apache::inputtags::part. + '&textresponse'. + '&HWVAL_' . $Apache::inputtags::response['-1']; + $result="\n\\\\\n".'\textField{'.$fieldname.'}{'.$size.'}{12 bp}'; + } else { + $result='\framebox['.$size.'][s]{\tiny\strut}'; + } } elsif ($target eq 'tex' && $Apache::lonhomework::type eq 'exam' && &needs_exam_box($tagstack)) { @@ -418,13 +427,14 @@ sub end_hiddenline { # $part -> partid # $id -> responseid # $uploadefiletypes -> comma seperated list of extensions allowed or * for any -# $which -> 'uploadedonly' -> only newly uploaded files +# $which -> 'uploadonly' -> only newly uploaded files # 'portfolioonly' -> only allow files from portfolio # 'both' -> allow files from either location # $extratext -> additional text to go between the link and the input box +# $maxfilesize -> maximum cumulative filesize for submitted files (in MB). # returns a table row sub file_selector { - my ($part,$id,$uploadedfiletypes,$which,$extratext)=@_; + my ($part,$id,$uploadedfiletypes,$which,$extratext,$maxfilesize)=@_; if (!$uploadedfiletypes) { return ''; } my $jspart=$part; @@ -433,9 +443,16 @@ sub file_selector { my $result; $result.=''; - if ($uploadedfiletypes ne '*') { - $result.= - &mt('Allowed filetypes: [_1]',$uploadedfiletypes).'
'; + if (($uploadedfiletypes ne '*') || ($maxfilesize)) { + if ($uploadedfiletypes ne '*') { + $result.= + &mt('Allowed filetypes: [_1]',''.$uploadedfiletypes.'').'
'; + } + if ($maxfilesize) { + $result.=&mt('Combined size of files not to exceed: [_1] MB[_2].', + ''.$maxfilesize.'').'
'; + } + $result .= '
'; } if ($which eq 'uploadonly' || $which eq 'both') { $result.=&mt('Submit a file: (only one file can be uploaded)'). @@ -452,7 +469,6 @@ sub file_selector { ''. '
'; $result .= &show_past_portfile_submission($part,$id); - } $result.=''; return $result; @@ -514,9 +530,10 @@ sub valid_award { 'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT', 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', - 'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT', + 'BAD_FORMULA', 'INTERNAL_ERROR', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK', 'INVALID_FILETYPE', - 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE', + 'EXCESS_FILESIZE', 'DRAFT', + 'SUBMITTED', 'ASSIGNED_SCORE', 'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') { if ($award eq $possibleaward) { return 1; } } @@ -528,10 +545,10 @@ sub valid_award { 'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT', - 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA', + 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA', 'INTERNAL_ERROR', 'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK', - 'INVALID_FILETYPE', 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE', - 'APPROX_ANS', 'EXACT_ANS'); + 'INVALID_FILETYPE', 'EXCESS_FILESIZE', 'DRAFT', 'SUBMITTED', + 'ASSIGNED_SCORE', 'APPROX_ANS', 'EXACT_ANS'); my $i=0; my %fwd_awards = map { ($_,$i++) } @awards; my $max=scalar(@awards); @@ -576,6 +593,9 @@ sub finalizeawards { return ('NO_RESPONSE'); } } + + if ($Apache::lonxml::internal_error) { $result='INTERNAL_ERROR'; } + if (!$final_scantron && defined($result)) { return ($result); } # if in scantron mode, if the award for any response is @@ -672,7 +692,8 @@ sub decideoutput { if (($symb ne '') && ($env{'course.'.$env{'request.course.id'}. - '.disable_receipt_display'} ne 'yes')) { + '.disable_receipt_display'} ne 'yes') && + ($Apache::lonhomework::type ne 'practice')) { $message.=(($target eq 'web')?'
':' '). &mt('Your receipt is [_1]', (&Apache::lonnet::receipt($Apache::inputtags::part). @@ -727,10 +748,13 @@ sub decideoutput { $button = 1; } elsif ($award eq 'MISSING_ANSWER') { $message = &mt('Some items were not submitted.'); + if ($target ne 'tex') { + $message .= &Apache::loncommon::help_open_topic('Some_Items_Were_Not_Submitted'); + } $css_class=$possible_class{'not_charged_try'}; $button = 1; } elsif ($award eq 'ERROR') { - $message = &mt('An error occured while grading your answer.'); + $message = &mt('An error occurred while grading your answer.'); $css_class=$possible_class{'not_charged_try'}; $button = 1; } elsif ($award eq 'TOO_LONG') { @@ -742,12 +766,16 @@ sub decideoutput { $css_class=$possible_class{'not_charged_try'}; $button=1; } elsif ($award eq 'MISORDERED_RANK') { - $message = &mt('You have provided an invalid ranking'); - if ($target ne 'tex') { - $message.=', '.&mt('please refer to').' '.&Apache::loncommon::help_open_topic('Ranking_Problems','help on ranking problems'); - } + $message = &mt('You have provided an invalid ranking.'); + if ($target ne 'tex') { + $message.=' '.&mt('Please refer to [_1]',&Apache::loncommon::help_open_topic('Ranking_Problems',&mt('help on ranking problems'))); + } $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.'); + $css_class=$possible_class{'not_charged_try'}; + $button=1; } elsif ($award eq 'INVALID_FILETYPE') { $message = &mt('Submission won\'t be graded. The type of file submitted is not allowed.'); $css_class=$possible_class{'not_charged_try'}; @@ -787,15 +815,25 @@ sub decideoutput { $css_class=$possible_class{'not_charged_try'}; $button=1; } elsif ($award eq 'BAD_FORMULA') { - $message = &mt("Unable to understand formula"); + $message = &mt("Unable to understand formula").'.'; + if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Formula_Answers')}; $css_class=$possible_class{'not_charged_try'}; $button=1; + } elsif ($award eq 'INTERNAL_ERROR') { + $message = &mt("An internal error occurred while processing your answer. Please try again later."); + $css_class=$possible_class{'not_charged_try'}; + $button=1; } elsif ($award eq 'INCORRECT') { $message = &mt("Incorrect").'.'; $css_class=$possible_class{'charged_try'}; $button=1; } elsif ($award eq 'SUBMITTED') { $message = &mt("Your submission has been recorded."); + if ($env{'request.uri'} eq '/res/gci/gci/internal/submission.problem') { + if ($target eq 'web') { + $message .= '
'.&mt('Thank you for making a submission to the Geosciences Concept Inventory via the GCI Web Center.'); + } + } $css_class=$possible_class{'no_grade'}; $button=1; } elsif ($award eq 'DRAFT') { @@ -821,21 +859,41 @@ sub decideoutput { my (undef,undef,$domain,$user)=&Apache::lonnet::whichuser(); foreach my $resid(@Apache::inputtags::response){ if ($Apache::lonhomework::history{"resource.$part.$resid.handback"}) { - $message.='
'; + if ($target eq 'tex') { + $message.= "\\\\\n"; + } else { + $message.='
'; + } my @files = split(/\s*,\s*/, $Apache::lonhomework::history{"resource.$part.$resid.handback"}); my $file_msg; foreach my $file (@files) { - $file_msg.= '
'.$file.''; + if ($target eq 'tex') { + $file_msg.= "\\\\\n".$file; + } else { + $file_msg.= '
'.$file.''; + } } $message .= &mt('Returned file(s): [_1]',$file_msg); + if ($target eq 'tex') { + $message.= "\\\\\n"; + } else { + $message.='
'; + } } } if (&Apache::lonhomework::hide_problem_status() && $Apache::inputtags::status[-1] ne 'SHOW_ANSWER' && &hide_award($award)) { - $message = &mt("Answer Submitted: Your final submission will be graded after the due date."); + if ($env{'request.uri'} eq '/res/gci/gci/internal/submission.problem') { + if ($target eq 'web') { + $message = &mt("Your submission has been recorded.").'
'. + &mt('Thank you for making a submission to the Geosciences Concept Inventory via the GCI Web Center.'); + } + } else { + $message = &mt("Answer Submitted: Your final submission will be graded after the due date."); + } $css_class=$possible_class{'no_grade'}; $button=1; } @@ -844,6 +902,15 @@ sub decideoutput { $message.= $computer; $added_computer_text=1; } + if ($Apache::lonhomework::type eq 'practice') { + if ($target eq 'web') { + $message .= '
'; + } else { + $message .= ' '; + } + $message.=&mt('Submissions to practice problems are not permanently recorded.'); + } + return ($button,$css_class,$message,$previousmsg); } @@ -1073,7 +1140,7 @@ sub grade { my ($match) = &previous_match(\@Apache::inputtags::previous_version, scalar(@Apache::inputtags::response)); - + if ($match) { $previously_used = 'PREVIOUSLY_LAST'; foreach my $value (@Apache::inputtags::previous) { @@ -1141,16 +1208,20 @@ sub get_grade_messages { $trystr = '\vskip 0 mm '; } } else { - $trystr = "".$tries_text." $tries"; - if ($Apache::lonhomework::parsing_a_task) { - } elsif($env{'request.state'} ne 'construct') { - $trystr.="/$maxtries"; - } else { - if (defined($Apache::inputtags::params{'maxtries'})) { - $trystr.="/".$Apache::inputtags::params{'maxtries'}; - } - } - $trystr.=""; + $trystr = ''; + my %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'}); + if ($parmhash{'suppress_tries'} ne 'yes') { + $trystr .= "$tries_text $tries"; + if ($Apache::lonhomework::parsing_a_task) { + } elsif($env{'request.state'} ne 'construct') { + $trystr.="/$maxtries"; + } else { + if (defined($Apache::inputtags::params{'maxtries'})) { + $trystr.="/".$Apache::inputtags::params{'maxtries'}; + } + } + } + $trystr.=""; } } @@ -1190,14 +1261,18 @@ sub gradestatus { if ( $status eq 'SHOW_ANSWER') { undef($previousmsg); } - if ( $showbutton ) { - if ($target ne 'tex') { + if ( $showbutton ) { + if ($target ne 'tex') { + my $submit_text = &mt('Submit Answer'); + if ($env{'request.uri'} eq '/res/gci/gci/internal/submission.problem') { + $submit_text = &mt('Submit Questions'); + } $button = ''; + value="'.$submit_text.'" />'; } } @@ -1251,11 +1326,11 @@ sub previous_tries { && $Apache::lonhomework::history{"$prefix.solved"} =~/^correct/ ) { + my $txt_correct = &mt('Correct'); $message =~ s{()(.*?)()} - {$1 Correct. $3}s; + {$1 $txt_correct. $3}s; } - my $trystr = "(Try ". - $Apache::lonhomework::history{"$prefix.tries"}.')'; + my $trystr = "(".&mt('Try [_1]',$Apache::lonhomework::history{"$prefix.tries"}).")"; $message =~ s{()}{ $trystr $1}; } my ($class) = ($message =~ m{ // -".&mt("Previous Tries")."
"; +".$triestext."
"; #use Data::Dumper; #&Apache::lonnet::logthis(&Dumper(\%Apache::inputtags::submission_display)); return $result;