--- loncom/homework/grades.pm 2004/07/16 19:50:23 1.205 +++ loncom/homework/grades.pm 2004/10/07 22:12:47 1.220 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.205 2004/07/16 19:50:23 matthew Exp $ +# $Id: grades.pm,v 1.220 2004/10/07 22:12:47 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -25,16 +25,6 @@ # # http://www.lon-capa.org/ # -# 2/9,2/13 Guy Albertelli -# 6/8 Gerd Kortemeyer -# 7/26 H.K. Ng -# 8/20 Gerd Kortemeyer -# Year 2002 -# June-August H.K. Ng -# Year 2003 -# February, March H.K. Ng -# July, H. K. Ng -# package Apache::grades; use strict; @@ -167,6 +157,20 @@ sub response_type { return \@partlist,\%handgrade,\%responseType; } +sub get_display_part { + my ($partID,$url,$symb)=@_; + if (!defined($symb) || $symb eq '') { + $symb=$ENV{'form.symb'}; + if ($symb eq '') { $symb=&Apache::lonnet::symbread($url) } + } + my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb); + if (defined($display) and $display ne '') { + $display.= " (<font color=\"#999900\">id $partID</font>)"; + } else { + $display=$partID; + } + return $display; +} #--- Show resource title #--- and parts and response type sub showResourceInfo { @@ -194,7 +198,8 @@ sub showResourceInfo { } $partsseen{$partID}=1; } - $result.='<td><b>Part </b>'.$partID.' <font color="#999999">'. + my $display_part=&get_display_part($partID,$url); + $result.='<td><b>Part: </b>'.$display_part.' <font color="#999999">'. $resID.'</font></td>'. '<td><b>Type: </b>'.$responsetype.'</td></tr>'; # '<td><b>Handgrade: </b>'.$handgrade.'</td></tr>'; @@ -691,7 +696,9 @@ LISTJAVASCRIPT '<td>'.&nameUserString('header').'</td>'; if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') { foreach (sort(@$partlist)) { - $gradeTable.='<td><b> Part '.(split(/_/))[0].' Status </b></td>'; + my $display_part=&get_display_part((split(/_/))[0],$url,$symb); + $gradeTable.='<td><b> Part: '.$display_part. + ' Status </b></td>'; } } $loop++; @@ -984,6 +991,7 @@ sub sub_page_kw_js { my $request = shift; my $iconpath = $request->dir_config('lonIconsURL'); &commonJSfunctions($request); + my $docopen=&Apache::lonhtmlcommon::javascript_docopen(); $request->print(<<SUBJAVASCRIPT); <script type="text/javascript" language="javascript"> @@ -1093,10 +1101,10 @@ sub sub_page_kw_js { var ypos = (screen.height-height)/2-30; ypos = (ypos < 0) ? '0' : ypos; - pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height); + pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height); pWin.focus(); pDoc = pWin.document; - pDoc.open('text/html','replace'); + pDoc.$docopen; pDoc.write("<html><head>"); pDoc.write("<title>Message Central</title>"); @@ -1224,10 +1232,10 @@ sub sub_page_kw_js { var ypos = (screen.height-330)/2-30; ypos = (ypos < 0) ? '0' : ypos; - hwdWin = window.open('', 'KeywordHighlightCentral', 'toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos); + hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos); hwdWin.focus(); var hDoc = hwdWin.document; - hDoc.open('text/html','replace'); + hDoc.$docopen; hDoc.write("<html><head>"); hDoc.write("<title>Highlight Central</title>"); @@ -1298,8 +1306,9 @@ sub gradeBox { '' : $$record{'resource.'.$partid.'.awarded'}*$wgt); my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n"; + my $display_part=&get_display_part($partid,undef,$symb); $result.='<table border="0"><tr><td>'. - '<b>Part </b>'.$partid.' <b>Points: </b></td><td>'."\n"; + '<b>Part: </b>'.$display_part.' <b>Points: </b></td><td>'."\n"; my $ctr = 0; $result.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across @@ -1631,11 +1640,12 @@ KEYWORDS my %seenparts; for my $part (sort keys(%$handgrade)) { my ($partid,$respid) = split(/_/,$part); + my $display_part=&get_display_part($partid,$url,$symb); if ($ENV{"form.$uname:$udom:$partid:submitted_by"}) { if (exists($seenparts{$partid})) { next; } $seenparts{$partid}=1; - my $submitby='<b>Part '.$partid. - ' Collaborative submission by: </b>'. + my $submitby='<b>Part:</b> '.$display_part. + ' <b>Collaborative submission by:</b> '. '<a href="javascript:viewSubmitter(\''. $ENV{"form.$uname:$udom:$partid:submitted_by"}. '\')"; TARGET=_self>'. @@ -1645,8 +1655,8 @@ KEYWORDS } my $responsetype = $responseType->{$partid}->{$respid}; if (!exists($record{"resource.$partid.$respid.submission"})) { - $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '. - $partid.'</b> <font color="#999999">( ID '.$respid. + $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '. + $display_part.' <font color="#999999">( ID '.$respid. ' )</font> '. '<font color="red">Nothing submitted - no attempts</font><br /><br />'; next; @@ -1674,8 +1684,9 @@ KEYWORDS if ($ENV{'form.lastSub'} eq 'lastonly' || ($ENV{'form.lastSub'} eq 'hdgrade' && $$handgrade{$part} eq 'yes')) { - $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '. - $partid.'</b> <font color="#999999">( ID '.$respid. + my $display_part=&get_display_part($partid,$url,$symb); + $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '. + $display_part.' <font color="#999999">( ID '.$respid. ' )</font> '; if ($record{"resource.$partid.$respid.uploadedurl"}) { &Apache::lonnet::allowuploaded('/adm/grades', @@ -2335,7 +2346,8 @@ sub viewgrades { $ctsparts.'" value="'.$partid.'" />'."\n"; $result.='<input type="hidden" name="weight_'. $partid.'" value="'.$weight{$partid}.'" />'."\n"; - $result.='<tr><td><b>Part '.$partid.' Point:</b> </td><td>'; + my $display_part=&get_display_part($partid,$url,$symb); + $result.='<tr><td><b>Part:</b> '.$display_part.' <b>Point:</b> </td><td>'; $result.='<table border="0"><tr>'; my $ctr = 0; while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across @@ -2374,14 +2386,17 @@ sub viewgrades { my $display=&Apache::lonnet::metadata($url,$part.'.display'); $display =~ s|^Number of Attempts|Tries<br />|; # makes the column narrower if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); } + my ($partid) = &split_part_type($part); + my $display_part=&get_display_part($partid,$url,$symb); if ($display =~ /^Partial Credit Factor/) { - my ($partid) = &split_part_type($part); - $result.='<td><b>Score Part '.$partid.'<br />(weight = '. - $weight{$partid}.')</b></td>'."\n"; + $result.='<td><b>Score Part:</b> '.$display_part. + ' <br /><b>(weight = '.$weight{$partid}.')</b></td>'."\n"; next; + } else { + $display =~s/\[Part: \Q$partid\E\]/Part:<\/b> $display_part/; } $display =~ s|Problem Status|Grade Status<br />|; - $result.='<td><b>'.$display.'</b></td>'."\n"; + $result.='<td><b>'.$display.'</td>'."\n"; } $result.='</tr>'; @@ -2511,9 +2526,10 @@ sub editgrades { } } foreach my $partid (@partid) { + my $display_part=&get_display_part($partid,$url,$symb); $result .= '<td colspan="'.$columns{$partid}. - '" align="center"><b>Part '.$partid. - '</b> (Weight = '.$weight{$partid}.')</td>'; + '" align="center"><b>Part:</b> '.$display_part. + ' (Weight = '.$weight{$partid}.')</td>'; } $result .= '</tr><tr bgcolor="#deffff">'; @@ -3054,8 +3070,6 @@ sub getSymbMap { $minder++; } } - - $navmap->untieHashes(); return \@titles,\%symbx; } @@ -3188,8 +3202,6 @@ sub displayPage { $curRes = $iterator->next(); } - $navmap->untieHashes(); - $studentTable.='</td></tr></table></td></tr></table>'."\n". '<input type="button" value="Save" '. 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" TARGET=_self />'. @@ -3222,13 +3234,14 @@ sub displaySubByDates { foreach my $partid (@{$parts}) { my @matchKey = sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys); # next if ($$record{"$version:resource.$partid.solved"} eq ''); + my $display_part=&get_display_part($partid,undef,$symb); foreach my $matchKey (@matchKey) { if (exists($$record{$version.':'.$matchKey}) && $$record{$version.':'.$matchKey} ne '') { my ($responseId)=($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/); - $displaySub[0].='<b>Part '.$partid.' '; + $displaySub[0].='<b>Part:</b> '.$display_part.' '; $displaySub[0].='<font color="#999999">(ID '. - $responseId.')</font> '; + $responseId.')</font> <b>'; if ($$record{"$version:resource.$partid.tries"} eq '') { $displaySub[0].='Trial not counted'; } else { @@ -3246,14 +3259,14 @@ sub displaySubByDates { } } if (exists $$record{"$version:resource.$partid.award"}) { - $displaySub[1].='<b>Part '.$partid.'</b> '. + $displaySub[1].='<b>Part:</b> '.$display_part.' '. lc($$record{"$version:resource.$partid.award"}).' '. $mark{$$record{"$version:resource.$partid.solved"}}. '<br />'; } if (exists $$record{"$version:resource.$partid.regrader"}) { $displaySub[2].=$$record{"$version:resource.$partid.regrader"}. - ' (<b>'.&mt('Part').':</b> '.$partid.')'; + ' (<b>'.&mt('Part').':</b> '.$display_part.')'; } } # needed because old essay regrader has not parts info @@ -3350,12 +3363,13 @@ sub updateGradeByPage { $changeflag++; $newpts = ''; } - + my $display_part=&get_display_part($partid,undef, + $curRes->symb()); my $oldstatus = $ENV{'form.solved'.$question.'_'.$partid}; - $displayPts[0].=' <b>Part</b> '.$partid.' = '. + $displayPts[0].=' <b>Part:</b> '.$display_part.' = '. (($oldstatus eq 'excused') ? 'excused' : $oldpts). ' <br>'; - $displayPts[1].=' <b>Part</b> '.$partid.' = '. + $displayPts[1].=' <b>Part:</b> '.$display_part.' = '. (($score eq 'excused') ? 'excused' : $newpts). ' <br>'; @@ -3383,8 +3397,6 @@ sub updateGradeByPage { $curRes = $iterator->next(); } - $navmap->untieHashes(); - $studentTable.='</td></tr></table></td></tr></table>'; $studentTable.=&show_grading_menu_form($ENV{'form.symb'},$ENV{'form.url'}); my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' : @@ -3445,10 +3457,11 @@ sub scantron_filenames { } sub scantron_uploads { + my ($file2grade) = @_; my $result= '<select name="scantron_selectfile">'; $result.="<option></option>"; foreach my $filename (sort(&scantron_filenames())) { - $result.="<option>$filename</option>\n"; + $result.="<option".($filename eq $file2grade ? ' selected="on"':'').">$filename</option>\n"; } $result.="</select>"; return $result; @@ -3494,13 +3507,13 @@ sub scantron_CODEunique { } sub scantron_selectphase { - my ($r) = @_; + my ($r,$file2grade) = @_; my ($symb,$url)=&get_symb_and_url($r); if (!$symb) {return '';} my $sequence_selector=&getSequenceDropDown($r,$symb); my $default_form_data=&defaultFormData($symb,$url); my $grading_menu_button=&show_grading_menu_form($symb,$url); - my $file_selector=&scantron_uploads(); + my $file_selector=&scantron_uploads($file2grade); my $format_selector=&scantron_scantab(); my $CODE_selector=&scantron_CODElist(); my $CODE_unique=&scantron_CODEunique(); @@ -3827,7 +3840,8 @@ sub scantron_find_student { sub scantron_filter { my ($curres)=@_; - if (ref($curres) && $curres->is_problem() && !$curres->randomout) { + # randomout is dysfunctional at best for this purpose + if (ref($curres) && $curres->is_problem()) { #&& !$curres->randomout) { return 1; } return 0; @@ -3979,7 +3993,7 @@ sub scantron_form_start { <input type="hidden" name="selectpage" value="$ENV{'form.selectpage'}" /> <input type="hidden" name="scantron_format" value="$ENV{'form.scantron_format'}" /> <input type="hidden" name="scantron_selectfile" value="$ENV{'form.scantron_selectfile'}" /> - <input type="hidden" name="scantron_maxbubble" value="$max_bubble'" /> + <input type="hidden" name="scantron_maxbubble" value="$max_bubble" /> <input type="hidden" name="scantron_CODElist" value="$ENV{'form.scantron_CODElist'}" /> <input type="hidden" name="scantron_CODEunique" value="$ENV{'form.scantron_CODEunique'}" /> <input type="hidden" name="scantron_options_redo" value="$ENV{'form.scantron_options_redo'}" /> @@ -4452,7 +4466,8 @@ sub scantron_validate_CODE { $line,'incorrectCODE',\%allcodes); return(1,$currentphase); } - if (exists($usedCODEs{$CODE}) && $ENV{'form.scantron_CODEunique'} + if (exists($usedCODEs{$CODE}) + && $ENV{'form.scantron_CODEunique'} eq 'yes' && !$$scan_record{'scantron.CODE_ignore_dup'}) { &scantron_get_correction($r,$i,$scan_record, \%scantron_config, @@ -4619,9 +4634,10 @@ SCANTRONFORM $form{'CODE'}=$scan_record->{'scantron.CODE'}; } my $result=&Apache::lonnet::ssi($resource->src(),%form); - + if (&Apache::loncommon::connection_aborted($r)) { last; } } $completedstudents{$uname}={'line'=>$line}; + if (&Apache::loncommon::connection_aborted($r)) { last; } } continue { &Apache::lonnet::delenv('form.counter'); &Apache::lonnet::delenv('scantron\.'); @@ -4630,7 +4646,6 @@ SCANTRONFORM # my $lasttime = &Time::HiRes::time()-$start; # $r->print("<p>took $lasttime</p>"); - $navmap->untieHashes(); $r->print("</form>"); $r->print(&show_grading_menu_form($symb,$url)); return ''; @@ -4691,7 +4706,8 @@ sub scantron_upload_scantron_data_save { } return ''; } - $r->print("Doing upload to ".$ENV{'form.courseid'}." <br />"); + my %coursedata=&Apache::lonnet::coursedescription($ENV{'form.domainid'}.'_'.$ENV{'form.courseid'}); + $r->print("Doing upload to ".$coursedata{'description'}." <br />"); my $home=&Apache::lonnet::homeserver($ENV{'form.courseid'}, $ENV{'form.domainid'}); my $fname=$ENV{'form.upfile.filename'}; @@ -4708,6 +4724,7 @@ sub scantron_upload_scantron_data_save { $fname=~s/[^\w\.\-]//g; # See if there is anything left unless ($fname) { return 'error: no uploaded file'; } + my $uploadedfile=$fname; $fname='scantron_orig_'.$fname; if (length($ENV{'form.upfile'}) < 2) { $r->print("<font color='red'>Error:</font> The file you attempted to upload, <tt>".&HTML::Entities::encode($ENV{'form.upfile.filename'},'<>&"')."</tt>, contained no information. Please check that you entered the correct filename."); @@ -4716,11 +4733,11 @@ sub scantron_upload_scantron_data_save { if ($result =~ m|^/uploaded/|) { $r->print("<font color='green'>Success:</font> Successfully uploaded ".(length($ENV{'form.upfile'})-1)." bytes of data into location <tt>".$result."</tt>"); } else { - $r->print("<font color='red'>Error:</font> An error (".$result.") occured when attempting to upload the file, <tt>".&HTML::Entities::encode($ENV{'form.upfile.filename'},'<>&"')."</tt>"); + $r->print("<font color='red'>Error:</font> An error (".$result.") occurred when attempting to upload the file, <tt>".&HTML::Entities::encode($ENV{'form.upfile.filename'},'<>&"')."</tt>"); } } if ($symb) { - $r->print(&show_grading_menu_form($symb,$url)); + $r->print(&scantron_selectphase($r,$uploadedfile)); } else { $r->print($doanotherupload); } @@ -5084,8 +5101,7 @@ sub send_header { sub send_footer { my ($request)= @_; - $request->print('</body>'); - $request->print(&Apache::lontexconvert::footer()); + $request->print('</body></html>'); } 1;