Annotation of loncom/homework/grades.pm, revision 1.62

1.17      albertel    1: # The LearningOnline Network with CAPA
1.13      albertel    2: # The LON-CAPA Grading handler
1.17      albertel    3: #
1.62    ! albertel    4: # $Id: grades.pm,v 1.61 2002/11/27 15:54:24 albertel Exp $
1.17      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.13      albertel   28: # 2/9,2/13 Guy Albertelli
1.8       www        29: # 6/8 Gerd Kortemeyer
1.13      albertel   30: # 7/26 H.K. Ng
1.14      www        31: # 8/20 Gerd Kortemeyer
1.30      ng         32: # Year 2002
1.44      ng         33: # June-August H.K. Ng
1.30      ng         34: #
1.1       albertel   35: 
                     36: package Apache::grades;
                     37: use strict;
                     38: use Apache::style;
                     39: use Apache::lonxml;
                     40: use Apache::lonnet;
1.3       albertel   41: use Apache::loncommon;
1.1       albertel   42: use Apache::lonhomework;
1.55      matthew    43: use Apache::loncoursedata;
1.38      ng         44: use Apache::lonmsg qw(:user_normal_msg);
1.1       albertel   45: use Apache::Constants qw(:common);
                     46: 
1.44      ng         47: # ----- These first few routines are general use routines.-----
                     48: #
                     49: # --- Retrieve the parts that matches stores_\d+ from the metadata file.---
                     50: sub getpartlist {
                     51:     my ($url) = @_;
                     52:     my @parts =();
                     53:     my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
                     54:     foreach my $key (@metakeys) {
1.54      albertel   55: 	if ( $key =~ m/stores_(\w+)_.*/) {
1.44      ng         56: 	    push(@parts,$key);
1.41      ng         57: 	}
1.16      albertel   58:     }
1.44      ng         59:     return @parts;
1.2       albertel   60: }
                     61: 
1.44      ng         62: # --- Get the symbolic name of a problem and the url
                     63: sub get_symb_and_url {
                     64:     my ($request) = @_;
                     65:     (my $url=$ENV{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.41      ng         66:     my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.44      ng         67:     if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
                     68:     return ($symb,$url);
1.32      ng         69: }
                     70: 
1.44      ng         71: # --- Retrieve the fullname for a user. Return lastname, first middle ---
                     72: # --- Generation is attached next to the lastname if it exists. ---
1.34      ng         73: sub get_fullname {
1.39      ng         74:     my ($uname,$udom) = @_;
1.34      ng         75:     my %name=&Apache::lonnet::get('environment', ['lastname','generation',
1.55      matthew    76: 						  'firstname','middlename'],
                     77:                                   $udom,$uname);
1.34      ng         78:     my $fullname;
                     79:     my ($tmp) = keys(%name);
                     80:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
1.55      matthew    81:         $fullname = &Apache::loncoursedata::ProcessFullName
                     82:             (@name{qw/lastname generation firstname middlename/});
                     83:     } else {
                     84:         &Apache::lonnet::logthis('grades.pm: no name data for '.$uname.
                     85:                                  '@'.$udom.':'.$tmp);
1.34      ng         86:     }
                     87:     return $fullname;
                     88: }
                     89: 
1.44      ng         90: #--- Get the partlist and the response type for a given problem. ---
                     91: #--- Indicate if a response type is coded handgraded or not. ---
1.39      ng         92: sub response_type {
1.41      ng         93:     my ($url) = shift;
                     94:     my $allkeys = &Apache::lonnet::metadata($url,'keys');
                     95:     my %seen = ();
                     96:     my (@partlist,%handgrade);
                     97:     foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
1.54      albertel   98: 	if (/^\w+response_\w+.*/) {
1.41      ng         99: 	    my ($responsetype,$part) = split(/_/,$_,2);
                    100: 	    my ($partid,$respid) = split(/_/,$part);
                    101: 	    $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no');
                    102: 	    next if ($seen{$partid} > 0);
                    103: 	    $seen{$partid}++;
                    104: 	    push @partlist,$partid;
                    105: 	}
                    106:     }
                    107:     return \@partlist,\%handgrade;
1.39      ng        108: }
                    109: 
1.44      ng        110: #--- Dumps the class list with usernames,list of sections,
                    111: #--- section, ids and fullnames for each user.
                    112: sub getclasslist {
                    113:     my ($getsec,$hideexpired) = @_;
1.56      matthew   114:     my $classlist=&Apache::loncoursedata::get_classlist();
1.49      albertel  115:     # Bail out if we were unable to get the classlist
1.56      matthew   116:     return if (! defined($classlist));
                    117:     #
                    118:     my %sections;
                    119:     my %fullnames;
                    120:     foreach (keys(%$classlist)) {
                    121:         # the following undefs are for 'domain', and 'username' respectively.
                    122: 	my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
                    123:             @{$classlist->{$_}};
1.44      ng        124: 	# still a student?
1.56      matthew   125: 	if (($hideexpired) && ($status ne 'Active')) {
                    126:             delete ($classlist->{$_});
                    127:             next;
                    128:         }
1.44      ng        129: 	$section = ($section ne '' ? $section : 'no');
                    130: 	if ($getsec eq 'all' || $getsec eq $section) {
1.56      matthew   131:             $sections{$section}++;
                    132:             $fullnames{$_}=$fullname;
                    133:         } else {
                    134:             delete($classlist->{$_});
                    135:         }
1.44      ng        136:     }
                    137:     my %seen = ();
1.56      matthew   138:     my @sections = sort(keys(%sections));
                    139:     return ($classlist,\@sections,\%fullnames);
1.44      ng        140: }
                    141: 
                    142: #find user domain
                    143: sub finduser {
                    144:     my ($name) = @_;
                    145:     my $domain = '';
                    146:     if ( $Apache::grades::viewgrades eq 'F' ) {
                    147: 	my %classlist=&Apache::lonnet::dump('classlist',
                    148: 					    $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    149: 					    $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    150: 	my (@fields) = grep /^$name:/, keys %classlist;
                    151: 	($name, $domain) = split(/:/,$fields[0]);
                    152: 	return ($name,$domain);
                    153:     } else {
                    154: 	return ($ENV{'user.name'},$ENV{'user.domain'});
                    155:     }
                    156: }
                    157: 
                    158: #--- Prompts a user to enter a username.
                    159: sub moreinfo {
                    160:     my ($request,$reason) = @_;
                    161:     $request->print("Unable to process request: $reason");
                    162:     if ( $Apache::grades::viewgrades eq 'F' ) {
                    163: 	$request->print('<form action="/adm/grades" method="post">'."\n");
                    164: 	if ($ENV{'form.url'}) {
                    165: 	    $request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />'."\n");
                    166: 	}
                    167: 	if ($ENV{'form.symb'}) {
                    168: 	    $request->print('<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />'."\n");
                    169: 	}
                    170: 	$request->print('<input type="hidden" name="command" value="'.$ENV{'form.command'}.'" />'."\n");
                    171: 	$request->print("Student:".'<input type="text" name="student" value="'.$ENV{'form.student'}.'" />'."<br />\n");
                    172: 	$request->print("Domain:".'<input type="text" name="domain" value="'.$ENV{'user.domain'}.'" />'."<br />\n");
                    173: 	$request->print('<input type="submit" name="submit" value="ReSubmit" />'."<br />\n");
                    174: 	$request->print('</form>');
                    175:     }
                    176:     return '';
                    177: }
                    178: 
                    179: #--- Retrieve the grade status of a student for all the parts
                    180: sub student_gradeStatus {
                    181:     my ($url,$symb,$udom,$uname,$partlist) = @_;
                    182:     my %record     = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
                    183:     my %partstatus = ();
                    184:     foreach (@$partlist) {
                    185: 	my ($status,$foo)    = split(/_/,$record{"resource.$_.solved"},2);
                    186: 	$status              = 'nothing' if ($status eq '');
                    187: 	$partstatus{$_}      = $status;
                    188: 	my $subkey           = "resource.$_.submitted_by";
                    189: 	$partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
                    190:     }
                    191:     return %partstatus;
                    192: }
                    193: 
1.45      ng        194: # hidden form and javascript that calls the form
                    195: # Use by verifyscript and viewgrades
                    196: # Shows a student's view of problem and submission
                    197: sub jscriptNform {
                    198:     my ($url,$symb) = @_;
                    199:     my $jscript='<script type="text/javascript" language="javascript">'."\n".
                    200: 	'    function viewOneStudent(user,domain) {'."\n".
                    201: 	'	document.onestudent.student.value = user;'."\n".
                    202: 	'	document.onestudent.userdom.value = domain;'."\n".
                    203: 	'	document.onestudent.submit();'."\n".
                    204: 	'    }'."\n".
                    205: 	'</script>'."\n";
                    206:     $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
                    207: 	'<input type="hidden" name="symb"    value="'.$symb.'" />'."\n".
                    208: 	'<input type="hidden" name="url"     value="'.$url.'" />'."\n".
                    209: 	'<input type="hidden" name="command" value="submission" />'."\n".
                    210: 	'<input type="hidden" name="student" value="" />'."\n".
                    211: 	'<input type="hidden" name="userdom" value="" />'."\n".
                    212: 	'</form>'."\n";
                    213:     return $jscript;
                    214: }
1.39      ng        215: 
1.44      ng        216: #------------------ End of general use routines --------------------
                    217: #-------------------------------------------------------------------
                    218: 
                    219: #------------------------------------ Receipt Verification Routines
1.45      ng        220: #
1.44      ng        221: #--- Check whether a receipt number is valid.---
                    222: sub verifyreceipt {
                    223:     my $request  = shift;
                    224: 
                    225:     my $courseid = $ENV{'request.course.id'};
                    226:     my $receipt  = unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
                    227: 	$ENV{'form.receipt'};
                    228:     $receipt     =~ s/[^\-\d]//g;
                    229:     my $url      = $ENV{'form.url'};
                    230:     my $symb     = $ENV{'form.symb'};
                    231:     unless ($symb) {
                    232: 	$symb    = &Apache::lonnet::symbread($url);
                    233:     }
                    234: 
1.45      ng        235:     my $title.='<h3><font color="#339933">Verifying Submission Receipt '.
                    236: 	$receipt.'</h3></font>'."\n".
1.44      ng        237: 	'<font size=+1><b>Resource: </b>'.$ENV{'form.url'}.'</font><br><br>'."\n";
                    238: 
                    239:     my ($string,$contents,$matches) = ('','',0);
1.56      matthew   240:     my (undef,undef,$fullname) = &getclasslist('all','0');
                    241: 
1.53      albertel  242:     foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.44      ng        243: 	my ($uname,$udom)=split(/\:/);
                    244: 	if ($receipt eq 
                    245: 	    &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
                    246: 	    $contents.='<tr bgcolor="#ffffe6"><td>&nbsp;'."\n".
                    247: 		'<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
                    248: 		'\')"; TARGET=_self>'.$$fullname{$_}.'</a>&nbsp;</td>'."\n".
                    249: 		'<td>&nbsp;'.$uname.'&nbsp;</td>'.
                    250: 		'<td>&nbsp;'.$udom.'&nbsp;</td></tr>'."\n";
                    251: 	    
                    252: 	    $matches++;
                    253: 	}
                    254:     }
                    255:     if ($matches == 0) {
                    256: 	$string = $title.'No match found for the above receipt.';
                    257:     } else {
1.45      ng        258: 	$string = &jscriptNform($url,$symb).$title.
1.44      ng        259: 	    'The above receipt matches the following student'.
                    260: 	    ($matches <= 1 ? '.' : 's.')."\n".
                    261: 	    '<table border="0"><tr><td bgcolor="#777777">'."\n".
                    262: 	    '<table border="0"><tr bgcolor="#e6ffff">'."\n".
                    263: 	    '<td><b>&nbsp;Fullname&nbsp;</b></td>'."\n".
                    264: 	    '<td><b>&nbsp;Username&nbsp;</b></td>'."\n".
                    265: 	    '<td><b>&nbsp;Domain&nbsp;</b></td></tr>'."\n".
                    266: 	    $contents.
                    267: 	    '</table></td></tr></table>'."\n";
                    268:     }
1.50      albertel  269:     return $string.&show_grading_menu_form($symb,$url);
1.44      ng        270: }
                    271: 
                    272: #--- This is called by a number of programs.
                    273: #--- Called from the Grading Menu - View/Grade an individual student
                    274: #--- Also called directly when one clicks on the subm button 
                    275: #    on the problem page.
1.30      ng        276: sub listStudents {
1.41      ng        277:     my ($request) = shift;
1.49      albertel  278: 
                    279:     my ($symb,$url) = &get_symb_and_url();
                    280:     my $cdom      = $ENV{"course.$ENV{'request.course.id'}.domain"};
                    281:     my $cnum      = $ENV{"course.$ENV{'request.course.id'}.num"};
                    282:     my $getsec    = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
                    283:     my $submitonly= $ENV{'form.submitonly'} eq '' ? 'all' : $ENV{'form.submitonly'};
                    284: 
                    285:     my $result;
                    286:     my ($partlist,$handgrade) = &response_type($url);
                    287:     for (sort keys(%$handgrade)) {
                    288: 	my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
                    289: 	$ENV{'form.handgrade'} = 'yes' if ($handgrade eq 'yes');
                    290: 	$result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
                    291: 	    '<td><b>Type: </b>'.$responsetype.'</td>'.
                    292: 	    '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
                    293:     }
                    294:     $result.='</table>';
                    295: 
                    296:     my $viewgrade;
                    297:     if ($ENV{'form.handgrade'} eq 'yes') {
                    298: 	$viewgrade = 'View/Grade';
                    299:     } else {
                    300: 	$viewgrade = 'View';
                    301:     }
                    302: 
                    303:     $result='<h3><font color="#339933">&nbsp;'.
                    304: 	$viewgrade.
                    305: 	    ' Submissions for a Student or a Group of Students</font></h3>'.
                    306: 		'<table border="0"><tr><td colspan=3><font size=+1>'.
                    307: 		    '<b>Resource: </b>'.$url.'</font></td></tr>'.$result;
                    308: 
1.45      ng        309:     $request->print(<<LISTJAVASCRIPT);
                    310: <script type="text/javascript" language="javascript">
                    311:   function checkSelect(checkBox) {
                    312:     var ctr=0;
1.46      ng        313:     var sense="";
1.45      ng        314:     if (checkBox.length > 1) {
                    315:        for (var i=0; i<checkBox.length; i++) {
                    316: 	  if (checkBox[i].checked) {
                    317: 	     ctr++;
                    318: 	  }
                    319:        }
1.46      ng        320:        sense = "a student or group of students";
1.45      ng        321:     } else {
                    322:        if (checkBox.checked) {
                    323: 	   ctr = 1;
                    324:        }
1.46      ng        325:        sense = "the student";
1.45      ng        326:     }
                    327:     if (ctr == 0) {
1.49      albertel  328:        alert("Please select "+sense+" before clicking on the $viewgrade button.");
1.45      ng        329:        return false;
                    330:     }
                    331:     document.gradesub.submit();
                    332:   }
                    333: </script>
                    334: LISTJAVASCRIPT
                    335: 
1.41      ng        336:     $request->print($result);
1.39      ng        337: 
1.45      ng        338:     my $checkhdgrade = $ENV{'form.handgrade'} eq 'yes' ? 'checked' : '';
                    339:     my $checklastsub = $ENV{'form.handgrade'} eq 'yes' ? '' : 'checked';
1.44      ng        340: 
1.45      ng        341:     my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'."\n".
1.58      albertel  342: 	'&nbsp;<b>View Problem: </b><input type="radio" name="vProb" value="no" /> no '."\n".
                    343: 	'<input type="radio" name="vProb" value="yes" checked /> one student '."\n".
                    344: 	'<input type="radio" name="vProb" value="all" /> all students <br />'."\n".
1.49      albertel  345: 	'&nbsp;<b>Submissions: </b>'."\n";
                    346:     if ($ENV{'form.handgrade'} eq 'yes') {
                    347: 	$gradeTable.='<input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> handgrade only'."\n";
                    348:     }
                    349:     $gradeTable.='<input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last sub only'."\n".
1.45      ng        350: 	'<input type="radio" name="lastSub" value="last" /> last sub & parts info'."\n".
                    351: 	'<input type="radio" name="lastSub" value="all" /> all details'."\n".
                    352: 	'<input type="hidden" name="section"     value="'.$getsec.'" />'."\n".
                    353: 	'<input type="hidden" name="submitonly"  value="'.$submitonly.'" />'."\n".
                    354: 	'<input type="hidden" name="response"    value="'.$ENV{'form.response'}.'" />'."\n".
1.62    ! albertel  355: 	'<input type="hidden" name="handgrade": #falue="'.$ENV{'form.handgrade'}.'" /><br />'."\n".
1.45      ng        356: 	'<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" /><br />'."\n".
1.48      albertel  357: 	'<input type="hidden" name="url"  value="'.$url.'" />'."\n".
                    358: 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.49      albertel  359: 	'To '.lc($viewgrade).' a submission, click on the check box next to the student\'s name. Then '."\n".
                    360: 	'click on the '.$viewgrade.' button. To view the submissions for a group of students, click'."\n".
1.45      ng        361: 	' on the check boxes for the group of students.<br />'."\n".
                    362: 	'<input type="hidden" name="command" value="processGroup" />'."\n".
                    363: 	'<input type="button" '."\n".
                    364: 	'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1.49      albertel  365: 	'value="'.$viewgrade.'" />'."\n";
1.45      ng        366:  
1.56      matthew   367:     my (undef,undef,$fullname) = &getclasslist($getsec,'0');
1.41      ng        368:     
1.45      ng        369:     $gradeTable.='<table border="0"><tr><td bgcolor="#777777">'.
1.41      ng        370: 	'<table border="0"><tr bgcolor="#e6ffff">'.
1.44      ng        371: 	'<td><b>&nbsp;Select&nbsp;</b></td><td><b>&nbsp;Fullname&nbsp;</b></td>'.
                    372: 	'<td><b>&nbsp;Username&nbsp;</b></td><td><b>&nbsp;Domain&nbsp;</b></td>';
1.41      ng        373:     foreach (sort(@$partlist)) {
1.45      ng        374: 	$gradeTable.='<td><b>&nbsp;Part '.(split(/_/))[0].' Status&nbsp;</b></td>';
1.41      ng        375:     }
1.45      ng        376:     $gradeTable.='</tr>'."\n";
1.41      ng        377: 
1.45      ng        378:     my $ctr = 0;
1.53      albertel  379:     foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.41      ng        380: 	my ($uname,$udom) = split(/:/,$student);
1.48      albertel  381: 	my (%status) =&student_gradeStatus($url,$symb,$udom,$uname,$partlist);
1.41      ng        382: 	my $statusflg = '';
                    383: 	foreach (keys(%status)) {
                    384: 	    $statusflg = 1 if ($status{$_} ne 'nothing');
1.43      ng        385: 	    my ($foo,$partid,$foo1) = split(/\./,$_);
1.41      ng        386: 	    if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
                    387: 		$statusflg = '';
1.45      ng        388: 		$gradeTable.='<input type="hidden" name="'.
                    389: 		    $student.':submitted_by" value="'.
                    390: 		    $status{'resource.'.$partid.'.submitted_by'}.'" />';
1.41      ng        391: 	    }
                    392: 	}
                    393: 	next if ($statusflg eq '' && $submitonly eq 'yes');
1.34      ng        394: 
1.45      ng        395: 	$ctr++;
1.41      ng        396: 	if ( $Apache::grades::viewgrades eq 'F' ) {
1.45      ng        397: 	    $gradeTable.='<tr bgcolor="#ffffe6">'.
1.41      ng        398: 		'<td align="center"><input type=checkbox name="stuinfo" value="'.
                    399: 		$student.':'.$$fullname{$student}.'"></td>'."\n".
1.44      ng        400: 		'<td>&nbsp;'.$$fullname{$student}.'&nbsp;</td>'."\n".
1.41      ng        401: 		'<td>&nbsp;'.$uname.'&nbsp;</td>'."\n".
                    402: 		'<td align="middle">&nbsp;'.$udom.'&nbsp;</td>'."\n";
                    403: 	    
                    404: 	    foreach (sort keys(%status)) {
                    405: 		next if (/^resource.*?submitted_by$/);
1.45      ng        406: 		$gradeTable.='<td align="middle">&nbsp;'.$status{$_}.'&nbsp;</td>'."\n";
1.41      ng        407: 	    }
1.45      ng        408: 	    $gradeTable.='</tr>'."\n";
1.41      ng        409: 	}
                    410:     }
1.45      ng        411:     $gradeTable.='</table></td></tr></table>'.
                    412: 	'<input type="button" '.
                    413: 	'onClick="javascript:checkSelect(this.form.stuinfo);" '.
1.50      albertel  414: 	'value="'.$viewgrade.'" /></form>'."\n";
1.45      ng        415:     if ($ctr == 0) {
                    416: 	$gradeTable='<br />&nbsp;<font color="red">'.
                    417: 	    'No submission found for this resource.</font><br />';
1.46      ng        418:     } elsif ($ctr == 1) {
                    419: 	$gradeTable =~ s/type=checkbox/type=checkbox checked/;
1.45      ng        420:     }
1.50      albertel  421:     $gradeTable.=&show_grading_menu_form($symb,$url);
1.45      ng        422:     $request->print($gradeTable);
1.44      ng        423:     return '';
1.10      ng        424: }
                    425: 
1.44      ng        426: #---- Called from the listStudents routine
                    427: #     Displays the submissions for one student or a group of students
1.34      ng        428: sub processGroup {
1.41      ng        429:     my ($request)  = shift;
                    430:     my $ctr        = 0;
                    431:     my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
                    432: 		      : ($ENV{'form.stuinfo'}));
                    433:     my $total      = scalar(@stuchecked)-1;
1.45      ng        434: 
1.41      ng        435:     foreach (@stuchecked) {
                    436: 	my ($uname,$udom,$fullname) = split(/:/);
1.44      ng        437: 	$ENV{'form.student'}        = $uname;
                    438: 	$ENV{'form.userdom'}        = $udom;
                    439: 	$ENV{'form.fullname'}       = $fullname;
1.41      ng        440: 	&submission($request,$ctr,$total);
                    441: 	$ctr++;
                    442:     }
                    443:     return '';
1.35      ng        444: }
1.34      ng        445: 
1.44      ng        446: #------------------------------------------------------------------------------------
                    447: #
                    448: #-------------------------- Next few routines handles grading by student, essentially
                    449: #                           handles essay response type problem/part
                    450: #
                    451: #--- Javascript to handle the submission page functionality ---
                    452: sub sub_page_js {
                    453:     my $request = shift;
                    454:     $request->print(<<SUBJAVASCRIPT);
                    455: <script type="text/javascript" language="javascript">
                    456:   function updateRadio(radioButton,formtextbox,formsel,scores,weight) {
                    457:      var pts = formtextbox.value;
                    458:      var resetbox =false;
                    459:      if (isNaN(pts) || pts < 0) {
                    460:         alert("A number equal or greater than 0 is expected. Entered value = "+pts);
                    461:         for (var i=0; i<radioButton.length; i++) {
                    462:            if (radioButton[i].checked) {
                    463: 	      formtextbox.value = i;
                    464: 	      resetbox = true;
                    465: 	   }
                    466: 	}
                    467: 	if (!resetbox) {
                    468: 	   formtextbox.value = "";
                    469: 	}
                    470: 	return;
                    471:      }
1.13      albertel  472: 
1.44      ng        473:      if (pts > weight) {
                    474:         var resp = confirm("You entered a value ("+pts+
                    475:       		     ") greater than the weight for the part. Accept?");
                    476:         if (resp == false) {
                    477:            formtextbox.value = "";
                    478:            return;
                    479:        }
1.41      ng        480:     }
1.5       albertel  481: 
1.44      ng        482:     for (var i=0; i<radioButton.length; i++) {
                    483: 	radioButton[i].checked=false;
                    484: 	if (pts == i) {
                    485: 	   radioButton[i].checked=true;
1.41      ng        486: 	}
                    487:     }
1.44      ng        488:     updateSelect(formsel);
                    489:     scores.value = "0";
                    490:   }
                    491: 
                    492:   function writeBox(formrad,formsel,pts,scores) {
                    493:     formrad.value = pts;
                    494:     scores.value = "0";
                    495:     updateSelect(formsel,pts);
                    496:     return;
                    497:   }
1.5       albertel  498: 
1.44      ng        499:   function clearRadBox(radioButton,formbox,formsel,scores) {
                    500:     for (var i=0; i<formsel.length; i++) {
                    501: 	if (formsel[i].selected) {
                    502: 	    var selectx=i;
1.41      ng        503: 	}
1.13      albertel  504:     }
1.44      ng        505:     if (selectx == scores.value) { return };
                    506:     formbox.value = "";
                    507:     for (var i=0; i<radioButton.length; i++) {
                    508: 	radioButton[i].checked=false;
1.41      ng        509:     }
1.44      ng        510:     scores.value = selectx;
                    511:   }
1.33      ng        512: 
1.44      ng        513:   function updateSelect(formsel) {
                    514:     formsel[0].selected = true;
                    515:     return;
                    516:   }
                    517: 
1.45      ng        518: //=================== Check that a point is assigned for all the parts  ==============
                    519:   function checksubmit(val,total,parttot) {
                    520:      document.SCORE.gradeOpt.value = val;
                    521:      if (val == "Save & Next") {
                    522: 	for (i=0;i<=total;i++) {
                    523: 	   for (j=0;j<parttot;j++) {
                    524: 	      var partid = eval("document.SCORE.partid"+i+"_"+j+".value");
                    525: 	      var selopt = eval("document.SCORE.GD_SEL"+i+"_"+partid);
                    526: 	      if (selopt[0].selected) {
                    527: 		 var points = eval("document.SCORE.GD_BOX"+i+"_"+partid+".value");
                    528: 		 if (points == "") {
                    529: 		     var name = eval("document.SCORE.name"+i+".value");
1.46      ng        530: 		     alert("Please assign a score for "+name+", part "+partid+".");
1.45      ng        531: 		     return false;
                    532: 		 }
                    533: 	      }
                    534: 
                    535: 	  }
                    536:        }
                    537: 
                    538:      }
                    539:      document.SCORE.submit();
                    540:  }
                    541: 
1.44      ng        542: //===================== Show list of keywords ====================
                    543:   function keywords(keyform) {
                    544:     var keywds = keyform.value;
                    545:     var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keywds);
                    546:     if (nret==null) return;
                    547:     keyform.value = nret;
                    548: 
                    549:     document.SCORE.refresh.value = "on";
                    550:     if (document.SCORE.keywords.value != "") {
                    551: 	document.SCORE.submit();
                    552:     }
                    553:     return;
                    554:   }
                    555: 
                    556: //===================== Script to view submitted by ==================
                    557:   function viewSubmitter(submitter) {
                    558:     document.SCORE.refresh.value = "on";
                    559:     document.SCORE.NCT.value = "1";
                    560:     document.SCORE.unamedom0.value = submitter;
                    561:     document.SCORE.submit();
                    562:     return;
                    563:   }
                    564: 
                    565: //===================== Script to add keyword(s) ==================
                    566:   function getSel() {
                    567:     if (document.getSelection) txt = document.getSelection();
                    568:     else if (document.selection) txt = document.selection.createRange().text;
                    569:     else return;
                    570:     var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
                    571:     if (cleantxt=="") {
1.46      ng        572: 	alert("Please select a word or group of words from document and then click this link.");
1.44      ng        573: 	return;
                    574:     }
                    575:     var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
                    576:     if (nret==null) return;
                    577:     var curlist = document.SCORE.keywords.value;
                    578:     document.SCORE.keywords.value = curlist+" "+nret;
                    579:     document.SCORE.refresh.value = "on";
                    580:     if (document.SCORE.keywords.value != "") {
                    581: 	document.SCORE.submit();
                    582:     }
                    583:     return;
                    584:   }
                    585: 
                    586: //====================== Script for composing message ==============
                    587:   function msgCenter(msgform,usrctr,fullname) {
                    588:     var Nmsg  = msgform.savemsgN.value;
                    589:     savedMsgHeader(Nmsg,usrctr,fullname);
                    590:     var subject = msgform.msgsub.value;
                    591:     var rtrchk  = eval("document.SCORE.includemsg"+usrctr);
                    592:     var msgchk = rtrchk.value;
                    593:     re = /msgsub/;
                    594:     var shwsel = "";
                    595:     if (re.test(msgchk)) { shwsel = "checked" }
                    596:     displaySubject(subject,shwsel);
                    597:     for (var i=1; i<=Nmsg; i++) {
                    598: 	var testpt = "savemsg"+i+",";
                    599: 	re = /testpt/;
                    600: 	shwsel = "";
                    601: 	if (re.test(msgchk)) { shwsel = "checked" }
                    602: 	var message = eval("document.SCORE.savemsg"+i+".value");
                    603: 	displaySavedMsg(i,message,shwsel);
                    604:     }
                    605:     newmsg = eval("document.SCORE.newmsg"+usrctr+".value");
                    606:     shwsel = "";
                    607:     re = /newmsg/;
                    608:     if (re.test(msgchk)) { shwsel = "checked" }
                    609:     newMsg(newmsg,shwsel);
                    610:     msgTail(); 
                    611:     return;
                    612:   }
                    613: 
                    614:   function savedMsgHeader(Nmsg,usrctr,fullname) {
                    615:     var height = 30*Nmsg+250;
                    616:     var scrollbar = "no";
                    617:     if (height > 600) {
                    618: 	height = 600;
                    619: 	scrollbar = "yes";
                    620:     }
                    621: /*    if (window.pWin)
                    622: 	window.pWin.close(); */
                    623:     pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx=70,screeny=75,width=600,height='+height);
                    624:     pWin.document.write("<html><head>");
                    625:     pWin.document.write("<title>Message Central</title>");
                    626: 
                    627:     pWin.document.write("<script language=javascript>");
                    628:     pWin.document.write("function checkInput() {");
                    629:     pWin.document.write("  opener.document.SCORE.msgsub.value = document.msgcenter.msgsub.value;");
                    630:     pWin.document.write("  var nmsg   = opener.document.SCORE.savemsgN.value;");
                    631:     pWin.document.write("  var usrctr = document.msgcenter.usrctr.value;");
                    632:     pWin.document.write("  var newval = eval(\\"opener.document.SCORE.newmsg\\"+usrctr);");
                    633:     pWin.document.write("  newval.value = document.msgcenter.newmsg.value;");
                    634: 
                    635:     pWin.document.write("  var msgchk = \\"\\";");
                    636:     pWin.document.write("  if (document.msgcenter.subchk.checked) {");
                    637:     pWin.document.write("     msgchk = \\"msgsub,\\";");
                    638:     pWin.document.write("  }");
                    639:     pWin.document.write(   "for (var i=1; i<=nmsg; i++) {");
                    640:     pWin.document.write("      var opnmsg = eval(\\"opener.document.SCORE.savemsg\\"+i);");
                    641:     pWin.document.write("      var frmmsg = eval(\\"document.msgcenter.msg\\"+i);");
                    642:     pWin.document.write("      opnmsg.value = frmmsg.value;");
                    643:     pWin.document.write("      var chkbox = eval(\\"document.msgcenter.msgn\\"+i);");
                    644:     pWin.document.write("      if (chkbox.checked) {");
                    645:     pWin.document.write("         msgchk += \\"savemsg\\"+i+\\",\\";");
                    646:     pWin.document.write("      }");
                    647:     pWin.document.write("  }");
                    648:     pWin.document.write("  if (document.msgcenter.newmsgchk.checked) {");
                    649:     pWin.document.write("     msgchk += \\"newmsg\\"+usrctr;");
                    650:     pWin.document.write("  }");
                    651:     pWin.document.write("  var includemsg = eval(\\"opener.document.SCORE.includemsg\\"+usrctr);");
                    652:     pWin.document.write("  includemsg.value = msgchk;");
                    653: 
                    654:     pWin.document.write("  self.close()");
                    655: 
                    656:     pWin.document.write("}");
                    657: 
                    658:     pWin.document.write("<");
                    659:     pWin.document.write("/script>");
                    660: 
                    661:     pWin.document.write("</head><body bgcolor=white>");
                    662: 
                    663:     pWin.document.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
                    664:     pWin.document.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
                    665:     pWin.document.write("<font color=\\"green\\" size=+1>&nbsp;Compose Message for \"+fullname+\"</font><br><br>");
                    666: 
                    667:     pWin.document.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
                    668:     pWin.document.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
                    669:     pWin.document.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
                    670: }
                    671:     function displaySubject(msg,shwsel) {
                    672:     pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
                    673:     pWin.document.write("<td>Subject</td>");
                    674:     pWin.document.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1.62    ! albertel  675:     pWin.document.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.44      ng        676: }
                    677: 
                    678: function displaySavedMsg(ctr,msg,shwsel) {
                    679:     pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
                    680:     pWin.document.write("<td align=\\"center\\">"+ctr+"</td>");
                    681:     pWin.document.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
1.62    ! albertel  682:     pWin.document.write("<td><input name=\\"msg"+ctr+"\\" type=\\"text\\" value=\\""+msg+"\\" size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.44      ng        683: }
                    684: 
                    685:   function newMsg(newmsg,shwsel) {
                    686:     pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
                    687:     pWin.document.write("<td align=\\"center\\">New</td>");
                    688:     pWin.document.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1.62    ! albertel  689:     pWin.document.write("<td><input name=\\"newmsg\\" type=\\"text\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" value=\\""+newmsg+"\\" size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.44      ng        690: }
                    691: 
                    692:   function msgTail() {
                    693:     pWin.document.write("</table>");
                    694:     pWin.document.write("</td></tr></table>&nbsp;");
                    695:     pWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\">&nbsp;&nbsp;");
                    696:     pWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
                    697:     pWin.document.write("</form>");
                    698:     pWin.document.write("</body></html>");
                    699: }
                    700: 
                    701: //====================== Script for keyword highlight options ==============
                    702:   function kwhighlight() {
                    703:     var kwclr    = document.SCORE.kwclr.value;
                    704:     var kwsize   = document.SCORE.kwsize.value;
                    705:     var kwstyle  = document.SCORE.kwstyle.value;
                    706:     var redsel = "";
                    707:     var grnsel = "";
                    708:     var blusel = "";
                    709:     if (kwclr=="red")   {var redsel="checked"};
                    710:     if (kwclr=="green") {var grnsel="checked"};
                    711:     if (kwclr=="blue")  {var blusel="checked"};
                    712:     var sznsel = "";
                    713:     var sz1sel = "";
                    714:     var sz2sel = "";
                    715:     if (kwsize=="0")  {var sznsel="checked"};
                    716:     if (kwsize=="+1") {var sz1sel="checked"};
                    717:     if (kwsize=="+2") {var sz2sel="checked"};
                    718:     var synsel = "";
                    719:     var syisel = "";
                    720:     var sybsel = "";
                    721:     if (kwstyle=="")    {var synsel="checked"};
                    722:     if (kwstyle=="<i>") {var syisel="checked"};
                    723:     if (kwstyle=="<b>") {var sybsel="checked"};
                    724:     highlightCentral();
                    725:     highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
                    726:     highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
                    727:     highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
                    728:     highlightend();
                    729:     return;
                    730:   }
                    731: 
                    732: 
                    733:   function highlightCentral() {
                    734:     hwdWin = window.open('', 'KeywordHighlightCentral', 'toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx=100,screeny=75');
                    735:     hwdWin.document.write("<html><head>");
                    736:     hwdWin.document.write("<title>Highlight Central</title>");
                    737: 
                    738:     hwdWin.document.write("<script language=javascript>");
                    739:     hwdWin.document.write("function updateChoice(flag) {");
                    740:     hwdWin.document.write("  opener.document.SCORE.kwclr.value = radioSelection(document.hlCenter.kwdclr);");
                    741:     hwdWin.document.write("  opener.document.SCORE.kwsize.value = radioSelection(document.hlCenter.kwdsize);");
                    742:     hwdWin.document.write("  opener.document.SCORE.kwstyle.value = radioSelection(document.hlCenter.kwdstyle);");
                    743:     hwdWin.document.write("  opener.document.SCORE.refresh.value = \\"on\\";");
                    744:     hwdWin.document.write("  if (opener.document.SCORE.keywords.value!=\\"\\"){");
                    745:     hwdWin.document.write("     opener.document.SCORE.submit();");
                    746:     hwdWin.document.write("  }");
                    747:     hwdWin.document.write("  self.close()");
                    748:     hwdWin.document.write("}");
                    749: 
                    750:     hwdWin.document.write("function radioSelection(radioButton) {");
                    751:     hwdWin.document.write("    var selection=null;");
                    752:     hwdWin.document.write("    for (var i=0; i<radioButton.length; i++) {");
                    753:     hwdWin.document.write("        if (radioButton[i].checked) {");
                    754:     hwdWin.document.write("            selection=radioButton[i].value;");
                    755:     hwdWin.document.write("            return selection;");
                    756:     hwdWin.document.write("        }");
                    757:     hwdWin.document.write("    }");
                    758:     hwdWin.document.write("}");
                    759: 
                    760:     hwdWin.document.write("<");
                    761:     hwdWin.document.write("/script>");
                    762: 
                    763:     hwdWin.document.write("</head><body bgcolor=white>");
                    764: 
                    765:     hwdWin.document.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
                    766:     hwdWin.document.write("<font color=\\"green\\" size=+1>&nbsp;Keyword Highlight Options</font><br><br>");
                    767: 
                    768:     hwdWin.document.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
                    769:     hwdWin.document.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
                    770:     hwdWin.document.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
                    771:   }
                    772: 
                    773:   function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) { 
                    774:     hwdWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
                    775:     hwdWin.document.write("<td align=\\"left\\">");
                    776:     hwdWin.document.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+">&nbsp;"+clrtxt+"</td>");
                    777:     hwdWin.document.write("<td align=\\"left\\">");
                    778:     hwdWin.document.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+">&nbsp;"+sztxt+"</td>");
                    779:     hwdWin.document.write("<td align=\\"left\\">");
                    780:     hwdWin.document.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+">&nbsp;"+sytxt+"</td>");
                    781:     hwdWin.document.write("</tr>");
                    782:   }
                    783: 
                    784:   function highlightend() { 
                    785:     hwdWin.document.write("</table>");
                    786:     hwdWin.document.write("</td></tr></table>&nbsp;");
                    787: //    hwdWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(0)\\">&nbsp;&nbsp;");
                    788:     hwdWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\">&nbsp;&nbsp;");
                    789:     hwdWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
                    790:     hwdWin.document.write("</form>");
                    791:     hwdWin.document.write("</body></html>");
                    792:   }
                    793: 
                    794: </script>
                    795: SUBJAVASCRIPT
                    796: }
                    797: 
                    798: 
1.58      albertel  799: sub show_problem {
                    800:     my ($request,$symb,$uname,$udom,$removeform) = @_;
                    801:     my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
                    802: 						      $ENV{'request.course.id'});
                    803:     if ($removeform) {
                    804: 	$rendered=~s|<form(.*?)>||g;
                    805: 	$rendered=~s|</form>||g;
                    806: 	$rendered=~s|name="submit"|name="would_have_been_submit"|g;
                    807:     }
                    808:     my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
                    809: 							   $ENV{'request.course.id'});
                    810:     if ($removeform) {
                    811: 	$companswer=~s|<form(.*?)>||g;
                    812: 	$companswer=~s|</form>||g;
                    813: 	$rendered=~s|name="submit"|name="would_have_been_submit"|g;
                    814:     }
                    815:     my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
                    816:     $result.='<table border="0" width="100%"><tr><td bgcolor="#e6ffff">';
                    817:     $result.='<b> View of the problem - '.$ENV{'form.fullname'}.
                    818: 	'</b></td></tr><tr><td bgcolor="#ffffff">'.$rendered.'<br />';
                    819:     $result.='<b>Correct answer:</b><br />'.$companswer;
                    820:     $result.='</td></tr></table>';
                    821:     $result.='</td></tr></table><br />';
                    822:     $request->print($result);
                    823: }
                    824: 
1.44      ng        825: # --------------------------- show submissions of a student, option to grade 
                    826: sub submission {
                    827:     my ($request,$counter,$total) = @_;
                    828: 
                    829:     (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
                    830: #    if ($ENV{'form.student'} eq '') { &moreinfo($request,'Need student login id'); return ''; }
                    831:     my ($uname,$udom)     = ($ENV{'form.student'},$ENV{'form.userdom'});
                    832:     ($uname,$udom)        = &finduser($uname) if $udom eq '';
                    833:     $ENV{'form.fullname'} = &get_fullname ($uname,$udom) if $ENV{'form.fullname'} eq '';
                    834: #    if ($uname eq '') { &moreinfo($request,'Unable to find student'); return ''; }
1.41      ng        835: 
                    836:     my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
                    837:     if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
                    838:     my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
1.58      albertel  839: #    $ENV{'form.vProb'} = $ENV{'form.vProb'} ne '' ? $ENV{'form.vProb'} : 'yes';
1.41      ng        840: 
                    841:     # header info
                    842:     if ($counter == 0) {
                    843: 	&sub_page_js($request);
1.45      ng        844: 	$request->print('<h3>&nbsp;<font color="#339933">Submission Record</font></h3>'."\n".
                    845: 			'<font size=+1>&nbsp;<b>Resource: </b>'.$url.'</font>'."\n");
1.41      ng        846: 
1.44      ng        847: 	# option to display problem, only once else it cause problems 
                    848:         # with the form later since the problem has a form.
1.41      ng        849: 	if ($ENV{'form.vProb'} eq 'yes') {
1.58      albertel  850: 	    &show_problem($request,$symb,$uname,$udom,0);
1.41      ng        851: 	}
                    852: 	
1.44      ng        853: 	# kwclr is the only variable that is guaranteed to be non blank 
                    854:         # if this subroutine has been called once.
1.41      ng        855: 	my %keyhash = ();
                    856: 	if ($ENV{'form.kwclr'} eq '') {
                    857: 	    %keyhash = &Apache::lonnet::dump('nohist_handgrade',
                    858: 					     $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    859: 					     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    860: 
                    861: 	    my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
                    862: 	    $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
                    863: 	    $ENV{'form.kwclr'}    = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
                    864: 	    $ENV{'form.kwsize'}   = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
                    865: 	    $ENV{'form.kwstyle'}  = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
                    866: 	    $ENV{'form.msgsub'}   = $keyhash{$symb.'_subject'} ne '' ? 
                    867: 		$keyhash{$symb.'_subject'} : &Apache::lonnet::metadata($url,'title');
                    868: 	    $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.38      ng        869: 
1.41      ng        870: 	}
1.44      ng        871: 
1.41      ng        872: 	$request->print('<form action="/adm/grades" method="post" name="SCORE">'."\n".
                    873: 			'<input type="hidden" name="command"    value="handgrade" />'."\n".
                    874: 			'<input type="hidden" name="refresh"    value="off" />'."\n".
                    875: 			'<input type="hidden" name="symb"       value="'.$symb.'" />'."\n".
                    876: 			'<input type="hidden" name="url"        value="'.$url.'" />'."\n".
                    877: 			'<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" />'."\n".
                    878: 			'<input type="hidden" name="vProb"      value="'.$ENV{'form.vProb'}.'" />'."\n".
                    879: 			'<input type="hidden" name="lastSub"    value="'.$ENV{'form.lastSub'}.'" />'."\n".
                    880: 			'<input type="hidden" name="section"    value="'.$ENV{'form.section'}.'">'."\n".
                    881: 			'<input type="hidden" name="submitonly" value="'.$ENV{'form.submitonly'}.'">'."\n".
                    882: 			'<input type="hidden" name="response"   value="'.$ENV{'form.response'}.'">'."\n".
                    883: 			'<input type="hidden" name="handgrade"  value="'.$ENV{'form.handgrade'}.'">'."\n".
                    884: 			'<input type="hidden" name="keywords"   value="'.$ENV{'form.keywords'}.'" />'."\n".
                    885: 			'<input type="hidden" name="kwclr"      value="'.$ENV{'form.kwclr'}.'" />'."\n".
                    886: 			'<input type="hidden" name="kwsize"     value="'.$ENV{'form.kwsize'}.'" />'."\n".
                    887: 			'<input type="hidden" name="kwstyle"    value="'.$ENV{'form.kwstyle'}.'" />'."\n".
                    888: 			'<input type="hidden" name="msgsub"     value="'.$ENV{'form.msgsub'}.'" />'."\n".
                    889: 			'<input type="hidden" name="savemsgN"   value="'.$ENV{'form.savemsgN'}.'" />'."\n".
                    890: 			'<input type="hidden" name="NCT"'.
                    891: 			' value="'.($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : $total+1).'" />'."\n");
                    892: 	
                    893: 	my ($cts,$prnmsg) = (1,'');
                    894: 	while ($cts <= $ENV{'form.savemsgN'}) {
                    895: 	    $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
                    896: 		($keyhash{$symb.'_savemsg'.$cts} eq '' ? $ENV{'form.savemsg'.$cts} : $keyhash{$symb.'_savemsg'.$cts}).
                    897: 		'" />'."\n";
                    898: 	    $cts++;
                    899: 	}
                    900: 	$request->print($prnmsg);
1.32      ng        901: 
1.41      ng        902: 	if ($ENV{'form.handgrade'} eq 'yes' && $ENV{'form.showgrading'} eq 'yes') {
                    903: 	    $request->print(<<KEYWORDS);
1.38      ng        904: &nbsp;<b>Keyword Options:</b>&nbsp;
                    905: <a href="javascript:keywords(document.SCORE.keywords)"; TARGET=_self>List</a>&nbsp; &nbsp;
                    906: <a href="#" onMouseDown="javascript:getSel(); return false"
                    907:  CLASS="page">Paste Selection to List</a>&nbsp; &nbsp;
                    908: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
                    909: KEYWORDS
1.41      ng        910:         }
                    911:     }
1.44      ng        912: 
1.58      albertel  913:     if ($ENV{'form.vProb'} eq 'all') {
                    914: 	$request->print('<br /><br /><br />');
                    915: 	&show_problem($request,$symb,$uname,$udom,1);
                    916:     }
                    917: 
1.41      ng        918:     my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
                    919:     my ($partlist,$handgrade) = &response_type($url);
                    920: 
1.44      ng        921:     # Display student info
1.41      ng        922:     $request->print(($counter == 0 ? '' : '<br />'));
1.45      ng        923:     my $result='<table border="0" width=100%><tr><td bgcolor="#777777">'."\n".
                    924: 	'<table border="0" width=100%><tr bgcolor="#edffff"><td>'."\n";
1.44      ng        925: 
                    926:     $result.='<b>Fullname: </b>'.$ENV{'form.fullname'}.
                    927: 	'<font color="#999999">&nbsp; &nbsp;Username: '.$uname.'</font>'.
1.45      ng        928: 	'<font color="#999999">&nbsp; &nbsp;Domain: '.$udom.'</font><br />'."\n";
                    929:     $result.='<input type="hidden" name="name'.$counter.
                    930: 	'" value="'.$ENV{'form.fullname'}.'" />'."\n";
1.41      ng        931: 
1.44      ng        932:     # If this is handgraded, then check for collaborators
1.45      ng        933:     my @col_fullnames;
1.56      matthew   934:     my ($classlist,$fullname);
1.41      ng        935:     if ($ENV{'form.handgrade'} eq 'yes') {
                    936: 	my @col_list;
1.56      matthew   937: 	($classlist,undef,$fullname) = &getclasslist('all','0');
1.41      ng        938: 	for (keys (%$handgrade)) {
1.44      ng        939: 	    my $ncol = &Apache::lonnet::EXT('resource.'.$_.
1.57      matthew   940: 					    '.maxcollaborators',
                    941:                                             $symb,$udom,$uname);
                    942: 	    next if ($ncol <= 0);
                    943:             s/\_/\./g;
                    944:             next if ($record{'resource.'.$_.'.collaborators'} eq '');
                    945:             my (@collaborators) = split(/,?\s+/,
                    946:                                    $record{'resource.'.$_.'.collaborators'});
                    947:             my (@badcollaborators);
                    948:             if (scalar(@collaborators) != 0) {
                    949:                 $result.='<b>Collaborators: </b>';
                    950:                 foreach my $collaborator (@collaborators) {
                    951:                     my ($co_name,$co_dom) = split /\@|:/,$collaborator;
                    952:                     $co_dom = $udom if (! defined($co_dom));
                    953:                     next if ($co_name eq $uname && $co_dom eq $udom);
                    954:                     # Doing this grep allows 'fuzzy' specification
                    955:                     my @Matches = grep /^$co_name:$co_dom/i,
                    956:                     keys %$classlist;
                    957:                     if (! scalar(@Matches)) {
                    958:                         push @badcollaborators,$collaborator;
                    959:                         next;
                    960:                     }
                    961:                     push @col_list, @Matches;
                    962:                     foreach (@Matches) {
                    963:                         my ($lastname,$givenn) = split(/,/,$$fullname{$_});
                    964:                         push @col_fullnames, $givenn.' '.$lastname;
                    965:                         $result.=$$fullname{$_}.'&nbsp; &nbsp; &nbsp;';
                    966:                     }
                    967:                 }
                    968:                 $result.='<br />'."\n";
                    969:                 if (scalar(@badcollaborators) > 0) {
                    970:                     $result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
                    971:                     $result.='This student has submitted ';
                    972:                     if (scalar(@badcollaborators) == 1) {
                    973:                         $result .= 'an invalid collaborator';
                    974:                     } else {
                    975:                         $result .= 'invalid collaborators';
                    976:                     }
                    977:                     $result .= ': '.join(', ',@badcollaborators);
                    978:                     
                    979:                 }
                    980:                 if (scalar(@collaborators > $ncol)) {
                    981:                     $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
                    982:                     $result .= 'This student has sumbitted too many '.
                    983:                         'collaborators.  Maximum is '.$ncol;
                    984:                     $result .= '</td></tr></table>';
                    985:                 }
                    986:                 $result.='<input type="hidden" name="collaborator'.$counter.
                    987:                     '" value="'.(join ':',@col_list).'" />'."\n";
                    988:             }
1.41      ng        989: 	}
                    990:     }
1.44      ng        991:     $request->print($result."\n");
1.33      ng        992: 
1.44      ng        993:     # print student answer/submission
                    994:     # Options are (1) Handgaded submission only
                    995:     #             (2) Last submission, includes submission that is not handgraded 
                    996:     #                  (for multi-response type part)
                    997:     #             (3) Last submission plus the parts info
                    998:     #             (4) The whole record for this student
1.41      ng        999:     if ($ENV{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
                   1000: 	if ($ENV{'form.'.$uname.':'.$udom.':submitted_by'}) {
1.44      ng       1001: 	    my $submitby=''.
1.41      ng       1002: 		'<b>Collaborative submission by: </b>'.
1.44      ng       1003: 		'<a href="javascript:viewSubmitter(\''.
                   1004: 		$ENV{'form.'.$uname.':'.$udom.':submitted_by'}.
1.41      ng       1005: 		'\')"; TARGET=_self>'.
                   1006: 		$$fullname{$ENV{'form.'.$uname.':'.$udom.':submitted_by'}}.'</a>';
                   1007: 	    $request->print($submitby);
                   1008: 	} else {
1.44      ng       1009: 	    my ($string,$timestamp)=
1.46      ng       1010: 		&get_last_submission (%record);
1.44      ng       1011: 	    my $lastsubonly.=''.
                   1012: 		($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
                   1013: 		 $$timestamp).'';
1.41      ng       1014: 	    if ($$timestamp eq '') {
1.45      ng       1015: 		$lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0].'</td></tr>'."\n";
1.41      ng       1016: 	    } else {
                   1017: 		for my $part (sort keys(%$handgrade)) {
                   1018: 		    foreach (@$string) {
                   1019: 			my ($partid,$respid) = /^resource\.(\d+)\.(\d+)\.submission/;
                   1020: 			if ($part eq ($partid.'_'.$respid)) {
                   1021: 			    my ($ressub,$subval) = split(/:/,$_,2);
1.44      ng       1022: 			    $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
                   1023: 				$partid.'</b> <font color="#999999">( ID '.$respid.
                   1024: 				' )</font>&nbsp; &nbsp;<b>Answer: </b>'.
1.45      ng       1025: 				&keywords_highlight($subval).'</td></tr>'."\n"
1.41      ng       1026: 				if ($ENV{'form.lastSub'} eq 'lastonly' || 
1.44      ng       1027: 				    ($ENV{'form.lastSub'} eq 'hdgrade' && 
                   1028: 				     $$handgrade{$part} =~ /:yes$/));
1.41      ng       1029: 			}
                   1030: 		    }
                   1031: 		}
                   1032: 	    }
1.45      ng       1033: 	    $lastsubonly.='</td></tr>'."\n";
1.41      ng       1034: 	    $request->print($lastsubonly);
                   1035: 	}
                   1036:     } else {
                   1037: 	$request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.44      ng       1038: 								 $ENV{'request.course.id'},
                   1039: 								 $last,'.submission',
                   1040: 								 'Apache::grades::keywords_highlight'));
1.41      ng       1041:     }
                   1042:     
1.44      ng       1043:     # return if view submission with no grading option
1.41      ng       1044:     if ($ENV{'form.showgrading'} eq '') {
1.45      ng       1045: 	$request->print('</td></tr></table></td></tr></table></form>'."\n");
1.41      ng       1046: 	return;
                   1047:     }
1.33      ng       1048: 
1.44      ng       1049:     # Grading options
1.41      ng       1050:     $result='<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n".
                   1051: 	'<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.45      ng       1052: 	'<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
                   1053: 	.$udom.'" />'."\n";
                   1054:     my ($lastname,$givenn) = split(/,/,$ENV{'form.fullname'});
                   1055:     my $msgfor = $givenn.' '.$lastname;
                   1056:     if (scalar(@col_fullnames) > 0) {
                   1057: 	my $lastone = pop @col_fullnames;
                   1058: 	$msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
                   1059:     }
                   1060:     $result.='<tr><td bgcolor="#ffffff">'."\n".
                   1061: 	'&nbsp;<a href="javascript:msgCenter(document.SCORE,'.$counter.
                   1062: 	',\''.$msgfor.'\')"; TARGET=_self>'.
                   1063: 	'Compose Message to student'.(scalar(@col_fullnames) >= 1 ? 's' : '').'</a>'.
1.44      ng       1064: 	'<br />&nbsp;(Message will be sent when you click on Save & Next below.)'."\n" 
                   1065: 	if ($ENV{'form.handgrade'} eq 'yes');
1.41      ng       1066:     $request->print($result);
                   1067: 
                   1068:     my %seen = ();
                   1069:     my @partlist;
                   1070:     for (sort keys(%$handgrade)) {
                   1071: 	my ($partid,$respid) = split(/_/);
                   1072: 	next if ($seen{$partid} > 0);
                   1073: 	$seen{$partid}++;
                   1074: 	next if ($$handgrade{$_} =~ /:no$/);
                   1075: 	push @partlist,$partid;
                   1076: 	my $wgt    = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.44      ng       1077: 	my $wgtmsg = ($wgt > 0 ? '(problem weight)' : 
                   1078: 		      '<font color="red">problem weight assigned by computer</font>');
1.41      ng       1079: 	$wgt       = ($wgt > 0 ? $wgt : '1');
                   1080: 	my $score  = ($record{'resource.'.$partid.'.awarded'} eq '' ?
                   1081: 		      '' : $record{'resource.'.$partid.'.awarded'}*$wgt);
                   1082: 	$result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />';
1.44      ng       1083: 	$result.='<table border="0"><tr><td><b>Part </b>'.$partid.' <b>Points: </b></td><td>';
1.41      ng       1084: 
                   1085: 	my $ctr = 0;
                   1086: 	$result.='<table border="0"><tr>';  # display radio buttons in a nice table 10 across
                   1087: 	while ($ctr<=$wgt) {
                   1088: 	    $result.= '<td><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.43      ng       1089: 		'onclick="javascript:writeBox(this.form.GD_BOX'.$counter.'_'.$partid.
                   1090: 		',this.form.GD_SEL'.$counter.'_'.$partid.','.$ctr.
1.41      ng       1091: 		',this.form.stores'.$counter.'_'.$partid.')" '.
                   1092: 		($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
                   1093: 	    $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
                   1094: 	    $ctr++;
                   1095: 	}
                   1096: 	$result.='</tr></table>';
1.39      ng       1097: 
1.41      ng       1098: 	$result.='</td><td>&nbsp;<b>or</b>&nbsp;</td>';
1.43      ng       1099: 	$result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.41      ng       1100: 	    ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
                   1101: 	    'onChange="javascript:updateRadio(this.form.RADVAL'.$counter.'_'.$partid.
1.43      ng       1102: 	    ',this.form.GD_BOX'.$counter.'_'.$partid.
                   1103: 	    ',this.form.GD_SEL'.$counter.'_'.$partid.
1.44      ng       1104: 	    ',this.form.stores'.$counter.'_'.$partid.
                   1105: 	    ','.$wgt.')" /></td>'."\n";
1.41      ng       1106: 	$result.='<td>/'.$wgt.' '.$wgtmsg.' </td><td>';
                   1107: 
1.43      ng       1108: 	$result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.41      ng       1109: 	    'onChange="javascript:clearRadBox(this.form.RADVAL'.$counter.'_'.$partid.
1.43      ng       1110: 	    ',this.form.GD_BOX'.$counter.'_'.$partid.
                   1111: 	    ',this.form.GD_SEL'.$counter.'_'.$partid.
1.58      albertel 1112: 	    ',this.form.stores'.$counter.'_'.$partid.')" >'."\n";
                   1113: 	if ($record{'resource.'.$partid.'.solved'} eq 'excused') {
                   1114: 	    $result.='<option> </option>'.
                   1115: 		'<option selected="on">excused</option></select>';
                   1116: 	} else {
                   1117: 	    $result.='<option selected="on"> </option>'.
                   1118: 		'<option>excused</option></select>';
                   1119: 	}
                   1120: 	$result.="&nbsp&nbsp\n";
1.41      ng       1121: 	$result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="0" />';
1.45      ng       1122: 	$result.='</td></tr></table>'."\n";
1.41      ng       1123: 	$request->print($result);
                   1124:     }
1.45      ng       1125:     $result='<input type="hidden" name="partlist'.$counter.
                   1126: 	'" value="'.(join ":",@partlist).'" />'."\n";
                   1127:     my $ctr = 0;
                   1128:     while ($ctr < scalar(@partlist)) {
                   1129: 	$result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
                   1130: 	    $partlist[$ctr].'" />'."\n";
                   1131: 	$ctr++;
                   1132:     }
                   1133:     $request->print($result.'</td></tr></table></td></tr></table>'."\n");
1.41      ng       1134: 
                   1135:     # print end of form
                   1136:     if ($counter == $total) {
1.45      ng       1137: 	my $endform='<table border="0"><tr><td>'.
                   1138: 	    '<input type="hidden" name="gradeOpt" value="" />'."\n";
                   1139: 	if ($ENV{'form.handgrade'} eq 'yes') {
                   1140: 	    $endform.='<input type="button" value="Save & Next" '.
                   1141: 		'onClick="javascript:checksubmit(\'Save & Next\','.
                   1142: 		$total.','.scalar(@partlist).');" TARGET=_self> &nbsp;'."\n";
                   1143: 	    my $ntstu ='<select name="NTSTU">'.
                   1144: 		'<option>1</option><option>2</option>'.
                   1145: 		'<option>3</option><option>5</option>'.
                   1146: 		'<option>7</option><option>10</option></select>'."\n";
                   1147: 	    my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
                   1148: 	    $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
                   1149: 	    $endform.=$ntstu.'student(s) &nbsp;&nbsp;';
                   1150: 	} else {
                   1151: 	    $endform.='<input type="hidden" name="NTSTU" value="1" />'."\n";
                   1152: 	}
                   1153: 	$endform.='<input type="button" value="Next" '.
                   1154: 	    'onClick="javascript:checksubmit(\'Next\');" TARGET=_self> &nbsp;'."\n".
                   1155: 	    '<input type="button" value="Previous" '.
                   1156: 	    'onClick="javascript:checksubmit(\'Previous\');" TARGET=_self> &nbsp;';
                   1157: 	$endform.='(Next and Previous do not save the scores.)'."\n" 
                   1158: 	    if ($ENV{'form.handgrade'} eq 'yes');
                   1159: 	$endform.='</td><tr></table></form>';
1.50      albertel 1160: 	$endform.=&show_grading_menu_form($symb,$url);
1.41      ng       1161: 	$request->print($endform);
                   1162:     }
                   1163:     return '';
1.38      ng       1164: }
                   1165: 
1.44      ng       1166: #--- Retrieve the last submission for all the parts
1.38      ng       1167: sub get_last_submission {
1.46      ng       1168:     my (%returnhash)=@_;
                   1169:     my (@string,$timestamp);
                   1170:     if ($returnhash{'version'}) {
                   1171: 	my %lasthash=();
                   1172: 	my ($version);
                   1173: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
                   1174: 	    foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   1175: 		$lasthash{$_}=$returnhash{$version.':'.$_};
1.61      albertel 1176: #		if ($returnhash{$version.':'.$_} =~ /(SUBMITTED|DRAFT)$/) {
1.46      ng       1177: 		   $timestamp = scalar(localtime($returnhash{$version.':timestamp'}));
1.61      albertel 1178: #	       } 
1.46      ng       1179: 	    }
                   1180: 	}
                   1181: 	foreach ((keys %lasthash)) {
                   1182: 	    if ($_ =~ /\.submission$/) {
                   1183: 		my ($partid,$foo) = split(/submission$/,$_);
                   1184: 		my $draft  = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
                   1185: 		    '<font color="red">Draft Copy</font> ' : '';
                   1186: 		push @string, (join(':',$_,$draft.$lasthash{$_}));
1.41      ng       1187: 	    }
                   1188: 	}
                   1189:     }
1.46      ng       1190:     @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string;
                   1191:     return \@string,\$timestamp;
1.38      ng       1192: }
1.35      ng       1193: 
1.44      ng       1194: #--- High light keywords, with style choosen by user.
1.38      ng       1195: sub keywords_highlight {
1.44      ng       1196:     my $string    = shift;
                   1197:     my $size      = $ENV{'form.kwsize'} eq '0' ? '' : 'size='.$ENV{'form.kwsize'};
                   1198:     my $styleon   = $ENV{'form.kwstyle'} eq ''  ? '' : $ENV{'form.kwstyle'};
1.41      ng       1199:     (my $styleoff = $styleon) =~ s/\</\<\//;
1.44      ng       1200:     my @keylist   = split(/[,\s+]/,$ENV{'form.keywords'});
1.41      ng       1201:     foreach (@keylist) {
1.60      albertel 1202: 	$string =~ s/\b\Q$_\E(\b|\.)/\<font color\=$ENV{'form.kwclr'} $size\>$styleon$_$styleoff\<\/font\>/gi;
1.41      ng       1203:     }
1.57      matthew  1204:     # This is not really the right place to do this, but I cannot find a
                   1205:     # better one at this time.  So here we go - the m in the s:::mg causes
                   1206:     # ^ to match the beginning of a new line.  So we replace(???) the beginning
                   1207:     # of the line with <br /> to make things formatted a little better.
                   1208:     $string =~ s:^:<br />:mg;
1.41      ng       1209:     return $string;
1.38      ng       1210: }
1.36      ng       1211: 
1.44      ng       1212: #--- Called from submission routine
1.38      ng       1213: sub processHandGrade {
1.41      ng       1214:     my ($request) = shift;
                   1215:     my $url    = $ENV{'form.url'};
                   1216:     my $symb   = $ENV{'form.symb'};
                   1217:     my $button = $ENV{'form.gradeOpt'};
                   1218:     my $ngrade = $ENV{'form.NCT'};
                   1219:     my $ntstu  = $ENV{'form.NTSTU'};
                   1220: 
1.44      ng       1221:     if ($button eq 'Save & Next') {
                   1222: 	my $ctr = 0;
                   1223: 	while ($ctr < $ngrade) {
                   1224: 	    my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
1.45      ng       1225: 	    my ($errorflag) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
1.44      ng       1226: 
                   1227: 	    my $includemsg = $ENV{'form.includemsg'.$ctr};
                   1228: 	    my ($subject,$message,$msgstatus) = ('','','');
1.62    ! albertel 1229: 	    if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.44      ng       1230: 		$subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/);
                   1231: 		my (@msgnum) = split(/,/,$includemsg);
                   1232: 		foreach (@msgnum) {
                   1233: 		    $message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
                   1234: 		}
                   1235: 		$message =~ s/\s+/ /g;
                   1236: 		$msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
                   1237: 							       $ENV{'form.msgsub'},$message);
                   1238: 	    }
                   1239: 	    if ($ENV{'form.collaborator'.$ctr}) {
                   1240: 		my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
                   1241: 		foreach (@collaborators) {
                   1242: 		    &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,
                   1243: 				   $ENV{'form.unamedom'.$ctr});
                   1244: 		    if ($message ne '') {
                   1245: 			$msgstatus = &Apache::lonmsg::user_normal_msg ($_,$udom,
                   1246: 								       $ENV{'form.msgsub'},
                   1247: 								       $message);
                   1248: 		    }
                   1249: 		}
                   1250: 	    }
                   1251: 	    $ctr++;
                   1252: 	}
                   1253:     }
                   1254: 
                   1255:     # Keywords sorted in alphabatical order
1.41      ng       1256:     my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
                   1257:     my %keyhash = ();
                   1258:     $ENV{'form.keywords'}           =~ s/,\s{0,}|\s+/ /g;
                   1259:     $ENV{'form.keywords'}           =~ s/^\s+|\s+$//;
1.44      ng       1260:     my (@keywords) = sort(split(/\s+/,$ENV{'form.keywords'}));
                   1261:     $ENV{'form.keywords'} = join(' ',@keywords);
1.41      ng       1262:     $keyhash{$symb.'_keywords'}     = $ENV{'form.keywords'};
                   1263:     $keyhash{$symb.'_subject'}      = $ENV{'form.msgsub'};
                   1264:     $keyhash{$loginuser.'_kwclr'}   = $ENV{'form.kwclr'};
                   1265:     $keyhash{$loginuser.'_kwsize'}  = $ENV{'form.kwsize'};
                   1266:     $keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
                   1267: 
1.44      ng       1268:     # message center - Order of message gets changed. Blank line is eliminated.
                   1269:     # New messages are saved in ENV for the next student.
                   1270:     # All messages are saved in nohist_handgrade.db
1.41      ng       1271:     my ($ctr,$idx) = (1,1);
                   1272:     while ($ctr <= $ENV{'form.savemsgN'}) {
                   1273: 	if ($ENV{'form.savemsg'.$ctr} ne '') {
                   1274: 	    $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
                   1275: 	    $idx++;
                   1276: 	}
                   1277: 	$ctr++;
                   1278:     }
                   1279:     $ctr = 0;
                   1280:     while ($ctr < $ngrade) {
                   1281: 	if ($ENV{'form.newmsg'.$ctr} ne '') {
                   1282: 	    $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
                   1283: 	    $ENV{'form.savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
                   1284: 	    $idx++;
                   1285: 	}
                   1286: 	$ctr++;
                   1287:     }
                   1288:     $ENV{'form.savemsgN'} = --$idx;
                   1289:     $keyhash{$symb.'_savemsgN'} = $ENV{'form.savemsgN'};
                   1290:     my $putresult = &Apache::lonnet::put
                   1291: 	('nohist_handgrade',\%keyhash,
                   1292: 	 $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1293: 	 $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   1294: 
1.44      ng       1295:     # Called by Save & Refresh from Highlight Attribute Window
1.41      ng       1296:     if ($ENV{'form.refresh'} eq 'on') {
                   1297: 	my $ctr = 0;
                   1298: 	$ENV{'form.NTSTU'}=$ngrade;
                   1299: 	while ($ctr < $ngrade) {
1.44      ng       1300: 	    ($ENV{'form.student'},$ENV{'form.userdom'}) = split(/:/,$ENV{'form.unamedom'.$ctr});
1.41      ng       1301: 	    &submission($request,$ctr,$ngrade-1);
                   1302: 	    $ctr++;
                   1303: 	}
                   1304: 	return '';
                   1305:     }
1.36      ng       1306: 
1.44      ng       1307:     # Get the next/previous one or group of students
1.41      ng       1308:     my $firststu = $ENV{'form.unamedom0'};
                   1309:     my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
                   1310:     $ctr = 2;
                   1311:     while ($laststu eq '') {
                   1312: 	$laststu  = $ENV{'form.unamedom'.($ngrade-$ctr)};
                   1313: 	$ctr++;
                   1314: 	$laststu = $firststu if ($ctr > $ngrade);
                   1315:     }
1.44      ng       1316: 
1.56      matthew  1317:     my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1.41      ng       1318:     my (@parsedlist,@nextlist);
                   1319:     my ($nextflg) = 0;
1.53      albertel 1320:     foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.41      ng       1321: 	if ($nextflg == 1 && $button =~ /Next$/) {
                   1322: 	    push @parsedlist,$_;
                   1323: 	}
                   1324: 	$nextflg = 1 if ($_ eq $laststu);
                   1325: 	if ($button eq 'Previous') {
                   1326: 	    last if ($_ eq $firststu);
                   1327: 	    push @parsedlist,$_;
                   1328: 	}
                   1329:     }
                   1330:     $ctr = 0;
                   1331:     my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
                   1332:     @parsedlist = reverse @parsedlist if ($button eq 'Previous');
                   1333:     foreach my $student (@parsedlist) {
                   1334: 	my ($uname,$udom) = split(/:/,$student);
                   1335: 	if ($ENV{'form.submitonly'} eq 'yes') {
1.44      ng       1336: 	    my (%status) = &student_gradeStatus($ENV{'form.url'},$symb,$udom,$uname,$partlist) ;
1.41      ng       1337: 	    my $statusflg = '';
                   1338: 	    foreach (keys(%status)) {
                   1339: 		$statusflg = 1 if ($status{$_} ne 'nothing');
1.44      ng       1340: 		my ($foo,$partid,$foo1) = split(/\./);
1.41      ng       1341: 		$statusflg = '' if ($status{'resource.'.$partid.'.submitted_by'} ne '');
                   1342: 	    }
                   1343: 	    next if ($statusflg eq '');
                   1344: 	}
                   1345: 	push @nextlist,$student if ($ctr < $ntstu);
                   1346: 	$ctr++;
                   1347:     }
1.36      ng       1348: 
1.41      ng       1349:     $ctr = 0;
                   1350:     my $total = scalar(@nextlist)-1;
1.39      ng       1351: 
1.41      ng       1352:     foreach (sort @nextlist) {
                   1353: 	my ($uname,$udom,$submitter) = split(/:/);
1.44      ng       1354: 	$ENV{'form.student'}  = $uname;
                   1355: 	$ENV{'form.userdom'}  = $udom;
1.41      ng       1356: 	$ENV{'form.fullname'} = $$fullname{$_};
                   1357: #	$ENV{'form.'.$_.':submitted_by'} = $submitter;
                   1358: #	print "submitter=$ENV{'form.'.$_.':submitted_by'}= $submitter:<br>";
                   1359: 	&submission($request,$ctr,$total);
                   1360: 	$ctr++;
                   1361:     }
                   1362:     if ($total < 0) {
                   1363: 	my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
                   1364: 	$the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
                   1365: 	$the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
                   1366: 	$the_end.=&show_grading_menu_form ($symb,$url);
                   1367: 	$request->print($the_end);
                   1368:     }
                   1369:     return '';
1.38      ng       1370: }
1.36      ng       1371: 
1.44      ng       1372: #---- Save the score and award for each student, if changed
1.38      ng       1373: sub saveHandGrade {
1.41      ng       1374:     my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter) = @_;
1.44      ng       1375:     my %record=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
1.41      ng       1376:     my %newrecord;
                   1377:     foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
1.43      ng       1378: 	if ($ENV{'form.GD_SEL'.$newflg.'_'.$_} eq 'excused') {
1.58      albertel 1379: 	    if ($record{'resource.'.$_.'.solved'} ne 'excused') {
                   1380: 		$newrecord{'resource.'.$_.'.solved'} = 'excused';
                   1381: 		if (exists($record{'resource.'.$_.'.awarded'})) {
                   1382: 		    $newrecord{'resource.'.$_.'.awarded'} = '';
                   1383: 		}
                   1384: 	    }
1.41      ng       1385: 	} else {
1.44      ng       1386: 	    my $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ? 
                   1387: 		       $ENV{'form.GD_BOX'.$newflg.'_'.$_} : 
                   1388: 		       $ENV{'form.RADVAL'.$newflg.'_'.$_});
                   1389: 	    my $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 : 
                   1390: 		$ENV{'form.WGT'.$newflg.'_'.$_};
1.41      ng       1391: 	    my $partial= $pts/$wgt;
1.44      ng       1392: 	    $newrecord{'resource.'.$_.'.awarded'}  = $partial 
                   1393: 		if ($record{'resource.'.$_.'.awarded'} ne $partial);
                   1394: 	    my $reckey = 'resource.'.$_.'.solved';
1.41      ng       1395: 	    if ($partial == 0) {
1.44      ng       1396: 		$newrecord{$reckey} = 'incorrect_by_override' 
                   1397: 		    if ($record{$reckey} ne 'incorrect_by_override');
1.41      ng       1398: 	    } else {
1.44      ng       1399: 		$newrecord{$reckey} = 'correct_by_override' 
                   1400: 		    if ($record{$reckey} ne 'correct_by_override');
1.41      ng       1401: 	    }
1.44      ng       1402: 	    $newrecord{'resource.'.$_.'.submitted_by'} = $submitter 
                   1403: 		if ($submitter && ($record{'resource.'.$_.'.submitted_by'} ne $submitter));
1.41      ng       1404: 	}
                   1405:     }
1.44      ng       1406: 
                   1407:     if (scalar(keys(%newrecord)) > 0) {
1.41      ng       1408: 	$newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.44      ng       1409: 	&Apache::lonnet::cstore(\%newrecord,$symb,
                   1410: 				$ENV{'request.course.id'},$domain,$stuname);
1.41      ng       1411:     }
                   1412:     return '';
1.36      ng       1413: }
1.38      ng       1414: 
1.44      ng       1415: #--------------------------------------------------------------------------------------
                   1416: #
                   1417: #-------------------------- Next few routines handles grading by section or whole class
                   1418: #
                   1419: #--- Javascript to handle grading by section or whole class
1.42      ng       1420: sub viewgrades_js {
                   1421:     my ($request) = shift;
                   1422: 
1.41      ng       1423:     $request->print(<<VIEWJAVASCRIPT);
                   1424: <script type="text/javascript" language="javascript">
1.45      ng       1425:    function writePoint(partid,weight,point) {
1.42      ng       1426: 	var radioButton = eval("document.classgrade.RADVAL_"+partid);
                   1427: 	var textbox = eval("document.classgrade.TEXTVAL_"+partid);
                   1428: 	if (point == "textval") {
                   1429: 	    var point = eval("document.classgrade.TEXTVAL_"+partid+".value");
                   1430: 	    if (isNaN(point) || point < 0) {
                   1431: 		alert("A number equal or greater than 0 is expected. Entered value = "+point);
                   1432: 		var resetbox = false;
                   1433: 		for (var i=0; i<radioButton.length; i++) {
                   1434: 		    if (radioButton[i].checked) {
                   1435: 			textbox.value = i;
                   1436: 			resetbox = true;
                   1437: 		    }
                   1438: 		}
                   1439: 		if (!resetbox) {
                   1440: 		    textbox.value = "";
                   1441: 		}
                   1442: 		return;
                   1443: 	    }
1.44      ng       1444: 	    if (point > weight) {
                   1445: 		var resp = confirm("You entered a value ("+point+
                   1446: 				   ") greater than the weight for the part. Accept?");
                   1447: 		if (resp == false) {
                   1448: 		    textbox.value = "";
                   1449: 		    return;
                   1450: 		}
                   1451: 	    }
1.42      ng       1452: 	    for (var i=0; i<radioButton.length; i++) {
                   1453: 		radioButton[i].checked=false;
                   1454: 		if (point == i) {
                   1455: 		    radioButton[i].checked=true;
                   1456: 		}
                   1457: 	    }
1.41      ng       1458: 
1.42      ng       1459: 	} else {
                   1460: 	    textbox.value = point;
                   1461: 	}
1.41      ng       1462: 	for (i=0;i<document.classgrade.total.value;i++) {
1.43      ng       1463: 	    var user = eval("document.classgrade.ctr"+i+".value");
                   1464: 	    var scorename = eval("document.classgrade.GD_"+user+
1.54      albertel 1465: 				 "_"+partid+"_awarded");
1.43      ng       1466: 	    var saveval   = eval("document.classgrade.GD_"+user+
1.54      albertel 1467: 				 "_"+partid+"_solved_s.value");
                   1468: 	    var selname   = eval("document.classgrade.GD_"+user+"_"+partid+"_solved");
1.42      ng       1469: 	    if (saveval != "correct") {
                   1470: 		scorename.value = point;
1.43      ng       1471: 		if (selname[0].selected != true) {
                   1472: 		    selname[0].selected = true;
                   1473: 		}
1.42      ng       1474: 	    }
                   1475: 	}
                   1476: 	var selval   = eval("document.classgrade.SELVAL_"+partid);
                   1477: 	selval[0].selected = true;
                   1478:     }
                   1479: 
                   1480:     function writeRadText(partid,weight) {
                   1481: 	var selval   = eval("document.classgrade.SELVAL_"+partid);
1.43      ng       1482: 	var radioButton = eval("document.classgrade.RADVAL_"+partid);
                   1483: 	var textbox = eval("document.classgrade.TEXTVAL_"+partid);
1.42      ng       1484: 	if (selval[1].selected) {
                   1485: 	    for (var i=0; i<radioButton.length; i++) {
                   1486: 		radioButton[i].checked=false;
                   1487: 
                   1488: 	    }
                   1489: 	    textbox.value = "";
                   1490: 
                   1491: 	    for (i=0;i<document.classgrade.total.value;i++) {
1.43      ng       1492: 		var user = eval("document.classgrade.ctr"+i+".value");
                   1493: 		var scorename = eval("document.classgrade.GD_"+user+
1.54      albertel 1494: 				     "_"+partid+"_awarded");
1.43      ng       1495: 		var saveval   = eval("document.classgrade.GD_"+user+
1.54      albertel 1496: 				     "_"+partid+"_solved_s.value");
1.43      ng       1497: 		var selname   = eval("document.classgrade.GD_"+user+
1.54      albertel 1498: 				     "_"+partid+"_solved");
1.42      ng       1499: 		if (saveval != "correct") {
                   1500: 		    scorename.value = "";
                   1501: 		    selname[1].selected = true;
                   1502: 		}
                   1503: 	    }
1.43      ng       1504: 	} else {
                   1505: 	    for (i=0;i<document.classgrade.total.value;i++) {
                   1506: 		var user = eval("document.classgrade.ctr"+i+".value");
                   1507: 		var scorename = eval("document.classgrade.GD_"+user+
1.54      albertel 1508: 				     "_"+partid+"_awarded");
1.43      ng       1509: 		var saveval   = eval("document.classgrade.GD_"+user+
1.54      albertel 1510: 				     "_"+partid+"_solved_s.value");
1.43      ng       1511: 		var selname   = eval("document.classgrade.GD_"+user+
1.54      albertel 1512: 				     "_"+partid+"_solved");
1.43      ng       1513: 		if (saveval != "correct") {
                   1514: 		    scorename.value = eval("document.classgrade.GD_"+user+
1.54      albertel 1515: 				     "_"+partid+"_awarded_s.value");;
1.43      ng       1516: 		    selname[0].selected = true;
                   1517: 		}
                   1518: 	    }
                   1519: 	}	    
1.42      ng       1520:     }
                   1521: 
                   1522:     function changeSelect(partid,user) {
1.54      albertel 1523: 	var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_solved");
                   1524: 	var textbox = eval("document.classgrade.GD_"+user+'_'+partid+"_awarded");
1.44      ng       1525: 	var point  = textbox.value;
                   1526: 	var weight = eval("document.classgrade.weight_"+partid+".value");
                   1527: 
                   1528: 	if (isNaN(point) || point < 0) {
                   1529: 	    alert("A number equal or greater than 0 is expected. Entered value = "+point);
                   1530: 	    textbox.value = "";
                   1531: 	    return;
                   1532: 	}
                   1533: 	if (point > weight) {
                   1534: 	    var resp = confirm("You entered a value ("+point+
                   1535: 			       ") greater than the weight of the part. Accept?");
                   1536: 	    if (resp == false) {
                   1537: 		textbox.value = "";
                   1538: 		return;
                   1539: 	    }
                   1540: 	}
1.42      ng       1541: 	selval[0].selected = true;
                   1542:     }
                   1543: 
                   1544:     function changeOneScore(partid,user) {
1.54      albertel 1545: 	var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_solved");
1.42      ng       1546: 	if (selval[1].selected) {
1.54      albertel 1547: 	    var boxval = eval("document.classgrade.GD_"+user+'_'+partid+"_awarded");
1.42      ng       1548: 	    boxval.value = "";
                   1549: 	}
                   1550:     }
                   1551: 
                   1552:     function resetEntry(numpart) {
                   1553: 	for (ctpart=0;ctpart<numpart;ctpart++) {
                   1554: 	    var partid = eval("document.classgrade.partid_"+ctpart+".value");
                   1555: 	    var radioButton = eval("document.classgrade.RADVAL_"+partid);
                   1556: 	    var textbox = eval("document.classgrade.TEXTVAL_"+partid);
                   1557: 	    var selval  = eval("document.classgrade.SELVAL_"+partid);
                   1558: 	    for (var i=0; i<radioButton.length; i++) {
                   1559: 		radioButton[i].checked=false;
                   1560: 
                   1561: 	    }
                   1562: 	    textbox.value = "";
                   1563: 	    selval[0].selected = true;
                   1564: 
                   1565: 	    for (i=0;i<document.classgrade.total.value;i++) {
1.43      ng       1566: 		var user = eval("document.classgrade.ctr"+i+".value");
                   1567: 		var resetscore = eval("document.classgrade.GD_"+user+
1.54      albertel 1568: 				      "_"+partid+"_awarded");
1.43      ng       1569: 		resetscore.value = eval("document.classgrade.GD_"+user+
1.54      albertel 1570: 					"_"+partid+"_awarded_s.value");
1.42      ng       1571: 
1.43      ng       1572: 		var saveselval   = eval("document.classgrade.GD_"+user+
1.54      albertel 1573: 				     "_"+partid+"_solved_s.value");
1.42      ng       1574: 
1.54      albertel 1575: 		var selname   = eval("document.classgrade.GD_"+user+"_"+partid+"_solved");
1.42      ng       1576: 		if (saveselval == "excused") {
1.43      ng       1577: 		    if (selname[1].selected == false) { selname[1].selected = true;}
1.42      ng       1578: 		} else {
1.43      ng       1579: 		    if (selname[0].selected == false) {selname[0].selected = true};
1.42      ng       1580: 		}
                   1581: 	    }
1.41      ng       1582: 	}
1.42      ng       1583:     }
                   1584: 
1.41      ng       1585: </script>
                   1586: VIEWJAVASCRIPT
1.42      ng       1587: }
                   1588: 
1.44      ng       1589: #--- show scores for a section or whole class w/ option to change/update a score
1.42      ng       1590: sub viewgrades {
                   1591:     my ($request) = shift;
                   1592:     &viewgrades_js($request);
1.41      ng       1593: 
                   1594:     my ($symb,$url) = ($ENV{'form.symb'},$ENV{'form.url'}); 
1.45      ng       1595:     my $result='<h3><font color="#339933">Manual Grading</font></h3>';
1.38      ng       1596: 
1.43      ng       1597:     $result.='<font size=+1><b>Resource: </b>'.$ENV{'form.url'}.'</font>'."\n";
1.41      ng       1598: 
                   1599:     #view individual student submission form - called using Javascript viewOneStudent
1.45      ng       1600:     $result.=&jscriptNform($url,$symb);
1.41      ng       1601: 
1.44      ng       1602:     #beginning of class grading form
1.41      ng       1603:     $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
                   1604: 	'<input type="hidden" name="symb"    value="'.$symb.'" />'."\n".
                   1605: 	'<input type="hidden" name="url"     value="'.$url.'" />'."\n".
1.38      ng       1606: 	'<input type="hidden" name="command" value="editgrades" />'."\n".
1.41      ng       1607: 	'<input type="hidden" name="section" value="'.$ENV{'form.section'}.'" />'."\n";
1.52      albertel 1608:     $result.='<h3>Assign Common Grade To ';
                   1609:     if ($ENV{'form.section'} eq 'all') {
                   1610: 	$result.='Class </h3>';
                   1611:     } elsif ($ENV{'form.section'} eq 'no') {
                   1612: 	$result.='Students in no Section </h3>';
                   1613:     } else {
                   1614: 	$result.='Students in Section '.$ENV{'form.section'}.'</h3>';
                   1615:     }
                   1616:     $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
                   1617: 	'<table border=0><tr bgcolor="#ffffdd"><td>';
                   1618: #    $result.='To assign the same score for all the students use the radio buttons or '.
                   1619: #	'text box below. To assign scores individually fill in the score boxes for '.
                   1620: #	'each student in the table below. <font color="red">A part that has already '.
                   1621: #	'been graded does not get changed using the radio buttons or text box. '.
                   1622: #	'If needed, it has to be changed individually.</font>';
                   1623: #    $result.='</td></tr><tr><td>';
1.44      ng       1624:     #radio buttons/text box for assigning points for a section or class.
                   1625:     #handles different parts of a problem
1.42      ng       1626:     my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
                   1627:     my %weight = ();
                   1628:     my $ctsparts = 0;
1.41      ng       1629:     $result.='<table border="0">';
1.45      ng       1630:     my %seen = ();
1.42      ng       1631:     for (sort keys(%$handgrade)) {
1.54      albertel 1632: 	my ($partid,$respid) = split (/_/,$_,2);
1.45      ng       1633: 	next if $seen{$partid};
                   1634: 	$seen{$partid}++;
1.42      ng       1635: 	my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
                   1636: 	my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
                   1637: 	$weight{$partid} = $wgt eq '' ? '1' : $wgt;
                   1638: 
1.44      ng       1639: 	$result.='<input type="hidden" name="partid_'.
                   1640: 	    $ctsparts.'" value="'.$partid.'" />'."\n";
                   1641: 	$result.='<input type="hidden" name="weight_'.
                   1642: 	    $partid.'" value="'.$weight{$partid}.'" />'."\n";
                   1643: 	$result.='<tr><td><b>Part  '.$partid.'&nbsp; &nbsp;Point:</b> </td><td>';
1.42      ng       1644: 	$result.='<table border="0"><tr>';  
1.41      ng       1645: 	my $ctr = 0;
1.42      ng       1646: 	while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
                   1647: 	    $result.= '<td><input type="radio" name="RADVAL_'.$partid.'" '.
1.54      albertel 1648: 		'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.41      ng       1649: 		','.$ctr.')" />'.$ctr."</td>\n";
                   1650: 	    $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
                   1651: 	    $ctr++;
                   1652: 	}
                   1653: 	$result.='</tr></table>';
1.44      ng       1654: 	$result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
1.54      albertel 1655: 	    $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
                   1656: 		$partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.42      ng       1657: 	    $weight{$partid}.' (problem weight)</td>'."\n";
                   1658: 	$result.= '</td><td><select name="SELVAL_'.$partid.'"'.
1.54      albertel 1659: 	    'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59      albertel 1660: 		$weight{$partid}.')"> '.
1.42      ng       1661: 	    '<option selected="on"> </option>'.
                   1662: 	    '<option>excused</option></select></td></tr>'."\n";
                   1663: 	$ctsparts++;
1.41      ng       1664:     }
1.52      albertel 1665:     $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
                   1666: 	'<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.42      ng       1667:     $result.='<input type="button" value="Reset" '.
1.43      ng       1668: 	'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self> &nbsp; &nbsp;';
1.45      ng       1669:     $result.='<input type="button" value="Submit Changes" '.
                   1670: 	'onClick="javascript:submit();" TARGET=_self />'."\n";
1.41      ng       1671: 
1.44      ng       1672:     #table listing all the students in a section/class
                   1673:     #header of table
1.52      albertel 1674:     $result.= '<h3>Assign Grade to Specific Students in ';
                   1675:     if ($ENV{'form.section'} eq 'all') {
                   1676: 	$result.='the Class </h3>';
                   1677:     } elsif ($ENV{'form.section'} eq 'no') {
                   1678: 	$result.='no Section </h3>';
                   1679:     } else {
                   1680: 	$result.='Section '.$ENV{'form.section'}.'</h3>';
                   1681:     }
1.42      ng       1682:     $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.41      ng       1683: 	'<table border=0><tr bgcolor="#deffff">'.
1.44      ng       1684: 	'<td><b>Fullname</b></td><td><b>Username</b></td><td><b>Domain</b></td>'."\n";
1.41      ng       1685:     my (@parts) = sort(&getpartlist($url));
                   1686:     foreach my $part (@parts) {
                   1687: 	my $display=&Apache::lonnet::metadata($url,$part.'.display');
                   1688: 	if  (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
                   1689: 	if ($display =~ /^Partial Credit Factor/) {
1.54      albertel 1690: 	    my ($partid) = &split_part_type($part);
1.53      albertel 1691: 	    $result.='<td><b>Score Part '.$partid.'<br />(weight = '.
1.42      ng       1692: 		$weight{$partid}.')</b></td>'."\n";
1.41      ng       1693: 	    next;
                   1694: 	}
1.53      albertel 1695: 	$display =~ s|Problem Status|Grade Status<br />|;
1.41      ng       1696: 	$result.='<td><b>'.$display.'</b></td>'."\n";
                   1697:     }
                   1698:     $result.='</tr>';
1.44      ng       1699: 
1.41      ng       1700:     #get info for each student
1.44      ng       1701:     #list all the students - with points and grade status
1.56      matthew  1702:     my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1.41      ng       1703:     my $ctr = 0;
1.53      albertel 1704:     foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.44      ng       1705: 	my ($uname,$udom) = split(/:/);
                   1706: 	$result.='<input type="hidden" name="ctr'.$ctr.'" value="'.$uname.'" />'."\n";
1.41      ng       1707: 	$result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},
                   1708: 				   $_,$$fullname{$_},\@parts,\%weight);
                   1709: 	$ctr++;
                   1710:     }
                   1711:     $result.='</table></td></tr></table>';
                   1712:     $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.45      ng       1713:     $result.='<input type="button" value="Submit Changes" '.
                   1714: 	'onClick="javascript:submit();" TARGET=_self /></form>'."\n";
1.41      ng       1715:     $result.=&show_grading_menu_form($symb,$url);
                   1716:     return $result;
                   1717: }
                   1718: 
1.44      ng       1719: #--- call by previous routine to display each student
1.41      ng       1720: sub viewstudentgrade {
                   1721:     my ($url,$symb,$courseid,$student,$fullname,$parts,$weight) = @_;
1.44      ng       1722:     my ($uname,$udom) = split(/:/,$student);
                   1723:     my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.41      ng       1724:     my $result='<tr bgcolor="#ffffdd"><td>'.
1.44      ng       1725: 	'<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
                   1726: 	'\')"; TARGET=_self>'.$fullname.'</a>'.
                   1727: 	'</td><td>'.$uname.'</td><td align="middle">'.$udom.'</td>'."\n";
1.41      ng       1728:     foreach my $part (@$parts) {
1.54      albertel 1729: 	my ($part,$type) = &split_part_type($part);
1.41      ng       1730: 	my $score=$record{"resource.$part.$type"};
                   1731: 	if ($type eq 'awarded') {
1.42      ng       1732: 	    my $pts = $score eq '' ? '' : $score*$$weight{$part};
                   1733: 	    $result.='<input type="hidden" name="'.
1.54      albertel 1734: 		'GD_'.$uname.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.42      ng       1735: 	    $result.='<td align="middle"><input type="text" name="'.
1.54      albertel 1736: 		'GD_'.$uname.'_'.$part.'_awarded" '.
                   1737: 		'onChange="javascript:changeSelect(\''.$part.'\',\''.$uname.
1.44      ng       1738: 		'\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41      ng       1739: 	} elsif ($type eq 'solved') {
                   1740: 	    my ($status,$foo)=split(/_/,$score,2);
                   1741: 	    $status = 'nothing' if ($status eq '');
1.54      albertel 1742: 	    $result.='<input type="hidden" name="'.'GD_'.$uname.'_'.
                   1743: 		$part.'_solved_s" value="'.$status.'" />'."\n";
1.42      ng       1744: 	    $result.='<td align="middle"><select name="'.
1.54      albertel 1745: 		'GD_'.$uname.'_'.$part.'_solved" '.
                   1746: 		'onChange="javascript:changeOneScore(\''.$part.'\',\''.$uname.'\')" >'."\n";
1.42      ng       1747: 	    my $optsel = '<option selected="on"> </option><option>excused</option>'."\n";
                   1748: 	    $optsel = '<option> </option><option selected="on">excused</option>'."\n"
                   1749: 		if ($status eq 'excused');
1.41      ng       1750: 	    $result.=$optsel;
                   1751: 	    $result.="</select></td>\n";
1.54      albertel 1752: 	} else {
                   1753: 	    $result.='<input type="hidden" name="'.
                   1754: 		'GD_'.$uname.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
                   1755: 		    "\n";
                   1756: 	    $result.='<td align="middle"><input type="text" name="'.
                   1757: 		'GD_'.$uname.'_'.$part.'_'.$type.'" '.
                   1758: 		'value="'.$score.'" size="4" /></td>'."\n";
1.41      ng       1759: 	}
                   1760:     }
                   1761:     $result.='</tr>';
                   1762:     return $result;
1.38      ng       1763: }
                   1764: 
1.44      ng       1765: #--- change scores for all the students in a section/class
                   1766: #    record does not get update if unchanged
1.38      ng       1767: sub editgrades {
1.41      ng       1768:     my ($request) = @_;
                   1769: 
                   1770:     my $symb=$ENV{'form.symb'};
1.43      ng       1771:     my $url =$ENV{'form.url'};
1.45      ng       1772:     my $title='<h3><font color="#339933">Current Grade Status</font></h3>';
1.44      ng       1773:     $title.='<font size=+1><b>Resource: </b>'.$ENV{'form.url'}.'</font><br />'."\n";
                   1774:     $title.='<font size=+1><b>Section: </b>'.$ENV{'form.section'}.'</font>'."\n";
                   1775:     $title.= &show_grading_menu_form ($symb,$url);
                   1776:     my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
1.43      ng       1777:     $result.= '<table border="0"><tr bgcolor="#deffff">'.
                   1778: 	'<td rowspan=2><b>Username</b></td><td rowspan=2><b>Fullname</b></td>'."\n";
                   1779: 
                   1780:     my %scoreptr = (
                   1781: 		    'correct'  =>'correct_by_override',
                   1782: 		    'incorrect'=>'incorrect_by_override',
                   1783: 		    'excused'  =>'excused',
                   1784: 		    'ungraded' =>'ungraded_attempted',
                   1785: 		    'nothing'  => '',
                   1786: 		    );
1.56      matthew  1787:     my ($classlist,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1.34      ng       1788: 
1.44      ng       1789:     my (@partid);
                   1790:     my %weight = ();
1.54      albertel 1791:     my %columns = ();
1.44      ng       1792:     my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54      albertel 1793: 
                   1794:     my (@parts) = sort(&getpartlist($url));
                   1795:     my $header;
1.44      ng       1796:     while ($ctr < $ENV{'form.totalparts'}) {
                   1797: 	my $partid = $ENV{'form.partid_'.$ctr};
                   1798: 	push @partid,$partid;
                   1799: 	$weight{$partid} = $ENV{'form.weight_'.$partid};
                   1800: 	$ctr++;
1.54      albertel 1801:     }
                   1802:     foreach my $partid (@partid) {
                   1803: 	$header .= '<td align="center">&nbsp;<b>Old Score</b>&nbsp;</td>'.
                   1804: 	    '<td align="center">&nbsp;<b>New Score</b>&nbsp;</td>';
                   1805: 	$columns{$partid}=2;
                   1806: 	foreach my $stores (@parts) {
                   1807: 	    my ($part,$type) = &split_part_type($stores);
                   1808: 	    if ($part !~ m/^\Q$partid\E/) { next;}
                   1809: 	    if ($type eq 'awarded' || $type eq 'solved') { next; }
                   1810: 	    my $display=&Apache::lonnet::metadata($url,$stores.'.display');
                   1811: 	    $display =~ s/\[Part: (\w)+\]//;
                   1812: 	    $header .= '<td align="center">&nbsp;<b>Old</b> '.$display.'&nbsp;</td>'.
                   1813: 		'<td align="center">&nbsp;<b>New</b> '.$display.'&nbsp;</td>';
                   1814: 	    $columns{$partid}+=2;
                   1815: 	}
                   1816:     }
                   1817:     foreach my $partid (@partid) {
                   1818: 	$result .= '<td colspan="'.$columns{$partid}.
                   1819: 	    '" align="center"><b>Part '.$partid.
1.44      ng       1820: 	    '</b> (Weight = '.$weight{$partid}.')</td>';
1.54      albertel 1821: 
1.44      ng       1822:     }
                   1823:     $result .= '</tr><tr bgcolor="#deffff">';
1.54      albertel 1824:     $result .= $header;
1.44      ng       1825:     $result .= '</tr>'."\n";
1.13      albertel 1826: 
1.44      ng       1827:     for ($i=0; $i<$ENV{'form.total'}; $i++) {
                   1828: 	my $user = $ENV{'form.ctr'.$i};
                   1829: 	my %newrecord;
                   1830: 	my $updateflag = 0;
                   1831: 	my @userdom = grep /^$user:/,keys %$classlist;
1.54      albertel 1832: 	my (undef,$udom) = split(/:/,$userdom[0]);
1.13      albertel 1833: 
1.44      ng       1834: 	$result .= '<tr bgcolor="#ffffde"><td>'.$user.'&nbsp;</td><td>'.
                   1835: 	    $$fullname{$userdom[0]}.'&nbsp;</td>';
                   1836: 	foreach (@partid) {
1.54      albertel 1837: 	    my $old_aw    = $ENV{'form.GD_'.$user.'_'.$_.'_awarded_s'};
                   1838: 	    my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
                   1839: 	    my $old_part  = $old_aw eq '' ? '' : $old_part_pcr;
                   1840: 	    my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
                   1841: 
                   1842: 	    my $awarded   = $ENV{'form.GD_'.$user.'_'.$_.'_awarded'};
                   1843: 	    my $pcr       = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
                   1844: 	    my $partial   = $awarded eq '' ? '' : $pcr;
1.44      ng       1845: 	    my $score;
                   1846: 	    if ($partial eq '') {
1.54      albertel 1847: 		$score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44      ng       1848: 	    } elsif ($partial > 0) {
                   1849: 		$score = 'correct_by_override';
                   1850: 	    } elsif ($partial == 0) {
                   1851: 		$score = 'incorrect_by_override';
                   1852: 	    }
1.54      albertel 1853: 	    $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_solved'} eq 'excused') &&
1.44      ng       1854: 				   ($score ne 'excused'));
                   1855: 	    $result .= '<td align="center">'.$old_aw.'&nbsp;</td>'.
                   1856: 		'<td align="center">'.$awarded.
                   1857: 		($score eq 'excused' ? $score : '').'&nbsp;</td>';
1.5       albertel 1858: 
1.54      albertel 1859: 	    if (!($old_part eq $partial && $old_score eq $score)) {
                   1860: 		$updateflag = 1;
                   1861: 		$newrecord{'resource.'.$_.'.awarded'}  = $partial if $partial ne '';
                   1862: 		$newrecord{'resource.'.$_.'.solved'}   = $score;
                   1863: 		$rec_update++;
                   1864: 	    }
                   1865: 
                   1866: 	    my $partid=$_;
                   1867: 	    foreach my $stores (@parts) {
                   1868: 		my ($part,$type) = &split_part_type($stores);
                   1869: 		if ($part !~ m/^\Q$partid\E/) { next;}
                   1870: 		if ($type eq 'awarded' || $type eq 'solved') { next; }
                   1871: 		my $old_aw    = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
                   1872: 		my $awarded   = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type};
                   1873: 		if ($awarded ne '' && $awarded ne $old_aw) {
                   1874: 		    $newrecord{'resource.'.$part.'.'.$type}= $awarded;
                   1875: 		    $updateflag=1;
                   1876: 		}
                   1877: 		$result .= '<td align="center">'.$old_aw.'&nbsp;</td>'.
                   1878: 		    '<td align="center">'.$awarded.'&nbsp;</td>';
                   1879: 	    }
1.44      ng       1880: 	}
                   1881: 	$result .= '</tr>'."\n";
                   1882: 	if ($updateflag) {
                   1883: 	    $count++;
                   1884: 	    $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
                   1885: 	    &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},
                   1886: 				    $udom,$user);
                   1887: 	}
                   1888:     }
                   1889:     $result .= '</table></td></tr></table>'."\n";
                   1890:     my $msg = '<b>Number of records updated = '.$rec_update.
                   1891: 	' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
                   1892: 	'<b>Total number of students = '.$ENV{'form.total'}.'</b><br />';
                   1893:     return $title.$msg.$result;
1.5       albertel 1894: }
1.54      albertel 1895: 
                   1896: sub split_part_type {
                   1897:     my ($partstr) = @_;
                   1898:     my ($temp,@allparts)=split(/_/,$partstr);
                   1899:     my $type=pop(@allparts);
                   1900:     my $part=join('.',@allparts);
                   1901:     return ($part,$type);
                   1902: }
                   1903: 
1.44      ng       1904: #------------- end of section for handling grading by section/class ---------
                   1905: #
                   1906: #----------------------------------------------------------------------------
                   1907: 
1.5       albertel 1908: 
1.44      ng       1909: #----------------------------------------------------------------------------
                   1910: #
                   1911: #-------------------------- Next few routines handles grading by csv upload
                   1912: #
                   1913: #--- Javascript to handle csv upload
1.27      albertel 1914: sub csvupload_javascript_reverse_associate {
                   1915:   return(<<ENDPICK);
                   1916:   function verify(vf) {
                   1917:     var foundsomething=0;
                   1918:     var founduname=0;
                   1919:     var founddomain=0;
                   1920:     for (i=0;i<=vf.nfields.value;i++) {
                   1921:       tw=eval('vf.f'+i+'.selectedIndex');
                   1922:       if (i==0 && tw!=0) { founduname=1; }
                   1923:       if (i==1 && tw!=0) { founddomain=1; }
                   1924:       if (i!=0 && i!=1 && tw!=0) { foundsomething=1; }
                   1925:     }
                   1926:     if (founduname==0 || founddomain==0) {
                   1927:       alert('You need to specify at both the username and domain');
                   1928:       return;
                   1929:     }
                   1930:     if (foundsomething==0) {
                   1931:       alert('You need to specify at least one grading field');
                   1932:       return;
                   1933:     }
                   1934:     vf.submit();
                   1935:   }
                   1936:   function flip(vf,tf) {
                   1937:     var nw=eval('vf.f'+tf+'.selectedIndex');
                   1938:     var i;
                   1939:     for (i=0;i<=vf.nfields.value;i++) {
                   1940:       //can not pick the same destination field for both name and domain
                   1941:       if (((i ==0)||(i ==1)) && 
                   1942:           ((tf==0)||(tf==1)) && 
                   1943:           (i!=tf) &&
                   1944:           (eval('vf.f'+i+'.selectedIndex')==nw)) {
                   1945:         eval('vf.f'+i+'.selectedIndex=0;')
                   1946:       }
                   1947:     }
                   1948:   }
                   1949: ENDPICK
                   1950: }
                   1951: 
                   1952: sub csvupload_javascript_forward_associate {
                   1953:   return(<<ENDPICK);
                   1954:   function verify(vf) {
                   1955:     var foundsomething=0;
                   1956:     var founduname=0;
                   1957:     var founddomain=0;
                   1958:     for (i=0;i<=vf.nfields.value;i++) {
                   1959:       tw=eval('vf.f'+i+'.selectedIndex');
                   1960:       if (tw==1) { founduname=1; }
                   1961:       if (tw==2) { founddomain=1; }
                   1962:       if (tw>2) { foundsomething=1; }
                   1963:     }
                   1964:     if (founduname==0 || founddomain==0) {
                   1965:       alert('You need to specify at both the username and domain');
                   1966:       return;
                   1967:     }
                   1968:     if (foundsomething==0) {
                   1969:       alert('You need to specify at least one grading field');
                   1970:       return;
                   1971:     }
                   1972:     vf.submit();
                   1973:   }
                   1974:   function flip(vf,tf) {
                   1975:     var nw=eval('vf.f'+tf+'.selectedIndex');
                   1976:     var i;
                   1977:     //can not pick the same destination field twice
                   1978:     for (i=0;i<=vf.nfields.value;i++) {
                   1979:       if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
                   1980:         eval('vf.f'+i+'.selectedIndex=0;')
                   1981:       }
                   1982:     }
                   1983:   }
                   1984: ENDPICK
                   1985: }
                   1986: 
1.26      albertel 1987: sub csvuploadmap_header {
1.41      ng       1988:     my ($request,$symb,$url,$datatoken,$distotal)= @_;
                   1989:     my $javascript;
                   1990:     if ($ENV{'form.upfile_associate'} eq 'reverse') {
                   1991: 	$javascript=&csvupload_javascript_reverse_associate();
                   1992:     } else {
                   1993: 	$javascript=&csvupload_javascript_forward_associate();
                   1994:     }
1.45      ng       1995: 
                   1996:     my $result='<table border="0">';
                   1997:     $result.='<tr><td colspan=3><font size=+1><b>Resource: </b>'.$url.'</font></td></tr>';
                   1998:     my ($partlist,$handgrade) = &response_type($url);
                   1999:     my ($resptype,$hdgrade)=('','no');
                   2000:     for (sort keys(%$handgrade)) {
                   2001: 	my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
                   2002: 	$resptype = $responsetype;
                   2003: 	$hdgrade = $handgrade if ($handgrade eq 'yes');
                   2004: 	$result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
                   2005: 	    '<td><b>Type: </b>'.$responsetype.'</td>'.
                   2006: 	    '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
                   2007:     }
                   2008:     $result.='</table>';
1.41      ng       2009:     $request->print(<<ENDPICK);
1.26      albertel 2010: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.45      ng       2011: <h3><font color="#339933">Uploading Class Grades</font></h3>
                   2012: $result
1.26      albertel 2013: <hr>
                   2014: <h3>Identify fields</h3>
                   2015: Total number of records found in file: $distotal <hr />
                   2016: Enter as many fields as you can. The system will inform you and bring you back
                   2017: to this page if the data selected is insufficient to run your class.<hr />
                   2018: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
                   2019: <input type="hidden" name="associate"  value="" />
                   2020: <input type="hidden" name="phase"      value="three" />
                   2021: <input type="hidden" name="datatoken"  value="$datatoken" />
                   2022: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
                   2023: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
                   2024: <input type="hidden" name="upfile_associate" 
                   2025:                                        value="$ENV{'form.upfile_associate'}" />
                   2026: <input type="hidden" name="symb"       value="$symb" />
                   2027: <input type="hidden" name="url"        value="$url" />
                   2028: <input type="hidden" name="command"    value="csvuploadassign" />
                   2029: <hr />
                   2030: <script type="text/javascript" language="Javascript">
                   2031: $javascript
                   2032: </script>
                   2033: ENDPICK
1.41      ng       2034: return '';
1.26      albertel 2035: 
                   2036: }
                   2037: 
                   2038: sub csvupload_fields {
1.41      ng       2039:     my ($url) = @_;
                   2040:     my (@parts) = &getpartlist($url);
                   2041:     my @fields=(['username','Student Username'],['domain','Student Domain']);
                   2042:     foreach my $part (sort(@parts)) {
                   2043: 	my @datum;
                   2044: 	my $display=&Apache::lonnet::metadata($url,$part.'.display');
                   2045: 	my $name=$part;
                   2046: 	if  (!$display) { $display = $name; }
                   2047: 	@datum=($name,$display);
                   2048: 	push(@fields,\@datum);
                   2049:     }
                   2050:     return (@fields);
1.26      albertel 2051: }
                   2052: 
                   2053: sub csvuploadmap_footer {
1.41      ng       2054:     my ($request,$i,$keyfields) =@_;
                   2055:     $request->print(<<ENDPICK);
1.26      albertel 2056: </table>
                   2057: <input type="hidden" name="nfields" value="$i" />
                   2058: <input type="hidden" name="keyfields" value="$keyfields" />
                   2059: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
                   2060: </form>
                   2061: ENDPICK
                   2062: }
                   2063: 
                   2064: sub csvuploadmap {
1.41      ng       2065:     my ($request)= @_;
                   2066:     my ($symb,$url)=&get_symb_and_url($request);
                   2067:     if (!$symb) {return '';}
                   2068:     my $datatoken;
                   2069:     if (!$ENV{'form.datatoken'}) {
                   2070: 	$datatoken=&Apache::loncommon::upfile_store($request);
1.26      albertel 2071:     } else {
1.41      ng       2072: 	$datatoken=$ENV{'form.datatoken'};
                   2073: 	&Apache::loncommon::load_tmp_file($request);
1.26      albertel 2074:     }
1.41      ng       2075:     my @records=&Apache::loncommon::upfile_record_sep();
                   2076:     &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
                   2077:     my ($i,$keyfields);
                   2078:     if (@records) {
                   2079: 	my @fields=&csvupload_fields($url);
1.45      ng       2080: 
1.41      ng       2081: 	if ($ENV{'form.upfile_associate'} eq 'reverse') {	
                   2082: 	    &Apache::loncommon::csv_print_samples($request,\@records);
                   2083: 	    $i=&Apache::loncommon::csv_print_select_table($request,\@records,
                   2084: 							  \@fields);
                   2085: 	    foreach (@fields) { $keyfields.=$_->[0].','; }
                   2086: 	    chop($keyfields);
                   2087: 	} else {
                   2088: 	    unshift(@fields,['none','']);
                   2089: 	    $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
                   2090: 							    \@fields);
                   2091: 	    my %sone=&Apache::loncommon::record_sep($records[0]);
                   2092: 	    $keyfields=join(',',sort(keys(%sone)));
                   2093: 	}
                   2094:     }
                   2095:     &csvuploadmap_footer($request,$i,$keyfields);
                   2096:     return '';
1.27      albertel 2097: }
                   2098: 
                   2099: sub csvuploadassign {
1.41      ng       2100:     my ($request)= @_;
                   2101:     my ($symb,$url)=&get_symb_and_url($request);
                   2102:     if (!$symb) {return '';}
                   2103:     &Apache::loncommon::load_tmp_file($request);
1.44      ng       2104:     my @gradedata = &Apache::loncommon::upfile_record_sep();
1.41      ng       2105:     my @keyfields = split(/\,/,$ENV{'form.keyfields'});
                   2106:     my %fields=();
                   2107:     for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
                   2108: 	if ($ENV{'form.upfile_associate'} eq 'reverse') {
                   2109: 	    if ($ENV{'form.f'.$i} ne 'none') {
                   2110: 		$fields{$keyfields[$i]}=$ENV{'form.f'.$i};
                   2111: 	    }
                   2112: 	} else {
                   2113: 	    if ($ENV{'form.f'.$i} ne 'none') {
                   2114: 		$fields{$ENV{'form.f'.$i}}=$keyfields[$i];
                   2115: 	    }
                   2116: 	}
1.27      albertel 2117:     }
1.41      ng       2118:     $request->print('<h3>Assigning Grades</h3>');
                   2119:     my $courseid=$ENV{'request.course.id'};
                   2120:     my ($classlist) = &getclasslist('all','1');
                   2121:     my @skipped;
                   2122:     my $countdone=0;
                   2123:     foreach my $grade (@gradedata) {
                   2124: 	my %entries=&Apache::loncommon::record_sep($grade);
                   2125: 	my $username=$entries{$fields{'username'}};
                   2126: 	my $domain=$entries{$fields{'domain'}};
                   2127: 	if (!exists($$classlist{"$username:$domain"})) {
                   2128: 	    push(@skipped,"$username:$domain");
                   2129: 	    next;
                   2130: 	}
                   2131: 	my %grades;
                   2132: 	foreach my $dest (keys(%fields)) {
                   2133: 	    if ($dest eq 'username' || $dest eq 'domain') { next; }
                   2134: 	    if ($entries{$fields{$dest}} eq '') { next; }
                   2135: 	    my $store_key=$dest;
                   2136: 	    $store_key=~s/^stores/resource/;
                   2137: 	    $store_key=~s/_/\./g;
                   2138: 	    $grades{$store_key}=$entries{$fields{$dest}};
                   2139: 	}
                   2140: 	$grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
                   2141: 	&Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
                   2142: 				$domain,$username);
                   2143: 	$request->print('.');
                   2144: 	$request->rflush();
                   2145: 	$countdone++;
                   2146:     }
                   2147:     $request->print("<br />Stored $countdone students\n");
                   2148:     if (@skipped) {
                   2149: 	$request->print('<br /><font size="+1"><b>Skipped Students</b></font><br />');
                   2150: 	foreach my $student (@skipped) { $request->print("<br />$student"); }
                   2151:     }
                   2152:     $request->print(&view_edit_entire_class_form($symb,$url));
                   2153:     $request->print(&show_grading_menu_form($symb,$url));
                   2154:     return '';
1.26      albertel 2155: }
1.44      ng       2156: #------------- end of section for handling csv file upload ---------
                   2157: #
                   2158: #-------------------------------------------------------------------
                   2159: 
                   2160: #-------------------------- Menu interface -------------------------
                   2161: #
                   2162: #--- Show a Grading Menu button - Calls the next routine ---
                   2163: sub show_grading_menu_form {
                   2164:     my ($symb,$url)=@_;
                   2165:     my $result.='<form action="/adm/grades" method="post">'."\n".
                   2166: 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
                   2167: 	'<input type="hidden" name="url" value="'.$url.'" />'."\n".
                   2168: 	'<input type="hidden" name="command" value="gradingmenu" />'."\n".
                   2169: 	'<input type="submit" name="submit" value="Grading Menu" />'."\n".
                   2170: 	'</form>'."\n";
                   2171:     return $result;
                   2172: }
                   2173: 
                   2174: #--- Displays the main menu page -------
                   2175: sub gradingmenu {
                   2176:     my ($request) = @_;
                   2177:     my ($symb,$url)=&get_symb_and_url($request);
                   2178:     if (!$symb) {return '';}
1.45      ng       2179:     my $result='<h3>&nbsp;<font color="#339933">Select a Grading Method</font></h3>';
1.44      ng       2180:     $result.='<table border="0">';
                   2181:     $result.='<tr><td colspan=3><font size=+1><b>Resource: </b>'.$url.'</font></td></tr>';
                   2182:     my ($partlist,$handgrade) = &response_type($url);
                   2183:     my ($resptype,$hdgrade)=('','no');
                   2184:     for (sort keys(%$handgrade)) {
                   2185: 	my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
                   2186: 	$resptype = $responsetype;
                   2187: 	$hdgrade = $handgrade if ($handgrade eq 'yes');
                   2188: 	$result.='<tr><td><b>Part </b>'.(split(/_/))[0].'</td>'.
                   2189: 	    '<td><b>Type: </b>'.$responsetype.'</td>'.
                   2190: 	    '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
                   2191:     }
                   2192:     $result.='</table>';
                   2193:     $result.=&view_edit_entire_class_form($symb,$url).'<br />';
                   2194:     $result.=&upcsvScores_form($symb,$url).'<br />';
                   2195:     $result.=&viewGradeaStu_form($symb,$url,$resptype,$hdgrade).'<br />';
                   2196:     $result.=&verifyReceipt_form($symb,$url) 
                   2197: 	if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb));
                   2198:  
                   2199:     return $result;
                   2200: }
                   2201: 
                   2202: #--- Menu for grading a section or the whole class ---
                   2203: sub view_edit_entire_class_form {
                   2204:     my ($symb,$url)=@_;
1.56      matthew  2205:     my ($classlist,$sections,undef) = &getclasslist('all','0');
1.44      ng       2206:     my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
                   2207:     $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
1.52      albertel 2208:     $result.='&nbsp;<b>Grade Entire Section or Class</b></td></tr>'."\n";
1.44      ng       2209:     $result.='<tr bgcolor=#ffffe6><td>'."\n";
                   2210:     $result.='<form action="/adm/grades" method="post">'."\n".
                   2211: 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
                   2212: 	'<input type="hidden" name="url" value="'.$url.'" />'."\n".
                   2213: 	'<input type="hidden" name="command" value="viewgrades" />'."\n";
                   2214:     $result.='&nbsp;<b>Select section:</b> <select name="section">'."\n";
1.49      albertel 2215:     if (ref($sections)) {
                   2216: 	foreach (sort (@$sections)) {
                   2217: 	    $result.= '<option>'.$_.'</option>'."\n";
                   2218: 	}
1.44      ng       2219:     }
                   2220:     $result.='<option selected="on">all</select>'."<br />\n";
1.51      albertel 2221:     $result.='&nbsp;<input type="button" onClick="submit();" value="Grade" /></form>'."\n";
1.44      ng       2222:     $result.='</td></tr></table>'."\n";
                   2223:     $result.='</td></tr></table>'."\n";
                   2224:     return $result;
                   2225: }
                   2226: 
                   2227: #--- Menu to upload a csv scores ---
                   2228: sub upcsvScores_form {
                   2229:     my ($symb,$url) = @_;
                   2230:     if (!$symb) {return '';}
1.46      ng       2231:     my $result = '<script type="text/javascript" language="javascript">'."\n".
                   2232: 	'  function checkUpload(formname) {'."\n".
                   2233: 	'    if (formname.upfile.value == "") {'."\n".
                   2234: 	'       alert("Please use the browse button to select a file from your local directory.");'."\n".
                   2235: 	'       return false;'."\n".
                   2236: 	'    }'."\n".
                   2237: 	'    formname.submit();'."\n".
                   2238: 	'  }'."\n".
                   2239: 	'</script>'."\n";
                   2240: 
                   2241:     $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
1.44      ng       2242:     $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
                   2243:     $result.='&nbsp;<b>Specify a file containing the class scores for above resource</b></td></tr>'."\n";
                   2244:     $result.='<tr bgcolor=#ffffe6><td>'."\n";
                   2245:     my $upfile_select=&Apache::loncommon::upfile_select_html();
                   2246:   $result.=<<ENDUPFORM;
                   2247: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
                   2248: <input type="hidden" name="symb" value="$symb" />
                   2249: <input type="hidden" name="url" value="$url" />
                   2250: <input type="hidden" name="command" value="csvuploadmap" />
                   2251: $upfile_select
1.46      ng       2252: <br />&nbsp;<input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Grades" />
1.44      ng       2253: </form>
                   2254: ENDUPFORM
                   2255:     $result.='</td></tr></table>'."\n";
                   2256:     $result.='</td></tr></table>'."\n";
                   2257:     return $result;
                   2258: }
                   2259: 
                   2260: #--- Handgrading problems ---
                   2261: sub viewGradeaStu_form {
                   2262:     my ($symb,$url,$response,$handgrade) = @_;
                   2263:     my ($classlist,$sections) = &getclasslist('all','0');
                   2264:     my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
                   2265:     $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
1.49      albertel 2266:     $result.='&nbsp;<b>';
                   2267:     if ($handgrade eq 'yes') {
                   2268: 	$result.="View/Grade ";
                   2269:     } else {
                   2270: 	$result.="View ";
                   2271:     }
                   2272:     $result.='an Individual Student\'s Submission</b></td></tr>'."\n";
1.44      ng       2273:     $result.='<tr bgcolor=#ffffe6><td>'."\n";
                   2274:     $result.='<form action="/adm/grades" method="post">'."\n".
                   2275: 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
                   2276: 	'<input type="hidden" name="url" value="'.$url.'" />'."\n".
                   2277: 	'<input type="hidden" name="response" value="'.$response.'" />'."\n".
                   2278: 	'<input type="hidden" name="handgrade" value="'.$handgrade.'" />'."\n".
                   2279: 	'<input type="hidden" name="showgrading" value="yes" />'."\n".
                   2280: 	'<input type="hidden" name="command" value="submission" />'."\n";
1.26      albertel 2281: 
1.44      ng       2282:     $result.='&nbsp;<b>Select section:</b> <select name="section">'."\n";
1.49      albertel 2283:     if (ref($sections)) {
                   2284: 	foreach (sort (@$sections)) {$result.='<option>'.$_.'</option>'."\n";}
1.44      ng       2285:     }
                   2286:     $result.= '<option selected="on">all</select>'."\n";
                   2287:     $result.='&nbsp;&nbsp;<b>Display students who has: </b>'.
                   2288: 	'<input type="radio" name="submitonly" value="yes" checked> submitted'.
                   2289: 	'<input type="radio" name="submitonly" value="all"> everybody <br />';
1.49      albertel 2290:     if (ref($sections)) {
                   2291: 	$result.='&nbsp;(Section "no" implies the students were not assigned a section.)<br />' 
                   2292: 	    if (grep /no/,@$sections);
                   2293:     }
                   2294: 
                   2295: 
                   2296:     $result.='<br />&nbsp;<input type="button" onClick="submit();" value="';
                   2297:     if ($handgrade eq 'yes') {
                   2298: 	$result.="View/Grade";
                   2299:     } else {
                   2300: 	$result.="View";
                   2301:     }
                   2302:     $result.='" />'."\n".'</form>'."\n";
1.44      ng       2303:     $result.='</td></tr></table>'."\n";
                   2304:     $result.='</td></tr></table>'."\n";
                   2305:     return $result;
1.2       albertel 2306: }
                   2307: 
1.44      ng       2308: #--- Form to input a receipt number ---
                   2309: sub verifyReceipt_form {
                   2310:     my ($symb,$url) = @_;
1.46      ng       2311:     my $result = '<script type="text/javascript" language="javascript">'."\n".
                   2312: 	'  function checkEntry(formname) {'."\n".
                   2313: 	'    var receipt = formname.receipt.value;'."\n".
                   2314: 	'    if (isNaN(receipt) || receipt == "") {'."\n".
                   2315: 	'       alert("Please enter a receipt number given by a student in the box.");'."\n".
                   2316: 	'       return false;'."\n".
                   2317: 	'    }'."\n".
                   2318: 	'    formname.submit();'."\n".
                   2319: 	'  }'."\n".
                   2320: 	'</script>'."\n";
                   2321: 
1.44      ng       2322:     my $hostver=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'});
                   2323: 
1.46      ng       2324:     $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
1.44      ng       2325:     $result.='<table width=100% border=0><tr><td bgcolor=#e6ffff>'."\n";
                   2326:     $result.='&nbsp;<b>Verify a Submission Receipt Issued by this Server</td></tr>'."\n";
                   2327:     $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.46      ng       2328:     $result.='<form action="/adm/grades" method="post" name="verifyform">'."\n";
1.44      ng       2329:     $result.='&nbsp;<tt>'.$hostver.'-<input type="text" name="receipt" size="4"></tt><br />'."\n";
1.46      ng       2330:     $result.='&nbsp;<input type="button" onClick="javascript:checkEntry(this.form);"'.
                   2331: 	' value="Verify Receipt">'."\n";
1.44      ng       2332:     $result.='<input type="hidden" name="command" value="verify">'."\n";
                   2333:     if ($ENV{'form.url'}) {
                   2334: 	$result.='<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />';
                   2335:     }
                   2336:     if ($ENV{'form.symb'}) {
                   2337: 	$result.='<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />';
                   2338:     }
                   2339:     $result.='</form>';
                   2340:     $result.='</td></tr></table>'."\n";
                   2341:     $result.='</td></tr></table>'."\n";
                   2342:     return $result;
1.2       albertel 2343: }
                   2344: 
1.1       albertel 2345: sub handler {
1.41      ng       2346:     my $request=$_[0];
                   2347:     
                   2348:     if ($ENV{'browser.mathml'}) {
                   2349: 	$request->content_type('text/xml');
                   2350:     } else {
                   2351: 	$request->content_type('text/html');
                   2352:     }
                   2353:     $request->send_http_header;
1.44      ng       2354:     return '' if $request->header_only;
1.41      ng       2355:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
                   2356:     my $url=$ENV{'form.url'};
                   2357:     my $symb=$ENV{'form.symb'};
                   2358:     my $command=$ENV{'form.command'};
                   2359:     if (!$url) {
                   2360: 	my ($temp1,$temp2);
                   2361: 	($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
                   2362: 	$url = $ENV{'form.url'};
                   2363:     }
                   2364:     &send_header($request);
                   2365:     if ($url eq '' && $symb eq '') {
                   2366: 	if ($ENV{'user.adv'}) {
                   2367: 	    if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
                   2368: 		($ENV{'form.codethree'})) {
                   2369: 		my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
                   2370: 		    $ENV{'form.codethree'};
                   2371: 		my ($tsymb,$tuname,$tudom,$tcrsid)=
                   2372: 		    &Apache::lonnet::checkin($token);
                   2373: 		if ($tsymb) {
                   2374: 		    my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
                   2375: 		    if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
                   2376: 			$request->print(
                   2377: 					&Apache::lonnet::ssi('/res/'.$url,
                   2378: 							     ('grade_username' => $tuname,
                   2379: 							      'grade_domain' => $tudom,
                   2380: 							      'grade_courseid' => $tcrsid,
                   2381: 							      'grade_symb' => $tsymb)));
                   2382: 		    } else {
1.45      ng       2383: 			$request->print('<h3>Not authorized: '.$token.'</h3>');
1.41      ng       2384: 		    }           
                   2385: 		} else {
1.45      ng       2386: 		    $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41      ng       2387: 		}
1.14      www      2388: 	    } else {
1.41      ng       2389: 		$request->print(&Apache::lonxml::tokeninputfield());
                   2390: 	    }
                   2391: 	}
                   2392:     } else {
                   2393: 	$Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
                   2394: 	if ($command eq 'submission') {
                   2395: 	    &listStudents($request) if ($ENV{'form.student'} eq '');
                   2396: 	    &submission($request,0,0) if ($ENV{'form.student'} ne '');
                   2397: 	} elsif ($command eq 'processGroup') {
                   2398: 	    &processGroup($request);
                   2399: 	} elsif ($command eq 'gradingmenu') {
                   2400: 	    $request->print(&gradingmenu($request));
                   2401: 	} elsif ($command eq 'viewgrades') {
                   2402: 	    $request->print(&viewgrades($request));
                   2403: 	} elsif ($command eq 'handgrade') {
                   2404: 	    $request->print(&processHandGrade($request));
                   2405: 	} elsif ($command eq 'editgrades') {
                   2406: 	    $request->print(&editgrades($request));
                   2407: 	} elsif ($command eq 'verify') {
                   2408: 	    $request->print(&verifyreceipt($request));
                   2409: 	} elsif ($command eq 'csvupload') {
                   2410: 	    $request->print(&csvupload($request));
                   2411: 	} elsif ($command eq 'viewclasslist') {
                   2412: 	    $request->print(&viewclasslist($request));
                   2413: 	} elsif ($command eq 'csvuploadmap') {
                   2414: 	    $request->print(&csvuploadmap($request));
                   2415: 	} elsif ($command eq 'csvuploadassign') {
                   2416: 	    if ($ENV{'form.associate'} ne 'Reverse Association') {
                   2417: 		$request->print(&csvuploadassign($request));
                   2418: 	    } else {
                   2419: 		if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
                   2420: 		    $ENV{'form.upfile_associate'} = 'reverse';
                   2421: 		} else {
                   2422: 		    $ENV{'form.upfile_associate'} = 'forward';
                   2423: 		}
                   2424: 		$request->print(&csvuploadmap($request));
                   2425: 	    }
1.26      albertel 2426: 	} else {
1.41      ng       2427: 	    $request->print("Unknown action: $command:");
1.26      albertel 2428: 	}
1.2       albertel 2429:     }
1.41      ng       2430:     &send_footer($request);
1.44      ng       2431:     return '';
                   2432: }
                   2433: 
                   2434: sub send_header {
                   2435:     my ($request)= @_;
                   2436:     $request->print(&Apache::lontexconvert::header());
                   2437: #  $request->print("
                   2438: #<script>
                   2439: #remotewindow=open('','homeworkremote');
                   2440: #remotewindow.close();
                   2441: #</script>"); 
1.47      www      2442:     $request->print(&Apache::loncommon::bodytag('Grading'));
1.44      ng       2443: }
                   2444: 
                   2445: sub send_footer {
                   2446:     my ($request)= @_;
                   2447:     $request->print('</body>');
                   2448:     $request->print(&Apache::lontexconvert::footer());
1.1       albertel 2449: }
                   2450: 
                   2451: 1;
                   2452: 
1.13      albertel 2453: __END__;

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