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

1.17      albertel    1: # The LearningOnline Network with CAPA
1.13      albertel    2: # The LON-CAPA Grading handler
1.17      albertel    3: #
1.151   ! albertel    4: # $Id: grades.pm,v 1.150 2003/11/07 19:10:51 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.68      ng         34: # Year 2003
1.71      ng         35: # February, March H.K. Ng
1.125     ng         36: # July, H. K. Ng
1.30      ng         37: #
1.1       albertel   38: 
                     39: package Apache::grades;
                     40: use strict;
                     41: use Apache::style;
                     42: use Apache::lonxml;
                     43: use Apache::lonnet;
1.3       albertel   44: use Apache::loncommon;
1.112     ng         45: use Apache::lonhtmlcommon;
1.68      ng         46: use Apache::lonnavmaps;
1.1       albertel   47: use Apache::lonhomework;
1.55      matthew    48: use Apache::loncoursedata;
1.38      ng         49: use Apache::lonmsg qw(:user_normal_msg);
1.1       albertel   50: use Apache::Constants qw(:common);
1.87      www        51: use String::Similarity;
                     52: 
                     53: my %oldessays=();
1.103     albertel   54: my %perm=();
1.1       albertel   55: 
1.68      ng         56: # ----- These first few routines are general use routines.----
1.44      ng         57: #
1.146     albertel   58: # --- Retrieve the parts from the metadata file.---
1.44      ng         59: sub getpartlist {
1.146     albertel   60:     my ($url,$symb) = @_;
                     61:     my $partorder = &Apache::lonnet::metadata($url, 'partorder');
                     62:     my @parts;
                     63:     if ($partorder) {
                     64: 	for my $part (split (/,/,$partorder)) {
                     65: 	    if (!&Apache::loncommon::check_if_partid_hidden($part,$symb)) {
                     66: 		push(@parts, $part);
                     67: 	    }
                     68: 	}	    
                     69:     } else {
                     70: 	my $metadata = &Apache::lonnet::metadata($url, 'packages');
                     71: 	foreach (split(/\,/,$metadata)) {
                     72: 	    if ($_ =~ /^part_(.*)$/) {
                     73: 		if (!&Apache::loncommon::check_if_partid_hidden($1,$symb)) {
                     74: 		    push(@parts, $1);
                     75: 		}
                     76: 	    }
1.41      ng         77: 	}
1.16      albertel   78:     }
1.146     albertel   79:     my @stores;
                     80:     foreach my $part (@parts) {
                     81: 	my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
                     82: 	foreach my $key (@metakeys) {
                     83: 	    if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
                     84: 	}
                     85:     }
                     86:     return @stores;
1.2       albertel   87: }
                     88: 
1.44      ng         89: # --- Get the symbolic name of a problem and the url
                     90: sub get_symb_and_url {
                     91:     my ($request) = @_;
                     92:     (my $url=$ENV{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.41      ng         93:     my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.44      ng         94:     if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
                     95:     return ($symb,$url);
1.32      ng         96: }
                     97: 
1.44      ng         98: # --- Retrieve the fullname for a user. Return lastname, first middle ---
                     99: # --- Generation is attached next to the lastname if it exists. ---
1.34      ng        100: sub get_fullname {
1.39      ng        101:     my ($uname,$udom) = @_;
1.34      ng        102:     my %name=&Apache::lonnet::get('environment', ['lastname','generation',
1.55      matthew   103: 						  'firstname','middlename'],
                    104:                                   $udom,$uname);
1.34      ng        105:     my $fullname;
                    106:     my ($tmp) = keys(%name);
                    107:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
1.55      matthew   108:         $fullname = &Apache::loncoursedata::ProcessFullName
                    109:             (@name{qw/lastname generation firstname middlename/});
                    110:     } else {
                    111:         &Apache::lonnet::logthis('grades.pm: no name data for '.$uname.
                    112:                                  '@'.$udom.':'.$tmp);
1.34      ng        113:     }
                    114:     return $fullname;
                    115: }
                    116: 
1.129     ng        117: #--- Format fullname, username:domain if different for display
                    118: #--- Use anywhere where the student names are listed
                    119: sub nameUserString {
                    120:     my ($type,$fullname,$uname,$udom) = @_;
                    121:     if ($type eq 'header') {
                    122: 	return '<b>&nbsp;Fullname&nbsp;</b><font color="#999999">(Username)</font>&nbsp;';
                    123:     } else {
                    124: 	return '&nbsp;'.$fullname.'<font color="#999999">&nbsp;('.$uname.
                    125: 	    ($ENV{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</font>';
                    126:     }
                    127: }
                    128: 
1.44      ng        129: #--- Get the partlist and the response type for a given problem. ---
                    130: #--- Indicate if a response type is coded handgraded or not. ---
1.39      ng        131: sub response_type {
1.125     ng        132:     my ($url,$symb) = shift;
                    133:     $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url))) if ($symb eq '');
1.41      ng        134:     my $allkeys = &Apache::lonnet::metadata($url,'keys');
                    135:     my %seen = ();
1.147     albertel  136:     my (@partlist,%handgrade,%responseType);
1.41      ng        137:     foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
1.147     albertel  138: 	if (/^\w+response_.*/) {
1.41      ng        139: 	    my ($responsetype,$part) = split(/_/,$_,2);
                    140: 	    my ($partid,$respid) = split(/_/,$part);
1.146     albertel  141: 	    if (&Apache::loncommon::check_if_partid_hidden($partid,$symb)) {
                    142: 		next;
                    143: 	    }
1.118     ng        144: 	    $responsetype =~ s/response$//; # make it compatible w/ navmaps - should move to that!!
1.127     ng        145: 	    my ($value) = &Apache::lonnet::EXT('resource.'.$part.'.handgrade',$symb);
1.147     albertel  146: 	    $handgrade{$part} = ($value eq 'yes' ? 'yes' : 'no'); 
                    147: 	    if (!exists($responseType{$partid})) { $responseType{$partid}={}; }
                    148: 	    $responseType{$partid}->{$respid}=$responsetype;
1.41      ng        149: 	    next if ($seen{$partid} > 0);
                    150: 	    $seen{$partid}++;
                    151: 	    push @partlist,$partid;
                    152: 	}
                    153:     }
1.147     albertel  154:     return \@partlist,\%handgrade,\%responseType;
1.39      ng        155: }
                    156: 
1.118     ng        157: #--- Show resource title
                    158: #--- and parts and response type
                    159: sub showResourceInfo {
                    160:     my ($url,$probTitle) = @_;
                    161:     my $result ='<table border="0">'.
                    162: 	'<tr><td colspan=3><font size=+1><b>Current Resource: </b>'.$probTitle.'</font></td></tr>'."\n";
1.147     albertel  163:     my ($partlist,$handgrade,$responseType) = &response_type($url);
1.126     ng        164:     my %resptype = ();
1.122     ng        165:     my $hdgrade='no';
1.147     albertel  166:     for my $part_resID (sort keys(%$handgrade)) {
                    167: 	my $handgrade=$$handgrade{$part_resID};
                    168: 	my ($partID,$resID) = split(/_/,$part_resID);
                    169: 	my $responsetype = $responseType->{$partID}->{$resID};
1.118     ng        170: 	$hdgrade = $handgrade if ($handgrade eq 'yes');
1.147     albertel  171: 	$result.='<tr><td><b>Part </b>'.$partID.' <font color="#999999">'.
                    172: 	    $resID.'</font></td>'.
1.118     ng        173: 	    '<td><b>Type: </b>'.$responsetype.'</td></tr>';
                    174: #	    '<td><b>Handgrade: </b>'.$handgrade.'</td></tr>';
                    175:     }
                    176:     $result.='</table>'."\n";
1.147     albertel  177:     return $result,$responseType,$hdgrade,$partlist,$handgrade;
1.118     ng        178: }
                    179: 
1.148     albertel  180: 
                    181: sub get_order {
                    182:     my ($partid,$respid,$symb,$uname,$udom)=@_;
                    183:     my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
                    184:     $url=&Apache::lonnet::clutter($url);
                    185:     my $subresult=&Apache::lonnet::ssi($url,
                    186: 				       ('grade_target' => 'analyze'),
                    187: 				       ('grade_domain' => $udom),
                    188: 				       ('grade_symb' => $symb),
                    189: 				       ('grade_courseid' => 
                    190: 					        $ENV{'request.course.id'}),
                    191: 				       ('grade_username' => $uname));
1.149     albertel  192:     (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
1.148     albertel  193:     my %analyze=&Apache::lonnet::str2hash($subresult);
                    194:     return ($analyze{"$partid.$respid.shown"});
                    195: }
1.118     ng        196: #--- Clean response type for display
1.148     albertel  197: #--- Currently filters option/rank/radiobutton/match/essay response types only.
1.118     ng        198: sub cleanRecord {
1.148     albertel  199:     my ($answer,$response,$symb,$partid,$respid,$record,$order,$version) = @_;
                    200:     my $grayFont = '<font color="#999999">';
                    201:     if ($response =~ /^(option|rank)$/) {
                    202: 	my %answer=&Apache::lonnet::str2hash($answer);
                    203: 	my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
                    204: 	my ($toprow,$bottomrow);
                    205: 	foreach my $foil (@$order) {
                    206: 	    if ($grading{$foil} == 1) {
                    207: 		$toprow.='<td><b>'.$answer{$foil}.'&nbsp;</b></td>';
                    208: 	    } else {
                    209: 		$toprow.='<td><i>'.$answer{$foil}.'&nbsp;</i></td>';
                    210: 	    }
                    211: 	    $bottomrow.='<td>'.$grayFont.$foil.'</font>&nbsp;</td>';
                    212: 	}
                    213: 	return '<blockquote><table border="1">'.
                    214: 	    '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
                    215: 	    '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
                    216: 	    $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
                    217:     } elsif ($response eq 'match') {
                    218: 	my %answer=&Apache::lonnet::str2hash($answer);
                    219: 	my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
                    220: 	my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
                    221: 	my ($toprow,$middlerow,$bottomrow);
                    222: 	foreach my $foil (@$order) {
                    223: 	    my $item=shift(@items);
                    224: 	    if ($grading{$foil} == 1) {
                    225: 		$toprow.='<td><b>'.$item.'&nbsp;</b></td>';
                    226: 		$middlerow.='<td><b>'.$grayFont.$answer{$foil}.'&nbsp;</font></b></td>';
                    227: 	    } else {
                    228: 		$toprow.='<td><i>'.$item.'&nbsp;</i></td>';
                    229: 		$middlerow.='<td><i>'.$grayFont.$answer{$foil}.'&nbsp;</font></i></td>';
                    230: 	    }
                    231: 	    $bottomrow.='<td>'.$grayFont.$foil.'</font>&nbsp;</td>';
1.118     ng        232: 	}
1.126     ng        233: 	return '<blockquote><table border="1">'.
1.148     albertel  234: 	    '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
                    235: 	    '<tr valign="top"><td>'.$grayFont.'Item ID</font></td>'.
                    236: 	    $middlerow.'</tr>'.
                    237: 	    '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
                    238: 	    $bottomrow.'</tr>'.'</table></blockquote>';
                    239:     } elsif ($response eq 'radiobutton') {
                    240: 	my %answer=&Apache::lonnet::str2hash($answer);
                    241: 	my ($toprow,$bottomrow);
                    242: 	my $correct=($order->[0])+1;
                    243: 	for (my $i=1;$i<=$#$order;$i++) {
                    244: 	    my $foil=$order->[$i];
                    245: 	    if (exists($answer{$foil})) {
                    246: 		if ($i == $correct) {
                    247: 		    $toprow.='<td><b>true</b></td>';
                    248: 		} else {
                    249: 		    $toprow.='<td><i>true</i></td>';
                    250: 		}
                    251: 	    } else {
                    252: 		$toprow.='<td>false</td>';
                    253: 	    }
                    254: 	    $bottomrow.='<td>'.$grayFont.$foil.'</font>&nbsp;</td>';
                    255: 	}
                    256: 	return '<blockquote><table border="1">'.
                    257: 	    '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
                    258: 	    '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
                    259: 	    $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
                    260:     } elsif ($response eq 'essay') {
1.122     ng        261: 	if (! exists ($ENV{'form.'.$symb})) {
                    262: 	    my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
                    263: 						  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    264: 						  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    265: 
                    266: 	    my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
                    267: 	    $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
                    268: 	    $ENV{'form.kwclr'}    = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
                    269: 	    $ENV{'form.kwsize'}   = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
                    270: 	    $ENV{'form.kwstyle'}  = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
                    271: 	    $ENV{'form.'.$symb} = 1; # so that we don't have to read it from disk for multiple sub of the same prob.
                    272: 	}
1.143     albertel  273: 	return '<br /><br /><blockquote><pre>'.&keywords_highlight($answer).'</pre></blockquote>';
1.122     ng        274:     }
1.118     ng        275:     return $answer;
                    276: }
                    277: 
                    278: #-- A couple of common js functions
                    279: sub commonJSfunctions {
                    280:     my $request = shift;
                    281:     $request->print(<<COMMONJSFUNCTIONS);
                    282: <script type="text/javascript" language="javascript">
                    283:     function radioSelection(radioButton) {
                    284: 	var selection=null;
                    285: 	if (radioButton.length > 1) {
                    286: 	    for (var i=0; i<radioButton.length; i++) {
                    287: 		if (radioButton[i].checked) {
                    288: 		    return radioButton[i].value;
                    289: 		}
                    290: 	    }
                    291: 	} else {
                    292: 	    if (radioButton.checked) return radioButton.value;
                    293: 	}
                    294: 	return selection;
                    295:     }
                    296: 
                    297:     function pullDownSelection(selectOne) {
                    298: 	var selection="";
                    299: 	if (selectOne.length > 1) {
                    300: 	    for (var i=0; i<selectOne.length; i++) {
                    301: 		if (selectOne[i].selected) {
                    302: 		    return selectOne[i].value;
                    303: 		}
                    304: 	    }
                    305: 	} else {
1.138     albertel  306:             // only one value it must be the selected one
                    307: 	    return selectOne.value;
1.118     ng        308: 	}
                    309:     }
                    310: </script>
                    311: COMMONJSFUNCTIONS
                    312: }
                    313: 
1.44      ng        314: #--- Dumps the class list with usernames,list of sections,
                    315: #--- section, ids and fullnames for each user.
                    316: sub getclasslist {
1.76      ng        317:     my ($getsec,$filterlist) = @_;
1.121     ng        318:     $getsec = $getsec eq '' ? 'all' : $getsec;
1.56      matthew   319:     my $classlist=&Apache::loncoursedata::get_classlist();
1.49      albertel  320:     # Bail out if we were unable to get the classlist
1.56      matthew   321:     return if (! defined($classlist));
                    322:     #
                    323:     my %sections;
                    324:     my %fullnames;
                    325:     foreach (keys(%$classlist)) {
                    326:         # the following undefs are for 'domain', and 'username' respectively.
                    327: 	my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
                    328:             @{$classlist->{$_}};
1.76      ng        329: 	# filter students according to status selected
1.112     ng        330: 	if ($filterlist && $ENV{'form.Status'} ne 'Any') {
                    331: 	    if ($ENV{'form.Status'} ne $status) {
1.76      ng        332: 		delete ($classlist->{$_});
                    333: 		next;
                    334: 	    }
                    335: 	}
1.44      ng        336: 	$section = ($section ne '' ? $section : 'no');
1.106     albertel  337: 	if (&canview($section)) {
1.103     albertel  338: 	    if ($getsec eq 'all' || $getsec eq $section) {
                    339: 		$sections{$section}++;
                    340: 		$fullnames{$_}=$fullname;
                    341: 	    } else {
                    342: 		delete($classlist->{$_});
                    343: 	    }
                    344: 	} else {
                    345: 	    delete($classlist->{$_});
                    346: 	}
1.44      ng        347:     }
                    348:     my %seen = ();
1.56      matthew   349:     my @sections = sort(keys(%sections));
                    350:     return ($classlist,\@sections,\%fullnames);
1.44      ng        351: }
                    352: 
1.103     albertel  353: sub canmodify {
                    354:     my ($sec)=@_;
                    355:     if ($perm{'mgr'}) {
                    356: 	if (!defined($perm{'mgr_section'})) {
                    357: 	    # can modify whole class
                    358: 	    return 1;
                    359: 	} else {
                    360: 	    if ($sec eq $perm{'mgr_section'}) {
                    361: 		#can modify the requested section
                    362: 		return 1;
                    363: 	    } else {
                    364: 		# can't modify the request section
                    365: 		return 0;
                    366: 	    }
                    367: 	}
                    368:     }
                    369:     #can't modify
                    370:     return 0;
                    371: }
                    372: 
                    373: sub canview {
                    374:     my ($sec)=@_;
                    375:     if ($perm{'vgr'}) {
                    376: 	if (!defined($perm{'vgr_section'})) {
                    377: 	    # can modify whole class
                    378: 	    return 1;
                    379: 	} else {
                    380: 	    if ($sec eq $perm{'vgr_section'}) {
                    381: 		#can modify the requested section
                    382: 		return 1;
                    383: 	    } else {
                    384: 		# can't modify the request section
                    385: 		return 0;
                    386: 	    }
                    387: 	}
                    388:     }
                    389:     #can't modify
                    390:     return 0;
                    391: }
                    392: 
1.44      ng        393: #--- Retrieve the grade status of a student for all the parts
                    394: sub student_gradeStatus {
                    395:     my ($url,$symb,$udom,$uname,$partlist) = @_;
                    396:     my %record     = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
                    397:     my %partstatus = ();
                    398:     foreach (@$partlist) {
1.128     ng        399: 	my ($status,undef)   = split(/_/,$record{"resource.$_.solved"},2);
1.44      ng        400: 	$status              = 'nothing' if ($status eq '');
                    401: 	$partstatus{$_}      = $status;
                    402: 	my $subkey           = "resource.$_.submitted_by";
                    403: 	$partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
                    404:     }
                    405:     return %partstatus;
                    406: }
                    407: 
1.45      ng        408: # hidden form and javascript that calls the form
                    409: # Use by verifyscript and viewgrades
                    410: # Shows a student's view of problem and submission
                    411: sub jscriptNform {
                    412:     my ($url,$symb) = @_;
                    413:     my $jscript='<script type="text/javascript" language="javascript">'."\n".
                    414: 	'    function viewOneStudent(user,domain) {'."\n".
                    415: 	'	document.onestudent.student.value = user;'."\n".
                    416: 	'	document.onestudent.userdom.value = domain;'."\n".
                    417: 	'	document.onestudent.submit();'."\n".
                    418: 	'    }'."\n".
                    419: 	'</script>'."\n";
                    420:     $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
                    421: 	'<input type="hidden" name="symb"    value="'.$symb.'" />'."\n".
                    422: 	'<input type="hidden" name="url"     value="'.$url.'" />'."\n".
1.77      ng        423: 	'<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72      ng        424: 	'<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n".
1.125     ng        425: 	'<input type="hidden" name="Status"  value="'.$ENV{'form.Status'}.'" />'."\n".
1.45      ng        426: 	'<input type="hidden" name="command" value="submission" />'."\n".
                    427: 	'<input type="hidden" name="student" value="" />'."\n".
                    428: 	'<input type="hidden" name="userdom" value="" />'."\n".
                    429: 	'</form>'."\n";
                    430:     return $jscript;
                    431: }
1.39      ng        432: 
1.44      ng        433: #------------------ End of general use routines --------------------
1.87      www       434: 
                    435: #
                    436: # Find most similar essay
                    437: #
                    438: 
                    439: sub most_similar {
                    440:     my ($uname,$udom,$uessay)=@_;
                    441: 
                    442: # ignore spaces and punctuation
                    443: 
                    444:     $uessay=~s/\W+/ /gs;
                    445: 
                    446: # these will be returned. Do not care if not at least 50 percent similar
1.88      www       447:     my $limit=0.6;
1.87      www       448:     my $sname='';
                    449:     my $sdom='';
                    450:     my $scrsid='';
                    451:     my $sessay='';
                    452: # go through all essays ...
                    453:     foreach my $tkey (keys %oldessays) {
                    454: 	my ($tname,$tdom,$tcrsid)=split(/\./,$tkey);
                    455: # ... except the same student
1.88      www       456:         if (($tname ne $uname) || ($tdom ne $udom)) {
1.87      www       457: 	    my $tessay=$oldessays{$tkey};
                    458:             $tessay=~s/\W+/ /gs;
                    459: # String similarity gives up if not even limit
1.88      www       460:             my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87      www       461: # Found one
                    462:             if ($tsimilar>$limit) {
                    463: 		$limit=$tsimilar;
                    464:                 $sname=$tname;
1.88      www       465:                 $sdom=$tdom;
1.87      www       466:                 $scrsid=$tcrsid;
                    467:                 $sessay=$oldessays{$tkey};
                    468:             }
                    469:         } 
                    470:     }
1.88      www       471:     if ($limit>0.6) {
1.87      www       472:        return ($sname,$sdom,$scrsid,$sessay,$limit);
                    473:     } else {
                    474:        return ('','','','',0);
                    475:     }
                    476: }
                    477: 
1.44      ng        478: #-------------------------------------------------------------------
                    479: 
                    480: #------------------------------------ Receipt Verification Routines
1.45      ng        481: #
1.44      ng        482: #--- Check whether a receipt number is valid.---
                    483: sub verifyreceipt {
                    484:     my $request  = shift;
                    485: 
                    486:     my $courseid = $ENV{'request.course.id'};
                    487:     my $receipt  = unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
                    488: 	$ENV{'form.receipt'};
                    489:     $receipt     =~ s/[^\-\d]//g;
                    490:     my $url      = $ENV{'form.url'};
                    491:     my $symb     = $ENV{'form.symb'};
                    492:     unless ($symb) {
                    493: 	$symb    = &Apache::lonnet::symbread($url);
                    494:     }
                    495: 
1.45      ng        496:     my $title.='<h3><font color="#339933">Verifying Submission Receipt '.
                    497: 	$receipt.'</h3></font>'."\n".
1.118     ng        498: 	'<font size=+1><b>Resource: </b>'.$ENV{'form.probTitle'}.'</font><br><br>'."\n";
1.44      ng        499: 
                    500:     my ($string,$contents,$matches) = ('','',0);
1.56      matthew   501:     my (undef,undef,$fullname) = &getclasslist('all','0');
                    502: 
1.53      albertel  503:     foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.44      ng        504: 	my ($uname,$udom)=split(/\:/);
                    505: 	if ($receipt eq 
                    506: 	    &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
                    507: 	    $contents.='<tr bgcolor="#ffffe6"><td>&nbsp;'."\n".
                    508: 		'<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
                    509: 		'\')"; TARGET=_self>'.$$fullname{$_}.'</a>&nbsp;</td>'."\n".
                    510: 		'<td>&nbsp;'.$uname.'&nbsp;</td>'.
                    511: 		'<td>&nbsp;'.$udom.'&nbsp;</td></tr>'."\n";
                    512: 	    
                    513: 	    $matches++;
                    514: 	}
                    515:     }
                    516:     if ($matches == 0) {
                    517: 	$string = $title.'No match found for the above receipt.';
                    518:     } else {
1.45      ng        519: 	$string = &jscriptNform($url,$symb).$title.
1.44      ng        520: 	    'The above receipt matches the following student'.
                    521: 	    ($matches <= 1 ? '.' : 's.')."\n".
                    522: 	    '<table border="0"><tr><td bgcolor="#777777">'."\n".
                    523: 	    '<table border="0"><tr bgcolor="#e6ffff">'."\n".
                    524: 	    '<td><b>&nbsp;Fullname&nbsp;</b></td>'."\n".
                    525: 	    '<td><b>&nbsp;Username&nbsp;</b></td>'."\n".
                    526: 	    '<td><b>&nbsp;Domain&nbsp;</b></td></tr>'."\n".
                    527: 	    $contents.
                    528: 	    '</table></td></tr></table>'."\n";
                    529:     }
1.50      albertel  530:     return $string.&show_grading_menu_form($symb,$url);
1.44      ng        531: }
                    532: 
                    533: #--- This is called by a number of programs.
                    534: #--- Called from the Grading Menu - View/Grade an individual student
                    535: #--- Also called directly when one clicks on the subm button 
                    536: #    on the problem page.
1.30      ng        537: sub listStudents {
1.41      ng        538:     my ($request) = shift;
1.49      albertel  539: 
1.72      ng        540:     my ($symb,$url) = &get_symb_and_url($request);
1.49      albertel  541:     my $cdom      = $ENV{"course.$ENV{'request.course.id'}.domain"};
                    542:     my $cnum      = $ENV{"course.$ENV{'request.course.id'}.num"};
                    543:     my $getsec    = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
                    544:     my $submitonly= $ENV{'form.submitonly'} eq '' ? 'all' : $ENV{'form.submitonly'};
                    545: 
1.118     ng        546:     my $viewgrade = $ENV{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
1.76      ng        547:     $ENV{'form.probTitle'} = $ENV{'form.probTitle'} eq '' ? 
                    548: 	&Apache::lonnet::gettitle($symb) : $ENV{'form.probTitle'};
1.49      albertel  549: 
1.118     ng        550:     my $result='<h3><font color="#339933">&nbsp;'.$viewgrade.
                    551: 	' Submissions for a Student or a Group of Students</font></h3>';
                    552: 
1.122     ng        553:     my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($url,$ENV{'form.probTitle'});
1.118     ng        554:     $result.=$table;
1.49      albertel  555: 
1.45      ng        556:     $request->print(<<LISTJAVASCRIPT);
                    557: <script type="text/javascript" language="javascript">
1.110     ng        558:     function checkSelect(checkBox) {
                    559: 	var ctr=0;
                    560: 	var sense="";
                    561: 	if (checkBox.length > 1) {
                    562: 	    for (var i=0; i<checkBox.length; i++) {
                    563: 		if (checkBox[i].checked) {
                    564: 		    ctr++;
                    565: 		}
                    566: 	    }
                    567: 	    sense = "a student or group of students";
                    568: 	} else {
                    569: 	    if (checkBox.checked) {
                    570: 		ctr = 1;
                    571: 	    }
                    572: 	    sense = "the student";
                    573: 	}
                    574: 	if (ctr == 0) {
1.126     ng        575: 	    alert("Please select "+sense+" before clicking on the Next button.");
1.110     ng        576: 	    return false;
                    577: 	}
                    578: 	document.gradesub.submit();
                    579:     }
                    580: 
                    581:     function reLoadList(formname) {
1.112     ng        582: 	if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110     ng        583: 	formname.command.value = 'submission';
                    584: 	formname.submit();
                    585:     }
1.45      ng        586: </script>
                    587: LISTJAVASCRIPT
                    588: 
1.118     ng        589:     &commonJSfunctions($request);
1.41      ng        590:     $request->print($result);
1.39      ng        591: 
1.118     ng        592:     my $checkhdgrade = ($ENV{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked' : '';
1.119     ng        593:     my $checklastsub = $checkhdgrade eq '' ? 'checked' : '';
1.45      ng        594:     my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'."\n".
1.144     albertel  595: 	'&nbsp;<b>View Problem Text: </b><input type="radio" name="vProb" value="no" checked="on" /> no '."\n".
1.80      ng        596: 	'<input type="radio" name="vProb" value="yes" /> one student '."\n".
1.58      albertel  597: 	'<input type="radio" name="vProb" value="all" /> all students <br />'."\n".
1.144     albertel  598: 	'&nbsp;<b>View Answer: </b><input type="radio" name="vAns" value="no"  /> no '."\n".
                    599: 	'<input type="radio" name="vAns" value="yes" /> one student '."\n".
                    600: 	'<input type="radio" name="vAns" value="all" checked="on" /> all students <br />'."\n".
1.49      albertel  601: 	'&nbsp;<b>Submissions: </b>'."\n";
1.118     ng        602:     if ($ENV{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
                    603: 	$gradeTable.='<input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> essay part only'."\n";
1.49      albertel  604:     }
1.110     ng        605: 
1.112     ng        606:     my $saveStatus = $ENV{'form.Status'} eq '' ? 'Active' : $ENV{'form.Status'};
                    607:     $ENV{'form.Status'} = $saveStatus;
1.110     ng        608: 
1.135     bowersj2  609:     $gradeTable.='<input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last submission only'."\n".
                    610: 	'<input type="radio" name="lastSub" value="last" /> last submission & parts info'."\n".
1.122     ng        611: 	'<input type="radio" name="lastSub" value="datesub" /> by dates and submissions'."\n".
1.45      ng        612: 	'<input type="radio" name="lastSub" value="all" /> all details'."\n".
                    613: 	'<input type="hidden" name="section"     value="'.$getsec.'" />'."\n".
                    614: 	'<input type="hidden" name="submitonly"  value="'.$submitonly.'" />'."\n".
1.65      albertel  615: 	'<input type="hidden" name="handgrade"   value="'.$ENV{'form.handgrade'}.'" /><br />'."\n".
1.64      albertel  616: 	'<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" /><br />'."\n".
1.77      ng        617: 	'<input type="hidden" name="saveState"   value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72      ng        618: 	'<input type="hidden" name="probTitle"   value="'.$ENV{'form.probTitle'}.'" />'."\n".
1.48      albertel  619: 	'<input type="hidden" name="url"  value="'.$url.'" />'."\n".
                    620: 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.110     ng        621: 	'<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
                    622: 
1.124     ng        623:     if (exists($ENV{'form.gradingMenu'}) && exists($ENV{'form.Status'})) {
                    624: 	$gradeTable.='<input type="hidden" name="Status"   value="'.$ENV{'form.Status'}.'" />'."\n";
                    625:     } else {
                    626: 	$gradeTable.='<b>Student Status:</b> '.
                    627: 	    &Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,'javascript:reLoadList(this.form);').'<br />';
                    628:     }
1.112     ng        629: 
1.126     ng        630:     $gradeTable.='To '.lc($viewgrade).' a submission or a group of submissions, click on the check box(es) '.
                    631: 	'next to the student\'s name(s). Then click on the Next button.<br />'."\n".
1.110     ng        632: 	'<input type="hidden" name="command" value="processGroup" />'."\n";
                    633:     $gradeTable.='<input type="button" '."\n".
1.45      ng        634: 	'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1.126     ng        635: 	'value="Next->" />'."\n";
1.134     www       636:     $gradeTable.='<input type="checkbox" name="checkPlag" checked="on">Check For Plagiarism</input>';
1.110     ng        637:     my (undef, undef, $fullname) = &getclasslist($getsec,'1');  
1.45      ng        638:     $gradeTable.='<table border="0"><tr><td bgcolor="#777777">'.
1.110     ng        639: 	'<table border="0"><tr bgcolor="#e6ffff">';
                    640:     my $loop = 0;
                    641:     while ($loop < 2) {
1.126     ng        642: 	$gradeTable.='<td><b>&nbsp;No.</b>&nbsp;</td><td><b>&nbsp;Select&nbsp;</b></td>'.
1.129     ng        643: 	    '<td>'.&nameUserString('header').'</td>';
1.110     ng        644: 	if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
                    645: 	    foreach (sort(@$partlist)) {
                    646: 		$gradeTable.='<td><b>&nbsp;Part '.(split(/_/))[0].' Status&nbsp;</b></td>';
                    647: 	    }
                    648: 	}
                    649: 	$loop++;
1.126     ng        650: #	$gradeTable.='<td></td>' if ($loop%2 ==1);
1.41      ng        651:     }
1.45      ng        652:     $gradeTable.='</tr>'."\n";
1.41      ng        653: 
1.45      ng        654:     my $ctr = 0;
1.53      albertel  655:     foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.41      ng        656: 	my ($uname,$udom) = split(/:/,$student);
1.110     ng        657: 	my %status = ();
                    658: 	if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
                    659: 	    (%status) =&student_gradeStatus($url,$symb,$udom,$uname,$partlist);
1.145     albertel  660: 	    my $submitted = 0;
                    661: 	    my $graded = 1;
1.110     ng        662: 	    foreach (keys(%status)) {
1.145     albertel  663: 		$submitted = 1 if ($status{$_} ne 'nothing');
                    664: 		$graded = 0 if ($status{$_} =~ /^correct/);
1.110     ng        665: 		my ($foo,$partid,$foo1) = split(/\./,$_);
                    666: 		if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145     albertel  667: 		    $submitted = 0;
1.150     albertel  668: 		    my ($part)=split(/\./,$partid);
1.110     ng        669: 		    $gradeTable.='<input type="hidden" name="'.
1.150     albertel  670: 			$student.':'.$part.':submitted_by" value="'.
1.110     ng        671: 			$status{'resource.'.$partid.'.submitted_by'}.'" />';
                    672: 		}
1.41      ng        673: 	    }
1.145     albertel  674: 	    next if (!$submitted && ($submitonly eq 'yes' || $submitonly eq 'graded'));
                    675: 	    next if (!$graded && $submitonly eq 'graded');
1.41      ng        676: 	}
1.34      ng        677: 
1.45      ng        678: 	$ctr++;
1.104     albertel  679: 	if ( $perm{'vgr'} eq 'F' ) {
1.110     ng        680: 	    $gradeTable.='<tr bgcolor="#ffffe6">' if ($ctr%2 ==1);
1.126     ng        681: 	    $gradeTable.='<td align="right">'.$ctr.'&nbsp;</td>'.
                    682: 		'<td align="center"><input type=checkbox name="stuinfo" value="'.
1.110     ng        683: 		$student.':'.$$fullname{$student}.'&nbsp;"></td>'."\n".
1.129     ng        684: 		'<td>'.&nameUserString(undef,$$fullname{$student},$uname,$udom).'</td>'."\n";
1.110     ng        685: 
                    686: 	    if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
                    687: 		foreach (sort keys(%status)) {
                    688: 		    next if (/^resource.*?submitted_by$/);
                    689: 		    $gradeTable.='<td align="middle">&nbsp;'.$status{$_}.'&nbsp;</td>'."\n";
                    690: 		}
1.41      ng        691: 	    }
1.126     ng        692: #	    $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.110     ng        693: 	    $gradeTable.='</tr>'."\n" if ($ctr%2 ==0);
1.41      ng        694: 	}
                    695:     }
1.110     ng        696:     if ($ctr%2 ==1) {
1.126     ng        697: 	$gradeTable.='<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>';
1.110     ng        698: 	    if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
                    699: 		foreach (@$partlist) {
                    700: 		    $gradeTable.='<td>&nbsp;</td>';
                    701: 		}
                    702: 	    }
                    703: 	$gradeTable.='</tr>';
                    704:     }
                    705: 
1.45      ng        706:     $gradeTable.='</table></td></tr></table>'.
                    707: 	'<input type="button" '.
                    708: 	'onClick="javascript:checkSelect(this.form.stuinfo);" '.
1.126     ng        709: 	'value="Next->" /></form>'."\n";
1.45      ng        710:     if ($ctr == 0) {
1.96      albertel  711: 	my $num_students=(scalar(keys(%$fullname)));
                    712: 	if ($num_students eq 0) {
                    713: 	    $gradeTable='<br />&nbsp;<font color="red">There are no students currently enrolled.</font>';
                    714: 	} else {
                    715: 	    $gradeTable='<br />&nbsp;<font color="red">'.
1.110     ng        716: 		'No submissions found for this resource for any students. ('.$num_students.
1.145     albertel  717: 		' checked for submissions)</font><br />';
1.96      albertel  718: 	}
1.46      ng        719:     } elsif ($ctr == 1) {
                    720: 	$gradeTable =~ s/type=checkbox/type=checkbox checked/;
1.45      ng        721:     }
1.50      albertel  722:     $gradeTable.=&show_grading_menu_form($symb,$url);
1.45      ng        723:     $request->print($gradeTable);
1.44      ng        724:     return '';
1.10      ng        725: }
                    726: 
1.44      ng        727: #---- Called from the listStudents routine
                    728: #     Displays the submissions for one student or a group of students
1.34      ng        729: sub processGroup {
1.41      ng        730:     my ($request)  = shift;
                    731:     my $ctr        = 0;
                    732:     my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
                    733: 		      : ($ENV{'form.stuinfo'}));
                    734:     my $total      = scalar(@stuchecked)-1;
1.45      ng        735: 
1.41      ng        736:     foreach (@stuchecked) {
                    737: 	my ($uname,$udom,$fullname) = split(/:/);
1.44      ng        738: 	$ENV{'form.student'}        = $uname;
                    739: 	$ENV{'form.userdom'}        = $udom;
                    740: 	$ENV{'form.fullname'}       = $fullname;
1.41      ng        741: 	&submission($request,$ctr,$total);
                    742: 	$ctr++;
                    743:     }
                    744:     return '';
1.35      ng        745: }
1.34      ng        746: 
1.44      ng        747: #------------------------------------------------------------------------------------
                    748: #
                    749: #-------------------------- Next few routines handles grading by student, essentially
                    750: #                           handles essay response type problem/part
                    751: #
                    752: #--- Javascript to handle the submission page functionality ---
                    753: sub sub_page_js {
                    754:     my $request = shift;
                    755:     $request->print(<<SUBJAVASCRIPT);
                    756: <script type="text/javascript" language="javascript">
1.71      ng        757:     function updateRadio(formname,id,weight) {
1.125     ng        758: 	var gradeBox = formname["GD_BOX"+id];
                    759: 	var radioButton = formname["RADVAL"+id];
                    760: 	var oldpts = formname["oldpts"+id].value;
1.72      ng        761: 	var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71      ng        762: 	gradeBox.value = pts;
                    763: 	var resetbox = false;
                    764: 	if (isNaN(pts) || pts < 0) {
                    765: 	    alert("A number equal or greater than 0 is expected. Entered value = "+pts);
                    766: 	    for (var i=0; i<radioButton.length; i++) {
                    767: 		if (radioButton[i].checked) {
                    768: 		    gradeBox.value = i;
                    769: 		    resetbox = true;
                    770: 		}
                    771: 	    }
                    772: 	    if (!resetbox) {
                    773: 		formtextbox.value = "";
                    774: 	    }
                    775: 	    return;
1.44      ng        776: 	}
1.71      ng        777: 
                    778: 	if (pts > weight) {
                    779: 	    var resp = confirm("You entered a value ("+pts+
                    780: 			       ") greater than the weight for the part. Accept?");
                    781: 	    if (resp == false) {
1.125     ng        782: 		gradeBox.value = oldpts;
1.71      ng        783: 		return;
                    784: 	    }
1.44      ng        785: 	}
1.13      albertel  786: 
1.71      ng        787: 	for (var i=0; i<radioButton.length; i++) {
                    788: 	    radioButton[i].checked=false;
                    789: 	    if (pts == i && pts != "") {
                    790: 		radioButton[i].checked=true;
                    791: 	    }
                    792: 	}
                    793: 	updateSelect(formname,id);
1.125     ng        794: 	formname["stores"+id].value = "0";
1.41      ng        795:     }
1.5       albertel  796: 
1.72      ng        797:     function writeBox(formname,id,pts) {
1.125     ng        798: 	var gradeBox = formname["GD_BOX"+id];
1.71      ng        799: 	if (checkSolved(formname,id) == 'update') {
                    800: 	    gradeBox.value = pts;
                    801: 	} else {
1.125     ng        802: 	    var oldpts = formname["oldpts"+id].value;
1.72      ng        803: 	    gradeBox.value = oldpts;
1.125     ng        804: 	    var radioButton = formname["RADVAL"+id];
1.71      ng        805: 	    for (var i=0; i<radioButton.length; i++) {
                    806: 		radioButton[i].checked=false;
1.72      ng        807: 		if (i == oldpts) {
1.71      ng        808: 		    radioButton[i].checked=true;
                    809: 		}
                    810: 	    }
1.41      ng        811: 	}
1.125     ng        812: 	formname["stores"+id].value = "0";
1.71      ng        813: 	updateSelect(formname,id);
                    814: 	return;
1.41      ng        815:     }
1.44      ng        816: 
1.71      ng        817:     function clearRadBox(formname,id) {
                    818: 	if (checkSolved(formname,id) == 'noupdate') {
                    819: 	    updateSelect(formname,id);
                    820: 	    return;
                    821: 	}
1.125     ng        822: 	gradeSelect = formname["GD_SEL"+id];
1.71      ng        823: 	for (var i=0; i<gradeSelect.length; i++) {
                    824: 	    if (gradeSelect[i].selected) {
                    825: 		var selectx=i;
                    826: 	    }
                    827: 	}
1.125     ng        828: 	var stores = formname["stores"+id];
1.71      ng        829: 	if (selectx == stores.value) { return };
1.125     ng        830: 	var gradeBox = formname["GD_BOX"+id];
1.71      ng        831: 	gradeBox.value = "";
1.125     ng        832: 	var radioButton = formname["RADVAL"+id];
1.71      ng        833: 	for (var i=0; i<radioButton.length; i++) {
                    834: 	    radioButton[i].checked=false;
                    835: 	}
                    836: 	stores.value = selectx;
                    837:     }
1.5       albertel  838: 
1.71      ng        839:     function checkSolved(formname,id) {
1.125     ng        840: 	if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118     ng        841: 	    var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
                    842: 	    if (!reply) {return "noupdate";}
1.120     ng        843: 	    formname.overRideScore.value = 'yes';
1.41      ng        844: 	}
1.71      ng        845: 	return "update";
1.13      albertel  846:     }
1.71      ng        847: 
                    848:     function updateSelect(formname,id) {
1.125     ng        849: 	formname["GD_SEL"+id][0].selected = true;
1.71      ng        850: 	return;
1.41      ng        851:     }
1.33      ng        852: 
1.121     ng        853: //=========== Check that a point is assigned for all the parts  ============
1.71      ng        854:     function checksubmit(formname,val,total,parttot) {
1.121     ng        855: 	formname.gradeOpt.value = val;
1.71      ng        856: 	if (val == "Save & Next") {
                    857: 	    for (i=0;i<=total;i++) {
                    858: 		for (j=0;j<parttot;j++) {
1.125     ng        859: 		    var partid = formname["partid"+i+"_"+j].value;
1.127     ng        860: 		    if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125     ng        861: 			var points = formname["GD_BOX"+i+"_"+partid].value;
1.71      ng        862: 			if (points == "") {
1.125     ng        863: 			    var name = formname["name"+i].value;
1.129     ng        864: 			    var studentID = (name != '' ? name : formname["unamedom"+i].value);
                    865: 			    var resp = confirm("You did not assign a score for "+studentID+
                    866: 					       ", part "+partid+". Continue?");
1.71      ng        867: 			    if (resp == false) {
1.125     ng        868: 				formname["GD_BOX"+i+"_"+partid].focus();
1.71      ng        869: 				return false;
                    870: 			    }
                    871: 			}
                    872: 		    }
                    873: 		    
                    874: 		}
                    875: 	    }
                    876: 	    
                    877: 	}
1.121     ng        878: 	if (val == "Grade Student") {
                    879: 	    formname.showgrading.value = "yes";
                    880: 	    if (formname.Status.value == "") {
                    881: 		formname.Status.value = "Active";
                    882: 	    }
                    883: 	    formname.studentNo.value = total;
                    884: 	}
1.120     ng        885: 	formname.submit();
                    886:     }
                    887: 
1.71      ng        888: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
                    889:     function checkSubmitPage(formname,total) {
                    890: 	noscore = new Array(100);
                    891: 	var ptr = 0;
                    892: 	for (i=1;i<total;i++) {
1.125     ng        893: 	    var partid = formname["q_"+i].value;
1.127     ng        894: 	    if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125     ng        895: 		var points = formname["GD_BOX"+i+"_"+partid].value;
                    896: 		var status = formname["solved"+i+"_"+partid].value;
1.71      ng        897: 		if (points == "" && status != "correct_by_student") {
                    898: 		    noscore[ptr] = i;
                    899: 		    ptr++;
                    900: 		}
                    901: 	    }
                    902: 	}
                    903: 	if (ptr != 0) {
                    904: 	    var sense = ptr == 1 ? ": " : "s: ";
                    905: 	    var prolist = "";
                    906: 	    if (ptr == 1) {
                    907: 		prolist = noscore[0];
                    908: 	    } else {
                    909: 		var i = 0;
                    910: 		while (i < ptr-1) {
                    911: 		    prolist += noscore[i]+", ";
                    912: 		    i++;
                    913: 		}
                    914: 		prolist += "and "+noscore[i];
                    915: 	    }
                    916: 	    var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
                    917: 	    if (resp == false) {
                    918: 		return false;
                    919: 	    }
                    920: 	}
1.45      ng        921: 
1.71      ng        922: 	formname.submit();
                    923:     }
                    924: </script>
                    925: SUBJAVASCRIPT
                    926: }
1.45      ng        927: 
1.71      ng        928: #--- javascript for essay type problem --
                    929: sub sub_page_kw_js {
                    930:     my $request = shift;
1.80      ng        931:     my $iconpath = $request->dir_config('lonIconsURL');
1.118     ng        932:     &commonJSfunctions($request);
1.71      ng        933:     $request->print(<<SUBJAVASCRIPT);
                    934: <script type="text/javascript" language="javascript">
1.45      ng        935: 
1.44      ng        936: //===================== Show list of keywords ====================
1.122     ng        937:   function keywords(formname) {
                    938:     var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
1.44      ng        939:     if (nret==null) return;
1.122     ng        940:     formname.keywords.value = nret;
1.44      ng        941: 
1.122     ng        942:     if (formname.keywords.value != "") {
1.128     ng        943: 	formname.refresh.value = "on";
1.122     ng        944: 	formname.submit();
1.44      ng        945:     }
                    946:     return;
                    947:   }
                    948: 
                    949: //===================== Script to view submitted by ==================
                    950:   function viewSubmitter(submitter) {
                    951:     document.SCORE.refresh.value = "on";
                    952:     document.SCORE.NCT.value = "1";
                    953:     document.SCORE.unamedom0.value = submitter;
                    954:     document.SCORE.submit();
                    955:     return;
                    956:   }
                    957: 
                    958: //===================== Script to add keyword(s) ==================
                    959:   function getSel() {
                    960:     if (document.getSelection) txt = document.getSelection();
                    961:     else if (document.selection) txt = document.selection.createRange().text;
                    962:     else return;
                    963:     var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
                    964:     if (cleantxt=="") {
1.46      ng        965: 	alert("Please select a word or group of words from document and then click this link.");
1.44      ng        966: 	return;
                    967:     }
                    968:     var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
                    969:     if (nret==null) return;
1.127     ng        970:     document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44      ng        971:     if (document.SCORE.keywords.value != "") {
1.127     ng        972: 	document.SCORE.refresh.value = "on";
1.44      ng        973: 	document.SCORE.submit();
                    974:     }
                    975:     return;
                    976:   }
                    977: 
                    978: //====================== Script for composing message ==============
1.80      ng        979:    // preload images
                    980:    img1 = new Image();
                    981:    img1.src = "$iconpath/mailbkgrd.gif";
                    982:    img2 = new Image();
                    983:    img2.src = "$iconpath/mailto.gif";
                    984: 
1.44      ng        985:   function msgCenter(msgform,usrctr,fullname) {
                    986:     var Nmsg  = msgform.savemsgN.value;
                    987:     savedMsgHeader(Nmsg,usrctr,fullname);
                    988:     var subject = msgform.msgsub.value;
1.127     ng        989:     var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44      ng        990:     re = /msgsub/;
                    991:     var shwsel = "";
                    992:     if (re.test(msgchk)) { shwsel = "checked" }
1.123     ng        993:     subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
                    994:     displaySubject(checkEntities(subject),shwsel);
1.44      ng        995:     for (var i=1; i<=Nmsg; i++) {
1.123     ng        996: 	var testmsg = "savemsg"+i+",";
                    997: 	re = new RegExp(testmsg,"g");
1.44      ng        998: 	shwsel = "";
                    999: 	if (re.test(msgchk)) { shwsel = "checked" }
1.125     ng       1000: 	var message = document.SCORE["savemsg"+i].value;
1.126     ng       1001: 	message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123     ng       1002: 	displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
                   1003: 	                                   //any &lt; is already converted to <, etc. However, only once!!
1.44      ng       1004:     }
1.125     ng       1005:     newmsg = document.SCORE["newmsg"+usrctr].value;
1.44      ng       1006:     shwsel = "";
                   1007:     re = /newmsg/;
                   1008:     if (re.test(msgchk)) { shwsel = "checked" }
                   1009:     newMsg(newmsg,shwsel);
                   1010:     msgTail(); 
                   1011:     return;
                   1012:   }
                   1013: 
1.123     ng       1014:   function checkEntities(strx) {
                   1015:     if (strx.length == 0) return strx;
                   1016:     var orgStr = ["&", "<", ">", '"']; 
                   1017:     var newStr = ["&amp;", "&lt;", "&gt;", "&quot;"];
                   1018:     var counter = 0;
                   1019:     while (counter < 4) {
                   1020: 	strx = strReplace(strx,orgStr[counter],newStr[counter]);
                   1021: 	counter++;
                   1022:     }
                   1023:     return strx;
                   1024:   }
                   1025: 
                   1026:   function strReplace(strx, orgStr, newStr) {
                   1027:     return strx.split(orgStr).join(newStr);
                   1028:   }
                   1029: 
1.44      ng       1030:   function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76      ng       1031:     var height = 70*Nmsg+250;
1.44      ng       1032:     var scrollbar = "no";
                   1033:     if (height > 600) {
                   1034: 	height = 600;
                   1035: 	scrollbar = "yes";
                   1036:     }
1.118     ng       1037:     var xpos = (screen.width-600)/2;
                   1038:     xpos = (xpos < 0) ? '0' : xpos;
                   1039:     var ypos = (screen.height-height)/2-30;
                   1040:     ypos = (ypos < 0) ? '0' : ypos;
                   1041: 
                   1042:     pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
1.76      ng       1043:     pWin.focus();
                   1044:     pDoc = pWin.document;
1.128     ng       1045:     pDoc.open('text/html','replace');
1.76      ng       1046:     pDoc.write("<html><head>");
                   1047:     pDoc.write("<title>Message Central</title>");
                   1048: 
                   1049:     pDoc.write("<script language=javascript>");
                   1050:     pDoc.write("function checkInput() {");
1.123     ng       1051:     pDoc.write("  opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);");
1.76      ng       1052:     pDoc.write("  var nmsg   = opener.document.SCORE.savemsgN.value;");
                   1053:     pDoc.write("  var usrctr = document.msgcenter.usrctr.value;");
1.125     ng       1054:     pDoc.write("  var newval = opener.document.SCORE[\\"newmsg\\"+usrctr];");
1.123     ng       1055:     pDoc.write("  newval.value = opener.checkEntities(document.msgcenter.newmsg.value);");
1.76      ng       1056: 
                   1057:     pDoc.write("  var msgchk = \\"\\";");
                   1058:     pDoc.write("  if (document.msgcenter.subchk.checked) {");
                   1059:     pDoc.write("     msgchk = \\"msgsub,\\";");
                   1060:     pDoc.write("  }");
1.80      ng       1061:     pDoc.write("  var includemsg = 0;");
                   1062:     pDoc.write("  for (var i=1; i<=nmsg; i++) {");
1.125     ng       1063:     pDoc.write("      var opnmsg = opener.document.SCORE[\\"savemsg\\"+i];");
                   1064:     pDoc.write("      var frmmsg = document.msgcenter[\\"msg\\"+i];");
1.123     ng       1065:     pDoc.write("      opnmsg.value = opener.checkEntities(frmmsg.value);");
1.125     ng       1066:     pDoc.write("      var showflg = opener.document.SCORE[\\"shownOnce\\"+i];");
1.123     ng       1067:     pDoc.write("      showflg.value = \\"1\\";");
1.125     ng       1068:     pDoc.write("      var chkbox = document.msgcenter[\\"msgn\\"+i];");
1.76      ng       1069:     pDoc.write("      if (chkbox.checked) {");
                   1070:     pDoc.write("         msgchk += \\"savemsg\\"+i+\\",\\";");
1.80      ng       1071:     pDoc.write("         includemsg = 1;");
1.76      ng       1072:     pDoc.write("      }");
                   1073:     pDoc.write("  }");
                   1074:     pDoc.write("  if (document.msgcenter.newmsgchk.checked) {");
                   1075:     pDoc.write("     msgchk += \\"newmsg\\"+usrctr;");
1.80      ng       1076:     pDoc.write("     includemsg = 1;");
                   1077:     pDoc.write("  }");
1.125     ng       1078:     pDoc.write("  imgformname = opener.document.SCORE[\\"mailicon\\"+usrctr];");
1.84      ng       1079:     pDoc.write("  imgformname.src = \\"$iconpath/\\"+((includemsg) ? \\"mailto.gif\\" : \\"mailbkgrd.gif\\");");
1.125     ng       1080:     pDoc.write("  var includemsg = opener.document.SCORE[\\"includemsg\\"+usrctr];");
1.76      ng       1081:     pDoc.write("  includemsg.value = msgchk;");
                   1082: 
                   1083:     pDoc.write("  self.close()");
                   1084: 
                   1085:     pDoc.write("}");
                   1086: 
                   1087:     pDoc.write("<");
                   1088:     pDoc.write("/script>");
                   1089: 
                   1090:     pDoc.write("</head><body bgcolor=white>");
                   1091: 
                   1092:     pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
                   1093:     pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
                   1094:     pDoc.write("<font color=\\"green\\" size=+1>&nbsp;Compose Message for \"+fullname+\"</font><br><br>");
                   1095: 
                   1096:     pDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
                   1097:     pDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
                   1098:     pDoc.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
1.44      ng       1099: }
                   1100:     function displaySubject(msg,shwsel) {
1.76      ng       1101:     pDoc = pWin.document;
                   1102:     pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
                   1103:     pDoc.write("<td>Subject</td>");
                   1104:     pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
                   1105:     pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.44      ng       1106: }
                   1107: 
1.72      ng       1108:   function displaySavedMsg(ctr,msg,shwsel) {
1.76      ng       1109:     pDoc = pWin.document;
                   1110:     pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
                   1111:     pDoc.write("<td align=\\"center\\">"+ctr+"</td>");
                   1112:     pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
                   1113:     pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"</textarea></td></tr>");
1.44      ng       1114: }
                   1115: 
                   1116:   function newMsg(newmsg,shwsel) {
1.76      ng       1117:     pDoc = pWin.document;
                   1118:     pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
                   1119:     pDoc.write("<td align=\\"center\\">New</td>");
                   1120:     pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
                   1121:     pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"</textarea></td></tr>");
1.44      ng       1122: }
                   1123: 
                   1124:   function msgTail() {
1.76      ng       1125:     pDoc = pWin.document;
                   1126:     pDoc.write("</table>");
                   1127:     pDoc.write("</td></tr></table>&nbsp;");
                   1128:     pDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\">&nbsp;&nbsp;");
                   1129:     pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
                   1130:     pDoc.write("</form>");
                   1131:     pDoc.write("</body></html>");
1.128     ng       1132:     pDoc.close();
1.44      ng       1133: }
                   1134: 
                   1135: //====================== Script for keyword highlight options ==============
                   1136:   function kwhighlight() {
                   1137:     var kwclr    = document.SCORE.kwclr.value;
                   1138:     var kwsize   = document.SCORE.kwsize.value;
                   1139:     var kwstyle  = document.SCORE.kwstyle.value;
                   1140:     var redsel = "";
                   1141:     var grnsel = "";
                   1142:     var blusel = "";
                   1143:     if (kwclr=="red")   {var redsel="checked"};
                   1144:     if (kwclr=="green") {var grnsel="checked"};
                   1145:     if (kwclr=="blue")  {var blusel="checked"};
                   1146:     var sznsel = "";
                   1147:     var sz1sel = "";
                   1148:     var sz2sel = "";
                   1149:     if (kwsize=="0")  {var sznsel="checked"};
                   1150:     if (kwsize=="+1") {var sz1sel="checked"};
                   1151:     if (kwsize=="+2") {var sz2sel="checked"};
                   1152:     var synsel = "";
                   1153:     var syisel = "";
                   1154:     var sybsel = "";
                   1155:     if (kwstyle=="")    {var synsel="checked"};
                   1156:     if (kwstyle=="<i>") {var syisel="checked"};
                   1157:     if (kwstyle=="<b>") {var sybsel="checked"};
                   1158:     highlightCentral();
                   1159:     highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
                   1160:     highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
                   1161:     highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
                   1162:     highlightend();
                   1163:     return;
                   1164:   }
                   1165: 
                   1166:   function highlightCentral() {
1.76      ng       1167: //    if (window.hwdWin) window.hwdWin.close();
1.118     ng       1168:     var xpos = (screen.width-400)/2;
                   1169:     xpos = (xpos < 0) ? '0' : xpos;
                   1170:     var ypos = (screen.height-330)/2-30;
                   1171:     ypos = (ypos < 0) ? '0' : ypos;
                   1172: 
                   1173:     hwdWin = window.open('', 'KeywordHighlightCentral', 'toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76      ng       1174:     hwdWin.focus();
                   1175:     var hDoc = hwdWin.document;
1.128     ng       1176:     hDoc.open('text/html','replace');
1.76      ng       1177:     hDoc.write("<html><head>");
                   1178:     hDoc.write("<title>Highlight Central</title>");
                   1179: 
                   1180:     hDoc.write("<script language=javascript>");
                   1181:     hDoc.write("function updateChoice(flag) {");
1.118     ng       1182:     hDoc.write("  opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);");
                   1183:     hDoc.write("  opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);");
                   1184:     hDoc.write("  opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);");
1.76      ng       1185:     hDoc.write("  opener.document.SCORE.refresh.value = \\"on\\";");
                   1186:     hDoc.write("  if (opener.document.SCORE.keywords.value!=\\"\\"){");
                   1187:     hDoc.write("     opener.document.SCORE.submit();");
                   1188:     hDoc.write("  }");
                   1189:     hDoc.write("  self.close()");
                   1190:     hDoc.write("}");
                   1191: 
                   1192:     hDoc.write("<");
                   1193:     hDoc.write("/script>");
                   1194: 
                   1195:     hDoc.write("</head><body bgcolor=white>");
                   1196: 
                   1197:     hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
                   1198:     hDoc.write("<font color=\\"green\\" size=+1>&nbsp;Keyword Highlight Options</font><br><br>");
                   1199: 
                   1200:     hDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
                   1201:     hDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
                   1202:     hDoc.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
1.44      ng       1203:   }
                   1204: 
                   1205:   function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) { 
1.76      ng       1206:     var hDoc = hwdWin.document;
                   1207:     hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
                   1208:     hDoc.write("<td align=\\"left\\">");
                   1209:     hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+">&nbsp;"+clrtxt+"</td>");
                   1210:     hDoc.write("<td align=\\"left\\">");
                   1211:     hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+">&nbsp;"+sztxt+"</td>");
                   1212:     hDoc.write("<td align=\\"left\\">");
                   1213:     hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+">&nbsp;"+sytxt+"</td>");
                   1214:     hDoc.write("</tr>");
1.44      ng       1215:   }
                   1216: 
                   1217:   function highlightend() { 
1.76      ng       1218:     var hDoc = hwdWin.document;
                   1219:     hDoc.write("</table>");
                   1220:     hDoc.write("</td></tr></table>&nbsp;");
                   1221:     hDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\">&nbsp;&nbsp;");
                   1222:     hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
                   1223:     hDoc.write("</form>");
                   1224:     hDoc.write("</body></html>");
1.128     ng       1225:     hDoc.close();
1.44      ng       1226:   }
                   1227: 
                   1228: </script>
                   1229: SUBJAVASCRIPT
                   1230: }
                   1231: 
1.71      ng       1232: #--- displays the grading box, used in essay type problem and grading by page/sequence
                   1233: sub gradeBox {
                   1234:     my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
                   1235: 
                   1236:     my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
                   1237: 	'/check.gif" height="16" border="0" />';
                   1238: 
                   1239:     my $wgt    = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
                   1240:     my $wgtmsg = ($wgt > 0 ? '(problem weight)' : 
                   1241: 		  '<font color="red">problem weight assigned by computer</font>');
                   1242:     $wgt       = ($wgt > 0 ? $wgt : '1');
                   1243:     my $score  = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
                   1244: 		  '' : $$record{'resource.'.$partid.'.awarded'}*$wgt);
                   1245:     my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
                   1246: 
                   1247:     $result.='<table border="0"><tr><td>'.
                   1248: 	'<b>Part </b>'.$partid.' <b>Points: </b></td><td>'."\n";
                   1249: 
                   1250:     my $ctr = 0;
                   1251:     $result.='<table border="0"><tr>'."\n";  # display radio buttons in a nice table 10 across
                   1252:     while ($ctr<=$wgt) {
                   1253: 	$result.= '<td><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
                   1254: 	    'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.72      ng       1255: 	    $ctr.')" value="'.$ctr.'" '.
1.71      ng       1256: 	    ($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
                   1257: 	$result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
                   1258: 	$ctr++;
                   1259:     }
                   1260:     $result.='</tr></table>';
                   1261: 
                   1262:     $result.='</td><td>&nbsp;<b>or</b>&nbsp;</td>'."\n";
                   1263:     $result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
                   1264: 	($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
                   1265: 	'onChange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
                   1266: 	$wgt.')" /></td>'."\n";
                   1267:     $result.='<td>/'.$wgt.' '.$wgtmsg.
                   1268: 	($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? '&nbsp;'.$checkIcon : '').
                   1269: 	' </td><td>'."\n";
                   1270: 
                   1271:     $result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
                   1272: 	'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
                   1273:     if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
                   1274: 	$result.='<option> </option>'.
1.125     ng       1275: 	    '<option selected="on">excused</option>';
1.71      ng       1276:     } else {
                   1277: 	$result.='<option selected="on"> </option>'.
1.125     ng       1278: 	    '<option>excused</option>';
1.71      ng       1279:     }
1.125     ng       1280:     $result.='<option>reset status</option></select>'."\n";
1.71      ng       1281:     $result.="&nbsp&nbsp\n";
                   1282:     $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
                   1283: 	'<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
                   1284: 	'<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
                   1285: 	$$record{'resource.'.$partid.'.solved'}.'" />'."\n";
                   1286:     $result.='</td></tr></table>'."\n";
                   1287:     return $result;
                   1288: }
1.44      ng       1289: 
1.58      albertel 1290: sub show_problem {
1.144     albertel 1291:     my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode) = @_;
                   1292:     my $rendered;
                   1293:     if ($mode eq 'both' or $mode eq 'text') {
                   1294: 	$rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
                   1295: 					     $ENV{'request.course.id'});
                   1296:     }
1.58      albertel 1297:     if ($removeform) {
                   1298: 	$rendered=~s|<form(.*?)>||g;
                   1299: 	$rendered=~s|</form>||g;
                   1300: 	$rendered=~s|name="submit"|name="would_have_been_submit"|g;
                   1301:     }
1.144     albertel 1302:     my $companswer;
                   1303:     if ($mode eq 'both' or $mode eq 'answer') {
                   1304: 	$companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
                   1305: 						    $ENV{'request.course.id'});
                   1306:     }
1.58      albertel 1307:     if ($removeform) {
                   1308: 	$companswer=~s|<form(.*?)>||g;
                   1309: 	$companswer=~s|</form>||g;
1.144     albertel 1310: 	$companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58      albertel 1311:     }
                   1312:     my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.71      ng       1313:     $result.='<table border="0" width="100%">';
1.144     albertel 1314:     if ($viewon) {
                   1315: 	$result.='<tr><td bgcolor="#e6ffff"><b> ';
                   1316: 	if ($mode eq 'both' or $mode eq 'text') {
                   1317: 	    $result.='View of the problem - ';
                   1318: 	} else {
                   1319: 	    $result.='Correct answer: ';
                   1320: 	}
                   1321: 	$result.=$ENV{'form.fullname'}.'</b></td></tr>';
                   1322:     }
                   1323:     if ($mode eq 'both') {
                   1324: 	$result.='<tr><td bgcolor="#ffffff">'.$rendered.'<br />';
                   1325: 	$result.='<b>Correct answer:</b><br />'.$companswer;
                   1326:     } elsif ($mode eq 'text') {
                   1327: 	$result.='<tr><td bgcolor="#ffffff">'.$rendered;
                   1328:     } elsif ($mode eq 'answer') {
                   1329: 	$result.='<tr><td bgcolor="#ffffff">'.$companswer;
                   1330:     }
1.58      albertel 1331:     $result.='</td></tr></table>';
                   1332:     $result.='</td></tr></table><br />';
1.71      ng       1333:     return $result;
1.58      albertel 1334: }
                   1335: 
1.44      ng       1336: # --------------------------- show submissions of a student, option to grade 
                   1337: sub submission {
                   1338:     my ($request,$counter,$total) = @_;
                   1339: 
                   1340:     (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
                   1341:     my ($uname,$udom)     = ($ENV{'form.student'},$ENV{'form.userdom'});
1.120     ng       1342:     $udom = ($udom eq '' ? $ENV{'user.domain'} : $udom); #has form.userdom changed for a student?
1.104     albertel 1343:     my $usec = &Apache::lonnet::getsection($udom,$uname,$ENV{'request.course.id'});
1.44      ng       1344:     $ENV{'form.fullname'} = &get_fullname ($uname,$udom) if $ENV{'form.fullname'} eq '';
1.41      ng       1345: 
                   1346:     my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   1347:     if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
1.104     albertel 1348: 
                   1349:     if (!&canview($usec)) {
1.116     ng       1350: 	$request->print('<font color="red">Unable to view requested student.('.
                   1351: 			$uname.$udom.$usec.$ENV{'request.course.id'}.')</font>');
1.104     albertel 1352: 	$request->print(&show_grading_menu_form($symb,$url));
                   1353: 	return;
                   1354:     }
                   1355: 
1.122     ng       1356:     $ENV{'form.lastSub'} = ($ENV{'form.lastSub'} eq '' ? 'datesub' : $ENV{'form.lastSub'});
1.41      ng       1357:     my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
1.122     ng       1358:     my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
                   1359: 	'/check.gif" height="16" border="0" />';
1.41      ng       1360: 
                   1361:     # header info
                   1362:     if ($counter == 0) {
                   1363: 	&sub_page_js($request);
1.118     ng       1364: 	&sub_page_kw_js($request) if ($ENV{'form.handgrade'} eq 'yes');
1.76      ng       1365: 	$ENV{'form.probTitle'} = $ENV{'form.probTitle'} eq '' ? 
                   1366: 	    &Apache::lonnet::gettitle($symb) : $ENV{'form.probTitle'};
                   1367: 
1.45      ng       1368: 	$request->print('<h3>&nbsp;<font color="#339933">Submission Record</font></h3>'."\n".
1.118     ng       1369: 			'<font size=+1>&nbsp;<b>Resource: </b>'.$ENV{'form.probTitle'}.'</font>'."\n");
                   1370: 
                   1371: 	if ($ENV{'form.handgrade'} eq 'no') {
                   1372: 	    my $checkMark='<br /><br />&nbsp;<b>Note:</b> Part(s) graded correct by the computer is marked with a '.
                   1373: 		$checkIcon.' symbol.'."\n";
                   1374: 	    $request->print($checkMark);
                   1375: 	}
1.41      ng       1376: 
1.44      ng       1377: 	# option to display problem, only once else it cause problems 
                   1378:         # with the form later since the problem has a form.
1.144     albertel 1379: 	if ($ENV{'form.vProb'} eq 'yes' or $ENV{'form.vAns'} eq 'yes') {
                   1380: 	    my $mode;
                   1381: 	    if ($ENV{'form.vProb'} eq 'yes' && $ENV{'form.vAns'} eq 'yes') {
                   1382: 		$mode='both';
                   1383: 	    } elsif ($ENV{'form.vProb'} eq 'yes') {
                   1384: 		$mode='text';
                   1385: 	    } elsif ($ENV{'form.vAns'} eq 'yes') {
                   1386: 		$mode='answer';
                   1387: 	    }
                   1388: 	    $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41      ng       1389: 	}
                   1390: 	
1.44      ng       1391: 	# kwclr is the only variable that is guaranteed to be non blank 
                   1392:         # if this subroutine has been called once.
1.41      ng       1393: 	my %keyhash = ();
1.118     ng       1394: 	if ($ENV{'form.kwclr'} eq '' && $ENV{'form.handgrade'} eq 'yes') {
1.41      ng       1395: 	    %keyhash = &Apache::lonnet::dump('nohist_handgrade',
                   1396: 					     $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1397: 					     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   1398: 
                   1399: 	    my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
                   1400: 	    $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
                   1401: 	    $ENV{'form.kwclr'}    = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
                   1402: 	    $ENV{'form.kwsize'}   = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
                   1403: 	    $ENV{'form.kwstyle'}  = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
                   1404: 	    $ENV{'form.msgsub'}   = $keyhash{$symb.'_subject'} ne '' ? 
1.72      ng       1405: 		$keyhash{$symb.'_subject'} : $ENV{'form.probTitle'};
1.41      ng       1406: 	    $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
                   1407: 	}
1.120     ng       1408: 	my $overRideScore = $ENV{'form.overRideScore'} eq '' ? 'no' : $ENV{'form.overRideScore'};
1.44      ng       1409: 
1.41      ng       1410: 	$request->print('<form action="/adm/grades" method="post" name="SCORE">'."\n".
                   1411: 			'<input type="hidden" name="command"    value="handgrade" />'."\n".
1.80      ng       1412: 			'<input type="hidden" name="saveState"  value="'.$ENV{'form.saveState'}.'" />'."\n".
1.119     ng       1413: 			'<input type="hidden" name="Status"     value="'.$ENV{'form.Status'}.'" />'."\n".
1.120     ng       1414: 			'<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.72      ng       1415: 			'<input type="hidden" name="probTitle"  value="'.$ENV{'form.probTitle'}.'" />'."\n".
1.41      ng       1416: 			'<input type="hidden" name="refresh"    value="off" />'."\n".
1.120     ng       1417: 			'<input type="hidden" name="studentNo"  value="" />'."\n".
                   1418: 			'<input type="hidden" name="gradeOpt"   value="" />'."\n".
1.41      ng       1419: 			'<input type="hidden" name="symb"       value="'.$symb.'" />'."\n".
                   1420: 			'<input type="hidden" name="url"        value="'.$url.'" />'."\n".
                   1421: 			'<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" />'."\n".
                   1422: 			'<input type="hidden" name="vProb"      value="'.$ENV{'form.vProb'}.'" />'."\n".
1.144     albertel 1423: 			'<input type="hidden" name="vAns"       value="'.$ENV{'form.vAns'}.'" />'."\n".
1.41      ng       1424: 			'<input type="hidden" name="lastSub"    value="'.$ENV{'form.lastSub'}.'" />'."\n".
                   1425: 			'<input type="hidden" name="section"    value="'.$ENV{'form.section'}.'">'."\n".
                   1426: 			'<input type="hidden" name="submitonly" value="'.$ENV{'form.submitonly'}.'">'."\n".
                   1427: 			'<input type="hidden" name="handgrade"  value="'.$ENV{'form.handgrade'}.'">'."\n".
                   1428: 			'<input type="hidden" name="NCT"'.
                   1429: 			' value="'.($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : $total+1).'" />'."\n");
1.123     ng       1430: 	if ($ENV{'form.handgrade'} eq 'yes') {
                   1431: 	    $request->print('<input type="hidden" name="keywords" value="'.$ENV{'form.keywords'}.'" />'."\n".
                   1432: 			    '<input type="hidden" name="kwclr"    value="'.$ENV{'form.kwclr'}.'" />'."\n".
                   1433: 			    '<input type="hidden" name="kwsize"   value="'.$ENV{'form.kwsize'}.'" />'."\n".
                   1434: 			    '<input type="hidden" name="kwstyle"  value="'.$ENV{'form.kwstyle'}.'" />'."\n".
                   1435: 			    '<input type="hidden" name="msgsub"   value="'.$ENV{'form.msgsub'}.'" />'."\n".
                   1436: 			    '<input type="hidden" name="shownSub" value="0" />'."\n".
                   1437: 			    '<input type="hidden" name="savemsgN" value="'.$ENV{'form.savemsgN'}.'" />'."\n");
                   1438: 	}
1.41      ng       1439: 	
                   1440: 	my ($cts,$prnmsg) = (1,'');
                   1441: 	while ($cts <= $ENV{'form.savemsgN'}) {
                   1442: 	    $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123     ng       1443: 		(!exists($keyhash{$symb.'_savemsg'.$cts}) ? 
1.80      ng       1444: 		 &Apache::lonfeedback::clear_out_html($ENV{'form.savemsg'.$cts}) :
                   1445: 		 &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123     ng       1446: 		'" />'."\n".
                   1447: 		'<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41      ng       1448: 	    $cts++;
                   1449: 	}
                   1450: 	$request->print($prnmsg);
1.32      ng       1451: 
1.41      ng       1452: 	if ($ENV{'form.handgrade'} eq 'yes' && $ENV{'form.showgrading'} eq 'yes') {
1.88      www      1453: #
                   1454: # Print out the keyword options line
                   1455: #
1.41      ng       1456: 	    $request->print(<<KEYWORDS);
1.38      ng       1457: &nbsp;<b>Keyword Options:</b>&nbsp;
1.122     ng       1458: <a href="javascript:keywords(document.SCORE)"; TARGET=_self>List</a>&nbsp; &nbsp;
1.38      ng       1459: <a href="#" onMouseDown="javascript:getSel(); return false"
                   1460:  CLASS="page">Paste Selection to List</a>&nbsp; &nbsp;
                   1461: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
                   1462: KEYWORDS
1.88      www      1463: #
                   1464: # Load the other essays for similarity check
                   1465: #
                   1466:             my $essayurl=&Apache::lonnet::declutter($url);
                   1467: 	    my ($adom,$aname,$apath)=($essayurl=~/^(\w+)\/(\w+)\/(.*)$/);
                   1468: 	    $apath=&Apache::lonnet::escape($apath);
                   1469: 	    $apath=~s/\W/\_/gs;
                   1470: 	    %oldessays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41      ng       1471:         }
                   1472:     }
1.44      ng       1473: 
1.144     albertel 1474:     if ($ENV{'form.vProb'} eq 'all' or $ENV{'form.vAns'} eq 'all') {
1.71      ng       1475: 	$request->print('<br /><br /><br />') if ($counter > 0);
1.144     albertel 1476: 	my $mode;
                   1477: 	if ($ENV{'form.vProb'} eq 'all' && $ENV{'form.vAns'} eq 'all') {
                   1478: 	    $mode='both';
                   1479: 	} elsif ($ENV{'form.vProb'} eq 'all' ) {
                   1480: 	    $mode='text';
                   1481: 	} elsif ($ENV{'form.vAns'} eq 'all') {
                   1482: 	    $mode='answer';
                   1483: 	}
                   1484: 	$request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode));
1.58      albertel 1485:     }
1.144     albertel 1486: 
1.41      ng       1487:     my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
1.125     ng       1488: 
1.147     albertel 1489:     my ($partlist,$handgrade,$responseType) = &response_type($url,$symb);
1.41      ng       1490: 
1.44      ng       1491:     # Display student info
1.41      ng       1492:     $request->print(($counter == 0 ? '' : '<br />'));
1.45      ng       1493:     my $result='<table border="0" width=100%><tr><td bgcolor="#777777">'."\n".
                   1494: 	'<table border="0" width=100%><tr bgcolor="#edffff"><td>'."\n";
1.44      ng       1495: 
1.129     ng       1496:     $result.='<b>Fullname: </b>'.&nameUserString(undef,$ENV{'form.fullname'},$uname,$udom).'<br />'."\n";
1.45      ng       1497:     $result.='<input type="hidden" name="name'.$counter.
                   1498: 	'" value="'.$ENV{'form.fullname'}.'" />'."\n";
1.41      ng       1499: 
1.118     ng       1500:     # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.45      ng       1501:     my @col_fullnames;
1.56      matthew  1502:     my ($classlist,$fullname);
1.41      ng       1503:     if ($ENV{'form.handgrade'} eq 'yes') {
1.80      ng       1504: 	($classlist,undef,$fullname) = &getclasslist('all','0');
1.41      ng       1505: 	for (keys (%$handgrade)) {
1.44      ng       1506: 	    my $ncol = &Apache::lonnet::EXT('resource.'.$_.
1.57      matthew  1507: 					    '.maxcollaborators',
                   1508:                                             $symb,$udom,$uname);
                   1509: 	    next if ($ncol <= 0);
                   1510:             s/\_/\./g;
                   1511:             next if ($record{'resource.'.$_.'.collaborators'} eq '');
1.86      ng       1512:             my @goodcollaborators = ();
                   1513:             my @badcollaborators  = ();
                   1514: 	    foreach (split(/,?\s+/,$record{'resource.'.$_.'.collaborators'})) { 
                   1515: 		$_ =~ s/[\$\^\(\)]//g;
                   1516: 		next if ($_ eq '');
1.80      ng       1517: 		my ($co_name,$co_dom) = split /\@|:/,$_;
1.86      ng       1518: 		$co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
1.80      ng       1519: 		next if ($co_name eq $uname && $co_dom eq $udom);
1.86      ng       1520: 		# Doing this grep allows 'fuzzy' specification
                   1521: 		my @Matches = grep /^$co_name:$co_dom$/i,keys %$classlist;
                   1522: 		if (! scalar(@Matches)) {
                   1523: 		    push @badcollaborators,$_;
                   1524: 		} else {
                   1525: 		    push @goodcollaborators, @Matches;
                   1526: 		}
1.80      ng       1527: 	    }
1.86      ng       1528:             if (scalar(@goodcollaborators) != 0) {
1.57      matthew  1529:                 $result.='<b>Collaborators: </b>';
1.86      ng       1530:                 foreach (@goodcollaborators) {
                   1531: 		    my ($lastname,$givenn) = split(/,/,$$fullname{$_});
                   1532: 		    push @col_fullnames, $givenn.' '.$lastname;
                   1533: 		    $result.=$$fullname{$_}.'&nbsp; &nbsp; &nbsp;';
                   1534: 		}
1.57      matthew  1535:                 $result.='<br />'."\n";
1.150     albertel 1536: 		my ($part)=split(/\./,$_);
1.86      ng       1537: 		$result.='<input type="hidden" name="collaborator'.$counter.
1.150     albertel 1538: 		    '" value="'.$part.':'.(join ':',@goodcollaborators).'" />'.
                   1539: 		    "\n";
1.86      ng       1540: 	    }
                   1541: 	    if (scalar(@badcollaborators) > 0) {
                   1542: 		$result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
                   1543: 		$result.='This student has submitted ';
                   1544: 		$result.=(scalar(@badcollaborators) == 1) ? 'an invalid collaborator' : 'invalid collaborators';
                   1545: 		$result .= ': '.join(', ',@badcollaborators);
                   1546: 		$result .= '</td></tr></table>';
                   1547: 	    }         
                   1548: 	    if (scalar(@badcollaborators > $ncol)) {
                   1549: 		$result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
                   1550: 		$result .= 'This student has submitted too many '.
                   1551: 		    'collaborators.  Maximum is '.$ncol.'.';
                   1552: 		$result .= '</td></tr></table>';
                   1553: 	    }
1.41      ng       1554: 	}
                   1555:     }
1.44      ng       1556:     $request->print($result."\n");
1.33      ng       1557: 
1.44      ng       1558:     # print student answer/submission
                   1559:     # Options are (1) Handgaded submission only
                   1560:     #             (2) Last submission, includes submission that is not handgraded 
                   1561:     #                  (for multi-response type part)
                   1562:     #             (3) Last submission plus the parts info
                   1563:     #             (4) The whole record for this student
1.41      ng       1564:     if ($ENV{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151   ! albertel 1565: 	my ($string,$timestamp)= &get_last_submission(\%record);
        !          1566: 	my $lastsubonly=''.
        !          1567: 	    ($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
        !          1568: 	     $$timestamp)."</td></tr>\n";
        !          1569: 	if ($$timestamp eq '') {
        !          1570: 	    $lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0]; 
        !          1571: 	} else {
        !          1572: 	    my %seenparts;
        !          1573: 	    for my $part (sort keys(%$handgrade)) {
        !          1574: 		my ($partid,$respid) = split(/_/,$part);
        !          1575: 		if ($ENV{"form.$uname:$udom:$partid:submitted_by"}) {
        !          1576: 		    if (exists($seenparts{$partid})) { next; }
        !          1577: 		    $seenparts{$partid}=1;
        !          1578: 		    my $submitby='<b>Part '.$partid.
        !          1579: 			' Collaborative submission by: </b>'.
        !          1580: 			'<a href="javascript:viewSubmitter(\''.
        !          1581: 			$ENV{"form.$uname:$udom:$partid:submitted_by"}.
        !          1582: 			'\')"; TARGET=_self>'.
        !          1583: 			$$fullname{$ENV{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
        !          1584: 		    $request->print($submitby);
        !          1585: 		    next;
        !          1586: 		}
        !          1587: 		my $responsetype = $responseType->{$partid}->{$respid};
        !          1588: 		if (!exists($record{"resource.$partid.$respid.submission"})) {
        !          1589: 		    $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
        !          1590: 			$partid.'</b> <font color="#999999">( ID '.$respid.
        !          1591: 			' )</font>&nbsp; &nbsp;'.
        !          1592: 			'<font color="red">Nothing submitted - no attempts</font><br /><br />';
        !          1593: 		    next;
        !          1594: 		}
        !          1595: 		foreach (@$string) {
        !          1596: 		    my ($partid,$respid) = /^resource\.([^\.]*)\.([^\.]*)\.submission/;
        !          1597: 		    if ($part ne ($partid.'_'.$respid)) { next; }
        !          1598: 		    my ($ressub,$subval) = split(/:/,$_,2);
        !          1599: 		    # Similarity check
        !          1600: 		    my $similar='';
        !          1601: 		    if($ENV{'form.checkPlag'}){
        !          1602: 			my ($oname,$odom,$ocrsid,$oessay,$osim)=
        !          1603: 			    &most_similar($uname,$udom,$subval);
        !          1604: 			if ($osim) {
        !          1605: 			    $osim=int($osim*100.0);
        !          1606: 			    $similar="<hr /><h3><font color=\"#FF0000\">Essay".
        !          1607: 				" is $osim% similar to an essay by ".
        !          1608: 				&Apache::loncommon::plainname($oname,$odom).
        !          1609: 				'</font></h3><blockquote><i>'.
        !          1610: 				&keywords_highlight($oessay).
        !          1611: 				'</i></blockquote><hr />';
        !          1612: 			}
1.150     albertel 1613: 		    }
1.151   ! albertel 1614: 		    my $order=&get_order($partid,$respid,$symb,$uname,$udom);
        !          1615: 		    if ($ENV{'form.lastSub'} eq 'lastonly' || 
        !          1616: 			($ENV{'form.lastSub'} eq 'hdgrade' && 
        !          1617: 			 $$handgrade{$part} eq 'yes')) {
1.118     ng       1618: 			$lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
                   1619: 			    $partid.'</b> <font color="#999999">( ID '.$respid.
1.151   ! albertel 1620: 			    ' )</font>&nbsp; &nbsp;';
        !          1621: 			if ($record{"resource.$partid.$respid.uploadedurl"}) {
        !          1622: 			    $lastsubonly.='<a href="'.&Apache::lonnet::tokenwrapper($record{"resource.$partid.$respid.uploadedurl"}).'"><img src="/adm/lonIcons/unknown.gif" border=0"> File uploaded by student</a> <font color="red" size="1">Like all files provided by users, this file may contain virusses</font><br />';
1.41      ng       1623: 			}
1.151   ! albertel 1624: 			$lastsubonly.='<b>Submitted Answer: </b>'.
        !          1625: 			    &cleanRecord($subval,$responsetype,$symb,$partid,
        !          1626: 					 $respid,\%record,$order);
        !          1627: 			if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.41      ng       1628: 		    }
                   1629: 		}
                   1630: 	    }
1.151   ! albertel 1631: 	}
        !          1632: 	$lastsubonly.='</td></tr><tr bgcolor="#ffffff"><td>'."\n";
        !          1633: 	$request->print($lastsubonly);
1.122     ng       1634:     } elsif ($ENV{'form.lastSub'} eq 'datesub') {
                   1635: 	my (undef,$responseType,undef,$parts) = &showResourceInfo($url);
1.148     albertel 1636: 	$request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.122     ng       1637:     } elsif ($ENV{'form.lastSub'} =~ /^(last|all)$/) {
1.41      ng       1638: 	$request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.44      ng       1639: 								 $ENV{'request.course.id'},
                   1640: 								 $last,'.submission',
                   1641: 								 'Apache::grades::keywords_highlight'));
1.41      ng       1642:     }
1.120     ng       1643: 
1.121     ng       1644:     $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
                   1645: 	.$udom.'" />'."\n");
1.41      ng       1646:     
1.44      ng       1647:     # return if view submission with no grading option
1.118     ng       1648:     if ($ENV{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120     ng       1649: 	my $toGrade.='<input type="button" value="Grade Student" '.
1.121     ng       1650: 	    'onClick="javascript:checksubmit(this.form,\'Grade Student\',\''
                   1651: 	    .$counter.'\');" TARGET=_self> &nbsp;'."\n" if (&canmodify($usec));
1.120     ng       1652: 	$toGrade.='</td></tr></table></td></tr></table></form>'."\n";
                   1653: 	$toGrade.=&show_grading_menu_form($symb,$url) 
1.72      ng       1654: 	    if (($ENV{'form.command'} eq 'submission') || 
                   1655: 		($ENV{'form.command'} eq 'processGroup' && $counter == $total));
1.120     ng       1656: 	$request = print($toGrade);
1.41      ng       1657: 	return;
                   1658:     }
1.33      ng       1659: 
1.121     ng       1660:     # essay grading message center
1.118     ng       1661:     if ($ENV{'form.handgrade'} eq 'yes') {
                   1662: 	my ($lastname,$givenn) = split(/,/,$ENV{'form.fullname'});
                   1663: 	my $msgfor = $givenn.' '.$lastname;
                   1664: 	if (scalar(@col_fullnames) > 0) {
                   1665: 	    my $lastone = pop @col_fullnames;
                   1666: 	    $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
                   1667: 	}
                   1668: 	$msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.121     ng       1669: 	$result='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
                   1670: 	    '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
                   1671: 	$result.='&nbsp;<a href="javascript:msgCenter(document.SCORE,'.$counter.
1.118     ng       1672: 	    ',\''.$msgfor.'\')"; TARGET=_self>'.
                   1673: 	    'Compose Message to student'.(scalar(@col_fullnames) >= 1 ? 's' : '').'</a> &nbsp;'.
                   1674: 	    '<img src="'.$request->dir_config('lonIconsURL').
                   1675: 	    '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
                   1676: 	    '<br />&nbsp;(Message will be sent when you click on Save & Next below.)'."\n" 
                   1677: 	    if ($ENV{'form.handgrade'} eq 'yes');
1.121     ng       1678: 	$request->print($result);
1.118     ng       1679:     }
1.41      ng       1680: 
                   1681:     my %seen = ();
                   1682:     my @partlist;
1.129     ng       1683:     my @gradePartRespid;
1.41      ng       1684:     for (sort keys(%$handgrade)) {
                   1685: 	my ($partid,$respid) = split(/_/);
                   1686: 	next if ($seen{$partid} > 0);
                   1687: 	$seen{$partid}++;
1.118     ng       1688: 	next if ($$handgrade{$_} =~ /:no$/ && $ENV{'form.lastSub'} =~ /^(hdgrade)$/);
1.41      ng       1689: 	push @partlist,$partid;
1.129     ng       1690: 	push @gradePartRespid,$partid.'.'.$respid;
1.41      ng       1691: 
1.71      ng       1692: 	$request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41      ng       1693:     }
1.45      ng       1694:     $result='<input type="hidden" name="partlist'.$counter.
                   1695: 	'" value="'.(join ":",@partlist).'" />'."\n";
1.129     ng       1696:     $result.='<input type="hidden" name="gradePartRespid'.
                   1697: 	'" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45      ng       1698:     my $ctr = 0;
                   1699:     while ($ctr < scalar(@partlist)) {
                   1700: 	$result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
                   1701: 	    $partlist[$ctr].'" />'."\n";
                   1702: 	$ctr++;
                   1703:     }
                   1704:     $request->print($result.'</td></tr></table></td></tr></table>'."\n");
1.41      ng       1705: 
                   1706:     # print end of form
                   1707:     if ($counter == $total) {
1.120     ng       1708: 	my $endform='<table border="0"><tr><td>'."\n";
1.119     ng       1709: 	$endform.='<input type="button" value="Save & Next" '.
                   1710: 	    'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
                   1711: 	    $total.','.scalar(@partlist).');" TARGET=_self> &nbsp;'."\n";
                   1712: 	my $ntstu ='<select name="NTSTU">'.
                   1713: 	    '<option>1</option><option>2</option>'.
                   1714: 	    '<option>3</option><option>5</option>'.
                   1715: 	    '<option>7</option><option>10</option></select>'."\n";
                   1716: 	my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
                   1717: 	$ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
                   1718: 	$endform.=$ntstu.'student(s) &nbsp;&nbsp;';
1.126     ng       1719: 	$endform.='<input type="button" value="Previous" '.
                   1720: 	    'onClick="javascript:checksubmit(this.form,\'Previous\');" TARGET=_self> &nbsp;'."\n".
                   1721: 	    '<input type="button" value="Next" '.
                   1722: 	    'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self> &nbsp;';
                   1723: 	$endform.='(Next and Previous (student) do not save the scores.)'."\n" ;
1.45      ng       1724: 	$endform.='</td><tr></table></form>';
1.50      albertel 1725: 	$endform.=&show_grading_menu_form($symb,$url);
1.41      ng       1726: 	$request->print($endform);
                   1727:     }
                   1728:     return '';
1.38      ng       1729: }
                   1730: 
1.44      ng       1731: #--- Retrieve the last submission for all the parts
1.38      ng       1732: sub get_last_submission {
1.119     ng       1733:     my ($returnhash)=@_;
1.46      ng       1734:     my (@string,$timestamp);
1.119     ng       1735:     if ($$returnhash{'version'}) {
1.46      ng       1736: 	my %lasthash=();
                   1737: 	my ($version);
1.119     ng       1738: 	for ($version=1;$version<=$$returnhash{'version'};$version++) {
                   1739: 	    foreach (sort(split(/\:/,$$returnhash{$version.':keys'}))) {
                   1740: 		$lasthash{$_}=$$returnhash{$version.':'.$_};
                   1741: 		   $timestamp = scalar(localtime($$returnhash{$version.':timestamp'}));
1.46      ng       1742: 	    }
                   1743: 	}
                   1744: 	foreach ((keys %lasthash)) {
                   1745: 	    if ($_ =~ /\.submission$/) {
                   1746: 		my ($partid,$foo) = split(/submission$/,$_);
                   1747: 		my $draft  = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
                   1748: 		    '<font color="red">Draft Copy</font> ' : '';
                   1749: 		push @string, (join(':',$_,$draft.$lasthash{$_}));
1.41      ng       1750: 	    }
                   1751: 	}
                   1752:     }
1.125     ng       1753:     @string = $string[0] eq '' ? '<font color="red">Nothing submitted - no attempts.</font>' : @string;
1.46      ng       1754:     return \@string,\$timestamp;
1.38      ng       1755: }
1.35      ng       1756: 
1.44      ng       1757: #--- High light keywords, with style choosen by user.
1.38      ng       1758: sub keywords_highlight {
1.44      ng       1759:     my $string    = shift;
                   1760:     my $size      = $ENV{'form.kwsize'} eq '0' ? '' : 'size='.$ENV{'form.kwsize'};
                   1761:     my $styleon   = $ENV{'form.kwstyle'} eq ''  ? '' : $ENV{'form.kwstyle'};
1.41      ng       1762:     (my $styleoff = $styleon) =~ s/\</\<\//;
1.44      ng       1763:     my @keylist   = split(/[,\s+]/,$ENV{'form.keywords'});
1.41      ng       1764:     foreach (@keylist) {
1.119     ng       1765: 	$string =~ s/\b\Q$_\E(\b|\.)/<font color\=$ENV{'form.kwclr'} $size\>$styleon$_$styleoff<\/font>/gi;
1.41      ng       1766:     }
                   1767:     return $string;
1.38      ng       1768: }
1.36      ng       1769: 
1.44      ng       1770: #--- Called from submission routine
1.38      ng       1771: sub processHandGrade {
1.41      ng       1772:     my ($request) = shift;
                   1773:     my $url    = $ENV{'form.url'};
                   1774:     my $symb   = $ENV{'form.symb'};
                   1775:     my $button = $ENV{'form.gradeOpt'};
                   1776:     my $ngrade = $ENV{'form.NCT'};
                   1777:     my $ntstu  = $ENV{'form.NTSTU'};
1.44      ng       1778:     if ($button eq 'Save & Next') {
                   1779: 	my $ctr = 0;
                   1780: 	while ($ctr < $ngrade) {
                   1781: 	    my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
1.77      ng       1782: 	    my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
1.71      ng       1783: 	    if ($errorflag eq 'no_score') {
                   1784: 		$ctr++;
                   1785: 		next;
                   1786: 	    }
1.104     albertel 1787: 	    if ($errorflag eq 'not_allowed') {
                   1788: 		$request->print("<font color=\"red\">Not allowed to modify grades for $uname:$udom</font>");
                   1789: 		$ctr++;
                   1790: 		next;
                   1791: 	    }
1.44      ng       1792: 	    my $includemsg = $ENV{'form.includemsg'.$ctr};
                   1793: 	    my ($subject,$message,$msgstatus) = ('','','');
1.62      albertel 1794: 	    if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.44      ng       1795: 		$subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/);
                   1796: 		my (@msgnum) = split(/,/,$includemsg);
                   1797: 		foreach (@msgnum) {
                   1798: 		    $message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
                   1799: 		}
1.80      ng       1800: 		$message =&Apache::lonfeedback::clear_out_html($message);
1.77      ng       1801: 		$message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.80      ng       1802: 		$message.=" for <a href=\"".
                   1803: 		    &Apache::lonnet::clutter($url).
                   1804: 		    "?symb=$symb\">$ENV{'form.probTitle'}</a>";
1.44      ng       1805: 		$msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
                   1806: 							       $ENV{'form.msgsub'},$message);
                   1807: 	    }
                   1808: 	    if ($ENV{'form.collaborator'.$ctr}) {
1.150     albertel 1809: 		&Apache::lonnet::logthis('collab '.(join(':',@{ $ENV{'form.collaborator'.$ctr} })));
                   1810: 		my @collabstrs;
                   1811: 		if (ref($ENV{'form.collaborator'.$ctr}) eq 'ARRAY') {
                   1812: 		    @collabstrs=@{$ENV{'form.collaborator'.$ctr}};
                   1813: 		} else {
                   1814: 		    @collabstrs=$ENV{'form.collaborator'.$ctr};
                   1815: 		}
                   1816: 		foreach my $collabstr (@collabstrs) {
                   1817: 		    my ($part,@collaborators) = split(/:/,$collabstr);
                   1818: 		    foreach (@collaborators) {
                   1819: 			my ($errorflag,$pts,$wgt) = 
                   1820: 			    &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,
                   1821: 					   $ENV{'form.unamedom'.$ctr},$part);
                   1822: 			if ($errorflag eq 'not_allowed') {
                   1823: 			    $request->print("<font color=\"red\">Not allowed to modify grades for $_:$udom</font>");
                   1824: 			    next;
                   1825: 			} else {
                   1826: 			    if ($message ne '') {
                   1827: 				$msgstatus = &Apache::lonmsg::user_normal_msg($_,$udom,$ENV{'form.msgsub'},$message);
                   1828: 			    }
                   1829: 			    
1.104     albertel 1830: 			}
1.44      ng       1831: 		    }
                   1832: 		}
                   1833: 	    }
                   1834: 	    $ctr++;
                   1835: 	}
                   1836:     }
                   1837: 
1.119     ng       1838:     if ($ENV{'form.handgrade'} eq 'yes') {
                   1839: 	# Keywords sorted in alphabatical order
                   1840: 	my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
                   1841: 	my %keyhash = ();
                   1842: 	$ENV{'form.keywords'}           =~ s/,\s{0,}|\s+/ /g;
                   1843: 	$ENV{'form.keywords'}           =~ s/^\s+|\s+$//;
                   1844: 	my (@keywords) = sort(split(/\s+/,$ENV{'form.keywords'}));
                   1845: 	$ENV{'form.keywords'} = join(' ',@keywords);
                   1846: 	$keyhash{$symb.'_keywords'}     = $ENV{'form.keywords'};
                   1847: 	$keyhash{$symb.'_subject'}      = $ENV{'form.msgsub'};
                   1848: 	$keyhash{$loginuser.'_kwclr'}   = $ENV{'form.kwclr'};
                   1849: 	$keyhash{$loginuser.'_kwsize'}  = $ENV{'form.kwsize'};
                   1850: 	$keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
                   1851: 
                   1852: 	# message center - Order of message gets changed. Blank line is eliminated.
                   1853: 	# New messages are saved in ENV for the next student.
                   1854: 	# All messages are saved in nohist_handgrade.db
                   1855: 	my ($ctr,$idx) = (1,1);
                   1856: 	while ($ctr <= $ENV{'form.savemsgN'}) {
                   1857: 	    if ($ENV{'form.savemsg'.$ctr} ne '') {
                   1858: 		$keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
                   1859: 		$idx++;
                   1860: 	    }
                   1861: 	    $ctr++;
1.41      ng       1862: 	}
1.119     ng       1863: 	$ctr = 0;
                   1864: 	while ($ctr < $ngrade) {
                   1865: 	    if ($ENV{'form.newmsg'.$ctr} ne '') {
                   1866: 		$keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
                   1867: 		$ENV{'form.savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
                   1868: 		$idx++;
                   1869: 	    }
                   1870: 	    $ctr++;
1.41      ng       1871: 	}
1.119     ng       1872: 	$ENV{'form.savemsgN'} = --$idx;
                   1873: 	$keyhash{$symb.'_savemsgN'} = $ENV{'form.savemsgN'};
                   1874: 	my $putresult = &Apache::lonnet::put
                   1875: 	    ('nohist_handgrade',\%keyhash,
                   1876: 	     $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1877: 	     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.41      ng       1878:     }
1.44      ng       1879:     # Called by Save & Refresh from Highlight Attribute Window
1.119     ng       1880:     my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'1');
1.41      ng       1881:     if ($ENV{'form.refresh'} eq 'on') {
1.86      ng       1882: 	my ($ctr,$total) = (0,0);
                   1883: 	while ($ctr < $ngrade) {
                   1884: 	    $total++ if  $ENV{'form.unamedom'.$ctr} ne '';
                   1885: 	    $ctr++;
                   1886: 	}
1.41      ng       1887: 	$ENV{'form.NTSTU'}=$ngrade;
1.86      ng       1888: 	$ctr = 0;
                   1889: 	while ($ctr < $total) {
                   1890: 	    my $processUser = $ENV{'form.unamedom'.$ctr};
                   1891: 	    ($ENV{'form.student'},$ENV{'form.userdom'}) = split(/:/,$processUser);
                   1892: 	    $ENV{'form.fullname'} = $$fullname{$processUser};
                   1893: 	    &submission($request,$ctr,$total-1);
1.41      ng       1894: 	    $ctr++;
                   1895: 	}
                   1896: 	return '';
                   1897:     }
1.36      ng       1898: 
1.121     ng       1899: # Go directly to grade student - from submission or link from chart page
1.120     ng       1900:     if ($button eq 'Grade Student') {
1.121     ng       1901: 	(undef,undef,$ENV{'form.handgrade'},undef,undef) = &showResourceInfo($url);
1.120     ng       1902: 	my $processUser = $ENV{'form.unamedom'.$ENV{'form.studentNo'}};
                   1903: 	($ENV{'form.student'},$ENV{'form.userdom'}) = split(/:/,$processUser);
                   1904: 	$ENV{'form.fullname'} = $$fullname{$processUser};
                   1905: 	&submission($request,0,0);
                   1906: 	return '';
                   1907:     }
                   1908: 
1.44      ng       1909:     # Get the next/previous one or group of students
1.41      ng       1910:     my $firststu = $ENV{'form.unamedom0'};
                   1911:     my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
1.119     ng       1912:     my $ctr = 2;
1.41      ng       1913:     while ($laststu eq '') {
                   1914: 	$laststu  = $ENV{'form.unamedom'.($ngrade-$ctr)};
                   1915: 	$ctr++;
                   1916: 	$laststu = $firststu if ($ctr > $ngrade);
                   1917:     }
1.44      ng       1918: 
1.41      ng       1919:     my (@parsedlist,@nextlist);
                   1920:     my ($nextflg) = 0;
1.53      albertel 1921:     foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.41      ng       1922: 	if ($nextflg == 1 && $button =~ /Next$/) {
                   1923: 	    push @parsedlist,$_;
                   1924: 	}
                   1925: 	$nextflg = 1 if ($_ eq $laststu);
                   1926: 	if ($button eq 'Previous') {
                   1927: 	    last if ($_ eq $firststu);
                   1928: 	    push @parsedlist,$_;
                   1929: 	}
                   1930:     }
                   1931:     $ctr = 0;
                   1932:     @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.145     albertel 1933:     my ($partlist) = &response_type($url);
1.41      ng       1934:     foreach my $student (@parsedlist) {
1.145     albertel 1935: 	my $submitonly=$ENV{'form.submitonly'};
1.41      ng       1936: 	my ($uname,$udom) = split(/:/,$student);
1.145     albertel 1937: 	if ($submitonly =~ /^(yes|graded)$/) {
                   1938: #	    my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
                   1939: 	    my %status=&student_gradeStatus($url,$symb,$udom,$uname,$partlist);
                   1940: 	    my $submitted = 0;
                   1941: 	    my $graded = 1;
                   1942: 	    foreach (keys(%status)) {
                   1943: 		$submitted = 1 if ($status{$_} ne 'nothing');
                   1944: 		$graded = 0 if ($status{$_} =~ /^correct/);
                   1945: 		my ($foo,$partid,$foo1) = split(/\./,$_);
                   1946: 		if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
                   1947: 		    $submitted = 0;
                   1948: 		}
1.41      ng       1949: 	    }
1.145     albertel 1950: 	    next if (!$submitted && ($submitonly eq 'yes' || $submitonly eq 'graded'));
                   1951: 	    next if (!$graded && $submitonly eq 'graded');
1.41      ng       1952: 	}
                   1953: 	push @nextlist,$student if ($ctr < $ntstu);
1.129     ng       1954: 	last if ($ctr == $ntstu);
1.41      ng       1955: 	$ctr++;
                   1956:     }
1.36      ng       1957: 
1.41      ng       1958:     $ctr = 0;
                   1959:     my $total = scalar(@nextlist)-1;
1.39      ng       1960: 
1.41      ng       1961:     foreach (sort @nextlist) {
                   1962: 	my ($uname,$udom,$submitter) = split(/:/);
1.44      ng       1963: 	$ENV{'form.student'}  = $uname;
                   1964: 	$ENV{'form.userdom'}  = $udom;
1.41      ng       1965: 	$ENV{'form.fullname'} = $$fullname{$_};
                   1966: 	&submission($request,$ctr,$total);
                   1967: 	$ctr++;
                   1968:     }
                   1969:     if ($total < 0) {
                   1970: 	my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
                   1971: 	$the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
                   1972: 	$the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
                   1973: 	$the_end.=&show_grading_menu_form ($symb,$url);
                   1974: 	$request->print($the_end);
                   1975:     }
                   1976:     return '';
1.38      ng       1977: }
1.36      ng       1978: 
1.44      ng       1979: #---- Save the score and award for each student, if changed
1.38      ng       1980: sub saveHandGrade {
1.150     albertel 1981:     my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.104     albertel 1982:     my $usec = &Apache::lonnet::getsection($domain,$stuname,
                   1983: 					   $ENV{'request.course.id'});
                   1984:     if (!&canmodify($usec)) { return('not_allowed'); }
1.77      ng       1985:     my %record     = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
                   1986:     my %newrecord  = ();
                   1987:     my ($pts,$wgt) = ('','');
1.41      ng       1988:     foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
1.150     albertel 1989: 	&Apache::lonnet::logthis("-$submitter-$stuname-$part-$_");
                   1990: 	#collaborator may vary for different parts
                   1991: 	if ($submitter && $_ ne $part) { next; }
1.125     ng       1992: 	my $dropMenu = $ENV{'form.GD_SEL'.$newflg.'_'.$_};
                   1993: 	if ($dropMenu eq 'excused') {
1.58      albertel 1994: 	    if ($record{'resource.'.$_.'.solved'} ne 'excused') {
                   1995: 		$newrecord{'resource.'.$_.'.solved'} = 'excused';
                   1996: 		if (exists($record{'resource.'.$_.'.awarded'})) {
                   1997: 		    $newrecord{'resource.'.$_.'.awarded'} = '';
                   1998: 		}
1.125     ng       1999: 	    $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.58      albertel 2000: 	    }
1.125     ng       2001: 	} elsif ($dropMenu eq 'reset status'
                   2002: 		 && exists($record{'resource.'.$_.'.solved'})) { #don't bother if no old records -> no attempts
                   2003: 	    $newrecord{'resource.'.$_.'.tries'} = 0;
                   2004: 	    $newrecord{'resource.'.$_.'.solved'} = '';
                   2005: 	    $newrecord{'resource.'.$_.'.award'} = '';
                   2006: 	    $newrecord{'resource.'.$_.'.awarded'} = 0;
                   2007: 	    $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
                   2008: 	} elsif ($dropMenu eq '') {
1.77      ng       2009: 	    $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ? 
                   2010: 		    $ENV{'form.GD_BOX'.$newflg.'_'.$_} : 
                   2011: 		    $ENV{'form.RADVAL'.$newflg.'_'.$_});
1.71      ng       2012: 	    return 'no_score' if ($pts eq '' && $ENV{'form.GD_SEL'.$newflg.'_'.$_} eq '');
1.77      ng       2013: 	    $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 : 
1.44      ng       2014: 		$ENV{'form.WGT'.$newflg.'_'.$_};
1.41      ng       2015: 	    my $partial= $pts/$wgt;
1.119     ng       2016: 	    next if ($partial eq $record{'resource.'.$_.'.awarded'}); #do not update score for part if not changed.
1.44      ng       2017: 	    $newrecord{'resource.'.$_.'.awarded'}  = $partial 
                   2018: 		if ($record{'resource.'.$_.'.awarded'} ne $partial);
                   2019: 	    my $reckey = 'resource.'.$_.'.solved';
1.41      ng       2020: 	    if ($partial == 0) {
1.44      ng       2021: 		$newrecord{$reckey} = 'incorrect_by_override' 
                   2022: 		    if ($record{$reckey} ne 'incorrect_by_override');
1.41      ng       2023: 	    } else {
1.44      ng       2024: 		$newrecord{$reckey} = 'correct_by_override' 
                   2025: 		    if ($record{$reckey} ne 'correct_by_override');
1.41      ng       2026: 	    }
1.150     albertel 2027: 	    
1.44      ng       2028: 	    $newrecord{'resource.'.$_.'.submitted_by'} = $submitter 
                   2029: 		if ($submitter && ($record{'resource.'.$_.'.submitted_by'} ne $submitter));
1.122     ng       2030: 	    $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.41      ng       2031: 	}
                   2032:     }
1.44      ng       2033: 
                   2034:     if (scalar(keys(%newrecord)) > 0) {
                   2035: 	&Apache::lonnet::cstore(\%newrecord,$symb,
                   2036: 				$ENV{'request.course.id'},$domain,$stuname);
1.41      ng       2037:     }
1.77      ng       2038:     return '',$pts,$wgt;
1.36      ng       2039: }
1.38      ng       2040: 
1.44      ng       2041: #--------------------------------------------------------------------------------------
                   2042: #
                   2043: #-------------------------- Next few routines handles grading by section or whole class
                   2044: #
                   2045: #--- Javascript to handle grading by section or whole class
1.42      ng       2046: sub viewgrades_js {
                   2047:     my ($request) = shift;
                   2048: 
1.41      ng       2049:     $request->print(<<VIEWJAVASCRIPT);
                   2050: <script type="text/javascript" language="javascript">
1.45      ng       2051:    function writePoint(partid,weight,point) {
1.125     ng       2052: 	var radioButton = document.classgrade["RADVAL_"+partid];
                   2053: 	var textbox = document.classgrade["TEXTVAL_"+partid];
1.42      ng       2054: 	if (point == "textval") {
1.125     ng       2055: 	    point = document.classgrade["TEXTVAL_"+partid].value;
1.109     matthew  2056: 	    if (isNaN(point) || parseFloat(point) < 0) {
                   2057: 		alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.42      ng       2058: 		var resetbox = false;
                   2059: 		for (var i=0; i<radioButton.length; i++) {
                   2060: 		    if (radioButton[i].checked) {
                   2061: 			textbox.value = i;
                   2062: 			resetbox = true;
                   2063: 		    }
                   2064: 		}
                   2065: 		if (!resetbox) {
                   2066: 		    textbox.value = "";
                   2067: 		}
                   2068: 		return;
                   2069: 	    }
1.109     matthew  2070: 	    if (parseFloat(point) > parseFloat(weight)) {
                   2071: 		var resp = confirm("You entered a value ("+parseFloat(point)+
1.44      ng       2072: 				   ") greater than the weight for the part. Accept?");
                   2073: 		if (resp == false) {
                   2074: 		    textbox.value = "";
                   2075: 		    return;
                   2076: 		}
                   2077: 	    }
1.42      ng       2078: 	    for (var i=0; i<radioButton.length; i++) {
                   2079: 		radioButton[i].checked=false;
1.109     matthew  2080: 		if (parseFloat(point) == i) {
1.42      ng       2081: 		    radioButton[i].checked=true;
                   2082: 		}
                   2083: 	    }
1.41      ng       2084: 
1.42      ng       2085: 	} else {
1.125     ng       2086: 	    textbox.value = parseFloat(point);
1.42      ng       2087: 	}
1.41      ng       2088: 	for (i=0;i<document.classgrade.total.value;i++) {
1.125     ng       2089: 	    var user = document.classgrade["ctr"+i].value;
                   2090: 	    var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
                   2091: 	    var saveval   = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
                   2092: 	    var selname   = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42      ng       2093: 	    if (saveval != "correct") {
                   2094: 		scorename.value = point;
1.43      ng       2095: 		if (selname[0].selected != true) {
                   2096: 		    selname[0].selected = true;
                   2097: 		}
1.42      ng       2098: 	    }
                   2099: 	}
1.125     ng       2100: 	document.classgrade["SELVAL_"+partid][0].selected = true;
1.42      ng       2101:     }
                   2102: 
                   2103:     function writeRadText(partid,weight) {
1.125     ng       2104: 	var selval   = document.classgrade["SELVAL_"+partid];
                   2105: 	var radioButton = document.classgrade["RADVAL_"+partid];
                   2106: 	var textbox = document.classgrade["TEXTVAL_"+partid];
                   2107: 	if (selval[1].selected || selval[2].selected) {
1.42      ng       2108: 	    for (var i=0; i<radioButton.length; i++) {
                   2109: 		radioButton[i].checked=false;
                   2110: 
                   2111: 	    }
                   2112: 	    textbox.value = "";
                   2113: 
                   2114: 	    for (i=0;i<document.classgrade.total.value;i++) {
1.125     ng       2115: 		var user = document.classgrade["ctr"+i].value;
                   2116: 		var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
                   2117: 		var saveval   = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
                   2118: 		var selname   = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42      ng       2119: 		if (saveval != "correct") {
                   2120: 		    scorename.value = "";
1.125     ng       2121: 		    if (selval[1].selected) {
                   2122: 			selname[1].selected = true;
                   2123: 		    } else {
                   2124: 			selname[2].selected = true;
                   2125: 			if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value)) 
                   2126: 			{document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
                   2127: 		    }
1.42      ng       2128: 		}
                   2129: 	    }
1.43      ng       2130: 	} else {
                   2131: 	    for (i=0;i<document.classgrade.total.value;i++) {
1.125     ng       2132: 		var user = document.classgrade["ctr"+i].value;
                   2133: 		var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
                   2134: 		var saveval   = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
                   2135: 		var selname   = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.43      ng       2136: 		if (saveval != "correct") {
1.125     ng       2137: 		    scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43      ng       2138: 		    selname[0].selected = true;
                   2139: 		}
                   2140: 	    }
                   2141: 	}	    
1.42      ng       2142:     }
                   2143: 
                   2144:     function changeSelect(partid,user) {
1.125     ng       2145: 	var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
                   2146: 	var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44      ng       2147: 	var point  = textbox.value;
1.125     ng       2148: 	var weight = document.classgrade["weight_"+partid].value;
1.44      ng       2149: 
1.109     matthew  2150: 	if (isNaN(point) || parseFloat(point) < 0) {
                   2151: 	    alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.44      ng       2152: 	    textbox.value = "";
                   2153: 	    return;
                   2154: 	}
1.109     matthew  2155: 	if (parseFloat(point) > parseFloat(weight)) {
                   2156: 	    var resp = confirm("You entered a value ("+parseFloat(point)+
1.44      ng       2157: 			       ") greater than the weight of the part. Accept?");
                   2158: 	    if (resp == false) {
                   2159: 		textbox.value = "";
                   2160: 		return;
                   2161: 	    }
                   2162: 	}
1.42      ng       2163: 	selval[0].selected = true;
                   2164:     }
                   2165: 
                   2166:     function changeOneScore(partid,user) {
1.125     ng       2167: 	var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
                   2168: 	if (selval[1].selected || selval[2].selected) {
                   2169: 	    document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
                   2170: 	    if (selval[2].selected) {
                   2171: 		document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
                   2172: 	    }
1.42      ng       2173: 	}
                   2174:     }
                   2175: 
                   2176:     function resetEntry(numpart) {
                   2177: 	for (ctpart=0;ctpart<numpart;ctpart++) {
1.125     ng       2178: 	    var partid = document.classgrade["partid_"+ctpart].value;
                   2179: 	    var radioButton = document.classgrade["RADVAL_"+partid];
                   2180: 	    var textbox = document.classgrade["TEXTVAL_"+partid];
                   2181: 	    var selval  = document.classgrade["SELVAL_"+partid];
1.42      ng       2182: 	    for (var i=0; i<radioButton.length; i++) {
                   2183: 		radioButton[i].checked=false;
                   2184: 
                   2185: 	    }
                   2186: 	    textbox.value = "";
                   2187: 	    selval[0].selected = true;
                   2188: 
                   2189: 	    for (i=0;i<document.classgrade.total.value;i++) {
1.125     ng       2190: 		var user = document.classgrade["ctr"+i].value;
                   2191: 		var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
                   2192: 		resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
                   2193: 		var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
                   2194: 		resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
                   2195: 		var saveselval   = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
                   2196: 		var selname   = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42      ng       2197: 		if (saveselval == "excused") {
1.43      ng       2198: 		    if (selname[1].selected == false) { selname[1].selected = true;}
1.42      ng       2199: 		} else {
1.43      ng       2200: 		    if (selname[0].selected == false) {selname[0].selected = true};
1.42      ng       2201: 		}
                   2202: 	    }
1.41      ng       2203: 	}
1.42      ng       2204:     }
                   2205: 
1.41      ng       2206: </script>
                   2207: VIEWJAVASCRIPT
1.42      ng       2208: }
                   2209: 
1.44      ng       2210: #--- show scores for a section or whole class w/ option to change/update a score
1.42      ng       2211: sub viewgrades {
                   2212:     my ($request) = shift;
                   2213:     &viewgrades_js($request);
1.41      ng       2214: 
                   2215:     my ($symb,$url) = ($ENV{'form.symb'},$ENV{'form.url'}); 
1.45      ng       2216:     my $result='<h3><font color="#339933">Manual Grading</font></h3>';
1.38      ng       2217: 
1.118     ng       2218:     $result.='<font size=+1><b>Current Resource: </b>'.$ENV{'form.probTitle'}.'</font>'."\n";
1.41      ng       2219: 
                   2220:     #view individual student submission form - called using Javascript viewOneStudent
1.45      ng       2221:     $result.=&jscriptNform($url,$symb);
1.41      ng       2222: 
1.44      ng       2223:     #beginning of class grading form
1.41      ng       2224:     $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.106     albertel 2225: 	'<input type="hidden" name="symb"    value="'.$symb.'" />'."\n".
1.41      ng       2226: 	'<input type="hidden" name="url"     value="'.$url.'" />'."\n".
1.38      ng       2227: 	'<input type="hidden" name="command" value="editgrades" />'."\n".
1.72      ng       2228: 	'<input type="hidden" name="section" value="'.$ENV{'form.section'}.'" />'."\n".
1.77      ng       2229: 	'<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
1.125     ng       2230: 	'<input type="hidden" name="Status" value="'.$ENV{'form.Status'}.'" />'."\n".
1.72      ng       2231: 	'<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n";
                   2232: 
1.126     ng       2233:     my $sectionClass;
1.52      albertel 2234:     if ($ENV{'form.section'} eq 'all') {
1.126     ng       2235: 	$sectionClass='Class </h3>';
1.52      albertel 2236:     } elsif ($ENV{'form.section'} eq 'no') {
1.126     ng       2237: 	$sectionClass='Students in no Section </h3>';
1.52      albertel 2238:     } else {
1.126     ng       2239: 	$sectionClass='Students in Section '.$ENV{'form.section'}.'</h3>';
1.52      albertel 2240:     }
1.126     ng       2241:     $result.='<h3>Assign Common Grade To '.$sectionClass;
1.52      albertel 2242:     $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
                   2243: 	'<table border=0><tr bgcolor="#ffffdd"><td>';
1.44      ng       2244:     #radio buttons/text box for assigning points for a section or class.
                   2245:     #handles different parts of a problem
1.125     ng       2246:     my ($partlist,$handgrade) = &response_type($url,$symb);
1.42      ng       2247:     my %weight = ();
                   2248:     my $ctsparts = 0;
1.41      ng       2249:     $result.='<table border="0">';
1.45      ng       2250:     my %seen = ();
1.42      ng       2251:     for (sort keys(%$handgrade)) {
1.54      albertel 2252: 	my ($partid,$respid) = split (/_/,$_,2);
1.45      ng       2253: 	next if $seen{$partid};
                   2254: 	$seen{$partid}++;
1.147     albertel 2255: 	my $handgrade=$$handgrade{$_};
1.42      ng       2256: 	my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
                   2257: 	$weight{$partid} = $wgt eq '' ? '1' : $wgt;
                   2258: 
1.44      ng       2259: 	$result.='<input type="hidden" name="partid_'.
                   2260: 	    $ctsparts.'" value="'.$partid.'" />'."\n";
                   2261: 	$result.='<input type="hidden" name="weight_'.
                   2262: 	    $partid.'" value="'.$weight{$partid}.'" />'."\n";
                   2263: 	$result.='<tr><td><b>Part  '.$partid.'&nbsp; &nbsp;Point:</b> </td><td>';
1.42      ng       2264: 	$result.='<table border="0"><tr>';  
1.41      ng       2265: 	my $ctr = 0;
1.42      ng       2266: 	while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
                   2267: 	    $result.= '<td><input type="radio" name="RADVAL_'.$partid.'" '.
1.54      albertel 2268: 		'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.41      ng       2269: 		','.$ctr.')" />'.$ctr."</td>\n";
                   2270: 	    $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
                   2271: 	    $ctr++;
                   2272: 	}
                   2273: 	$result.='</tr></table>';
1.44      ng       2274: 	$result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
1.54      albertel 2275: 	    $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
                   2276: 		$partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.42      ng       2277: 	    $weight{$partid}.' (problem weight)</td>'."\n";
                   2278: 	$result.= '</td><td><select name="SELVAL_'.$partid.'"'.
1.54      albertel 2279: 	    'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59      albertel 2280: 		$weight{$partid}.')"> '.
1.42      ng       2281: 	    '<option selected="on"> </option>'.
1.125     ng       2282: 	    '<option>excused</option>'.
                   2283: 	    '<option>reset status</option></select></td></tr>'."\n";
1.42      ng       2284: 	$ctsparts++;
1.41      ng       2285:     }
1.52      albertel 2286:     $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
                   2287: 	'<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.42      ng       2288:     $result.='<input type="button" value="Reset" '.
1.111     ng       2289: 	'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self>';
1.41      ng       2290: 
1.44      ng       2291:     #table listing all the students in a section/class
                   2292:     #header of table
1.126     ng       2293:     $result.= '<h3>Assign Grade to Specific Students in '.$sectionClass;
1.42      ng       2294:     $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.126     ng       2295: 	'<table border=0><tr bgcolor="#deffff"><td>&nbsp;<b>No.</b>&nbsp;</td>'.
1.129     ng       2296: 	'<td>'.&nameUserString('header')."</td>\n";
1.146     albertel 2297:     my (@parts) = sort(&getpartlist($url,$symb));
1.41      ng       2298:     foreach my $part (@parts) {
                   2299: 	my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.126     ng       2300: 	$display =~ s|^Number of Attempts|Tries<br />|; # makes the column narrower
1.41      ng       2301: 	if  (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
                   2302: 	if ($display =~ /^Partial Credit Factor/) {
1.54      albertel 2303: 	    my ($partid) = &split_part_type($part);
1.53      albertel 2304: 	    $result.='<td><b>Score Part '.$partid.'<br />(weight = '.
1.42      ng       2305: 		$weight{$partid}.')</b></td>'."\n";
1.41      ng       2306: 	    next;
                   2307: 	}
1.53      albertel 2308: 	$display =~ s|Problem Status|Grade Status<br />|;
1.41      ng       2309: 	$result.='<td><b>'.$display.'</b></td>'."\n";
                   2310:     }
                   2311:     $result.='</tr>';
1.44      ng       2312: 
1.41      ng       2313:     #get info for each student
1.44      ng       2314:     #list all the students - with points and grade status
1.76      ng       2315:     my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'1');
1.41      ng       2316:     my $ctr = 0;
1.53      albertel 2317:     foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
1.90      albertel 2318: 	my $uname = $_;
                   2319: 	$uname=~s/:/_/;
                   2320: 	$result.='<input type="hidden" name="ctr'.$ctr.'" value="'.$uname.'" />'."\n";
1.126     ng       2321: 	$ctr++;
1.41      ng       2322: 	$result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},
1.126     ng       2323: 				   $_,$$fullname{$_},\@parts,\%weight,$ctr);
1.41      ng       2324:     }
                   2325:     $result.='</table></td></tr></table>';
                   2326:     $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.126     ng       2327:     $result.='<input type="button" value="Save" '.
1.45      ng       2328: 	'onClick="javascript:submit();" TARGET=_self /></form>'."\n";
1.96      albertel 2329:     if (scalar(%$fullname) eq 0) {
                   2330: 	my $colspan=3+scalar(@parts);
1.116     ng       2331: 	$result='<font color="red">There are no students in section "'.$ENV{'form.section'}.
                   2332: 	    '" with enrollment status "'.$ENV{'form.Status'}.'" to modify or grade.</font>';
1.96      albertel 2333:     }
1.41      ng       2334:     $result.=&show_grading_menu_form($symb,$url);
                   2335:     return $result;
                   2336: }
                   2337: 
1.44      ng       2338: #--- call by previous routine to display each student
1.41      ng       2339: sub viewstudentgrade {
1.130     albertel 2340:     my ($url,$symb,$courseid,$student,$fullname,$parts,$weight,$ctr) = @_;
1.44      ng       2341:     my ($uname,$udom) = split(/:/,$student);
1.90      albertel 2342:     $student=~s/:/_/;
1.44      ng       2343:     my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.126     ng       2344:     my $result='<tr bgcolor="#ffffdd"><td align="right">'.$ctr.'&nbsp;</td><td>&nbsp;'.
1.44      ng       2345: 	'<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.112     ng       2346: 	'\')"; TARGET=_self>'.$fullname.'</a> '.
                   2347: 	'<font color="#999999">('.$uname.($ENV{'user.domain'} eq $udom ? '' : ':'.$udom).')</font></td>'."\n";
1.63      albertel 2348:     foreach my $apart (@$parts) {
                   2349: 	my ($part,$type) = &split_part_type($apart);
1.41      ng       2350: 	my $score=$record{"resource.$part.$type"};
                   2351: 	if ($type eq 'awarded') {
1.42      ng       2352: 	    my $pts = $score eq '' ? '' : $score*$$weight{$part};
                   2353: 	    $result.='<input type="hidden" name="'.
1.89      albertel 2354: 		'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.42      ng       2355: 	    $result.='<td align="middle"><input type="text" name="'.
1.89      albertel 2356: 		'GD_'.$student.'_'.$part.'_awarded" '.
                   2357: 		'onChange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44      ng       2358: 		'\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41      ng       2359: 	} elsif ($type eq 'solved') {
                   2360: 	    my ($status,$foo)=split(/_/,$score,2);
                   2361: 	    $status = 'nothing' if ($status eq '');
1.89      albertel 2362: 	    $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54      albertel 2363: 		$part.'_solved_s" value="'.$status.'" />'."\n";
1.126     ng       2364: 	    $result.='<td align="middle">&nbsp;<select name="'.
1.89      albertel 2365: 		'GD_'.$student.'_'.$part.'_solved" '.
                   2366: 		'onChange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.125     ng       2367: 	    $result.= (($status eq 'excused') ? '<option> </option><option selected="on">excused</option>' 
                   2368: 		: '<option selected="on"> </option><option>excused</option>')."\n";
                   2369: 	    $result.='<option>reset status</option>';
1.126     ng       2370: 	    $result.="</select>&nbsp;</td>\n";
1.122     ng       2371: 	} else {
                   2372: 	    $result.='<input type="hidden" name="'.
                   2373: 		'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
                   2374: 		    "\n";
                   2375: 	    $result.='<td align="middle"><input type="text" name="'.
                   2376: 		'GD_'.$student.'_'.$part.'_'.$type.'" '.
                   2377: 		'value="'.$score.'" size="4" /></td>'."\n";
1.41      ng       2378: 	}
                   2379:     }
                   2380:     $result.='</tr>';
                   2381:     return $result;
1.38      ng       2382: }
                   2383: 
1.44      ng       2384: #--- change scores for all the students in a section/class
                   2385: #    record does not get update if unchanged
1.38      ng       2386: sub editgrades {
1.41      ng       2387:     my ($request) = @_;
                   2388: 
                   2389:     my $symb=$ENV{'form.symb'};
1.43      ng       2390:     my $url =$ENV{'form.url'};
1.45      ng       2391:     my $title='<h3><font color="#339933">Current Grade Status</font></h3>';
1.118     ng       2392:     $title.='<font size=+1><b>Current Resource: </b>'.$ENV{'form.probTitle'}.'</font><br />'."\n";
1.44      ng       2393:     $title.='<font size=+1><b>Section: </b>'.$ENV{'form.section'}.'</font>'."\n";
1.126     ng       2394: 
1.44      ng       2395:     my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
1.129     ng       2396:     $result.= '<table border="0"><tr bgcolor="#deffff">'.
                   2397: 	'<td rowspan=2 valign="center">&nbsp;<b>No.</b>&nbsp;</td>'.
                   2398: 	'<td rowspan=2 valign="center">'.&nameUserString('header')."</td>\n";
1.43      ng       2399: 
                   2400:     my %scoreptr = (
                   2401: 		    'correct'  =>'correct_by_override',
                   2402: 		    'incorrect'=>'incorrect_by_override',
                   2403: 		    'excused'  =>'excused',
                   2404: 		    'ungraded' =>'ungraded_attempted',
                   2405: 		    'nothing'  => '',
                   2406: 		    );
1.56      matthew  2407:     my ($classlist,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
1.34      ng       2408: 
1.44      ng       2409:     my (@partid);
                   2410:     my %weight = ();
1.54      albertel 2411:     my %columns = ();
1.44      ng       2412:     my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54      albertel 2413: 
1.146     albertel 2414:     my (@parts) = sort(&getpartlist($url,$symb));
1.54      albertel 2415:     my $header;
1.44      ng       2416:     while ($ctr < $ENV{'form.totalparts'}) {
                   2417: 	my $partid = $ENV{'form.partid_'.$ctr};
                   2418: 	push @partid,$partid;
                   2419: 	$weight{$partid} = $ENV{'form.weight_'.$partid};
                   2420: 	$ctr++;
1.54      albertel 2421:     }
                   2422:     foreach my $partid (@partid) {
                   2423: 	$header .= '<td align="center">&nbsp;<b>Old Score</b>&nbsp;</td>'.
                   2424: 	    '<td align="center">&nbsp;<b>New Score</b>&nbsp;</td>';
                   2425: 	$columns{$partid}=2;
                   2426: 	foreach my $stores (@parts) {
                   2427: 	    my ($part,$type) = &split_part_type($stores);
                   2428: 	    if ($part !~ m/^\Q$partid\E/) { next;}
                   2429: 	    if ($type eq 'awarded' || $type eq 'solved') { next; }
                   2430: 	    my $display=&Apache::lonnet::metadata($url,$stores.'.display');
                   2431: 	    $display =~ s/\[Part: (\w)+\]//;
1.125     ng       2432: 	    $display =~ s/Number of Attempts/Tries/;
                   2433: 	    $header .= '<td align="center">&nbsp;<b>Old '.$display.'</b>&nbsp;</td>'.
                   2434: 		'<td align="center">&nbsp;<b>New '.$display.'</b>&nbsp;</td>';
1.54      albertel 2435: 	    $columns{$partid}+=2;
                   2436: 	}
                   2437:     }
                   2438:     foreach my $partid (@partid) {
                   2439: 	$result .= '<td colspan="'.$columns{$partid}.
                   2440: 	    '" align="center"><b>Part '.$partid.
1.44      ng       2441: 	    '</b> (Weight = '.$weight{$partid}.')</td>';
1.54      albertel 2442: 
1.44      ng       2443:     }
                   2444:     $result .= '</tr><tr bgcolor="#deffff">';
1.54      albertel 2445:     $result .= $header;
1.44      ng       2446:     $result .= '</tr>'."\n";
1.93      albertel 2447:     my $noupdate;
1.126     ng       2448:     my ($updateCtr,$noupdateCtr) = (1,1);
1.44      ng       2449:     for ($i=0; $i<$ENV{'form.total'}; $i++) {
1.93      albertel 2450: 	my $line;
1.44      ng       2451: 	my $user = $ENV{'form.ctr'.$i};
1.92      albertel 2452: 	my $usercolon = $user;
                   2453: 	$usercolon =~s/_/:/;
                   2454: 	my ($uname,$udom)=split(/_/,$user);
1.44      ng       2455: 	my %newrecord;
                   2456: 	my $updateflag = 0;
1.129     ng       2457: 	$line .= '<td>'.&nameUserString(undef,$$fullname{$usercolon},$uname,$udom).'</td>';
1.108     albertel 2458: 	my $usec=$classlist->{"$uname:$udom"}[5];
1.105     albertel 2459: 	if (!&canmodify($usec)) {
1.126     ng       2460: 	    my $numcols=scalar(@partid)*4+2;
1.105     albertel 2461: 	    $noupdate.=$line."<td colspan=\"$numcols\"><font color=\"red\">Not allowed to modify student</font></td></tr>";
                   2462: 	    next;
                   2463: 	}
1.44      ng       2464: 	foreach (@partid) {
1.54      albertel 2465: 	    my $old_aw    = $ENV{'form.GD_'.$user.'_'.$_.'_awarded_s'};
                   2466: 	    my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
                   2467: 	    my $old_part  = $old_aw eq '' ? '' : $old_part_pcr;
                   2468: 	    my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
                   2469: 
                   2470: 	    my $awarded   = $ENV{'form.GD_'.$user.'_'.$_.'_awarded'};
                   2471: 	    my $pcr       = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
                   2472: 	    my $partial   = $awarded eq '' ? '' : $pcr;
1.44      ng       2473: 	    my $score;
                   2474: 	    if ($partial eq '') {
1.54      albertel 2475: 		$score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44      ng       2476: 	    } elsif ($partial > 0) {
                   2477: 		$score = 'correct_by_override';
                   2478: 	    } elsif ($partial == 0) {
                   2479: 		$score = 'incorrect_by_override';
                   2480: 	    }
1.125     ng       2481: 	    my $dropMenu = $ENV{'form.GD_'.$user.'_'.$_.'_solved'};
                   2482: 	    $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
                   2483: 
                   2484: 	    if ($dropMenu eq 'reset status' &&
                   2485: 		$old_score ne '') { # ignore if no previous attempts => nothing to reset
                   2486: 		$newrecord{'resource.'.$_.'.tries'} = 0;
                   2487: 		$newrecord{'resource.'.$_.'.solved'} = '';
                   2488: 		$newrecord{'resource.'.$_.'.award'} = '';
                   2489: 		$newrecord{'resource.'.$_.'.awarded'} = 0;
                   2490: 		$newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
                   2491: 		$updateflag = 1;
1.139     albertel 2492: 	    } elsif (!($old_part eq $partial && $old_score eq $score)) {
                   2493: 		$updateflag = 1;
                   2494: 		$newrecord{'resource.'.$_.'.awarded'}  = $partial if $partial ne '';
                   2495: 		$newrecord{'resource.'.$_.'.solved'}   = $score;
                   2496: 		$rec_update++;
1.125     ng       2497: 	    }
                   2498: 
1.93      albertel 2499: 	    $line .= '<td align="center">'.$old_aw.'&nbsp;</td>'.
1.44      ng       2500: 		'<td align="center">'.$awarded.
                   2501: 		($score eq 'excused' ? $score : '').'&nbsp;</td>';
1.5       albertel 2502: 
1.54      albertel 2503: 
                   2504: 	    my $partid=$_;
                   2505: 	    foreach my $stores (@parts) {
                   2506: 		my ($part,$type) = &split_part_type($stores);
                   2507: 		if ($part !~ m/^\Q$partid\E/) { next;}
                   2508: 		if ($type eq 'awarded' || $type eq 'solved') { next; }
                   2509: 		my $old_aw    = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
                   2510: 		my $awarded   = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type};
                   2511: 		if ($awarded ne '' && $awarded ne $old_aw) {
                   2512: 		    $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.122     ng       2513: 		    $newrecord{'resource.'.$part.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.54      albertel 2514: 		    $updateflag=1;
                   2515: 		}
1.93      albertel 2516: 		$line .= '<td align="center">'.$old_aw.'&nbsp;</td>'.
1.54      albertel 2517: 		    '<td align="center">'.$awarded.'&nbsp;</td>';
                   2518: 	    }
1.44      ng       2519: 	}
1.93      albertel 2520: 	$line.='</tr>'."\n";
1.44      ng       2521: 	if ($updateflag) {
                   2522: 	    $count++;
                   2523: 	    &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},
1.89      albertel 2524: 				    $udom,$uname);
1.126     ng       2525: 	    $result.='<tr bgcolor="#ffffde"><td align="right">&nbsp;'.$updateCtr.'&nbsp;</td>'.$line;
                   2526: 	    $updateCtr++;
1.93      albertel 2527: 	} else {
1.126     ng       2528: 	    $noupdate.='<tr bgcolor="#ffffde"><td align="right">&nbsp;'.$noupdateCtr.'&nbsp;</td>'.$line;
                   2529: 	    $noupdateCtr++;
1.44      ng       2530: 	}
1.93      albertel 2531:     }
                   2532:     if ($noupdate) {
1.126     ng       2533: #	my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
                   2534: 	my $numcols=scalar(@partid)*4+2;
                   2535: 	$result .= '<tr bgcolor="#ffffff"><td align="center" colspan="'.$numcols.'">No Changes Occurred For the Students Below</td></tr>'.$noupdate;
1.44      ng       2536:     }
1.72      ng       2537:     $result .= '</table></td></tr></table>'."\n".
                   2538: 	&show_grading_menu_form ($symb,$url);
1.125     ng       2539:     my $msg = '<br /><b>Number of records updated = '.$rec_update.
1.44      ng       2540: 	' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
                   2541: 	'<b>Total number of students = '.$ENV{'form.total'}.'</b><br />';
                   2542:     return $title.$msg.$result;
1.5       albertel 2543: }
1.54      albertel 2544: 
                   2545: sub split_part_type {
                   2546:     my ($partstr) = @_;
                   2547:     my ($temp,@allparts)=split(/_/,$partstr);
                   2548:     my $type=pop(@allparts);
                   2549:     my $part=join('.',@allparts);
                   2550:     return ($part,$type);
                   2551: }
                   2552: 
1.44      ng       2553: #------------- end of section for handling grading by section/class ---------
                   2554: #
                   2555: #----------------------------------------------------------------------------
                   2556: 
1.5       albertel 2557: 
1.44      ng       2558: #----------------------------------------------------------------------------
                   2559: #
                   2560: #-------------------------- Next few routines handles grading by csv upload
                   2561: #
                   2562: #--- Javascript to handle csv upload
1.27      albertel 2563: sub csvupload_javascript_reverse_associate {
                   2564:   return(<<ENDPICK);
                   2565:   function verify(vf) {
                   2566:     var foundsomething=0;
                   2567:     var founduname=0;
                   2568:     var founddomain=0;
                   2569:     for (i=0;i<=vf.nfields.value;i++) {
                   2570:       tw=eval('vf.f'+i+'.selectedIndex');
                   2571:       if (i==0 && tw!=0) { founduname=1; }
                   2572:       if (i==1 && tw!=0) { founddomain=1; }
                   2573:       if (i!=0 && i!=1 && tw!=0) { foundsomething=1; }
                   2574:     }
                   2575:     if (founduname==0 || founddomain==0) {
                   2576:       alert('You need to specify at both the username and domain');
                   2577:       return;
                   2578:     }
                   2579:     if (foundsomething==0) {
                   2580:       alert('You need to specify at least one grading field');
                   2581:       return;
                   2582:     }
                   2583:     vf.submit();
                   2584:   }
                   2585:   function flip(vf,tf) {
                   2586:     var nw=eval('vf.f'+tf+'.selectedIndex');
                   2587:     var i;
                   2588:     for (i=0;i<=vf.nfields.value;i++) {
                   2589:       //can not pick the same destination field for both name and domain
                   2590:       if (((i ==0)||(i ==1)) && 
                   2591:           ((tf==0)||(tf==1)) && 
                   2592:           (i!=tf) &&
                   2593:           (eval('vf.f'+i+'.selectedIndex')==nw)) {
                   2594:         eval('vf.f'+i+'.selectedIndex=0;')
                   2595:       }
                   2596:     }
                   2597:   }
                   2598: ENDPICK
                   2599: }
                   2600: 
                   2601: sub csvupload_javascript_forward_associate {
                   2602:   return(<<ENDPICK);
                   2603:   function verify(vf) {
                   2604:     var foundsomething=0;
                   2605:     var founduname=0;
                   2606:     var founddomain=0;
                   2607:     for (i=0;i<=vf.nfields.value;i++) {
                   2608:       tw=eval('vf.f'+i+'.selectedIndex');
                   2609:       if (tw==1) { founduname=1; }
                   2610:       if (tw==2) { founddomain=1; }
                   2611:       if (tw>2) { foundsomething=1; }
                   2612:     }
                   2613:     if (founduname==0 || founddomain==0) {
                   2614:       alert('You need to specify at both the username and domain');
                   2615:       return;
                   2616:     }
                   2617:     if (foundsomething==0) {
                   2618:       alert('You need to specify at least one grading field');
                   2619:       return;
                   2620:     }
                   2621:     vf.submit();
                   2622:   }
                   2623:   function flip(vf,tf) {
                   2624:     var nw=eval('vf.f'+tf+'.selectedIndex');
                   2625:     var i;
                   2626:     //can not pick the same destination field twice
                   2627:     for (i=0;i<=vf.nfields.value;i++) {
                   2628:       if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
                   2629:         eval('vf.f'+i+'.selectedIndex=0;')
                   2630:       }
                   2631:     }
                   2632:   }
                   2633: ENDPICK
                   2634: }
                   2635: 
1.26      albertel 2636: sub csvuploadmap_header {
1.41      ng       2637:     my ($request,$symb,$url,$datatoken,$distotal)= @_;
                   2638:     my $javascript;
                   2639:     if ($ENV{'form.upfile_associate'} eq 'reverse') {
                   2640: 	$javascript=&csvupload_javascript_reverse_associate();
                   2641:     } else {
                   2642: 	$javascript=&csvupload_javascript_forward_associate();
                   2643:     }
1.45      ng       2644: 
1.122     ng       2645:     my ($result) = &showResourceInfo($url,$ENV{'form.probTitle'});
1.118     ng       2646: 
1.41      ng       2647:     $request->print(<<ENDPICK);
1.26      albertel 2648: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.45      ng       2649: <h3><font color="#339933">Uploading Class Grades</font></h3>
                   2650: $result
1.26      albertel 2651: <hr>
                   2652: <h3>Identify fields</h3>
                   2653: Total number of records found in file: $distotal <hr />
                   2654: Enter as many fields as you can. The system will inform you and bring you back
                   2655: to this page if the data selected is insufficient to run your class.<hr />
                   2656: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
                   2657: <input type="hidden" name="associate"  value="" />
                   2658: <input type="hidden" name="phase"      value="three" />
                   2659: <input type="hidden" name="datatoken"  value="$datatoken" />
                   2660: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
                   2661: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
                   2662: <input type="hidden" name="upfile_associate" 
                   2663:                                        value="$ENV{'form.upfile_associate'}" />
                   2664: <input type="hidden" name="symb"       value="$symb" />
                   2665: <input type="hidden" name="url"        value="$url" />
1.77      ng       2666: <input type="hidden" name="saveState"  value="$ENV{'form.saveState'}" />
1.72      ng       2667: <input type="hidden" name="probTitle"  value="$ENV{'form.probTitle'}" />
1.26      albertel 2668: <input type="hidden" name="command"    value="csvuploadassign" />
                   2669: <hr />
                   2670: <script type="text/javascript" language="Javascript">
                   2671: $javascript
                   2672: </script>
                   2673: ENDPICK
1.118     ng       2674:     return '';
1.26      albertel 2675: 
                   2676: }
                   2677: 
                   2678: sub csvupload_fields {
1.146     albertel 2679:     my ($url,$symb) = @_;
                   2680:     my (@parts) = &getpartlist($url,$symb);
1.41      ng       2681:     my @fields=(['username','Student Username'],['domain','Student Domain']);
                   2682:     foreach my $part (sort(@parts)) {
                   2683: 	my @datum;
                   2684: 	my $display=&Apache::lonnet::metadata($url,$part.'.display');
                   2685: 	my $name=$part;
                   2686: 	if  (!$display) { $display = $name; }
                   2687: 	@datum=($name,$display);
                   2688: 	push(@fields,\@datum);
                   2689:     }
                   2690:     return (@fields);
1.26      albertel 2691: }
                   2692: 
                   2693: sub csvuploadmap_footer {
1.41      ng       2694:     my ($request,$i,$keyfields) =@_;
                   2695:     $request->print(<<ENDPICK);
1.26      albertel 2696: </table>
                   2697: <input type="hidden" name="nfields" value="$i" />
                   2698: <input type="hidden" name="keyfields" value="$keyfields" />
                   2699: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
                   2700: </form>
                   2701: ENDPICK
                   2702: }
                   2703: 
1.86      ng       2704: sub upcsvScores_form {
                   2705:     my ($request) = shift;
                   2706:     my ($symb,$url)=&get_symb_and_url($request);
                   2707:     if (!$symb) {return '';}
                   2708:     my $result =<<CSVFORMJS;
                   2709: <script type="text/javascript" language="javascript">
                   2710:     function checkUpload(formname) {
                   2711: 	if (formname.upfile.value == "") {
                   2712: 	    alert("Please use the browse button to select a file from your local directory.");
                   2713: 	    return false;
                   2714: 	}
                   2715: 	formname.submit();
                   2716:     }
                   2717:     </script>
                   2718: CSVFORMJS
                   2719:     $ENV{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.118     ng       2720:     my ($table) = &showResourceInfo($url,$ENV{'form.probTitle'});
                   2721:     $result.=$table;
1.86      ng       2722:     $result.='<br /><table width=100% border=0><tr><td bgcolor="#777777">'."\n";
                   2723:     $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
1.118     ng       2724:     $result.='&nbsp;<b>Specify a file containing the class scores for current resource'.
1.86      ng       2725: 	'.</b></td></tr>'."\n";
                   2726:     $result.='<tr bgcolor=#ffffe6><td>'."\n";
                   2727:     my $upfile_select=&Apache::loncommon::upfile_select_html();
                   2728:     $result.=<<ENDUPFORM;
1.106     albertel 2729: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86      ng       2730: <input type="hidden" name="symb" value="$symb" />
                   2731: <input type="hidden" name="url" value="$url" />
                   2732: <input type="hidden" name="command" value="csvuploadmap" />
                   2733: <input type="hidden" name="probTitle" value="$ENV{'form.probTitle'}" />
                   2734: <input type="hidden" name="saveState"  value="$ENV{'form.saveState'}" />
                   2735: $upfile_select
                   2736: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scores" />
                   2737: 
                   2738: </form>
                   2739: ENDUPFORM
                   2740:     $result.='</td></tr></table>'."\n";
                   2741:     $result.='</td></tr></table><br /><br />'."\n";
                   2742:     $result.=&show_grading_menu_form($symb,$url);
                   2743:     return $result;
                   2744: }
                   2745: 
                   2746: 
1.26      albertel 2747: sub csvuploadmap {
1.41      ng       2748:     my ($request)= @_;
                   2749:     my ($symb,$url)=&get_symb_and_url($request);
                   2750:     if (!$symb) {return '';}
1.72      ng       2751: 
1.41      ng       2752:     my $datatoken;
                   2753:     if (!$ENV{'form.datatoken'}) {
                   2754: 	$datatoken=&Apache::loncommon::upfile_store($request);
1.26      albertel 2755:     } else {
1.41      ng       2756: 	$datatoken=$ENV{'form.datatoken'};
                   2757: 	&Apache::loncommon::load_tmp_file($request);
1.26      albertel 2758:     }
1.41      ng       2759:     my @records=&Apache::loncommon::upfile_record_sep();
                   2760:     &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
                   2761:     my ($i,$keyfields);
                   2762:     if (@records) {
1.146     albertel 2763: 	my @fields=&csvupload_fields($url,$symb);
1.45      ng       2764: 
1.41      ng       2765: 	if ($ENV{'form.upfile_associate'} eq 'reverse') {	
                   2766: 	    &Apache::loncommon::csv_print_samples($request,\@records);
                   2767: 	    $i=&Apache::loncommon::csv_print_select_table($request,\@records,
                   2768: 							  \@fields);
                   2769: 	    foreach (@fields) { $keyfields.=$_->[0].','; }
                   2770: 	    chop($keyfields);
                   2771: 	} else {
                   2772: 	    unshift(@fields,['none','']);
                   2773: 	    $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
                   2774: 							    \@fields);
                   2775: 	    my %sone=&Apache::loncommon::record_sep($records[0]);
                   2776: 	    $keyfields=join(',',sort(keys(%sone)));
                   2777: 	}
                   2778:     }
                   2779:     &csvuploadmap_footer($request,$i,$keyfields);
1.72      ng       2780:     $request->print(&show_grading_menu_form($symb,$url));
                   2781: 
1.41      ng       2782:     return '';
1.27      albertel 2783: }
                   2784: 
                   2785: sub csvuploadassign {
1.41      ng       2786:     my ($request)= @_;
                   2787:     my ($symb,$url)=&get_symb_and_url($request);
                   2788:     if (!$symb) {return '';}
                   2789:     &Apache::loncommon::load_tmp_file($request);
1.44      ng       2790:     my @gradedata = &Apache::loncommon::upfile_record_sep();
1.41      ng       2791:     my @keyfields = split(/\,/,$ENV{'form.keyfields'});
                   2792:     my %fields=();
                   2793:     for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
                   2794: 	if ($ENV{'form.upfile_associate'} eq 'reverse') {
                   2795: 	    if ($ENV{'form.f'.$i} ne 'none') {
                   2796: 		$fields{$keyfields[$i]}=$ENV{'form.f'.$i};
                   2797: 	    }
                   2798: 	} else {
                   2799: 	    if ($ENV{'form.f'.$i} ne 'none') {
                   2800: 		$fields{$ENV{'form.f'.$i}}=$keyfields[$i];
                   2801: 	    }
                   2802: 	}
1.27      albertel 2803:     }
1.41      ng       2804:     $request->print('<h3>Assigning Grades</h3>');
                   2805:     my $courseid=$ENV{'request.course.id'};
1.97      albertel 2806:     my ($classlist) = &getclasslist('all',0);
1.106     albertel 2807:     my @notallowed;
1.41      ng       2808:     my @skipped;
                   2809:     my $countdone=0;
                   2810:     foreach my $grade (@gradedata) {
                   2811: 	my %entries=&Apache::loncommon::record_sep($grade);
                   2812: 	my $username=$entries{$fields{'username'}};
                   2813: 	my $domain=$entries{$fields{'domain'}};
                   2814: 	if (!exists($$classlist{"$username:$domain"})) {
                   2815: 	    push(@skipped,"$username:$domain");
                   2816: 	    next;
                   2817: 	}
1.108     albertel 2818: 	my $usec=$classlist->{"$username:$domain"}[5];
1.106     albertel 2819: 	if (!&canmodify($usec)) {
                   2820: 	    push(@notallowed,"$username:$domain");
                   2821: 	    next;
                   2822: 	}
1.41      ng       2823: 	my %grades;
                   2824: 	foreach my $dest (keys(%fields)) {
                   2825: 	    if ($dest eq 'username' || $dest eq 'domain') { next; }
                   2826: 	    if ($entries{$fields{$dest}} eq '') { next; }
                   2827: 	    my $store_key=$dest;
                   2828: 	    $store_key=~s/^stores/resource/;
                   2829: 	    $store_key=~s/_/\./g;
                   2830: 	    $grades{$store_key}=$entries{$fields{$dest}};
                   2831: 	}
                   2832: 	$grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
                   2833: 	&Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
                   2834: 				$domain,$username);
                   2835: 	$request->print('.');
                   2836: 	$request->rflush();
                   2837: 	$countdone++;
                   2838:     }
                   2839:     $request->print("<br />Stored $countdone students\n");
                   2840:     if (@skipped) {
1.106     albertel 2841: 	$request->print('<p<font size="+1"><b>Skipped Students</b></font></p>');
                   2842: 	foreach my $student (@skipped) { $request->print("$student<br />\n"); }
                   2843:     }
                   2844:     if (@notallowed) {
                   2845: 	$request->print('<p><font size="+1" color="red"><b>Students Not Allowed to Modify</b></font></p>');
                   2846: 	foreach my $student (@notallowed) { $request->print("$student<br />\n"); }
1.41      ng       2847:     }
1.106     albertel 2848:     $request->print("<br />\n");
1.41      ng       2849:     $request->print(&show_grading_menu_form($symb,$url));
                   2850:     return '';
1.26      albertel 2851: }
1.44      ng       2852: #------------- end of section for handling csv file upload ---------
                   2853: #
                   2854: #-------------------------------------------------------------------
                   2855: #
1.122     ng       2856: #-------------- Next few routines handle grading by page/sequence
1.72      ng       2857: #
                   2858: #--- Select a page/sequence and a student to grade
1.68      ng       2859: sub pickStudentPage {
                   2860:     my ($request) = shift;
                   2861: 
                   2862:     $request->print(<<LISTJAVASCRIPT);
                   2863: <script type="text/javascript" language="javascript">
                   2864: 
                   2865: function checkPickOne(formname) {
1.76      ng       2866:     if (radioSelection(formname.student) == null) {
1.68      ng       2867: 	alert("Please select the student you wish to grade.");
                   2868: 	return;
                   2869:     }
1.125     ng       2870:     ptr = pullDownSelection(formname.selectpage);
                   2871:     formname.page.value = formname["page"+ptr].value;
                   2872:     formname.title.value = formname["title"+ptr].value;
1.68      ng       2873:     formname.submit();
                   2874: }
                   2875: 
                   2876: </script>
                   2877: LISTJAVASCRIPT
1.118     ng       2878:     &commonJSfunctions($request);
1.72      ng       2879:     my ($symb,$url) = &get_symb_and_url($request);
1.68      ng       2880:     my $cdom      = $ENV{"course.$ENV{'request.course.id'}.domain"};
                   2881:     my $cnum      = $ENV{"course.$ENV{'request.course.id'}.num"};
                   2882:     my $getsec    = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
                   2883: 
                   2884:     my $result='<h3><font color="#339933">&nbsp;'.
                   2885: 	'Manual Grading by Page or Sequence</font></h3>';
                   2886: 
1.80      ng       2887:     $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.70      ng       2888:     $result.='&nbsp;<b>Problems from:</b> <select name="selectpage">'."\n";
1.74      albertel 2889:     my ($titles,$symbx) = &getSymbMap($request);
1.137     albertel 2890:     my ($curpage) =&Apache::lonnet::decode_symb($symb); 
                   2891: #    my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb); 
                   2892: #    my $type=($curpage =~ /\.(page|sequence)/);
1.70      ng       2893:     my $ctr=0;
1.68      ng       2894:     foreach (@$titles) {
                   2895: 	my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.70      ng       2896: 	$result.='<option value="'.$ctr.'" '.
1.71      ng       2897: 	    ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
                   2898: 	    '>'.$showtitle.'</option>'."\n";
1.70      ng       2899: 	$ctr++;
1.68      ng       2900:     }
                   2901:     $result.= '</select>'."<br>\n";
1.70      ng       2902:     $ctr=0;
                   2903:     foreach (@$titles) {
                   2904: 	my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
                   2905: 	$result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
                   2906: 	$result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
                   2907: 	$ctr++;
                   2908:     }
1.72      ng       2909:     $result.='<input type="hidden" name="page" />'."\n".
                   2910: 	'<input type="hidden" name="title" />'."\n";
1.68      ng       2911: 
1.144     albertel 2912:     $result.='&nbsp;<b>View Problems Text: </b><input type="radio" name="vProb" value="no" checked="on" /> no '."\n".
1.71      ng       2913: 	'<input type="radio" name="vProb" value="yes" /> yes '."<br>\n";
1.72      ng       2914: 
1.71      ng       2915:     $result.='&nbsp;<b>Submission Details: </b>'.
                   2916: 	'<input type="radio" name="lastSub" value="none" /> none'."\n".
1.122     ng       2917: 	'<input type="radio" name="lastSub" value="datesub" checked /> by dates and submissions'."\n".
1.71      ng       2918: 	'<input type="radio" name="lastSub" value="all" /> all details'."\n";
1.72      ng       2919: 
1.68      ng       2920:     $result.='<input type="hidden" name="section"     value="'.$getsec.'" />'."\n".
1.118     ng       2921: 	'<input type="hidden" name="Status"  value="'.$ENV{'form.Status'}.'" />'."\n".
1.72      ng       2922: 	'<input type="hidden" name="command" value="displayPage" />'."\n".
                   2923: 	'<input type="hidden" name="url"     value="'.$url.'" />'."\n".
1.80      ng       2924: 	'<input type="hidden" name="symb"    value="'.$symb.'" />'."\n".
                   2925: 	'<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."<br />\n";
1.72      ng       2926: 
1.80      ng       2927:     $result.='&nbsp;<input type="button" '.
1.126     ng       2928: 	'onClick="javascript:checkPickOne(this.form);"value="Next->" /><br />'."\n";
1.72      ng       2929: 
1.68      ng       2930:     $request->print($result);
                   2931: 
1.126     ng       2932:     my $studentTable.='&nbsp;<b>Select a student you wish to grade and then click on the Next button.</b><br>'.
1.68      ng       2933: 	'<table border="0"><tr><td bgcolor="#777777">'.
                   2934: 	'<table border="0"><tr bgcolor="#e6ffff">'.
1.126     ng       2935: 	'<td align="right">&nbsp;<b>No.</b></td>'.
1.129     ng       2936: 	'<td>'.&nameUserString('header').'</td>'.
1.126     ng       2937: 	'<td align="right">&nbsp;<b>No.</b></td>'.
1.129     ng       2938: 	'<td>'.&nameUserString('header').'</td></tr>';
1.68      ng       2939:  
1.76      ng       2940:     my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68      ng       2941:     my $ptr = 1;
                   2942:     foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
                   2943: 	my ($uname,$udom) = split(/:/,$student);
1.126     ng       2944: 	$studentTable.=($ptr%2 == 1 ? '<tr bgcolor="#ffffe6">' : '</td>');
                   2945: 	$studentTable.='<td align="right">'.$ptr.'&nbsp;</td>';
1.129     ng       2946: 	$studentTable.='<td>&nbsp;<input type="radio" name="student" value="'.$student.'" /> '
                   2947: 	    .&nameUserString(undef,$$fullname{$student},$uname,$udom)."\n";
1.126     ng       2948: 	$studentTable.=($ptr%2 == 0 ? '</td></tr>' : '');
1.68      ng       2949: 	$ptr++;
                   2950:     }
1.126     ng       2951:     $studentTable.='</td><td>&nbsp;</td><td>&nbsp;' if ($ptr%2 == 0);
1.68      ng       2952:     $studentTable.='</td></tr></table></td></tr></table>'."\n";
1.126     ng       2953:     $studentTable.='<input type="button" '.
                   2954: 	'onClick="javascript:checkPickOne(this.form);"value="Next->" /></form>'."\n";
1.68      ng       2955: 
                   2956:     $studentTable.=&show_grading_menu_form($symb,$url);
                   2957:     $request->print($studentTable);
                   2958: 
                   2959:     return '';
                   2960: }
                   2961: 
                   2962: sub getSymbMap {
1.74      albertel 2963:     my ($request) = @_;
1.132     bowersj2 2964:     my $navmap = Apache::lonnavmaps::navmap->new();
1.68      ng       2965: 
                   2966:     my %symbx = ();
                   2967:     my @titles = ();
1.117     bowersj2 2968:     my $minder = 0;
                   2969: 
                   2970:     # Gather every sequence that has problems.
                   2971:     my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); }, 1);
                   2972:     for my $sequence ($navmap->getById('0.0'), @sequences) {
                   2973: 	if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
                   2974: 	    my $title = $minder.'.'.$sequence->compTitle();
                   2975: 	    push @titles, $title; # minder in case two titles are identical
                   2976: 	    $symbx{$title} = $sequence->symb();
                   2977: 	    $minder++;
                   2978: 	}
1.68      ng       2979:     }
                   2980: 
                   2981:     $navmap->untieHashes();
                   2982:     return \@titles,\%symbx;
                   2983: }
                   2984: 
1.72      ng       2985: #
                   2986: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68      ng       2987: sub displayPage {
                   2988:     my ($request) = shift;
                   2989: 
1.72      ng       2990:     my ($symb,$url) = &get_symb_and_url($request);
1.68      ng       2991:     my $cdom      = $ENV{"course.$ENV{'request.course.id'}.domain"};
                   2992:     my $cnum      = $ENV{"course.$ENV{'request.course.id'}.num"};
                   2993:     my $getsec    = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
                   2994:     my $pageTitle = $ENV{'form.page'};
1.103     albertel 2995:     my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.70      ng       2996:     my ($uname,$udom) = split(/:/,$ENV{'form.student'});
1.103     albertel 2997:     my $usec=$classlist->{$ENV{'form.student'}}[5];
                   2998:     if (!&canview($usec)) {
                   2999: 	$request->print('<font color="red">Unable to view requested student.('.$ENV{'form.student'}.')</font>');
                   3000: 	$request->print(&show_grading_menu_form($symb,$url));
                   3001: 	return;
                   3002:     }
1.70      ng       3003:     my $result='<h3><font color="#339933">&nbsp;'.$ENV{'form.title'}.'</font></h3>';
1.129     ng       3004:     $result.='<h3>&nbsp;Student: '.&nameUserString(undef,$$fullname{$ENV{'form.student'}},$uname,$udom).
                   3005: 	'</h3>'."\n";
1.71      ng       3006:     &sub_page_js($request);
                   3007:     $request->print($result);
                   3008: 
1.132     bowersj2 3009:     my $navmap = Apache::lonnavmaps::navmap->new();
1.136     www      3010:     my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($ENV{'form.page'});
1.68      ng       3011:     my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
                   3012: 
                   3013:     my $iterator = $navmap->getIterator($map->map_start(),
                   3014: 					$map->map_finish());
                   3015: 
1.71      ng       3016:     my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72      ng       3017: 	'<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.125     ng       3018: 	'<input type="hidden" name="fullname" value="'.$$fullname{$ENV{'form.student'}}.'" />'."\n".
1.72      ng       3019: 	'<input type="hidden" name="student" value="'.$ENV{'form.student'}.'" />'."\n".
                   3020: 	'<input type="hidden" name="page"    value="'.$pageTitle.'" />'."\n".
                   3021: 	'<input type="hidden" name="title"   value="'.$ENV{'form.title'}.'" />'."\n".
                   3022: 	'<input type="hidden" name="url"     value="'.$url.'" />'."\n".
                   3023: 	'<input type="hidden" name="symb"    value="'.$symb.'" />'."\n".
1.125     ng       3024: 	'<input type="hidden" name="overRideScore" value="no" />'."\n".
1.77      ng       3025: 	'<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n";
1.71      ng       3026: 
                   3027:     my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
                   3028: 	'/check.gif" height="16" border="0" />';
                   3029: 
1.118     ng       3030:     $studentTable.='&nbsp;<b>Note:</b> Problems graded correct by the computer are marked with a '.$checkIcon.
                   3031: 	' symbol.'."\n".
1.71      ng       3032: 	'<table border="0"><tr><td bgcolor="#777777">'.
                   3033: 	'<table border="0"><tr bgcolor="#e6ffff">'.
1.118     ng       3034: 	'<td align="center"><b>&nbsp;Prob.&nbsp;</b></td>'.
                   3035: 	'<td><b>&nbsp;'.($ENV{'form.vProb'} eq 'no' ? 'Title' : 'Problem Text').'/Grade</b></td></tr>';
1.71      ng       3036: 
1.101     albertel 3037:     my ($depth,$question) = (1,1);
1.68      ng       3038:     $iterator->next(); # skip the first BEGIN_MAP
                   3039:     my $curRes = $iterator->next(); # for "current resource"
1.101     albertel 3040:     while ($depth > 0) {
1.68      ng       3041:         if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100     bowersj2 3042:         if($curRes == $iterator->END_MAP) { $depth--; }
1.68      ng       3043: 
1.120     ng       3044:         if (ref($curRes) && $curRes->is_problem()) {
1.91      albertel 3045: 	    my $parts = $curRes->parts();
1.68      ng       3046:             my $title = $curRes->compTitle();
1.71      ng       3047: 	    my $symbx = $curRes->symb();
                   3048: 	    $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.
                   3049: 		(scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).'&nbsp;parts)').'</td>';
                   3050: 	    $studentTable.='<td valign="top">';
1.144     albertel 3051: 	    if ($ENV{'form.vProb'} eq 'yes' ) {
                   3052: 		$studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
                   3053: 					     undef,'both');
1.71      ng       3054: 	    } else {
1.116     ng       3055: 		my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$ENV{'request.course.id'});
1.80      ng       3056: 		$companswer =~ s|<form(.*?)>||g;
                   3057: 		$companswer =~ s|</form>||g;
1.71      ng       3058: #		while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116     ng       3059: #		    $companswer =~ s/$1/ /ms;
                   3060: #		    $request->print('match='.$1."<br>\n");
1.71      ng       3061: #		}
1.116     ng       3062: #		$companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.71      ng       3063: 		$studentTable.='&nbsp;<b>'.$title.'</b>&nbsp;<br>&nbsp;<b>Correct answer:</b><br>'.$companswer;
                   3064: 	    }
                   3065: 
                   3066: 	    my %record = &Apache::lonnet::restore($symbx,$ENV{'request.course.id'},$udom,$uname);
1.125     ng       3067: 
1.71      ng       3068: 	    if ($ENV{'form.lastSub'} eq 'datesub') {
                   3069: 		if ($record{'version'} eq '') {
                   3070: 		    $studentTable.='<br />&nbsp;<font color="red">No recorded submission for this problem</font><br />';
                   3071: 		} else {
1.116     ng       3072: 		    my %responseType = ();
                   3073: 		    foreach my $partid (@{$parts}) {
1.147     albertel 3074: 			my @responseIds =$curRes->responseIds($partid);
                   3075: 			my @responseType =$curRes->responseType($partid);
                   3076: 			my %responseIds;
                   3077: 			for (my $i=0;$i<=$#responseIds;$i++) {
                   3078: 			    $responseIds{$responseIds[$i]}=$responseType[$i];
                   3079: 			}
                   3080: 			$responseType{$partid} = \%responseIds;
1.116     ng       3081: 		    }
1.148     albertel 3082: 		    $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147     albertel 3083: 
1.71      ng       3084: 		}
                   3085: 	    } elsif ($ENV{'form.lastSub'} eq 'all') {
                   3086: 		my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
                   3087: 		$studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
                   3088: 									$ENV{'request.course.id'},
                   3089: 									'','.submission');
                   3090:  
                   3091: 	    }
1.103     albertel 3092: 	    if (&canmodify($usec)) {
                   3093: 		foreach my $partid (@{$parts}) {
                   3094: 		    $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
                   3095: 		    $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
                   3096: 		    $question++;
                   3097: 		}
1.71      ng       3098: 	    }
                   3099: 	    $studentTable.='</td></tr>';
1.68      ng       3100: 
1.103     albertel 3101: 	}
1.68      ng       3102:         $curRes = $iterator->next();
                   3103:     }
                   3104: 
1.98      albertel 3105:     $navmap->untieHashes();
                   3106: 
1.71      ng       3107:     $studentTable.='</td></tr></table></td></tr></table>'."\n".
1.125     ng       3108: 	'<input type="button" value="Save" '.
1.71      ng       3109: 	'onClick="javascript:checkSubmitPage(this.form,'.$question.');" TARGET=_self />'.
                   3110: 	'</form>'."\n";
                   3111:     $studentTable.=&show_grading_menu_form($symb,$url);
                   3112:     $request->print($studentTable);
                   3113: 
                   3114:     return '';
1.119     ng       3115: }
                   3116: 
                   3117: sub displaySubByDates {
1.148     albertel 3118:     my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.119     ng       3119:     my $studentTable='<table border="0" width="100%"><tr><td bgcolor="#777777">'.
                   3120: 	'<table border="0" width="100%"><tr bgcolor="#e6ffff">'.
                   3121: 	'<td><b>Date/Time</b></td>'.
                   3122: 	'<td><b>Submission</b></td>'.
                   3123: 	'<td><b>Status&nbsp;</b></td></tr>';
                   3124:     my ($version);
                   3125:     my %mark;
1.148     albertel 3126:     my %orders;
1.119     ng       3127:     $mark{'correct_by_student'} = $checkIcon;
1.147     albertel 3128:     if (!exists($$record{'1:timestamp'})) {
                   3129: 	return '<br />&nbsp;<font color="red">Nothing submitted - no attempts</font><br />';
                   3130:     }
1.119     ng       3131:     for ($version=1;$version<=$$record{'version'};$version++) {
                   3132: 	my $timestamp = scalar(localtime($$record{$version.':timestamp'}));
                   3133: 	$studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>';
                   3134: 	my @versionKeys = split(/\:/,$$record{$version.':keys'});
                   3135: 	my @displaySub = ();
                   3136: 	foreach my $partid (@{$parts}) {
1.147     albertel 3137: 	    my @matchKey = sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys);
1.122     ng       3138: #	    next if ($$record{"$version:resource.$partid.solved"} eq '');
1.147     albertel 3139: 	    foreach my $matchKey (@matchKey) {
                   3140: 		if (exists $$record{$version.':'.$matchKey}) {
                   3141: 		    my ($responseId)=($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/);
                   3142: 		    $displaySub[0].='<b>Part&nbsp;'.$partid.'&nbsp;';
                   3143: 		    $displaySub[0].='<font color="#999999">(ID&nbsp;'.
                   3144: 			$responseId.')</font>&nbsp;';
                   3145: 		    if ($$record{"$version:resource.$partid.tries"} eq '') {
                   3146: 			$displaySub[0].='Trial&nbsp;not&nbsp;counted';
                   3147: 		    } else {
                   3148: 			$displaySub[0].='Trial&nbsp;'.
                   3149: 			    $$record{"$version:resource.$partid.tries"};
                   3150: 		    }
                   3151: 		    my $responseType=$responseType->{$partid}->{$responseId};
1.148     albertel 3152: 		    if (!exists($orders{$partid})) { $orders{$partid}={}; }
                   3153: 		    if (!exists($orders{$partid}->{$responseId})) {
                   3154: 			$orders{$partid}->{$responseId}=
                   3155: 			    &get_order($partid,$responseId,$symb,$uname,$udom);
                   3156: 		    }
1.147     albertel 3157: 		    $displaySub[0].='</b>&nbsp; '.
1.148     albertel 3158: 			&cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:").'<br />';
1.147     albertel 3159: 		}
                   3160: 	    }
                   3161: 	    if (exists $$record{"$version:resource.$partid.award"}) {
                   3162: 		$displaySub[1].='<b>Part&nbsp;'.$partid.'</b> &nbsp;'.
                   3163: 		    lc($$record{"$version:resource.$partid.award"}).' '.
                   3164: 		    $mark{$$record{"$version:resource.$partid.solved"}}.
                   3165: 		    '<br />';
                   3166: 	    }
                   3167: 	    if (exists $$record{"$version:resource.$partid.regrader"}) {
                   3168: 		$displaySub[2].=$$record{"$version:resource.$partid.regrader"}.
                   3169: 		    ' (<b>Part:</b> '.$partid.')';
                   3170: 	    }
                   3171: 	}
                   3172: 	# needed because old essay regrader has not parts info
                   3173: 	if (exists $$record{"$version:resource.regrader"}) {
                   3174: 	    $displaySub[2].=$$record{"$version:resource.regrader"};
                   3175: 	}
                   3176: 	$studentTable.='<td>'.$displaySub[0].'&nbsp;</td><td>'.$displaySub[1];
                   3177: 	if ($displaySub[2]) {
                   3178: 	    $studentTable.='Manually graded by '.$displaySub[2];
                   3179: 	}
                   3180: 	$studentTable.='&nbsp;</td></tr>';
                   3181:     
1.119     ng       3182:     }
                   3183:     $studentTable.='</table></td></tr></table>';
                   3184:     return $studentTable;
1.71      ng       3185: }
                   3186: 
                   3187: sub updateGradeByPage {
                   3188:     my ($request) = shift;
                   3189: 
                   3190:     my $cdom      = $ENV{"course.$ENV{'request.course.id'}.domain"};
                   3191:     my $cnum      = $ENV{"course.$ENV{'request.course.id'}.num"};
                   3192:     my $getsec    = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
                   3193:     my $pageTitle = $ENV{'form.page'};
1.103     albertel 3194:     my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.71      ng       3195:     my ($uname,$udom) = split(/:/,$ENV{'form.student'});
1.103     albertel 3196:     my $usec=$classlist->{$ENV{'form.student'}}[5];
                   3197:     if (!&canmodify($usec)) {
                   3198: 	$request->print('<font color="red">Unable to modify requested student.('.$ENV{'form.student'}.'</font>');
                   3199: 	$request->print(&show_grading_menu_form($ENV{'form.symb'},$ENV{'form.url'}));
                   3200: 	return;
                   3201:     }
1.71      ng       3202:     my $result='<h3><font color="#339933">&nbsp;'.$ENV{'form.title'}.'</font></h3>';
1.129     ng       3203:     $result.='<h3>&nbsp;Student: '.&nameUserString(undef,$ENV{'form.fullname'},$uname,$udom).
                   3204: 	'</h3>'."\n";
1.70      ng       3205: 
1.68      ng       3206:     $request->print($result);
                   3207: 
1.132     bowersj2 3208:     my $navmap = Apache::lonnavmaps::navmap->new();
1.136     www      3209:     my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $ENV{'form.page'});
1.71      ng       3210:     my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
                   3211: 
                   3212:     my $iterator = $navmap->getIterator($map->map_start(),
                   3213: 					$map->map_finish());
1.70      ng       3214: 
1.71      ng       3215:     my $studentTable='<table border="0"><tr><td bgcolor="#777777">'.
1.68      ng       3216: 	'<table border="0"><tr bgcolor="#e6ffff">'.
1.125     ng       3217: 	'<td align="center"><b>&nbsp;Prob.&nbsp;</b></td>'.
1.71      ng       3218: 	'<td><b>&nbsp;Title&nbsp;</b></td>'.
                   3219: 	'<td><b>&nbsp;Previous Score&nbsp;</b></td>'.
                   3220: 	'<td><b>&nbsp;New Score&nbsp;</b></td></tr>';
                   3221: 
                   3222:     $iterator->next(); # skip the first BEGIN_MAP
                   3223:     my $curRes = $iterator->next(); # for "current resource"
1.101     albertel 3224:     my ($depth,$question,$changeflag)= (1,1,0);
                   3225:     while ($depth > 0) {
1.71      ng       3226:         if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100     bowersj2 3227:         if($curRes == $iterator->END_MAP) { $depth--; }
1.71      ng       3228: 
                   3229:         if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
1.91      albertel 3230: 	    my $parts = $curRes->parts();
1.71      ng       3231:             my $title = $curRes->compTitle();
                   3232: 	    my $symbx = $curRes->symb();
                   3233: 	    $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$question.
                   3234: 		(scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).'&nbsp;parts)').'</td>';
                   3235: 	    $studentTable.='<td valign="top">&nbsp;<b>'.$title.'</b>&nbsp;</td>';
                   3236: 
                   3237: 	    my %newrecord=();
                   3238: 	    my @displayPts=();
                   3239: 	    foreach my $partid (@{$parts}) {
                   3240: 		my $newpts = $ENV{'form.GD_BOX'.$question.'_'.$partid};
                   3241: 		my $oldpts = $ENV{'form.oldpts'.$question.'_'.$partid};
                   3242: 
                   3243: 		my $wgt = $ENV{'form.WGT'.$question.'_'.$partid} != 0 ? 
                   3244: 		    $ENV{'form.WGT'.$question.'_'.$partid} : 1;
                   3245: 		my $partial = $newpts/$wgt;
                   3246: 		my $score;
                   3247: 		if ($partial > 0) {
                   3248: 		    $score = 'correct_by_override';
1.125     ng       3249: 		} elsif ($newpts ne '') { #empty is taken as 0
1.71      ng       3250: 		    $score = 'incorrect_by_override';
                   3251: 		}
1.125     ng       3252: 		my $dropMenu = $ENV{'form.GD_SEL'.$question.'_'.$partid};
                   3253: 		if ($dropMenu eq 'excused') {
1.71      ng       3254: 		    $partial = '';
                   3255: 		    $score = 'excused';
1.125     ng       3256: 		} elsif ($dropMenu eq 'reset status'
                   3257: 			 && $ENV{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
                   3258: 		    $newrecord{'resource.'.$partid.'.tries'} = 0;
                   3259: 		    $newrecord{'resource.'.$partid.'.solved'} = '';
                   3260: 		    $newrecord{'resource.'.$partid.'.award'} = '';
                   3261: 		    $newrecord{'resource.'.$partid.'.awarded'} = 0;
                   3262: 		    $newrecord{'resource.'.$partid.'.regrader'} = "$ENV{'user.name'}:$ENV{'user.domain'}";
                   3263: 		    $changeflag++;
                   3264: 		    $newpts = '';
1.71      ng       3265: 		}
1.125     ng       3266: 
1.71      ng       3267: 		my $oldstatus = $ENV{'form.solved'.$question.'_'.$partid};
                   3268: 		$displayPts[0].='&nbsp;<b>Part</b> '.$partid.' = '.
                   3269: 		    (($oldstatus eq 'excused') ? 'excused' : $oldpts).
                   3270: 		    '&nbsp;<br>';
                   3271: 		$displayPts[1].='&nbsp;<b>Part</b> '.$partid.' = '.
1.125     ng       3272: 		     (($score eq 'excused') ? 'excused' : $newpts).
1.71      ng       3273: 		    '&nbsp;<br>';
                   3274: 
                   3275: 		$question++;
1.125     ng       3276: 		next if ($dropMenu eq 'reset status' || ($newpts == $oldpts && $score ne 'excused'));
                   3277: 
1.71      ng       3278: 		$newrecord{'resource.'.$partid.'.awarded'}  = $partial if $partial ne '';
1.125     ng       3279: 		$newrecord{'resource.'.$partid.'.solved'}   = $score if $score ne '';
                   3280: 		$newrecord{'resource.'.$partid.'.regrader'} = "$ENV{'user.name'}:$ENV{'user.domain'}"
                   3281: 		    if (scalar(keys(%newrecord)) > 0);
1.71      ng       3282: 
                   3283: 		$changeflag++;
                   3284: 	    }
                   3285: 	    if (scalar(keys(%newrecord)) > 0) {
                   3286: 		&Apache::lonnet::cstore(\%newrecord,$symbx,$ENV{'request.course.id'},
                   3287: 					$udom,$uname);
                   3288: 	    }
1.125     ng       3289: 
1.71      ng       3290: 	    $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
                   3291: 		'<td valign="top">'.$displayPts[1].'</td>'.
                   3292: 		'</tr>';
1.68      ng       3293: 
                   3294: 	}
1.71      ng       3295:         $curRes = $iterator->next();
1.68      ng       3296:     }
1.98      albertel 3297: 
                   3298:     $navmap->untieHashes();
1.68      ng       3299: 
1.71      ng       3300:     $studentTable.='</td></tr></table></td></tr></table>';
                   3301:     $studentTable.=&show_grading_menu_form($ENV{'form.symb'},$ENV{'form.url'});
1.76      ng       3302:     my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
                   3303: 		  'The scores were changed for '.
                   3304: 		  $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
                   3305:     $request->print($grademsg.$studentTable);
1.68      ng       3306: 
1.70      ng       3307:     return '';
                   3308: }
                   3309: 
1.72      ng       3310: #-------- end of section for handling grading by page/sequence ---------
                   3311: #
                   3312: #-------------------------------------------------------------------
                   3313: 
1.75      albertel 3314: #--------------------Scantron Grading-----------------------------------
                   3315: #
                   3316: #------ start of section for handling grading by page/sequence ---------
                   3317: 
1.81      albertel 3318: sub defaultFormData {
                   3319:     my ($symb,$url)=@_;
                   3320:     return '
                   3321:       <input type="hidden" name="symb"    value="'.$symb.'" />'."\n".
                   3322:      '<input type="hidden" name="url"     value="'.$url.'" />'."\n".
                   3323:      '<input type="hidden" name="saveState" value="'.$ENV{'form.saveState'}.'" />'."\n".
                   3324:      '<input type="hidden" name="probTitle" value="'.$ENV{'form.probTitle'}.'" />'."\n";
                   3325: }
                   3326: 
1.75      albertel 3327: sub getSequenceDropDown {
                   3328:     my ($request,$symb)=@_;
                   3329:     my $result='<select name="selectpage">'."\n";
                   3330:     my ($titles,$symbx) = &getSymbMap($request);
1.137     albertel 3331:     my ($curpage)=&Apache::lonnet::decode_symb($symb); 
1.75      albertel 3332:     my $ctr=0;
                   3333:     foreach (@$titles) {
                   3334: 	my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
                   3335: 	$result.='<option value="'.$$symbx{$_}.'" '.
                   3336: 	    ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
                   3337: 	    '>'.$showtitle.'</option>'."\n";
                   3338: 	$ctr++;
                   3339:     }
                   3340:     $result.= '</select>';
                   3341:     return $result;
                   3342: }
                   3343: 
1.81      albertel 3344: sub scantron_uploads {
                   3345:     if (!-e $Apache::lonnet::perlvar{'lonScansDir'}) { return ''};
                   3346:     my $result=	'<select name="scantron_selectfile">';
                   3347:     opendir(DIR,$Apache::lonnet::perlvar{'lonScansDir'});
                   3348:     my @files=sort(readdir(DIR));
                   3349:     foreach my $filename (@files) {
                   3350: 	if ($filename eq '.' or $filename eq '..') { next; }
                   3351: 	$result.="<option>$filename</option>\n";
                   3352:     }
                   3353:     closedir(DIR);
                   3354:     $result.="</select>";
                   3355:     return $result;
                   3356: }
                   3357: 
1.82      albertel 3358: sub scantron_scantab {
                   3359:     my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
                   3360:     my $result='<select name="scantron_format">'."\n";
                   3361:     foreach my $line (<$fh>) {
                   3362: 	my ($name,$descrip)=split(/:/,$line);
                   3363: 	if ($name =~ /^\#/) { next; }
                   3364: 	$result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
                   3365:     }
                   3366:     $result.='</select>'."\n";
                   3367: 
                   3368:     return $result;
                   3369: }
                   3370: 
1.75      albertel 3371: sub scantron_selectphase {
                   3372:     my ($r) = @_;
                   3373:     my ($symb,$url)=&get_symb_and_url($r);
                   3374:     if (!$symb) {return '';}
                   3375:     my $sequence_selector=&getSequenceDropDown($r,$symb);
1.81      albertel 3376:     my $default_form_data=&defaultFormData($symb,$url);
                   3377:     my $grading_menu_button=&show_grading_menu_form($symb,$url);
                   3378:     my $file_selector=&scantron_uploads();
1.82      albertel 3379:     my $format_selector=&scantron_scantab();
1.75      albertel 3380:     my $result;
                   3381:     $result.= <<SCANTRONFORM;
1.82      albertel 3382: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantro_process">
1.142     albertel 3383:   <input type="hidden" name="command" value="scantron_validate" />
1.81      albertel 3384:   $default_form_data
1.75      albertel 3385:   <table width="100%" border="0">
                   3386:     <tr>
                   3387:       <td bgcolor="#777777">
                   3388:         <table width="100%" border="0">
                   3389:           <tr bgcolor="#e6ffff">
                   3390:             <td>
                   3391:               &nbsp;<b>Specify file location and which Folder/Sequence to grade</b>
                   3392:             </td>
                   3393:           </tr>
                   3394:           <tr bgcolor="#ffffe6">
                   3395:             <td>
                   3396:                Sequence to grade: $sequence_selector
                   3397: 	    </td>
                   3398:           </tr>
                   3399:           <tr bgcolor="#ffffe6">
                   3400:             <td>
1.81      albertel 3401: 		Filename of scoring office file: $file_selector
1.75      albertel 3402: 	    </td>
                   3403:           </tr>
1.82      albertel 3404:           <tr bgcolor="#ffffe6">
                   3405:             <td>
                   3406:               Format of data file: $format_selector
                   3407: 	    </td>
                   3408:           </tr>
1.75      albertel 3409:         </table>
                   3410:       </td>
                   3411:     </tr>
                   3412:   </table>
1.142     albertel 3413:   <input type="submit" value="Validate Scantron Records" />
1.75      albertel 3414: </form>
1.81      albertel 3415: $grading_menu_button
1.75      albertel 3416: SCANTRONFORM
                   3417: 
                   3418:     return $result;
                   3419: }
                   3420: 
1.82      albertel 3421: sub get_scantron_config {
                   3422:     my ($which) = @_;
                   3423:     my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
                   3424:     my %config;
                   3425:     foreach my $line (<$fh>) {
                   3426: 	my ($name,$descrip)=split(/:/,$line);
                   3427: 	if ($name ne $which ) { next; }
                   3428: 	chomp($line);
                   3429: 	my @config=split(/:/,$line);
                   3430: 	$config{'name'}=$config[0];
                   3431: 	$config{'description'}=$config[1];
                   3432: 	$config{'CODElocation'}=$config[2];
                   3433: 	$config{'CODEstart'}=$config[3];
                   3434: 	$config{'CODElength'}=$config[4];
                   3435: 	$config{'IDstart'}=$config[5];
                   3436: 	$config{'IDlength'}=$config[6];
                   3437: 	$config{'Qstart'}=$config[7];
                   3438: 	$config{'Qlength'}=$config[8];
                   3439: 	$config{'Qoff'}=$config[9];
                   3440: 	$config{'Qon'}=$config[10];
                   3441: 	last;
                   3442:     }
                   3443:     return %config;
                   3444: }
                   3445: 
                   3446: sub username_to_idmap {
                   3447:     my ($classlist)= @_;
                   3448:     my %idmap;
                   3449:     foreach my $student (keys(%$classlist)) {
                   3450: 	$idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
                   3451: 	    $student;
                   3452:     }
                   3453:     return %idmap;
                   3454: }
                   3455: 
                   3456: sub scantron_parse_scanline {
                   3457:     my ($line,$scantron_config)=@_;
                   3458:     my %record;
                   3459:     my $questions=substr($line,$$scantron_config{'Qstart'}-1);
                   3460:     my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
                   3461:     if ($$scantron_config{'CODElocation'} ne 0) {
                   3462: 	if ($$scantron_config{'CODElocation'} < 0) {
1.83      albertel 3463: 	    $record{'scantron.CODE'}=substr($data,$$scantron_config{'CODEstart'}-1,
                   3464: 					    $$scantron_config{'CODElength'});
1.82      albertel 3465: 	} else {
                   3466: 	    #FIXME interpret first N questions
                   3467: 	}
                   3468:     }
1.83      albertel 3469:     $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
                   3470: 				  $$scantron_config{'IDlength'});
1.82      albertel 3471:     my @alphabet=('A'..'Z');
                   3472:     my $questnum=0;
                   3473:     while ($questions) {
                   3474: 	$questnum++;
                   3475: 	my $currentquest=substr($questions,0,$$scantron_config{'Qlength'});
                   3476: 	substr($questions,0,$$scantron_config{'Qlength'})='';
1.83      albertel 3477: 	if (length($currentquest) < $$scantron_config{'Qlength'}) { next; }
1.82      albertel 3478: 	my (@array)=split(/$$scantron_config{'Qon'}/,$currentquest);
                   3479: 	if (scalar(@array) gt 2) {
                   3480: 	    #FIXME do something intelligent with double bubbles
1.83      albertel 3481: 	    Apache->request->print("<br ><b>Wha!!!</b> <pre>".scalar(@array).
                   3482: 				   '-'.$currentquest.'-'.$questnum.'</pre><br />');
1.82      albertel 3483: 	}
                   3484: 	if (length($array[0]) eq $$scantron_config{'Qlength'}) {
1.83      albertel 3485: 	    $record{"scantron.$questnum.answer"}='';
1.82      albertel 3486: 	} else {
1.83      albertel 3487: 	    $record{"scantron.$questnum.answer"}=$alphabet[length($array[0])];
1.82      albertel 3488: 	}
                   3489:     }
1.83      albertel 3490:     $record{'scantron.maxquest'}=$questnum;
                   3491:     return \%record;
1.82      albertel 3492: }
                   3493: 
                   3494: sub scantron_add_delay {
1.140     albertel 3495:     my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
                   3496:     Apache->request->print('add_delay_error '.$_[2] );
                   3497:     push(@$delayqueue,
                   3498: 	 {'line' => $scanline, 'emsg' => $errormessage,
                   3499: 	  'ecode' => $errorcode }
                   3500: 	 );
1.82      albertel 3501: }
                   3502: 
                   3503: sub scantron_find_student {
1.83      albertel 3504:     my ($scantron_record,$idmap)=@_;
                   3505:     my $scanID=$$scantron_record{'scantron.ID'};
                   3506:     foreach my $id (keys(%$idmap)) {
1.140     albertel 3507: 	#Apache->request->print('<pre>checking studnet -'.$id.'- againt -'.$scanID.'- </pre>');
                   3508: 	if (lc($id) eq lc($scanID)) {
                   3509: 	    #Apache->request->print('success');
                   3510: 	    return $$idmap{$id};
                   3511: 	}
1.83      albertel 3512:     }
                   3513:     return undef;
                   3514: }
                   3515: 
                   3516: sub scantron_filter {
                   3517:     my ($curres)=@_;
                   3518:     if (ref($curres) && $curres->is_problem() && !$curres->randomout) {
                   3519: 	return 1;
                   3520:     }
                   3521:     return 0;
1.82      albertel 3522: }
                   3523: 
1.140     albertel 3524: #FIXME I think I am doing this in the wrong order, I think it would be
                   3525: #better to make a several passes analyzing all of the lines in the
                   3526: #file for common errors wrong/invalid PID/username duplicated
                   3527: #PID/username, missing bubbles, double bubbles, missing/invalid CODE
                   3528: #and then get the instructor to fix all of these errors, then grade
                   3529: #the corrected one, I'll still need to catch error conditions, but
                   3530: #maybe most will taken care even before we start
1.142     albertel 3531: 
                   3532: sub scantron_validate_file {
                   3533:     my ($r) = @_;
                   3534: }
                   3535: 
1.82      albertel 3536: sub scantron_process_students {
1.75      albertel 3537:     my ($r) = @_;
1.136     www      3538:     my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($ENV{'form.selectpage'});
1.81      albertel 3539:     my ($symb,$url)=&get_symb_and_url($r);
                   3540:     if (!$symb) {return '';}
                   3541:     my $default_form_data=&defaultFormData($symb,$url);
1.82      albertel 3542: 
                   3543:     my %scantron_config=&get_scantron_config($ENV{'form.scantron_format'});
                   3544:     my $scanlines=Apache::File->new($Apache::lonnet::perlvar{'lonScansDir'}."/$ENV{'form.scantron_selectfile'}");
1.85      albertel 3545:     my @scanlines=<$scanlines>;
1.82      albertel 3546:     my $classlist=&Apache::loncoursedata::get_classlist();
                   3547:     my %idmap=&username_to_idmap($classlist);
1.132     bowersj2 3548:     my $navmap=Apache::lonnavmaps::navmap->new();
1.83      albertel 3549:     my $map=$navmap->getResourceByUrl($sequence);
                   3550:     my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.140     albertel 3551: #    $r->print("geto ".scalar(@resources)."<br />");
1.82      albertel 3552:     my $result= <<SCANTRONFORM;
1.81      albertel 3553: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
                   3554:   <input type="hidden" name="command" value="scantron_configphase" />
                   3555:   $default_form_data
                   3556: SCANTRONFORM
1.82      albertel 3557:     $r->print($result);
                   3558: 
                   3559:     my @delayqueue;
1.140     albertel 3560:     my %completedstudents;
                   3561:     
1.85      albertel 3562:     my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,
                   3563: 	           'Scantron Status','Scantron Progress',scalar(@scanlines));
1.140     albertel 3564:     &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
                   3565: 					  'Processing first student');
                   3566:     my $start=&Time::HiRes::time();
1.85      albertel 3567:     foreach my $line (@scanlines) {
1.140     albertel 3568: 	$r->print('<pre>line is'.$line.'</pre>');
1.75      albertel 3569: 
1.83      albertel 3570: 	chomp($line);
1.82      albertel 3571: 	my $scan_record=&scantron_parse_scanline($line,\%scantron_config);
                   3572: 	my ($uname,$udom);
1.140     albertel 3573: 	unless ($uname=&scantron_find_student($scan_record,\%idmap)) {
1.82      albertel 3574: 	    &scantron_add_delay(\@delayqueue,$line,
1.140     albertel 3575: 				'Unable to find a student that matches',1);
                   3576: 	    next;
                   3577: 	}
                   3578: 	if (exists $completedstudents{$uname}) {
                   3579: 	    &scantron_add_delay(\@delayqueue,$line,
                   3580: 				'Student '.$uname.' has multiple sheets',2);
                   3581: 	    next;
1.82      albertel 3582: 	}
1.83      albertel 3583: 	$r->print('<pre>doing studnet'.$uname.'</pre>');
1.82      albertel 3584: 	($uname,$udom)=split(/:/,$uname);
1.85      albertel 3585: 	&Apache::lonnet::delenv('form.counter');
1.83      albertel 3586: 	&Apache::lonnet::appenv(%$scan_record);
1.85      albertel 3587: #    &Apache::lonhomework::showhash(%ENV);
1.140     albertel 3588: #    $Apache::lonxml::debug=1;
                   3589: #	&Apache::lonxml::debug("line is $line");
1.83      albertel 3590: 	
1.85      albertel 3591: 	    my $i=0;
1.83      albertel 3592: 	foreach my $resource (@resources) {
1.85      albertel 3593: 	    $i++;
1.83      albertel 3594: 	    my $result=&Apache::lonnet::ssi($resource->src(),
                   3595: 				 ('submitted'     =>'scantron',
                   3596: 				  'grade_target'  =>'grade',
                   3597: 				  'grade_username'=>$uname,
                   3598: 				  'grade_domain'  =>$udom,
                   3599: 				  'grade_courseid'=>$ENV{'request.course.id'},
                   3600: 				  'grade_symb'    =>$resource->symb()));
1.140     albertel 3601: #	    my %score=&Apache::lonnet::restore($resource->symb(),
                   3602: #					       $ENV{'request.course.id'},
                   3603: #					       $udom,$uname);
                   3604: #	    foreach my $part ($resource->{PARTS}) {
                   3605: #		if ($score{'resource.'.$part.'.solved'} =~ /^correct/) {
                   3606: #		    $studentcorrect++;
                   3607: #		    $totalcorrect++;
                   3608: #		} else {
                   3609: #		    $studentincorrect++;
                   3610: #		    $totalincorrect++;
                   3611: #		}
                   3612: #	    }
                   3613: #	    $r->print('<pre>'.
                   3614: #		      $resource->symb().'-'.
                   3615: #		      $resource->src().'-'.'</pre>result is'.$result);
                   3616: #	    &Apache::lonhomework::showhash(%score);
1.85      albertel 3617: 	#    if ($i eq 3) {last;}
1.83      albertel 3618: 	}
1.140     albertel 3619: 	$completedstudents{$uname}={'line'=>$line};
                   3620:     } continue {
1.85      albertel 3621: 	&Apache::lonnet::delenv('form.counter');
1.83      albertel 3622: 	&Apache::lonnet::delenv('scantron\.');
1.85      albertel 3623: 	&Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
1.140     albertel 3624: 						 'last student');
                   3625: 	#last;
1.82      albertel 3626: 	#FIXME
                   3627: 	#get iterator for $sequence
                   3628: 	#foreach question 'submit' the students answer to the server
                   3629: 	#   through grade target {
                   3630: 	#   generate data to pass back that includes grade recevied
                   3631: 	#}
                   3632:     }
1.140     albertel 3633:     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
                   3634:     my $lasttime = &Time::HiRes::time()-$start;
                   3635:     $r->print("<p>took $lasttime</p>");
                   3636: 
                   3637:     #$Apache::lonxml::debug=0;
1.82      albertel 3638:     foreach my $delay (@delayqueue) {
                   3639: 	#FIXME
                   3640: 	#print out each delayed student with interface to select how
                   3641: 	#  to repair student provided info
                   3642: 	#Expected errors include
                   3643: 	#  1 bad/no stuid/username
                   3644: 	#  2 invalid bubblings
                   3645: 	
                   3646:     }
1.75      albertel 3647:     #FIXME
                   3648:     # if delay queue exists 2 submits one to process delayed students one
                   3649:     #     to ignore delayed students, possibly saving the delay queue for later
1.85      albertel 3650:     
                   3651:     $navmap->untieHashes();
1.75      albertel 3652: }
                   3653: #-------- end of section for handling grading scantron forms -------
                   3654: #
                   3655: #-------------------------------------------------------------------
                   3656: 
                   3657: 
1.72      ng       3658: #-------------------------- Menu interface -------------------------
                   3659: #
                   3660: #--- Show a Grading Menu button - Calls the next routine ---
                   3661: sub show_grading_menu_form {
                   3662:     my ($symb,$url)=@_;
1.125     ng       3663:     my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.72      ng       3664: 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
                   3665: 	'<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.77      ng       3666: 	'<input type="hidden" name="saveState"  value="'.$ENV{'form.saveState'}.'" />'."\n".
1.72      ng       3667: 	'<input type="hidden" name="command" value="gradingmenu" />'."\n".
                   3668: 	'<input type="submit" name="submit" value="Grading Menu" />'."\n".
                   3669: 	'</form>'."\n";
                   3670:     return $result;
                   3671: }
                   3672: 
1.77      ng       3673: # -- Retrieve choices for grading form
                   3674: sub savedState {
                   3675:     my %savedState = ();
                   3676:     if ($ENV{'form.saveState'}) {
                   3677: 	foreach (split(/:/,$ENV{'form.saveState'})) {
                   3678: 	    my ($key,$value) = split(/=/,$_,2);
                   3679: 	    $savedState{$key} = $value;
                   3680: 	}
                   3681:     }
                   3682:     return \%savedState;
                   3683: }
1.76      ng       3684: 
1.72      ng       3685: #--- Displays the main menu page -------
                   3686: sub gradingmenu {
                   3687:     my ($request) = @_;
                   3688:     my ($symb,$url)=&get_symb_and_url($request);
                   3689:     if (!$symb) {return '';}
1.76      ng       3690:     my $probTitle = &Apache::lonnet::gettitle($symb);
1.72      ng       3691: 
                   3692:     $request->print(<<GRADINGMENUJS);
                   3693: <script type="text/javascript" language="javascript">
1.116     ng       3694:     function checkChoice(formname,val,cmdx) {
                   3695: 	if (val <= 2) {
                   3696: 	    var cmd = radioSelection(formname.radioChoice);
1.118     ng       3697: 	    var cmdsave = cmd;
1.116     ng       3698: 	} else {
                   3699: 	    cmd = cmdx;
1.118     ng       3700: 	    cmdsave = 'submission';
1.116     ng       3701: 	}
                   3702: 	formname.command.value = cmd;
1.118     ng       3703: 	formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145     albertel 3704: 	    ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116     ng       3705: 	if (val < 5) formname.submit();
                   3706: 	if (val == 5) {
1.72      ng       3707: 	    if (!checkReceiptNo(formname,'notOK')) { return false;}
                   3708: 	    formname.submit();
                   3709: 	}
                   3710:     }
                   3711: 
                   3712:     function checkReceiptNo(formname,nospace) {
                   3713: 	var receiptNo = formname.receipt.value;
                   3714: 	var checkOpt = false;
                   3715: 	if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
                   3716: 	if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
                   3717: 	if (checkOpt) {
                   3718: 	    alert("Please enter a receipt number given by a student in the receipt box.");
                   3719: 	    formname.receipt.value = "";
                   3720: 	    formname.receipt.focus();
                   3721: 	    return false;
                   3722: 	}
                   3723: 	return true;
                   3724:     }
                   3725: </script>
                   3726: GRADINGMENUJS
1.118     ng       3727:     &commonJSfunctions($request);
                   3728:     my $result='<h3>&nbsp;<font color="#339933">Manual Grading/View Submission</font></h3>';
1.122     ng       3729:     my ($table,undef,$hdgrade) = &showResourceInfo($url,$probTitle);
1.118     ng       3730:     $result.=$table;
1.76      ng       3731:     my (undef,$sections) = &getclasslist('all','0');
1.77      ng       3732:     my $savedState = &savedState();
1.118     ng       3733:     my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77      ng       3734:     my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118     ng       3735:     my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77      ng       3736:     my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72      ng       3737: 
                   3738:     $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
                   3739: 	'<input type="hidden" name="symb"        value="'.$symb.'" />'."\n".
                   3740: 	'<input type="hidden" name="url"         value="'.$url.'" />'."\n".
                   3741: 	'<input type="hidden" name="handgrade"   value="'.$hdgrade.'" />'."\n".
                   3742: 	'<input type="hidden" name="probTitle"   value="'.$probTitle.'" />'."\n".
1.116     ng       3743: 	'<input type="hidden" name="command"     value="" />'."\n".
1.77      ng       3744: 	'<input type="hidden" name="saveState"   value="" />'."\n".
1.124     ng       3745: 	'<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72      ng       3746: 	'<input type="hidden" name="showgrading" value="yes" />'."\n";
                   3747: 
1.116     ng       3748:     $result.='<table width="100%" border=0><tr><td bgcolor=#777777>'."\n".
                   3749: 	'<table width=100% border=0><tr bgcolor="#e6ffff"><td colspan="2">'."\n".
1.72      ng       3750: 	'&nbsp;<b>Select a Grading/Viewing Option</b></td></tr>'."\n".
1.116     ng       3751: 	'<tr bgcolor="#ffffe6" valign="top"><td>'."\n";
                   3752: 
                   3753:     $result.='<table width="100%" border=0>';
                   3754:     $result.='<tr bgcolor="#ffffe6" valign="top"><td>'."\n".
1.118     ng       3755: 	'&nbsp;Select Section: <select name="section">'."\n";
1.116     ng       3756:     if (ref($sections)) {
                   3757: 	foreach (sort (@$sections)) {$result.='<option value="'.$_.'" '.
                   3758: 					 ($saveSec eq $_ ? 'selected="on"' : '').'>'.$_.'</option>'."\n";}
                   3759:     }
                   3760:     $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="on"' : ''). '>all</select> &nbsp; ';
                   3761: 
                   3762:     $result.='Student Status:</b>'.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,undef);
1.72      ng       3763: 
1.116     ng       3764:     if (ref($sections)) {
                   3765: 	$result.='&nbsp;(Section "no" implies the students were not assigned a section.)<br />' 
                   3766: 	    if (grep /no/,@$sections);
                   3767:     }
                   3768:     $result.='</td></tr>';
                   3769: 
1.118     ng       3770:     $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
                   3771: 	'<input type="radio" name="radioChoice" value="submission" '.
1.145     albertel 3772: 	($saveCmd eq 'submission' ? 'checked' : '').'> '.'<b>Current Resource:</b> For one or more students '.
                   3773: 	'<select name="submitonly">'.
                   3774: 	'<option value="yes" '.
                   3775: 	($saveSub eq 'yes' ? 'selected="on"' : '').'>with submissions</option>'.
                   3776: 	'<option value="graded" '.
                   3777: 	($saveSub eq 'graded' ? 'selected="on"' : '').'>with ungraded submissions</option>'.
                   3778: 	'<option value="all" '.
                   3779: 	($saveSub eq 'all' ? 'selected="on"' : '').'>with any status</option></select></td></tr>'."\n";
1.72      ng       3780: 
1.116     ng       3781:     $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
                   3782: 	'<input type="radio" name="radioChoice" value="viewgrades" '.
1.76      ng       3783: 	($saveCmd eq 'viewgrades' ? 'checked' : '').'> '.
1.118     ng       3784: 	'<b>Current Resource:</b> For all students in selected section or course</td></tr>'."\n";
1.72      ng       3785: 
1.118     ng       3786:     $result.='<tr bgcolor="#ffffe6" valign="top"><td>'.
                   3787: 	'<input type="radio" name="radioChoice" value="pickStudentPage" '.
                   3788: 	($saveCmd eq 'pickStudentPage' ? 'checked' : '').'> '.
                   3789: 	'The <b>complete</b> set/page/sequence: For one student</td></tr>'."\n";
1.46      ng       3790: 
1.116     ng       3791:     $result.='<tr bgcolor="#ffffe6"><td><br />'.
1.126     ng       3792: 	'<input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="Next->" />'.
1.116     ng       3793: 	'</td></tr></table>'."\n";
                   3794: 
                   3795:     $result.='</td><td valign="top">';
                   3796: 
                   3797:     $result.='<table width="100%" border=0>';
                   3798:     $result.='<tr bgcolor="#ffffe6"><td>'.
                   3799: 	'<input type="button" onClick="javascript:checkChoice(this.form,\'3\',\'csvform\');" value="Upload" />'.
                   3800: 	' scores from file </td></tr>'."\n";
1.72      ng       3801: 
1.75      albertel 3802:     $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
1.116     ng       3803: 	'<input type="button" onClick="javascript:checkChoice(this.form,\'4\',\'scantron_selectphase\');'.
                   3804: 	'" value="Grade" /> scantron forms</td></tr>'."\n";
1.75      albertel 3805: 
1.72      ng       3806:     if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb)) {
                   3807: 	$result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.116     ng       3808: 	    '<input type="button" onClick="javascript:checkChoice(this.form,\'5\',\'verify\');" value="Verify" />'.
                   3809: 	    ' submission Receipt no: '.unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).
1.72      ng       3810: 	    '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')">'.
                   3811: 	    '</td></tr>'."\n";
                   3812:     } 
1.44      ng       3813: 
1.116     ng       3814:     $result.='</form></td></tr></table>'."\n".
1.72      ng       3815: 	'</td></tr></table>'."\n".
                   3816: 	'</td></tr></table>'."\n";
1.44      ng       3817:     return $result;
1.2       albertel 3818: }
                   3819: 
1.1       albertel 3820: sub handler {
1.41      ng       3821:     my $request=$_[0];
1.102     albertel 3822: 
1.103     albertel 3823:     undef(%perm);
1.41      ng       3824:     if ($ENV{'browser.mathml'}) {
1.141     www      3825: 	&Apache::loncommon::content_type($request,'text/xml');
1.41      ng       3826:     } else {
1.141     www      3827: 	&Apache::loncommon::content_type($request,'text/html');
1.41      ng       3828:     }
                   3829:     $request->send_http_header;
1.44      ng       3830:     return '' if $request->header_only;
1.41      ng       3831:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
                   3832:     my $url=$ENV{'form.url'};
                   3833:     my $symb=$ENV{'form.symb'};
                   3834:     my $command=$ENV{'form.command'};
                   3835:     if (!$url) {
                   3836: 	my ($temp1,$temp2);
1.136     www      3837: 	($temp1,$temp2,$ENV{'form.url'})=&Apache::lonnet::decode_symb($symb);
1.41      ng       3838: 	$url = $ENV{'form.url'};
                   3839:     }
                   3840:     &send_header($request);
                   3841:     if ($url eq '' && $symb eq '') {
                   3842: 	if ($ENV{'user.adv'}) {
                   3843: 	    if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
                   3844: 		($ENV{'form.codethree'})) {
                   3845: 		my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
                   3846: 		    $ENV{'form.codethree'};
                   3847: 		my ($tsymb,$tuname,$tudom,$tcrsid)=
                   3848: 		    &Apache::lonnet::checkin($token);
                   3849: 		if ($tsymb) {
1.137     albertel 3850: 		    my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41      ng       3851: 		    if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.99      albertel 3852: 			$request->print(&Apache::lonnet::ssi_body('/res/'.$url,
                   3853: 					  ('grade_username' => $tuname,
                   3854: 					   'grade_domain' => $tudom,
                   3855: 					   'grade_courseid' => $tcrsid,
                   3856: 					   'grade_symb' => $tsymb)));
1.41      ng       3857: 		    } else {
1.45      ng       3858: 			$request->print('<h3>Not authorized: '.$token.'</h3>');
1.99      albertel 3859: 		    }
1.41      ng       3860: 		} else {
1.45      ng       3861: 		    $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41      ng       3862: 		}
1.14      www      3863: 	    } else {
1.41      ng       3864: 		$request->print(&Apache::lonxml::tokeninputfield());
                   3865: 	    }
                   3866: 	}
                   3867:     } else {
1.103     albertel 3868: 	if (!($perm{'vgr'}=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}))) {
                   3869: 	    if ($perm{'vgr'}=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}.'/'.$ENV{'request.course.sec'})) {
                   3870: 		$perm{'vgr_section'}=$ENV{'request.course.sec'};
1.102     albertel 3871: 	    } else {
1.103     albertel 3872: 		delete($perm{'vgr'});
1.102     albertel 3873: 	    }
                   3874: 	}
1.103     albertel 3875: 	if (!($perm{'mgr'}=&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'}))) {
                   3876: 	    if ($perm{'mgr'}=&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'}.'/'.$ENV{'request.course.sec'})) {
                   3877: 		$perm{'mgr_section'}=$ENV{'request.course.sec'};
1.102     albertel 3878: 	    } else {
1.103     albertel 3879: 		delete($perm{'mgr'});
1.102     albertel 3880: 	    }
                   3881: 	}
                   3882: 
1.104     albertel 3883: 	if ($command eq 'submission' && $perm{'vgr'}) {
1.68      ng       3884: 	    ($ENV{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103     albertel 3885: 	} elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68      ng       3886: 	    &pickStudentPage($request);
1.103     albertel 3887: 	} elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68      ng       3888: 	    &displayPage($request);
1.104     albertel 3889: 	} elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71      ng       3890: 	    &updateGradeByPage($request);
1.104     albertel 3891: 	} elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41      ng       3892: 	    &processGroup($request);
1.104     albertel 3893: 	} elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.41      ng       3894: 	    $request->print(&gradingmenu($request));
1.104     albertel 3895: 	} elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41      ng       3896: 	    $request->print(&viewgrades($request));
1.104     albertel 3897: 	} elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41      ng       3898: 	    $request->print(&processHandGrade($request));
1.106     albertel 3899: 	} elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41      ng       3900: 	    $request->print(&editgrades($request));
1.106     albertel 3901: 	} elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41      ng       3902: 	    $request->print(&verifyreceipt($request));
1.106     albertel 3903: 	} elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72      ng       3904: 	    $request->print(&upcsvScores_form($request));
1.106     albertel 3905: 	} elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41      ng       3906: 	    $request->print(&csvupload($request));
1.106     albertel 3907: 	} elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41      ng       3908: 	    $request->print(&csvuploadmap($request));
1.106     albertel 3909: 	} elsif ($command eq 'csvuploadassign' && $perm{'mgr'}) {
1.41      ng       3910: 	    if ($ENV{'form.associate'} ne 'Reverse Association') {
                   3911: 		$request->print(&csvuploadassign($request));
                   3912: 	    } else {
                   3913: 		if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
                   3914: 		    $ENV{'form.upfile_associate'} = 'reverse';
                   3915: 		} else {
                   3916: 		    $ENV{'form.upfile_associate'} = 'forward';
                   3917: 		}
                   3918: 		$request->print(&csvuploadmap($request));
                   3919: 	    }
1.106     albertel 3920: 	} elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75      albertel 3921: 	    $request->print(&scantron_selectphase($request));
1.142     albertel 3922: 	} elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
                   3923: 	    $request->print(&scantron_validate_file($request));
1.106     albertel 3924: 	} elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82      albertel 3925: 	    $request->print(&scantron_process_students($request));
1.106     albertel 3926: 	} elsif ($command) {
                   3927: 	    $request->print("Access Denied");
1.26      albertel 3928: 	}
1.2       albertel 3929:     }
1.41      ng       3930:     &send_footer($request);
1.44      ng       3931:     return '';
                   3932: }
                   3933: 
                   3934: sub send_header {
                   3935:     my ($request)= @_;
                   3936:     $request->print(&Apache::lontexconvert::header());
                   3937: #  $request->print("
                   3938: #<script>
                   3939: #remotewindow=open('','homeworkremote');
                   3940: #remotewindow.close();
                   3941: #</script>"); 
1.47      www      3942:     $request->print(&Apache::loncommon::bodytag('Grading'));
1.150     albertel 3943:     foreach my $key (sort(keys(%ENV))) {
                   3944: 	if ($key =~ /^form\./) {
                   3945: 	    Apache->request->print("$key => $ENV{$key} <br />");
                   3946: 	}
                   3947:     }
1.44      ng       3948: }
                   3949: 
                   3950: sub send_footer {
                   3951:     my ($request)= @_;
                   3952:     $request->print('</body>');
                   3953:     $request->print(&Apache::lontexconvert::footer());
1.1       albertel 3954: }
                   3955: 
                   3956: 1;
                   3957: 
1.13      albertel 3958: __END__;

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