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

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

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