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