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