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

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

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