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

1.17      albertel    1: # The LearningOnline Network with CAPA
1.13      albertel    2: # The LON-CAPA Grading handler
1.17      albertel    3: #
1.43    ! ng          4: # $Id: grades.pm,v 1.42 2002/07/26 20:28:42 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.35      ng         33: # June, July 2002 H.K. Ng
1.30      ng         34: #
1.1       albertel   35: 
                     36: package Apache::grades;
                     37: use strict;
                     38: use Apache::style;
                     39: use Apache::lonxml;
                     40: use Apache::lonnet;
1.3       albertel   41: use Apache::loncommon;
1.1       albertel   42: use Apache::lonhomework;
1.38      ng         43: use Apache::lonmsg qw(:user_normal_msg);
1.1       albertel   44: use Apache::Constants qw(:common);
1.39      ng         45: #use Time::HiRes qw( gettimeofday tv_interval );
1.1       albertel   46: 
1.2       albertel   47: sub moreinfo {
1.41      ng         48:     my ($request,$reason) = @_;
                     49:     $request->print("Unable to process request: $reason");
                     50:     if ( $Apache::grades::viewgrades eq 'F' ) {
                     51: 	$request->print('<form action="/adm/grades" method="post">'."\n");
                     52: 	if ($ENV{'form.url'}) {
                     53: 	    $request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />'."\n");
                     54: 	}
                     55: 	if ($ENV{'form.symb'}) {
                     56: 	    $request->print('<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />'."\n");
                     57: 	}
                     58: #    $request->print('<input type="hidden" name="command" value="submission" />'."\n");
                     59: 	$request->print('<input type="hidden" name="command" value="'.$ENV{'form.command'}.'" />'."\n");
                     60: 	$request->print("Student:".'<input type="text" name="student" value="'.$ENV{'form.student'}.'" />'."<br />\n");
                     61: 	$request->print("Domain:".'<input type="text" name="domain" value="'.$ENV{'user.domain'}.'" />'."<br />\n");
                     62: 	$request->print('<input type="submit" name="submit" value="ReSubmit" />'."<br />\n");
                     63: 	$request->print('</form>');
1.16      albertel   64:     }
1.41      ng         65:     return '';
1.2       albertel   66: }
                     67: 
1.23      www        68: sub verifyreceipt {
                     69:     my $request=shift;
                     70:     my $courseid=$ENV{'request.course.id'};
1.34      ng         71: #    my $cdom=$ENV{"course.$courseid.domain"};
                     72: #    my $cnum=$ENV{"course.$courseid.num"};
1.23      www        73:     my $receipt=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
1.41      ng         74: 	$ENV{'form.receipt'};
1.23      www        75:     $receipt=~s/[^\-\d]//g;
                     76:     my $symb=$ENV{'form.symb'};
                     77:     unless ($symb) {
                     78: 	$symb=&Apache::lonnet::symbread($ENV{'form.url'});
                     79:     }
                     80:     if ((&Apache::lonnet::allowed('mgr',$courseid)) && ($symb)) {
                     81:         $request->print('<h1>Verifying Submission Receipt '.$receipt.'</h1>');
                     82:         my $matches=0;
1.34      ng         83:         my ($classlist) = &getclasslist('all','0');
                     84:         foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
1.23      www        85:             my ($uname,$udom)=split(/\:/,$student);
                     86:             if ($receipt eq 
1.41      ng         87: 		&Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
                     88: 		$request->print('Matching '.$student.'<br>');
                     89: 		$matches++;
1.23      www        90: 	   }
                     91:         }
1.30      ng         92:         $request->printf('<p>'.$matches." match%s</p>",$matches <= 1 ? '' : 'es');
1.33      ng         93: # needs to print who is matched
1.23      www        94:     }
                     95:     return '';
                     96: }
1.13      albertel   97: 
1.32      ng         98: sub student_gradeStatus {
1.41      ng         99:     my ($url,$udom,$uname,$partlist) = @_;
                    100:     my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
                    101:     my %record= &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
                    102:     my %partstatus = ();
                    103:     foreach (@$partlist) {
                    104: 	my ($status,$foo)=split(/_/,$record{"resource.$_.solved"},2);
                    105: 	$status = 'nothing' if ($status eq '');
                    106: 	$partstatus{$_} = $status;
                    107: 	$partstatus{"resource.$_.submitted_by"} = $record{"resource.$_.submitted_by"} 
                    108: 	if ($record{"resource.$_.submitted_by"} ne '');
                    109:     }
                    110:     return %partstatus;
1.32      ng        111: }
                    112: 
1.34      ng        113: sub get_fullname {
1.39      ng        114:     my ($uname,$udom) = @_;
1.34      ng        115:     my %name=&Apache::lonnet::get('environment', ['lastname','generation',
1.41      ng        116: 						  'firstname','middlename'],$udom,$uname);
1.34      ng        117:     my $fullname;
                    118:     my ($tmp) = keys(%name);
                    119:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                    120: 	$fullname=$name{'lastname'}.$name{'generation'};
                    121: 	if ($fullname =~ /[^\s]+/) { $fullname.=', '; }
                    122: 	$fullname.=$name{'firstname'}.' '.$name{'middlename'};
                    123:     }
                    124:     return $fullname;
                    125: }
                    126: 
1.39      ng        127: sub response_type {
1.41      ng        128:     my ($url) = shift;
                    129:     my $allkeys = &Apache::lonnet::metadata($url,'keys');
                    130: #    print "allkeys=>$allkeys<br>";
                    131:     my %seen = ();
                    132:     my (@partlist,%handgrade);
                    133:     foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
1.43    ! ng        134: 	if (/^\w+response_\d+.*/) {
1.41      ng        135: 	    my ($responsetype,$part) = split(/_/,$_,2);
                    136: 	    my ($partid,$respid) = split(/_/,$part);
                    137: 	    $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no');
                    138: 	    next if ($seen{$partid} > 0);
                    139: 	    $seen{$partid}++;
                    140: 	    push @partlist,$partid;
                    141: 	}
                    142:     }
                    143:     return \@partlist,\%handgrade;
1.39      ng        144: }
                    145: 
                    146: 
1.30      ng        147: sub listStudents {
1.41      ng        148:     my ($request) = shift;
                    149:     my $cdom      =$ENV{"course.$ENV{'request.course.id'}.domain"};
                    150:     my $cnum      =$ENV{"course.$ENV{'request.course.id'}.num"};
                    151:     my $getsec    =$ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
                    152:     my $submitonly=$ENV{'form.submitonly'} eq '' ? 'all' : $ENV{'form.submitonly'};
                    153: 
                    154:     my $result='<h2><font color="#339933">&nbsp;View Submissions for a Student or a Group of Students</font></h2>';
                    155:     $result.='<table border="0">';
                    156:     $result.='<tr><td colspan=3><font size=+1><b>Resource: </b>'.$ENV{'form.url'}.'</font></td></tr>';
                    157:     my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
                    158:     for (sort keys(%$handgrade)) {
                    159: 	my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
                    160: 	$ENV{'form.handgrade'} = 'yes' if ($handgrade eq 'yes');
1.43    ! ng        161: 	$result.='<tr><td><b>Part id: </b>'.(split(/_/))[0].'</td>'.
1.41      ng        162: 	    '<td><b>Type: </b>'.$responsetype.'</td>'.
                    163: 	    '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
                    164:     }
                    165:     $result.='</table>';
                    166:     $request->print($result);
1.39      ng        167: 
1.41      ng        168:     $request->print(<<ENDTABLEST);
1.39      ng        169: <form action="/adm/grades" method="post">
1.34      ng        170: &nbsp;<b>View Problem: </b><input type="radio" name="vProb" value="no" checked> no 
1.37      ng        171: <input type="radio" name="vProb" value="yes"> yes <br />
                    172: &nbsp;<b>Submissions: </b>
1.40      ng        173: <input type="radio" name="lastSub" value="hdgrade" checked /> handgrade only
                    174: <input type="radio" name="lastSub" value="lastonly" /> last sub only
1.39      ng        175: <input type="radio" name="lastSub" value="last" /> last sub & parts info
                    176: <input type="radio" name="lastSub" value="all" /> all details
                    177: <input type="hidden" name="section" value="$getsec" />
                    178: <input type="hidden" name="submitonly" value="$submitonly" />
                    179: <input type="hidden" name="response" value="$ENV{'form.response'}" />
1.41      ng        180: <input type="hidden" name="handgrade" value="$ENV{'form.handgrade'}" /><br />
                    181: <input type="hidden" name="showgrading" value="$ENV{'form.showgrading'}" /><br />
1.39      ng        182: <input type="submit" name="submit" value="View/Grade" />
1.23      www       183: ENDTABLEST
1.41      ng        184:     if ($ENV{'form.url'}) {
                    185: 	$request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />'."\n");
                    186:     }
                    187:     if ($ENV{'form.symb'}) {
                    188: 	$request->print('<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />'."\n");
                    189:     }
                    190:     $request->print('<input type="hidden" name="command" value="processGroup" />'."\n");
                    191:     
                    192:     my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($getsec,'0');
                    193:     
                    194:     $result='<table border="0"><tr><td bgcolor="#777777">'.
                    195: 	'<table border="0"><tr bgcolor="#e6ffff">'.
                    196: 	'<td><b>&nbsp;Select&nbsp;</b></td><td><b>&nbsp;Username&nbsp;</b></td>'.
                    197: 	'<td><b>&nbsp;Fullname&nbsp;</b></td><td><b>&nbsp;Domain&nbsp;</b></td>';
                    198:     foreach (sort(@$partlist)) {
1.43    ! ng        199: 	$result.='<td><b>&nbsp;Part ID '.(split(/_/))[0].' Status&nbsp;</b></td>';
1.41      ng        200:     }
                    201:     $request->print($result.'</tr>'."\n");
                    202: 
                    203:     foreach my $student (sort(@{ $$classlist{$getsec} }) ) {
                    204: 	my ($uname,$udom) = split(/:/,$student);
                    205: 	my (%status) = &student_gradeStatus($ENV{'form.url'},$udom,$uname,$partlist);
                    206: 	my $statusflg = '';
                    207: 	foreach (keys(%status)) {
                    208: 	    $statusflg = 1 if ($status{$_} ne 'nothing');
1.43    ! ng        209: 	    my ($foo,$partid,$foo1) = split(/\./,$_);
1.41      ng        210: 	    if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
                    211: 		$statusflg = '';
                    212: 		$request->print('<input type="hidden" name="'.
                    213: 				$student.':submitted_by" value="'.
                    214: 				$status{'resource.'.$partid.'.submitted_by'}.'" />');
                    215: 	    }
                    216: 	}
                    217: 	next if ($statusflg eq '' && $submitonly eq 'yes');
1.34      ng        218: 
1.41      ng        219: 	if ( $Apache::grades::viewgrades eq 'F' ) {
                    220: 	    $result='<tr bgcolor="#ffffe6">'.
                    221: 		'<td align="center"><input type=checkbox name="stuinfo" value="'.
                    222: 		$student.':'.$$fullname{$student}.'"></td>'."\n".
                    223: 		'<td>&nbsp;'.$uname.'&nbsp;</td>'."\n".
                    224: 		'<td>&nbsp;'.$$fullname{$student}.'&nbsp;</td>'."\n".
                    225: 		'<td align="middle">&nbsp;'.$udom.'&nbsp;</td>'."\n";
                    226: 	    
                    227: 	    foreach (sort keys(%status)) {
                    228: 		next if (/^resource.*?submitted_by$/);
                    229: 		$result.='<td align="middle">&nbsp;'.$status{$_}.'&nbsp;</td>'."\n";
                    230: 	    }
                    231: 	    $request->print($result.'</tr>'."\n");
                    232: 	}
                    233:     }
                    234:     $request->print('</table></td></tr></table>');
                    235:     $request->print('<input type="submit" name="submit" value="View/Grade" /><form />');
1.10      ng        236: }
                    237: 
1.34      ng        238: sub processGroup {
1.41      ng        239:     my ($request)  = shift;
                    240:     my $ctr        = 0;
                    241:     my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
                    242: 		      : ($ENV{'form.stuinfo'}));
                    243:     my $total      = scalar(@stuchecked)-1;
                    244:     if ($stuchecked[0] eq '') {
                    245: 	&userError($request,'No student was selected for viewing/grading.');
                    246: 	return;
                    247:     }
                    248:     foreach (@stuchecked) {
                    249: 	my ($uname,$udom,$fullname) = split(/:/);
                    250: 	$ENV{'form.student'} = $uname;
                    251: 	$ENV{'form.fullname'} = $fullname;
                    252: 	&submission($request,$ctr,$total);
                    253: 	$ctr++;
                    254:     }
                    255:     return '';
1.35      ng        256: }
1.34      ng        257: 
1.35      ng        258: sub userError {
                    259:     my ($request, $reason, $step) = @_;
                    260:     $request->print('<h3><font color="red">LON-CAPA User Error</font></h3><br />'."\n");
                    261:     $request->print('<b>Reason: </b>'.$reason.'<br /><br />'."\n");
                    262:     $request->print('<b>Step: </b>'.($step ne '' ? $step : 'Use your browser back button to correct')
                    263: 		    .'<br /><br />'."\n");
                    264:     return '';
1.34      ng        265: }
1.13      albertel  266: 
1.7       albertel  267: #FIXME - needs to handle multiple matches
1.2       albertel  268: sub finduser {
1.41      ng        269:     my ($name) = @_;
                    270:     my $domain = '';
                    271:     if ( $Apache::grades::viewgrades eq 'F' ) {
                    272: 	my ($classlist) = &getclasslist('all','0');
                    273: 	foreach ( sort(@{ $$classlist{'all'} }) ) {
                    274: 	    my ($posname,$posdomain) = split(/:/);
                    275: 	    if ($posname =~ $name) { $name=$posname; $domain=$posdomain; last; }
                    276: 	}
                    277: 	return ($name,$domain);
                    278:     } else {
                    279: 	return ($ENV{'user.name'},$ENV{'user.domain'});
                    280:     }
1.5       albertel  281: }
                    282: 
                    283: sub getclasslist {
1.41      ng        284:     my ($getsec,$hideexpired) = @_;
                    285:     my $now = time;
                    286:     my %classlist=&Apache::lonnet::dump('classlist',
                    287: 					$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    288: 					$ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    289:     my (@holdsec,@sections,%allids,%stusec,%fullname);
                    290:     foreach (keys(%classlist)) {
                    291: 	my ($end,$start,$id,$section,$fullname)=split(/:/,$classlist{$_});
1.39      ng        292:        # still a student?
1.41      ng        293: 	if (($hideexpired) && ($end) && ($end < $now)) {
                    294: 	    next;
                    295: 	}
                    296: 	$section = ($section ne '' ? $section : 'no');
                    297: 	push @holdsec,$section;
                    298: 	if ($getsec eq 'all' || $getsec eq $section) {
                    299: 	    push (@{ $classlist{$getsec} }, $_);
                    300: 	    $allids{$_}=$id;
                    301: 	    $stusec{$_}=$section;
                    302: 	    $fullname{$_}=$fullname;
                    303: 	}
                    304:     }
                    305:     my %seen = ();
                    306:     foreach my $item (@holdsec) {
                    307: 	push (@sections, $item) unless $seen{$item}++;
                    308:     }
                    309:     return (\%classlist,\@sections,\%allids,\%stusec,\%fullname);
1.5       albertel  310: }
                    311: 
                    312: sub getpartlist {
1.41      ng        313:     my ($url) = @_;
                    314:     my @parts =();
                    315:     my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
                    316:     foreach my $key (@metakeys) {
                    317: 	if ( $key =~ m/stores_([0-9]+)_.*/) {
                    318: 	    push(@parts,$key);
                    319: 	}
1.13      albertel  320:     }
1.41      ng        321:     return @parts;
1.5       albertel  322: }
1.31      ng        323: 
1.41      ng        324: sub print_hash {
                    325:     my ($request, $hash) = @_;
                    326:     $request->print('<table border=1><tr><td>Key</td><td>Value</td></tr>');
                    327:     for (sort keys (%$hash)) {
                    328: 	$request->print('<tr><td>'.$_.'</td><td>'.$$hash{$_}.'&nbsp;</td></tr>');
                    329:     }
                    330:     $request->print('</table>');
                    331:     return '';
                    332: }
1.33      ng        333: #
1.32      ng        334: # --------------------------- show submissions of a student, option to grade --------
1.2       albertel  335: sub submission {
1.41      ng        336:     my ($request,$counter,$total) = @_;
1.33      ng        337: 
1.41      ng        338:     (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
                    339:     if ($ENV{'form.student'} eq '') { &moreinfo($request,'Need student login id'); return ''; }
                    340:     my ($uname,$udom) = &finduser($ENV{'form.student'});
                    341:     if ($uname eq '') { &moreinfo($request,'Unable to find student'); return ''; }
                    342: 
                    343:     my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
                    344:     if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
                    345:     my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
                    346:     $ENV{'form.vProb'} = $ENV{'form.vProb'} ne '' ? $ENV{'form.vProb'} : 'yes';
                    347:     my ($classlist,$seclist,$ids,$stusec,$fullname);
                    348: 
                    349:     # header info
                    350:     if ($counter == 0) {
                    351: 	&sub_page_js($request);
                    352: 	$request->print('<h2>&nbsp;<font color="#339933">Submission Record</font></h2>'.
                    353: 			'<font size=+1>&nbsp;<b>Resource: </b>'.$url.'</font>');
                    354: 
                    355: 	# option to display problem, only once else it cause problems with the form later 
                    356: 	# since the problem has a form.
                    357: 	if ($ENV{'form.vProb'} eq 'yes') {
                    358: 	    my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
                    359: 							      $ENV{'request.course.id'});
                    360: 	    my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
                    361: 								   $ENV{'request.course.id'});
                    362: 	    my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
                    363: 	    $result.='<table border="0" width="100%"><tr><td bgcolor="#e6ffff">';
                    364: 	    $result.='<b>Student\'s view of the problem</b></td></tr><tr><td bgcolor="#ffffff">'.$rendered.'<br />';
                    365: 	    $result.='<b>Correct answer:</b><br />'.$companswer;
                    366: 	    $result.='</td></tr></table>';
                    367: 	    $result.='</td></tr></table><br />';
                    368: 	    $request->print($result);
                    369: 	}
                    370: 	
                    371: 	# kwclr is the only variable that is guaranteed to be non blank if this subroutine has been called once.
                    372: 	my %keyhash = ();
                    373: 	if ($ENV{'form.kwclr'} eq '') {
                    374: 	    %keyhash = &Apache::lonnet::dump('nohist_handgrade',
                    375: 					     $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    376: 					     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    377: 
                    378: 	    my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
                    379: 	    $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
                    380: 	    $ENV{'form.kwclr'}    = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
                    381: 	    $ENV{'form.kwsize'}   = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
                    382: 	    $ENV{'form.kwstyle'}  = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
                    383: 	    $ENV{'form.msgsub'}   = $keyhash{$symb.'_subject'} ne '' ? 
                    384: 		$keyhash{$symb.'_subject'} : &Apache::lonnet::metadata($url,'title');
                    385: 	    $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.38      ng        386: 
1.41      ng        387: 	}
                    388: 	$request->print('<form action="/adm/grades" method="post" name="SCORE">'."\n".
                    389: 			'<input type="hidden" name="command"    value="handgrade" />'."\n".
                    390: 			'<input type="hidden" name="refresh"    value="off" />'."\n".
                    391: 			'<input type="hidden" name="symb"       value="'.$symb.'" />'."\n".
                    392: 			'<input type="hidden" name="url"        value="'.$url.'" />'."\n".
                    393: 			'<input type="hidden" name="showgrading" value="'.$ENV{'form.showgrading'}.'" />'."\n".
                    394: 			'<input type="hidden" name="vProb"      value="'.$ENV{'form.vProb'}.'" />'."\n".
                    395: 			'<input type="hidden" name="lastSub"    value="'.$ENV{'form.lastSub'}.'" />'."\n".
                    396: 			'<input type="hidden" name="section"    value="'.$ENV{'form.section'}.'">'."\n".
                    397: 			'<input type="hidden" name="submitonly" value="'.$ENV{'form.submitonly'}.'">'."\n".
                    398: 			'<input type="hidden" name="response"   value="'.$ENV{'form.response'}.'">'."\n".
                    399: 			'<input type="hidden" name="handgrade"  value="'.$ENV{'form.handgrade'}.'">'."\n".
                    400: 			'<input type="hidden" name="keywords"   value="'.$ENV{'form.keywords'}.'" />'."\n".
                    401: 			'<input type="hidden" name="kwclr"      value="'.$ENV{'form.kwclr'}.'" />'."\n".
                    402: 			'<input type="hidden" name="kwsize"     value="'.$ENV{'form.kwsize'}.'" />'."\n".
                    403: 			'<input type="hidden" name="kwstyle"    value="'.$ENV{'form.kwstyle'}.'" />'."\n".
                    404: 			'<input type="hidden" name="msgsub"     value="'.$ENV{'form.msgsub'}.'" />'."\n".
                    405: 			'<input type="hidden" name="savemsgN"   value="'.$ENV{'form.savemsgN'}.'" />'."\n".
                    406: 			'<input type="hidden" name="NCT"'.
                    407: 			' value="'.($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : $total+1).'" />'."\n");
                    408: 	
                    409: 	my ($cts,$prnmsg) = (1,'');
                    410: 	while ($cts <= $ENV{'form.savemsgN'}) {
                    411: 	    $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
                    412: 		($keyhash{$symb.'_savemsg'.$cts} eq '' ? $ENV{'form.savemsg'.$cts} : $keyhash{$symb.'_savemsg'.$cts}).
                    413: 		'" />'."\n";
                    414: 	    $cts++;
                    415: 	}
                    416: 	$request->print($prnmsg);
1.32      ng        417: 
1.41      ng        418: 	if ($ENV{'form.handgrade'} eq 'yes' && $ENV{'form.showgrading'} eq 'yes') {
                    419: 	    $request->print(<<KEYWORDS);
1.38      ng        420: &nbsp;<b>Keyword Options:</b>&nbsp;
                    421: <a href="javascript:keywords(document.SCORE.keywords)"; TARGET=_self>List</a>&nbsp; &nbsp;
                    422: <a href="#" onMouseDown="javascript:getSel(); return false"
                    423:  CLASS="page">Paste Selection to List</a>&nbsp; &nbsp;
                    424: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
                    425: KEYWORDS
1.41      ng        426:         }
                    427:     }
                    428:     my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
                    429:     my ($partlist,$handgrade) = &response_type($url);
                    430: #    &print_hash($request,\%record);
                    431: 
                    432:     # Student info
                    433:     $request->print(($counter == 0 ? '' : '<br />'));
1.43    ! ng        434: #    my $fullname = ($ENV{'form.fullname'} ne '' ? $ENV{'form.fullname'} : &get_fullname($uname,$udom));
1.41      ng        435:     my $result='<table border="0" width=100%><tr><td bgcolor="#777777">'.
                    436: 	'<table border="0" width=100%><tr bgcolor="#ffffff"><td>';
                    437: 
1.43    ! ng        438:     $result.='<table border="0"><tr bgcolor="#ffffff"><td><b>Fullname: </b>'.$ENV{'form.fullname'}.
        !           439: #    $result.='<table border="0"><tr bgcolor="#ffffff"><td><b>Fullname: </b>'.$fullname.
1.41      ng        440: 	'</td><td>&nbsp; &nbsp;<b>Username: </b>'.$uname.
                    441: 	'</td><td>&nbsp; &nbsp;<b>Domain: </b>'.$udom.'</td></tr>';
                    442:     if ($ENV{'form.handgrade'} eq 'yes') {
                    443: 	my @col_list;
                    444: 	($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist('all','0');
                    445: 	for (keys (%$handgrade)) {
                    446: 	    my $ncol = &Apache::lonnet::EXT('resource.'.$_.'.maxcollaborators',$symb,$udom,$uname);
                    447: 	    if ($ncol > 0) {
                    448: 		s/\_/\./g;
                    449: 		if ($record{'resource.'.$_.'.collaborators'} ne '') {
                    450: 		    my (@collaborators) = split(/,?\s+/,$record{'resource.'.$_.'.collaborators'});
                    451: 		    my (@badcollaborators);
                    452: 		    if (scalar(@collaborators) != 0) {
                    453: 			$result.='<tr bgcolor="#ffffff"><td colspan=3><b>Collaborators: </b>';
                    454: 			foreach my $collaborator (@collaborators) {
                    455: 			    $collaborator = $collaborator =~ /\@|:/ ? 
                    456: 				(split(/@|:/,$collaborator))[0] : $collaborator;
                    457: 			    next if ($collaborator eq $uname);
                    458: 			    if (!grep /^$collaborator:/i,keys %$classlist) {
                    459: 				push @badcollaborators,$collaborator;
                    460: 				next;
                    461: 			    }
                    462: 			    push @col_list, $collaborator;
                    463: 			    $result.=$$fullname{$collaborator.':'.$udom}.' ('.$collaborator.') &nbsp; &nbsp;';
                    464: 			}
                    465: 			$result.='</td></tr>'."\n";
                    466: 			$result.='<tr bgcolor="#ffbbbb"><td colspan=2>'.
                    467: 			    'This student has submitted '.(scalar (@badcollaborators) > 1 ? '' : 'an').
                    468: 			    ' invalid collaborator'.(scalar (@badcollaborators) > 1 ? 's. ' : '. ').
                    469: 			    (join ', ',@badcollaborators).'</td></tr>' 
                    470: 			    if (scalar(@badcollaborators) > 0);
                    471: 
                    472: 			$result.='<tr bgcolor="#ffbbbb"><td colspan=2>'.
                    473: 			    'This student has submitted too many collaborators. Maximum is '.
                    474: 			    $ncol.'.</td></tr>' if (scalar(@collaborators) > $ncol);
                    475: 			$result.='<input type="hidden" name="collaborator'.$counter.
                    476: 			    '" value="'.(join ':',@col_list).'" />'."\n";
                    477: 		    }
                    478: 		}
                    479: 	    }
                    480: 	}
                    481:     }
                    482:     $request->print($result.'</table>'."\n");
1.33      ng        483: 
1.41      ng        484:     # print student answer
                    485:     if ($ENV{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
                    486: 	if ($ENV{'form.'.$uname.':'.$udom.':submitted_by'}) {
                    487: 	    my $submitby='</td></tr><tr><td bgcolor="#e6ffff">'.
                    488: 		'<b>Collaborative submission by: </b>'.
                    489: 		'<a href="javascript:viewSubmitter(\''.$ENV{'form.'.$uname.':'.$udom.':submitted_by'}.
                    490: 		'\')"; TARGET=_self>'.
                    491: 		$$fullname{$ENV{'form.'.$uname.':'.$udom.':submitted_by'}}.'</a>';
                    492: 	    $submitby.='</td></tr><tr><td bgcolor="#ffffff">'."\n";
                    493: 	    $request->print($submitby);
                    494: 	} else {
                    495: 	    my ($string,$timestamp)=&get_last_submission ($symb,$uname,$udom,$ENV{'request.course.id'});
                    496: 	    my $lastsubonly.='</td></tr><tr><td bgcolor="#e6ffff"><b>Last Submission Only</b>'.
                    497: 		($$timestamp eq '' ? '' : '&nbsp; &nbsp; <b>Date Submitted:</b> '.$$timestamp).'</td></tr>';
                    498: 	    if ($$timestamp eq '') {
                    499: 		$lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0].'</td></tr>';
                    500: 	    } else {
                    501: 		for my $part (sort keys(%$handgrade)) {
                    502: 		    foreach (@$string) {
                    503: 			my ($partid,$respid) = /^resource\.(\d+)\.(\d+)\.submission/;
                    504: 			if ($part eq ($partid.'_'.$respid)) {
                    505: 			    my ($ressub,$subval) = split(/:/,$_,2);
                    506: 			    $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part ID</b> '.
                    507: 				$partid.' <b>Response ID</b> '.$respid.
                    508: 				' <b>Submission</b> '.&keywords_highlight($subval).'</td></tr>'
                    509: 				if ($ENV{'form.lastSub'} eq 'lastonly' || 
                    510: 				    ($ENV{'form.lastSub'} eq 'hdgrade' && $$handgrade{$part} =~ /:yes$/));
                    511: 			}
                    512: 		    }
                    513: 		}
                    514: 	    }
                    515: 	    $lastsubonly.='</td></tr><tr><td bgcolor="#ffffff">'."\n";
                    516: 	    $request->print($lastsubonly);
                    517: 	}
                    518:     } else {
                    519: 	$request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
                    520: 								 $ENV{'request.course.id'},$last,
                    521: 								 '.submission','Apache::grades::keywords_highlight'));
                    522:     }
                    523:     
                    524:     # view submission with no grading option
                    525:     if ($ENV{'form.showgrading'} eq '') {
                    526: 	$request->print('</td></tr></table></td></tr></table></form>');
                    527: 	return;
                    528:     }
1.33      ng        529: 
1.41      ng        530:     $result='<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n".
                    531: 	'<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
                    532: 	'<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'.$udom.'" />'."\n";
                    533:     $result.='&nbsp;<a href="javascript:msgCenter(document.SCORE,'.$counter.
                    534: 	',\''.$fullname.'\')"; TARGET=_self>Compose Message</a><br />'."\n" if ($ENV{'form.handgrade'} eq 'yes');
                    535:     $request->print($result);
                    536: 
                    537:     my %seen = ();
                    538:     my @partlist;
                    539:     for (sort keys(%$handgrade)) {
                    540: 	my ($partid,$respid) = split(/_/);
                    541: 	next if ($seen{$partid} > 0);
                    542: 	$seen{$partid}++;
                    543: 	next if ($$handgrade{$_} =~ /:no$/);
                    544: 	push @partlist,$partid;
                    545: 	my $wgt    = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
                    546: 	my $wgtmsg = ($wgt > 0 ? '(problem weight)' : '<font color="red">problem weight assigned by computer</font>');
                    547: 	$wgt       = ($wgt > 0 ? $wgt : '1');
                    548: 	my $score  = ($record{'resource.'.$partid.'.awarded'} eq '' ?
                    549: 		      '' : $record{'resource.'.$partid.'.awarded'}*$wgt);
                    550: 
                    551: 	# display grading options
                    552: 	$result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />';
                    553: 	$result.='<table border="0"><tr><td><b>Part </b>'.$partid.' <b>Points</b></td><td>';
                    554: 
                    555: 	my $ctr = 0;
                    556: 	$result.='<table border="0"><tr>';  # display radio buttons in a nice table 10 across
                    557: 	while ($ctr<=$wgt) {
                    558: 	    $result.= '<td><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.43    ! ng        559: 		'onclick="javascript:writeBox(this.form.GD_BOX'.$counter.'_'.$partid.
        !           560: 		',this.form.GD_SEL'.$counter.'_'.$partid.','.$ctr.
1.41      ng        561: 		',this.form.stores'.$counter.'_'.$partid.')" '.
                    562: 		($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
                    563: 	    $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
                    564: 	    $ctr++;
                    565: 	}
                    566: 	$result.='</tr></table>';
1.39      ng        567: 
1.41      ng        568: 	$result.='</td><td>&nbsp;<b>or</b>&nbsp;</td>';
1.43    ! ng        569: 	$result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.41      ng        570: 	    ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
                    571: 	    'onChange="javascript:updateRadio(this.form.RADVAL'.$counter.'_'.$partid.
1.43    ! ng        572: 	    ',this.form.GD_BOX'.$counter.'_'.$partid.
        !           573: 	    ',this.form.GD_SEL'.$counter.'_'.$partid.
1.41      ng        574: 	    ',this.form.stores'.$counter.'_'.$partid.')" /></td>'."\n";
                    575: 	$result.='<td>/'.$wgt.' '.$wgtmsg.' </td><td>';
                    576: 
1.43    ! ng        577: 	$result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.41      ng        578: 	    'onChange="javascript:clearRadBox(this.form.RADVAL'.$counter.'_'.$partid.
1.43    ! ng        579: 	    ',this.form.GD_BOX'.$counter.'_'.$partid.
        !           580: 	    ',this.form.GD_SEL'.$counter.'_'.$partid.
1.41      ng        581: 	    ',this.form.stores'.$counter.'_'.$partid.')" />'."\n".
                    582: 	    '<option selected="on"> </option>'.
                    583: 	    '<option>excused</option></select>'."&nbsp&nbsp\n";
                    584: 	$result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="0" />';
                    585: 	$result.='</td></tr></table>';
                    586: 	$request->print($result);
                    587:     }
                    588:     $request->print('<input type="hidden" name="partlist'.$counter.'" value="'.(join ":",@partlist).'" />'."\n");
                    589:     $request->print('</td></tr></table></td></tr></table>'."\n");
                    590: 
                    591:     # print end of form
                    592:     if ($counter == $total) {
                    593: 	my $endform.='<table border="0"><tr><td><input type="submit" name="gradeOpt" value="Save & Next" />';
                    594: 	my $ntstu ='<select name="NTSTU">'.
                    595: 	    '<option>1</option><option>2</option>'.
                    596: 	    '<option>3</option><option>5</option>'.
                    597: 	    '<option>7</option><option>10</option></select>'."\n";
                    598: 	my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
                    599: 	$ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
                    600: 	$endform.=$ntstu.'student(s) &nbsp;&nbsp;'.
                    601: 	    '<input type="submit" name="gradeOpt" value="Next" />&nbsp'.
                    602: 	    '<input type="submit" name="gradeOpt" value="Previous" />&nbsp'.
                    603: 	    '(Next and Previous do not save the scores.)'.
                    604: 	    '</td><tr></table></form>';
                    605: 	$request->print($endform);
                    606:     }
                    607:     return '';
1.38      ng        608: }
                    609: 
                    610: sub get_last_submission {
1.41      ng        611:     my ($symb,$username,$domain,$course)=@_;
                    612:     if ($symb) {
                    613: 	my (@string,$timestamp);
                    614: 	my (%returnhash)=&Apache::lonnet::restore($symb,$course,$domain,$username);
                    615: 	if ($returnhash{'version'}) {
                    616: 	    my %lasthash=();
                    617: 	    my ($version);
                    618: 	    for ($version=1;$version<=$returnhash{'version'};$version++) {
                    619: 		foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                    620: 		    $lasthash{$_}=$returnhash{$version.':'.$_};
                    621: 		}
                    622: 	    }
                    623: 	    foreach ((keys %lasthash)) {
                    624: 		if ($_ =~ /\.submission$/) {push @string, (join(':',$_,$lasthash{$_}))}
                    625: 		if ($_ =~ /timestamp/) {$timestamp = scalar(localtime($lasthash{$_}))};
                    626: 	    }
                    627: 	}
                    628: 	@string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string;
                    629: 	return \@string,\$timestamp;
                    630:     }
1.38      ng        631: }
1.35      ng        632: 
1.38      ng        633: sub keywords_highlight {
1.41      ng        634:     my $string  = shift;
                    635:     my $size    = $ENV{'form.kwsize'} eq '0' ? '' : 'size='.$ENV{'form.kwsize'};
                    636:     my $styleon = $ENV{'form.kwstyle'} eq ''  ? '' : $ENV{'form.kwstyle'};
                    637:     (my $styleoff = $styleon) =~ s/\</\<\//;
                    638:     my @keylist = split(/[,\s+]/,$ENV{'form.keywords'});
                    639:     foreach (@keylist) {
                    640: 	$string =~ s/\b$_(\b|\.)/\<font color\=$ENV{'form.kwclr'} $size\>$styleon$_$styleoff\<\/font\>/gi;
                    641:     }
                    642:     return $string;
1.38      ng        643: }
1.36      ng        644: 
1.38      ng        645: sub processHandGrade {
1.41      ng        646:     my ($request) = shift;
                    647:     my $url    = $ENV{'form.url'};
                    648:     my $symb   = $ENV{'form.symb'};
                    649:     my $button = $ENV{'form.gradeOpt'};
                    650:     my $ngrade = $ENV{'form.NCT'};
                    651:     my $ntstu  = $ENV{'form.NTSTU'};
                    652: 
                    653:     my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
                    654:     my %keyhash = ();
                    655:     $ENV{'form.keywords'}           =~ s/,\s{0,}|\s+/ /g;
                    656:     $ENV{'form.keywords'}           =~ s/^\s+|\s+$//;
                    657:     $keyhash{$symb.'_keywords'}     = $ENV{'form.keywords'};
                    658:     $keyhash{$symb.'_subject'}      = $ENV{'form.msgsub'};
                    659:     $keyhash{$loginuser.'_kwclr'}   = $ENV{'form.kwclr'};
                    660:     $keyhash{$loginuser.'_kwsize'}  = $ENV{'form.kwsize'};
                    661:     $keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
                    662: 
                    663:     my ($ctr,$idx) = (1,1);
                    664:     while ($ctr <= $ENV{'form.savemsgN'}) {
                    665: 	if ($ENV{'form.savemsg'.$ctr} ne '') {
                    666: 	    $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
                    667: 	    $idx++;
                    668: 	}
                    669: 	$ctr++;
                    670:     }
                    671:     $ctr = 0;
                    672:     while ($ctr < $ngrade) {
                    673: 	if ($ENV{'form.newmsg'.$ctr} ne '') {
                    674: 	    $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
                    675: 	    $ENV{'form.savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
                    676: 	    $idx++;
                    677: 	}
                    678: 	$ctr++;
                    679:     }
                    680:     $ENV{'form.savemsgN'} = --$idx;
                    681:     $keyhash{$symb.'_savemsgN'} = $ENV{'form.savemsgN'};
                    682:     my $putresult = &Apache::lonnet::put
                    683: 	('nohist_handgrade',\%keyhash,
                    684: 	 $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    685: 	 $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    686: 
                    687:     if ($ENV{'form.refresh'} eq 'on') {
                    688: 	my $ctr = 0;
                    689: 	$ENV{'form.NTSTU'}=$ngrade;
                    690: 	while ($ctr < $ngrade) {
                    691: 	    ($ENV{'form.student'},my $udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
                    692: 	    &submission($request,$ctr,$ngrade-1);
                    693: 	    $ctr++;
                    694: 	}
                    695: 	return '';
                    696:     }
1.36      ng        697: 
1.41      ng        698:     if ($button eq 'Save & Next') {
                    699: 	my $ctr = 0;
                    700: 	while ($ctr < $ngrade) {
                    701: 	    my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
                    702: 	    my ($errorflg) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
                    703: 	    return '' if ($errorflg eq 'error');
                    704: 
                    705: 	    my $includemsg = $ENV{'form.includemsg'.$ctr};
                    706: 	    my ($subject,$message,$msgstatus) = ('','','');
                    707: 	    if ($includemsg =~ /savemsg|new$ctr/) {
                    708: 		$subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/);
                    709: 		my (@msgnum) = split(/,/,$includemsg);
                    710: 		foreach (@msgnum) {
                    711: 		    $message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
                    712: 		}
                    713: 		$message =~ s/\s+/ /g;
                    714: 		$msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
                    715: 							       $ENV{'form.msgsub'},$message);
                    716: 	    }
                    717: 	    if ($ENV{'form.collaborator'.$ctr}) {
                    718: 		my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
                    719: 		foreach (@collaborators) {
                    720: 		    &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,
                    721: 				   $ENV{'form.unamedom'.$ctr});
                    722: 		    if ($message ne '') {
                    723: 			$msgstatus = &Apache::lonmsg::user_normal_msg ($_,$udom,
                    724: 								       $ENV{'form.msgsub'},
                    725: 								       $message);
                    726: 		    }
                    727: 		}
                    728: 	    }
                    729: 	    $ctr++;
                    730: 	}
                    731:     }
                    732:     my $firststu = $ENV{'form.unamedom0'};
                    733:     my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
                    734:     $ctr = 2;
                    735:     while ($laststu eq '') {
                    736: 	$laststu  = $ENV{'form.unamedom'.($ngrade-$ctr)};
                    737: 	$ctr++;
                    738: 	$laststu = $firststu if ($ctr > $ngrade);
                    739:     }
                    740:     my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($ENV{'form.section'},'0');
                    741: 
                    742:     my (@parsedlist,@nextlist);
                    743:     my ($nextflg) = 0;
                    744:     foreach ( sort(@{ $$classlist{$ENV{'form.section'}} }) ) {
                    745: 	if ($nextflg == 1 && $button =~ /Next$/) {
                    746: 	    push @parsedlist,$_;
                    747: 	}
                    748: 	$nextflg = 1 if ($_ eq $laststu);
                    749: 	if ($button eq 'Previous') {
                    750: 	    last if ($_ eq $firststu);
                    751: 	    push @parsedlist,$_;
                    752: 	}
                    753:     }
                    754:     $ctr = 0;
                    755:     my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
                    756:     @parsedlist = reverse @parsedlist if ($button eq 'Previous');
                    757:     foreach my $student (@parsedlist) {
                    758: 	my ($uname,$udom) = split(/:/,$student);
                    759: 	if ($ENV{'form.submitonly'} eq 'yes') {
                    760: 	    my (%status) = &student_gradeStatus($ENV{'form.url'},$udom,$uname,$partlist) ;
                    761: 	    my $statusflg = '';
                    762: 	    foreach (keys(%status)) {
                    763: 		$statusflg = 1 if ($status{$_} ne 'nothing');
1.43    ! ng        764: 		my ($foo,$partid,$foo1) = split(/\./,$_);
1.41      ng        765: 		$statusflg = '' if ($status{'resource.'.$partid.'.submitted_by'} ne '');
                    766: 	    }
                    767: 	    next if ($statusflg eq '');
                    768: 	}
                    769: 	push @nextlist,$student if ($ctr < $ntstu);
                    770: 	$ctr++;
                    771:     }
1.36      ng        772: 
1.41      ng        773:     $ctr = 0;
                    774:     my $total = scalar(@nextlist)-1;
1.39      ng        775: 
1.41      ng        776:     foreach (sort @nextlist) {
                    777: 	my ($uname,$udom,$submitter) = split(/:/);
                    778: 	$ENV{'form.student'} = $uname;
                    779: 	$ENV{'form.fullname'} = $$fullname{$_};
                    780: #	$ENV{'form.'.$_.':submitted_by'} = $submitter;
                    781: #	print "submitter=$ENV{'form.'.$_.':submitted_by'}= $submitter:<br>";
                    782: 	&submission($request,$ctr,$total);
                    783: 	$ctr++;
                    784:     }
                    785:     if ($total < 0) {
                    786: 	my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
                    787: 	$the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
                    788: 	$the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
                    789: 	$the_end.=&show_grading_menu_form ($symb,$url);
                    790: 	$request->print($the_end);
                    791:     }
                    792:     return '';
1.38      ng        793: }
1.36      ng        794: 
1.38      ng        795: sub saveHandGrade {
1.41      ng        796:     my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter) = @_;
                    797: #   my %record=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
                    798:     my %newrecord;
                    799:     foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
1.43    ! ng        800: 	if ($ENV{'form.GD_SEL'.$newflg.'_'.$_} eq 'excused') {
1.41      ng        801: 	    $newrecord{'resource.'.$_.'.solved'} = 'excused';
                    802: 	} else {
1.43    ! ng        803: 	    my $pts    = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ? 
        !           804: 			  $ENV{'form.GD_BOX'.$newflg.'_'.$_} : $ENV{'form.RADVAL'.$newflg.'_'.$_});
1.41      ng        805: 	    if ($pts eq '') {
                    806: 		&userError($request,'No point was assigned for part id '.$_.' and for username '.$stuname.'.');
                    807: 		return 'error';
                    808: 	    }
                    809: 	    my $wgt    = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 : $ENV{'form.WGT'.$newflg.'_'.$_};
                    810: 	    my $partial= $pts/$wgt;
                    811: 	    $newrecord{'resource.'.$_.'.awarded'}  = $partial;
                    812: 	    if ($partial == 0) {
                    813: 		$newrecord{'resource.'.$_.'.solved'} = 'incorrect_by_override';
                    814: 	    } else {
                    815: 		$newrecord{'resource.'.$_.'.solved'} = 'correct_by_override';
                    816: 	    }
                    817: 	    $newrecord{'resource.'.$_.'.submitted_by'} = $submitter if ($submitter);
                    818: 	}
                    819:     }
                    820:     
                    821:     if ( scalar(keys(%newrecord)) > 0 ) {
                    822: 	$newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
                    823: #	&print_hash($request,\%newrecord);
                    824: 	&Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},$domain,$stuname);
                    825:     }
                    826:     return '';
1.36      ng        827: }
1.38      ng        828: 
                    829: sub get_symb_and_url {
1.41      ng        830:     my ($request) = @_;
                    831:     (my $url=$ENV{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
                    832:     my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
                    833:     if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
                    834:     return ($symb,$url);
1.36      ng        835: }
                    836: 
1.38      ng        837: sub show_grading_menu_form {
1.41      ng        838:     my ($symb,$url)=@_;
                    839:     my $result.='<form action="/adm/grades" method="post">'."\n".
                    840: 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
                    841: 	'<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.38      ng        842: 	'<input type="hidden" name="command" value="gradingmenu" />'."\n".
1.41      ng        843: 	'<input type="submit" name="submit" value="Grading Menu" />'."\n".
                    844: 	'</form>'."\n";
                    845:     return $result;
1.36      ng        846: }
                    847: 
1.38      ng        848: sub gradingmenu {
1.41      ng        849:     my ($request) = @_;
                    850:     my ($symb,$url)=&get_symb_and_url($request);
                    851:     if (!$symb) {return '';}
                    852:     my $result='<h2>&nbsp;<font color="#339933">Select a Grading Method</font></h2>';
                    853:     $result.='<table border="0">';
                    854:     $result.='<tr><td colspan=3><font size=+1><b>Resource: </b>'.$url.'</font></td></tr>';
                    855:     my ($partlist,$handgrade) = &response_type($url);
                    856:     my ($resptype,$hdgrade)=('','no');
                    857:     for (sort keys(%$handgrade)) {
                    858: 	my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
                    859: 	$resptype = $responsetype;
                    860: 	$hdgrade = $handgrade if ($handgrade eq 'yes');
1.43    ! ng        861: 	$result.='<tr><td><b>Part ID: </b>'.(split(/_/))[0].'</td>'.
1.41      ng        862: 	    '<td><b>Type: </b>'.$responsetype.'</td>'.
                    863: 	    '<td><b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
                    864:     }
                    865:     $result.='</table>';
                    866:     $result.=&view_edit_entire_class_form($symb,$url).'<br />';
                    867:     $result.=&upcsvScores_form($symb,$url).'<br />';
                    868:     $result.=&viewGradeaStu_form($symb,$url,$resptype,$hdgrade).'<br />';
                    869:     $result.=&verifyReceipt_form($symb,$url).'<br />';
                    870:     $result.=&view_classlist_form($symb,$url);
1.39      ng        871: 
1.41      ng        872:     return $result;
1.39      ng        873: }
                    874: 
                    875: sub view_classlist_form {
1.41      ng        876:     my ($symb,$url)=@_;
                    877:     my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
                    878:     $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
                    879:     $result.='&nbsp;<b>View Class List</b></td></tr>'."\n";
                    880:     $result.='<tr bgcolor=#ffffe6><td>'."\n";
                    881:     $result.='<form action="/adm/grades" method="post">'."\n".
                    882: 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
                    883: 	'<input type="hidden" name="url" value="'.$url.'" />'."\n".
                    884: 	'<input type="hidden" name="command" value="viewclasslist" />'."\n";
                    885:     $result.='&nbsp;<input type="submit" name="submit" value="View Class" /></form>'."\n";
                    886:     $result.='</td></tr></table>'."\n";
                    887:     $result.='</td></tr></table>'."\n";
                    888:     return $result;
1.36      ng        889: }
                    890: 
1.39      ng        891: sub viewclasslist {
1.41      ng        892:     my ($request) = shift;
                    893:     my ($coursedomain,$coursenum) = split(/_/,$ENV{'request.course.id'});
                    894:     my %classlist=&Apache::lonnet::dump('classlist',$coursedomain,$coursenum);
                    895:     $request->print('<table border=1>');
                    896:     foreach (sort keys(%classlist)) {
1.39      ng        897: #    my ($unam,$udom) = split(/:/,$_,2);
                    898: #    my $section = &Apache::lonnet::usection($udom,$unam,$ENV{'request.course.id'});
                    899: #    my $fullname = &get_fullname ($unam,$udom);
                    900: #    my @uname;
                    901: #    $uname[0]=$unam;
                    902: #    my %userid=&Apache::lonnet::idrget($udom,@uname);
                    903: #    my $value=$classlist{$_}.':'.$userid{$unam}.':'.$section.':'.$fullname;
                    904: #    $classlist{$_}=$value;
1.41      ng        905: 	$request->print('<tr><td>'.$_.' </td><td><pre> '.$classlist{$_}.'</pre></td></tr>');
                    906:     }
                    907:     $request->print('</table>');
1.39      ng        908: #  my $putresult = &Apache::lonnet::put
                    909: #      ('classlist',\%classlist,
                    910: #       $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    911: #       $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    912: 
1.41      ng        913:     return '';
1.39      ng        914: }
                    915: 
1.38      ng        916: sub view_edit_entire_class_form {
1.41      ng        917:     my ($symb,$url)=@_;
                    918:     my ($classlist,$sections) = &getclasslist('all','0');
                    919:     my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
                    920:     $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
                    921:     $result.='&nbsp;<b>View/Grade Entire Section/Class</b></td></tr>'."\n";
                    922:     $result.='<tr bgcolor=#ffffe6><td>'."\n";
                    923:     $result.='<form action="/adm/grades" method="post">'."\n".
                    924: 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
                    925: 	'<input type="hidden" name="url" value="'.$url.'" />'."\n".
                    926: 	'<input type="hidden" name="command" value="viewgrades" />'."\n";
                    927:     $result.='&nbsp;<b>Select section:</b> <select name="section">'."\n";
                    928:     foreach (sort (@$sections)) {
                    929: 	$result.= '<option>'.$_.'</option>'."\n";
                    930:     }
1.43    ! ng        931:     $result.='<option selected="on">all</select>'."<br />\n";
1.41      ng        932:     $result.='&nbsp;<input type="submit" name="submit" value="View/Grade" /></form>'."\n";
                    933:     $result.='</td></tr></table>'."\n";
                    934:     $result.='</td></tr></table>'."\n";
                    935:     return $result;
1.36      ng        936: }
                    937: 
1.38      ng        938: sub upcsvScores_form {
1.41      ng        939:     my ($symb,$url) = @_;
                    940:     if (!$symb) {return '';}
                    941:     my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
                    942:     $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
                    943:     $result.='&nbsp;<b>Specify a file containing the class scores for above resource</b></td></tr>'."\n";
                    944:     $result.='<tr bgcolor=#ffffe6><td>'."\n";
                    945:     my $upfile_select=&Apache::loncommon::upfile_select_html();
1.38      ng        946:   $result.=<<ENDUPFORM;
                    947: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
                    948: <input type="hidden" name="symb" value="$symb" />
                    949: <input type="hidden" name="url" value="$url" />
                    950: <input type="hidden" name="command" value="csvuploadmap" />
                    951: $upfile_select
                    952: <br />&nbsp;<input type="submit" name="submit" value="Upload Grades" />
                    953: </form>
                    954: ENDUPFORM
1.41      ng        955:     $result.='</td></tr></table>'."\n";
                    956:     $result.='</td></tr></table>'."\n";
                    957:     return $result;
1.38      ng        958: }
                    959: 
                    960: sub viewGradeaStu_form {
1.41      ng        961:     my ($symb,$url,$response,$handgrade) = @_;
                    962:     my ($classlist,$sections) = &getclasslist('all','0');
                    963:     my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
                    964:     $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
                    965:     $result.='&nbsp;<b>View/Grade an Individual Student\'s Submission</b></td></tr>'."\n";
                    966:     $result.='<tr bgcolor=#ffffe6><td>'."\n";
                    967:     $result.='<form action="/adm/grades" method="post">'."\n".
                    968: 	'<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
                    969: 	'<input type="hidden" name="url" value="'.$url.'" />'."\n".
                    970: 	'<input type="hidden" name="response" value="'.$response.'" />'."\n".
                    971: 	'<input type="hidden" name="handgrade" value="'.$handgrade.'" />'."\n".
                    972: 	'<input type="hidden" name="showgrading" value="yes" />'."\n".
                    973: 	'<input type="hidden" name="command" value="submission" />'."\n";
                    974: 
                    975:     $result.='&nbsp;<b>Select section:</b> <select name="section">'."\n";
                    976:     foreach (sort (@$sections)) {
                    977: 	$result.= '<option>'.$_.'</option>'."\n";
                    978:     }
                    979:     $result.= '<option selected="on">all</select>'."\n";
                    980:     $result.='&nbsp;&nbsp;<b>Display students who has: </b>'.
                    981: 	'<input type="radio" name="submitonly" value="yes" checked> submitted'.
                    982: 	'<input type="radio" name="submitonly" value="all"> everybody <br />';
                    983:     $result.='&nbsp;(Section "no" implies the students were not assigned a section.)<br />' 
                    984: 	if (grep /no/,@$sections);
                    985:     
                    986:     $result.='<br />&nbsp;<input type="submit" name="submit" value="View/Grade" />'."\n".
                    987: 	'</form>'."\n";
                    988:     $result.='</td></tr></table>'."\n";
                    989:     $result.='</td></tr></table>'."\n";
                    990:     return $result;
1.36      ng        991: }
                    992: 
1.38      ng        993: sub verifyReceipt_form {
1.41      ng        994:     my ($symb,$url) = @_;
                    995:     my $cdom=$ENV{"course.$ENV{'request.course.id'}.domain"};
                    996:     my $cnum=$ENV{"course.$ENV{'request.course.id'}.num"};
                    997:     my $hostver=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'});
                    998: 
                    999:     my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
                   1000:     $result.='<table width=100% border=0><tr><td bgcolor=#e6ffff>'."\n";
                   1001:     $result.='&nbsp;<b>Verify a Submission Receipt Issued by this Server</td></tr>'."\n";
                   1002:     $result.='<tr bgcolor=#ffffe6><td>'."\n";
                   1003:     $result.='<form action="/adm/grades" method="post">'."\n";
                   1004:     $result.='&nbsp;<tt>'.$hostver.'-<input type="text" name="receipt" size="4"></tt><br />'."\n";
                   1005:     $result.='&nbsp;<input type="submit" name="submit" value="Verify Receipt">'."\n";
                   1006:     $result.='<input type="hidden" name="command" value="verify">'."\n";
                   1007:     if ($ENV{'form.url'}) {
                   1008: 	$result.='<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />';
                   1009:     }
                   1010:     if ($ENV{'form.symb'}) {
                   1011: 	$result.='<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />';
                   1012:     }
                   1013:     $result.='</form>';
                   1014:     $result.='</td></tr></table>'."\n";
                   1015:     $result.='</td></tr></table>'."\n";
                   1016:     return $result;
1.36      ng       1017: }
                   1018: 
1.42      ng       1019: sub viewgrades_js {
                   1020:     my ($request) = shift;
                   1021: 
1.41      ng       1022:     $request->print(<<VIEWJAVASCRIPT);
                   1023: <script type="text/javascript" language="javascript">
                   1024:     function viewOneStudent(user) {
                   1025: 	document.onestudent.student.value = user;
                   1026: 	document.onestudent.submit();
                   1027:     }
                   1028: 
1.42      ng       1029:     function writePoint(partid,weight,point) {
                   1030: 	var radioButton = eval("document.classgrade.RADVAL_"+partid);
                   1031: 	var textbox = eval("document.classgrade.TEXTVAL_"+partid);
                   1032: 	if (point == "textval") {
                   1033: 	    var point = eval("document.classgrade.TEXTVAL_"+partid+".value");
                   1034: 	    if (isNaN(point) || point < 0) {
                   1035: 		alert("A number equal or greater than 0 is expected. Entered value = "+point);
                   1036: 		var resetbox = false;
                   1037: 		for (var i=0; i<radioButton.length; i++) {
                   1038: 		    if (radioButton[i].checked) {
                   1039: 			textbox.value = i;
                   1040: 			resetbox = true;
                   1041: 		    }
                   1042: 		}
                   1043: 		if (!resetbox) {
                   1044: 		    textbox.value = "";
                   1045: 		}
                   1046: 		return;
                   1047: 	    }
                   1048: 	    for (var i=0; i<radioButton.length; i++) {
                   1049: 		radioButton[i].checked=false;
                   1050: 		if (point == i) {
                   1051: 		    radioButton[i].checked=true;
                   1052: 		}
                   1053: 	    }
1.41      ng       1054: 
1.42      ng       1055: 	} else {
                   1056: 	    textbox.value = point;
                   1057: 	}
1.41      ng       1058: 	for (i=0;i<document.classgrade.total.value;i++) {
1.43    ! ng       1059: 	    var user = eval("document.classgrade.ctr"+i+".value");
        !          1060: 	    var scorename = eval("document.classgrade.GD_"+user+
        !          1061: 				 "_"+partid+"_aw");
        !          1062: 	    var saveval   = eval("document.classgrade.GD_"+user+
        !          1063: 				 "_"+partid+"_sv_s.value");
        !          1064: 	    var selname   = eval("document.classgrade.GD_"+user+"_"+partid+"_sv");
1.42      ng       1065: 	    if (saveval != "correct") {
                   1066: 		scorename.value = point;
1.43    ! ng       1067: 		if (selname[0].selected != true) {
        !          1068: 		    selname[0].selected = true;
        !          1069: 		}
1.42      ng       1070: 	    }
                   1071: 	}
                   1072: 	var selval   = eval("document.classgrade.SELVAL_"+partid);
                   1073: 	selval[0].selected = true;
                   1074:     }
                   1075: 
                   1076:     function writeRadText(partid,weight) {
                   1077: 	var selval   = eval("document.classgrade.SELVAL_"+partid);
1.43    ! ng       1078: 	var radioButton = eval("document.classgrade.RADVAL_"+partid);
        !          1079: 	var textbox = eval("document.classgrade.TEXTVAL_"+partid);
1.42      ng       1080: 	if (selval[1].selected) {
                   1081: 	    for (var i=0; i<radioButton.length; i++) {
                   1082: 		radioButton[i].checked=false;
                   1083: 
                   1084: 	    }
                   1085: 	    textbox.value = "";
                   1086: 
                   1087: 	    for (i=0;i<document.classgrade.total.value;i++) {
1.43    ! ng       1088: 		var user = eval("document.classgrade.ctr"+i+".value");
        !          1089: 		var scorename = eval("document.classgrade.GD_"+user+
        !          1090: 				     "_"+partid+"_aw");
        !          1091: 		var saveval   = eval("document.classgrade.GD_"+user+
        !          1092: 				     "_"+partid+"_sv_s.value");
        !          1093: 		var selname   = eval("document.classgrade.GD_"+user+
        !          1094: 				     "_"+partid+"_sv");
1.42      ng       1095: 		if (saveval != "correct") {
                   1096: 		    scorename.value = "";
                   1097: 		    selname[1].selected = true;
                   1098: 		}
                   1099: 	    }
1.43    ! ng       1100: 	} else {
        !          1101: 	    for (i=0;i<document.classgrade.total.value;i++) {
        !          1102: 		var user = eval("document.classgrade.ctr"+i+".value");
        !          1103: 		var scorename = eval("document.classgrade.GD_"+user+
        !          1104: 				     "_"+partid+"_aw");
        !          1105: 		var saveval   = eval("document.classgrade.GD_"+user+
        !          1106: 				     "_"+partid+"_sv_s.value");
        !          1107: 		var selname   = eval("document.classgrade.GD_"+user+
        !          1108: 				     "_"+partid+"_sv");
        !          1109: 		if (saveval != "correct") {
        !          1110: 		    scorename.value = eval("document.classgrade.GD_"+user+
        !          1111: 				     "_"+partid+"_aw_s.value");;
        !          1112: 		    selname[0].selected = true;
        !          1113: 		}
        !          1114: 	    }
        !          1115: 	}	    
1.42      ng       1116:     }
                   1117: 
                   1118:     function changeSelect(partid,user) {
1.43    ! ng       1119: 	var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_sv");
1.42      ng       1120: 	selval[0].selected = true;
                   1121:     }
                   1122: 
                   1123:     function changeOneScore(partid,user) {
1.43    ! ng       1124: 	var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_sv");
1.42      ng       1125: 	if (selval[1].selected) {
1.43    ! ng       1126: 	    var boxval = eval("document.classgrade.GD_"+user+'_'+partid+"_aw");
1.42      ng       1127: 	    boxval.value = "";
                   1128: 	}
                   1129:     }
                   1130: 
                   1131:     function resetEntry(numpart) {
                   1132: 	for (ctpart=0;ctpart<numpart;ctpart++) {
                   1133: 	    var partid = eval("document.classgrade.partid_"+ctpart+".value");
                   1134: 	    var radioButton = eval("document.classgrade.RADVAL_"+partid);
                   1135: 	    var textbox = eval("document.classgrade.TEXTVAL_"+partid);
                   1136: 	    var selval  = eval("document.classgrade.SELVAL_"+partid);
                   1137: 	    for (var i=0; i<radioButton.length; i++) {
                   1138: 		radioButton[i].checked=false;
                   1139: 
                   1140: 	    }
                   1141: 	    textbox.value = "";
                   1142: 	    selval[0].selected = true;
                   1143: 
                   1144: 	    for (i=0;i<document.classgrade.total.value;i++) {
1.43    ! ng       1145: 		var user = eval("document.classgrade.ctr"+i+".value");
        !          1146: 		var resetscore = eval("document.classgrade.GD_"+user+
        !          1147: 				      "_"+partid+"_aw");
        !          1148: 		resetscore.value = eval("document.classgrade.GD_"+user+
        !          1149: 					"_"+partid+"_aw_s.value");
1.42      ng       1150: 
1.43    ! ng       1151: 		var saveselval   = eval("document.classgrade.GD_"+user+
        !          1152: 				     "_"+partid+"_sv_s.value");
1.42      ng       1153: 
1.43    ! ng       1154: 		var selname   = eval("document.classgrade.GD_"+user+"_"+partid+"_sv");
1.42      ng       1155: 		if (saveselval == "excused") {
1.43    ! ng       1156: 		    if (selname[1].selected == false) { selname[1].selected = true;}
1.42      ng       1157: 		} else {
1.43    ! ng       1158: 		    if (selname[0].selected == false) {selname[0].selected = true};
1.42      ng       1159: 		}
                   1160: 	    }
1.41      ng       1161: 	}
1.42      ng       1162:     }
                   1163: 
1.43    ! ng       1164:     function submitForm() {
        !          1165: 	document.classgrade.submit();
        !          1166:     }
1.42      ng       1167: 
1.41      ng       1168: </script>
                   1169: VIEWJAVASCRIPT
1.42      ng       1170: }
                   1171: 
                   1172: sub viewgrades {
                   1173:     my ($request) = shift;
                   1174:     &viewgrades_js($request);
1.41      ng       1175: 
                   1176:     my ($symb,$url) = ($ENV{'form.symb'},$ENV{'form.url'}); 
1.43    ! ng       1177:     my $result='<h2><font color="#339933">Manual Grading</font></h2>';
1.38      ng       1178: 
1.43    ! ng       1179:     $result.='<font size=+1><b>Resource: </b>'.$ENV{'form.url'}.'</font>'."\n";
1.41      ng       1180: 
                   1181:     #view individual student submission form - called using Javascript viewOneStudent
1.42      ng       1182:     $result.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.41      ng       1183: 	'<input type="hidden" name="symb"    value="'.$symb.'" />'."\n".
                   1184: 	'<input type="hidden" name="url"     value="'.$url.'" />'."\n".
                   1185: 	'<input type="hidden" name="command" value="submission" />'."\n".
                   1186: 	'<input type="hidden" name="student" value="" />'."\n".
                   1187: 	'</form>'."\n";
                   1188: 
                   1189:     #start the form
                   1190:     $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
                   1191: 	'<input type="hidden" name="symb"    value="'.$symb.'" />'."\n".
                   1192: 	'<input type="hidden" name="url"     value="'.$url.'" />'."\n".
1.38      ng       1193: 	'<input type="hidden" name="command" value="editgrades" />'."\n".
1.41      ng       1194: 	'<input type="hidden" name="section" value="'.$ENV{'form.section'}.'" />'."\n";
1.42      ng       1195: 
                   1196:     $result.='To assign the same score for all the students use the radio buttons or '.
                   1197: 	'text box below. To assign scores individually fill in the score boxes for '.
                   1198: 	'each student in the table below. <font color="red">A score that has already '.
                   1199: 	'been graded does not get changed using the radio buttons or text box. '.
                   1200: 	'If needed, it has to be changed individually.</font>';
                   1201: 
                   1202:     my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
                   1203:     my %weight = ();
                   1204:     my $ctsparts = 0;
1.41      ng       1205:     $result.='<table border="0">';
1.42      ng       1206:     for (sort keys(%$handgrade)) {
                   1207: 	my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
                   1208: 	my ($partid,$respid) = split (/_/);
                   1209: 	my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
                   1210: 	$weight{$partid} = $wgt eq '' ? '1' : $wgt;
                   1211: 
                   1212: 	$result.='<input type="hidden" name="partid_'.$ctsparts.'" value="'.$partid.'" />'."\n";
                   1213: 	$result.='<tr><td><b>Part ID:</b> '.$partid.'&nbsp; &nbsp;</td><td>';
                   1214: 	$result.='<table border="0"><tr>';  
1.41      ng       1215: 	my $ctr = 0;
1.42      ng       1216: 	while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
                   1217: 	    $result.= '<td><input type="radio" name="RADVAL_'.$partid.'" '.
                   1218: 		'onclick="javascript:writePoint('.$partid.','.$weight{$partid}.
1.41      ng       1219: 		','.$ctr.')" />'.$ctr."</td>\n";
                   1220: 	    $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
                   1221: 	    $ctr++;
                   1222: 	}
                   1223: 	$result.='</tr></table>';
1.42      ng       1224: 	$result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.$partid.'" size="4" '.
                   1225: 	    'onChange="javascript:writePoint('.$partid.','.$weight{$partid}.',\'textval\')" /> /'.
                   1226: 	    $weight{$partid}.' (problem weight)</td>'."\n";
                   1227: 	$result.= '</td><td><select name="SELVAL_'.$partid.'"'.
                   1228: 	    'onChange="javascript:writeRadText('.$partid.','.$weight{$partid}.')" /> '.
                   1229: 	    '<option selected="on"> </option>'.
                   1230: 	    '<option>excused</option></select></td></tr>'."\n";
                   1231: 	$ctsparts++;
1.41      ng       1232:     }
1.42      ng       1233:     $result.='</table><input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
                   1234:     $result.='<input type="button" value="Reset" '.
1.43    ! ng       1235: 	'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self> &nbsp; &nbsp;';
        !          1236: #    $result.='<input type="button" value="Submit Changes" '.
        !          1237: #	'onClick="document.classgrade.submit();" TARGET=_self />'."\n";
1.42      ng       1238:     $result.= '<input type="submit" name="submit"  value="Submit Changes" />'."\n";
1.41      ng       1239: 
1.42      ng       1240:     $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.41      ng       1241: 	'<table border=0><tr bgcolor="#deffff">'.
                   1242: 	'<td><b>Username</b></td><td><b>Fullname</b></td><td><b>Domain</b></td>'."\n";
                   1243:     #get list of parts for this problem
                   1244:     my (@parts) = sort(&getpartlist($url));
                   1245:     foreach my $part (@parts) {
                   1246: 	my $display=&Apache::lonnet::metadata($url,$part.'.display');
                   1247: 	next if ($display =~ /^Number of Attempts/);
                   1248: 	if  (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
                   1249: 	if ($display =~ /^Partial Credit Factor/) {
                   1250: 	    $_ = $display;
                   1251: 	    my ($partid) = /.*?(\d+).*/;
1.42      ng       1252: 	    $result.='<td><b>Score Part '.$partid.'<br>(weight = '.
                   1253: 		$weight{$partid}.')</b></td>'."\n";
1.41      ng       1254: 	    next;
                   1255: 	}
1.42      ng       1256: 	$display =~ s/Problem Status/Grade Status<br>/;
1.41      ng       1257: 	$result.='<td><b>'.$display.'</b></td>'."\n";
                   1258:     }
                   1259:     $result.='</tr>';
                   1260:     #get info for each student
                   1261:     my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($ENV{'form.section'},'0');
                   1262:     my $ctr = 0;
                   1263:     foreach ( sort(@{ $$classlist{$ENV{'form.section'}} }) ) {
                   1264: 	(my $username = $_) = split(/:/);
1.43    ! ng       1265: 	$result.='<input type="hidden" name="ctr'.$ctr.'" value="'.$username.'" />'."\n";
1.41      ng       1266: 	$result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},
                   1267: 				   $_,$$fullname{$_},\@parts,\%weight);
                   1268: 	$ctr++;
                   1269:     }
                   1270:     $result.='</table></td></tr></table>';
                   1271:     $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
                   1272:     $result.='<input type="submit" name="submit" value="Submit Changes" /></form>';
                   1273:     $result.=&show_grading_menu_form($symb,$url);
                   1274:     return $result;
                   1275: }
                   1276: 
                   1277: sub viewstudentgrade {
                   1278:     my ($url,$symb,$courseid,$student,$fullname,$parts,$weight) = @_;
                   1279:     my ($username,$domain) = split(/:/,$student);
                   1280:     my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$username);
                   1281:     my $result='<tr bgcolor="#ffffdd"><td>'.
                   1282: 	'<a href="javascript:viewOneStudent(\''.$username.'\')"; TARGET=_self>'.$username.'</a>'.
                   1283: 	'</td><td>'.$fullname.'</td><td align="middle">'.$domain.'</td>'."\n";
                   1284:     foreach my $part (@$parts) {
                   1285: 	my ($temp,$part,$type)=split(/_/,$part);
                   1286: 	my $score=$record{"resource.$part.$type"};
                   1287: 	next if $type eq 'tries';
                   1288: 	if ($type eq 'awarded') {
1.42      ng       1289: 	    my $pts = $score eq '' ? '' : $score*$$weight{$part};
                   1290: 	    $result.='<input type="hidden" name="'.
1.43    ! ng       1291: 		'GD_'.$username.'_'.$part.'_aw_s" value="'.$pts.'" />'."\n";
1.42      ng       1292: 	    $result.='<td align="middle"><input type="text" name="'.
1.43    ! ng       1293: 		'GD_'.$username.'_'.$part.'_aw"'.
1.42      ng       1294: 		'onChange="javascript:changeSelect('.$part.',\''.$username.'\')" value="'.
                   1295: 		$pts.'" size="4" /></td>'."\n";
1.41      ng       1296: 	} elsif ($type eq 'solved') {
                   1297: 	    my ($status,$foo)=split(/_/,$score,2);
                   1298: 	    $status = 'nothing' if ($status eq '');
1.42      ng       1299: 	    $result.='<input type="hidden" name="'.
1.43    ! ng       1300: 		'GD_'.$username.'_'.$part.'_sv_s" value="'.$status.'" />'."\n";
1.42      ng       1301: 	    $result.='<td align="middle"><select name="'.
1.43    ! ng       1302: 		'GD_'.$username.'_'.$part.'_sv" '.
1.42      ng       1303: 		'onChange="javascript:changeOneScore('.$part.',\''.$username.'\')" >'."\n";
                   1304: 	    my $optsel = '<option selected="on"> </option><option>excused</option>'."\n";
                   1305: 	    $optsel = '<option> </option><option selected="on">excused</option>'."\n"
                   1306: 		if ($status eq 'excused');
1.41      ng       1307: 	    $result.=$optsel;
                   1308: 	    $result.="</select></td>\n";
                   1309: 	}
                   1310:     }
                   1311:     $result.='</tr>';
                   1312:     return $result;
1.38      ng       1313: }
                   1314: 
1.41      ng       1315: 
1.38      ng       1316: sub editgrades {
1.41      ng       1317:     my ($request) = @_;
                   1318: 
                   1319:     my $symb=$ENV{'form.symb'};
1.43    ! ng       1320:     my $url =$ENV{'form.url'};
        !          1321:     my $result='<h2><font color="#339933">Current Grade Status</font></h2>';
        !          1322:     $result.='<font size=+1><b>Resource: </b>'.$ENV{'form.url'}.'</font><br />'."\n";
        !          1323:     $result.='<font size=+1><b>Section: </b>'.$ENV{'form.section'}.'</font>'."\n";
        !          1324:     $result.= &show_grading_menu_form ($symb,$url);
        !          1325:     $result.= '<table border="0"><tr><td bgcolor="#777777">'."\n";
        !          1326:     $result.= '<table border="0"><tr bgcolor="#deffff">'.
        !          1327: 	'<td rowspan=2><b>Username</b></td><td rowspan=2><b>Fullname</b></td>'."\n";
        !          1328: 
        !          1329:     my %scoreptr = (
        !          1330: 		    'correct'  =>'correct_by_override',
        !          1331: 		    'incorrect'=>'incorrect_by_override',
        !          1332: 		    'excused'  =>'excused',
        !          1333: 		    'ungraded' =>'ungraded_attempted',
        !          1334: 		    'nothing'  => '',
        !          1335: 		    );
        !          1336:     my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($ENV{'form.section'},'0');
1.34      ng       1337: 
1.43    ! ng       1338:     my (@partid);
        !          1339:     my %weight = ();
        !          1340:     my ($i,$ctr) = (0,0);
        !          1341:     while ($ctr < $ENV{'form.totalparts'}) {
        !          1342: 	my $partid = $ENV{'form.partid_'.$ctr};
        !          1343: 	push @partid,$partid;
        !          1344: 	my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
        !          1345: 	$weight{$partid} = $wgt eq '' ? '1' : $wgt;
        !          1346: 	$ctr++;
        !          1347: 	$result .= '<td colspan = 2 align="center"><b>Part ID '.$partid.
        !          1348: 	    '</b> (Weight = '.$weight{$partid}.')</td>';
1.41      ng       1349:     }
1.43    ! ng       1350:     $result .= '</tr><tr bgcolor="#deffff">';
        !          1351:     foreach (@partid) {
        !          1352: 	$result .= '<td align="center">&nbsp;<b>Old Score</b>&nbsp;</td>'.
        !          1353: 	    '<td align="center">&nbsp;<b>New Score</b>&nbsp;</td>';
        !          1354:     }
        !          1355:     $result .= '</tr>'."\n";
        !          1356: 
        !          1357:     for ($i=0; $i<$ENV{'form.total'}; $i++) {
        !          1358: 	my $user = $ENV{'form.ctr'.$i};
        !          1359: 	my %newrecord;
        !          1360: 	my $updateflag = 0;
        !          1361: 	my @userdom = grep /^$user:/,keys %$classlist;
        !          1362: 	my ($foo,$udom) = split(/:/,$userdom[0]);
        !          1363: 
        !          1364: 	$result .= '<tr bgcolor="#ffffde"><td>'.$user.'&nbsp;</td><td>'.
        !          1365: 	    $$fullname{$userdom[0]}.'&nbsp;</td>';
        !          1366: 
        !          1367: 	foreach (@partid) {
        !          1368: 	    my $old_aw    = $ENV{'form.GD_'.$user.'_'.$_.'_aw_s'};
        !          1369: 	    my $old_part  = $old_aw eq '' ? '' : $old_aw/$weight{$_};
        !          1370: 	    my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_sv_s'}};
        !          1371: 
        !          1372: 	    my $awarded   = $ENV{'form.GD_'.$user.'_'.$_.'_aw'};
        !          1373: 	    my $partial   = $awarded eq '' ? '' : $awarded/$weight{$_};
        !          1374: 	    my $score;
        !          1375: 	    if ($partial eq '') {
        !          1376: 		$score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_sv_s'}};
        !          1377: 	    } elsif ($partial > 0) {
        !          1378: 		$score = 'correct_by_override';
        !          1379: 	    } elsif ($partial == 0) {
        !          1380: 		$score = 'incorrect_by_override';
        !          1381: 	    }
        !          1382: 	    $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_sv'} eq 'excused') &&
        !          1383: 				   ($score ne 'excused'));
        !          1384: 	    $result .= '<td align="center">'.$old_aw.'&nbsp;</td>'.
        !          1385: 		'<td align="center">'.$awarded.
        !          1386: 		($score eq 'excused' ? $score : '').'&nbsp;</td>';
        !          1387: 
        !          1388: 	    next if ($old_part eq $partial && $old_score eq $score);
        !          1389: 
        !          1390: 	    $updateflag = 1;
        !          1391: 	    $newrecord{'resource.'.$_.'.awarded'}  = $partial if $partial ne '';
        !          1392: 	    $newrecord{'resource.'.$_.'.solved'} = $score;
1.35      ng       1393: 
1.43    ! ng       1394: 	}
        !          1395: 	$result .= '</tr>'."\n";
        !          1396: 	if ($updateflag) {
        !          1397: 	    $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
        !          1398: 	    &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},
        !          1399: 				    $udom,$user);
        !          1400: 	}
        !          1401:     }
        !          1402:     $result .= '</table></td></tr></table>'."\n";
1.41      ng       1403:     return $result;
1.38      ng       1404: }
1.42      ng       1405: 
                   1406: 
                   1407: #FIXME need to look at the metadata <stores> spec on what type of data to accept and provide an
                   1408: #interface based on that, also do that to above function.
                   1409: sub setstudentgrade {
                   1410:     my ($url,$symb,$courseid,$student,@parts) = @_;
                   1411:     my $result ='';
                   1412:     my ($stuname,$domain) = split(/:/,$student);
                   1413:     my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$stuname);
                   1414:     my %newrecord;
                   1415: 
                   1416:     foreach my $part (@parts) {
                   1417: 	my ($temp,$part,$type)=split(/_/,$part);
                   1418: 	my $oldscore=$record{"resource.$part.$type"};
1.43    ! ng       1419: 	my $newscore=$ENV{"form.GD.$student.$part.$type"};
1.42      ng       1420: 	if ($type eq 'solved') {
                   1421: 	    my $update=0;
                   1422: 	    if ($newscore eq 'nothing' ) {
                   1423: 		if ($oldscore ne '') {
                   1424: 		    $update=1;
                   1425: 		    $newscore = '';
                   1426: 		}
                   1427: 	    } elsif ($oldscore !~ m/^$newscore/) {
                   1428: 		$update=1;
                   1429: 		$result.="Updating $stuname to $newscore<br />\n";
                   1430: 		if ($newscore eq 'correct')   { $newscore = 'correct_by_override'; }
                   1431: 		if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }
                   1432: 		if ($newscore eq 'excused')   { $newscore = 'excused'; }
                   1433: 		if ($newscore eq 'ungraded')  { $newscore = 'ungraded_attempted'; }
                   1434: 	    } else {
                   1435: 		#$result.="$stuname:$part:$type:unchanged  $oldscore to $newscore:<br />\n";
                   1436: 	    }
                   1437: 	    if ($update) { $newrecord{"resource.$part.$type"}=$newscore; }
                   1438: 	} else {
                   1439: 	    if ($oldscore ne $newscore) {
                   1440: 		$newrecord{"resource.$part.$type"}=$newscore;
                   1441: 		$result.="Updating $student"."'s status for $part.$type to $newscore<br />\n";
                   1442: 	    } else {
                   1443: 		#$result.="$stuname:$part:$type:unchanged  $oldscore to $newscore:<br />\n";
                   1444: 	    }
                   1445: 	}
                   1446:     }
                   1447:     if ( scalar(keys(%newrecord)) > 0 ) {
                   1448: 	$newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
                   1449: #       &Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$stuname);
                   1450: 
                   1451: 	$result.="Stored away ".scalar(keys(%newrecord))." elements.<br />\n";
                   1452:     }
                   1453:     return $result;
                   1454: }
                   1455: 
1.38      ng       1456: 
                   1457: sub sub_page_js {
1.41      ng       1458:     my $request = shift;
                   1459:     $request->print(<<SUBJAVASCRIPT);
1.38      ng       1460: <script type="text/javascript" language="javascript">
1.39      ng       1461:   function updateRadio(radioButton,formtextbox,formsel,scores) {
1.38      ng       1462:      var pts = formtextbox.value;
                   1463:      var resetbox =false;
                   1464:      if (isNaN(pts) || pts < 0) {
                   1465: 	alert("A number equal or greater than 0 is expected. Entered value = "+pts);
                   1466: 	for (var i=0; i<radioButton.length; i++) {
                   1467: 	   if (radioButton[i].checked) {
                   1468: 	      formtextbox.value = i;
                   1469: 	      resetbox = true;
                   1470: 	   }
                   1471: 	}
                   1472: 	if (!resetbox) {
                   1473: 	   formtextbox.value = "";
                   1474: 	}
                   1475: 	return;
                   1476:     }
1.37      ng       1477: 
1.38      ng       1478:     for (var i=0; i<radioButton.length; i++) {
                   1479: 	radioButton[i].checked=false;
                   1480: 	if (pts == i) {
                   1481: 	   radioButton[i].checked=true;
                   1482: 	}
                   1483:     }
1.39      ng       1484:     updateSelect(formsel);
                   1485:     scores.value = "0";
1.37      ng       1486:   }
                   1487: 
1.39      ng       1488:   function writeBox(formrad,formsel,pts,scores) {
1.38      ng       1489:     formrad.value = pts;
1.39      ng       1490:     scores.value = "0";
                   1491:     updateSelect(formsel,pts);
1.38      ng       1492:     return;
1.31      ng       1493:   }
1.34      ng       1494: 
1.39      ng       1495:   function clearRadBox(radioButton,formbox,formsel,scores) {
                   1496:     for (var i=0; i<formsel.length; i++) {
                   1497: 	if (formsel[i].selected) {
                   1498: 	    var selectx=i;
                   1499: 	}
1.38      ng       1500:     }
1.39      ng       1501:     if (selectx == scores.value) { return };
                   1502:     formbox.value = "";
                   1503:     for (var i=0; i<radioButton.length; i++) {
                   1504: 	radioButton[i].checked=false;
1.33      ng       1505:     }
1.39      ng       1506:     scores.value = selectx;
                   1507:   }
                   1508: 
                   1509:   function updateSelect(formsel) {
                   1510:     formsel[0].selected = true;
1.38      ng       1511:     return;
1.33      ng       1512:   }
1.37      ng       1513: 
1.39      ng       1514: //===================== Show list of keywords ====================
1.38      ng       1515:   function keywords(keyform) {
                   1516:     var keywds = keyform.value;
                   1517:     var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keywds);
                   1518:     if (nret==null) return;
                   1519:     keyform.value = nret;
                   1520:     return;
1.34      ng       1521:   }
1.30      ng       1522: 
1.41      ng       1523: //===================== Script to view submitted by ==================
                   1524:   function viewSubmitter(submitter) {
                   1525:     document.SCORE.refresh.value = "on";
                   1526:     document.SCORE.NCT.value = "1";
                   1527:     document.SCORE.unamedom0.value = submitter;
                   1528:     document.SCORE.submit();
                   1529:     return;
                   1530:   }
                   1531: 
1.38      ng       1532: //===================== Script to add keyword(s) ==================
                   1533:   function getSel() {
                   1534:     if (document.getSelection) txt = document.getSelection();
                   1535:     else if (document.selection) txt = document.selection.createRange().text;
                   1536:     else return;
                   1537:     var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
                   1538:     if (cleantxt=="") {
                   1539: 	alert("Select a word or group of words from document and then click this link.");
                   1540: 	return;
1.35      ng       1541:     }
1.38      ng       1542:     var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
                   1543:     if (nret==null) return;
                   1544:     var curlist = document.SCORE.keywords.value;
                   1545:     document.SCORE.keywords.value = curlist+" "+nret;
                   1546:     return;
1.35      ng       1547:   }
                   1548: 
1.38      ng       1549: //====================== Script for composing message ==============
                   1550:   function msgCenter(msgform,usrctr,fullname) {
                   1551:     var Nmsg  = msgform.savemsgN.value;
                   1552:     savedMsgHeader(Nmsg,usrctr,fullname);
                   1553:     var subject = msgform.msgsub.value;
                   1554:     var rtrchk  = eval("document.SCORE.includemsg"+usrctr);
                   1555:     var msgchk = rtrchk.value;
                   1556: //    alert("checked=>"+msgchk);
                   1557:     re = /msgsub/;
                   1558:     var shwsel = "";
                   1559:     if (re.test(msgchk)) { shwsel = "checked" }
                   1560:     displaySubject(subject,shwsel);
                   1561:     for (var i=1; i<=Nmsg; i++) {
                   1562: 	var testpt = "savemsg"+i+",";
                   1563: 	re = /testpt/;
                   1564: 	shwsel = "";
                   1565: 	if (re.test(msgchk)) { shwsel = "checked" }
                   1566: 	var message = eval("document.SCORE.savemsg"+i+".value");
                   1567: 	displaySavedMsg(i,message,shwsel);
                   1568:     }
                   1569:     newmsg = eval("document.SCORE.newmsg"+usrctr+".value");
                   1570:     shwsel = "";
                   1571:     re = /newmsg/;
                   1572:     if (re.test(msgchk)) { shwsel = "checked" }
                   1573:     newMsg(newmsg,shwsel);
                   1574:     msgTail(); 
                   1575:     return;
1.35      ng       1576:   }
                   1577: 
1.38      ng       1578:   function savedMsgHeader(Nmsg,usrctr,fullname) {
                   1579:     var height = 30*Nmsg+250;
                   1580:     var scrollbar = "no";
                   1581:     if (height > 600) {
                   1582: 	height = 600;
                   1583: 	scrollbar = "yes";
                   1584:     }
                   1585: /*    if (window.pWin)
                   1586: 	window.pWin.close(); */
                   1587:     pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx=70,screeny=75,width=600,height='+height);
                   1588:     pWin.document.write("<html><head>");
                   1589:     pWin.document.write("<title>Message Central</title>");
1.37      ng       1590: 
1.38      ng       1591:     pWin.document.write("<script language=javascript>");
                   1592:     pWin.document.write("function checkInput() {");
                   1593:     pWin.document.write("  opener.document.SCORE.msgsub.value = document.msgcenter.msgsub.value;");
                   1594:     pWin.document.write("  var nmsg   = opener.document.SCORE.savemsgN.value;");
                   1595:     pWin.document.write("  var usrctr = document.msgcenter.usrctr.value;");
                   1596:     pWin.document.write("  var newval = eval(\\"opener.document.SCORE.newmsg\\"+usrctr);");
                   1597:     pWin.document.write("  newval.value = document.msgcenter.newmsg.value;");
1.37      ng       1598: 
1.38      ng       1599:     pWin.document.write("  var msgchk = \\"\\";");
                   1600:     pWin.document.write("  if (document.msgcenter.subchk.checked) {");
                   1601:     pWin.document.write("     msgchk = \\"msgsub,\\";");
                   1602:     pWin.document.write("  }");
                   1603:     pWin.document.write(   "for (var i=1; i<=nmsg; i++) {");
                   1604:     pWin.document.write("      var opnmsg = eval(\\"opener.document.SCORE.savemsg\\"+i);");
                   1605:     pWin.document.write("      var frmmsg = eval(\\"document.msgcenter.msg\\"+i);");
                   1606:     pWin.document.write("      opnmsg.value = frmmsg.value;");
                   1607:     pWin.document.write("      var chkbox = eval(\\"document.msgcenter.msgn\\"+i);");
                   1608:     pWin.document.write("      if (chkbox.checked) {");
                   1609:     pWin.document.write("         msgchk += \\"savemsg\\"+i+\\",\\";");
                   1610:     pWin.document.write("      }");
                   1611:     pWin.document.write("  }");
                   1612:     pWin.document.write("  if (document.msgcenter.newmsgchk.checked) {");
                   1613:     pWin.document.write("     msgchk += \\"newmsg\\"+usrctr;");
                   1614:     pWin.document.write("  }");
                   1615:     pWin.document.write("  var includemsg = eval(\\"opener.document.SCORE.includemsg\\"+usrctr);");
                   1616:     pWin.document.write("  includemsg.value = msgchk;");
1.37      ng       1617: 
1.38      ng       1618: //    pWin.document.write("  alert(\\"slected=\\"+msgchk)");
                   1619:     pWin.document.write("  self.close()");
1.37      ng       1620: 
1.38      ng       1621:     pWin.document.write("}");
1.34      ng       1622: 
1.38      ng       1623:     pWin.document.write("<");
                   1624:     pWin.document.write("/script>");
1.33      ng       1625: 
1.38      ng       1626:     pWin.document.write("</head><body bgcolor=white>");
1.37      ng       1627: 
1.38      ng       1628:     pWin.document.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
                   1629:     pWin.document.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
                   1630:     pWin.document.write("<font color=\\"green\\" size=+1>&nbsp;Compose Message for \"+fullname+\"</font><br><br>");
1.34      ng       1631: 
1.38      ng       1632:     pWin.document.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
                   1633:     pWin.document.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
                   1634:     pWin.document.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
                   1635: }
                   1636:     function displaySubject(msg,shwsel) {
                   1637:     pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
                   1638:     pWin.document.write("<td>Subject</td>");
                   1639:     pWin.document.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
                   1640:     pWin.document.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+" \\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.34      ng       1641: }
                   1642: 
1.38      ng       1643: function displaySavedMsg(ctr,msg,shwsel) {
                   1644:     pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
                   1645:     pWin.document.write("<td align=\\"center\\">"+ctr+"</td>");
                   1646:     pWin.document.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
                   1647:     pWin.document.write("<td><input name=\\"msg"+ctr+"\\" type=\\"text\\" value=\\""+msg+" \\" size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.34      ng       1648: }
                   1649: 
1.38      ng       1650:   function newMsg(newmsg,shwsel) {
                   1651:     pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
                   1652:     pWin.document.write("<td align=\\"center\\">New</td>");
                   1653:     pWin.document.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1.39      ng       1654:     pWin.document.write("<td><input name=\\"newmsg\\" type=\\"text\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" value=\\""+newmsg+" \\" size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.34      ng       1655: }
                   1656: 
1.38      ng       1657:   function msgTail() {
                   1658:     pWin.document.write("</table>");
                   1659:     pWin.document.write("</td></tr></table>&nbsp;");
                   1660:     pWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\">&nbsp;&nbsp;");
                   1661:     pWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
                   1662:     pWin.document.write("</form>");
                   1663:     pWin.document.write("</body></html>");
                   1664: }
1.34      ng       1665: 
1.38      ng       1666: //====================== Script for keyword highlight options ==============
                   1667:   function kwhighlight() {
                   1668:     var kwclr    = document.SCORE.kwclr.value;
                   1669:     var kwsize   = document.SCORE.kwsize.value;
                   1670:     var kwstyle  = document.SCORE.kwstyle.value;
                   1671:     var redsel = "";
                   1672:     var grnsel = "";
                   1673:     var blusel = "";
                   1674:     if (kwclr=="red")   {var redsel="checked"};
                   1675:     if (kwclr=="green") {var grnsel="checked"};
                   1676:     if (kwclr=="blue")  {var blusel="checked"};
                   1677:     var sznsel = "";
                   1678:     var sz1sel = "";
                   1679:     var sz2sel = "";
                   1680:     if (kwsize=="0")  {var sznsel="checked"};
                   1681:     if (kwsize=="+1") {var sz1sel="checked"};
                   1682:     if (kwsize=="+2") {var sz2sel="checked"};
                   1683:     var synsel = "";
                   1684:     var syisel = "";
                   1685:     var sybsel = "";
                   1686:     if (kwstyle=="")    {var synsel="checked"};
                   1687:     if (kwstyle=="<i>") {var syisel="checked"};
                   1688:     if (kwstyle=="<b>") {var sybsel="checked"};
                   1689:     highlightCentral();
                   1690:     highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
                   1691:     highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
                   1692:     highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
                   1693:     highlightend();
                   1694:     return;
1.34      ng       1695:   }
                   1696: 
                   1697: 
1.38      ng       1698:   function highlightCentral() {
                   1699:     hwdWin = window.open('', 'KeywordHighlightCentral', 'toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx=100,screeny=75');
                   1700:     hwdWin.document.write("<html><head>");
                   1701:     hwdWin.document.write("<title>Highlight Central</title>");
1.34      ng       1702: 
1.38      ng       1703:     hwdWin.document.write("<script language=javascript>");
1.39      ng       1704:     hwdWin.document.write("function updateChoice(flag) {");
1.38      ng       1705:     hwdWin.document.write("  opener.document.SCORE.kwclr.value = radioSelection(document.hlCenter.kwdclr);");
                   1706:     hwdWin.document.write("  opener.document.SCORE.kwsize.value = radioSelection(document.hlCenter.kwdsize);");
                   1707:     hwdWin.document.write("  opener.document.SCORE.kwstyle.value = radioSelection(document.hlCenter.kwdstyle);");
1.40      ng       1708: //    hwdWin.document.write("     var kwords=opener.document.SCORE.keywords.value;");
                   1709: //    hwdWin.document.write("     alert(\\"keywords=\\"+opener.document.SCORE.keywords.value);");
                   1710: //    hwdWin.document.write("     return;");
                   1711: 
1.39      ng       1712:     hwdWin.document.write("  if (flag==1){");
                   1713:     hwdWin.document.write("     opener.document.SCORE.refresh.value = \\"on\\";");
1.40      ng       1714:     hwdWin.document.write("     if (opener.document.SCORE.keywords.value!=\\"\\"){");
                   1715:     hwdWin.document.write("        opener.document.SCORE.submit();");
                   1716:     hwdWin.document.write("     }");
1.39      ng       1717:     hwdWin.document.write("   }");
1.38      ng       1718:     hwdWin.document.write("  self.close()");
                   1719:     hwdWin.document.write("}");
1.26      albertel 1720: 
1.38      ng       1721:     hwdWin.document.write("function radioSelection(radioButton) {");
                   1722:     hwdWin.document.write("    var selection=null;");
                   1723:     hwdWin.document.write("    for (var i=0; i<radioButton.length; i++) {");
                   1724:     hwdWin.document.write("        if (radioButton[i].checked) {");
                   1725:     hwdWin.document.write("            selection=radioButton[i].value;");
                   1726:     hwdWin.document.write("            return selection;");
                   1727:     hwdWin.document.write("        }");
                   1728:     hwdWin.document.write("    }");
                   1729:     hwdWin.document.write("}");
1.26      albertel 1730: 
1.38      ng       1731:     hwdWin.document.write("<");
                   1732:     hwdWin.document.write("/script>");
1.13      albertel 1733: 
1.38      ng       1734:     hwdWin.document.write("</head><body bgcolor=white>");
1.13      albertel 1735: 
1.38      ng       1736:     hwdWin.document.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
                   1737:     hwdWin.document.write("<font color=\\"green\\" size=+1>&nbsp;Keyword Highlight Options</font><br><br>");
1.13      albertel 1738: 
1.38      ng       1739:     hwdWin.document.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
                   1740:     hwdWin.document.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
                   1741:     hwdWin.document.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
1.30      ng       1742:   }
1.38      ng       1743: 
                   1744:   function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) { 
                   1745:     hwdWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
                   1746:     hwdWin.document.write("<td align=\\"left\\">");
                   1747:     hwdWin.document.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+">&nbsp;"+clrtxt+"</td>");
                   1748:     hwdWin.document.write("<td align=\\"left\\">");
                   1749:     hwdWin.document.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+">&nbsp;"+sztxt+"</td>");
                   1750:     hwdWin.document.write("<td align=\\"left\\">");
                   1751:     hwdWin.document.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+">&nbsp;"+sytxt+"</td>");
                   1752:     hwdWin.document.write("</tr>");
1.13      albertel 1753:   }
1.5       albertel 1754: 
1.38      ng       1755:   function highlightend() { 
                   1756:     hwdWin.document.write("</table>");
                   1757:     hwdWin.document.write("</td></tr></table>&nbsp;");
1.40      ng       1758:     hwdWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(0)\\">&nbsp;&nbsp;");
                   1759:     hwdWin.document.write("<input type=\\"button\\" value=\\"Save & Refresh\\" onClick=\\"javascript:updateChoice(1)\\">&nbsp;&nbsp;");
1.38      ng       1760:     hwdWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
                   1761:     hwdWin.document.write("</form>");
                   1762:     hwdWin.document.write("</body></html>");
1.13      albertel 1763:   }
1.5       albertel 1764: 
1.38      ng       1765: </script>
                   1766: SUBJAVASCRIPT
1.5       albertel 1767: }
                   1768: 
1.27      albertel 1769: sub csvupload_javascript_reverse_associate {
                   1770:   return(<<ENDPICK);
                   1771:   function verify(vf) {
                   1772:     var foundsomething=0;
                   1773:     var founduname=0;
                   1774:     var founddomain=0;
                   1775:     for (i=0;i<=vf.nfields.value;i++) {
                   1776:       tw=eval('vf.f'+i+'.selectedIndex');
                   1777:       if (i==0 && tw!=0) { founduname=1; }
                   1778:       if (i==1 && tw!=0) { founddomain=1; }
                   1779:       if (i!=0 && i!=1 && tw!=0) { foundsomething=1; }
                   1780:     }
                   1781:     if (founduname==0 || founddomain==0) {
                   1782:       alert('You need to specify at both the username and domain');
                   1783:       return;
                   1784:     }
                   1785:     if (foundsomething==0) {
                   1786:       alert('You need to specify at least one grading field');
                   1787:       return;
                   1788:     }
                   1789:     vf.submit();
                   1790:   }
                   1791:   function flip(vf,tf) {
                   1792:     var nw=eval('vf.f'+tf+'.selectedIndex');
                   1793:     var i;
                   1794:     for (i=0;i<=vf.nfields.value;i++) {
                   1795:       //can not pick the same destination field for both name and domain
                   1796:       if (((i ==0)||(i ==1)) && 
                   1797:           ((tf==0)||(tf==1)) && 
                   1798:           (i!=tf) &&
                   1799:           (eval('vf.f'+i+'.selectedIndex')==nw)) {
                   1800:         eval('vf.f'+i+'.selectedIndex=0;')
                   1801:       }
                   1802:     }
                   1803:   }
                   1804: ENDPICK
                   1805: }
                   1806: 
                   1807: sub csvupload_javascript_forward_associate {
                   1808:   return(<<ENDPICK);
                   1809:   function verify(vf) {
                   1810:     var foundsomething=0;
                   1811:     var founduname=0;
                   1812:     var founddomain=0;
                   1813:     for (i=0;i<=vf.nfields.value;i++) {
                   1814:       tw=eval('vf.f'+i+'.selectedIndex');
                   1815:       if (tw==1) { founduname=1; }
                   1816:       if (tw==2) { founddomain=1; }
                   1817:       if (tw>2) { foundsomething=1; }
                   1818:     }
                   1819:     if (founduname==0 || founddomain==0) {
                   1820:       alert('You need to specify at both the username and domain');
                   1821:       return;
                   1822:     }
                   1823:     if (foundsomething==0) {
                   1824:       alert('You need to specify at least one grading field');
                   1825:       return;
                   1826:     }
                   1827:     vf.submit();
                   1828:   }
                   1829:   function flip(vf,tf) {
                   1830:     var nw=eval('vf.f'+tf+'.selectedIndex');
                   1831:     var i;
                   1832:     //can not pick the same destination field twice
                   1833:     for (i=0;i<=vf.nfields.value;i++) {
                   1834:       if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
                   1835:         eval('vf.f'+i+'.selectedIndex=0;')
                   1836:       }
                   1837:     }
                   1838:   }
                   1839: ENDPICK
                   1840: }
                   1841: 
1.26      albertel 1842: sub csvuploadmap_header {
1.41      ng       1843:     my ($request,$symb,$url,$datatoken,$distotal)= @_;
                   1844:     my $result;
                   1845:     my $javascript;
                   1846:     if ($ENV{'form.upfile_associate'} eq 'reverse') {
                   1847: 	$javascript=&csvupload_javascript_reverse_associate();
                   1848:     } else {
                   1849: 	$javascript=&csvupload_javascript_forward_associate();
                   1850:     }
                   1851:     $request->print(<<ENDPICK);
1.26      albertel 1852: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
                   1853: <h3>Uploading Class Grades for resource $url</h3>
                   1854: <hr>
                   1855: <h3>Identify fields</h3>
                   1856: Total number of records found in file: $distotal <hr />
                   1857: Enter as many fields as you can. The system will inform you and bring you back
                   1858: to this page if the data selected is insufficient to run your class.<hr />
                   1859: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
                   1860: <input type="hidden" name="associate"  value="" />
                   1861: <input type="hidden" name="phase"      value="three" />
                   1862: <input type="hidden" name="datatoken"  value="$datatoken" />
                   1863: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
                   1864: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
                   1865: <input type="hidden" name="upfile_associate" 
                   1866:                                        value="$ENV{'form.upfile_associate'}" />
                   1867: <input type="hidden" name="symb"       value="$symb" />
                   1868: <input type="hidden" name="url"        value="$url" />
                   1869: <input type="hidden" name="command"    value="csvuploadassign" />
                   1870: <hr />
                   1871: <script type="text/javascript" language="Javascript">
                   1872: $javascript
                   1873: </script>
                   1874: ENDPICK
1.41      ng       1875: return '';
1.26      albertel 1876: 
                   1877: }
                   1878: 
                   1879: sub csvupload_fields {
1.41      ng       1880:     my ($url) = @_;
                   1881:     my (@parts) = &getpartlist($url);
                   1882:     my @fields=(['username','Student Username'],['domain','Student Domain']);
                   1883:     foreach my $part (sort(@parts)) {
                   1884: 	my @datum;
                   1885: 	my $display=&Apache::lonnet::metadata($url,$part.'.display');
                   1886: 	my $name=$part;
                   1887: 	if  (!$display) { $display = $name; }
                   1888: 	@datum=($name,$display);
                   1889: 	push(@fields,\@datum);
                   1890:     }
                   1891:     return (@fields);
1.26      albertel 1892: }
                   1893: 
                   1894: sub csvuploadmap_footer {
1.41      ng       1895:     my ($request,$i,$keyfields) =@_;
                   1896:     $request->print(<<ENDPICK);
1.26      albertel 1897: </table>
                   1898: <input type="hidden" name="nfields" value="$i" />
                   1899: <input type="hidden" name="keyfields" value="$keyfields" />
                   1900: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
                   1901: </form>
                   1902: ENDPICK
                   1903: }
                   1904: 
                   1905: sub csvuploadmap {
1.41      ng       1906:     my ($request)= @_;
                   1907:     my ($symb,$url)=&get_symb_and_url($request);
                   1908:     if (!$symb) {return '';}
                   1909:     my $datatoken;
                   1910:     if (!$ENV{'form.datatoken'}) {
                   1911: 	$datatoken=&Apache::loncommon::upfile_store($request);
1.26      albertel 1912:     } else {
1.41      ng       1913: 	$datatoken=$ENV{'form.datatoken'};
                   1914: 	&Apache::loncommon::load_tmp_file($request);
1.26      albertel 1915:     }
1.41      ng       1916:     my @records=&Apache::loncommon::upfile_record_sep();
                   1917:     &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
                   1918:     my ($i,$keyfields);
                   1919:     if (@records) {
                   1920: 	my @fields=&csvupload_fields($url);
                   1921: 	if ($ENV{'form.upfile_associate'} eq 'reverse') {	
                   1922: 	    &Apache::loncommon::csv_print_samples($request,\@records);
                   1923: 	    $i=&Apache::loncommon::csv_print_select_table($request,\@records,
                   1924: 							  \@fields);
                   1925: 	    foreach (@fields) { $keyfields.=$_->[0].','; }
                   1926: 	    chop($keyfields);
                   1927: 	} else {
                   1928: 	    unshift(@fields,['none','']);
                   1929: 	    $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
                   1930: 							    \@fields);
                   1931: 	    my %sone=&Apache::loncommon::record_sep($records[0]);
                   1932: 	    $keyfields=join(',',sort(keys(%sone)));
                   1933: 	}
                   1934:     }
                   1935:     &csvuploadmap_footer($request,$i,$keyfields);
                   1936:     return '';
1.27      albertel 1937: }
                   1938: 
                   1939: sub csvuploadassign {
1.41      ng       1940:     my ($request)= @_;
                   1941:     my ($symb,$url)=&get_symb_and_url($request);
                   1942:     if (!$symb) {return '';}
                   1943:     &Apache::loncommon::load_tmp_file($request);
                   1944:     my @gradedata=&Apache::loncommon::upfile_record_sep();
                   1945:     my @keyfields = split(/\,/,$ENV{'form.keyfields'});
                   1946:     my %fields=();
                   1947:     for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
                   1948: 	if ($ENV{'form.upfile_associate'} eq 'reverse') {
                   1949: 	    if ($ENV{'form.f'.$i} ne 'none') {
                   1950: 		$fields{$keyfields[$i]}=$ENV{'form.f'.$i};
                   1951: 	    }
                   1952: 	} else {
                   1953: 	    if ($ENV{'form.f'.$i} ne 'none') {
                   1954: 		$fields{$ENV{'form.f'.$i}}=$keyfields[$i];
                   1955: 	    }
                   1956: 	}
1.27      albertel 1957:     }
1.41      ng       1958:     $request->print('<h3>Assigning Grades</h3>');
                   1959:     my $courseid=$ENV{'request.course.id'};
1.34      ng       1960: #  my $cdom=$ENV{"course.$courseid.domain"};
                   1961: #  my $cnum=$ENV{"course.$courseid.num"};
1.41      ng       1962:     my ($classlist) = &getclasslist('all','1');
                   1963:     my @skipped;
                   1964:     my $countdone=0;
                   1965:     foreach my $grade (@gradedata) {
                   1966: 	my %entries=&Apache::loncommon::record_sep($grade);
                   1967: 	my $username=$entries{$fields{'username'}};
                   1968: 	my $domain=$entries{$fields{'domain'}};
                   1969: 	if (!exists($$classlist{"$username:$domain"})) {
                   1970: 	    push(@skipped,"$username:$domain");
                   1971: 	    next;
                   1972: 	}
                   1973: 	my %grades;
                   1974: 	foreach my $dest (keys(%fields)) {
                   1975: 	    if ($dest eq 'username' || $dest eq 'domain') { next; }
                   1976: 	    if ($entries{$fields{$dest}} eq '') { next; }
                   1977: 	    my $store_key=$dest;
                   1978: 	    $store_key=~s/^stores/resource/;
                   1979: 	    $store_key=~s/_/\./g;
                   1980: 	    $grades{$store_key}=$entries{$fields{$dest}};
                   1981: 	}
                   1982: 	$grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
                   1983: 	&Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
                   1984: 				$domain,$username);
                   1985: 	$request->print('.');
                   1986: 	$request->rflush();
                   1987: 	$countdone++;
                   1988:     }
                   1989:     $request->print("<br />Stored $countdone students\n");
                   1990:     if (@skipped) {
                   1991: 	$request->print('<br /><font size="+1"><b>Skipped Students</b></font><br />');
                   1992: 	foreach my $student (@skipped) { $request->print("<br />$student"); }
                   1993:     }
                   1994:     $request->print(&view_edit_entire_class_form($symb,$url));
                   1995:     $request->print(&show_grading_menu_form($symb,$url));
                   1996:     return '';
1.26      albertel 1997: }
                   1998: 
1.2       albertel 1999: sub send_header {
1.41      ng       2000:     my ($request)= @_;
                   2001:     $request->print(&Apache::lontexconvert::header());
1.6       albertel 2002: #  $request->print("
                   2003: #<script>
                   2004: #remotewindow=open('','homeworkremote');
                   2005: #remotewindow.close();
                   2006: #</script>"); 
1.41      ng       2007:     $request->print('<body bgcolor="#FFFFFF">');
1.2       albertel 2008: }
                   2009: 
                   2010: sub send_footer {
1.41      ng       2011:     my ($request)= @_;
                   2012:     $request->print('</body>');
                   2013:     $request->print(&Apache::lontexconvert::footer());
1.2       albertel 2014: }
                   2015: 
1.1       albertel 2016: sub handler {
1.41      ng       2017:     my $request=$_[0];
                   2018:     
                   2019:     if ($ENV{'browser.mathml'}) {
                   2020: 	$request->content_type('text/xml');
                   2021:     } else {
                   2022: 	$request->content_type('text/html');
                   2023:     }
                   2024:     $request->send_http_header;
                   2025:     return OK if $request->header_only;
                   2026:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
                   2027:     my $url=$ENV{'form.url'};
                   2028:     my $symb=$ENV{'form.symb'};
                   2029:     my $command=$ENV{'form.command'};
                   2030:     if (!$url) {
                   2031: 	my ($temp1,$temp2);
                   2032: 	($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
                   2033: 	$url = $ENV{'form.url'};
                   2034:     }
                   2035:     &send_header($request);
                   2036:     if ($url eq '' && $symb eq '') {
                   2037: 	if ($ENV{'user.adv'}) {
                   2038: 	    if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
                   2039: 		($ENV{'form.codethree'})) {
                   2040: 		my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
                   2041: 		    $ENV{'form.codethree'};
                   2042: 		my ($tsymb,$tuname,$tudom,$tcrsid)=
                   2043: 		    &Apache::lonnet::checkin($token);
                   2044: 		if ($tsymb) {
                   2045: 		    my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
                   2046: 		    if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
                   2047: 			$request->print(
                   2048: 					&Apache::lonnet::ssi('/res/'.$url,
                   2049: 							     ('grade_username' => $tuname,
                   2050: 							      'grade_domain' => $tudom,
                   2051: 							      'grade_courseid' => $tcrsid,
                   2052: 							      'grade_symb' => $tsymb)));
                   2053: 		    } else {
                   2054: 			$request->print('<h1>Not authorized: '.$token.'</h1>');
                   2055: 		    }           
                   2056: 		} else {
                   2057: 		    $request->print('<h1>Not a valid DocID: '.$token.'</h1>');
                   2058: 		}
1.14      www      2059: 	    } else {
1.41      ng       2060: 		$request->print(&Apache::lonxml::tokeninputfield());
                   2061: 	    }
                   2062: 	}
                   2063:     } else {
                   2064: 	#&Apache::lonhomework::showhashsubset(\%ENV,'^form');
                   2065: 	$Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
                   2066: 	if ($command eq 'submission') {
                   2067: 	    &listStudents($request) if ($ENV{'form.student'} eq '');
                   2068: 	    &submission($request,0,0) if ($ENV{'form.student'} ne '');
                   2069: 	} elsif ($command eq 'processGroup') {
                   2070: 	    &processGroup($request);
                   2071: 	} elsif ($command eq 'gradingmenu') {
                   2072: 	    $request->print(&gradingmenu($request));
                   2073: 	} elsif ($command eq 'viewgrades') {
                   2074: 	    $request->print(&viewgrades($request));
                   2075: 	} elsif ($command eq 'handgrade') {
                   2076: 	    $request->print(&processHandGrade($request));
                   2077: 	} elsif ($command eq 'editgrades') {
                   2078: 	    $request->print(&editgrades($request));
                   2079: 	} elsif ($command eq 'verify') {
                   2080: 	    $request->print(&verifyreceipt($request));
                   2081: 	} elsif ($command eq 'csvupload') {
                   2082: 	    $request->print(&csvupload($request));
                   2083: 	} elsif ($command eq 'viewclasslist') {
                   2084: 	    $request->print(&viewclasslist($request));
                   2085: 	} elsif ($command eq 'csvuploadmap') {
                   2086: 	    $request->print(&csvuploadmap($request));
1.34      ng       2087: #    } elsif ($command eq 'receiptInput') {
                   2088: #      &receiptInput($request);
1.41      ng       2089: 	} elsif ($command eq 'csvuploadassign') {
                   2090: 	    if ($ENV{'form.associate'} ne 'Reverse Association') {
                   2091: 		$request->print(&csvuploadassign($request));
                   2092: 	    } else {
                   2093: 		if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
                   2094: 		    $ENV{'form.upfile_associate'} = 'reverse';
                   2095: 		} else {
                   2096: 		    $ENV{'form.upfile_associate'} = 'forward';
                   2097: 		}
                   2098: 		$request->print(&csvuploadmap($request));
                   2099: 	    }
1.26      albertel 2100: 	} else {
1.41      ng       2101: 	    $request->print("Unknown action: $command:");
1.26      albertel 2102: 	}
1.2       albertel 2103:     }
1.41      ng       2104:     &send_footer($request);
                   2105:     return OK;
1.1       albertel 2106: }
                   2107: 
                   2108: 1;
                   2109: 
1.13      albertel 2110: __END__;

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