--- loncom/homework/grades.pm 2012/08/09 23:25:48 1.596.2.13 +++ loncom/homework/grades.pm 2010/03/11 16:29:42 1.597 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.596.2.13 2012/08/09 23:25:48 raeburn Exp $ +# $Id: grades.pm,v 1.597 2010/03/11 16:29:42 wenzelju Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,10 +40,9 @@ use Apache::lonhomework; use Apache::lonpickcode; use Apache::loncoursedata; use Apache::lonmsg(); -use Apache::Constants qw(:common :http); +use Apache::Constants qw(:common); use Apache::lonlocal; use Apache::lonenc; -use Apache::bridgetask(); use String::Similarity; use LONCAPA; @@ -52,7 +51,6 @@ use POSIX qw(floor); my %perm=(); -my %old_essays=(); # These variables are used to recover from ssi errors @@ -129,7 +127,7 @@ sub get_symb { my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url))); if ($symb eq '') { if (!$silent) { - $request->print(&mt("Unable to handle ambiguous references: [_1].",$url)); + $request->print("Unable to handle ambiguous references:$url:."); return (); } } @@ -261,7 +259,6 @@ sub showResourceInfo { sub reset_caches { &reset_analyze_cache(); &reset_perm(); - &reset_old_essays(); } { @@ -274,13 +271,8 @@ sub reset_caches { } sub get_analyze { - my ($symb,$uname,$udom,$no_increment,$add_to_hash,$type,$trial,$rndseed)=@_; + my ($symb,$uname,$udom,$no_increment,$add_to_hash)=@_; my $key = "$symb\0$uname\0$udom"; - if ($type eq 'randomizetry') { - if ($trial ne '') { - $key .= "\0".$trial; - } - } if (exists($analyze_cache{$key})) { my $getupdate = 0; if (ref($add_to_hash) eq 'HASH') { @@ -308,15 +300,9 @@ sub reset_caches { 'grade_courseid' => $env{'request.course.id'}, 'grade_username' => $uname, 'grade_noincrement' => $no_increment); - if ($type eq 'randomizetry') { - $form{'grade_questiontype'} = $type; - if ($rndseed ne '') { - $form{'grade_rndseed'} = $rndseed; - } - } if (ref($add_to_hash)) { %form = (%form,%{$add_to_hash}); - } + } my $subresult=&ssi_with_retries($url, $ssi_retries,%form); (undef,$subresult)=split(/_HASH_REF__/,$subresult,2); my %analyze=&Apache::lonnet::str2hash($subresult); @@ -329,15 +315,15 @@ sub reset_caches { } sub get_order { - my ($partid,$respid,$symb,$uname,$udom,$no_increment,$type,$trial,$rndseed)=@_; - my $analyze = &get_analyze($symb,$uname,$udom,$no_increment,undef,$type,$trial,$rndseed); + my ($partid,$respid,$symb,$uname,$udom,$no_increment)=@_; + my $analyze = &get_analyze($symb,$uname,$udom,$no_increment); return $analyze->{"$partid.$respid.shown"}; } sub get_radiobutton_correct_foil { - my ($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed)=@_; - my $analyze = &get_analyze($symb,$uname,$udom,undef,undef,$type,$trial,$rndseed); - my $foils = &get_order($partid,$respid,$symb,$uname,$udom,undef,$type,$trial,$rndseed); + my ($partid,$respid,$symb,$uname,$udom)=@_; + my $analyze = &get_analyze($symb,$uname,$udom); + my $foils = &get_order($partid,$respid,$symb,$uname,$udom); if (ref($foils) eq 'ARRAY') { foreach my $foil (@{$foils}) { if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') { @@ -379,7 +365,7 @@ sub reset_caches { # response types only. sub cleanRecord { my ($answer,$response,$symb,$partid,$respid,$record,$order,$version, - $uname,$udom,$type,$trial,$rndseed) = @_; + $uname,$udom) = @_; my $grayFont = ''; if ($response =~ /^(option|rank)$/) { my %answer=&Apache::lonnet::str2hash($answer); @@ -396,7 +382,7 @@ sub cleanRecord { return '
'. ''.$toprow.''. ''. - $bottomrow.'
'.&mt('Answer').'
'.$grayFont.&mt('Option ID').'
'; + $grayFont.$bottomrow.''.''; } elsif ($response eq 'match') { my %answer=&Apache::lonnet::str2hash($answer); my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"}); @@ -418,12 +404,12 @@ sub cleanRecord { ''.$grayFont.&mt('Item ID').'
'. $middlerow.''. ''.$grayFont.&mt('Option ID').''. - $bottomrow.''; + $bottomrow.''.''; } elsif ($response eq 'radiobutton') { my %answer=&Apache::lonnet::str2hash($answer); my ($toprow,$bottomrow); my $correct = - &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed); + &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom); foreach my $foil (@$order) { if (exists($answer{$foil})) { if ($foil eq $correct) { @@ -439,7 +425,7 @@ sub cleanRecord { return '
'. ''.$toprow.''. ''. - $bottomrow.'
'.&mt('Answer').'
'.$grayFont.&mt('Option ID').'
'; + $bottomrow.''.''; } elsif ($response eq 'essay') { if (! exists ($env{'form.'.$symb})) { my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade', @@ -501,8 +487,7 @@ sub cleanRecord { #-- A couple of common js functions sub commonJSfunctions { my $request = shift; - $request->print(< + $request->print(&Apache::lonhtmlcommon::scripttag(< 1) { @@ -530,7 +515,6 @@ sub commonJSfunctions { return selectOne.value; } } - COMMONJSFUNCTIONS } @@ -685,13 +669,13 @@ sub student_gradeStatus { sub jscriptNform { my ($symb) = @_; my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status')); - my $jscript=''."\n"; + "\n"); $jscript.= '
'."\n". ''."\n". ''."\n". @@ -740,11 +724,7 @@ sub compute_points { # sub most_similar { - my ($uname,$udom,$symb,$uessay)=@_; - - unless ($symb) { return ''; } - - unless (ref($old_essays{$symb}) eq 'HASH') { return ''; } + my ($uname,$udom,$uessay,$old_essays)=@_; # ignore spaces and punctuation @@ -752,7 +732,7 @@ sub most_similar { # ignore empty submissions (occuring when only files are sent) - unless ($uessay=~/\w+/s) { return ''; } + unless ($uessay=~/\w+/) { return ''; } # these will be returned. Do not care if not at least 50 percent similar my $limit=0.6; @@ -761,11 +741,11 @@ sub most_similar { my $scrsid=''; my $sessay=''; # go through all essays ... - foreach my $tkey (keys(%{$old_essays{$symb}})) { + foreach my $tkey (keys(%$old_essays)) { my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey)); # ... except the same student next if (($tname eq $uname) && ($tdom eq $udom)); - my $tessay=$old_essays{$symb}{$tkey}; + my $tessay=$old_essays->{$tkey}; $tessay=~s/\W+/ /gs; # String similarity gives up if not even limit my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit); @@ -775,7 +755,7 @@ sub most_similar { $sname=$tname; $sdom=$tdom; $scrsid=$tcrsid; - $sessay=$old_essays{$symb}{$tkey}; + $sessay=$old_essays->{$tkey}; } } if ($limit>0.6) { @@ -904,8 +884,7 @@ sub listStudents { 'multiple' => 'Please select a student or group of students before clicking on the Next button.', 'single' => 'Please select the student before clicking on the Next button.', ); - $request->print(< + $request->print(&Apache::lonhtmlcommon::scripttag(< LISTJAVASCRIPT &commonJSfunctions($request); @@ -1170,7 +1148,7 @@ LISTJAVASCRIPT sub check_script { my ($form, $type)=@_; - my $chkallscript=''."\n"; +'."\n"); return $chkallscript; } @@ -1240,8 +1218,7 @@ sub processGroup { sub sub_page_js { my $request = shift; my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = '); - $request->print(< + $request->print(&Apache::lonhtmlcommon::scripttag(< SUBJAVASCRIPT } @@ -1419,8 +1395,7 @@ sub sub_page_kw_js { my $iconpath = $request->dir_config('lonIconsURL'); &commonJSfunctions($request); - my $inner_js_msg_central=< + my $inner_js_msg_central= &Apache::lonhtmlcommon::scripttag(< INNERJS - my $inner_js_highlight_central=< + my $inner_js_highlight_central= &Apache::lonhtmlcommon::scripttag(< INNERJS my $start_page_msg_central = @@ -1495,29 +1467,12 @@ INNERJS my $docopen=&Apache::lonhtmlcommon::javascript_docopen(); $docopen=~s/^document\.//; - my %lt = &Apache::lonlocal::texthash( - keyw => 'Keywords list, separated by a space. Add/delete to list if desired.', - plse => 'Please select a word or group of words from document and then click this link.', - adds => 'Add selection to keyword list? Edit if desired.', - comp => 'Compose Message for: ', - incl => 'Include', - type => 'Type', - subj => 'Subject', - mesa => 'Message', - new => 'New', - save => 'Save', - canc => 'Cancel', - kehi => 'Keyword Highlight Options', - txtc => 'Text Color', - font => 'Font Size', - fnst => 'Font Style', - ); - $request->print(< + my $alertmsg = &mt('Please select a word or group of words from document and then click this link.'); + $request->print(&Apache::lonhtmlcommon::scripttag(<"); pDoc.write(""); - pDoc.write("

 $lt{'comp'}\"+fullname+\"<\\/span><\\/h3>

"); + pDoc.write("

 Compose Message for \"+fullname+\"<\\/span><\\/h3>

"); pDoc.write('
'); pDoc.write(''); - pDoc.write(""); - pDoc.write(""); - pDoc.write("
$lt{'type'}<\\/b><\\/td>$lt{'incl'}<\\/b><\\/td>$lt{'mesa'}<\\/td><\\/tr>"); + pDoc.write("Type<\\/b><\\/td>Include<\\/b><\\/td>Message<\\/td><\\/tr>"); } function displaySubject(msg,shwsel) { pDoc = pWin.document; pDoc.write("
$lt{'subj'}<\\/td>"); + pDoc.write("Subject<\\/td>"); pDoc.write("<\\/td>"); pDoc.write("<\\/td><\\/tr>"); } @@ -1654,7 +1609,7 @@ INNERJS function newMsg(newmsg,shwsel) { pDoc = pWin.document; pDoc.write("
$lt{'new'}<\\/td>"); + pDoc.write("New<\\/td>"); pDoc.write("<\\/td>"); pDoc.write("