--- loncom/homework/grades.pm 2002/07/01 21:20:29 1.34
+++ loncom/homework/grades.pm 2002/07/03 21:05:33 1.35
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.34 2002/07/01 21:20:29 ng Exp $
+# $Id: grades.pm,v 1.35 2002/07/03 21:05:33 ng Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,7 +30,7 @@
# 7/26 H.K. Ng
# 8/20 Gerd Kortemeyer
# Year 2002
-# June 2002 H.K. Ng
+# June, July 2002 H.K. Ng
#
package Apache::grades;
@@ -53,6 +53,7 @@ sub moreinfo {
if ($ENV{'form.symb'}) {
$request->print(''."\n");
}
+# $request->print(''."\n");
$request->print(''."\n");
$request->print("Student:".''."
\n");
$request->print("Domain:".''."
\n");
@@ -140,6 +141,8 @@ sub listStudents {
all
+
+
Select | Username |
@@ -181,31 +184,39 @@ sub processGroup {
my ($request) = shift;
my $ctr = 0;
my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
- : ($ENV{'form.stuinfo'}) );
+ : ($ENV{'form.stuinfo'}));
my $total = scalar(@stuchecked)-1;
- foreach my $student (@stuchecked) {
- my ($sname,$sdom,$fullname) = split(/:/,$student);
+ if ($stuchecked[0] eq '') {
+ &userError($request,'No student was selected for viewing/grading.');
+ return;
+ }
+ foreach (@stuchecked) {
+ my ($sname,$sdom,$fullname) = split(/:/);
$ENV{'form.student'} = $sname;
$ENV{'form.fullname'} = $fullname;
&submission($request,$ctr,$total);
$ctr++;
}
-
return 'The End';
}
+sub userError {
+ my ($request, $reason, $step) = @_;
+ $request->print('LON-CAPA User Error '."\n");
+ $request->print('Reason: '.$reason.'
'."\n");
+ $request->print('Step: '.($step ne '' ? $step : 'Use your browser back button to correct')
+ .'
'."\n");
+ return '';
+}
+
#FIXME - needs to handle multiple matches
sub finduser {
my ($name) = @_;
my $domain = '';
-
if ( $Apache::grades::viewgrades eq 'F' ) {
- #get classlist
-# my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
- #print "Found $cdom:$cnum ";
my ($classlist) = &getclasslist('all','0');
- foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
- my ($posname,$posdomain) = split(/:/,$student);
+ foreach ( sort(@{ $$classlist{'all'} }) ) {
+ my ($posname,$posdomain) = split(/:/);
if ($posname =~ $name) { $name=$posname; $domain=$posdomain; last; }
}
return ($name,$domain);
@@ -228,8 +239,9 @@ sub getclasslist {
}
my ($unam,$udom) = split(/:/,$student,2);
my $section = &Apache::lonnet::usection($udom,$unam,$ENV{'request.course.id'});
+ $section = ($section ne '-1' ? $section : 'no');
push @holdsec,$section;
- push (@{ $classlist{$getsec} }, $student) if ($getsec eq 'all' or $getsec == $section);
+ push (@{ $classlist{$getsec} }, $student) if ($getsec eq 'all' || $getsec eq $section);
}
my %seen = ();
foreach my $item (@holdsec) {
@@ -326,10 +338,6 @@ sub setstudentgrade {
}
if ( scalar(keys(%newrecord)) > 0 ) {
$newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
- print "grader=$newrecord{'resource.regrader'}: records ";
- while (my ($k,$v) = each %newrecord) {
- print "k=$k:v=$v: \n";
- }
# &Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$stuname);
$result.="Stored away ".scalar(keys(%newrecord))." elements. \n";
@@ -390,13 +398,37 @@ sub submission {
return;
}
+ function keywords(keyform) {
+ var keywds = keyform.value;
+ var nret = prompt("Keywords list, separate by a space or comma. Add/delete to list if desired.",keywds);
+ if (nret==null) return;
+ keyform.value = nret;
+ return;
+ }
+
+ function addmsg(msgform) {
+ var msg = msgform.value;
+ var nret = prompt("Enter the message you wish to send to the student.",msg);
+ if (nret==null) return;
+ msgform.value = nret;
+ return;
+ }
+
+ function savedmsg(msgform) {
+ var Nmsg = msgform.value;
+ var nret = prompt("Number of saved messages = ",Nmsg);
+ if (nret==null) return;
+ msgform.value = nret;
+ return;
+ }
+
JAVASCRIPT
}
(my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
- if ($ENV{'form.student'} eq '') { &moreinfo($request,"Need student login id"); return ''; }
+ if ($ENV{'form.student'} eq '') { &moreinfo($request,'Need student login id'); return ''; }
my ($uname,$udom) = &finduser($ENV{'form.student'});
- if ($uname eq '') { &moreinfo($request,"Unable to find student"); return ''; }
+ if ($uname eq '') { &moreinfo($request,'Unable to find student'); return ''; }
my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
@@ -425,17 +457,40 @@ JAVASCRIPT
#
# beginning of form
if ($counter == 0) {
+ my %keyhash = &Apache::lonnet::get
+ ('nohist_handgrade',[$symb.'_keywords'],
+ $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+ $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+
$request->print(' ';
- $result.='Resource: '.$url.' | ';
+ if ($ENV{'form.handgrade'} eq 'yes') {
+ my $subonly = &get_last_submission($symb,$uname,$udom,$ENV{'request.course.id'});
+ my ($classlist) = &getclasslist('all','0');
+ my @collaborators;
+ foreach ( sort(@{ $$classlist{'all'} }) ) {
+ my ($sname,$sdom) = split(/:/);
+ push @collaborators,$sname if (grep /\b$sname(\b|\.)/i,$subonly);
+ }
+ push @collaborators,'leede','carlandmm','freyniks'; # as a test to display collaborators.
+ if (scalar(@collaborators) != 0) {
+ $result.=' |
Collaborators: ';
+ foreach (@collaborators) {
+ $result.=$_.' ('.&get_fullname($_,$udom).') ';
+ }
+ $result.=' |
'."\n";
+ $result.=''."\n";
+ }
+ }
+ $result.='Resource: '.$url.' |
'."\n";
$request->print($result);
#
# print student answer
- my $answer=&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
- $ENV{'request.course.id'},$last);
- $request->print($answer);
- $answer =~ m/.*<\/tr>.*?(.*?) | (.*?)<\/td>/;
- print "Submitted=$1: $2;";
+ $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
+ $ENV{'request.course.id'},$last,
+ '.submission','Apache::grades::keywords_highlight'));
+#
#
my $wgt = &Apache::lonnet::EXT('resource.partid.weight',$symb,$udom,$uname);
my $wgtmsg = ($wgt > 0 ? '(problem weight)' : 'problem weight assigned by computer');
@@ -522,6 +595,42 @@ JAVASCRIPT
return '';
}
+sub get_last_submission {
+ my ($symb,$username,$domain,$course)=@_;
+ if ($symb) {
+ my (%returnhash)=&Apache::lonnet::restore($symb,$course,$domain,$username);
+ if ($returnhash{'version'}) {
+ my %lasthash=();
+ my $version;
+ for ($version=1;$version<=$returnhash{'version'};$version++) {
+ foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
+ $lasthash{$_}=$returnhash{$version.':'.$_};
+ }
+ }
+ foreach ((keys %lasthash)) {
+ if ($_ =~ /\.submission$/) {return $lasthash{$_}}
+ }
+ return '';
+ }
+ }
+}
+
+sub keywords_highlight {
+ my $string = shift;
+ (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
+ my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
+ my %keyhash = &Apache::lonnet::get
+ ('nohist_handgrade',[$symb.'_keywords'],
+ $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+ $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ my @keylist = split(/[,\s+]/,$keyhash{$symb.'_keywords'});
+ foreach my $word (@keylist) {
+ next if ($word eq '');
+ $string =~ s/\b$word(\b|\.)/\$word\<\/font\>/gi;
+ }
+ return $string;
+}
+
sub processHandGrade {
my ($request) = shift;
my $url = $ENV{'form.url'};
@@ -529,34 +638,40 @@ sub processHandGrade {
my $button = $ENV{'form.gradeOpt'};
my $ngrade = $ENV{'form.NCT'};
my $ntstu = $ENV{'form.NTSTU'};
-# my $vProb = $ENV{'form.vProb'};
-# my $lastSub= $ENV{'form.lastSub'};
-
+ my $keywords= $ENV{'form.keywords'};
+ my $addmsg = $ENV{'form.addmsg'};
+ print "addmsg=$addmsg ";
+ if ($keywords ne '') {
+ my $crsname = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
+ my $crsdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+ my $putresult = &Apache::lonnet::put
+ ('nohist_handgrade',{$symb.'_keywords' => $keywords},
+ $crsdom,$crsname);
+ }
my (@parts) = sort(&getpartlist($url));
if ($button eq 'Save & Next') {
my $ctr = 0;
while ($ctr < $ENV{'form.NCT'}) {
-# my $pts = ($ENV{'form.GRADE_BOX'.$ctr} ne '' ? $ENV{'form.GRADE_BOX'.$ctr} : $ENV{'form.RADVAL'.$ctr});
-# my $wgt = $ENV{'form.WGT'.$ctr};
-# my $sel = $ENV{'form.GRADE_SEL'.$ctr};
-# my $score = $pts/$wgt if ($wgt != 0);
my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
&saveHandGrade($url,$symb,$uname,$udom,$ctr,@parts);
-# &saveHandGrade($url,$symb,$uname,$udom,$score,@parts);
+ if ($ENV{'form.collaborator'.$ctr}) {
+ my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
+ foreach (@collaborators) {
+ &saveHandGrade($url,$symb,$_,$udom,$ctr,@parts);
+ }
+ }
$ctr++;
}
}
my $firststu = $ENV{'form.unamedom0'};
my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
- #get classlist
-# my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
- my ($classlist) = &getclasslist('all','0');
+ my ($classlist) = &getclasslist($ENV{'form.section'},'0');
my (@nextlist,@prevlist);
my ($nextflg,$prevflg,$ctr,$ctprev) = (0,0,0,0);
- foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
+ foreach my $student ( sort(@{ $$classlist{$ENV{'form.section'}} }) ) {
my ($uname,$udom) = split(/:/,$student);
if ($nextflg == 1 && $button =~ /Next$/) {
push @nextlist,$uname if ($ctr < $ntstu);
@@ -594,7 +709,6 @@ sub processHandGrade {
sub saveHandGrade {
my ($url,$symb,$stuname,$domain,$newflg,@parts) = @_;
-# my ($stuname,$domain) = split(/:/,$student);
my %record=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
my %newrecord;
@@ -603,7 +717,8 @@ sub saveHandGrade {
my $oldscore=$record{"resource.$part.$type"};
my $newscore;
if ($type eq 'awarded' && $newflg >= 0) {
- my $pts = ($ENV{'form.GRADE_BOX'.$newflg} ne '' ? $ENV{'form.GRADE_BOX'.$newflg} : $ENV{'form.RADVAL'.$newflg});
+ my $pts = ($ENV{'form.GRADE_BOX'.$newflg} ne '' ?
+ $ENV{'form.GRADE_BOX'.$newflg} : $ENV{'form.RADVAL'.$newflg});
my $wgt = $ENV{'form.WGT'.$newflg};
# my $sel = $ENV{'form.GRADE_SEL'.$newflg};
$newscore = $pts/$wgt if ($wgt != 0);
@@ -633,10 +748,10 @@ sub saveHandGrade {
}
if ( scalar(keys(%newrecord)) > 0 ) {
$newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
- while (my ($k,$v) = each %newrecord) {
- print "k=$k:v=$v: \n";
- }
- print "symb=$symb,courseid=$ENV{'request.course.id'},dom=$domain,name=$stuname ";
+# while (my ($k,$v) = each %newrecord) {
+# print "k=$k:v=$v: \n";
+# }
+# print "symb=$symb,courseid=$ENV{'request.course.id'},dom=$domain,name=$stuname ";
# &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},$domain,$stuname);
}
return '';
@@ -665,13 +780,21 @@ sub gradingmenu {
my ($request) = @_;
my ($symb,$url)=&get_symb_and_url($request);
if (!$symb) {return '';}
+ my $allkeys = &Apache::lonnet::metadata($url,'keys');
+ my $handgrade = ($allkeys =~ /parameter_.*?_handgrade/ ? 'yes' : 'no');
+ my ($responsetype,$foo) = split(/_/,&Apache::lonnet::metadata($url,'packages'));
my $result=' Select a Grading Method';
- $result.=' Resource: '.$url.'
';
+ $result.='';
+ $result.='Resource: | '.
+ ''.$url.' | ';
+ $result.='Type: | '.
+ ''.$responsetype.' Handgrade: '.$handgrade.' | ';
+ $result.=' ';
$result.=&view_edit_entire_class_form($symb,$url).' ';
$result.=&upcsvScores_form($symb,$url).' ';
- $result.=&viewGradeaStu_form($symb,$url).' ';
+ $result.=&viewGradeaStu_form($symb,$url,$responsetype,$handgrade).' ';
$result.=&verifyReceipt_form($symb,$url);
return $result;
}
@@ -718,7 +841,7 @@ ENDUPFORM
}
sub viewGradeaStu_form {
- my ($symb,$url) = @_;
+ my ($symb,$url,$response,$handgrade) = @_;
my ($classlist,$sections) = &getclasslist('all','0');
my $result.=' |