Diff for /loncom/homework/grades.pm between versions 1.32 and 1.33

version 1.32, 2002/06/26 21:25:31 version 1.33, 2002/06/27 21:34:18
Line 87  sub verifyreceipt { Line 87  sub verifyreceipt {
    }     }
         }          }
         $request->printf('<p>'.$matches." match%s</p>",$matches <= 1 ? '' : 'es');          $request->printf('<p>'.$matches." match%s</p>",$matches <= 1 ? '' : 'es');
   # needs to print who is matched
     }      }
     return '';      return '';
 }  }
Line 183  ENDTABLEST Line 184  ENDTABLEST
   '<input type="radio" name="vProb" value="no" checked> no '.    '<input type="radio" name="vProb" value="no" checked> no '.
   '<input type="radio" name="vProb" value="yes"> yes </td>');    '<input type="radio" name="vProb" value="yes"> yes </td>');
   $request->print('<td>'.    $request->print('<td>'.
   '<input type="radio" name="submission" value="last" checked> last '.    '<input type="radio" name="lastSub" value="last" checked> last '.
   '<input type="radio" name="submission" value="all"> all </td>');    '<input type="radio" name="lastSub" value="all"> all </td>');
   my ($type,$status) = &student_gradeStatus($ENV{'form.url'},$cdom,$sname);    my ($type,$status) = &student_gradeStatus($ENV{'form.url'},$cdom,$sname);
   $request->print(    $request->print(
   '<td align="middle">'.$status.'&nbsp;</td>');    '<td align="middle">'.$status.'&nbsp;</td>');
Line 272  sub viewstudentgrade { Line 273  sub viewstudentgrade {
       my ($status,$foo)=split(/_/,$score,2);        my ($status,$foo)=split(/_/,$score,2);
       $result.="<td align=\"middle\"><select name=\"GRADE.$student.$part.$type\">\n";        $result.="<td align=\"middle\"><select name=\"GRADE.$student.$part.$type\">\n";
       my $optsel = '<option>correct</option><option>incorrect</option><option>excused</option>'.        my $optsel = '<option>correct</option><option>incorrect</option><option>excused</option>'.
   '<option>ungraded</option><option>handgraded</option><option>nothing</option>'."\n";    '<option>ungraded</option><option>partial</option><option>nothing</option>'."\n";
       $status = 'nothing' if ($status eq '');        $status = 'nothing' if ($status eq '');
       $optsel =~ s/<option>$status/<option selected="on">$status/;        $optsel =~ s/<option>$status/<option selected="on">$status/;
       $result.=$optsel;        $result.=$optsel;
Line 338  sub setstudentgrade { Line 339  sub setstudentgrade {
   return $result;    return $result;
 }  }
   
 # --------------------------- show submissions of a student, option to grade --------  
 #  #
   # --------------------------- show submissions of a student, option to grade --------
 sub submission {  sub submission {
   my ($request) = @_;    my ($request) = @_;
   
   $request->print(<<JAVASCRIPT);    $request->print(<<JAVASCRIPT);
 <script type="text/javascript" language="javascript">  <script type="text/javascript" language="javascript">
     function updateRadio() {    function updateRadio(radioButton,formtextbox,formsel,wgt) {
  var pts = document.SCORE.GRADE_BOX.value;       var pts = formtextbox.value;
  var radioButton = document.SCORE.radval;       var resetbox =false;
  var checked  =true;       if (isNaN(pts) || pts < 0) {
  var unchecked=false;   alert("A number equal or greater than 0 is expected. Entered value = "+pts);
  var resetbox =false;   for (var i=0; i<radioButton.length; i++) {
  if (isNaN(pts) || pts < 0) {     if (radioButton[i].checked) {
     alert("A number equal or greater than 0 is expected. Entered value = "+pts);        formtextbox.value = i;
     for (var i=0; i<radioButton.length; i++) {        resetbox = true;
  if (radioButton[i].checked) {     }
     document.SCORE.GRADE_BOX.value = i;  
     resetbox = true;  
  }  
     }  
     if (!resetbox) {  
  document.SCORE.GRADE_BOX.value = "";  
     }  
     return;  
  }   }
    if (!resetbox) {
      formtextbox.value = "";
    }
    return;
       }
   
  for (var i=0; i<radioButton.length; i++) {      for (var i=0; i<radioButton.length; i++) {
     radioButton[i].checked=unchecked;   radioButton[i].checked=false;
     if (pts == i) {   if (pts == i) {
  radioButton[i].checked=checked;     radioButton[i].checked=true;
     }  
  }   }
     }      }
       updateSelect(formsel,pts,wgt);
     }
   
     function writeBox(formrad,formsel,pts,wgt) {
       formrad.value = pts;
       updateSelect(formsel,pts,wgt);
       return;
     }
   
     function updateSelect(formsel,pts,wgt) {
       if (pts == 0) {
         formsel[1].selected = true;
       }
       if (pts > 0 && pts < wgt) {
         formsel[4].selected = true;
       }
       if (pts == wgt) {
         formsel[0].selected = true;
       }
       return;
     }
   
 </script>  </script>
 JAVASCRIPT  JAVASCRIPT
   my $url=$ENV{'form.url'};    (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
   $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 ''; }
     print "formstu=$ENV{'form.student'}:<br>";
   my ($uname,$udom) = &finduser($ENV{'form.student'});    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 ''; }
   
Line 385  JAVASCRIPT Line 404  JAVASCRIPT
 #  #
 # header info  # header info
   my $result='<h2><font color="#339933">Submission Record</font></h2>';    my $result='<h2><font color="#339933">Submission Record</font></h2>';
   $result.='<table border="0"><tr><td><b>Username: </b>'.$uname.'</td><td><b>Fullname: </b>'.$ENV{'form.fullname'}.'</td><td><b>Domain: </b>'.$udom.'</td></tr>';    $result.='<table border="0"><tr><td><b>Username: </b>'.$uname.
         '</td><td><b>Fullname: </b>'.$ENV{'form.fullname'}.'</td><td><b>Domain: </b>'.$udom.'</td></tr>';
   $result.='<tr><td colspan=3><b>Resource: </b>'.$url.'</td></tr></table>';    $result.='<tr><td colspan=3><b>Resource: </b>'.$url.'</td></tr></table>';
 #  #
 # option to display problem  # option to display problem
Line 394  JAVASCRIPT Line 414  JAVASCRIPT
    $ENV{'request.course.id'});     $ENV{'request.course.id'});
       my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,        my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
  $ENV{'request.course.id'});   $ENV{'request.course.id'});
       $result.='<table border="0"><tr><td bgcolor="#777777">';        $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
       $result.='<table border="0"><tr><td bgcolor="#e6ffff">';        $result.='<table border="0" width="100%"><tr><td bgcolor="#e6ffff">';
       $result.='<b>Student\'s view of the problem</b></td></tr><tr><td bgcolor="#ffffff">'.$rendered.'<br />';        $result.='<b>Student\'s view of the problem</b></td></tr><tr><td bgcolor="#ffffff">'.$rendered.'<br />';
       $result.='<b>Correct answer:</b><br />'.$companswer;        $result.='<b>Correct answer:</b><br />'.$companswer;
       $result.='</td></tr></table>';        $result.='</td></tr></table>';
       $result.='</td></tr></table><br />';        $result.='</td></tr></table><br />';
   }    }
   my $last = '';    my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
   $last = 'last' if ($ENV{'form.submission'} eq 'last');  
   my $answer=&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,    my $answer=&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
       $ENV{'request.course.id'},$last);        $ENV{'request.course.id'},$last);
   $result.=$answer;    $result.=$answer;
Line 414  JAVASCRIPT Line 433  JAVASCRIPT
   $result.= '<form action="/adm/grades" method="post" name="SCORE">'."\n".    $result.= '<form action="/adm/grades" method="post" name="SCORE">'."\n".
     '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".      '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
       '<input type="hidden" name="url" value="'.$url.'" />'."\n".        '<input type="hidden" name="url" value="'.$url.'" />'."\n".
  '<input type="hidden" name="command" value="handgrade" />'."\n";          '<input type="hidden" name="vProb" value="'.$ENV{'form.vProb'}.'" />'."\n".
             '<input type="hidden" name="lastSub" value="'.$last.'" />'."\n".
       '<input type="hidden" name="command" value="handgrade" />'."\n".
         '<input type="hidden" name="NCT"'.
           ' value="'.($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1').'" />'."\n";
   
     my $counter = 0;
     $result.='<input type="hidden" name="WGT'.$counter.'" value="'.$wgt.'" />'.
         '<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'.$udom.'" />'."\n";
   $result.='<table border="0"><tr><td><b>Points</b></td><td>';    $result.='<table border="0"><tr><td><b>Points</b></td><td>';
   my $ctr = 0;    my $ctr = 0;
   while ($ctr<=$wgt) {    while ($ctr<=$wgt) {
       $result.= '<input type="radio" name="radval" '.        $result.= '<input type="radio" name="RADVAL'.$counter.'" '.
 #  'onclick="javascript:writeBox(\'GRADE_'.$ENV{'form.student'}.'\',\''.$ctr.'\')" '.    'onclick="javascript:writeBox(this.form.GRADE_BOX'.$counter.
   'onclick="javascript:SCORE.GRADE_BOX.value='.$ctr.'" '.      ',this.form.GRADE_SEL'.$counter.',\''.$ctr.'\',\''.$wgt.'\')" '.
   ($score == $ctr? 'checked':'').' /> '.$ctr."\n";   ($score == $ctr? 'checked':'').' /> '.$ctr."\n";
       $ctr++;        $ctr++;
   }    }
   $result.='</td><td>&nbsp;<b>or</b>&nbsp;</td>';    $result.='</td><td>&nbsp;<b>or</b>&nbsp;</td>';
   $result.='<td><input type="text" name="GRADE_BOX"'.    $result.='<td><input type="text" name="GRADE_BOX'.$counter.'"'.
       ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.        ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
       'onChange="javascript:updateRadio()" /></td>'."\n";           'onChange="javascript:updateRadio(this.form.RADVAL'.$counter.
   $result.='<td>/'.$wgt.' (problem weight)</td></tr>';          ',this.form.GRADE_BOX'.$counter.
      ',this.form.GRADE_SEL'.$counter.',\''.$wgt.'\')" /></td>'."\n";
     $result.='<td>/'.($wgt > 0 ? $wgt.' (problem weight)' : '<font color="red">invalid problem weight</font>' ).
         ' </td><td>';
   
     foreach my $part (&getpartlist($url)) {
       my ($temp,$part,$type)=split(/_/,$part);
       if ($type eq 'solved') {
         my ($status,$foo)=split(/_/,$record{"resource.$part.$type"},2);
         $result.='<select name="GRADE_SEL'.$counter.'">'."\n";
         my $optsel = '<option>correct</option><option>incorrect</option>'.
     '<option>excused</option><option>ungraded</option>'.
         '<option>partial</option><option>nothing</option>'."\n";
         $status = 'nothing' if ($status eq '');
         $optsel =~ s/<option>$status/<option selected="on">$status/;
         $result.=$optsel;
         $result.="</select></td></tr>\n";
       }
     }
   
   $result.='<input type="hidden" name="GRADE_'.$uname.':'.$udom.'" value="handgraded" />'."\n";    $result.='<tr><td colspan="6"><input type="submit" name="gradeOpt" value="Save & Next" />';
   $result.='<tr><td colspan="5"><input type="submit" name="gradeOpt" value="Save & Next" />&nbsp;';    my $ntstu ='<select name="NTSTU">'.
         '<option>1</option><option>2</option>'.
     '<option>3</option><option>5</option>'.
         '<option>7</option><option>10</option></select>'."\n";
     my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
     $ntstu =~ s/<option>$nsel/<option selected="on">$nsel/;
     $result.=$ntstu.'student(s) &nbsp;'."\n <br />";
   $result.='<input type="submit" name="gradeOpt" value="Next" />&nbsp';    $result.='<input type="submit" name="gradeOpt" value="Next" />&nbsp';
   $result.='<input type="submit" name="gradeOpt" value="Previous" />&nbsp';    $result.='<input type="submit" name="gradeOpt" value="Previous" />&nbsp';
     $result.='(Next and Previous do not save the scores.)';
   $result.='</td><tr></table></form>';    $result.='</td><tr></table></form>';
   return $result;    return $result;
 }  }
   
 sub processHandGrade {  sub processHandGrade {
   my ($url,$symb,$courseid,$student,@parts) = @_;    my ($request) = @_;
     my $result='';
   
   my ($stuname,$domain) = split(/:/,$student);    my $url    = $ENV{'form.url'};
   my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$stuname);    my $symb   = $ENV{'form.symb'};
     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 (@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,$score,@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($cdom,$cnum,'0');
   
     my (@nextlist,@prevlist);
     my ($nextflg,$prevflg,$ctr) = (0,0,0);
     foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
         my ($uname,$udom) = split(/:/,$student);
         if ($nextflg == 1 && $button =~ /Next$/) {
     push @nextlist,$uname if ($ctr < $ENV{'form.NTSTU'});
     $ctr++;
         }
         $nextflg = 1 if ($student eq $laststu);
         $prevflg = 1 if ($student eq $firststu);
     }
     foreach my $student (@nextlist) {
         $ENV{'form.student'} = $student;
         $request->print(&submission($request));
     }
     $request->print ("<h2><font color=\"#339933\">Grading</font></h2>");
   
     #get info for each student
     foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
       my $display=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
         print "ID=$ENV{'request.course.id'}:STU=$student:DIS=$display:<br>\n";
   #    $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
     }
   
     return 'The End';
   #  return $result;
   }
   
   sub saveHandGrade {
     my ($url,$symb,$stuname,$domain,$newscore,@parts) = @_;
   
   #  my ($stuname,$domain) = split(/:/,$student);
     my %record=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
   my %newrecord;    my %newrecord;
   
   foreach my $part (@parts) {    foreach my $part (@parts) {
     my ($temp,$part,$type)=split(/_/,$part);      my ($temp,$part,$type)=split(/_/,$part);
     my $oldscore=$record{"resource.$part.$type"};      my $oldscore=$record{"resource.$part.$type"};
     my $newscore=($ENV{'form.GRADE_BOX'} ne '' ? $ENV{"form.GRADE_BOX"} : $ENV{'form.radval'});  
     if ($type eq 'solved') {      if ($type eq 'solved') {
       my $update=0;        my $update=0;
       if ($newscore eq 'nothing' ) {        if ($newscore eq 'nothing' ) {
Line 463  sub processHandGrade { Line 573  sub processHandGrade {
  if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }   if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }
  if ($newscore eq 'excused')   { $newscore = 'excused'; }   if ($newscore eq 'excused')   { $newscore = 'excused'; }
  if ($newscore eq 'ungraded')  { $newscore = 'ungraded_attempted'; }   if ($newscore eq 'ungraded')  { $newscore = 'ungraded_attempted'; }
  if ($newscore eq 'handgraded') { $newscore = 'handgraded_by_grader'; }   if ($newscore eq 'partial')   { $newscore = 'partial_correct'; }
       }        }
       if ($update) { $newrecord{"resource.$part.$type"}=$newscore; }        if ($update) { $newrecord{"resource.$part.$type"}=$newscore; }
     } else {      } else {
       if ($oldscore ne $newscore) {        if ($oldscore ne $newscore) {
  $newrecord{"resource.$part.$type"}=$newscore;   $newrecord{"resource.$part.$type"}=$newscore;
         }
     }      }
   }      if ( scalar(keys(%newrecord)) > 0 ) {
   if ( scalar(keys(%newrecord)) > 0 ) {        $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
     $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";  #      print "grader=$newrecord{'resource.regrader'}:<br>records<br>";
     print "grader=$newrecord{'resource.regrader'}:<br>records<br>";  #      while (my ($k,$v) = each %newrecord) {
     while (my ($k,$v) = each %newrecord) {  # print "k=$k:v=$v:<br>\n";
  print "k=$k:v=$v:<br>\n";  #      }
   #     &Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$stuname);
     }      }
     &Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$stuname);      return '';
   }    }
   return '';  
 }  }
   
 sub get_symb_and_url {  sub get_symb_and_url {
Line 949  sub handler { Line 1060  sub handler {
       $request->print(&gradingmenu($request));        $request->print(&gradingmenu($request));
     } elsif ($command eq 'viewgrades') {      } elsif ($command eq 'viewgrades') {
       $request->print(&viewgrades($request));        $request->print(&viewgrades($request));
       } elsif ($command eq 'handgrade') {
         $request->print(&processHandGrade($request));
     } elsif ($command eq 'editgrades') {      } elsif ($command eq 'editgrades') {
       $request->print(&editgrades($request));        $request->print(&editgrades($request));
     } elsif ($command eq 'verify') {      } elsif ($command eq 'verify') {

Removed from v.1.32  
changed lines
  Added in v.1.33


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>