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

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

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