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

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

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