--- loncom/homework/grades.pm 2006/03/08 21:56:49 1.329
+++ loncom/homework/grades.pm 2007/01/04 14:59:57 1.386
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.329 2006/03/08 21:56:49 albertel Exp $
+# $Id: grades.pm,v 1.386 2007/01/04 14:59:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,10 +36,14 @@ use Apache::lonhtmlcommon;
use Apache::lonnavmaps;
use Apache::lonhomework;
use Apache::loncoursedata;
-use Apache::lonmsg qw(:user_normal_msg);
+use Apache::lonmsg();
use Apache::Constants qw(:common);
use Apache::lonlocal;
+use Apache::lonenc;
use String::Similarity;
+use lib '/home/httpd/lib/perl';
+use LONCAPA;
+
use POSIX qw(floor);
my %oldessays=();
@@ -109,35 +113,34 @@ sub nameUserString {
#--- Indicate if a response type is coded handgraded or not. ---
sub response_type {
my ($symb) = shift;
- my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
- my $allkeys = &Apache::lonnet::metadata($url,'keys');
- my %vPart;
- foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
- $vPart{$partid}=1;
- }
- my %seen = ();
- my (@partlist,%handgrade,%responseType);
- foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
- if (/^\w+response_.*/) {
- my ($responsetype,$part) = split(/_/,$_,2);
- my ($partid,$respid) = split(/_/,$part);
- if (&Apache::loncommon::check_if_partid_hidden($partid,$symb)) {
- next;
- }
- if (%vPart && !exists($vPart{$partid})) {
- next;
- }
- $responsetype =~ s/response$//; # make it compatible w/ navmaps - should move to that!!
- my ($value) = &Apache::lonnet::EXT('resource.'.$part.'.handgrade',$symb);
- $handgrade{$part} = ($value eq 'yes' ? 'yes' : 'no');
- if (!exists($responseType{$partid})) { $responseType{$partid}={}; }
- $responseType{$partid}->{$respid}=$responsetype;
- next if ($seen{$partid} > 0);
- $seen{$partid}++;
- push @partlist,$partid;
- }
- }
- return (\@partlist,\%handgrade,\%responseType);
+
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ my $res = $navmap->getBySymb($symb);
+ my $partlist = $res->parts();
+ my (%response_types,%handgrade);
+ foreach my $part (@{ $partlist }) {
+ my @types = $res->responseType($part);
+ my @ids = $res->responseIds($part);
+ for (my $i=0; $i < scalar(@ids); $i++) {
+ $response_types{$part}{$ids[$i]} = $types[$i];
+ $handgrade{$part.'_'.$ids[$i]} =
+ &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
+ '.handgrade',$symb);
+ }
+ }
+ return ($partlist,\%handgrade,\%response_types);
+}
+
+sub flatten_responseType {
+ my ($responseType) = @_;
+ my @part_response_id =
+ map {
+ my $part = $_;
+ map {
+ [$part,$_]
+ } sort(keys(%{ $responseType->{$part} }));
+ } sort(keys(%$responseType));
+ return @part_response_id;
}
sub get_display_part {
@@ -164,25 +167,26 @@ sub showResourceInfo {
my %resptype = ();
my $hdgrade='no';
my %partsseen;
- for my $part_resID (sort keys(%$handgrade)) {
- my $handgrade=$$handgrade{$part_resID};
- my ($partID,$resID) = split(/_/,$part_resID);
- my $responsetype = $responseType->{$partID}->{$resID};
- $hdgrade = $handgrade if ($handgrade eq 'yes');
- $result.='
';
- if ($checkboxes) {
- if (exists($partsseen{$partID})) {
- $result.=" | ";
- } else {
- $result.=" | ";
+ foreach my $partID (sort keys(%$responseType)) {
+ foreach my $resID (sort keys(%{ $responseType->{$partID} })) {
+ my $handgrade=$$handgrade{$partID.'_'.$resID};
+ my $responsetype = $responseType->{$partID}->{$resID};
+ $hdgrade = $handgrade if ($handgrade eq 'yes');
+ $result.='
';
+ if ($checkboxes) {
+ if (exists($partsseen{$partID})) {
+ $result.=" | ";
+ } else {
+ $result.=" | ";
+ }
+ $partsseen{$partID}=1;
}
- $partsseen{$partID}=1;
- }
- my $display_part=&get_display_part($partID,$symb);
- $result.='Part: '.$display_part.' '.
- $resID.' | '.
- 'Type: '.$responsetype.' |
';
+ my $display_part=&get_display_part($partID,$symb);
+ $result.='Part: '.$display_part.' '.
+ $resID.' | '.
+ 'Type: '.$responsetype.' | ';
# 'Handgrade: '.$handgrade.' | ';
+ }
}
$result.=''."\n";
return $result,$responseType,$hdgrade,$partlist,$handgrade;
@@ -205,9 +209,11 @@ sub get_order {
return ($analyze{"$partid.$respid.shown"});
}
#--- Clean response type for display
-#--- Currently filters option/rank/radiobutton/match/essay response types only.
+#--- Currently filters option/rank/radiobutton/match/essay/Task
+# response types only.
sub cleanRecord {
- my ($answer,$response,$symb,$partid,$respid,$record,$order,$version) = @_;
+ my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
+ $uname,$udom) = @_;
my $grayFont = '';
if ($response =~ /^(option|rank)$/) {
my %answer=&Apache::lonnet::str2hash($answer);
@@ -288,6 +294,37 @@ sub cleanRecord {
my $jme=$record->{$version."resource.$partid.$respid.molecule"};
$result.=&Apache::chemresponse::jme_img($jme,$answer,400);
return $result;
+ } elsif ( $response eq 'Task') {
+ if ( $answer eq 'SUBMITTED') {
+ my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
+ my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
+ return $result;
+ } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
+ my @matches = grep(/^\Q$version\E.*?\.instance$/,
+ keys(%{$record}));
+ return join('
',($version,@matches));
+
+
+ } else {
+ my $result =
+ ''
+ .&mt('Overall result: [_1]',
+ $record->{$version."resource.$respid.$partid.status"})
+ .'
';
+
+ $result .= '';
+ my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
+ keys(%{$record}));
+ foreach my $grade (sort(@grade)) {
+ my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
+ $result.= '- '.&mt("Dimension: [_1], status [_2] ",
+ $dim, $record->{$grade}).
+ '
';
+ }
+ $result.='
';
+ return $result;
+ }
+
}
return $answer;
}
@@ -552,7 +589,7 @@ sub verifyreceipt {
my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
$env{'form.receipt'};
$receipt =~ s/[^\-\d]//g;
- my $symb = &Apache::lonnet::symbread();
+ my ($symb) = &get_symb($request);
my $title.='Verifying Submission Receipt '.
$receipt.'
'."\n".
@@ -688,7 +725,14 @@ LISTJAVASCRIPT
$gradeTable.=''."\n".
''."\n".
''."\n".
- ''."\n".
+ '
'."\n".
+ ' Grading Increments: '.
+
''."\n".
''."\n".
'
'."\n".
@@ -1101,6 +1145,81 @@ sub sub_page_kw_js {
my $request = shift;
my $iconpath = $request->dir_config('lonIconsURL');
&commonJSfunctions($request);
+
+ my $inner_js_msg_central=<
+ function checkInput() {
+ opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
+ var nmsg = opener.document.SCORE.savemsgN.value;
+ var usrctr = document.msgcenter.usrctr.value;
+ var newval = opener.document.SCORE["newmsg"+usrctr];
+ newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
+
+ var msgchk = "";
+ if (document.msgcenter.subchk.checked) {
+ msgchk = "msgsub,";
+ }
+ var includemsg = 0;
+ for (var i=1; i<=nmsg; i++) {
+ var opnmsg = opener.document.SCORE["savemsg"+i];
+ var frmmsg = document.msgcenter["msg"+i];
+ opnmsg.value = opener.checkEntities(frmmsg.value);
+ var showflg = opener.document.SCORE["shownOnce"+i];
+ showflg.value = "1";
+ var chkbox = document.msgcenter["msgn"+i];
+ if (chkbox.checked) {
+ msgchk += "savemsg"+i+",";
+ includemsg = 1;
+ }
+ }
+ if (document.msgcenter.newmsgchk.checked) {
+ msgchk += "newmsg"+usrctr;
+ includemsg = 1;
+ }
+ imgformname = opener.document.SCORE["mailicon"+usrctr];
+ imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
+ var includemsg = opener.document.SCORE["includemsg"+usrctr];
+ includemsg.value = msgchk;
+
+ self.close()
+
+ }
+
+INNERJS
+
+ my $inner_js_highlight_central=<
+ function updateChoice(flag) {
+ opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
+ opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
+ opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
+ opener.document.SCORE.refresh.value = "on";
+ if (opener.document.SCORE.keywords.value!=""){
+ opener.document.SCORE.submit();
+ }
+ self.close()
+ }
+
+INNERJS
+
+ my $start_page_msg_central =
+ &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
+ {'js_ready' => 1,
+ 'only_body' => 1,
+ 'bgcolor' =>'#FFFFFF',});
+ my $end_page_msg_central =
+ &Apache::loncommon::end_page({'js_ready' => 1});
+
+
+ my $start_page_highlight_central =
+ &Apache::loncommon::start_page('Highlight Central',
+ $inner_js_highlight_central,
+ {'js_ready' => 1,
+ 'only_body' => 1,
+ 'bgcolor' =>'#FFFFFF',});
+ my $end_page_highlight_central =
+ &Apache::loncommon::end_page({'js_ready' => 1});
+
my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
$docopen=~s/^document\.//;
$request->print(<");
- pDoc.write("Message Central");
-
- pDoc.write("
ENDSCRIPT
my $href="/adm/pickcode?".
- "form=".&Apache::lonnet::escape("scantronupload").
- "&scantron_format=".&Apache::lonnet::escape($env{'form.scantron_format'}).
- "&scantron_CODElist=".&Apache::lonnet::escape($env{'form.scantron_CODElist'}).
- "&curCODE=".&Apache::lonnet::escape($$scan_record{'scantron.CODE'}).
- "&scantron_selectfile=".&Apache::lonnet::escape($env{'form.scantron_selectfile'});
- $r->print(" Selected CODE is ");
- $r->print("\n
");
+ "form=".&escape("scantronupload").
+ "&scantron_format=".&escape($env{'form.scantron_format'}).
+ "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
+ "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
+ "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
+ if ($env{'form.scantron_CODElist'} =~ /\S/) {
+ $r->print(" Selected CODE is ");
+ $r->print("\n
");
+ }
$r->print(" as the CODE.");
$r->print("\n
");
} elsif ($error eq 'doublebubble') {
@@ -5250,28 +5577,29 @@ sub scantron_validate_doublebubble {
return (0,$currentphase+1);
}
-sub scantron_get_maxbubble {
- my ($r)=@_;
+sub scantron_get_maxbubble {
if (defined($env{'form.scantron_maxbubble'}) &&
$env{'form.scantron_maxbubble'}) {
return $env{'form.scantron_maxbubble'};
}
+
my $navmap=Apache::lonnavmaps::navmap->new();
my (undef,undef,$sequence)=
&Apache::lonnet::decode_symb($env{'form.selectpage'});
+
my $map=$navmap->getResourceByUrl($sequence);
my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
- &Apache::lonnet::delenv('form.counter');
+
+ &Apache::lonxml::clear_problem_counter();
+
foreach my $resource (@resources) {
- my $result=&Apache::lonnet::ssi($resource->src().'?symb='.&Apache::lonnet::escape($resource->symb()));
+ my $result=&Apache::lonnet::ssi($resource->src(),
+ ('symb' => $resource->symb()));
}
&Apache::lonnet::delenv('scantron\.');
- my $envfile=$env{'user.environment'};
- $envfile=~/\/([^\/]+)\.id$/;
- $envfile=$1;
- &Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'),
- $envfile);
- $env{'form.scantron_maxbubble'}=$env{'form.counter'}-1;
+ $env{'form.scantron_maxbubble'} =
+ &Apache::lonxml::get_problem_counter()-1;
+
return $env{'form.scantron_maxbubble'};
}
@@ -5365,8 +5693,13 @@ SCANTRONFORM
next;
}
($uname,$udom)=split(/:/,$uname);
- &Apache::lonnet::delenv('form.counter');
+
+ &Apache::lonxml::clear_problem_counter();
&Apache::lonnet::appenv(%$scan_record);
+
+ if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
+ &scantron_putfile($scanlines,$scan_data);
+ }
my $i=0;
foreach my $resource (@resources) {
@@ -5377,8 +5710,9 @@ SCANTRONFORM
'grade_domain' =>$udom,
'grade_courseid'=>$env{'request.course.id'},
'grade_symb' =>$resource->symb());
- if (exists($scan_record->{'scantron.CODE'}) &&
- $scan_record->{'scantron.CODE'}) {
+ if (exists($scan_record->{'scantron.CODE'})
+ &&
+ &Apache::lonnet::validCODE($scan_record->{'scantron.CODE'})) {
$form{'CODE'}=$scan_record->{'scantron.CODE'};
} else {
$form{'CODE'}='';
@@ -5393,7 +5727,7 @@ SCANTRONFORM
$completedstudents{$uname}={'line'=>$line};
if (&Apache::loncommon::connection_aborted($r)) { last; }
} continue {
- &Apache::lonnet::delenv('form.counter');
+ &Apache::lonxml::clear_problem_counter();
&Apache::lonnet::delenv('scantron\.');
}
&Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
@@ -5499,7 +5833,6 @@ sub scantron_upload_scantron_data_save {
sub valid_file {
my ($requested_file)=@_;
foreach my $filename (sort(&scantron_filenames())) {
- &Apache::lonnet::logthis("$requested_file $filename");
if ($requested_file eq $filename) { return 1; }
}
return 0;
@@ -5755,7 +6088,7 @@ sub handler {
if ($#commands > 0) {
&Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
}
- &send_header($request);
+ $request->print(&Apache::loncommon::start_page('Grading'));
if ($symb eq '' && $command eq '') {
if ($env{'user.adv'}) {
if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
@@ -5846,27 +6179,10 @@ sub handler {
$request->print("Access Denied ($command)");
}
}
- &send_footer($request);
+ $request->print(&Apache::loncommon::end_page());
return '';
}
-sub send_header {
- my ($request)= @_;
- $request->print(&Apache::lontexconvert::header());
-# $request->print("
-#");
- $request->print(&Apache::loncommon::bodytag('Grading'));
- $request->rflush();
-}
-
-sub send_footer {
- my ($request)= @_;
- $request->print('