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

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

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