--- loncom/homework/inputtags.pm 2011/10/10 17:47:58 1.271.2.9 +++ loncom/homework/inputtags.pm 2013/04/11 14:59:40 1.315 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # input definitons # -# $Id: inputtags.pm,v 1.271.2.9 2011/10/10 17:47:58 raeburn Exp $ +# $Id: inputtags.pm,v 1.315 2013/04/11 14:59:40 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -125,6 +125,37 @@ sub initialize_inputtags { %Apache::inputtags::submission_display=(); } +# +# provides the onblur binding for spellchecking. This could be an +# empty string if spellchecking was not enabled. +# Jquery selector binding is done rather than setting an onblur +# attribute because we'll need to set the element's spellcheck language +# option dynamically so we need $(this) to be defined. +# +# @param id - The element id to bind. +# @param lang - Language in which spellchecking is desired. +# if undef, nothing is generated. +# @return string - onblur specification to do the requested spellchecking. +# +sub spellcheck_onblur { + my ($id, $lang) = @_; + my $result = ''; + if ($lang) { + + $result = < +\$('\#$id').blur(function() { + doSpellcheck('\#$id', '$lang'); + }); + + +JAVASCRIPT + + + } + return $result; +} + sub check_for_duplicate_ids { my %check; foreach my $id (@Apache::inputtags::partlist, @@ -185,7 +216,7 @@ sub start_textfield { } } unless ($newvariation) { - $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"},'<>&"'); + $oldresponse = $Apache::lonhomework::history{"resource.$partid.$resid.submission"}; } if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { my $cols = &Apache::lonxml::get_param('cols',$parstack,$safeeval); @@ -194,13 +225,15 @@ sub start_textfield { if ( $rows eq '') { $rows = 16; } my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval); $result=''; + my $tagident = 'HWVAL_' . $resid; if ($addchars) { - $result.=&addchars('HWVAL_'.$resid,$addchars); + $result.=&addchars($tagident, $addchars); } - my $textareaclass = 'class="LC_richDetectHtml"'; - $result.= '"; + my $resid = $Apache::inputtags::response[-1]; + my $tagident = 'HWVAL_' . $resid; + my $result = ""; + $result .= &spellcheck_onblur($tagident, $spellcheck); + return $result; } } elsif ($target eq 'edit') { $result=&Apache::edit::end_table(); @@ -330,6 +379,12 @@ sub start_textline { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result = ""; my $input_id = &start_input($parstack,$safeeval); + + # The spellcheck attribute + # 1. enables spellchecking. + # 2. Provides the language code in which the spellchecking will be performed. + + my $spellcheck = &Apache::lonxml::get_param('spellcheck', $parstack, $safeeval); if ($target eq 'web') { $Apache::lonxml::evaluate--; my $partid=$Apache::inputtags::part; @@ -354,7 +409,6 @@ sub start_textline { unless ($newvariation) { $oldresponse = $Apache::lonhomework::history{"resource.$partid.$id.submission"}; &Apache::lonxml::debug("oldresponse $oldresponse is ".ref($oldresponse)); - if (ref($oldresponse) eq 'ARRAY') { $oldresponse = $oldresponse->[$#Apache::inputtags::inputlist]; } @@ -381,8 +435,15 @@ sub start_textline { if ($Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') { $name = "none"; } - $result.= ''; + $result.= ''; + + $result .= &spellcheck_onblur($name, $spellcheck); } if ($Apache::lonhomework::type eq 'exam' && &needs_exam_box($tagstack)) { @@ -401,12 +462,15 @@ sub start_textline { 'addchars',$token,10); $result.=&Apache::edit::select_arg('Readonly:','readonly', ['no','yes'],$token); + my $spell_langs = &spelling_languages(); + $result.=&Apache::edit::select_arg("Spellcheck for: ", 'spellcheck', + $spell_langs, $token); $result.=&Apache::edit::end_row(); $result.=&Apache::edit::end_table(); } elsif ($target eq 'modified') { my $constructtag=&Apache::edit::get_new_args($token,$parstack, $safeeval,'size', - 'addchars','readonly'); + 'addchars','readonly', 'spellcheck'); if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } } elsif ($target eq 'tex' && $Apache::lonhomework::type ne 'exam') { @@ -479,6 +543,7 @@ sub end_hiddenline { return ""; } + sub start_hiddensubmission { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result = ""; @@ -571,13 +636,25 @@ 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:').'
'; } - if ($which eq 'portfolioonly' || $which eq 'both') { - $result.=$extratext.''. + if ($which eq 'portfolioonly' || $which eq 'both') { + my $symb = $env{'request.symb'}; + (undef,undef,my $res)=&Apache::lonnet::decode_symb($symb); + my $showsymb; + # If resource is a .task and URL is unencrypted, include symb in query string + # for url opened in portfolio file selection window. Can be used to override + # blocking of portfolio access resulting from an exam event in a different course. + if ($res =~ /\.task$/i) { + my $encsymb = &Apache::lonenc::check_encrypt($symb); + if ($symb eq $encsymb) { + $showsymb = $symb; + } + } + $result.=$extratext.''. &mt('Select Portfolio Files: (one or more files per submission)').'
'. ''. '
'; @@ -676,9 +753,11 @@ sub current_file_submissions { } } if ($header_shown) { - $result .= &Apache::loncommon::end_data_table(). - '
'. - &mt('Exclude existing file(s) from grading by checking the "Delete?" checkbox(es) and clicking "Submit Answer"').''; + $result .= &Apache::loncommon::end_data_table(); + if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { + $result .= '
'. + &mt('Exclude existing file(s) from grading by checking the "Delete?" checkbox(es) and clicking "Submit Answer"').''; + } } if (@bad_file_list) { my $bad_files = ''. @@ -728,7 +807,7 @@ sub valid_award { 'UNIT_FAIL', 'NO_UNIT', 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA', 'NOT_FUNCTION', 'WRONG_FORMAT', - 'INTERNAL_ERROR', 'SIG_FAIL', 'INCORRECT', + 'INTERNAL_ERROR', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK', 'INVALID_FILETYPE', 'EXCESS_FILESIZE', 'FILENAME_INUSE', 'DRAFT', 'SUBMITTED', 'SUBMITTED_CREDIT', @@ -746,7 +825,7 @@ sub valid_award { 'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT', 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA', 'NOT_FUNCTION', - 'WRONG_FORMAT', 'INTERNAL_ERROR', + 'WRONG_FORMAT', 'INTERNAL_ERROR', 'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK', 'INVALID_FILETYPE', 'EXCESS_FILESIZE', 'FILENAME_INUSE', 'DRAFT', 'SUBMITTED', @@ -862,13 +941,13 @@ 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 || $nocorrect)? '' : " ".&mt("Computer's answer now shown above."); &Apache::lonxml::debug("handgrade has :$handgrade:"); @@ -886,7 +965,7 @@ sub decideoutput { $css_class=$possible_class{'charged_try'}; } if ($handgrade || - ($env{'request.filename'}=~ m{/res/lib/templates/(examupload|DropBox)\.problem$})) { + ($env{'request.filename'}=~/\/res\/lib\/templates\/(examupload|DropBox).problem$/)) { $message = &mt("A score has been assigned."); $added_computer_text=1; } else { @@ -911,7 +990,13 @@ sub decideoutput { } } } - $button=0; + if ($awarded >= 1) { + $button=0; + } elsif (&Apache::lonnet::EXT("resource.$part.retrypartial") !~/^1|on|yes$/i) { + $button=0; + } else { + $button=1; + } $previousmsg=''; } elsif ($solved =~ /^excused/) { if ($target eq 'tex') { @@ -993,7 +1078,7 @@ sub decideoutput { } else { $message .= '
'; } - $message .= &mt('Please use a different file name.'); + $message .= &mt('Please use a different filename.'); $css_class=$possible_class{'not_charged_try'}; $button=1; } elsif ($award eq 'INVALID_FILETYPE') { @@ -1047,7 +1132,7 @@ sub decideoutput { $message = &mt("Wrong format").'.'; $css_class=$possible_class{'not_charged_try'}; $button=1; - } elsif ($award eq 'INTERNAL_ERROR') { + } 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; @@ -1070,6 +1155,7 @@ sub decideoutput { } elsif ($award eq 'ANONYMOUS_CREDIT') { $message = &mt("Your anonymous submission has been recorded, and credit awarded."); $css_class=$possible_class{'correct'}; + $button=1; } elsif ($award eq 'DRAFT') { $message = &mt("Copy saved but not submitted."); $css_class=$possible_class{'not_charged_try'}; @@ -1120,7 +1206,17 @@ sub decideoutput { 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."); + $message = &mt("Answer Submitted: Your final submission will be graded after the due date."); + my @interval= &Apache::lonnet::EXT("resource.$part.interval"); + if ($interval[0] =~ /\d+/) { + my $first_access=&Apache::lonnet::get_first_access($interval[1]); + if (defined($first_access)) { + my $due_date= &Apache::lonnet::EXT("resource.$part.duedate"); + unless (($due_date) && ($due_date < $first_access + $interval[0])) { + $message = &mt("Answer Submitted: Your final submission will be graded when the time limit is reached."); + } + } + } $css_class=$possible_class{'no_grade'}; $button=1; } @@ -1137,7 +1233,6 @@ sub decideoutput { } $message.=&mt('Submissions to practice problems are not permanently recorded.'); } - return ($button,$css_class,$message,$previousmsg); } @@ -1190,8 +1285,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, @@ -1312,8 +1406,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 @@ -1323,14 +1416,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; - } - if ($Apache::lonhomework::type eq 'randomizetry') { - $Apache::lonhomework::results{"resource.$id.rndseed"} = $env{'form.'.$id.'.rndseed'}; - } + $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 { @@ -1449,24 +1538,24 @@ sub get_grade_messages { if ($env{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam' && $env{'form.suppress_tries'} ne 'yes') { - $trystr ='{\vskip 1 mm \small ' + $trystr ='{\vskip 1 mm \small ' .&mt('[_1]'.$tries_text.'[_2] [_3]' - ,'\textit{','}',$tries.'/'.$maxtries ) + ,'\textit{','}',$tries.'/'.$maxtries ) .'} \vskip 2 mm'; } else { $trystr = '\vskip 0 mm '; } } else { - my $trial = $tries; + my $trial =$tries; if ($Apache::lonhomework::parsing_a_task) { } elsif($env{'request.state'} ne 'construct') { - $trial.="/$maxtries"; + $trial.="/".&Apache::lonhtmlcommon::direct_parm_link($maxtries,$env{'request.symb'},'maxtries',$id,$target); } else { if (defined($Apache::inputtags::params{'maxtries'})) { $trial.="/".$Apache::inputtags::params{'maxtries'}; } } - $trystr.=''.&mt("$tries_text [_1]",$trial).''; + $trystr = ''.&mt($tries_text.' [_1]',$trial).''; } } @@ -1495,12 +1584,19 @@ sub gradestatus { && $status ne 'UNAVAILABLE' && $status ne 'INVALID_ACCESS' && $status ne 'NEEDS_CHECKIN' - && $status ne 'NOT_IN_A_SLOT') { + && $status ne 'NOT_IN_A_SLOT' + && $status ne 'RESERVABLE' + && $status ne 'RESERVABLE_LATER' + && $status ne 'NOTRESERVABLE') { + + if ($status eq 'SHOW_ANSWER') { + $showbutton = 0; + } ($previousmsg,$latemessage,$message,$trystr) = &get_grade_messages($id,"resource.$id",$target,$status, $showbutton); - if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') { + if ($status eq 'CANNOT_ANSWER') { $showbutton = 0; } if ( $status eq 'SHOW_ANSWER') { @@ -1556,7 +1652,6 @@ sub previous_tries { $count++; $count_lookup{$i} = $count; my $curr_rndseed = $Apache::lonhomework::history{"$prefix.rndseed"}; - my ($previousmsg,$latemessage,$message,$trystr); ($previousmsg,$latemessage,$message,$trystr) = @@ -1592,7 +1687,7 @@ sub previous_tries { if ($curr_rndseed ne $lastrndseed) { $trystr .= '
'.&mt('New problem variation this try.').''; } - } + } $message =~ s{()}{ $trystr $1}; } my ($class) = ($message =~ m{'. &mt('Submitted Answer').''; $output =''.$headers.$output.'
'; - #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, - {'only_body' => 1, - 'bgcolor' => '#FFFFFF', - 'js_ready' => 1, - 'inherit_jsmath' => 1, }); - my $end_page = - &Apache::loncommon::end_page({'js_ready' => 1,}); my $prefix = $env{'form.request.prefix'}; $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_window($function_name,420,410,$output,&mt($tries_text))."
"; return $result; } @@ -1680,6 +1757,21 @@ sub get_tries_text { return $tries_text; } +sub spelling_languages { + my %langchoices; + foreach my $id (&Apache::loncommon::languageids()) { + my $code = &Apache::loncommon::supportedlanguagecode($id); + if ($code ne '') { + $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id); + } + } + my @spelllangs = ('none'); + foreach my $code ('en','de','he','es','fr','pt','tr') { + push(@spelllangs,[$code,$langchoices{$code}]); + } + return \@spelllangs; +} + 1; __END__