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

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

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