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

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

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