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

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

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