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