Diff for /loncom/homework/grades.pm between versions 1.67 and 1.68

version 1.67, 2003/01/24 20:40:37 version 1.68, 2003/02/27 21:05:58
Line 31 Line 31
 # 8/20 Gerd Kortemeyer  # 8/20 Gerd Kortemeyer
 # Year 2002  # Year 2002
 # June-August H.K. Ng  # June-August H.K. Ng
   # Year 2003
   # February H.K. Ng
 #  #
   
 package Apache::grades;  package Apache::grades;
Line 39  use Apache::style; Line 41  use Apache::style;
 use Apache::lonxml;  use Apache::lonxml;
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::loncommon;  use Apache::loncommon;
   use Apache::lonnavmaps;
 use Apache::lonhomework;  use Apache::lonhomework;
 use Apache::loncoursedata;  use Apache::loncoursedata;
 use Apache::lonmsg qw(:user_normal_msg);  use Apache::lonmsg qw(:user_normal_msg);
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
   
 # ----- These first few routines are general use routines.-----  # ----- These first few routines are general use routines.----
 #  #
 # --- Retrieve the parts that matches stores_\d+ from the metadata file.---  # --- Retrieve the parts that matches stores_\d+ from the metadata file.---
 sub getpartlist {  sub getpartlist {
Line 269  sub verifyreceipt { Line 272  sub verifyreceipt {
     return $string.&show_grading_menu_form($symb,$url);      return $string.&show_grading_menu_form($symb,$url);
 }  }
   
   #
   # Pick student and page/sequence for manual grading
   
   
 #--- This is called by a number of programs.  #--- This is called by a number of programs.
 #--- Called from the Grading Menu - View/Grade an individual student  #--- Called from the Grading Menu - View/Grade an individual student
 #--- Also called directly when one clicks on the subm button   #--- Also called directly when one clicks on the subm button 
Line 293  sub listStudents { Line 300  sub listStudents {
     }      }
     $result.='</table>';      $result.='</table>';
   
     my $viewgrade;      my $viewgrade = $ENV{'form.handgrade'} eq 'yes' ? 'View/Grade' : 'View';
     if ($ENV{'form.handgrade'} eq 'yes') {  
  $viewgrade = 'View/Grade';  
     } else {  
  $viewgrade = 'View';  
     }  
   
     $result='<h3><font color="#339933">&nbsp;'.      $result='<h3><font color="#339933">&nbsp;'.
  $viewgrade.   $viewgrade.
Line 2198  sub gradingmenu { Line 2200  sub gradingmenu {
     $result.=&view_edit_entire_class_form($symb,$url).'<br />';      $result.=&view_edit_entire_class_form($symb,$url).'<br />';
     $result.=&upcsvScores_form($symb,$url).'<br />';      $result.=&upcsvScores_form($symb,$url).'<br />';
     $result.=&viewGradeaStu_form($symb,$url,$resptype,$hdgrade).'<br />';      $result.=&viewGradeaStu_form($symb,$url,$resptype,$hdgrade).'<br />';
       $result.=&gradeByPage_form($symb,$url,$resptype,$hdgrade).'<br />';
     $result.=&verifyReceipt_form($symb,$url)       $result.=&verifyReceipt_form($symb,$url) 
  if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb));   if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb));
     
Line 2269  sub viewGradeaStu_form { Line 2272  sub viewGradeaStu_form {
     my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";      my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
     $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";      $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
     $result.='&nbsp;<b>';      $result.='&nbsp;<b>';
     if ($handgrade eq 'yes') {      $result.=($handgrade eq 'yes' ? 'View/Grade' : 'View').' an Individual Student\'s Submission</b></td></tr>'."\n";
  $result.="View/Grade ";  
     } else {  
  $result.="View ";  
     }  
     $result.='an Individual Student\'s Submission</b></td></tr>'."\n";  
     $result.='<tr bgcolor=#ffffe6><td>'."\n";      $result.='<tr bgcolor=#ffffe6><td>'."\n";
     $result.='<form action="/adm/grades" method="post">'."\n".      $result.='<form action="/adm/grades" method="post">'."\n".
  '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".   '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
Line 2310  sub viewGradeaStu_form { Line 2308  sub viewGradeaStu_form {
     return $result;      return $result;
 }  }
   
   #--- Handgrading problems by page/sequence for each student ---
   sub gradeByPage_form {
       my ($symb,$url,$response,$handgrade) = @_;
       my ($classlist,$sections) = &getclasslist('all','0');
       my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
       $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
       $result.='&nbsp;<b>';
       $result.='Handgrade an Individual Student\'s by Page/Sequence</b></td></tr>'."\n";
       $result.='<tr bgcolor=#ffffe6><td>'."\n";
       $result.='<form action="/adm/grades" method="post">'."\n".
    '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
    '<input type="hidden" name="url" value="'.$url.'" />'."\n".
    '<input type="hidden" name="response" value="'.$response.'" />'."\n".
    '<input type="hidden" name="handgrade" value="'.$handgrade.'" />'."\n".
    '<input type="hidden" name="showgrading" value="yes" />'."\n".
    '<input type="hidden" name="command" value="pickStudentPage" />'."\n";
   
       $result.='&nbsp;<b>Select section:</b> <select name="section">'."\n";
       if (ref($sections)) {
    foreach (sort (@$sections)) {$result.='<option>'.$_.'</option>'."\n";}
       }
       $result.= '<option selected="on">all</select>'."\n";
   
       $result.='<br />&nbsp;<input type="button" onClick="submit();" value="';
       $result.='View/Grade'.'" />'."\n".'</form>'."\n";
       $result.='</td></tr></table>'."\n";
       $result.='</td></tr></table>'."\n";
       return $result;
   }
   
   
   sub pickStudentPage {
       my ($request) = shift;
   
       $request->print(<<LISTJAVASCRIPT);
   <script type="text/javascript" language="javascript">
   
   function checkPickOne(formname) {
       var user = radioSelection(formname.pickOne);
       if (user == null) {
    alert("Please select the student you wish to grade.");
    return;
       }
       formname.submit();
   }
   
   function radioSelection(radioButton) {
       var selection=null;
       for (var i=0; i<radioButton.length; i++) {
           if (radioButton[i].checked) {
               selection=radioButton[i].value;
               return selection;
           }
       }
       return selection;
   }
   </script>
   LISTJAVASCRIPT
   
       my ($symb,$url) = &get_symb_and_url();
       my $cdom      = $ENV{"course.$ENV{'request.course.id'}.domain"};
       my $cnum      = $ENV{"course.$ENV{'request.course.id'}.num"};
       my $getsec    = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
   
       my $result='<h3><font color="#339933">&nbsp;'.
    'Manual Grading by Page or Sequence</font></h3>';
   
       my ($pagepath,$pagename,$type,$mapId) = ($symb =~ /(.*\/)(.*?\.(page|sequence))___(\d+)___/); 
       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";
       my ($titles,$symbx) = &getSymbMap();
   #    shift @$titles; # skip the top level sequence
       foreach (@$titles) {
    my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
    my $check_select = ($showtitle eq $curtitle ? 'selected="on"' : '');
    $result.='<option value="'.$_.'" '.$check_select.'>'.$showtitle.'</option>'."\n";
       }
       $result.= '</select>'."<br>\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";
   #    $result.='&nbsp;<b>Submission Details: </b>'.
   # '<input type="radio" name="lastSub" value="last" checked /> last sub only'."\n".
   # '<input type="radio" name="lastSub" value="all" /> all details'."\n";
       $result.='<input type="hidden" name="section"     value="'.$getsec.'" />'."\n".
    '<input type="hidden" name="command"  value="displayPage" />'."\n".
    '<input type="hidden" name="url"  value="'.$url.'" />'."\n".
    '<input type="hidden" name="symb" value="'.$symb.'" />'."<br><br>\n";
       $request->print($result);
   
       my $studentTable.='&nbsp;<b>Select a Student you wish to grade</b><br>'.
    '<table border="0"><tr><td bgcolor="#777777">'.
    '<table border="0"><tr bgcolor="#e6ffff">'.
    '<td><b>&nbsp;Fullname <font color="#999999">(username)</font></b></td>'.
    '<td><b>&nbsp;Fullname <font color="#999999">(username)</font></b></td>'.
    '<td><b>&nbsp;Fullname <font color="#999999">(username)</font></b></td>'.
    '<td><b>&nbsp;Fullname <font color="#999999">(username)</font></b></td></tr>';
    
       my (undef,undef,$fullname) = &getclasslist($getsec,'0');
       my $ptr = 1;
       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}.
       '<font color="#999999"> ('.$uname.($udom eq $cdom ? '':':'.$udom).')</font>'."\n";
    $studentTable.=($ptr%4 == 0 ? '</td></tr>' : '');
    $ptr++;
       }
       $studentTable.='</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;' if ($ptr%4 == 2);
       $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.=&show_grading_menu_form($symb,$url);
       $request->print($studentTable);
   
       return '';
   }
   
   sub getSymbMap {
       my $navmap = Apache::lonnavmaps::navmap-> new(
     $ENV{'request.course.fn'}.'.db',
     $ENV{'request.course.fn'}.'_parms.db',1, 1);
   
       my $res = $navmap->firstResource(); # temp resource to access constants
       $navmap->init();
   
       # End navmap using boilerplate
   
       my $iterator = $navmap->getIterator(undef, undef, undef, 1);
       my $depth = 1;
       $iterator->next(); # ignore first BEGIN_MAP
       my $curRes = $iterator->next();
   
       my %symbx = ();
       my @titles = ();
       my $minder=0;
       while ($depth > 0) {
           if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
           if ($curRes == $iterator->END_MAP()) { $depth--; }
   
           if (ref($curRes) && $curRes->is_map()) {
               my $title = $curRes->compTitle();
       push @titles,$minder.'.'.$title; # minder, just in case two titles are identical
       $symbx{$minder.'.'.$title} = $curRes->symb();
       $minder++;
          }
           $curRes = $iterator->next();
       }
   
       $navmap->untieHashes();
       return \@titles,\%symbx;
   }
   
   sub displayPage {
       my ($request) = shift;
   
       my $cdom      = $ENV{"course.$ENV{'request.course.id'}.domain"};
       my $cnum      = $ENV{"course.$ENV{'request.course.id'}.num"};
       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 ($idx,$showtitle) = ($pageTitle =~ /(\d+)\.(.*)/);
   
       my $result='<h3><font color="#339933">&nbsp;'.$showtitle.'</font></h3>';
       $result.='<h3>&nbsp;Student: '.$$fullname{$ENV{'form.pickOne'}}.
    '<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 $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
   
       my $iterator = $navmap->getIterator($map->map_start(),
    $map->map_finish());
   
       my $depth = 1;
       $iterator->next(); # skip the first BEGIN_MAP
       my $curRes = $iterator->next(); # for "current resource"
       my %symbx = ();
       my @titles = ();
       my %parts = ();
       my $ctr=0;
       my $minder=0;
       while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop
           if($curRes == $iterator->BEGIN_MAP) { $depth++; }
           if($curRes == $iterator->END_MAP) { $depth++; }
   
           if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
       my $parts = $curRes->parts();
               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;
   
               $symbx{$minder.'.'.$title} = $curRes->symb();
       $minder++;
   
          }
           $curRes = $iterator->next();
    $ctr++;
       }
   
       $navmap->init();
       $request->print($result);
   
       my $studentTable.=
    '<table border="0"><tr><td bgcolor="#777777">'.
    '<table border="0"><tr bgcolor="#e6ffff">'.
    '<td><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>';
    $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 $subresult=&Apache::lonnet::ssi($request->uri,
      ('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);
   
    $studentTable.='<td>&nbsp;';
    while (my($key,$value) = each (%analyze)){
       $studentTable.='key='.$key.'->value='.$value.'<br>';
    }
    $studentTable.='</td></tr>';
    $question++;
   
       }
   
       $studentTable.='</table></td></tr></table>';
   #    $result.='<form action="/adm/grades" method="post" name="displayPage">'."<br>\n";
   #    $result.='</form>'."\n";
   
       $request->print($studentTable);
   
   
       return '';
   }
   
 #--- Form to input a receipt number ---  #--- Form to input a receipt number ---
 sub verifyReceipt_form {  sub verifyReceipt_form {
     my ($symb,$url) = @_;      my ($symb,$url) = @_;
Line 2397  sub handler { Line 2655  sub handler {
     } else {      } else {
  $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});   $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
  if ($command eq 'submission') {   if ($command eq 'submission') {
     &listStudents($request) if ($ENV{'form.student'} eq '');      ($ENV{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
     &submission($request,0,0) if ($ENV{'form.student'} ne '');  # if ($command eq 'submission') {
   #    &listStudents($request) if ($ENV{'form.student'} eq '');
   #    &submission($request,0,0) if ($ENV{'form.student'} ne '');
    } elsif ($command eq 'pickStudentPage') {
       &pickStudentPage($request);
    } elsif ($command eq 'displayPage') {
       &displayPage($request);
  } elsif ($command eq 'processGroup') {   } elsif ($command eq 'processGroup') {
     &processGroup($request);      &processGroup($request);
  } elsif ($command eq 'gradingmenu') {   } elsif ($command eq 'gradingmenu') {

Removed from v.1.67  
changed lines
  Added in v.1.68


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