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

1.17      albertel    1: # The LearningOnline Network with CAPA
1.13      albertel    2: # The LON-CAPA Grading handler
1.17      albertel    3: #
1.38    ! ng          4: # $Id: grades.pm,v 1.37 2002/07/08 21:18:54 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.38    ! ng         45: use Time::HiRes qw( gettimeofday tv_interval );
1.1       albertel   46: 
1.2       albertel   47: sub moreinfo {
1.13      albertel   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");
1.16      albertel   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:     }
1.35      ng         58: #    $request->print('<input type="hidden" name="command" value="submission" />'."\n");
1.16      albertel   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");
1.13      albertel   63:     $request->print('</form>');
                     64:   }
                     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'}).'-'.
                     74:                 $ENV{'form.receipt'};
                     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 
                     87:              &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
                     88:                $request->print('Matching '.$student.'<br>');
                     89:                $matches++;
                     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 {
                     99:   my ($url,$udom,$uname) = @_;
                    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:   foreach my $part (&getpartlist($url)) {
                    103:     my ($temp,$part,$type)=split(/_/,$part);
                    104:     if ($type eq 'solved') {
                    105:       my ($status,$foo)=split(/_/,$record{"resource.$part.$type"},2);
1.34      ng        106:       $status = 'partial' if ($foo =~ /^partially/);
1.32      ng        107:       $status = 'nothing' if ($status eq '');
                    108:       return $type,$status;
                    109:     }
                    110:   }
                    111:   return '';
                    112: }
                    113: 
1.34      ng        114: sub get_fullname {
                    115:     my ($sname,$sdom) = @_;
                    116:     my %name=&Apache::lonnet::get('environment', ['lastname','generation',
                    117: 						  'firstname','middlename'],
                    118: 				  $sdom,$sname);
                    119:     my $fullname;
                    120:     my ($tmp) = keys(%name);
                    121:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                    122: 	$fullname=$name{'lastname'}.$name{'generation'};
                    123: 	if ($fullname =~ /[^\s]+/) { $fullname.=', '; }
                    124: 	$fullname.=$name{'firstname'}.' '.$name{'middlename'};
                    125:     }
                    126:     return $fullname;
                    127: }
                    128: 
1.30      ng        129: sub listStudents {
                    130:   my ($request) = shift;
1.34      ng        131:   my $cdom      =$ENV{"course.$ENV{'request.course.id'}.domain"};
                    132:   my $cnum      =$ENV{"course.$ENV{'request.course.id'}.num"};
                    133:   my $getsec    =$ENV{'form.section'};
                    134:   my $submitonly=$ENV{'form.submitonly'};
1.30      ng        135: 
1.23      www       136:   $request->print(<<ENDTABLEST);
1.34      ng        137: <h2><font color="#339933">&nbsp;View Submissions for a Student or a Group of Students</font></h2>
                    138: &nbsp;<font size=+1><b>Resource:</b> $ENV{'form.url'}<br /><br />
                    139: <form action="/adm/grades" method="post">&nbsp;<b>View Options</b></font><br />
                    140: &nbsp;<b>View Problem: </b><input type="radio" name="vProb" value="no" checked> no 
1.37      ng        141: <input type="radio" name="vProb" value="yes"> yes <br />
                    142: &nbsp;<b>Submissions: </b>
                    143: <input type="radio" name="lastSub" value="lastonly" checked> last sub only
                    144: <input type="radio" name="lastSub" value="last"> last sub & parts info
                    145: <input type="radio" name="lastSub" value="all"> all details
1.34      ng        146: <input type="hidden" name="section" value="$getsec">
                    147: <input type="hidden" name="submitonly" value="$submitonly">
1.35      ng        148: <input type="hidden" name="response" value="$ENV{'form.response'}">
                    149: <input type="hidden" name="handgrade" value="$ENV{'form.handgrade'}">
1.32      ng        150: <table border="0"><tr><td bgcolor="#777777">
1.34      ng        151: <table border="0"><tr bgcolor="#e6ffff">
                    152: <td><b>&nbsp;Select&nbsp;</b></td><td><b>&nbsp;Username&nbsp;</b></td>
                    153: <td><b>&nbsp;Fullname&nbsp;</b></td><td><b>&nbsp;Domain&nbsp;</b></td>
                    154: <td><b>&nbsp;Grade Status&nbsp;</b></td></tr>
1.23      www       155: ENDTABLEST
1.34      ng        156:   if ($ENV{'form.url'}) {
                    157:       $request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />'."\n");
                    158:   }
                    159:   if ($ENV{'form.symb'}) {
                    160:       $request->print('<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />'."\n");
                    161:   }
                    162:   $request->print('<input type="hidden" name="command" value="processGroup" />'."\n");
                    163: 
1.38    ! ng        164:   my $t0=&Time::HiRes::time();
        !           165: 
1.34      ng        166:   my ($classlist) = &getclasslist($getsec,'0');
1.38    ! ng        167:   my $t1=&Time::HiRes::time();
        !           168:   print "getclasslist=",$t1-$t0,"<br />";
        !           169: 
1.34      ng        170:   foreach my $student ( sort(@{ $$classlist{$getsec} }) ) {
1.13      albertel  171:       my ($sname,$sdom) = split(/:/,$student);
1.34      ng        172:       my ($type,$status) = &student_gradeStatus($ENV{'form.url'},$cdom,$sname);
                    173:       next if ($status eq 'nothing' && $submitonly eq 'yes');
1.13      albertel  174: 
1.34      ng        175:       my $fullname = &get_fullname($sname,$sdom);
1.13      albertel  176:       if ( $Apache::grades::viewgrades eq 'F' ) {
1.34      ng        177: 	  $request->print("\n".'<tr bgcolor="#ffffe6">'.
                    178: 			  '<td align="center"><input type=checkbox name="stuinfo" value="'.
                    179: 			  $student.':'.$fullname.'"></td>'."\n".
                    180: 			  '<td>&nbsp;'.$sname.'&nbsp;</td>'."\n".
                    181: 			  '<td>&nbsp;'.$fullname.'&nbsp;</td>'."\n".
                    182: 			  '<td align="middle">&nbsp;'.$sdom.'&nbsp;</td>'."\n");
                    183: 	  $request->print('<td align="middle">&nbsp;'.$status.'&nbsp;</td>'."\n");
                    184: 
                    185: 	  $request->print('</tr>');
1.13      albertel  186:       }
                    187:   }
1.38    ! ng        188:   my $t2=&Time::HiRes::time();
        !           189:   print "processclasslist=",$t2-$t1,"<br />";
1.28      ng        190:   $request->print('</table></td></tr></table>');
1.34      ng        191:   $request->print('<input type="submit" name="submit" value="View/Grade" /><form />');
1.10      ng        192: }
                    193: 
1.34      ng        194: sub processGroup {
                    195:   my ($request)  = shift;
                    196:   my $ctr        = 0;
                    197:   my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
1.35      ng        198:                            : ($ENV{'form.stuinfo'}));
1.34      ng        199:   my $total      = scalar(@stuchecked)-1;
1.35      ng        200:   if ($stuchecked[0] eq '') {
                    201:       &userError($request,'No student was selected for viewing/grading.');
                    202:       return;
                    203:   }
                    204:   foreach (@stuchecked) {
                    205:       my ($sname,$sdom,$fullname) = split(/:/);
1.34      ng        206:       $ENV{'form.student'} = $sname;
                    207:       $ENV{'form.fullname'} = $fullname;
                    208:       &submission($request,$ctr,$total);
                    209:       $ctr++;
                    210:   }
1.35      ng        211:   return 'The End';
                    212: }
1.34      ng        213: 
1.35      ng        214: sub userError {
                    215:     my ($request, $reason, $step) = @_;
                    216:     $request->print('<h3><font color="red">LON-CAPA User Error</font></h3><br />'."\n");
                    217:     $request->print('<b>Reason: </b>'.$reason.'<br /><br />'."\n");
                    218:     $request->print('<b>Step: </b>'.($step ne '' ? $step : 'Use your browser back button to correct')
                    219: 		    .'<br /><br />'."\n");
                    220:     return '';
1.34      ng        221: }
1.13      albertel  222: 
1.7       albertel  223: #FIXME - needs to handle multiple matches
1.2       albertel  224: sub finduser {
1.13      albertel  225:   my ($name) = @_;
                    226:   my $domain = '';
                    227:   if ( $Apache::grades::viewgrades eq 'F' ) {
1.34      ng        228:     my ($classlist) = &getclasslist('all','0');
1.35      ng        229:     foreach ( sort(@{ $$classlist{'all'} }) ) {
                    230:       my ($posname,$posdomain) = split(/:/);
1.13      albertel  231:       if ($posname =~ $name) { $name=$posname; $domain=$posdomain; last; }
1.7       albertel  232:     }
1.13      albertel  233:     return ($name,$domain);
                    234:   } else {
                    235:     return ($ENV{'user.name'},$ENV{'user.domain'});
                    236:   }
1.5       albertel  237: }
                    238: 
                    239: sub getclasslist {
1.34      ng        240:   my ($getsec,$hideexpired) = @_;
                    241:   my ($coursedomain,$coursenum) = split(/_/,$ENV{'request.course.id'});
1.24      albertel  242:   my %classlist=&Apache::lonnet::dump('classlist',$coursedomain,$coursenum);
1.13      albertel  243:   my $now = time;
1.34      ng        244:   my (@holdsec,@sections);
1.24      albertel  245:   foreach my $student (keys(%classlist)) {
                    246:     my ($end,$start)=split(/:/,$classlist{$student});
1.13      albertel  247:     # still a student?
                    248:     if (($hideexpired) && ($end) && ($end < $now)) {
                    249:       next;
                    250:     }
1.34      ng        251:     my ($unam,$udom) = split(/:/,$student,2);
                    252:     my $section = &Apache::lonnet::usection($udom,$unam,$ENV{'request.course.id'});
1.35      ng        253:     $section = ($section ne '-1' ? $section : 'no');
1.34      ng        254:     push @holdsec,$section;
1.35      ng        255:     push (@{ $classlist{$getsec} }, $student) if ($getsec eq 'all' || $getsec eq $section);
1.34      ng        256:   }
                    257:   my %seen = ();
                    258:   foreach my $item (@holdsec) {
                    259:       push (@sections, $item) unless $seen{$item}++;
1.13      albertel  260:   }
1.34      ng        261:   return (\%classlist,\@sections);
1.5       albertel  262: }
                    263: 
                    264: sub getpartlist {
1.13      albertel  265:   my ($url) = @_;
                    266:   my @parts =();
                    267:   my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
                    268:   foreach my $key (@metakeys) {
1.30      ng        269:     if ( $key =~ m/stores_([0-9]+)_.*/) {
1.13      albertel  270:       push(@parts,$key);
1.6       albertel  271:     }
1.13      albertel  272:   }
                    273:   return @parts;
1.5       albertel  274: }
                    275: 
                    276: sub viewstudentgrade {
1.13      albertel  277:   my ($url,$symb,$courseid,$student,@parts) = @_;
                    278:   my $result ='';
                    279:   my $cellclr = '"#ffffdd"';
1.28      ng        280:   my ($username,$domain) = split(/:/,$student);
1.13      albertel  281: 
1.34      ng        282:   my $fullname = &get_fullname($username,$domain);
1.28      ng        283:   my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$username);
1.32      ng        284: 
1.28      ng        285:   $result.="<tr bgcolor=$cellclr><td>$username</td><td>$fullname</td><td align=\"middle\">$domain</td>\n";
1.13      albertel  286:   foreach my $part (@parts) {
                    287:     my ($temp,$part,$type)=split(/_/,$part);
1.31      ng        288:     my $score=$record{"resource.$part.$type"};
                    289:     if ($type eq 'awarded' || $type eq 'tries') {
                    290:       $result.='<td align="middle"><input type="text" name="GRADE.'.$student.'.'.$part.'.'.$type.
                    291: 	  '" value="'.$score.'" size="4" /></td>'."\n";
1.13      albertel  292:     } elsif ($type eq 'solved') {
1.31      ng        293:       my ($status,$foo)=split(/_/,$score,2);
1.28      ng        294:       $result.="<td align=\"middle\"><select name=\"GRADE.$student.$part.$type\">\n";
1.31      ng        295:       my $optsel = '<option>correct</option><option>incorrect</option><option>excused</option>'.
1.33      ng        296: 	  '<option>ungraded</option><option>partial</option><option>nothing</option>'."\n";
1.31      ng        297:       $status = 'nothing' if ($status eq '');
                    298:       $optsel =~ s/<option>$status/<option selected="on">$status/;
                    299:       $result.=$optsel;
1.13      albertel  300:       $result.="</select></td>\n";
                    301:     }
                    302:   }
1.38    ! ng        303:   $result.='</td></tr>';
1.13      albertel  304:   return $result;
1.5       albertel  305: }
1.31      ng        306: 
                    307: #FIXME need to look at the metadata <stores> spec on what type of data to accept and provide an
1.6       albertel  308: #interface based on that, also do that to above function.
1.5       albertel  309: sub setstudentgrade {
1.13      albertel  310:   my ($url,$symb,$courseid,$student,@parts) = @_;
1.34      ng        311:   print "set student grade parts=@parts<br>";
1.13      albertel  312:   my $result ='';
                    313:   my ($stuname,$domain) = split(/:/,$student);
                    314:   my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$stuname);
                    315:   my %newrecord;
                    316: 
                    317:   foreach my $part (@parts) {
                    318:     my ($temp,$part,$type)=split(/_/,$part);
                    319:     my $oldscore=$record{"resource.$part.$type"};
                    320:     my $newscore=$ENV{"form.GRADE.$student.$part.$type"};
1.32      ng        321:     print "old=$oldscore:new=$newscore:<br>";
1.13      albertel  322:     if ($type eq 'solved') {
                    323:       my $update=0;
                    324:       if ($newscore eq 'nothing' ) {
                    325: 	if ($oldscore ne '') {
                    326: 	  $update=1;
                    327: 	  $newscore = '';
1.6       albertel  328: 	}
1.13      albertel  329:       } elsif ($oldscore !~ m/^$newscore/) {
                    330: 	$update=1;
                    331: 	$result.="Updating $stuname to $newscore<br />\n";
1.34      ng        332: 	if ($newscore eq 'correct')   { $newscore = 'correct_by_override'; }
1.13      albertel  333: 	if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }
1.34      ng        334: 	if ($newscore eq 'excused')   { $newscore = 'excused'; }
                    335: 	if ($newscore eq 'ungraded')  { $newscore = 'ungraded_attempted'; }
                    336: 	if ($newscore eq 'partial')   { $newscore = 'correct_partially_by_override'; }
1.13      albertel  337:       } else {
                    338: 	#$result.="$stuname:$part:$type:unchanged  $oldscore to $newscore:<br />\n";
                    339:       }
                    340:       if ($update) { $newrecord{"resource.$part.$type"}=$newscore; }
                    341:     } else {
                    342:       if ($oldscore ne $newscore) {
                    343: 	$newrecord{"resource.$part.$type"}=$newscore;
                    344: 	$result.="Updating $student"."'s status for $part.$type to $newscore<br />\n";
                    345:       } else {
                    346: 	#$result.="$stuname:$part:$type:unchanged  $oldscore to $newscore:<br />\n";
                    347:       }
                    348:     }
                    349:   }
                    350:   if ( scalar(keys(%newrecord)) > 0 ) {
1.32      ng        351:     $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
1.34      ng        352: #    &Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$stuname);
1.13      albertel  353: 
                    354:     $result.="Stored away ".scalar(keys(%newrecord))." elements.<br />\n";
                    355:   }
                    356:   return $result;
1.2       albertel  357: }
                    358: 
1.33      ng        359: #
1.32      ng        360: # --------------------------- show submissions of a student, option to grade --------
1.2       albertel  361: sub submission {
1.34      ng        362:   my ($request,$counter,$total) = @_;
1.33      ng        363: 
1.38    ! ng        364:   (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
        !           365:   if ($ENV{'form.student'} eq '') { &moreinfo($request,'Need student login id'); return ''; }
        !           366:   my ($uname,$udom) = &finduser($ENV{'form.student'});
        !           367:   if ($uname eq '') { &moreinfo($request,'Unable to find student'); return ''; }
        !           368: 
        !           369:   my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
        !           370:   if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
        !           371:   my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
        !           372: 
        !           373:   # header info
1.34      ng        374:   if ($counter == 0) {
1.38    ! ng        375:       &sub_page_js($request);
        !           376:       $request->print('<h2>&nbsp;<font color="#339933">Submission Record</font></h2>'.
        !           377: 		      '<font size=+1>&nbsp;<b>Resource: </b>'.$url.'</font>');
        !           378: 
        !           379:       # option to display problem, only once else it cause problems with the form later 
        !           380:       # since the problem has a form.
        !           381:       if ($ENV{'form.vProb'} eq 'yes') {
        !           382: 	  my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
        !           383: 							    $ENV{'request.course.id'});
        !           384: 	  my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
        !           385: 								 $ENV{'request.course.id'});
        !           386: 	  my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
        !           387: 	  $result.='<table border="0" width="100%"><tr><td bgcolor="#e6ffff">';
        !           388: 	  $result.='<b>Student\'s view of the problem</b></td></tr><tr><td bgcolor="#ffffff">'.$rendered.'<br />';
        !           389: 	  $result.='<b>Correct answer:</b><br />'.$companswer;
        !           390: 	  $result.='</td></tr></table>';
        !           391: 	  $result.='</td></tr></table><br />';
        !           392: 	  $request->print($result);
        !           393:       }
        !           394: 
        !           395:       # kwclr is the only variable that is non blank if this has been used once.
        !           396:       my %keyhash = ();
        !           397:       if ($ENV{'form.kwclr'} eq '') {
        !           398: 	  %keyhash = &Apache::lonnet::dump('nohist_handgrade',
        !           399: 					      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
        !           400: 					      $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
        !           401: 
        !           402: 	  my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
        !           403: 	  $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
        !           404: 	  $ENV{'form.kwclr'}    = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
        !           405: 	  $ENV{'form.kwsize'}   = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
        !           406: 	  $ENV{'form.kwstyle'}  = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
        !           407: 	  $ENV{'form.msgsub'}   = $keyhash{$symb.'_subject'} ne '' ? 
        !           408: 	      $keyhash{$symb.'_subject'} : &Apache::lonnet::metadata($url,'title');
        !           409: 	  $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
        !           410: 
        !           411:       }
        !           412:       $request->print('<form action="/adm/grades" method="post" name="SCORE">'."\n".
        !           413: 		      '<input type="hidden" name="command"    value="handgrade" />'."\n".
        !           414: 		      '<input type="hidden" name="symb"       value="'.$symb.'" />'."\n".
        !           415: 		      '<input type="hidden" name="url"        value="'.$url.'" />'."\n".
        !           416: 		      '<input type="hidden" name="vProb"      value="'.$ENV{'form.vProb'}.'" />'."\n".
        !           417: 		      '<input type="hidden" name="lastSub"    value="'.$ENV{'form.lastSub'}.'" />'."\n".
        !           418: 		      '<input type="hidden" name="section"    value="'.$ENV{'form.section'}.'">'."\n".
        !           419: 		      '<input type="hidden" name="submitonly" value="'.$ENV{'form.submitonly'}.'">'."\n".
        !           420: 		      '<input type="hidden" name="response"   value="'.$ENV{'form.response'}.'">'."\n".
        !           421: 		      '<input type="hidden" name="handgrade"  value="'.$ENV{'form.handgrade'}.'">'."\n".
        !           422: 		      '<input type="hidden" name="keywords"   value="'.$ENV{'form.keywords'}.'" />'."\n".
        !           423: 		      '<input type="hidden" name="kwclr"      value="'.$ENV{'form.kwclr'}.'" />'."\n".
        !           424: 		      '<input type="hidden" name="kwsize"     value="'.$ENV{'form.kwsize'}.'" />'."\n".
        !           425: 		      '<input type="hidden" name="kwstyle"    value="'.$ENV{'form.kwstyle'}.'" />'."\n".
        !           426: 		      '<input type="hidden" name="msgsub"     value="'.$ENV{'form.msgsub'}.'" />'."\n".
        !           427: 		      '<input type="hidden" name="savemsgN"   value="'.$ENV{'form.savemsgN'}.'" />'."\n".
        !           428: 		      '<input type="hidden" name="NCT"'.
        !           429: 		      ' value="'.($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : $total+1).'" />'."\n");
        !           430: 
        !           431:       my ($cts,$prnmsg) = (1,'');
        !           432:       while ($cts <= $ENV{'form.savemsgN'}) {
        !           433: 	  $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
        !           434: 	      ($keyhash{$symb.'_savemsg'.$cts} eq '' ? $ENV{'form.savemsg'.$cts} : $keyhash{$symb.'_savemsg'.$cts}).
        !           435: 	      '" />'."\n";
        !           436: 	  $cts++;
        !           437:       }
        !           438:       $request->print($prnmsg);
1.32      ng        439: 
1.38    ! ng        440:       if ($ENV{'form.handgrade'} eq 'yes') {
        !           441: 	  $request->print(<<KEYWORDS);
        !           442: &nbsp;<b>Keyword Options:</b>&nbsp;
        !           443: <a href="javascript:keywords(document.SCORE.keywords)"; TARGET=_self>List</a>&nbsp; &nbsp;
        !           444: <a href="#" onMouseDown="javascript:getSel(); return false"
        !           445:  CLASS="page">Paste Selection to List</a>&nbsp; &nbsp;
        !           446: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
        !           447: KEYWORDS
        !           448:       }
1.33      ng        449:   }
                    450: 
1.38    ! ng        451:   # Student info
        !           452:   $request->print(($counter == 0 ? '' : '<br />'));
        !           453:   my $fullname = ($ENV{'form.fullname'} ne '' ? $ENV{'form.fullname'} : &get_fullname($uname,$udom));
        !           454:   my $result.='<table border="0" width=100%><tr><td bgcolor="#777777">'.
        !           455:       '<table border="0" width=100%><tr bgcolor="#ffffff"><td>';
        !           456:   $result.='<table border="0"><tr bgcolor="#ffffff"><td><b>Username: </b>'.$uname.
        !           457:       '</td><td><b>Fullname: </b>'.$fullname.
        !           458: 	      '</td><td><b>Domain: </b>'.$udom.'</td></tr>';
        !           459:   if ($ENV{'form.handgrade'} eq 'yes') {
        !           460: #      my $subonly = &get_last_submission($symb,$uname,$udom,$ENV{'request.course.id'});
        !           461:       my ($classlist) = &getclasslist('all','0');
        !           462:       my @collaborators;
        !           463: #      foreach ( sort(@{ $$classlist{'all'} }) ) {
        !           464: #	  my ($sname,$sdom) = split(/:/);
        !           465: #	  push @collaborators,$sname if (grep /\b$sname(\b|\.)/i,$subonly);
        !           466: #      }
        !           467: #      push @collaborators,'leede','carlandmm','freyniks'; # as a test to display collaborators.
        !           468:       if (scalar(@collaborators) != 0) {
        !           469: 	  $result.='<tr bgcolor="#ffffff"><td colspan=3><b>Collaborators: </b>';
        !           470: 	  foreach (@collaborators) {
        !           471: 	      $result.=$_.' ('.&get_fullname($_,$udom).') &nbsp; &nbsp;';
        !           472: 	  }
        !           473: 	  $result.='</td></tr>'."\n";
        !           474: 	  $result.='<input type="hidden" name="collaborator'.$counter.
        !           475: 	      '" value="'.(join ':',@collaborators).'" />'."\n";
        !           476:       }
1.33      ng        477:   }
1.38    ! ng        478:   $result.='</table>'."\n";
        !           479:   $request->print($result);
1.33      ng        480: 
1.38    ! ng        481:  # print student answer
        !           482:   if ($ENV{'form.lastSub'} eq 'lastonly') {
        !           483:       my ($string,$timestamp)=&get_last_submission ($symb,$uname,$udom,$ENV{'request.course.id'});
        !           484:       $string=&keywords_highlight(join('::::',@$string));
        !           485:       my $lastsubonly='<table border="0" width=100%><tr><td bgcolor="#777777">';
        !           486:       $lastsubonly.='<table border="0" width=100%><tr bgcolor="#ddffff">';
        !           487:       $lastsubonly.='<td><b>Last Submission Only</b>'.
        !           488: 	  ($timestamp eq '' ? '' : '&nbsp; &nbsp; <b>Date Submitted:</b> '.@$timestamp).'</td></tr>';
        !           489:       $lastsubonly.='<tr><td bgcolor="#ffffe6">';
        !           490:       $lastsubonly.=$string;
        !           491:       $lastsubonly.='</td></tr></table></td></tr></table>'."\n";
        !           492:       $request->print($lastsubonly);
        !           493:   } else {
        !           494:       $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
        !           495: 							       $ENV{'request.course.id'},$last,
        !           496: 							       '.submission','Apache::grades::keywords_highlight'));
1.33      ng        497:   }
1.32      ng        498: 
1.38    ! ng        499:   my $wgt    = &Apache::lonnet::EXT('resource.partid.weight',$symb,$udom,$uname);
        !           500:   my $wgtmsg = ($wgt > 0 ? '(problem weight)' : '<font color="red">problem weight assigned by computer</font>');
        !           501:   $wgt       = ($wgt > 0 ? $wgt : '1');
        !           502:   my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
        !           503:   my $score  = ($record{'resource.0.awarded'} eq '' ? '' : $record{'resource.0.awarded'}*$wgt);
        !           504: 
        !           505:   # display grading options
        !           506:   $result='<input type="hidden" name="WGT'.$counter.'" value="'.$wgt.'" />'.
        !           507:       '<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'.$udom.'" />'."\n";
        !           508:   $result.='<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
        !           509:   $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n";
        !           510:   $result.='<table border="0"><tr><td><b>Points</b></td><td>';
        !           511: 
        !           512:   my $ctr = 0;
        !           513:   $result.='<table border="0"><tr>';  # display radio buttons in a nice table with 10 across
        !           514:   while ($ctr<=$wgt) {
        !           515:       $result.= '<td><input type="radio" name="RADVAL'.$counter.'" '.
        !           516: 	  'onclick="javascript:writeBox(this.form.GRADE_BOX'.$counter.
        !           517: 	    ',this.form.GRADE_SEL'.$counter.','.$ctr.','.$wgt.')" '.
        !           518: 		($score eq $ctr ? 'checked':'').' /> '.$ctr."</td>\n";
        !           519:       $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
        !           520:       $ctr++;
1.35      ng        521:   }
1.38    ! ng        522:   $result.='</tr></table>';
1.35      ng        523: 
1.38    ! ng        524:   $result.='</td><td>&nbsp;<b>or</b>&nbsp;</td>';
        !           525:   $result.='<td><input type="text" name="GRADE_BOX'.$counter.'"'.
        !           526:       ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
        !           527:        'onChange="javascript:updateRadio(this.form.RADVAL'.$counter.
        !           528:         ',this.form.GRADE_BOX'.$counter.
        !           529: 	   ',this.form.GRADE_SEL'.$counter.',\''.$wgt.'\')" /></td>'."\n";
        !           530:   $result.='<td>/'.$wgt.' '.$wgtmsg.' </td><td>';
        !           531: 
        !           532:   foreach my $part (&getpartlist($url)) {
        !           533:       print "parts=$part<br>";
        !           534:     my ($temp,$part,$type)=split(/_/,$part);
        !           535:     if ($type eq 'solved') {
        !           536:       my ($status,$foo)=split(/_/,$record{"resource.$part.$type"},2);
        !           537:       $status = 'partial' if ($foo =~ /partially/);
        !           538:       $status = 'nothing' if ($status eq '');
        !           539:       $result.='<select name="GRADE_SEL'.$counter.'">'."\n";
        !           540:       my $optsel = '<option>correct</option><option>incorrect</option>'.
        !           541: 	  '<option>excused</option><option>ungraded</option>'.
        !           542: 	      '<option>partial</option><option>nothing</option>'."\n";
        !           543:       $optsel =~ s/<option>$status/<option selected="on">$status/;
        !           544:       $result.=$optsel;
        !           545:       $result.="</select>&nbsp&nbsp\n";
1.36      ng        546:     }
1.38    ! ng        547:   }
        !           548:   $result.='<a href="javascript:msgCenter(document.SCORE,'.$counter.
        !           549:       ',\''.$fullname.'\')"; TARGET=_self>Compose Message</a></td></tr></table>'."\n";
        !           550: #  $result.='</table>';
        !           551:   $result.='</td></tr></table></td></tr></table>';
        !           552:   $request->print($result);
        !           553: 
        !           554:   # print end of form
        !           555:   if ($counter == $total) {
        !           556:       my $endform.='<table border="0"><tr><td><input type="submit" name="gradeOpt" value="Save & Next" />';
        !           557:       my $ntstu ='<select name="NTSTU">'.
        !           558: 	  '<option>1</option><option>2</option>'.
        !           559: 	      '<option>3</option><option>5</option>'.
        !           560: 		  '<option>7</option><option>10</option></select>'."\n";
        !           561:       my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
        !           562:       $ntstu =~ s/<option>$nsel/<option selected="on">$nsel/;
        !           563:       $endform.=$ntstu.'student(s) &nbsp;&nbsp;';
        !           564:       $endform.='<input type="submit" name="gradeOpt" value="Next" />&nbsp';
        !           565:       $endform.='<input type="submit" name="gradeOpt" value="Previous" />&nbsp';
        !           566:       $endform.='(Next and Previous do not save the scores.)';
        !           567:       $endform.='</td><tr></table></form>';
        !           568:       $request->print($endform);
1.36      ng        569:   }
                    570: 
1.38    ! ng        571:   return '';
        !           572: }
        !           573: 
        !           574: sub get_last_submission {
        !           575:   my ($symb,$username,$domain,$course)=@_;
        !           576:   if ($symb) {
        !           577:       my (@string,@timestamp);
        !           578:      my (%returnhash)=&Apache::lonnet::restore($symb,$course,$domain,$username);
        !           579:      if ($returnhash{'version'}) {
        !           580: 	my %lasthash=();
        !           581: 	my ($version);
        !           582: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
        !           583: 	  foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
        !           584: 	      $lasthash{$_}=$returnhash{$version.':'.$_};
        !           585: 	  }
        !           586:         }
        !           587: 	foreach ((keys %lasthash)) {
        !           588: 	    print "lasthash key=$_<br>";
        !           589: 	    if ($_ =~ /\.submission$/) {push @string, $_,$lasthash{$_}}
        !           590: 	    if ($_ =~ /timestamp/) {push @timestamp, scalar(localtime($lasthash{$_}))};
        !           591: #	    if ($_ =~ /\.submission$/) {$string = $lasthash{$_}}
        !           592: #	    if ($_ =~ /timestamp/) {$timestamp=scalar(localtime($lasthash{$_}))};
        !           593: 	}
1.36      ng        594:     }
1.38    ! ng        595:      @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string;
        !           596:      return \@string,\@timestamp;
1.35      ng        597:   }
1.38    ! ng        598: }
1.35      ng        599: 
1.38    ! ng        600: sub keywords_highlight {
        !           601:   my $string  = shift;
        !           602:   my $size    = $ENV{'form.kwsize'} eq '0' ? '' : 'size='.$ENV{'form.kwsize'};
        !           603:   my $styleon = $ENV{'form.kwstyle'} eq ''  ? '' : $ENV{'form.kwstyle'};
        !           604:   (my $styleoff = $styleon) =~ s/\</\<\//;
        !           605:   my @keylist = split(/[,\s+]/,$ENV{'form.keywords'});
        !           606:   foreach (@keylist) {
        !           607:  #     next if ($_ eq '');
        !           608:       $string =~ s/\b$_(\b|\.)/\<font color\=$ENV{'form.kwclr'} $size\>$styleon$_$styleoff\<\/font\>/gi;
        !           609:   }
        !           610:   return $string;
        !           611: }
1.36      ng        612: 
1.38    ! ng        613: sub processHandGrade {
        !           614:   my ($request) = shift;
        !           615:   my $url    = $ENV{'form.url'};
        !           616:   my $symb   = $ENV{'form.symb'};
        !           617:   my $button = $ENV{'form.gradeOpt'};
        !           618:   my $ngrade = $ENV{'form.NCT'};
        !           619:   my $ntstu  = $ENV{'form.NTSTU'};
        !           620: 
        !           621:   my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
        !           622:   my %keyhash = ();
        !           623:   $ENV{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
        !           624:   $keyhash{$symb.'_handgrade'} = 'activated';
        !           625:   $keyhash{$symb.'_keywords'} = $ENV{'form.keywords'};
        !           626:   $keyhash{$symb.'_subject'} = $ENV{'form.msgsub'};
        !           627:   $keyhash{$loginuser.'_kwclr'} = $ENV{'form.kwclr'};
        !           628:   $keyhash{$loginuser.'_kwsize'} = $ENV{'form.kwsize'};
        !           629:   $keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
        !           630: 
        !           631:   my ($ctr,$idx) = (1,1);
        !           632:   while ($ctr <= $ENV{'form.savemsgN'}) {
        !           633:       if ($ENV{'form.savemsg'.$ctr} ne '') {
        !           634: 	  $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
        !           635: 	  $idx++;
        !           636:       }
        !           637:       $ctr++;
        !           638:   }
        !           639:   $ctr = 0;
        !           640:   while ($ctr < $ngrade) {
        !           641:       if ($ENV{'form.newmsg'.$ctr} ne '') {
        !           642: 	  $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
        !           643: 	  $ENV{'form.savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
        !           644: 	  $idx++;
        !           645:       }
        !           646:       $ctr++;
        !           647:   }
        !           648:   $ENV{'form.savemsgN'} = --$idx;
        !           649:   $keyhash{$symb.'_savemsgN'} = $ENV{'form.savemsgN'};
        !           650:   my $putresult = &Apache::lonnet::put
        !           651:       ('nohist_handgrade',\%keyhash,
        !           652:        $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
        !           653:        $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.36      ng        654: 
1.38    ! ng        655:   my (@parts) = sort(&getpartlist($url));
1.36      ng        656: 
1.38    ! ng        657:   if ($button eq 'Save & Next') {
        !           658:       my $ctr = 0;
        !           659:       while ($ctr < $ngrade) {
        !           660: 	  my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
        !           661: 	  &saveHandGrade($url,$symb,$uname,$udom,$ctr,@parts);
1.36      ng        662: 
1.38    ! ng        663: 	  my $includemsg = $ENV{'form.includemsg'.$ctr};
        !           664: 	  my ($subject,$message,$msgstatus) = ('','','');
        !           665: 	  if ($includemsg =~ /savemsg|new$ctr/) {
        !           666: 	      $subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/);
        !           667: 	      my (@msgnum) = split(/,/,$includemsg);
        !           668: 	      foreach (@msgnum) {
        !           669: 		  $message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
        !           670: 	      }
        !           671: 	      $message =~ s/\s+/ /g;
        !           672: 	      $msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,$ENV{'form.msgsub'},$message);
        !           673: 	  }
        !           674: 	  if ($ENV{'form.collaborator'.$ctr}) {
        !           675: 	      my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
        !           676: 	      foreach (@collaborators) {
        !           677: 		  &saveHandGrade($url,$symb,$_,$udom,$ctr,@parts);
        !           678: 		  if ($message ne '') {
        !           679: 		      $msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,$ENV{'form.msgsub'},$message);
        !           680: 		  }
        !           681: 	      }
        !           682: 	  }
        !           683: 	  $ctr++;
        !           684:       }
        !           685:   }
        !           686:   my $firststu = $ENV{'form.unamedom0'};
        !           687:   my $laststu  = $ENV{'form.unamedom'.($ngrade-1)};
1.36      ng        688: 
1.38    ! ng        689:   my ($classlist) = &getclasslist($ENV{'form.section'},'0');
        !           690:   my (@nextlist,@prevlist);
        !           691:   my ($nextflg,$prevflg,$ctr,$ctprev) = (0,0,0,0);
        !           692:   foreach my $student ( sort(@{ $$classlist{$ENV{'form.section'}} }) ) {
        !           693:       my ($uname,$udom) = split(/:/,$student);
        !           694:       my ($type,$status) = &student_gradeStatus($ENV{'form.url'},$udom,$uname);
        !           695:       next if ($status eq 'nothing' && $ENV{'form.submitonly'} eq 'yes');
1.36      ng        696: 
1.38    ! ng        697:       if ($nextflg == 1 && $button =~ /Next$/) {
        !           698: 	  push @nextlist,$uname if ($ctr < $ntstu);
        !           699: 	  $ctr++;
        !           700:       }
        !           701:       $nextflg = 1 if ($student eq $laststu);
        !           702:       $prevflg = 1 if ($student eq $firststu);
        !           703:       if ($prevflg == 0 && $button eq 'Previous') {
        !           704: 	  push @prevlist,$uname;
        !           705: 	  $ctprev++;
        !           706:       }
        !           707:   }
        !           708:   if ($button eq 'Previous') {
        !           709:       if ($ctprev <= $ntstu) {
        !           710: 	  @nextlist = @prevlist;
        !           711:       } else {
        !           712: 	  my $idx = 0;
        !           713: 	  my $start = $ctprev - $ntstu;
        !           714: 	  while ($idx < $ntstu) {
        !           715: 	      $nextlist[$idx] = $prevlist[$start+$idx];
        !           716: 	      $idx++;
        !           717: 	  }
        !           718:       }
        !           719:   }
        !           720:   $ctr = 0;
        !           721:   my $total = scalar(@nextlist)-1;
        !           722:   foreach my $student (@nextlist) {
        !           723:       $ENV{'form.student'} = $student;
        !           724:       &submission($request,$ctr,$total);
        !           725:       $ctr++;
        !           726:   }
        !           727:   if ($total < 0) {
        !           728:       my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
        !           729:       $the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
        !           730:       $the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
        !           731:       $the_end.=&show_grading_menu_form ($symb,$url);
        !           732:       $request->print($the_end);
        !           733:   }
        !           734:   return '';
        !           735: }
1.36      ng        736: 
1.38    ! ng        737: sub saveHandGrade {
        !           738:   my ($url,$symb,$stuname,$domain,$newflg,@parts) = @_;
        !           739:   my %record=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
        !           740:   my %newrecord;
1.36      ng        741: 
1.38    ! ng        742:   foreach my $part (@parts) {
        !           743:     my ($temp,$part,$type)=split(/_/,$part);
        !           744:     my $oldscore=$record{"resource.$part.$type"};
        !           745:     my $newscore;
        !           746:     if ($type eq 'awarded' && $newflg >= 0) {
        !           747: 	my $pts    = ($ENV{'form.GRADE_BOX'.$newflg} ne '' ? 
        !           748: 		      $ENV{'form.GRADE_BOX'.$newflg} : $ENV{'form.RADVAL'.$newflg});
        !           749: 	my $wgt    = $ENV{'form.WGT'.$newflg};
        !           750: #	my $sel    = $ENV{'form.GRADE_SEL'.$newflg};
        !           751: 	$newscore  = $pts/$wgt if ($wgt != 0);
        !           752:     }
        !           753:     if ($type eq 'solved') {
        !           754:       $newscore = $ENV{'form.GRADE_SEL'.$newflg} if ($newflg >= 0);
        !           755:       my $update=0;
        !           756:       if ($newscore eq 'nothing' ) {
        !           757: 	if ($oldscore ne '') {
        !           758: 	  $update=1;
        !           759: 	  $newscore = '';
        !           760: 	}
        !           761:       } elsif ($oldscore !~ m/^$newscore/) {
        !           762: 	$update=1;
        !           763: 	if ($newscore eq 'correct')   { $newscore = 'correct_by_override'; }
        !           764: 	if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }
        !           765: 	if ($newscore eq 'excused')   { $newscore = 'excused'; }
        !           766: 	if ($newscore eq 'ungraded')  { $newscore = 'ungraded_attempted'; }
        !           767: 	if ($newscore eq 'partial')   { $newscore = 'correct_partially_by_override'; }
        !           768:       }
        !           769:       if ($update) { $newrecord{"resource.$part.$type"}=$newscore; }
        !           770:     } else {
        !           771:       if ($oldscore ne $newscore) {
        !           772: 	$newrecord{"resource.$part.$type"}=$newscore;
        !           773:       }
        !           774:     }
        !           775:   }
        !           776:   if ( scalar(keys(%newrecord)) > 0 ) {
        !           777:       $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
        !           778: #      while (my ($k,$v) = each %newrecord) {
        !           779: #	 print "k=$k:v=$v:<br>\n";
        !           780: #      }
        !           781: #      print "symb=$symb,courseid=$ENV{'request.course.id'},dom=$domain,name=$stuname<br>";
        !           782: #     &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},$domain,$stuname);
        !           783:   }
        !           784:   return '';
1.36      ng        785: }
1.38    ! ng        786: 
        !           787: sub get_symb_and_url {
        !           788:   my ($request) = @_;
        !           789:   (my $url=$ENV{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
        !           790:   my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
        !           791:   if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
        !           792:   return ($symb,$url);
1.36      ng        793: }
                    794: 
1.38    ! ng        795: sub show_grading_menu_form {
        !           796:   my ($symb,$url)=@_;
        !           797:   my $result.='<form action="/adm/grades" method="post">'."\n".
        !           798:     '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
        !           799:       '<input type="hidden" name="url" value="'.$url.'" />'."\n".
        !           800: 	'<input type="hidden" name="command" value="gradingmenu" />'."\n".
        !           801: 	  '<input type="submit" name="submit" value="Grading Menu" />'."\n".
        !           802: 	    '</form>'."\n";
        !           803:   return $result;
1.36      ng        804: }
                    805: 
1.38    ! ng        806: sub gradingmenu {
        !           807:   my ($request) = @_;
        !           808:   my ($symb,$url)=&get_symb_and_url($request);
        !           809:   if (!$symb) {return '';}
        !           810:   my $allkeys = &Apache::lonnet::metadata($url,'keys');
        !           811:   my $handgrade = ($allkeys =~ /parameter_.*?_handgrade/ ? 'yes' : 'no');
        !           812:   my ($responsetype,$foo) = split(/_/,&Apache::lonnet::metadata($url,'packages'));
        !           813:   $allkeys=~s/,/\<br\>/g;
        !           814: #  print "allkeys=$allkeys<br><br>";
        !           815:   $Apache::lonxml::debug=1;
        !           816:   &Apache::lonxml::debug(join(':',&Apache::lonnet::metadata($url,'packages')));
        !           817:   $Apache::lonxml::debug=0;
        !           818: 
        !           819:   my $result='<h2>&nbsp;<font color="#339933">Select a Grading Method</font></h2>';
        !           820:   $result.='<table border="0">';
        !           821:   $result.='<tr><td><font size=+1><b>Resource: </b></font></td>'.
        !           822:       '<td><font size=+1>'.$url.'</font></td></tr>';
        !           823:   $result.='<tr><td><font size=+1><b>Type: </b></font></td>'.
        !           824:       '<td><font size=+1>'.$responsetype.'&nbsp;&nbsp;<b>Handgrade: </b>'.$handgrade.'</font></td></tr>';
        !           825:   $result.='</table>';
        !           826:   my $t0=&Time::HiRes::time();
        !           827:   $result.=&view_edit_entire_class_form($symb,$url).'<br />';
        !           828:   my $t1=&Time::HiRes::time();
        !           829:   print "elapsed10=",$t1-$t0,"<br />";
        !           830:   $result.=&upcsvScores_form($symb,$url).'<br />';
        !           831:   my $t2=&Time::HiRes::time();
        !           832:   print "elapsed21=",$t2-$t1,"<br />";
        !           833:   $result.=&viewGradeaStu_form($symb,$url,$responsetype,$handgrade).'<br />';
        !           834:   my $t3=&Time::HiRes::time();
        !           835:   print "elapsed32=",$t3-$t2,"<br />";
        !           836:   $result.=&verifyReceipt_form($symb,$url);
        !           837:   my $t4=&Time::HiRes::time();
        !           838:   print "elapsed43=",$t4-$t3,"<br />";
        !           839:   print "Total elapsed time=",$t4-$t0,"<br />";
        !           840:   return $result;
1.36      ng        841: }
                    842: 
1.38    ! ng        843: sub view_edit_entire_class_form {
        !           844:   my ($symb,$url)=@_;
        !           845:   my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
        !           846:   $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
        !           847:   $result.='&nbsp;<b>View/Grade Entire Class</b></td></tr>'."\n";
        !           848:   $result.='<tr bgcolor=#ffffe6><td>'."\n";
        !           849:   $result.='<form action="/adm/grades" method="post">'."\n".
        !           850:     '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
        !           851:       '<input type="hidden" name="url" value="'.$url.'" />'."\n".
        !           852: 	  '<input type="hidden" name="command" value="viewgrades" />'."\n";
        !           853:   $result.='&nbsp;<b>Display students who has: </b>'.
        !           854:       '<input type="radio" name="submitonly" value="yes" checked> submitted'.
        !           855: 	  '<input type="radio" name="submitonly" value="all"> everybody <br /><br />';
        !           856:   $result.='&nbsp;<input type="submit" name="submit" value="View/Grade" /></form>'."\n";
        !           857:   $result.='</td></tr></table>'."\n";
        !           858:   $result.='</td></tr></table>'."\n";
        !           859:   return $result;
1.36      ng        860: }
                    861: 
1.38    ! ng        862: sub upcsvScores_form {
        !           863:   my ($symb,$url) = @_;
        !           864:   if (!$symb) {return '';}
        !           865:   my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
        !           866:   $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
        !           867:   $result.='&nbsp;<b>Specify a file containing the class scores for above resource</b></td></tr>'."\n";
        !           868:   $result.='<tr bgcolor=#ffffe6><td>'."\n";
        !           869:   my $upfile_select=&Apache::loncommon::upfile_select_html();
        !           870:   $result.=<<ENDUPFORM;
        !           871: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
        !           872: <input type="hidden" name="symb" value="$symb" />
        !           873: <input type="hidden" name="url" value="$url" />
        !           874: <input type="hidden" name="command" value="csvuploadmap" />
        !           875: $upfile_select
        !           876: <br />&nbsp;<input type="submit" name="submit" value="Upload Grades" />
        !           877: </form>
        !           878: ENDUPFORM
        !           879:   $result.='</td></tr></table>'."\n";
        !           880:   $result.='</td></tr></table>'."\n";
        !           881:   return $result;
        !           882: }
        !           883: 
        !           884: sub viewGradeaStu_form {
        !           885:   my ($symb,$url,$response,$handgrade) = @_;
1.35      ng        886: 
1.36      ng        887: 
1.38    ! ng        888:   my $t3=&Time::HiRes::time();
1.36      ng        889: 
1.38    ! ng        890:   my ($classlist,$sections) = &getclasslist('all','0');
1.36      ng        891: 
1.38    ! ng        892:   my $t4=&Time::HiRes::time();
        !           893:   print "elapsed_getclasslist=",$t4-$t3,"<br />";
1.36      ng        894: 
                    895: 
1.38    ! ng        896:   my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
        !           897:   $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
        !           898:   $result.='&nbsp;<b>View/Grade an Individual Student\'s Submission</b></td></tr>'."\n";
        !           899:   $result.='<tr bgcolor=#ffffe6><td>'."\n";
        !           900:   $result.='<form action="/adm/grades" method="post">'."\n".
        !           901:      '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
        !           902:       '<input type="hidden" name="url" value="'.$url.'" />'."\n".
        !           903:        '<input type="hidden" name="response" value="'.$response.'" />'."\n".
        !           904:         '<input type="hidden" name="handgrade" value="'.$handgrade.'" />'."\n".
        !           905: 	 '<input type="hidden" name="command" value="submission" />'."\n";
1.36      ng        906: 
1.38    ! ng        907:   $result.='&nbsp;<b>Select section:</b> <select name="section">'."\n";
        !           908:   foreach my $section (sort (@$sections)) {
        !           909:       $result.= '<option>'.$section.'</option>'."\n";
        !           910:   }
        !           911:   $result.= '<option selected="on">all</select>'."\n";
        !           912:   $result.='&nbsp;&nbsp;<b>Display students who has: </b>'.
        !           913:       '<input type="radio" name="submitonly" value="yes" checked> submitted'.
        !           914: 	  '<input type="radio" name="submitonly" value="all"> everybody <br />';
        !           915:   $result.='&nbsp;(Section "no" implies the students were not assigned a section.)<br />' 
        !           916:       if (grep /no/,@$sections);
1.36      ng        917: 
1.38    ! ng        918:   $result.='<br />&nbsp;<input type="submit" name="submit" value="View/Grade" />'."\n".
        !           919:       '</form>'."\n";
        !           920:   $result.='</td></tr></table>'."\n";
        !           921:   $result.='</td></tr></table>'."\n";
        !           922:   return $result;
1.36      ng        923: }
                    924: 
1.38    ! ng        925: sub verifyReceipt_form {
        !           926:   my ($symb,$url) = @_;
        !           927:   my $cdom=$ENV{"course.$ENV{'request.course.id'}.domain"};
        !           928:   my $cnum=$ENV{"course.$ENV{'request.course.id'}.num"};
        !           929:   my $hostver=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'});
1.36      ng        930: 
1.38    ! ng        931:   my $result.='<table width=100% border=0><tr><td bgcolor=#777777>'."\n";
        !           932:   $result.='<table width=100% border=0><tr><td bgcolor=#e6ffff>'."\n";
        !           933:   $result.='&nbsp;<b>Verify a Submission Receipt Issued by this Server</td></tr>'."\n";
        !           934:   $result.='<tr bgcolor=#ffffe6><td>'."\n";
        !           935:   $result.='<form action="/adm/grades" method="post">'."\n";
        !           936:   $result.='&nbsp;<tt>'.$hostver.'-<input type="text" name="receipt" size="4"></tt><br />'."\n";
        !           937:   $result.='&nbsp;<input type="submit" name="submit" value="Verify Receipt">'."\n";
        !           938:   $result.='<input type="hidden" name="command" value="verify">'."\n";
        !           939:   if ($ENV{'form.url'}) {
        !           940:       $result.='<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />';
        !           941:   }
        !           942:   if ($ENV{'form.symb'}) {
        !           943:       $result.='<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />';
        !           944:   }
        !           945:   $result.='</form>';
        !           946:   $result.='</td></tr></table>'."\n";
        !           947:   $result.='</td></tr></table>'."\n";
        !           948:   return $result;
1.36      ng        949: }
                    950: 
1.38    ! ng        951: sub viewgrades {
        !           952:   my ($request) = @_;
        !           953:   my $result='';
        !           954: 
        !           955:   #get resource reference
        !           956:   my ($symb,$url)=&get_symb_and_url($request);
        !           957:   if (!$symb) {return '';}
        !           958:   #get classlist
        !           959:   my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
        !           960:   #print "Found $cdom:$cnum<br />";
        !           961:   my ($classlist) = &getclasslist('all','0');
        !           962:   my $headerclr = '"#ddffff"';
        !           963:   my $cellclr = '"#ffffdd"';
        !           964: 
        !           965:   #get list of parts for this problem
        !           966:   my (@parts) = sort(&getpartlist($url));
1.32      ng        967: 
1.38    ! ng        968:   $request->print ("<h2><font color=\"#339933\">Manual Grading</font></h2>");
1.37      ng        969: 
1.38    ! ng        970:   #start the form
        !           971:   $result = '<form action="/adm/grades" method="post">'."\n".
        !           972:     '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
        !           973:       '<input type="hidden" name="url" value="'.$url.'" />'."\n".
        !           974: 	'<input type="hidden" name="command" value="editgrades" />'."\n".
        !           975: 	  '<input type="submit" name="submit" value="Submit Changes" />'."\n".
        !           976: 	    '<table border=0><tr><td bgcolor="#777777">'."\n".
        !           977: 	     '<table border=0>'."\n".
        !           978: 	      '<tr bgcolor='.$headerclr.'><td><b>Username</b></td><td><b>Fullname</b></td><td><b>Domain</b></td>'."\n";
        !           979:   foreach my $part (@parts) {
        !           980:      my $display=&Apache::lonnet::metadata($url,$part.'.display');
        !           981:      if  (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
        !           982:      $result.='<td><b>'.$display.'</b></td>'."\n";
        !           983:   }
        !           984:   $result.='</tr>';
        !           985:   #get info for each student
        !           986:   foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
        !           987: #    my $display=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
        !           988: #      print "ID=$ENV{'request.course.id'}:STU=$student:DIS=$display:<br>\n";
        !           989:     $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
1.34      ng        990:   }
1.38    ! ng        991:   $result.='</table></td></tr></table>';
        !           992:   $result.='<input type="submit" name="submit" value="Submit Changes" /></form>';
        !           993:   $result.=&show_grading_menu_form($symb,$url);
        !           994:   return $result;
        !           995: }
        !           996: 
        !           997: sub editgrades {
        !           998:   my ($request) = @_;
        !           999:   my $result='';
1.34      ng       1000: 
1.38    ! ng       1001:   my $symb=$ENV{'form.symb'};
        !          1002:   if ($symb eq '') { $request->print("Unable to handle ambiguous references:$symb:$ENV{'form.url'}"); return ''; }
        !          1003:   my $url=$ENV{'form.url'};
        !          1004:   #get classlist
        !          1005: #  my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
        !          1006:   #print "Found $cdom:$cnum<br />";
        !          1007:   my ($classlist) = &getclasslist('all','0');
1.37      ng       1008: 
1.38    ! ng       1009:   #get list of parts for this problem
        !          1010:   my (@parts) = &getpartlist($url);
1.37      ng       1011: 
1.38    ! ng       1012:   $result.='<form action="/adm/grades" method="post">'."\n".
        !          1013:     '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
        !          1014:       '<input type="hidden" name="url" value="'.$url.'" />'."\n".
        !          1015: 	'<input type="hidden" name="command" value="viewgrades" />'."\n".
        !          1016: 	  '<input type="submit" name="submit" value="See Grades" /> <br />'."\n";
1.35      ng       1017: 
1.38    ! ng       1018:   foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
        !          1019:     $result.=&setstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
1.30      ng       1020:   }
1.35      ng       1021: 
1.38    ! ng       1022:   $result.='<input type="submit" name="submit" value="See Grades" /></table></form>';
        !          1023:   return $result;
        !          1024: }
        !          1025: 
        !          1026: sub sub_page_js {
        !          1027:   my $request = shift;
        !          1028:   $request->print(<<SUBJAVASCRIPT);
        !          1029: <script type="text/javascript" language="javascript">
        !          1030:   function updateRadio(radioButton,formtextbox,formsel,wgt) {
        !          1031:      var pts = formtextbox.value;
        !          1032:      var resetbox =false;
        !          1033:      if (isNaN(pts) || pts < 0) {
        !          1034: 	alert("A number equal or greater than 0 is expected. Entered value = "+pts);
        !          1035: 	for (var i=0; i<radioButton.length; i++) {
        !          1036: 	   if (radioButton[i].checked) {
        !          1037: 	      formtextbox.value = i;
        !          1038: 	      resetbox = true;
        !          1039: 	   }
        !          1040: 	}
        !          1041: 	if (!resetbox) {
        !          1042: 	   formtextbox.value = "";
        !          1043: 	}
        !          1044: 	return;
        !          1045:     }
1.37      ng       1046: 
1.38    ! ng       1047:     for (var i=0; i<radioButton.length; i++) {
        !          1048: 	radioButton[i].checked=false;
        !          1049: 	if (pts == i) {
        !          1050: 	   radioButton[i].checked=true;
        !          1051: 	}
        !          1052:     }
        !          1053:     updateSelect(formsel,pts,wgt);
1.37      ng       1054:   }
                   1055: 
1.38    ! ng       1056:   function writeBox(formrad,formsel,pts,wgt) {
        !          1057:     formrad.value = pts;
        !          1058:     updateSelect(formsel,pts,wgt);
        !          1059:     return;
1.31      ng       1060:   }
1.34      ng       1061: 
1.38    ! ng       1062:   function updateSelect(formsel,pts,wgt) {
        !          1063:     if (pts == 0) {
        !          1064:       formsel[1].selected = true;
        !          1065:     }
        !          1066:     if (pts > 0 && pts < wgt) {
        !          1067:       formsel[4].selected = true;
        !          1068:     }
        !          1069:     if (pts == wgt) {
        !          1070:       formsel[0].selected = true;
1.33      ng       1071:     }
1.38    ! ng       1072:     return;
1.33      ng       1073:   }
1.37      ng       1074: 
1.38    ! ng       1075:   function keywords(keyform) {
        !          1076:     var keywds = keyform.value;
        !          1077:     var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keywds);
        !          1078:     if (nret==null) return;
        !          1079:     keyform.value = nret;
        !          1080:     return;
1.34      ng       1081:   }
1.30      ng       1082: 
1.38    ! ng       1083: //===================== Script to add keyword(s) ==================
        !          1084:   function getSel() {
        !          1085:     if (document.getSelection) txt = document.getSelection();
        !          1086:     else if (document.selection) txt = document.selection.createRange().text;
        !          1087:     else return;
        !          1088:     var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
        !          1089:     if (cleantxt=="") {
        !          1090: 	alert("Select a word or group of words from document and then click this link.");
        !          1091: 	return;
1.35      ng       1092:     }
1.38    ! ng       1093:     var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
        !          1094:     if (nret==null) return;
        !          1095:     var curlist = document.SCORE.keywords.value;
        !          1096:     document.SCORE.keywords.value = curlist+" "+nret;
        !          1097:     return;
1.35      ng       1098:   }
                   1099: 
1.38    ! ng       1100: //====================== Script for composing message ==============
        !          1101:   function msgCenter(msgform,usrctr,fullname) {
        !          1102:     var Nmsg  = msgform.savemsgN.value;
        !          1103:     savedMsgHeader(Nmsg,usrctr,fullname);
        !          1104:     var subject = msgform.msgsub.value;
        !          1105:     var rtrchk  = eval("document.SCORE.includemsg"+usrctr);
        !          1106:     var msgchk = rtrchk.value;
        !          1107: //    alert("checked=>"+msgchk);
        !          1108:     re = /msgsub/;
        !          1109:     var shwsel = "";
        !          1110:     if (re.test(msgchk)) { shwsel = "checked" }
        !          1111:     displaySubject(subject,shwsel);
        !          1112:     for (var i=1; i<=Nmsg; i++) {
        !          1113: 	var testpt = "savemsg"+i+",";
        !          1114: 	re = /testpt/;
        !          1115: 	shwsel = "";
        !          1116: 	if (re.test(msgchk)) { shwsel = "checked" }
        !          1117: 	var message = eval("document.SCORE.savemsg"+i+".value");
        !          1118: 	displaySavedMsg(i,message,shwsel);
        !          1119:     }
        !          1120:     newmsg = eval("document.SCORE.newmsg"+usrctr+".value");
        !          1121:     shwsel = "";
        !          1122:     re = /newmsg/;
        !          1123:     if (re.test(msgchk)) { shwsel = "checked" }
        !          1124:     newMsg(newmsg,shwsel);
        !          1125:     msgTail(); 
        !          1126:     return;
1.35      ng       1127:   }
                   1128: 
1.38    ! ng       1129:   function savedMsgHeader(Nmsg,usrctr,fullname) {
        !          1130:     var height = 30*Nmsg+250;
        !          1131:     var scrollbar = "no";
        !          1132:     if (height > 600) {
        !          1133: 	height = 600;
        !          1134: 	scrollbar = "yes";
        !          1135:     }
        !          1136: /*    if (window.pWin)
        !          1137: 	window.pWin.close(); */
        !          1138:     pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx=70,screeny=75,width=600,height='+height);
        !          1139:     pWin.document.write("<html><head>");
        !          1140:     pWin.document.write("<title>Message Central</title>");
1.37      ng       1141: 
1.38    ! ng       1142:     pWin.document.write("<script language=javascript>");
        !          1143:     pWin.document.write("function checkInput() {");
        !          1144:     pWin.document.write("  opener.document.SCORE.msgsub.value = document.msgcenter.msgsub.value;");
        !          1145:     pWin.document.write("  var nmsg   = opener.document.SCORE.savemsgN.value;");
        !          1146:     pWin.document.write("  var usrctr = document.msgcenter.usrctr.value;");
        !          1147:     pWin.document.write("  var newval = eval(\\"opener.document.SCORE.newmsg\\"+usrctr);");
        !          1148:     pWin.document.write("  newval.value = document.msgcenter.newmsg.value;");
1.37      ng       1149: 
1.38    ! ng       1150:     pWin.document.write("  var msgchk = \\"\\";");
        !          1151:     pWin.document.write("  if (document.msgcenter.subchk.checked) {");
        !          1152:     pWin.document.write("     msgchk = \\"msgsub,\\";");
        !          1153:     pWin.document.write("  }");
        !          1154:     pWin.document.write(   "for (var i=1; i<=nmsg; i++) {");
        !          1155:     pWin.document.write("      var opnmsg = eval(\\"opener.document.SCORE.savemsg\\"+i);");
        !          1156:     pWin.document.write("      var frmmsg = eval(\\"document.msgcenter.msg\\"+i);");
        !          1157:     pWin.document.write("      opnmsg.value = frmmsg.value;");
        !          1158:     pWin.document.write("      var chkbox = eval(\\"document.msgcenter.msgn\\"+i);");
        !          1159:     pWin.document.write("      if (chkbox.checked) {");
        !          1160:     pWin.document.write("         msgchk += \\"savemsg\\"+i+\\",\\";");
        !          1161:     pWin.document.write("      }");
        !          1162:     pWin.document.write("  }");
        !          1163:     pWin.document.write("  if (document.msgcenter.newmsgchk.checked) {");
        !          1164:     pWin.document.write("     msgchk += \\"newmsg\\"+usrctr;");
        !          1165:     pWin.document.write("  }");
        !          1166:     pWin.document.write("  var includemsg = eval(\\"opener.document.SCORE.includemsg\\"+usrctr);");
        !          1167:     pWin.document.write("  includemsg.value = msgchk;");
1.37      ng       1168: 
1.38    ! ng       1169: //    pWin.document.write("  alert(\\"slected=\\"+msgchk)");
        !          1170:     pWin.document.write("  self.close()");
1.37      ng       1171: 
1.38    ! ng       1172:     pWin.document.write("}");
1.34      ng       1173: 
1.38    ! ng       1174:     pWin.document.write("<");
        !          1175:     pWin.document.write("/script>");
1.33      ng       1176: 
1.38    ! ng       1177:     pWin.document.write("</head><body bgcolor=white>");
1.37      ng       1178: 
1.38    ! ng       1179:     pWin.document.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
        !          1180:     pWin.document.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
        !          1181:     pWin.document.write("<font color=\\"green\\" size=+1>&nbsp;Compose Message for \"+fullname+\"</font><br><br>");
1.34      ng       1182: 
1.38    ! ng       1183:     pWin.document.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
        !          1184:     pWin.document.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
        !          1185:     pWin.document.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
        !          1186: }
        !          1187:     function displaySubject(msg,shwsel) {
        !          1188:     pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
        !          1189:     pWin.document.write("<td>Subject</td>");
        !          1190:     pWin.document.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
        !          1191:     pWin.document.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+" \\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.34      ng       1192: }
                   1193: 
1.38    ! ng       1194: function displaySavedMsg(ctr,msg,shwsel) {
        !          1195:     pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
        !          1196:     pWin.document.write("<td align=\\"center\\">"+ctr+"</td>");
        !          1197:     pWin.document.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
        !          1198:     pWin.document.write("<td><input name=\\"msg"+ctr+"\\" type=\\"text\\" value=\\""+msg+" \\" size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.34      ng       1199: }
                   1200: 
1.38    ! ng       1201:   function newMsg(newmsg,shwsel) {
        !          1202:     pWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
        !          1203:     pWin.document.write("<td align=\\"center\\">New</td>");
        !          1204:     pWin.document.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
        !          1205:     pWin.document.write("<td><input name=\\"newmsg\\" type=\\"text\\" value=\\""+newmsg+" \\" size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.34      ng       1206: }
                   1207: 
1.38    ! ng       1208:   function msgTail() {
        !          1209:     pWin.document.write("</table>");
        !          1210:     pWin.document.write("</td></tr></table>&nbsp;");
        !          1211:     pWin.document.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\">&nbsp;&nbsp;");
        !          1212:     pWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
        !          1213:     pWin.document.write("</form>");
        !          1214:     pWin.document.write("</body></html>");
        !          1215: }
1.34      ng       1216: 
1.38    ! ng       1217: //====================== Script for keyword highlight options ==============
        !          1218:   function kwhighlight() {
        !          1219:     var kwclr    = document.SCORE.kwclr.value;
        !          1220:     var kwsize   = document.SCORE.kwsize.value;
        !          1221:     var kwstyle  = document.SCORE.kwstyle.value;
        !          1222:     var redsel = "";
        !          1223:     var grnsel = "";
        !          1224:     var blusel = "";
        !          1225:     if (kwclr=="red")   {var redsel="checked"};
        !          1226:     if (kwclr=="green") {var grnsel="checked"};
        !          1227:     if (kwclr=="blue")  {var blusel="checked"};
        !          1228:     var sznsel = "";
        !          1229:     var sz1sel = "";
        !          1230:     var sz2sel = "";
        !          1231:     if (kwsize=="0")  {var sznsel="checked"};
        !          1232:     if (kwsize=="+1") {var sz1sel="checked"};
        !          1233:     if (kwsize=="+2") {var sz2sel="checked"};
        !          1234:     var synsel = "";
        !          1235:     var syisel = "";
        !          1236:     var sybsel = "";
        !          1237:     if (kwstyle=="")    {var synsel="checked"};
        !          1238:     if (kwstyle=="<i>") {var syisel="checked"};
        !          1239:     if (kwstyle=="<b>") {var sybsel="checked"};
        !          1240:     highlightCentral();
        !          1241:     highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
        !          1242:     highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
        !          1243:     highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
        !          1244:     highlightend();
        !          1245:     return;
1.34      ng       1246:   }
                   1247: 
                   1248: 
1.38    ! ng       1249:   function highlightCentral() {
        !          1250:     hwdWin = window.open('', 'KeywordHighlightCentral', 'toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx=100,screeny=75');
        !          1251:     hwdWin.document.write("<html><head>");
        !          1252:     hwdWin.document.write("<title>Highlight Central</title>");
1.34      ng       1253: 
1.38    ! ng       1254:     hwdWin.document.write("<script language=javascript>");
        !          1255:     hwdWin.document.write("function updateChoice() {");
        !          1256:     hwdWin.document.write("  opener.document.SCORE.kwclr.value = radioSelection(document.hlCenter.kwdclr);");
        !          1257:     hwdWin.document.write("  opener.document.SCORE.kwsize.value = radioSelection(document.hlCenter.kwdsize);");
        !          1258:     hwdWin.document.write("  opener.document.SCORE.kwstyle.value = radioSelection(document.hlCenter.kwdstyle);");
        !          1259:     hwdWin.document.write("  self.close()");
        !          1260:     hwdWin.document.write("}");
1.26      albertel 1261: 
1.38    ! ng       1262:     hwdWin.document.write("function radioSelection(radioButton) {");
        !          1263:     hwdWin.document.write("    var selection=null;");
        !          1264:     hwdWin.document.write("    for (var i=0; i<radioButton.length; i++) {");
        !          1265:     hwdWin.document.write("        if (radioButton[i].checked) {");
        !          1266:     hwdWin.document.write("            selection=radioButton[i].value;");
        !          1267:     hwdWin.document.write("            return selection;");
        !          1268:     hwdWin.document.write("        }");
        !          1269:     hwdWin.document.write("    }");
        !          1270:     hwdWin.document.write("}");
1.26      albertel 1271: 
1.38    ! ng       1272:     hwdWin.document.write("<");
        !          1273:     hwdWin.document.write("/script>");
1.13      albertel 1274: 
1.38    ! ng       1275:     hwdWin.document.write("</head><body bgcolor=white>");
1.13      albertel 1276: 
1.38    ! ng       1277:     hwdWin.document.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
        !          1278:     hwdWin.document.write("<font color=\\"green\\" size=+1>&nbsp;Keyword Highlight Options</font><br><br>");
1.13      albertel 1279: 
1.38    ! ng       1280:     hwdWin.document.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
        !          1281:     hwdWin.document.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
        !          1282:     hwdWin.document.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
1.30      ng       1283:   }
1.38    ! ng       1284: 
        !          1285:   function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) { 
        !          1286:     hwdWin.document.write("<tr bgcolor=\\"#ffffdd\\">");
        !          1287:     hwdWin.document.write("<td align=\\"left\\">");
        !          1288:     hwdWin.document.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+">&nbsp;"+clrtxt+"</td>");
        !          1289:     hwdWin.document.write("<td align=\\"left\\">");
        !          1290:     hwdWin.document.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+">&nbsp;"+sztxt+"</td>");
        !          1291:     hwdWin.document.write("<td align=\\"left\\">");
        !          1292:     hwdWin.document.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+">&nbsp;"+sytxt+"</td>");
        !          1293:     hwdWin.document.write("</tr>");
1.13      albertel 1294:   }
1.5       albertel 1295: 
1.38    ! ng       1296:   function highlightend() { 
        !          1297:     hwdWin.document.write("</table>");
        !          1298:     hwdWin.document.write("</td></tr></table>&nbsp;");
        !          1299:     hwdWin.document.write("<input type=\\"button\\" value=\\"Set Options\\" onClick=\\"javascript:updateChoice()\\">&nbsp;&nbsp;");
        !          1300:     hwdWin.document.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
        !          1301:     hwdWin.document.write("</form>");
        !          1302:     hwdWin.document.write("</body></html>");
1.13      albertel 1303:   }
1.5       albertel 1304: 
1.38    ! ng       1305: </script>
        !          1306: SUBJAVASCRIPT
1.5       albertel 1307: }
                   1308: 
1.27      albertel 1309: sub csvupload_javascript_reverse_associate {
                   1310:   return(<<ENDPICK);
                   1311:   function verify(vf) {
                   1312:     var foundsomething=0;
                   1313:     var founduname=0;
                   1314:     var founddomain=0;
                   1315:     for (i=0;i<=vf.nfields.value;i++) {
                   1316:       tw=eval('vf.f'+i+'.selectedIndex');
                   1317:       if (i==0 && tw!=0) { founduname=1; }
                   1318:       if (i==1 && tw!=0) { founddomain=1; }
                   1319:       if (i!=0 && i!=1 && tw!=0) { foundsomething=1; }
                   1320:     }
                   1321:     if (founduname==0 || founddomain==0) {
                   1322:       alert('You need to specify at both the username and domain');
                   1323:       return;
                   1324:     }
                   1325:     if (foundsomething==0) {
                   1326:       alert('You need to specify at least one grading field');
                   1327:       return;
                   1328:     }
                   1329:     vf.submit();
                   1330:   }
                   1331:   function flip(vf,tf) {
                   1332:     var nw=eval('vf.f'+tf+'.selectedIndex');
                   1333:     var i;
                   1334:     for (i=0;i<=vf.nfields.value;i++) {
                   1335:       //can not pick the same destination field for both name and domain
                   1336:       if (((i ==0)||(i ==1)) && 
                   1337:           ((tf==0)||(tf==1)) && 
                   1338:           (i!=tf) &&
                   1339:           (eval('vf.f'+i+'.selectedIndex')==nw)) {
                   1340:         eval('vf.f'+i+'.selectedIndex=0;')
                   1341:       }
                   1342:     }
                   1343:   }
                   1344: ENDPICK
                   1345: }
                   1346: 
                   1347: sub csvupload_javascript_forward_associate {
                   1348:   return(<<ENDPICK);
                   1349:   function verify(vf) {
                   1350:     var foundsomething=0;
                   1351:     var founduname=0;
                   1352:     var founddomain=0;
                   1353:     for (i=0;i<=vf.nfields.value;i++) {
                   1354:       tw=eval('vf.f'+i+'.selectedIndex');
                   1355:       if (tw==1) { founduname=1; }
                   1356:       if (tw==2) { founddomain=1; }
                   1357:       if (tw>2) { foundsomething=1; }
                   1358:     }
                   1359:     if (founduname==0 || founddomain==0) {
                   1360:       alert('You need to specify at both the username and domain');
                   1361:       return;
                   1362:     }
                   1363:     if (foundsomething==0) {
                   1364:       alert('You need to specify at least one grading field');
                   1365:       return;
                   1366:     }
                   1367:     vf.submit();
                   1368:   }
                   1369:   function flip(vf,tf) {
                   1370:     var nw=eval('vf.f'+tf+'.selectedIndex');
                   1371:     var i;
                   1372:     //can not pick the same destination field twice
                   1373:     for (i=0;i<=vf.nfields.value;i++) {
                   1374:       if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
                   1375:         eval('vf.f'+i+'.selectedIndex=0;')
                   1376:       }
                   1377:     }
                   1378:   }
                   1379: ENDPICK
                   1380: }
                   1381: 
1.26      albertel 1382: sub csvuploadmap_header {
                   1383:   my ($request,$symb,$url,$datatoken,$distotal)= @_;
                   1384:   my $result;
                   1385:   my $javascript;
                   1386:   if ($ENV{'form.upfile_associate'} eq 'reverse') {
1.27      albertel 1387:     $javascript=&csvupload_javascript_reverse_associate();
1.26      albertel 1388:   } else {
1.27      albertel 1389:     $javascript=&csvupload_javascript_forward_associate();
1.26      albertel 1390:   }
                   1391:   $request->print(<<ENDPICK);
                   1392: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
                   1393: <h3>Uploading Class Grades for resource $url</h3>
                   1394: <hr>
                   1395: <h3>Identify fields</h3>
                   1396: Total number of records found in file: $distotal <hr />
                   1397: Enter as many fields as you can. The system will inform you and bring you back
                   1398: to this page if the data selected is insufficient to run your class.<hr />
                   1399: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
                   1400: <input type="hidden" name="associate"  value="" />
                   1401: <input type="hidden" name="phase"      value="three" />
                   1402: <input type="hidden" name="datatoken"  value="$datatoken" />
                   1403: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
                   1404: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
                   1405: <input type="hidden" name="upfile_associate" 
                   1406:                                        value="$ENV{'form.upfile_associate'}" />
                   1407: <input type="hidden" name="symb"       value="$symb" />
                   1408: <input type="hidden" name="url"        value="$url" />
                   1409: <input type="hidden" name="command"    value="csvuploadassign" />
                   1410: <hr />
                   1411: <script type="text/javascript" language="Javascript">
                   1412: $javascript
                   1413: </script>
                   1414: ENDPICK
                   1415:   return '';
                   1416: 
                   1417: }
                   1418: 
                   1419: sub csvupload_fields {
                   1420:   my ($url) = @_;
                   1421:   my (@parts) = &getpartlist($url);
1.27      albertel 1422:   my @fields=(['username','Student Username'],['domain','Student Domain']);
                   1423:   foreach my $part (sort(@parts)) {
1.26      albertel 1424:     my @datum;
                   1425:     my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.27      albertel 1426:     my $name=$part;
1.26      albertel 1427:     if  (!$display) { $display = $name; }
                   1428:     @datum=($name,$display);
                   1429:     push(@fields,\@datum);
                   1430:   }
                   1431:   return (@fields);
                   1432: }
                   1433: 
                   1434: sub csvuploadmap_footer {
                   1435:   my ($request,$i,$keyfields) =@_;
                   1436:   $request->print(<<ENDPICK);
                   1437: </table>
                   1438: <input type="hidden" name="nfields" value="$i" />
                   1439: <input type="hidden" name="keyfields" value="$keyfields" />
                   1440: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
                   1441: </form>
                   1442: ENDPICK
                   1443: }
                   1444: 
                   1445: sub csvuploadmap {
                   1446:   my ($request)= @_;
                   1447:   my ($symb,$url)=&get_symb_and_url($request);
                   1448:   if (!$symb) {return '';}
                   1449:   my $datatoken;
                   1450:   if (!$ENV{'form.datatoken'}) {
                   1451:     $datatoken=&Apache::loncommon::upfile_store($request);
                   1452:   } else {
                   1453:     $datatoken=$ENV{'form.datatoken'};
                   1454:     &Apache::loncommon::load_tmp_file($request);
                   1455:   }
                   1456:   my @records=&Apache::loncommon::upfile_record_sep();
                   1457:   &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
                   1458:   my $i;
                   1459:   my $keyfields;
                   1460:   if (@records) {
                   1461:     my @fields=&csvupload_fields($url);
                   1462:     if ($ENV{'form.upfile_associate'} eq 'reverse') {	
                   1463:       &Apache::loncommon::csv_print_samples($request,\@records);
                   1464:       $i=&Apache::loncommon::csv_print_select_table($request,\@records,
                   1465: 						    \@fields);
                   1466:       foreach (@fields) { $keyfields.=$_->[0].','; }
                   1467:       chop($keyfields);
                   1468:     } else {
                   1469:       unshift(@fields,['none','']);
                   1470:       $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
                   1471: 						      \@fields);
                   1472:       my %sone=&Apache::loncommon::record_sep($records[0]);
                   1473:       $keyfields=join(',',sort(keys(%sone)));
                   1474:     }
                   1475:   }
                   1476:   &csvuploadmap_footer($request,$i,$keyfields);
                   1477:   return '';
1.27      albertel 1478: }
                   1479: 
                   1480: sub csvuploadassign {
                   1481:   my ($request)= @_;
                   1482:   my ($symb,$url)=&get_symb_and_url($request);
                   1483:   if (!$symb) {return '';}
                   1484:   &Apache::loncommon::load_tmp_file($request);
                   1485:   my @gradedata=&Apache::loncommon::upfile_record_sep();
                   1486:   my @keyfields = split(/\,/,$ENV{'form.keyfields'});
                   1487:   my %fields=();
                   1488:   for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
                   1489:     if ($ENV{'form.upfile_associate'} eq 'reverse') {
                   1490:       if ($ENV{'form.f'.$i} ne 'none') {
                   1491: 	$fields{$keyfields[$i]}=$ENV{'form.f'.$i};
                   1492:       }
                   1493:     } else {
                   1494:       if ($ENV{'form.f'.$i} ne 'none') {
                   1495: 	$fields{$ENV{'form.f'.$i}}=$keyfields[$i];
                   1496:       }
                   1497:     }
                   1498:   }
                   1499:   $request->print('<h3>Assigning Grades</h3>');
                   1500:   my $courseid=$ENV{'request.course.id'};
1.34      ng       1501: #  my $cdom=$ENV{"course.$courseid.domain"};
                   1502: #  my $cnum=$ENV{"course.$courseid.num"};
                   1503:   my ($classlist) = &getclasslist('all','1');
1.29      albertel 1504:   my @skipped;
                   1505:   my $countdone=0;
                   1506:   foreach my $grade (@gradedata) {
                   1507:     my %entries=&Apache::loncommon::record_sep($grade);
                   1508:     my $username=$entries{$fields{'username'}};
                   1509:     my $domain=$entries{$fields{'domain'}};
1.34      ng       1510:     if (!exists($$classlist{"$username:$domain"})) {
1.29      albertel 1511:       push(@skipped,"$username:$domain");
                   1512:       next;
1.27      albertel 1513:     }
1.29      albertel 1514:     my %grades;
                   1515:     foreach my $dest (keys(%fields)) {
                   1516:       if ($dest eq 'username' || $dest eq 'domain') { next; }
                   1517:       if ($entries{$fields{$dest}} eq '') { next; }
                   1518:       my $store_key=$dest;
                   1519:       $store_key=~s/^stores/resource/;
                   1520:       $store_key=~s/_/\./g;
                   1521:       $grades{$store_key}=$entries{$fields{$dest}};
                   1522:     }
                   1523:     $grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
                   1524:     &Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
                   1525: 			    $domain,$username);
                   1526:     $request->print('.');
                   1527:     $request->rflush();
                   1528:     $countdone++;
                   1529:   }
                   1530:   $request->print("<br />Stored $countdone students\n");
                   1531:   if (@skipped) {
                   1532:     $request->print('<br /><font size="+1"><b>Skipped Students</b></font><br />');
                   1533:     foreach my $student (@skipped) { $request->print("<br />$student"); }
1.27      albertel 1534:   }
1.29      albertel 1535:   $request->print(&view_edit_entire_class_form($symb,$url));
                   1536:   $request->print(&show_grading_menu_form($symb,$url));
                   1537:   return '';
1.26      albertel 1538: }
                   1539: 
1.2       albertel 1540: sub send_header {
1.13      albertel 1541:   my ($request)= @_;
                   1542:   $request->print(&Apache::lontexconvert::header());
1.6       albertel 1543: #  $request->print("
                   1544: #<script>
                   1545: #remotewindow=open('','homeworkremote');
                   1546: #remotewindow.close();
                   1547: #</script>"); 
1.13      albertel 1548:   $request->print('<body bgcolor="#FFFFFF">');
1.2       albertel 1549: }
                   1550: 
                   1551: sub send_footer {
1.13      albertel 1552:   my ($request)= @_;
1.2       albertel 1553:   $request->print('</body>');
                   1554:   $request->print(&Apache::lontexconvert::footer());
                   1555: }
                   1556: 
1.1       albertel 1557: sub handler {
1.13      albertel 1558:   my $request=$_[0];
                   1559: 
                   1560:   if ($ENV{'browser.mathml'}) {
                   1561:     $request->content_type('text/xml');
                   1562:   } else {
                   1563:     $request->content_type('text/html');
                   1564:   }
                   1565:   $request->send_http_header;
                   1566:   return OK if $request->header_only;
1.16      albertel 1567:   &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.13      albertel 1568:   my $url=$ENV{'form.url'};
                   1569:   my $symb=$ENV{'form.symb'};
                   1570:   my $command=$ENV{'form.command'};
1.16      albertel 1571:   if (!$url) {
                   1572:     my ($temp1,$temp2);
                   1573:     ($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
                   1574:     $url = $ENV{'form.url'};
                   1575:   }
1.13      albertel 1576:   &send_header($request);
                   1577:   if ($url eq '' && $symb eq '') {
1.14      www      1578:      if ($ENV{'user.adv'}) {
                   1579:          if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
                   1580:              ($ENV{'form.codethree'})) {
                   1581:              my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
                   1582: 		        $ENV{'form.codethree'};
                   1583:              my ($tsymb,$tuname,$tudom,$tcrsid)=
                   1584: 		 &Apache::lonnet::checkin($token);
                   1585:              if ($tsymb) {
                   1586:                 my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
                   1587:                 if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
                   1588:                    $request->print(
                   1589:                      &Apache::lonnet::ssi('/res/'.$url,
                   1590:                         ('grade_username' => $tuname,
                   1591:                          'grade_domain' => $tudom,
                   1592:                          'grade_courseid' => $tcrsid,
                   1593:                          'grade_symb' => $tsymb)));
                   1594:                 } else {
                   1595:                    $request->print('<h1>Not authorized: '.$token.'</h1>');
                   1596:                 }           
                   1597: 	    } else {
                   1598:                 $request->print('<h1>Not a valid DocID: '.$token.'</h1>');
                   1599:             }
                   1600: 	 } else {
                   1601:              $request->print(&Apache::lonxml::tokeninputfield());
                   1602:          }
                   1603:      }
1.13      albertel 1604:   } else {
1.29      albertel 1605:     #&Apache::lonhomework::showhashsubset(\%ENV,'^form');
1.13      albertel 1606:     $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
                   1607:     if ($command eq 'submission') {
1.20      albertel 1608:       &listStudents($request) if ($ENV{'form.student'} eq '');
1.34      ng       1609:       &submission($request,0,0) if ($ENV{'form.student'} ne '');
                   1610:     } elsif ($command eq 'processGroup') {
                   1611:       &processGroup($request);
1.26      albertel 1612:     } elsif ($command eq 'gradingmenu') {
                   1613:       $request->print(&gradingmenu($request));
1.13      albertel 1614:     } elsif ($command eq 'viewgrades') {
                   1615:       $request->print(&viewgrades($request));
1.33      ng       1616:     } elsif ($command eq 'handgrade') {
                   1617:       $request->print(&processHandGrade($request));
1.13      albertel 1618:     } elsif ($command eq 'editgrades') {
                   1619:       $request->print(&editgrades($request));
1.23      www      1620:     } elsif ($command eq 'verify') {
                   1621:       $request->print(&verifyreceipt($request));
1.26      albertel 1622:     } elsif ($command eq 'csvupload') {
                   1623:       $request->print(&csvupload($request));
                   1624:     } elsif ($command eq 'csvuploadmap') {
                   1625:       $request->print(&csvuploadmap($request));
1.34      ng       1626: #    } elsif ($command eq 'receiptInput') {
                   1627: #      &receiptInput($request);
1.26      albertel 1628:     } elsif ($command eq 'csvuploadassign') {
                   1629:       if ($ENV{'form.associate'} ne 'Reverse Association') {
                   1630: 	$request->print(&csvuploadassign($request));
                   1631:       } else {
                   1632: 	if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
                   1633: 	  $ENV{'form.upfile_associate'} = 'reverse';
                   1634: 	} else {
                   1635: 	  $ENV{'form.upfile_associate'} = 'forward';
                   1636: 	}
                   1637: 	$request->print(&csvuploadmap($request));
                   1638:       }
1.12      harris41 1639:     } else {
1.23      www      1640:       $request->print("Unknown action: $command:");
1.2       albertel 1641:     }
1.13      albertel 1642:   }
                   1643:   &send_footer($request);
                   1644:   return OK;
1.1       albertel 1645: }
                   1646: 
                   1647: 1;
                   1648: 
1.13      albertel 1649: __END__;

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