--- loncom/homework/grades.pm 2003/01/24 20:40:37 1.67 +++ loncom/homework/grades.pm 2003/02/27 21:05:58 1.68 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.67 2003/01/24 20:40:37 www Exp $ +# $Id: grades.pm,v 1.68 2003/02/27 21:05:58 ng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,6 +31,8 @@ # 8/20 Gerd Kortemeyer # Year 2002 # June-August H.K. Ng +# Year 2003 +# February H.K. Ng # package Apache::grades; @@ -39,12 +41,13 @@ use Apache::style; use Apache::lonxml; use Apache::lonnet; use Apache::loncommon; +use Apache::lonnavmaps; use Apache::lonhomework; use Apache::loncoursedata; use Apache::lonmsg qw(:user_normal_msg); 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.--- sub getpartlist { @@ -269,6 +272,10 @@ sub verifyreceipt { return $string.&show_grading_menu_form($symb,$url); } +# +# Pick student and page/sequence for manual grading + + #--- This is called by a number of programs. #--- Called from the Grading Menu - View/Grade an individual student #--- Also called directly when one clicks on the subm button @@ -293,12 +300,7 @@ sub listStudents { } $result.='</table>'; - my $viewgrade; - if ($ENV{'form.handgrade'} eq 'yes') { - $viewgrade = 'View/Grade'; - } else { - $viewgrade = 'View'; - } + my $viewgrade = $ENV{'form.handgrade'} eq 'yes' ? 'View/Grade' : 'View'; $result='<h3><font color="#339933"> '. $viewgrade. @@ -2198,6 +2200,7 @@ sub gradingmenu { $result.=&view_edit_entire_class_form($symb,$url).'<br />'; $result.=&upcsvScores_form($symb,$url).'<br />'; $result.=&viewGradeaStu_form($symb,$url,$resptype,$hdgrade).'<br />'; + $result.=&gradeByPage_form($symb,$url,$resptype,$hdgrade).'<br />'; $result.=&verifyReceipt_form($symb,$url) if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb)); @@ -2269,12 +2272,7 @@ sub viewGradeaStu_form { my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n"; $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n"; $result.=' <b>'; - if ($handgrade eq 'yes') { - $result.="View/Grade "; - } else { - $result.="View "; - } - $result.='an Individual Student\'s Submission</b></td></tr>'."\n"; + $result.=($handgrade eq 'yes' ? 'View/Grade' : 'View').' an Individual Student\'s Submission</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". @@ -2310,6 +2308,266 @@ sub viewGradeaStu_form { 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.=' <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.=' <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 /> <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"> '. + '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.=' <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.=' <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.=' <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.=' <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> Fullname <font color="#999999">(username)</font></b></td>'. + '<td><b> Fullname <font color="#999999">(username)</font></b></td>'. + '<td><b> Fullname <font color="#999999">(username)</font></b></td>'. + '<td><b> 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> </td><td> </td><td> ' if ($ptr%4 == 2); + $studentTable.='</td><td> </td><td> ' if ($ptr%4 == 3); + $studentTable.='</td><td> ' if ($ptr%4 == 0); + $studentTable.='</td></tr></table></td></tr></table>'."\n"; + $studentTable.='<br /> <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"> '.$showtitle.'</font></h3>'; + $result.='<h3> 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> No </b></td>'. + '<td><b> Title</b></td>'. + '<td><b> Answer</b></td>'. + '<td><b> 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"> '.$showtitle.' </td>'; + $studentTable.='<td> '. + &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> '; + 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 --- sub verifyReceipt_form { my ($symb,$url) = @_; @@ -2397,8 +2655,14 @@ sub handler { } else { $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}); if ($command eq 'submission') { - &listStudents($request) if ($ENV{'form.student'} eq ''); - &submission($request,0,0) if ($ENV{'form.student'} ne ''); + ($ENV{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0)); +# 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') { &processGroup($request); } elsif ($command eq 'gradingmenu') {