--- loncom/homework/grades.pm 2003/07/17 22:08:25 1.118
+++ loncom/homework/grades.pm 2003/08/21 18:21:39 1.135
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.118 2003/07/17 22:08:25 ng Exp $
+# $Id: grades.pm,v 1.135 2003/08/21 18:21:39 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -33,6 +33,7 @@
# June-August H.K. Ng
# Year 2003
# February, March H.K. Ng
+# July, H. K. Ng
#
package Apache::grades;
@@ -95,10 +96,23 @@ sub get_fullname {
return $fullname;
}
+#--- Format fullname, username:domain if different for display
+#--- Use anywhere where the student names are listed
+sub nameUserString {
+ my ($type,$fullname,$uname,$udom) = @_;
+ if ($type eq 'header') {
+ return ' Fullname (Username) ';
+ } else {
+ return ' '.$fullname.' ('.$uname.
+ ($ENV{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')';
+ }
+}
+
#--- Get the partlist and the response type for a given problem. ---
#--- Indicate if a response type is coded handgraded or not. ---
sub response_type {
- my ($url) = shift;
+ my ($url,$symb) = shift;
+ $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url))) if ($symb eq '');
my $allkeys = &Apache::lonnet::metadata($url,'keys');
my %seen = ();
my (@partlist,%handgrade);
@@ -107,7 +121,8 @@ sub response_type {
my ($responsetype,$part) = split(/_/,$_,2);
my ($partid,$respid) = split(/_/,$part);
$responsetype =~ s/response$//; # make it compatible w/ navmaps - should move to that!!
- $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no');
+ my ($value) = &Apache::lonnet::EXT('resource.'.$part.'.handgrade',$symb);
+ $handgrade{$part} = $responsetype.':'.($value eq 'yes' ? 'yes' : 'no');
next if ($seen{$partid} > 0);
$seen{$partid}++;
push @partlist,$partid;
@@ -123,24 +138,25 @@ sub showResourceInfo {
my $result ='
'.
'
Current Resource: '.$probTitle.'
'."\n";
my ($partlist,$handgrade) = &response_type($url);
- my ($resptype,$hdgrade)=('','no');
+ my %resptype = ();
+ my $hdgrade='no';
for (sort keys(%$handgrade)) {
my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
- $resptype = $responsetype;
+ my $partID = (split(/_/))[0];
+ $resptype{$partID} = $responsetype;
$hdgrade = $handgrade if ($handgrade eq 'yes');
- $result.='
Part '.(split(/_/))[0].'
'.
+ $result.='
Part '.$partID.'
'.
'
Type: '.$responsetype.'
';
# '
Handgrade: '.$handgrade.'
';
}
$result.='
'."\n";
- return $result,$resptype,$hdgrade,$partlist,$handgrade;
+ return $result,\%resptype,$hdgrade,$partlist,$handgrade;
}
#--- Clean response type for display
#--- Currently filters option response type only.
sub cleanRecord {
- my ($answer,$response) = @_;
- $answer =~ s|^ ||;
+ my ($answer,$response,$symb) = @_;
if ($response eq 'option') {
my (@IDs,@ans);
foreach (split(/\&/,&Apache::lonnet::unescape($answer))) {
@@ -149,12 +165,27 @@ sub cleanRecord {
push @ans,$ans;
}
my $grayFont = '';
- return '
'.
+ return '
'.
'
Answer
'.
(join '
',@ans).'
'.
'
'.$grayFont.'Option ID
'.$grayFont.
(join '
'.$grayFont,@IDs).'
'.
- '
';
+ '
';
+ }
+ if ($response eq 'essay') {
+ if (! exists ($ENV{'form.'.$symb})) {
+ my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
+ $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+ $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+
+ my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
+ $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
+ $ENV{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
+ $ENV{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
+ $ENV{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
+ $ENV{'form.'.$symb} = 1; # so that we don't have to read it from disk for multiple sub of the same prob.
+ }
+ return '
'.&keywords_highlight($answer).'
';
}
return $answer;
}
@@ -198,6 +229,7 @@ COMMONJSFUNCTIONS
#--- section, ids and fullnames for each user.
sub getclasslist {
my ($getsec,$filterlist) = @_;
+ $getsec = $getsec eq '' ? 'all' : $getsec;
my $classlist=&Apache::loncoursedata::get_classlist();
# Bail out if we were unable to get the classlist
return if (! defined($classlist));
@@ -278,7 +310,7 @@ sub student_gradeStatus {
my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
my %partstatus = ();
foreach (@$partlist) {
- my ($status,$foo) = split(/_/,$record{"resource.$_.solved"},2);
+ my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
$status = 'nothing' if ($status eq '');
$partstatus{$_} = $status;
my $subkey = "resource.$_.submitted_by";
@@ -304,6 +336,7 @@ sub jscriptNform {
''."\n".
''."\n".
''."\n".
+ ''."\n".
''."\n".
''."\n".
''."\n".
@@ -431,7 +464,7 @@ sub listStudents {
my $result='
'.$viewgrade.
' Submissions for a Student or a Group of Students
';
- my ($table,$resptype,$hdgrade,$partlist,$handgrade) = &showResourceInfo($url,$ENV{'form.probTitle'});
+ my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($url,$ENV{'form.probTitle'});
$result.=$table;
$request->print(<print($result);
my $checkhdgrade = ($ENV{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked' : '';
- my $checklastsub = ($ENV{'form.handgrade'} eq 'no') ? 'checked' : '';
- $checklastsub = 'checked' if ($checkhdgrade eq '' && $checklastsub eq '');
+ my $checklastsub = $checkhdgrade eq '' ? 'checked' : '';
my $gradeTable=''."\n";
+ 'value="Next->" />'."\n";
if ($ctr == 0) {
my $num_students=(scalar(keys(%$fullname)));
if ($num_students eq 0) {
@@ -625,9 +662,9 @@ sub sub_page_js {
$request->print(<
function updateRadio(formname,id,weight) {
- var gradeBox = eval("formname.GD_BOX"+id);
- var radioButton = eval("formname.RADVAL"+id);
- var oldpts = eval("formname.oldpts"+id+".value");
+ var gradeBox = formname["GD_BOX"+id];
+ var radioButton = formname["RADVAL"+id];
+ var oldpts = formname["oldpts"+id].value;
var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
gradeBox.value = pts;
var resetbox = false;
@@ -649,7 +686,7 @@ sub sub_page_js {
var resp = confirm("You entered a value ("+pts+
") greater than the weight for the part. Accept?");
if (resp == false) {
- gradeBox.value = "";
+ gradeBox.value = oldpts;
return;
}
}
@@ -661,18 +698,17 @@ sub sub_page_js {
}
}
updateSelect(formname,id);
- var stores = eval("formname.stores"+id);
- stores.value = "0";
+ formname["stores"+id].value = "0";
}
function writeBox(formname,id,pts) {
- var gradeBox = eval("formname.GD_BOX"+id);
+ var gradeBox = formname["GD_BOX"+id];
if (checkSolved(formname,id) == 'update') {
gradeBox.value = pts;
} else {
- var oldpts = eval("formname.oldpts"+id+".value");
+ var oldpts = formname["oldpts"+id].value;
gradeBox.value = oldpts;
- var radioButton = eval("formname.RADVAL"+id);
+ var radioButton = formname["RADVAL"+id];
for (var i=0; i
//===================== Show list of keywords ====================
- function keywords(keyform) {
- var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keyform.value);
+ function keywords(formname) {
+ var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
if (nret==null) return;
- keyform.value = nret;
+ formname.keywords.value = nret;
- document.SCORE.refresh.value = "on";
- if (document.SCORE.keywords.value != "") {
- document.SCORE.submit();
+ if (formname.keywords.value != "") {
+ formname.refresh.value = "on";
+ formname.submit();
}
return;
}
@@ -832,10 +874,9 @@ sub sub_page_kw_js {
}
var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
if (nret==null) return;
- var curlist = document.SCORE.keywords.value;
- document.SCORE.keywords.value = curlist+" "+nret;
- document.SCORE.refresh.value = "on";
+ document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
if (document.SCORE.keywords.value != "") {
+ document.SCORE.refresh.value = "on";
document.SCORE.submit();
}
return;
@@ -852,21 +893,23 @@ sub sub_page_kw_js {
var Nmsg = msgform.savemsgN.value;
savedMsgHeader(Nmsg,usrctr,fullname);
var subject = msgform.msgsub.value;
- var rtrchk = eval("document.SCORE.includemsg"+usrctr);
- var msgchk = rtrchk.value;
+ var msgchk = document.SCORE["includemsg"+usrctr].value;
re = /msgsub/;
var shwsel = "";
if (re.test(msgchk)) { shwsel = "checked" }
- displaySubject(subject,shwsel);
+ subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
+ displaySubject(checkEntities(subject),shwsel);
for (var i=1; i<=Nmsg; i++) {
- var testpt = "savemsg"+i+",";
- re = /testpt/;
+ var testmsg = "savemsg"+i+",";
+ re = new RegExp(testmsg,"g");
shwsel = "";
if (re.test(msgchk)) { shwsel = "checked" }
- var message = eval("document.SCORE.savemsg"+i+".value");
- displaySavedMsg(i,message,shwsel);
+ var message = document.SCORE["savemsg"+i].value;
+ message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
+ displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
+ //any < is already converted to <, etc. However, only once!!
}
- newmsg = eval("document.SCORE.newmsg"+usrctr+".value");
+ newmsg = document.SCORE["newmsg"+usrctr].value;
shwsel = "";
re = /newmsg/;
if (re.test(msgchk)) { shwsel = "checked" }
@@ -875,6 +918,22 @@ sub sub_page_kw_js {
return;
}
+ function checkEntities(strx) {
+ if (strx.length == 0) return strx;
+ var orgStr = ["&", "<", ">", '"'];
+ var newStr = ["&", "<", ">", """];
+ var counter = 0;
+ while (counter < 4) {
+ strx = strReplace(strx,orgStr[counter],newStr[counter]);
+ counter++;
+ }
+ return strx;
+ }
+
+ function strReplace(strx, orgStr, newStr) {
+ return strx.split(orgStr).join(newStr);
+ }
+
function savedMsgHeader(Nmsg,usrctr,fullname) {
var height = 70*Nmsg+250;
var scrollbar = "no";
@@ -882,7 +941,6 @@ sub sub_page_kw_js {
height = 600;
scrollbar = "yes";
}
-// if (window.pWin) {window.pWin.close(); window.pWin=null}
var xpos = (screen.width-600)/2;
xpos = (xpos < 0) ? '0' : xpos;
var ypos = (screen.height-height)/2-30;
@@ -891,16 +949,17 @@ sub sub_page_kw_js {
pWin = window.open('', 'MessageCenter', '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.write("");
pDoc.write("Message Central");
pDoc.write("
@@ -1125,11 +1179,12 @@ sub gradeBox {
'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
$result.=''.
- ''."\n";
+ '';
} else {
$result.=''.
- ''."\n";
+ '';
}
+ $result.=''."\n";
$result.="  \n";
$result.=''."\n".
''."\n".
@@ -1172,6 +1227,7 @@ sub submission {
(my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
my ($uname,$udom) = ($ENV{'form.student'},$ENV{'form.userdom'});
+ $udom = ($udom eq '' ? $ENV{'user.domain'} : $udom); #has form.userdom changed for a student?
my $usec = &Apache::lonnet::getsection($udom,$uname,$ENV{'request.course.id'});
$ENV{'form.fullname'} = &get_fullname ($uname,$udom) if $ENV{'form.fullname'} eq '';
@@ -1185,7 +1241,10 @@ sub submission {
return;
}
+ $ENV{'form.lastSub'} = ($ENV{'form.lastSub'} eq '' ? 'datesub' : $ENV{'form.lastSub'});
my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
+ my $checkIcon = '';
# header info
if ($counter == 0) {
@@ -1198,8 +1257,6 @@ sub submission {
' Resource: '.$ENV{'form.probTitle'}.''."\n");
if ($ENV{'form.handgrade'} eq 'no') {
- my $checkIcon = '';
my $checkMark='
Note: Part(s) graded correct by the computer is marked with a '.
$checkIcon.' symbol.'."\n";
$request->print($checkMark);
@@ -1227,14 +1284,18 @@ sub submission {
$ENV{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
$keyhash{$symb.'_subject'} : $ENV{'form.probTitle'};
$ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
-
}
+ my $overRideScore = $ENV{'form.overRideScore'} eq '' ? 'no' : $ENV{'form.overRideScore'};
$request->print(''."\n");
- $request->print(&show_grading_menu_form($symb,$url))
+ my $toGrade.=' '."\n" if (&canmodify($usec));
+ $toGrade.=''."\n";
+ $toGrade.=&show_grading_menu_form($symb,$url)
if (($ENV{'form.command'} eq 'submission') ||
($ENV{'form.command'} eq 'processGroup' && $counter == $total));
+ $request = print($toGrade);
return;
}
- # essay grading options
+ # essay grading message center
if ($ENV{'form.handgrade'} eq 'yes') {
- $result=''."\n".
- ''."\n".
- ''."\n";
my ($lastname,$givenn) = split(/,/,$ENV{'form.fullname'});
my $msgfor = $givenn.' '.$lastname;
if (scalar(@col_fullnames) > 0) {
@@ -1460,7 +1534,8 @@ KEYWORDS
$msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
}
$msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
-# $result.='
'."\n".
+ $result=''."\n".
+ ''."\n";
$result.=' '.
'Compose Message to student'.(scalar(@col_fullnames) >= 1 ? 's' : '').' '.
@@ -1473,17 +1548,21 @@ KEYWORDS
my %seen = ();
my @partlist;
+ my @gradePartRespid;
for (sort keys(%$handgrade)) {
my ($partid,$respid) = split(/_/);
next if ($seen{$partid} > 0);
$seen{$partid}++;
next if ($$handgrade{$_} =~ /:no$/ && $ENV{'form.lastSub'} =~ /^(hdgrade)$/);
push @partlist,$partid;
+ push @gradePartRespid,$partid.'.'.$respid;
$request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
}
$result=''."\n";
+ $result.=''."\n" if ($counter == 0);
my $ctr = 0;
while ($ctr < scalar(@partlist)) {
$result.='
'.
- ''."\n";
-# if ($ENV{'form.handgrade'} eq 'yes') {
- $endform.=' '."\n";
- my $ntstu =''."\n";
- my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
- $ntstu =~ s/
'."\n".
- ' '.
''."\n";
$studentTable.=&show_grading_menu_form($symb,$url);
@@ -2896,6 +2950,47 @@ sub displayPage {
return '';
}
+sub displaySubByDates {
+ my ($symbx,$record,$parts,$responseType,$checkIcon) = @_;
+ my $studentTable='
'.
+ '
'.
+ '
Date/Time
'.
+ '
Submission
'.
+ '
Status
';
+ my ($version);
+ my %mark;
+ $mark{'correct_by_student'} = $checkIcon;
+ return ' Nothing submitted - no attempts '
+ if (!exists($$record{'1:timestamp'}));
+ for ($version=1;$version<=$$record{'version'};$version++) {
+ my $timestamp = scalar(localtime($$record{$version.':timestamp'}));
+ $studentTable.='
'.$timestamp.'
';
+ my @versionKeys = split(/\:/,$$record{$version.':keys'});
+ my @displaySub = ();
+ foreach my $partid (@{$parts}) {
+ my @matchKey = grep /^resource\.$partid\..*?\.submission$/,@versionKeys;
+# next if ($$record{"$version:resource.$partid.solved"} eq '');
+ $displaySub[0].=(exists $$record{$version.':'.$matchKey[0]}) ?
+ 'Part '.$partid.' '.
+ ($$record{"$version:resource.$partid.tries"} eq '' ? 'Trial not counted' :
+ 'Trial '.$$record{"$version:resource.$partid.tries"}).' '.
+ &cleanRecord($$record{$version.':'.$matchKey[0]},$$responseType{$partid},$$symbx).' ' : '';
+ $displaySub[1].=(exists $$record{"$version:resource.$partid.award"}) ?
+ 'Part '.$partid.' '.
+ lc($$record{"$version:resource.$partid.award"}).' '.
+ $mark{$$record{"$version:resource.$partid.solved"}}.' ' : '';
+ $displaySub[2].=(exists $$record{"$version:resource.$partid.regrader"}) ?
+ $$record{"$version:resource.$partid.regrader"}.' (Part: '.$partid.')' : '';
+ }
+ $displaySub[2].=(exists $$record{"$version:resource.regrader"}) ?
+ $$record{"$version:resource.regrader"} : ''; # needed because old essay regrader has not parts info
+ $studentTable.='
'."\n";
$request->print($result);
- my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db',
- $ENV{'request.course.fn'}.'_parms.db',1, 1);
+ my $navmap = Apache::lonnavmaps::navmap->new();
my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'});
my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
@@ -2927,7 +3021,7 @@ sub updateGradeByPage {
my $studentTable='
'.
'
'.
- '
No
'.
+ '
Prob.
'.
'
Title
'.
'
Previous Score
'.
'
New Score
';
@@ -2959,31 +3053,39 @@ sub updateGradeByPage {
my $score;
if ($partial > 0) {
$score = 'correct_by_override';
- } elsif ($partial == 0) {
+ } elsif ($newpts ne '') { #empty is taken as 0
$score = 'incorrect_by_override';
}
- if ($ENV{'form.GD_SEL'.$question.'_'.$partid} eq 'excused') {
+ my $dropMenu = $ENV{'form.GD_SEL'.$question.'_'.$partid};
+ if ($dropMenu eq 'excused') {
$partial = '';
$score = 'excused';
+ } elsif ($dropMenu eq 'reset status'
+ && $ENV{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
+ $newrecord{'resource.'.$partid.'.tries'} = 0;
+ $newrecord{'resource.'.$partid.'.solved'} = '';
+ $newrecord{'resource.'.$partid.'.award'} = '';
+ $newrecord{'resource.'.$partid.'.awarded'} = 0;
+ $newrecord{'resource.'.$partid.'.regrader'} = "$ENV{'user.name'}:$ENV{'user.domain'}";
+ $changeflag++;
+ $newpts = '';
}
+
my $oldstatus = $ENV{'form.solved'.$question.'_'.$partid};
$displayPts[0].=' Part '.$partid.' = '.
(($oldstatus eq 'excused') ? 'excused' : $oldpts).
' ';
$displayPts[1].=' Part '.$partid.' = '.
- ($oldstatus eq 'correct_by_student' ? $oldpts :
- (($score eq 'excused') ? 'excused' : $newpts)).
+ (($score eq 'excused') ? 'excused' : $newpts).
' ';
$question++;
- if (($oldstatus eq 'correct_by_student') ||
- ($newpts eq $oldpts && $score eq $oldstatus))
- {
- next;
- }
+ next if ($dropMenu eq 'reset status' || ($newpts == $oldpts && $score ne 'excused'));
+
$newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
- $newrecord{'resource.'.$partid.'.solved'} = $score;
- $newrecord{'resource.'.$partid.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
+ $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
+ $newrecord{'resource.'.$partid.'.regrader'} = "$ENV{'user.name'}:$ENV{'user.domain'}"
+ if (scalar(keys(%newrecord)) > 0);
$changeflag++;
}
@@ -2991,6 +3093,7 @@ sub updateGradeByPage {
&Apache::lonnet::cstore(\%newrecord,$symbx,$ENV{'request.course.id'},
$udom,$uname);
}
+
$studentTable.='
'.$displayPts[0].'
'.
'
'.$displayPts[1].'
'.
'';
@@ -3228,7 +3331,7 @@ sub scantron_process_students {
my @scanlines=<$scanlines>;
my $classlist=&Apache::loncoursedata::get_classlist();
my %idmap=&username_to_idmap($classlist);
- my $navmap=Apache::lonnavmaps::navmap->new($ENV{'request.course.fn'}.'.db',$ENV{'request.course.fn'}.'_parms.db',1, 1);
+ my $navmap=Apache::lonnavmaps::navmap->new();
my $map=$navmap->getResourceByUrl($sequence);
my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
$r->print("geto ".scalar(@resources)." ");
@@ -3332,7 +3435,7 @@ SCANTRONFORM
#--- Show a Grading Menu button - Calls the next routine ---
sub show_grading_menu_form {
my ($symb,$url)=@_;
- my $result.='