[LON-CAPA-cvs] cvs: loncom /homework grades.pm

ng lon-capa-cvs@mail.lon-capa.org
Fri, 28 Feb 2003 21:06:28 -0000


This is a MIME encoded message

--ng1046466388
Content-Type: text/plain

ng		Fri Feb 28 16:06:28 2003 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  add grading box for each part
  
  
  
--ng1046466388
Content-Type: text/plain
Content-Disposition: attachment; filename="ng-20030228160628.txt"

Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.69 loncom/homework/grades.pm:1.70
--- loncom/homework/grades.pm:1.69	Thu Feb 27 17:39:11 2003
+++ loncom/homework/grades.pm	Fri Feb 28 16:06:28 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.69 2003/02/27 22:39:11 albertel Exp $
+# $Id: grades.pm,v 1.70 2003/02/28 21:06:28 ng Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1080,53 +1080,9 @@
 	$seen{$partid}++;
 	next if ($$handgrade{$_} =~ /:no$/);
 	push @partlist,$partid;
-	my $wgt    = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
-	my $wgtmsg = ($wgt > 0 ? '(problem weight)' : 
-		      '<font color="red">problem weight assigned by computer</font>');
-	$wgt       = ($wgt > 0 ? $wgt : '1');
-	my $score  = ($record{'resource.'.$partid.'.awarded'} eq '' ?
-		      '' : $record{'resource.'.$partid.'.awarded'}*$wgt);
-	$result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />';
-	$result.='<table border="0"><tr><td><b>Part </b>'.$partid.' <b>Points: </b></td><td>';
 
-	my $ctr = 0;
-	$result.='<table border="0"><tr>';  # display radio buttons in a nice table 10 across
-	while ($ctr<=$wgt) {
-	    $result.= '<td><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
-		'onclick="javascript:writeBox(this.form.GD_BOX'.$counter.'_'.$partid.
-		',this.form.GD_SEL'.$counter.'_'.$partid.','.$ctr.
-		',this.form.stores'.$counter.'_'.$partid.')" '.
-		($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
-	    $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
-	    $ctr++;
-	}
-	$result.='</tr></table>';
+	$result=&gradeBox($symb,$uname,$udom,$counter,$partid,\%record);
 
-	$result.='</td><td>&nbsp;<b>or</b>&nbsp;</td>';
-	$result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
-	    ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
-	    'onChange="javascript:updateRadio(this.form.RADVAL'.$counter.'_'.$partid.
-	    ',this.form.GD_BOX'.$counter.'_'.$partid.
-	    ',this.form.GD_SEL'.$counter.'_'.$partid.
-	    ',this.form.stores'.$counter.'_'.$partid.
-	    ','.$wgt.')" /></td>'."\n";
-	$result.='<td>/'.$wgt.' '.$wgtmsg.' </td><td>';
-
-	$result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
-	    'onChange="javascript:clearRadBox(this.form.RADVAL'.$counter.'_'.$partid.
-	    ',this.form.GD_BOX'.$counter.'_'.$partid.
-	    ',this.form.GD_SEL'.$counter.'_'.$partid.
-	    ',this.form.stores'.$counter.'_'.$partid.')" >'."\n";
-	if ($record{'resource.'.$partid.'.solved'} eq 'excused') {
-	    $result.='<option> </option>'.
-		'<option selected="on">excused</option></select>';
-	} else {
-	    $result.='<option selected="on"> </option>'.
-		'<option>excused</option></select>';
-	}
-	$result.="&nbsp&nbsp\n";
-	$result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="0" />';
-	$result.='</td></tr></table>'."\n";
 	$request->print($result);
     }
     $result='<input type="hidden" name="partlist'.$counter.
@@ -2346,11 +2302,14 @@
 <script type="text/javascript" language="javascript">
 
 function checkPickOne(formname) {
-    var user = radioSelection(formname.pickOne);
+    var user = radioSelection(formname.student);
     if (user == null) {
 	alert("Please select the student you wish to grade.");
 	return;
     }
+    var ptr = pullDownSelection(formname.selectpage);
+    formname.page.value = formname.eval("page"+ptr).value;
+    formname.title.value = formname.eval("title"+ptr).value;
     formname.submit();
 }
 
@@ -2364,6 +2323,16 @@
     }
     return selection;
 }
+
+function pullDownSelection(selectOne) {
+    var selection=null;
+    for (var i=0; i<selectOne.length; i++) {
+        if (selectOne[i].selected) {
+            selection=selectOne[i].value;
+            return selection;
+        }
+    }
+}
 </script>
 LISTJAVASCRIPT
 
@@ -2379,15 +2348,26 @@
     my $curtitle = &Apache::lonnet::metadata($pagepath.$pagename,'title');
 
     $result.='<form action="/adm/grades" method="post" name="displayPage">'."<br>\n";
-    $result.='&nbsp;<b>Problems from:</b> <select name="page">'."\n";
+    $result.='&nbsp;<b>Problems from:</b> <select name="selectpage">'."\n";
     my ($titles,$symbx) = &getSymbMap();
 #    shift @$titles; # skip the top level sequence
+    my $ctr=0;
     foreach (@$titles) {
 	my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
-	my $check_select = ($showtitle eq $curtitle ? 'selected="on"' : '');
-	$result.='<option value="'.$_.'" '.$check_select.'>'.$showtitle.'</option>'."\n";
+	$result.='<option value="'.$ctr.'" '.
+	    ($showtitle eq $curtitle ? 'selected="on"' : '').'>'.$showtitle.'</option>'."\n";
+	$ctr++;
     }
     $result.= '</select>'."<br>\n";
+    $ctr=0;
+    foreach (@$titles) {
+	my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
+	$result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
+	$result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
+	$ctr++;
+    }
+    $result.='<input type="hidden" name="page" />'."\n";
+    $result.='<input type="hidden" name="title" />'."\n";
 
 #    $result.='&nbsp;<b>View Problems: </b><input type="radio" name="vProb" value="no" checked /> no '."\n".
 #	'<input type="radio" name="vProb" value="yes" /> yes '."<br>\n";
@@ -2413,7 +2393,7 @@
     foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
 	my ($uname,$udom) = split(/:/,$student);
 	$studentTable.=($ptr%4 == 1 ? '<tr bgcolor="#ffffe6"><td>' : '</td><td>');
-	$studentTable.='<input type="radio" name="pickOne" value="'.$student.'" /> '.$$fullname{$student}.
+	$studentTable.='<input type="radio" name="student" value="'.$student.'" /> '.$$fullname{$student}.
 	    '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font>'."\n";
 	$studentTable.=($ptr%4 == 0 ? '</td></tr>' : '');
 	$ptr++;
@@ -2422,7 +2402,8 @@
     $studentTable.='</td><td>&nbsp;</td><td>&nbsp;' if ($ptr%4 == 3);
     $studentTable.='</td><td>&nbsp;' if ($ptr%4 == 0);
     $studentTable.='</td></tr></table></td></tr></table>'."\n";
-    $studentTable.='<br />&nbsp;<input type="button" onClick="javascript:checkPickOne(this.form);" value="Submit" /></form>'."\n";
+    $studentTable.='<br />&nbsp;<input type="button" '.
+	'onClick="javascript:checkPickOne(this.form);"value="Submit" /></form>'."\n";
 
     $studentTable.=&show_grading_menu_form($symb,$url);
     $request->print($studentTable);
@@ -2473,20 +2454,17 @@
     my $getsec    = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
     my $pageTitle = $ENV{'form.page'};
     my (undef,undef,$fullname) = &getclasslist($getsec,'0');
-    my ($uname,$udom) = split(/:/,$ENV{'form.pickOne'});
+    my ($uname,$udom) = split(/:/,$ENV{'form.student'});
     my ($idx,$showtitle) = ($pageTitle =~ /(\d+)\.(.*)/);
 
-    my $result='<h3><font color="#339933">&nbsp;'.$showtitle.'</font></h3>';
-    $result.='<h3>&nbsp;Student: '.$$fullname{$ENV{'form.pickOne'}}.
+    my $result='<h3><font color="#339933">&nbsp;'.$ENV{'form.title'}.'</font></h3>';
+    $result.='<h3>&nbsp;Student: '.$$fullname{$ENV{'form.student'}}.
 	'<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font></h3>'."\n";
 
-    my ($pg_titles,$pg_symbx) = &getSymbMap();
-
     my $navmap = Apache::lonnavmaps::navmap-> new(
 						  $ENV{'request.course.fn'}.'.db',
 						  $ENV{'request.course.fn'}.'_parms.db',1, 1);
-
-    my ($mapUrl, $id, $resUrl) = split(/___/, $$pg_symbx{$ENV{'form.page'}});
+    my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'});
     my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
 
     my $iterator = $navmap->getIterator($map->map_start(),
@@ -2509,11 +2487,7 @@
             my $title = $curRes->compTitle();
 	    push @titles,$minder.'.'.$title; # minder, just in case two titles are identical
 	    if (scalar(@{$parts}) > 1) { shift @{$parts}; }
-	    for my $part (@$parts) {
-		$result.='title='.$title.'part='.$part.':<br>';
-	    }
-	    $parts{$minder.'.'.$title} = join '::',@$parts;
-
+	    $parts{$minder.'.'.$title} = join '::',@{$parts};
             $symbx{$minder.'.'.$title} = $curRes->symb();
 	    $minder++;
 
@@ -2522,52 +2496,101 @@
 	$ctr++;
     }
 
+
     $navmap->init();
     $request->print($result);
+    &sub_page_js($request);
 
-    my $studentTable.=
+    my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
+	'<input type="hidden" name="command"  value="gradePage" />'."\n".
+	'<input type="hidden" name="student"  value="'.$ENV{'form.student'}.'" />'."\n".
+	'<input type="hidden" name="page"  value="'.$pageTitle.'" />'."\n".
+	'<input type="hidden" name="title" value="'.$ENV{'form.title'}.'" />'."\n";
+
+    $studentTable.=
 	'<table border="0"><tr><td bgcolor="#777777">'.
 	'<table border="0"><tr bgcolor="#e6ffff">'.
-	'<td><b>&nbsp;No&nbsp;</b></td>'.
+	'<td align="center"><b>&nbsp;No&nbsp;</b></td>'.
 	'<td><b>&nbsp;Title</b></td>'.
 	'<td><b>&nbsp;Answer</b></td>'.
 	'<td><b>&nbsp;Grade</b></td></tr>';
     my $question=1;
     foreach (@titles) {
 	my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
-	$studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.'</td>';
+	my @parts = split(/::/,$parts{$_});
+	$studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.
+	    (scalar(@parts) == 1 ? '' : '<br>('.scalar(@parts).'&nbsp;parts)').'</td>';
 	$studentTable.='<td valign="top">&nbsp;'.$showtitle.'&nbsp;</td>';
 	$studentTable.='<td>&nbsp;'.
 	    &Apache::loncommon::get_student_answers($symbx{$_},$uname,$udom,$ENV{'request.course.id'}).'</td>';
 
-	my (undef,undef,$requesturl)=split(/___/,$symbx{$_});
-	$requesturl=&Apache::lonnet::clutter($requesturl);
-	my $subresult=&Apache::lonnet::ssi($requesturl,
-					   ('grade_target' => 'analyze'),
-					   ('grade_domain' => $udom),
-					   ('grade_user' => $uname),
-					   ('grade_symb' => $symbx{$_}),
-					   ('grade_courseid' => $ENV{'request.course.id'}));
-	(undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
-	my %analyze=&Apache::lonnet::str2hash($subresult);
-
+	my %record = &Apache::lonnet::restore($symbx{$_},$ENV{'request.course.id'},$udom,$uname);
 	$studentTable.='<td>&nbsp;';
-	while (my($key,$value) = each (%analyze)){
-	    $studentTable.='key='.$key.'->value='.$value.'<br>';
+	foreach my $partid (@parts) {
+	    $studentTable.=&gradeBox($symbx{$_},$uname,$udom,$question,$partid,\%record);
+	    $question++;
 	}
 	$studentTable.='</td></tr>';
-	$question++;
 
     }
 
     $studentTable.='</table></td></tr></table>';
-#    $result.='<form action="/adm/grades" method="post" name="displayPage">'."<br>\n";
-#    $result.='</form>'."\n";
+    $studentTable.='</form>';
 
     $request->print($studentTable);
 
-
     return '';
+}
+
+sub gradeBox {
+    my ($symb,$uname,$udom,$counter,$partid,$record) = @_;
+    my $wgt    = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
+    my $wgtmsg = ($wgt > 0 ? '(problem weight)' : 
+		  '<font color="red">problem weight assigned by computer</font>');
+    $wgt       = ($wgt > 0 ? $wgt : '1');
+    my $score  = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
+		  '' : $$record{'resource.'.$partid.'.awarded'}*$wgt);
+    my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />';
+    $result.='<table border="0"><tr><td><b>Part </b>'.$partid.' <b>Points: </b></td><td>';
+
+    my $ctr = 0;
+    $result.='<table border="0"><tr>';  # display radio buttons in a nice table 10 across
+    while ($ctr<=$wgt) {
+	$result.= '<td><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
+	    'onclick="javascript:writeBox(this.form.GD_BOX'.$counter.'_'.$partid.
+	    ',this.form.GD_SEL'.$counter.'_'.$partid.','.$ctr.
+	    ',this.form.stores'.$counter.'_'.$partid.')" '.
+	    ($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
+	$result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
+	$ctr++;
+    }
+    $result.='</tr></table>';
+    $result.='</td><td>&nbsp;<b>or</b>&nbsp;</td>';
+    $result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
+	($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
+	'onChange="javascript:updateRadio(this.form.RADVAL'.$counter.'_'.$partid.
+	',this.form.GD_BOX'.$counter.'_'.$partid.
+	',this.form.GD_SEL'.$counter.'_'.$partid.
+	',this.form.stores'.$counter.'_'.$partid.
+	','.$wgt.')" /></td>'."\n";
+    $result.='<td>/'.$wgt.' '.$wgtmsg.' </td><td>';
+
+    $result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
+	'onChange="javascript:clearRadBox(this.form.RADVAL'.$counter.'_'.$partid.
+	',this.form.GD_BOX'.$counter.'_'.$partid.
+	',this.form.GD_SEL'.$counter.'_'.$partid.
+	',this.form.stores'.$counter.'_'.$partid.')" >'."\n";
+    if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
+	$result.='<option> </option>'.
+	    '<option selected="on">excused</option></select>';
+    } else {
+	$result.='<option selected="on"> </option>'.
+	    '<option>excused</option></select>';
+    }
+    $result.="&nbsp&nbsp\n";
+    $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="0" />';
+    $result.='</td></tr></table>'."\n";
+    return $result;
 }
 
 #--- Form to input a receipt number ---

--ng1046466388--